private void saveTicket_Click(object sender, EventArgs e) { try { using (var context = new Cabinet_MedicalEntities()) { var af = (from afect in context.Diseases where afect.Denumire.Equals(diseaseBox.SelectedItem.ToString().Trim()) select afect.ID).ToList().First(); History_Patients hist = new History_Patients { ID_Afectiune = af, ID_Pacient = pacient.ID, ID_Medic = medic.ID, Data = DateTime.Now }; context.History_Patients.Add(hist); context.SaveChanges(); Internment_Tickets bilet = new Internment_Tickets { ID_Istoric = hist.ID, Descriere = diseaseBox.Text.ToString().Trim() }; context.Internment_Tickets.Add(bilet); context.SaveChanges(); MessageBox.Show("Biletul de trimitere a fost inregistrat!", "Succes!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Eroare!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Add_Pill_Click(object sender, EventArgs e) { try { if (Name_Box.Text.Length == 0) { throw new Exception("Introduceti numele medicamentului!"); } if (DatePick.Text.Length == 0) { throw new Exception("Alegeti data expirarii!"); } if (Username_Box.Text.Length == 0) { throw new Exception("Introduceti numarul de produse!"); } Drug med = new Drug(); med.Denumire = Name_Box.Text.Trim(); med.Stoc = Int32.Parse(Username_Box.Text.Trim()); med.Data_Expirarii = DatePick.Value; using (var context = new Cabinet_MedicalEntities()) { var query = (from pill in context.Drugs where pill.Denumire.Equals(med.Denumire) select pill).First(); if (query != null) { query.Stoc += med.Stoc; context.SaveChanges(); MessageBox.Show("Stocul de " + med.Denumire + " a fost actualizat!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { context.Drugs.Add(med); context.SaveChanges(); MessageBox.Show("Adaugarea s-a efectuat cu succes!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void saveAppointment_Click(object sender, EventArgs e) { try { if (Doctors.SelectedItem == null) { throw new Exception("Selectati un medic!"); } else if (dateTime.Checked == false) { throw new Exception("Selectati o data!"); } else { using (var context = new Cabinet_MedicalEntities()) { var medic = (from med in context.Employees where med.Nume.Equals(Doctors.SelectedItem.ToString()) select med).First(); var newapp = new Appointment() { ID_Medic = medic.ID, ID_Pacient = Abouts.ID, Date = dateTime.Value, Accepted = 1 }; if (checkAppointment(newapp.ID_Medic, newapp.ID_Pacient, newapp.Date) == true) { throw new Exception("Ati mai facut o programare identica!\n"); } else { context.Appointments.Add(newapp); context.SaveChanges(); } } } } catch (Exception exc) { MessageBox.Show(exc.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } Doctors.Text = ""; Doctors.Enabled = false; dateTime.Enabled = false; saveAppointment.Enabled = false; Doctors.Items.Clear(); }
private void Accept_Button_Click(object sender, EventArgs e) { try { if (PatientsData.SelectedRows.Count == 0) { throw new Exception("Selectati o programare!"); } if (PatientsData.SelectedCells[2].Value.ToString().Equals("Consultat")) { throw new Exception("Pacientul a fost deja consultat!"); } if (PatientsData.SelectedCells[2].Value.ToString().Equals("Refuzat")) { throw new Exception("Pacientul a fost deja refuzat!"); } Patient P; using (var context = new Cabinet_MedicalEntities()) { string name = PatientsData.SelectedCells[0].Value.ToString(); var query = (from app in context.Appointments join pat in context.Patients on app.ID_Pacient equals pat.ID where pat.Nume.Equals(name) select new { app.Accepted, pat.ID }).First(); PatientsData.SelectedCells[2].Value = "Consultat"; // var query2 = (from app in context.Appointments // where app.ID_Pacient == query.ID // select app).First(); var query3 = (from pat in context.Patients where pat.Nume.Equals(name) select pat).First(); context.SetData(name, 2); context.SaveChanges(); P = query3; } Form p = new View_Form(P, this, Abouts); p.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Add_Med_Click(object sender, EventArgs e) { try { if (Name_Box.Text.Length == 0) { throw new Exception("Introduceti numele!"); } if (Spec_Box.Text.Length == 0) { throw new Exception("Introduceti specializarea!"); } if (Username_Box.Text.Length == 0) { throw new Exception("Introduceti username-ul!"); } if (Parola_Box.Text.Length == 0) { throw new Exception("Introduceti parola!"); } Employee E = new Employee(); E.Nume = Name_Box.Text.Trim(); E.Specializare = Spec_Box.Text.Trim(); E.Username = Username_Box.Text.Trim(); E.Parola = getMD5(Parola_Box.Text.Trim()); // E.Parola = Parola_Box.Text.Trim(); using (var context = new Cabinet_MedicalEntities()) { var query = from emp in context.Employees where emp.Nume.Equals(E.Nume) || emp.Username.Equals(E.Username) select emp; if (query.Count() != 0) { throw new Exception("Medicul sau Username-ul exista deja in baza de date!"); } context.Employees.Add(E); context.SaveChanges(); MessageBox.Show("Adaugarea s-a efectuat cu succes!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Delete_Button_Click(object sender, EventArgs e) { try { if (PacientsData.SelectedRows.Count == 0) { throw new Exception("Selectati un pacient!"); } string name = PacientsData.SelectedCells[0].Value.ToString(); using (var context = new Cabinet_MedicalEntities()) { context.DeletePatient(name); context.SaveChanges(); PacientsData.Rows.Remove(PacientsData.SelectedRows[0]); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonSave_Click(object sender, EventArgs e) { try { using (var context = new Cabinet_MedicalEntities()) { string medic = textBoxMedic.Text; string afectiune = textBoxAfectiune.Text; int zile = Int32.Parse(textBoxZile.Text); if (textBoxMedic.Text.Length == 0) { throw new Exception("Nu ati introdus numele medicului/asistentului!"); } else if (textBoxAfectiune.Text.Length == 0) { throw new Exception("Nu ati introdus denumirea afectiunii!"); } else if (textBoxZile.Text.Length == 0) { throw new Exception("Nu ati introdus numarul de zile!"); } else if (textBoxTipScutire.Text.Length == 0) { throw new Exception("Nu ati introdus tipul scutirii!"); } else { var query = (from m in context.Employees where m.Nume.Equals(medic) select m).FirstOrDefault(); var query2 = (from a in context.Diseases where a.Denumire.Equals(afectiune) select a).FirstOrDefault(); if (query2 == null) { throw new Exception("Denumirea afectiunii este incorecta!"); } else if (query == null) { throw new Exception("Numele medicului introdus esti incorect!"); } else { var addnew = new History_Patients { ID_Medic = query.ID, Data = DateTime.Now, ID_Pacient = Pacient.ID, ID_Afectiune = query2.ID }; context.History_Patients.Add(addnew); context.SaveChanges(); var addsc = new Exemption { ID_Istoric = addnew.ID, Zile_Repaus = zile, Tip = textBoxTipScutire.Text }; context.Exemptions.Add(addsc); context.SaveChanges(); MessageBox.Show("Scutirea a fost inregistrata cu succes!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); textBoxAfectiune.Text = ""; textBoxMedic.Text = ""; textBoxTipScutire.Text = ""; textBoxZile.Text = ""; } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void buttonSave_Click(object sender, EventArgs e) { using (var context = new Cabinet_MedicalEntities()) { try { if (textBoxAf.Text.Length == 0) { throw new Exception("Nu ati introdus denumirea afectiunii!"); } else if (textBoxMed.Text.Length == 0) { throw new Exception("Nu ati introdus denumirea medicamentului!"); } else if (textBoxNrF.Text.Length == 0) { throw new Exception("Nu ati introdus numarul de flacoane!"); } else { var res = (from p in context.Drugs where p.Denumire.Equals(textBoxMed.Text) select p).FirstOrDefault(); int numar = Int32.Parse(textBoxNrF.Text); var query2 = (from a in context.Diseases where a.Denumire.Equals(textBoxAf.Text) select a).FirstOrDefault(); if (query2 == null) { throw new Exception("Denumirea afectiunii este incorecta!"); } string den = res.Denumire; if (res.Stoc > numar) { var addnew = new History_Patients { ID_Medic = m.ID, Data = DateTime.Now, ID_Pacient = Pacient.ID, ID_Afectiune = query2.ID }; context.History_Patients.Add(addnew); context.SaveChanges(); var addret = new Recipe { ID_Istoric = addnew.ID, ID_Medicament = res.ID, Numar_Flacoane = numar }; context.Recipes.Add(addret); context.SaveChanges(); using (var dbContextTransaction = context.Database.BeginTransaction()) { try { var pp = from dr in context.Drugs where dr.Denumire.Equals(den) select dr; foreach (var pastile in pp) { pastile.Stoc = pastile.Stoc - numar; } context.SaveChanges(); dbContextTransaction.Commit(); } catch (Exception) { dbContextTransaction.Rollback(); } } MessageBox.Show("Reteta a fost inregistrata cu succes!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); textBoxAf.Text = ""; textBoxMed.Text = ""; textBoxNrF.Text = ""; } else { MessageBox.Show("Stoc insuficient!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void addButton_Click(object sender, EventArgs e) { try { if (nameBox.Text == "") { throw new Exception("Campul nume nu a fost commpletat!"); } else if (cnpBox.Text == "") { throw new Exception("Campul CNP nu a fost completat!"); } else if (serieBox.Text == "") { throw new Exception("Campul Serie_buletin nu a fost completat!"); } else if (numberBox.Text == "") { throw new Exception("Campul Numar_buletin nu a fost completat!"); } else if (data_nasterePick.Value == null) { throw new Exception("Nu ati ales Data nasterii!"); } else if (userBox.Text == "") { throw new Exception("Nu ati ales un username!"); } else if (passwordBox.Text == "") { throw new Exception("Nu ati introdus o parola!"); } else if (passwordBox.Text != confirmBox.Text) { throw new Exception("Parola nu se potriveste!"); } else { if (cnpBox.Text.Length < 13) { throw new Exception("CNP-ul trebuie sa contina 13 cifre!"); } if (serieBox.Text.Length < 2) { throw new Exception("Seria buletinului este formata din 2 litere!"); } if (numberBox.Text.Length < 6) { throw new Exception("Numarul butletinului este format din 6 cifre!"); } if (check_Pass(passwordBox.Text.ToString()) == false) { throw new Exception("Parola trebuie sa contina cel putin 6 caractere!"); } if (numberOnly(cnpBox.Text.ToString()) == false) { throw new Exception("Campul CNP trebuie sa contina doar cifre!"); } if (numberOnly(numberBox.Text.ToString()) == false) { throw new Exception("Campul Numar_buletin trebuie sa contina doar cifre!"); } if (letterOnly(serieBox.Text.ToString()) == false) { throw new Exception("Campul Serie_buletin trebuie sa contina doar lietere!"); } else { var p = new Patient { Nume = nameBox.Text.ToString(), CNP = cnpBox.Text.ToString(), Serie_Buletin = serieBox.Text.ToString(), Numar_Buletin = numberBox.Text.ToString(), Data_Nasterii = data_nasterePick.Value, Username = userBox.Text.ToString(), Parola = getMD5(passwordBox.Text.ToString()) }; if (checkExists(nameBox.Text, cnpBox.Text, serieBox.Text, numberBox.Text) == true) { throw new Exception("Pacientul este deja inregistrat!"); } else if (userExists(userBox.Text) == true) { throw new Exception("Username-ul este deja inregistrat!\nIncercati alt username!"); } else { using (var context = new Cabinet_MedicalEntities()) { context.Patients.Add(p); context.SaveChanges(); MessageBox.Show("Pacientul a fost inregistrat cu succes!", "Succes!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Reintroduceti datele", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }