1、GIF效果圖

2.6....gif
2、畫(huà)面主要功能,并列出支持這些功能的后臺(tái)數(shù)據(jù)庫(kù)表結(jié)構(gòu)
畫(huà)面主要功能:
(1)成功連接數(shù)據(jù)庫(kù)。
(2)用戶(hù)登錄成功,進(jìn)入系統(tǒng)主界面。
數(shù)據(jù)表結(jié)構(gòu)
2.6.1.PNG
2.6.PNG
3、ADO.NET查詢(xún)數(shù)據(jù)庫(kù)的流程

ADO.NET查詢(xún)數(shù)據(jù)庫(kù)的流程圖.png
具體步驟:
- 導(dǎo)入命名空間;
- 運(yùn)用Connection對(duì)象建立與數(shù)據(jù)庫(kù)連接;
- 打開(kāi)連接;
- 利用Command對(duì)象的ExecuteReader()方法執(zhí)行Select查詢(xún)語(yǔ)句;
- 利用ExecuteReader()方法返回的DataReader對(duì)象讀取數(shù)據(jù),顯示到界面上;
- 關(guān)閉連接。
4、重要代碼片段,并進(jìn)行描述
(1)連接數(shù)據(jù)庫(kù),獲取數(shù)據(jù)。
String connStr = "Data Source=.;Initial Catalog=SuperMarketSales;Integrated Security=True";
SqlConnection sqlConn = new SqlConnection(connStr);
try
{
sqlConn.Open();
// 數(shù)據(jù)獲取
}
catch (Exception exp)
{
MessageBox.Show("數(shù)據(jù)庫(kù)連接失敗");
}
finally
{
sqlConn.Close();
}
(2)構(gòu)建查詢(xún)語(yǔ)句并提交查詢(xún)。USER是SQL Server關(guān)鍵字,表名不能命名為USER,而應(yīng)當(dāng)用USERS。用用戶(hù)ID登錄,而不是用戶(hù)名,用戶(hù)名可能會(huì)重復(fù)
String sqlStr = "";
if (this.cbb_UserType.Text == "收銀員")
{
sqlStr = "select * from USERS where ID=@id and PASSWORD=@pwd";
}
else
{
sqlStr = "select * from ADMIN where ID=@id and PASSWORD=@pwd";
}
SqlCommand cmd = new SqlCommand(sqlStr, sqlConn);
cmd.Parameters.Add(new SqlParameter("@id", this.tb_User.Text.Trim()));
cmd.Parameters.Add(new SqlParameter("@pwd", this.tb_Password.Text.Trim()));
SqlDataReader dr = cmd.ExecuteReader();
(3)如果能夠從數(shù)據(jù)庫(kù)中查詢(xún)到記錄,則表示可以登錄。反之則登陸失敗
if (dr.HasRows)
{
dr.Read();
UserInfo.userId = int.Parse(dr["ID"].ToString());
UserInfo.userName = dr["NAME"].ToString();
UserInfo.userPwd = dr["PASSWORD"].ToString();
UserInfo.userPhone = dr["PHONE"].ToString();
UserInfo.userType = this.cbb_UserType.Text;
MessageBox.Show(UserInfo.userType + "登錄成功");
}
if (UserInfo.userType == "收銀員")
{
// 顯示收銀員主界面
MainFormUser formUser = new MainFormUser();
formUser.Show();
// 隱藏登錄界面
this.Hide();
}
if (UserInfo.userType == "庫(kù)管員")
{
// 顯示庫(kù)管員主界面
MainFormAdmin formAdmin = new MainFormAdmin();
formAdmin.Show();
// 隱藏登錄界面
this.Hide();
}