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(); } } }
private void doctorsDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { int id = Convert.ToInt32(doctorsDataGridView.CurrentRow.Cells[0].Value); //7.8 if (e.ColumnIndex == 7) { doctor locd = db.doctors.Find(id); //Edit using (doctorEdit frm = new doctorEdit(locd)) { 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.EditDoctor(id, familyName, name, fatherName, db.doctor_position.Where(p => p.position.Equals(frm.posComboBox.SelectedItem.ToString())).First().id, frm.qualifNumericUpDown.Value, frm.notNullCheckBox.Checked)) { string spec2 = frm.spec2ComboBox.SelectedItem.ToString(); bool nullSpec = frm.notNullSpecCheckBox.Checked; 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 (nullSpec) { if (dbm.AddDoctorNewSpecialization(did, id2)) { MessageBox.Show("OK", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error with Specializations", "Info", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("OK", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Error", "Info", MessageBoxButtons.OK, MessageBoxIcon.Error); } //doctorsDataGridView.DataSource = db.doctors.ToList(); //doctorsDataGridView.DataSource = dbm.GetExtDoctors(); reloadData(); doctorsDataGridView.DataSource = db.ExtDoctors.ToList(); } } } if (e.ColumnIndex == 8) { //Delete if (dbm.DeleteDoctor(id)) { MessageBox.Show("OK", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error", "Info", MessageBoxButtons.OK, MessageBoxIcon.Error); } //doctorsDataGridView.DataSource = db.doctors.ToList(); //doctorsDataGridView.DataSource = dbm.GetExtDoctors(); reloadData(); doctorsDataGridView.DataSource = db.ExtDoctors.ToList(); } }