Beispiel #1
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            model.TeacherName = textBox1.Text.Trim();
            model.Date        = dateTimePicker.Value.Date;
            model.Position    = textBox3.Text.Trim();
            model.Number      = Int32.Parse(textBox4.Text);
            model.Department  = textBox5.Text.Trim();
            model.Discipline  = textBox6.Text.Trim();

            using (EducationDBEntities db = new EducationDBEntities())
            {
                if (model.TeacherId == 0)
                {
                    db.Teachers.Add(model);
                }
                else
                {
                    db.Entry(model).State = EntityState.Modified;
                }

                db.SaveChanges();
            }

            Clear();
            PopulateDataGridView();
            MessageBox.Show("Отправлено успешно!");
        }
Beispiel #2
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            model.Name    = textBoxForName.Text.Trim();
            model.Number  = Convert.ToInt32(textBoxForNumber.Text);
            model.Manager = textBoxForManager.Text.Trim();
            model.Faculty = textBoxForFaculty.Text.Trim();

            using (EducationDBEntities db = new EducationDBEntities())
            {
                if (model.DepartmentId == 0)
                {
                    db.Departments.Add(model);
                }
                else
                {
                    db.Entry(model).State = EntityState.Modified;
                }

                db.SaveChanges();
            }

            Clear();
            PopulateDataGridView();
            MessageBox.Show("Отправлено успешно!");
        }
        private void buttonSave_Click(object sender, EventArgs e)
        {
            model.Name       = textBoxForName.Text.Trim();
            model.Code       = textBoxForCode.Text.Trim();
            model.Semester   = Convert.ToInt32(textBoxForSemester.Text);
            model.Speciality = textBoxForSpeciality.Text.Trim();

            using (EducationDBEntities db = new EducationDBEntities())
            {
                if (model.DisciplineId == 0)
                {
                    db.DIsciplines.Add(model);
                }
                else
                {
                    db.Entry(model).State = EntityState.Modified;
                }

                db.SaveChanges();
            }

            Clear();
            PopulateDataGridView();
            MessageBox.Show("Отправлено успешно!");
        }
Beispiel #4
0
 private void buttonDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Вы действительно хотите удалить элемент?", "Операция удаления", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (EducationDBEntities db = new EducationDBEntities())
         {
             var entry = db.Entry(model);
             if (entry.State == EntityState.Detached)
             {
                 db.Teachers.Attach(model);
             }
             db.Teachers.Remove(model);
             db.SaveChanges();
             PopulateDataGridView();
             Clear();
             //MessageBox.Show("Удаление прошло успешно!");
         }
     }
 }