private void registerButton_Click(object sender, EventArgs e) { DateTime date = appointmentDatePicker.Value; DateTime time = appointmentTimePicker.Value; string doctor = doctorComboBox.SelectedItem.ToString(); Patient patient = GetPatientFromGrid(); if (patient == null) { return; } int registrarId = 0; if (Program.CurrentUser.Position == "RegistrationPerson") { int regCount = Program.CurrentUser.RegistrationPerson.Count; if (regCount != 1) { return; } RegistrationPerson reg = Program.CurrentUser.RegistrationPerson.First(); if (reg != null) { registrarId = reg.Id; } } if (Common.InsertAppointment(date, time, doctor, patient, registrarId) != 0) { MessageBox.Show("Zarejestrowano wizytę"); } else { MessageBox.Show("Błąd rejestracji"); } }
public static int InsertRegistrar(RegistrationPerson user) { db.RegistrationPerson.Add(user); return(db.SaveChanges()); }
private void saveButton_Click(object sender, EventArgs e) { user.Person.First_Name = nameTextBox.Text; user.Person.Last_Name = surnameTextBox.Text; user.Person.Sex = sexComboBox.SelectedIndex == 0 ? "Male" : "Female"; user.Person.Date_of_birth = birthdatePicker.Value; user.Person.Phone_number = phoneTextBox.Text; user.Login = loginTextBox.Text; if (termlessCheckBox.Checked) { user.dt_AccountValidityFrom = null; user.dt_AccountValidityTo = null; } else { user.dt_AccountValidityFrom = validityDateFromPicker.Value; user.dt_AccountValidityTo = validityDateToPicker.Value; } if (Common.CheckLogin(loginTextBox.Text) == -1 && ifNewUser) { MessageBox.Show("Użytkownik o podanym loginie już istnieje."); return; } bool changedRole = false; List <string> positions = new List <string>(); positions.Add("-"); positions.Add("RegistrationPerson"); positions.Add("Doctor"); positions.Add("LaboratoryPerson"); positions.Add("LaboratorySupervisor"); positions.Add("Admin"); if (Program.CurrentUser.Position == "Admin" && user.Position != positions[roleComboBox.SelectedIndex]) { int success = 0; if (!ifNewUser) { switch (user.Position) { case "RegistrationPerson": success = Common.DeleteRegistrar(user); break; case "Doctor": success = Common.DeleteDoctor(user); break; case "LaboratoryPerson": success = Common.DeleteLaboratoryPerson(user); break; case "LaboratorySupervisor": success = Common.DeleteLaboratorySupervisor(user); break; case "Admin": success = 1; break; default: break; } if (success == 0) { MessageBox.Show("Nie udało się zmienić roli!"); return; } } user.Position = positions[roleComboBox.SelectedIndex]; switch (roleComboBox.SelectedIndex) { case 1: RegistrationPerson reg = new RegistrationPerson(); reg.Employee = user; reg.EmployeeId = user.Id; success = Common.InsertRegistrar(reg); break; case 2: Doctor doc = new Doctor(); doc.Employee = user; doc.EmployeeId = user.Id; doc.NPWZ = permissionTextBox.Text; doc.Profession = specializationTextBox.Text; success = Common.InsertDoctor(doc); break; case 3: LaboratoryPerson lab = new LaboratoryPerson(); lab.Employee = user; lab.EmployeeId = user.Id; success = Common.InsertLaboratoryPerson(lab); break; case 4: LaboratorySupervisor klab = new LaboratorySupervisor(); klab.Employee = user; klab.EmployeeId = user.Id; success = Common.InsertLaboratorySupervisor(klab); break; case 5: success = 1; break; default: break; } if (success == 0 && !ifNewUser) { MessageBox.Show("Nie udało się zmienić roli!"); return; } else if (success == 0 && ifNewUser) { MessageBox.Show("Nie udało się dodać nowego użytkownika!"); return; } else if (success != 0 && ifNewUser) { MessageBox.Show("Użytkownika dodano pomyślnie."); Return(); } else { changedRole = true; } } if (!ifNewUser) { if (Common.UpdateEmployee(user) != 0 || changedRole) { MessageBox.Show("Dane zaktualizowano pomyślnie."); } else { MessageBox.Show("Nie zaktualizowano danych."); return; } } Return(); }