private void btnLogin_Click(object sender, RoutedEventArgs e) { //数据验证 if (txtLogId.Text.Trim().Length == 0) { MessageBox.Show("请输入登录账号!", "登录提示"); txtLogId.Focus(); return; } if (DataValidate.IsInteger(txtLogId.Text.Trim()) == false) { MessageBox.Show("请输入正确账号!(纯数字格式)", "登录提示"); txtLogId.Focus(); return; } if (txtLogPwd.Password.Length == 0) { MessageBox.Show("请输入登录密码!", "登录提示"); txtLogPwd.Focus(); return; } //输入的账号密码 Admins admin = new Admins() { LoginId = Convert.ToInt32(txtLogId.Text.Trim()), //LoginPwd = txtLogPwd.Password }; //和后台交互查询,判断登录信息是否正确 try { Admins mainuse = new AdminManager().GetAdmins(admin); if (mainuse == null) { MessageBox.Show("用户账号不存在!", "提示信息"); txtLogId.Focus(); } else { if (mainuse.LoginPwd == txtLogPwd.Password) { //保存登录信息 App.CurrentAdmin = mainuse; this.DialogResult = true; this.Close(); } else { MessageBox.Show("用户密码错误!", "提示信息"); txtLogPwd.Focus(); } } } catch (Exception ex) { MessageBox.Show("服务器连接异常,登录失败!请检查您的网络!"); } }
//登录 private void btnLogin_Click(object sender, EventArgs e) { //数据验证 if (this.txtLoginId.Text.Trim().Length == 0) { MessageBox.Show("请输入登录账号!", "登录提示"); this.txtLoginId.Focus(); return; } if (!DataValidate.IsInteger(this.txtLoginId.Text.Trim())) { MessageBox.Show("登录账号必须是正整数!", "登录提示"); this.txtLoginId.Focus(); this.txtLoginId.SelectAll(); return; } if (this.txtLoginPwd.Text.Trim().Length == 0) { MessageBox.Show("请输入登陆密码!", "登录提示"); this.txtLoginPwd.Focus(); return; } //封装用户信息到用户对象中 Admin objAdmin = new Admin() { LoginId = Convert.ToInt32(this.txtLoginId.Text.Trim()), LoginPwd = this.txtLoginPwd.Text.Trim() }; //提交用户信息 try { objAdmin = objAdminService.AdminLogin(objAdmin); if (objAdmin == null) { MessageBox.Show("用户名或密码错误!", "登录提示"); } else { Program.CurrentAdmin = objAdmin; //保存用户对象 this.DialogResult = DialogResult.OK; //设置登录成功信息提示 this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "登录失败!"); } }
//登录 private void btnLogin_Click(object sender, EventArgs e) { //数据验证 if (txtLoginId.Text.Trim().Length == 0) { MessageBox.Show("请输入登录账号!", "登录提示:"); txtLoginId.Focus(); return; } if (!DataValidate.IsInteger(txtLoginId.Text.Trim())) { MessageBox.Show("登录账号必须是正整数!", "登录提示:"); txtLoginId.Focus(); txtLoginId.SelectAll(); return; } if (txtLoginPwd.Text.Trim().Length == 0) { MessageBox.Show("请输入登录密码!", "登录提示:"); txtLoginPwd.Focus(); return; } //提交用户信息 Admin objAdmin = new Admin() { LoginId = Convert.ToInt32(txtLoginId.Text.Trim()), LoginPwd = txtLoginPwd.Text.Trim() }; try { objAdmin = adminService.AdminLogin(objAdmin); if (objAdmin == null) { MessageBox.Show("登陆账号或密码错误!", "登陆提示:"); } else { Program.currentAmin = objAdmin; //保存当前登陆用户 this.DialogResult = DialogResult.OK; //设置当前登陆成功 Close(); } } catch (Exception) { MessageBox.Show("登陆失败!", "登陆提示:"); } }
//根据C#成绩动态筛选 private void txtScore_TextChanged(object sender, EventArgs e) { if (ds == null || this.txtScore.Text.Trim().Length == 0) { return; } if (!DataValidate.IsInteger(this.txtScore.Text.Trim())) { return; } else { this.ds.Tables[0].DefaultView.RowFilter = "CSharp<" + this.txtScore.Text.Trim(); } }
//确认添加学员 private void BtnAdd_Click(object sender, EventArgs e) { #region 数据验证 if (this.txtStudentName.Text.Trim().Length == 0) { MessageBox.Show("姓名不能为空!", "提示信息"); this.txtStudentName.Focus(); return; } string gender = string.Empty; if (this.rdoMale.Checked == true) { gender = this.rdoMale.Text; } if (this.rdoFemale.Checked == true) { gender = this.rdoFemale.Text; } if (this.cboClassName.SelectedIndex == -1) { MessageBox.Show("请选择班级!", "提示信息"); return; } if (this.dtpBirthday.Value > DateTime.Now) { MessageBox.Show("出生日期不能大于当前时间!", "提示信息"); return; } //年龄验证:大于18而且小于30 //身份证日期与出生日期比较:对比出生日期与身份证的出生日期是否相同 //正则表达式验证身份证是否符合要求 if (!DataValidate.IsIdentityCard(this.txtStudentIdNo.Text)) { MessageBox.Show("身份证号格式错误!", "提示信息"); this.txtStudentIdNo.Focus(); return; } if (this.txtCardNo.Text.Trim().Length == 0) { MessageBox.Show("考勤卡号不能为空!", "提示信息"); this.txtStudentName.Focus(); return; } if (this.txtPhoneNumber.Text.Trim().Length != 11) { MessageBox.Show("电话号码格式错误!", "提示信息"); this.txtPhoneNumber.Focus(); return; } //验证身份证号是否重复 if (studentService.IsIdNoExisten(this.txtStudentIdNo.Text)) { MessageBox.Show("身份证号码重复,请确认!", "提示信息"); this.txtStudentIdNo.Focus(); this.txtStudentIdNo.SelectAll(); return; } #endregion #region 封装数据 Students student = new Students { StudentName = this.txtStudentName.Text.Trim(), Gender = gender, Birthday = this.dtpBirthday.Value, StudentIdNo = this.txtStudentIdNo.Text.Trim(), Age = DateTime.Now.Year - this.dtpBirthday.Value.Year, PhoneNumber = this.txtPhoneNumber.Text.Trim(), StudentAddress = this.txtAddress.Text.Trim(), CardNo = this.txtCardNo.Text.Trim(), ClassId = Convert.ToInt32(this.cboClassName.SelectedValue), }; #endregion #region 调用后台 try { var result = studentService.AddStudent(student); if (result == 1) { DialogResult dialogResult = MessageBox.Show("学员添加成功,是否继续添加?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { this.cboClassName.SelectedIndex = -1; this.rdoFemale.Checked = false; this.rdoMale.Checked = false; //清空所有文本框 foreach (Control item in this.Controls) { if (item is TextBox) { item.Text = ""; } } this.txtStudentName.Focus(); } } else { this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } #endregion }
//提交修改 private void btnModify_Click(object sender, EventArgs e) { //数据验证 if (this.txtStudentName.Text.Trim().Length == 0) { MessageBox.Show("学生姓名不能为空", "提示信息"); this.txtStudentName.Focus(); return; } if (!this.rdoMale.Checked && !this.rdoFemale.Checked) { MessageBox.Show("请选择性别", "验证提示"); return; } if ((DateTime.Now.Year - Convert.ToDateTime(this.dtpBirthday.Text).Year) < 16) { MessageBox.Show("学生年龄不得小于16,请重新选择", "验证提示"); return; } if (this.cboClassName.SelectedIndex == -1) { MessageBox.Show("请选择班级", "验证提示"); return; } //if (this.txtStudentIdNo.Text.Trim().Length == 0) //{ // MessageBox.Show("请输入身份证号", "验证提示"); // this.txtStudentIdNo.Focus(); // return; //} //if (this.txtCardNo.Text.Trim().Length == 0) //{ // MessageBox.Show("卡号不得为空", "验证提示"); // this.txtCardNo.Focus(); // return; //} //验证身份证号格式是否符合要求 if (!DataValidate.IsIdentityCard(this.txtStudentIdNo.Text.Trim())) { MessageBox.Show("身份证格式不正确,请重新输入", "验证提示"); this.txtStudentIdNo.Focus(); return; } //验证身份证号是否重复 if (objStudentService.IsIdNoExisted(this.txtStudentIdNo.Text.Trim(), this.txtStudentId.Text.Trim())) { MessageBox.Show("身份证号不能和现有学员身份证号相重复", "验证提示"); this.txtStudentIdNo.Focus(); this.txtStudentIdNo.SelectAll(); return; } //验证身份证号是否和出生日期相吻合 string month = string.Empty; string day = string.Empty; if (Convert.ToDateTime(this.dtpBirthday.Text).Month < 10) { month = "0" + Convert.ToDateTime(this.dtpBirthday.Text).Month; } else { month = Convert.ToDateTime(this.dtpBirthday.Text).Month.ToString(); } if (Convert.ToDateTime(this.dtpBirthday.Text).Day < 10) { day = "0" + Convert.ToDateTime(this.dtpBirthday.Text).Day; } else { day = Convert.ToDateTime(this.dtpBirthday.Text).Day.ToString(); } string birthday = Convert.ToDateTime(this.dtpBirthday.Text).Year.ToString() + month + day; if (!this.txtStudentIdNo.Text.Trim().Contains(birthday)) { MessageBox.Show("身份证号和出生日期不匹配", "验证提示"); this.txtStudentIdNo.Focus(); this.txtStudentIdNo.SelectAll(); return; } //// ? 判断身份证号是否已经存在 //if (this.objStudentService.IsIDCardExisted(this.txtStudentIdNo.Text.Trim())) //{ // MessageBox.Show("身份证号已存在", "验证提示"); // this.txtStudentIdNo.Focus(); // this.txtStudentIdNo.SelectAll(); // return; //} //判断学号是否已经存在 //if (this.objStudentService.IsCardNoExisted(this.txtCardNo.Text.Trim())) //{ // MessageBox.Show("学号已存在", "验证提示"); // this.txtCardNo.Focus(); // this.txtCardNo.SelectAll(); // return; //} //封装学生对象 Student objStudent = new Student() { StudentName = this.txtStudentName.Text.Trim(), Gender = this.rdoMale.Checked ? "男" : "女", Birthday = Convert.ToDateTime(this.dtpBirthday.Text), Age = DateTime.Now.Year - Convert.ToDateTime(this.dtpBirthday.Text).Year, ClassId = Convert.ToInt32(this.cboClassName.SelectedValue), StudentIdNo = this.txtStudentIdNo.Text.Trim(), CardNo = this.txtCardNo.Text.Trim(), PhoneNumber = this.txtPhoneNumber.Text.Trim(), StudentAddress = this.txtAddress.Text.Trim() == ""?"地址不详":this.txtAddress.Text.Trim(), StudentId = Convert.ToInt32(this.txtStudentId.Text.Trim()), StuImage = this.pbStu.Image == null ? new SerializeObjectToString().SerializeObject(this.pbStu.Image) :"" }; //提交对象 try { if (objStudentService.ModifyStudent(objStudent) == 1) { MessageBox.Show("学员信息修改成功", "提示信息"); this.DialogResult = DialogResult.OK; this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//添加新学员 private void btnAdd_Click(object sender, EventArgs e) { //数据验证 if (txtStudentName.Text.Trim().Length == 0) { MessageBox.Show("请填写学员姓名!", "验证提示:"); txtStudentName.Focus(); return; } if (!rdoFemale.Checked && !rdoMale.Checked) { MessageBox.Show("请选择学员性别!", "验证提示:"); return; } if ((DateTime.Now.Year - Convert.ToDateTime(dtpBirthday.Text).Year) < 18) { MessageBox.Show("学员年龄不能小于18岁,请修改出生日期!", "验证提示:"); dtpBirthday.Focus(); return; } if (cboClassName.SelectedIndex == -1) { MessageBox.Show("请选择学员班级!", "验证提示:"); cboClassName.Focus(); return; } if (txtStudentIdNo.Text.Trim().Length < 18) { MessageBox.Show("学员身份证号不正确,不够18位!", "验证提示:"); txtStudentIdNo.Focus(); txtStudentIdNo.SelectAll(); return; } if (!DataValidate.IsIdentityCard(txtStudentIdNo.Text.Trim())) { MessageBox.Show("学员身份证号不正确!", "验证提示:"); txtStudentIdNo.Focus(); txtStudentIdNo.SelectAll(); return; } //验证身份证号与出生日期相吻合 string month = string.Empty; string day = string.Empty; if (Convert.ToDateTime(dtpBirthday.Text).Month < 10) { month = "0" + Convert.ToDateTime(dtpBirthday.Text).Month; } else { month = Convert.ToDateTime(dtpBirthday.Text).Month.ToString(); } if (Convert.ToDateTime(dtpBirthday.Text).Day < 10) { day = "0" + Convert.ToDateTime(dtpBirthday.Text).Day; } else { day = Convert.ToDateTime(dtpBirthday.Text).Day.ToString(); } string birthDay = Convert.ToDateTime(dtpBirthday.Text).Year + month + day; if (!txtStudentIdNo.Text.Trim().Contains(birthDay)) { MessageBox.Show("学员身份证号与出生日期不匹配!", "验证提示:"); txtStudentIdNo.Focus(); txtStudentIdNo.SelectAll(); return; } //验证学生身份证是否重复 if (objStudnetService.IsIDCardExisted(txtStudentIdNo.Text.Trim())) { MessageBox.Show("学员身份证号有重复!", "验证提示:"); txtStudentIdNo.Focus(); txtStudentIdNo.SelectAll(); return; } if (txtCardNo.Text.Trim().Length == 0) { MessageBox.Show("请输入学员卡号!", "验证提示:"); txtCardNo.Focus(); return; } //验证学生卡号是否重复 if (objStudnetService.IsCardExisted(txtCardNo.Text.Trim())) { MessageBox.Show("学员卡号有重复!", "验证提示:"); txtCardNo.Focus(); txtCardNo.SelectAll(); return; } //封装学生信息 Student student = new Student() { StudentName = txtStudentName.Text.Trim(), Gender = rdoMale.Checked ? "男" : "女", Birthday = Convert.ToDateTime(dtpBirthday.Text), Age = DateTime.Now.Year - Convert.ToDateTime(dtpBirthday.Text).Year, ClassId = Convert.ToInt32(cboClassName.SelectedValue), StudentIdNo = txtStudentIdNo.Text.Trim(), CardNo = txtCardNo.Text.Trim(), PhoneNumber = txtPhoneNumber.Text.Trim(), StudentAddress = txtAddress.Text.Trim(), StuImage = pbStu.Image == null?"":new SerializeObjectToString().SerializeObject(pbStu.Image) }; //提交对象 try { int objAdd = objStudnetService.AddStudent(student); //判断是否保存成功 if (objAdd > 0) { DialogResult result = MessageBox.Show("学员添加成功!是否继续添加?", "添加提示:", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { foreach (Control item in gbStudent.Controls) { if (item is TextBox) { item.Text = ""; } else if (item is RadioButton) { ((RadioButton)item).Checked = false; } else if (item is ComboBox) { ((ComboBox)item).SelectedIndex = -1; } } pbStu.Image = null; dtpBirthday.Text = DateTime.Now.ToString(); } else { Close(); } } else { MessageBox.Show("添加失败!", "添加提示:"); } } catch (Exception ex) { MessageBox.Show("添加失败" + ex.Message); } }
//添加新学员 private void btnAdd_Click(object sender, EventArgs e) { //数据验证 if (this.txtStudentName.Text.Trim().Length == 0) { MessageBox.Show("请输入学生姓名", "验证提示"); this.txtStudentName.Focus(); return; } if (!this.rdoMale.Checked && !this.rdoFemale.Checked) { MessageBox.Show("请选择性别", "验证提示"); return; } if ((DateTime.Now.Year - Convert.ToDateTime(this.dtpBirthday.Text).Year) < 16) { MessageBox.Show("学生年龄不得小于16,请重新选择", "验证提示"); this.dtpBirthday.Focus(); return; } if (this.cboClassName.SelectedIndex == -1) { MessageBox.Show("请选择班级", "验证提示"); return; } if (this.txtStudentIdNo.Text.Trim().Length == 0) { MessageBox.Show("请输入身份证号", "验证提示"); this.txtStudentIdNo.Focus(); return; } if (this.txtCardNo.Text.Trim().Length == 0) { MessageBox.Show("卡号不得为空", "验证提示"); this.txtCardNo.Focus(); return; } //验证身份证号格式是否符合要求 if (!DataValidate.IsIdentityCard(this.txtStudentIdNo.Text.Trim())) { MessageBox.Show("身份证格式不正确,请重新输入", "验证提示"); this.txtStudentIdNo.Focus(); this.txtStudentIdNo.SelectAll(); return; } //验证身份证号是否和出生日期相吻合 string month = string.Empty; string day = string.Empty; if (Convert.ToDateTime(this.dtpBirthday.Text).Month < 10) { month = "0" + Convert.ToDateTime(this.dtpBirthday.Text).Month; } else { month = Convert.ToDateTime(this.dtpBirthday.Text).Month.ToString(); } if (Convert.ToDateTime(this.dtpBirthday.Text).Day < 10) { day = "0" + Convert.ToDateTime(this.dtpBirthday.Text).Day; } else { day = Convert.ToDateTime(this.dtpBirthday.Text).Day.ToString(); } string birthday = Convert.ToDateTime(this.dtpBirthday.Text).Year.ToString() + month + day; if (!this.txtStudentIdNo.Text.Trim().Contains(birthday)) { MessageBox.Show("身份证号和出生日期不匹配", "验证提示"); this.txtStudentIdNo.Focus(); this.txtStudentIdNo.SelectAll(); return; } //判断身份证号是否已经存在 if (this.objStudentService.IsIDCardExisted(this.txtStudentIdNo.Text.Trim())) { MessageBox.Show("身份证号已存在", "验证提示"); this.txtStudentIdNo.Focus(); this.txtStudentIdNo.SelectAll(); return; } //判断学号是否已经存在 if (this.objStudentService.IsCardNoExisted(this.txtCardNo.Text.Trim())) { MessageBox.Show("学号已存在", "验证提示"); this.txtCardNo.Focus(); this.txtCardNo.SelectAll(); return; } //封装学员对象 Student objStudent = new Student() { StudentName = this.txtStudentName.Text.Trim(), Gender = this.rdoMale.Checked ? "男" : "女", Birthday = Convert.ToDateTime(this.dtpBirthday.Text), Age = DateTime.Now.Year - Convert.ToDateTime(this.dtpBirthday.Text).Year, ClassId = Convert.ToInt32(this.cboClassName.SelectedValue), StudentIdNo = this.txtStudentIdNo.Text.Trim(), CardNo = this.txtCardNo.Text.Trim(), PhoneNumber = this.txtPhoneNumber.Text.Trim(), StudentAddress = this.txtAddress.Text.Trim(), StuImage = this.pbStu.Image == null?"":new SerializeObjectToString().SerializeObject(this.pbStu.Image) }; //提交对象 try { int result = objStudentService.AddStudent(objStudent); if (result == 1) { DialogResult dresult = MessageBox.Show("添加成功,是否继续添加", "添加询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dresult == DialogResult.OK) { //清空当前文本框 foreach (Control item in gbStuInfo.Controls) { if (item is TextBox) { item.Text = ""; } else if (item is RadioButton) { ((RadioButton)item).Checked = false; } else if (item is ComboBox) { ((ComboBox)item).SelectedIndex = -1; } } this.pbStu.Image = null; this.txtStudentName.Focus(); } } else { MessageBox.Show("添加失败", "添加提示"); } } catch (Exception ex) { MessageBox.Show(ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } //判断是否保存成功 }
//提交修改 private void btnModify_Click(object sender, EventArgs e) { //数据验证 if (txtStudentName.Text.Trim().Length == 0) { MessageBox.Show("请填写学员姓名!", "验证提示:"); txtStudentName.Focus(); return; } if (!rdoFemale.Checked && !rdoMale.Checked) { MessageBox.Show("请选择学员性别!", "验证提示:"); return; } if ((DateTime.Now.Year - Convert.ToDateTime(dtpBirthday.Text).Year) < 18) { MessageBox.Show("学员年龄不能小于18岁,请修改出生日期!", "验证提示:"); dtpBirthday.Focus(); return; } if (cboClassName.SelectedIndex == -1) { MessageBox.Show("请选择学员班级!", "验证提示:"); cboClassName.Focus(); return; } if (txtStudentIdNo.Text.Trim().Length < 18) { MessageBox.Show("学员身份证号不正确,不够18位!", "验证提示:"); txtStudentIdNo.Focus(); txtStudentIdNo.SelectAll(); return; } if (!DataValidate.IsIdentityCard(txtStudentIdNo.Text.Trim())) { MessageBox.Show("学员身份证号不正确!", "验证提示:"); txtStudentIdNo.Focus(); txtStudentIdNo.SelectAll(); return; } //验证身份证号与出生日期相吻合 string month = string.Empty; string day = string.Empty; if (Convert.ToDateTime(dtpBirthday.Text).Month < 10) { month = "0" + Convert.ToDateTime(dtpBirthday.Text).Month; } else { month = Convert.ToDateTime(dtpBirthday.Text).Month.ToString(); } if (Convert.ToDateTime(dtpBirthday.Text).Day < 10) { day = "0" + Convert.ToDateTime(dtpBirthday.Text).Day; } else { day = Convert.ToDateTime(dtpBirthday.Text).Day.ToString(); } string birthDay = Convert.ToDateTime(dtpBirthday.Text).Year + month + day; if (!txtStudentIdNo.Text.Trim().Contains(birthDay)) { MessageBox.Show("学员身份证号与出生日期不匹配!", "验证提示:"); txtStudentIdNo.Focus(); txtStudentIdNo.SelectAll(); return; } //验证学生身份证是否重复 if (objStudnetservice.IsIDCardExisted(txtStudentIdNo.Text.Trim(), txtStudentId.Text.Trim())) { MessageBox.Show("学员身份证号有重复!", "验证提示:"); txtStudentIdNo.Focus(); txtStudentIdNo.SelectAll(); return; } if (txtCardNo.Text.Trim().Length == 0) { MessageBox.Show("请输入学员卡号!", "验证提示:"); txtCardNo.Focus(); return; } //验证学生卡号是否重复 if (objStudnetservice.IsCardExisted(txtCardNo.Text.Trim(), txtStudentId.Text.Trim())) { MessageBox.Show("学员卡号有重复!", "验证提示:"); txtCardNo.Focus(); txtCardNo.SelectAll(); return; } //封装学生信息 Student student = new Student() { StudentName = txtStudentName.Text.Trim(), Gender = rdoMale.Checked ? "男" : "女", Birthday = Convert.ToDateTime(dtpBirthday.Text), Age = DateTime.Now.Year - Convert.ToDateTime(dtpBirthday.Text).Year, ClassId = Convert.ToInt32(cboClassName.SelectedValue), StudentIdNo = txtStudentIdNo.Text.Trim(), CardNo = txtCardNo.Text.Trim(), PhoneNumber = txtPhoneNumber.Text.Trim(), StudentAddress = txtAddress.Text.Trim(), StudentId = Convert.ToInt32(txtStudentId.Text.Trim()), StuImage = pbStu.Image == null ? "" : new SerializeObjectToString().SerializeObject(pbStu.Image) }; //提交对象 try { //判断是否保存成功 if (objStudnetservice.ModifyStudent(student)) { MessageBox.Show("学员修改成功!", "修改提示:"); Close(); } else { MessageBox.Show("修改失败!", "修改提示:"); } } catch (Exception ex) { MessageBox.Show("修改失败" + ex.Message); } }