Esempio n. 1
0
        //成绩快速浏览:txt=>change事件
        private void TxtScore_TextChanged(object sender, EventArgs e)
        {
            if (this.dgvScoreList.RowCount == 0)
            {
                return;
            }

            if (this.txtScore.Text.Trim().Length == 0)
            {
                return;
            }

            if (!DataValidate.IsInteger(this.txtScore.Text.Trim()))
            {
                this.txtScore.Text = "";
                this.txtScore.SelectAll();
                MessageBox.Show("成绩只能为整数!", "提示信息");
                return;
            }

            this.cboClass.SelectedIndex = -1;
            var item  = this.txtScore.Text.Trim();
            int score = Convert.ToInt32(item);

            if (score > 100 || score < 0)
            {
                this.txtScore.Text = "";
                this.txtScore.SelectAll();
                MessageBox.Show("成绩只能在0-100之间!", "提示信息");
                return;
            }
            this.da.Tables[0].DefaultView.RowFilter = "CSharp>" + this.txtScore.Text.Trim();
        }
Esempio n. 2
0
        private void BtnQueryById_Click(object sender, EventArgs e)
        {
            if (this.txtStudentId.Text.Trim().Length == 0)
            {
                MessageBox.Show("请输入学员学号", "提示信息");
                return;
            }
            if (!DataValidate.IsInteger(this.txtStudentId.Text.Trim()))
            {
                MessageBox.Show("学号必须为整数!", "提示信息");
                this.txtStudentId.Focus();
                this.txtStudentId.SelectAll();
                return;
            }
            int studentId   = Convert.ToInt32(this.txtStudentId.Text.Trim());
            var studentInfo = studentService.GetStudebntByStudentId(studentId);

            if (studentInfo == null)
            {
                MessageBox.Show("学员学号错误,暂无此学员!", "提示信息");
                return;
            }

            if (frmStudentInfo == null)
            {
                frmStudentInfo = new FrmStudentInfo(studentInfo);
                frmStudentInfo.ShowDialog();
            }
            else
            {
                frmStudentInfo.Activate();
                frmStudentInfo.WindowState = FormWindowState.Normal;
            }
        }
Esempio n. 3
0
 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();
     }
 }
Esempio n. 4
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            #region Data Not Empty Validate

            if (this.txtFName.Text.Trim().Length == 0)
            {
                MessageBox.Show("Please entry the Student First Name");
                this.txtFName.Focus();
                return;
            }
            if (this.txtLName.Text.Trim().Length == 0)
            {
                MessageBox.Show("Please entry the Student Last Name");
                this.txtLName.Focus();
                return;
            }
            if (!this.rdoMale.Checked && !this.rdoFemale.Checked)
            {
                MessageBox.Show("Select the Student Gender");
                return;
            }
            if (DateTime.Now.Year - Convert.ToDateTime(this.dateTimePicker1.Text).Year < 16)
            {
                MessageBox.Show("Student age cant beyond  16");
                this.dateTimePicker1.Focus();
                return;
            }
            if (this.cboClassName.SelectedIndex == -1)
            {
                MessageBox.Show("Please select the Class !");

                return;
            }
            if (this.txtStudentId.Text.Trim().Length == 0)
            {
                MessageBox.Show("Student ID can't  empty");
                this.txtStudentId.Focus();
                return;
            }
            if (this.txtPhoneNumber.Text.Trim().Length == 0)
            {
                MessageBox.Show("PhoneNumber can't  empty");
                this.txtPhoneNumber.Focus();
                return;
            }


            #endregion
            #region Data Format Validate
            if (!DataValidate.IsIdentityStudentID(this.txtStudentId.Text.Trim()))
            {
                MessageBox.Show("StudentId Must have 10 figures");
                this.txtStudentId.Focus();
                return;
            }

            #endregion

            //Judge the StudentIsExisted

            if (this.objStudentService.IsStudentIDExitsed(this.txtStudentId.Text.Trim()))
            {
                MessageBox.Show("StudentId Existed ,Please entry different StudentId ");
                this.txtStudentId.Focus();
                return;
            }


            //encapsulation

            Student objStudent = new Student()
            {
                FirstName   = this.txtFName.Text.Trim(),
                LastName    = this.txtLName.Text.Trim(),
                Gender      = rdoMale.Checked ? "Male" : "Female",
                Birthday    = Convert.ToDateTime(this.dateTimePicker1.Text),
                Age         = DateTime.Now.Year - Convert.ToDateTime(this.dateTimePicker1.Text).Year,
                ClassId     = Convert.ToInt32(this.cboClassName.SelectedValue),
                StudentIdNo = Convert.ToInt32(this.txtStudentId.Text.Trim()),
                PhoneNumber = this.txtPhoneNumber.Text.Trim(),
                Address     = 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("Add Successful ! keep going ?", "other Studnet ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (dresult == DialogResult.OK)
                    {
                        //clean controls in groupbox
                        foreach (Control item in this.gbStudentInfo.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;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 5
0
        //提交修改
        private void BtnModify_Click(object sender, EventArgs e)
        {
            #region 数据验证
            if (this.txtStudentName.Text.Trim().Length == 0)
            {
                MessageBox.Show("学生姓名不能为空!", "提示信息");
                return;
            }

            var age = DateTime.Now.Year - Convert.ToDateTime(this.dtpBirthday.Text).Year;

            if (age < 18 || age > 35)
            {
                MessageBox.Show("年龄必须在18到35之间!", "提示信息");
                return;
            }

            if (!DataValidate.IsIdentityCard(this.txtStudentIdNo.Text.Trim()))
            {
                MessageBox.Show("身份证号不符合要求!", "提示信息");
                this.txtStudentIdNo.SelectAll();
                this.txtStudentIdNo.Focus();
                return;
            }

            //验证身份证号与出生日期是否一致
            var birthday = Convert.ToDateTime(this.dtpBirthday.Text).ToString("yyyyMMdd");
            if (!this.txtStudentIdNo.Text.Trim().Contains(birthday))
            {
                MessageBox.Show("身份证与出生日期不匹配!", "提示信息");
                this.txtStudentIdNo.SelectAll();
                this.txtStudentIdNo.Focus();
                return;
            }

            var studentId = Convert.ToInt32(this.txtStudentId.Text.Trim());
            if (studentService.IsIdNoExisted(this.txtStudentIdNo.Text.Trim(), studentId))
            {
                MessageBox.Show("身份证号已经被其他学员使用!", "修改提示");
                this.txtStudentIdNo.SelectAll();
                this.txtStudentIdNo.Focus();
                return;
            }

            if (studentService.IsCradNoExisted(this.txtCardNo.Text.Trim(), studentId))
            {
                MessageBox.Show("考勤卡号已经被其他学员使用!", "修改提示");
                this.txtCardNo.SelectAll();
                this.txtCardNo.Focus();
                return;
            }
            #endregion

            Students student = new Students
            {
                StudentId                                          = studentId,
                StudentName                                        = this.txtStudentName.Text.Trim(),
                Gender                                             = this.rdoMale.Checked?"男":"女",
                Birthday                                           = Convert.ToDateTime(this.dtpBirthday.Text),
                StudentIdNo                                        = this.txtStudentIdNo.Text.Trim(),
                CardNo                                             = this.txtCardNo.Text.Trim(),
                StuImage                                           = this.pbStu.Image != null?SerializeObjectToString.SerializeObject(this.pbStu.Image) : "",
                                                    Age            = age,
                                                    PhoneNumber    = this.txtPhoneNumber.Text.Trim(),
                                                    StudentAddress = this.txtAddress.Text.Trim(),
                                                    ClassId        = Convert.ToInt32(this.cboClassName.SelectedValue),
            };

            try
            {
                var result = studentService.UpdateStudentInfo(student);
                if (result == 1)
                {
                    MessageBox.Show("学员信息修改成功!", "提示信息");

                    var item = FrmStudentManage.studentList.First(o => o.StudentId == studentId);
                    item.StudentName = this.txtStudentName.Text.Trim();
                    item.Gender      = this.rdoMale.Checked ? "男" : "女";
                    item.StudentIdNo = this.txtStudentIdNo.Text;
                    item.Birthday    = this.dtpBirthday.Value;
                    item.PhoneNumber = this.txtPhoneNumber.Text;
                    item.ClassName   = this.cboClassName.Text;
                    //this.dgvStudentList.Refresh();


                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示信息");
            }
        }
Esempio n. 6
0
        //添加学员
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            #region 数据验证
            if (this.txtStudentName.Text.Trim().Length == 0)
            {
                MessageBox.Show("学生姓名不能为空!", "提示信息");
                return;
            }

            if (this.rdoFemale.Checked == false && this.rdoMale.Checked == false)
            {
                MessageBox.Show("请选择性别!", "提示信息");
                return;
            }

            if (this.cboClassName.SelectedIndex == -1)
            {
                MessageBox.Show("请选择班级!", "提示信息");
                return;
            }

            var age = DateTime.Now.Year - Convert.ToDateTime(this.dtpBirthday.Text).Year;

            if (age < 18 || age > 35)
            {
                MessageBox.Show("年龄必须在18到35之间!", "提示信息");
                return;
            }

            if (!DataValidate.IsIdentityCard(this.txtStudentIdNo.Text.Trim()))
            {
                MessageBox.Show("身份证号不符合要求!", "提示信息");
                this.txtStudentIdNo.SelectAll();
                this.txtStudentIdNo.Focus();
                return;
            }

            //验证身份证号与出生日期是否一致
            var birthday = Convert.ToDateTime(this.dtpBirthday.Text).ToString("yyyyMMdd");
            if (!this.txtStudentIdNo.Text.Trim().Contains(birthday))
            {
                MessageBox.Show("身份证与出生日期不匹配!", "提示信息");
                this.txtStudentIdNo.SelectAll();
                this.txtStudentIdNo.Focus();
                return;
            }

            if (studentService.IsIdNoExisted(this.txtStudentIdNo.Text.Trim()))
            {
                MessageBox.Show("身份证号已经被其他学员使用!", "提示信息");
                this.txtStudentIdNo.SelectAll();
                this.txtStudentIdNo.Focus();
                return;
            }

            if (studentService.IsCradNoExisted(this.txtCardNo.Text.Trim()))
            {
                MessageBox.Show("考勤卡号已经被其他学员使用!", "提示信息");
                this.txtCardNo.SelectAll();
                this.txtCardNo.Focus();
                return;
            }



            #endregion

            #region 对象封装
            Students student = new Students
            {
                StudentName                                        = this.txtStudentName.Text.Trim(),
                Gender                                             = this.rdoFemale.Checked ? "女" : "男",
                Birthday                                           = Convert.ToDateTime(this.dtpBirthday.Text),
                StudentIdNo                                        = this.txtStudentIdNo.Text.Trim(),
                StuImage                                           = this.pbStu.Image != null?SerializeObjectToString.SerializeObject(this.pbStu.Image) : "",
                                                    Age            = age,
                                                    CardNo         = this.txtCardNo.Text.Trim(),
                                                    PhoneNumber    = this.txtPhoneNumber.Text.Trim(),
                                                    StudentAddress = this.txtAddress.Text.Trim(),
                                                    StudentId      = Convert.ToInt32(this.cboClassName.SelectedValue),
                                                    ClassId        = Convert.ToInt32(this.cboClassName.SelectedValue)
            };
            #endregion

            #region 后台调用
            try
            {
                var studenteId = studentService.AddNewStudent(student);
                if (studenteId == 1)
                {
                    student.ClassId = studenteId;
                    studentList.Add(student);
                    this.dgvStudentList.DataSource = null;
                    this.dgvStudentList.DataSource = studentList;
                    #region endregion询问是否继续添加
                    DialogResult result = MessageBox.Show("学员添加成功,是否继续添加?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        //清空数据
                        foreach (Control item in this.gbstuinfo.Controls)
                        {
                            if (item is TextBox)
                            {
                                item.Text = string.Empty;
                            }
                        }
                        this.cboClassName.SelectedIndex = -1;
                        this.rdoFemale.Checked          = false;
                        this.rdoMale.Checked            = false;
                        this.pbStu.Image = null;
                        this.txtStudentName.Focus();
                    }
                    else
                    {
                        this.Close();
                    }
                    # endregion
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("添加学员出现访问异常:" + ex.Message);
            }
            #endregion
        }