//insert new instructor private void Add_button(object sender, EventArgs e) { try { using (Online_Exame ent = new Online_Exame()) { //ent.NewInstructor(textBox1.Text, textBox2.Text, int.Parse(comboBox1.Text)); Instractor ins = new Instractor(); ins.Dept_id = int.Parse(comboBox1.Text); ins.Ins_fname = textBox1.Text; ins.Ins_lname = textBox2.Text; ent.Instractors.Add(ins); ent.SaveChanges(); Loadinstructor(); MessageBox.Show("Added Successfully"); comboBox1.Text = comboBox2.Text = textBox1.Text = textBox2.Text = string.Empty; } } catch (FormatException) { MessageBox.Show("Please complete the information"); } }
//delete instructor private void delete_button(object sender, EventArgs e) { try { int insId = (int)comboBox2.SelectedItem; using (Online_Exame ent = new Online_Exame()) { // ent.deleteInstructor(insId); int ins_id = int.Parse(comboBox2.Text); Instractor ins = ent.Instractors.Find(ins_id); ent.Instractors.Remove(ins); ent.SaveChanges(); Loadinstructor(); comboBox1.Text = comboBox2.Text = textBox1.Text = textBox2.Text = string.Empty; } MessageBox.Show("Deleted Successfully"); } catch (NullReferenceException) { MessageBox.Show("Incorrect ID"); } }