private void button2_Click(object sender, EventArgs e) { string strName = ""; string strPawword = ""; lbMessage.Text = ""; // 校验 if (username.Text.Trim() == "") { lbMessage.Text = "用户名不能为空!"; //MessageBox.Show("学号不能为空!"); username.Focus(); return; } if (password.Text.Trim() == "") { MessageBox.Show("密码不能为空!"); password.Focus(); return; } // 获取数据 strName = username.Text.Trim(); strPawword = password.Text.Trim(); DBCL.mange model = new DBCL.mange(); try { if (db.manges.Any(m => m.user_name == strName) == false) { MessageBox.Show("用户名不存在!"); } else if (db.manges.Any(m => m.user_password == strPawword) == false) { MessageBox.Show("密码错误!"); } else { MessageBox.Show("登陆成功!"); this.Hide(); Main frmMain = new Main(); frmMain.Show(); } } catch { MessageBox.Show("登录失败!"); } }
private void btYes_Click(object sender, EventArgs e) { string strName = ""; string strPawword = ""; string strPhone = ""; string strType = ""; string strEmail = ""; lbMessage1.Text = ""; lbMessage2.Text = ""; lbMessage3.Text = ""; lbMessage4.Text = ""; lbMessage5.Text = ""; lbMessage6.Text = ""; // 校验 if (texUsername.Text.Trim() == "") { lbMessage1.Text = "用户名不能为空!"; texUsername.Focus(); return; } if (texPassword.Text.Trim() == "") { lbMessage2.Text = "密码不能为空!"; texPassword.Focus(); return; } if (texPhone.Text.Trim() == "") { lbMessage4.Text = "手机号不能为空!"; texPhone.Focus(); return; } if (tbEmail.Text.Trim() == "") { lbMessage5.Text = "邮箱不能为空!"; tbEmail.Focus(); return; } if (texType.Text.Trim() == "") { lbMessage6.Text = "用户类型不能为空!"; texType.Focus(); return; } if (texPassword.Text.Trim() != texPassword1.Text.Trim()) { lbMessage3.Text = "两次密码不同!"; texPhone.Focus(); return; } // 获取数据 strName = texUsername.Text.Trim(); strPawword = texPassword.Text.Trim(); strPhone = texPhone.Text.Trim(); strType = texType.Text.Trim(); strEmail = tbEmail.Text.Trim(); // 检验学号是否重复 if (db.manges.Any(m => m.user_name == strName) == true) { MessageBox.Show("用户名重复!"); texUsername.Focus(); return; } DBCL.mange mode1 = new DBCL.mange(); mode1.user_name = strName; mode1.user_password = strPawword; mode1.user_phone = strPhone; mode1.user_type = strType; mode1.user_email = strEmail; try { db.manges.Add(mode1); db.SaveChanges(); } catch { MessageBox.Show("注册失败!"); return; } MessageBox.Show("注册成功,欢迎使用!"); this.Close(); login frmMain = new login(); frmMain.Show(); }