private void button2_Click(object sender, EventArgs e) { strID = tbID.Text.Trim(); strPsd = tbPsd.Text.Trim(); string strSql = ""; strSql = "select * from userTable where userID = '" + strID + "'"; SqlDataReader dr = db.DB_Red(strSql); if (dr.Read()) { string psd = db.DB_C(strSql, 1); if (strPsd.Equals(psd)) { string name = dr.GetString(2); string strSql2 = "delete from Users"; db.DB_ZSG(strSql2); string strSql1 = "insert into Users values('" + strID + "')"; db.DB_ZSG(strSql1); MessageBox.Show("登录成功"); Gloable.username = "******" + name; this.Close(); } } else { MessageBox.Show("用户名或者密码错误"); tbID.Text = ""; tbPsd.Text = ""; tbID.Focus(); } }
private void FmIdUp_Load(object sender, EventArgs e) { try { DBCL.DataBase db = new DBCL.DataBase(); string sql = "select * from userTable where userID = '" + username + "'"; textBox1.Text = db.DB_C(sql, 2); comboBox2.Text = db.DB_C(sql, 5); db.odrClose(); db.connClose(); } catch { MessageBox.Show("窗口加载失败"); } }
public FmPerson() { try { string strSql = ""; strSql = "select * from Users"; username = db.DB_C(strSql, 0); } catch { MessageBox.Show("获取用户名失败!"); } InitializeComponent(); LbMess.Text = ""; }
public FmIdUp() { try { DBCL.DataBase db = new DBCL.DataBase(); string strSql = ""; strSql = "select * from Users"; username = db.DB_C(strSql, 0); db.odrClose(); db.connClose(); } catch { MessageBox.Show("窗口初始化失败"); } InitializeComponent(); }
//登录按钮事件 private void btnLogin_Click(object sender, EventArgs e) { string strUserName = ""; string strUserPwd = ""; strUserName = tbUserName.Text.Trim(); strUserPwd = tbUserPwd.Text.Trim(); if (strUserName == "") { MessageBox.Show("用户名不能为空!", "警告"); return; } if (strUserPwd == "") { MessageBox.Show("密码不能为空!", "警告"); return; } string strSql = ""; strSql = "select UserPwd from UserTable where UserName = '******'"; SqlDataReader dr = db.DB_Red(strSql); if (dr.Read()) { if (strUserPwd.Equals(db.DB_C(strSql, 0))) { Form1 frm1 = new Form1(); frm1.Show(); this.Hide(); } else { MessageBox.Show("密码错误!", "警告"); return; } } else { MessageBox.Show("用户名不存在!", "警告"); return; } }