Exemplo n.º 1
0
 private void doctorAddBtn_Click(object sender, EventArgs e)
 {
     using (doctorEdit frm = new doctorEdit())
     {
         if (frm.ShowDialog() == DialogResult.OK)
         {
             string familyName = frm.familyNameTextBox.Text;
             string name       = frm.nameTextBox.Text;
             string fatherName = frm.fatherNameTextBox.Text;
             familyName = cutSpacesAndUnprintChars(familyName);
             name       = cutSpacesAndUnprintChars(name);
             fatherName = cutSpacesAndUnprintChars(fatherName);
             if (dbm.AddDoctor(familyName, name, fatherName, db.doctor_position.Where(p => p.position.Equals(frm.posComboBox.SelectedItem.ToString())).First().id, frm.qualifNumericUpDown.Value, frm.notNullCheckBox.Checked) != null)
             {
                 string spec1    = frm.spec1ComboBox.SelectedItem.ToString();
                 string spec2    = frm.spec2ComboBox.SelectedItem.ToString();
                 bool   nullSpec = frm.notNullSpecCheckBox.Checked;
                 int    id1      = db.doctor_specialization.Where(p => p.specialization.Equals(spec1)).FirstOrDefault().id;
                 int    id2      = db.doctor_specialization.Where(p => p.specialization.Equals(spec2)).FirstOrDefault().id;
                 int    did      = db.doctors.Where(p => (p.family_name.ToLower().Equals(familyName.ToLower())) && (p.name.ToLower().Equals(name.ToLower())) && (p.father_name.ToLower().Equals(fatherName.ToLower()))).FirstOrDefault().id;
                 if (!dbm.AddDoctorSpecialization(did, id1, id2, nullSpec))
                 {
                     MessageBox.Show("Error with Specializtions", "Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
             else
             {
                 MessageBox.Show("Error", "Info", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             //doctorsDataGridView.DataSource = db.doctors.ToList();
             //doctorsDataGridView.DataSource = dbm.GetExtDoctors();
             reloadData();
             doctorsDataGridView.DataSource = db.ExtDoctors.ToList();
         }
     }
 }