private void btn_login_Click(object sender, EventArgs e)//登录按钮 { tb_UserInfo User = new tb_UserInfo(); User.Lname1 = txtuser.Text.ToString().Trim(); User.Lpass1 = txtpass.Text.ToString().Trim(); if (txtuser.Text == "" || txtpass.Text == "") { MessageBox.Show("用户名或密码不能为空!"); if (txtuser.Text == "") { txtuser.Focus(); } else if (txtpass.Text == "") { txtpass.Focus(); } return; } else if (txtyzm.Text == "") { MessageBox.Show("验证码不能为空"); txtyzm.Focus(); return; } else if (txtyzm.Text != label4.Text) { MessageBox.Show("验证码输入有误"); txtyzm.Focus(); txtyzm.Clear(); label4.Text = YanZM(); return; } // string sql = "select * from Wm_Login where Lname=@userId and Lpass=@userpassword"; //DataRow row = Methods.GetRow(sql, new SqlParameter("@userId", txtuser.Text), new SqlParameter("@userpassword", txtpass.Text)); int flag = SQLOperation.ExistCount(User); if (flag > 0) { // MessageBox.Show("登录成功!\t"+flag.ToString()); Parameter_Query.username = this.txtuser.Text; Parameter_Query.userflag = flag; PassEdit.passs = this.txtpass.Text; Parameter_Query PQ = new Parameter_Query(); PQ.Show(); this.Hide(); return; } else { MessageBox.Show("不存在此用户!请重新登录!"); txtuser.Text = ""; txtpass.Text = ""; txtyzm.Text = ""; label4.Text = this.YanZM(); txtuser.Focus(); return; } }
//修改密码 public static int UpdatePwd(tb_UserInfo mp) { string sql = "update Wm_Login set Lpass=@passward where Lname=@ID"; int i = Methods.ExecuteNonQuery(sql, new SqlParameter("@ID", mp.Lname1), new SqlParameter("@passward", mp.Lpass1)); if (i != 0) { return(i); } else { return(0); } }
//插入用户 public static int insert_User(tb_UserInfo uer, int flag) { int i = 0; string sqL = "insert into Wm_Login values(@ID,@passward,@limite,@remarks)"; i = Methods.ExecuteNonQuery(sqL, new SqlParameter("@ID", uer.Lname1), new SqlParameter("@passward", uer.Lpass1), new SqlParameter("@limite", flag), new SqlParameter("@remarks", REMARKS[flag - 1])); if (i != 0) { return(i); } else { return(0); } }
public static int ExistCount(tb_UserInfo User)//判断查找的对象是否在数据库中 { string sql = "select * from Wm_Login where Lname=@userId and Lpass=@userpassword"; DataRow datarow = Methods.GetRow(sql, new SqlParameter("@userId", User.Lname1), new SqlParameter("@userpassword", User.Lpass1)); try { if (datarow != null) { object i = datarow["Llimit"]; if (i.Equals(1)) { return(1); } else if (i.Equals(2)) { return(2); } else if (i.Equals(3)) { return(3); } else if (i.Equals(4)) { return(4); } else if (i.Equals(5)) { return(5); } datarow.CancelEdit(); } return(-1);//用户名或者密码错误,或者不存在此用户; } catch (Exception ee) { System.Windows.Forms.MessageBox.Show(ee.ToString()); datarow.CancelEdit(); return(-1); } }