private void NEditStudentBtn_Click(object sender, EventArgs e)
        {
            this.Hide();
            StudentList slist = new StudentList();

            slist.ShowDialog();
        }
Exemple #2
0
        private void Update()
        {
            student1.SNAME = txtName.Text.Trim();

            student1.SADDRESS   = txtAddress.Text.Trim();
            student1.SEMAIL     = txtEmail.Text.Trim();
            student1.SGDNAME    = txtGDName.Text.Trim();
            student1.SGDCONTACT = txtGDContact.Text.Trim();
            student1.SDOB       = dateTimePickerDOB.Value;
            student1.Grade      = comboBoxGrade.Text.Trim();
            student1.ClassName  = comboBoxClass.Text.Trim();

            using (SchoolManagementSystemDBEntities db = new SchoolManagementSystemDBEntities())
            {
                if (student1.SID == 0)
                {
                    db.Students.Add(student1);
                }

                else
                {
                    db.Entry(student1).State = EntityState.Modified;
                }

                db.SaveChanges();
            }
            MessageBox.Show("Student Details Updated Sucessfully");
            this.Hide();
            StudentList slist = new StudentList();

            slist.ShowDialog();
        }
Exemple #3
0
        private void Save()
        {
            try
            {
                var student = new StudentModel()
                {
                    SName      = txtName.Text.Trim(),
                    SEmail     = txtEmail.Text.Trim(),
                    SAddress   = txtAddress.Text.Trim(),
                    SGDName    = txtGDName.Text.Trim(),
                    SGDContact = txtGDContact.Text.Trim(),
                    SDob       = dateTimePickerDOB.Value,
                    SGender    = gender,
                    SGrade     = comboBoxGrade.Text.Trim(),
                    SClass     = comboBoxClass.Text.Trim()
                };

                ValidationContext context = new ValidationContext(student);

                List <ValidationResult> errorList = new List <ValidationResult>();

                var error = string.Empty;

                if (!Validator.TryValidateObject(student, context, errorList, true))
                {
                    foreach (ValidationResult result1 in errorList)
                    {
                        error = error + result1.ErrorMessage + "\r\n";
                    }
                    MessageBox.Show(error);
                    return;
                }

                var  data   = new StudentData();
                bool result = data.SaveStudent(student);
                if (result)
                {
                    MessageBox.Show("Student Account Added Sucessfully");
                    this.Hide();
                    StudentList slist = new StudentList();
                    slist.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Student Account Added unsucessfully");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #4
0
 private void delete()
 {
     if (MessageBox.Show("Are You Sure to Delete this Account?", "EF CRUD Operetion", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (SchoolManagementSystemDBEntities db = new SchoolManagementSystemDBEntities())
         {
             var entry = db.Entry(student1);
             if (entry.State == EntityState.Detached)
             {
                 db.Students.Attach(student1);
             }
             db.Students.Remove(student1);
             db.SaveChanges();
             MessageBox.Show("Student Account Deleted Sucessfully");
             this.Hide();
             StudentList slist = new StudentList();
             slist.ShowDialog();
         }
     }
 }