private void button_confirm_Click(object sender, EventArgs e) { if (ValidateChildren(ValidationConstraints.Enabled)) { learning_program program = new learning_program { name = textbox_lesson_name.Text, year_of_creation = int.Parse(textbox_year_of_creation.Text) }; using (schoolEntities db = new schoolEntities()) { db.learning_program.Add(program); int[] keys = checkedlistbox_subjects.CheckedItems.Cast <subject>().Select(s => s.id).ToArray(); foreach (var key in keys) { subject s = db.subjects.Find(key); if (s != null) { s.learning_program1.Add(program); program.subjects1.Add(s); } } db.SaveChanges(); MessageBox.Show(string.Format("Learning program is added!"), "Success!"); textbox_lesson_name.Clear(); textbox_year_of_creation.Clear(); checkedlistbox_subjects.ClearSelected(); } } }
private void button_confirm_Click(object sender, EventArgs e) { if (ValidateChildren(ValidationConstraints.Enabled)) { subject c = new subject { name = textbox_lesson_name.Text, quantity = int.Parse(textbox_lesson_quantity.Text), year_of_creation = int.Parse(textbox_year_of_creation.Text) }; using (schoolEntities db = new schoolEntities()) { db.subjects.Add(c); db.SaveChanges(); MessageBox.Show(string.Format("Subject {0} (Y:{2}, Q:{1}) is added!", c.name, c.quantity, c.year_of_creation), "Success!"); } this.textbox_lesson_name.Clear(); this.textbox_year_of_creation.Clear(); this.textbox_lesson_quantity.Clear(); } }
private void button_confirm_Click(object sender, EventArgs e) { if (ValidateChildren(ValidationConstraints.Enabled)) { teacher t = new teacher { first_name = text_box_teacher_first_name.Text, last_name = text_box_teacher_last_name.Text, third_name = text_box_teacher_third_name.Text, }; using (schoolEntities db = new schoolEntities()) { int[] keys = checkedlistbox_subjects.CheckedItems.Cast <subject>().Select(s => s.id).ToArray(); foreach (var key in keys) { subject s = db.subjects.Find(key); if (s != null) { s.teachers.Add(t); t.subjects.Add(s); } } db.teachers.Add(t); db.SaveChanges(); MessageBox.Show(string.Format("Teacher {0} {1} {2} is added!", t.first_name, t.last_name, t.third_name), "Success!"); } text_box_teacher_first_name.Clear(); text_box_teacher_last_name.Clear(); text_box_teacher_third_name.Clear(); checkedlistbox_subjects.ClearSelected(); } }