private void buttonAdd_Click(object sender, EventArgs e)
 {
     if (EmptyCheck())
     {
         MessageBox.Show("All fields should be filled properly", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else if (DoValidation())
     {
         var student = new StudentViewModel
         {
             Name             = textBoxStudentName.Text,
             FatherName       = textBoxFatherName.Text,
             MotherName       = textBoxMotherName.Text,
             FatherProfession = textBoxFatherProfession.Text,
             MotherProfession = textBoxMotherProfession.Text,
             Email            = textBoxEmail.Text,
             Religion         = textBoxReligion.Text,
             Phone            = textBoxPhone.Text,
             DateOfBirth      = DateTime.Parse(dateTimePickerBirthDate.Text),
             GenderId         = GetSelectedGenderId(),
             IsActive         = checkBoxIsActive.Checked,
             BloodGroupId     = (int)comboBoxBloodGroup.SelectedValue == -1 ? (int?)null : (int)comboBoxBloodGroup.SelectedValue,
             Address          = richTextBoxAddress.Text,
             ClassId          = (int)comboBoxClass.SelectedValue,
             SectionId        = (int)comboBoxSection.SelectedValue,
             RollNumber       = int.Parse(textBoxRollNumber.Text),
             StatusId         = (int)comboBoxStatus.SelectedValue
         };
         if (_studentService.AddNewStudent(student))
         {
             gridViewSelectedId = student.Id.ToString();
             comboBoxLoadClass.SelectedValue   = student.ClassId;
             comboBoxLoadSection.SelectedValue = student.SectionId;
             buttonLoad.PerformClick();
             //LoadDataStudent(_studentService.GetStudentListByClassSection((int)comboBoxLoadSection.SelectedValue));
             //dataGridView1.Refresh();
             MessageBox.Show("Data Saved Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             MessageBox.Show("error");
         }
     }
     else
     {
         if (ErrorList.Count == 0)
         {
             MessageBox.Show("All fields should be filled properly", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             MessageBox.Show(ErrorList.First(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             ErrorList.Clear();
         }
     }
     ErrorMessage = "";
 }
Beispiel #2
0
 public ActionResult Create(Student student)
 {
     if (ModelState.IsValid)
     {
         studentService.AddNewStudent(student);
         return(RedirectToAction("Show"));
     }
     return(View("Create"));
 }
Beispiel #3
0
 public ActionResult Create(StudentViewModel student)
 {
     try
     {
         StudentService.AddNewStudent(student);
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         ViewBag.error = ex.Message;
         return(View());
     }
 }
Beispiel #4
0
        public static void Main()
        {
            IUnitOfWork        unitOfWork        = new UnitOfWork();
            IStudentRepository studentRepository = new StudentRepository(unitOfWork);
            IStudentService    studentService    = new StudentService(studentRepository);

            Student student = new Student {
                FirstName = "Pesho", LastName = "Peshov"
            };

            studentService.AddNewStudent(student);

            studentService.SaveChanges();
        }
Beispiel #5
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
        }