1
로그인 양식에서 DOCTOR 테이블에있는 잭으로 로그인하면 page_two로 이동합니다. 잭이 간호사가 아니라 의사이기 때문에 간호사 버튼 1과 간호사 버튼 2를 비활성화하고 싶습니다. 그런 다음 NURSE 테이블에있는 Mary로 로그인하면 반대쪽으로 page_two로 이동합니다. 메리가 의사가 아니라 간호사이기 때문에 의사 버튼 1과 의사 버튼 2를 비활성화하고 싶습니다. 로그인 한 사용자에 따라 특정 버튼을 비활성화하십시오.
Page_two의 버튼 이름
난 당신이 사람이 데이터를 보유하기 위해 일부Person
클래스를 생성하는 것이 좋습니다 btnDoctor1, btnDoctor2, btnNurse1 및 btnNurse2
// 로그인 양식 코드
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace GRP_02_03_SACP
{
public partial class page_one : Form
{
public page_one()
{
InitializeComponent();
}
private void page_one_Load(object sender, EventArgs e)
{
}
private void btnLogin_Click(object sender, EventArgs e)
{
//retrieve connection information info from App.config
string strConnectionString = ConfigurationManager.ConnectionStrings["sacpConnection"].ConnectionString;
//STEP 1: Create connection
SqlConnection myConnect = new SqlConnection(strConnectionString);
//STEP 2: Create command
string strCommandtext = "SELECT dUsername, dPassword from DOCTOR";
// Add a WHERE Clause to SQL statement
strCommandtext += " WHERE [email protected] AND [email protected];";
strCommandtext += "SELECT nUsername, nPassword from NURSE WHERE [email protected] AND [email protected]pwd;";
SqlCommand cmd = new SqlCommand(strCommandtext, myConnect);
cmd.Parameters.AddWithValue("@dname", textUsername.Text);
cmd.Parameters.AddWithValue("@dpwd", txtPassword.Text);
cmd.Parameters.AddWithValue("@nname", textUsername.Text);
cmd.Parameters.AddWithValue("@npwd", txtPassword.Text);
try
{
// STEP 3: open connection and retrieve data by calling ExecuteReader
myConnect.Open();
// STEP 4: Access Data
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read()) //For Doctor
{
if (MessageBox.Show("Login Successful") == DialogResult.OK)
{
page_two form = new page_two();
form.Show();
return;
}
}
reader.NextResult();
while (reader.Read()) //For Nurse
{
if (MessageBox.Show("Login Successful") == DialogResult.OK)
{
page_two form = new page_two();
form.Show();
return;
}
}
//STEP 5: close connection
reader.Close();
MessageBox.Show("Invalid username or password");
}
catch (SqlException ex)
{
}
finally
{
//STEP 5: close connection
myConnect.Close();
}
}
}
}
사용'form.nursebtn : 컨트롤을 활성화 또는 비활성화 할 사람이 로그인의 기본 폼의 사용 위치에
: 그것은
MainForm
생성자에 전달해야한다Person
인스턴스를 얻을 수PersonRepository
를 사용해야합니다. Visible = False; '를 선택합니다. –좋아요.하지만 잭으로 의사로 로그인 할 수는 없지만, nursebutton을 클릭 할 때 액세스 거부 메시지가 튀어 나오면 어떨까요? @ Al-3sli – Pony
당신이 공개 변수를 작성하여 의사가 투과 타입을 가질 수 있습니다. 의사가 다른 1, 2와 같이 설정하면 다음과 같습니다 :'permeationtype = 1;'이 사용자가 의사임을 나타내므로 사용자가 간호사 버튼을 누르면 투과 유형 1이면 메시지를 계속 보여주세요. –