Beispiel #1
0
        //add instructor to choosen course
        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                int crsId = int.Parse(comboBox1.Text);
                using (Online_Exame ent = new Online_Exame())
                {
                    //--get instractor from combo box
                    string insName = comboBox3.Text.ToString();
                    var    insId   = (int)(ent.Get_insid_by_inname(insName)).First();

                    //--add instractor to course
                    ent.Add_Course_instractor(crsId, insId);

                    MessageBox.Show("Added Successfully");
                    Courses.Items.Clear();
                    Instructors.Items.Clear();
                    label7.Text = comboBox1.Text = comboBox3.Text = textBox1.Text = string.Empty;


                    ent.SaveChanges();
                }
            }
            catch (System.Data.Entity.Core.EntityCommandExecutionException)
            {
                MessageBox.Show("This instructor already exist");
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("Please Choose Instructor Name");
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Please Choose Instructor Name");
            }
            catch (System.FormatException)
            {
                MessageBox.Show("Please Choose Course ID");
            }
        }