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 CSVExport(string filename) { var csv = new StringBuilder(); using (var context = new Cabinet_MedicalEntities()) { var query = from emp in context.Patients select new { emp.Nume, emp.CNP, emp.Serie_Buletin, emp.Numar_Buletin, emp.Data_Nasterii }; foreach (var row in query) { var newline = string.Format("{0},{1},{2},{3},{4}", row.Nume.ToString().Trim(), row.CNP.ToString().Trim(), row.Serie_Buletin.ToString().Trim(), row.Numar_Buletin.ToString().Trim(), row.Data_Nasterii.ToString().Trim()); csv.AppendLine(newline); } File.WriteAllText(filename, csv.ToString()); } }
private void View_Button_Click(object sender, EventArgs e) { try { using (var context = new Cabinet_MedicalEntities()) { string cell = PacientsData.SelectedRows[0].Cells[0].Value.ToString(); var query2 = (from pat in context.Patients where pat.Nume.Equals(cell) select pat).First(); if (PacientsData.SelectedRows.Count == 0) { throw new Exception("Selectati un pacient!"); } else { this.Hide(); View_Form view = new View_Form(query2, this, Abouts); view.Show(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ExcelExport(string filename) { try { Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlApp = new Microsoft.Office.Interop.Excel.Application(); if (xlApp == null) { throw new Exception("Eroare exportare foaie de calcul!"); } xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); using (var context = new Cabinet_MedicalEntities()) { var query = from emp in context.Patients select new { emp.Nume, emp.CNP, emp.Serie_Buletin, emp.Numar_Buletin, emp.Data_Nasterii }; int i = 1; foreach (var row in query) { xlWorkSheet.Cells[i, 1] = row.Nume.ToString().Trim(); xlWorkSheet.Cells[i, 2] = row.CNP.ToString().Trim(); xlWorkSheet.Cells[i, 3] = row.Serie_Buletin.ToString().Trim(); xlWorkSheet.Cells[i, 4] = row.Numar_Buletin.ToString().Trim(); xlWorkSheet.Cells[i, 5] = row.Data_Nasterii.ToString().Trim(); i++; } } xlWorkBook.SaveAs(filename); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Appointments_Form_Load(object sender, EventArgs e) { try { Name_Label.Text = Abouts.Nume.ToString().Trim(); Specs_Label.Text = Abouts.Specializare.ToString().Trim(); using (var context = new Cabinet_MedicalEntities()) { var query = from app in context.Appointments join pat in context.Patients on app.ID_Pacient equals pat.ID where app.ID_Medic.Equals(Abouts.ID) select new { pat.Nume, app.Date, app.Accepted }; if (query.Count() != 0) { foreach (var line in query) { if (line.Accepted == 1) { PatientsData.Rows.Add(line.Nume.ToString().Trim(), line.Date.ToString().Trim(), "In Asteptare"); } else if (line.Accepted == 2) { PatientsData.Rows.Add(line.Nume.ToString().Trim(), line.Date.ToString().Trim(), "Consultat"); } else if (line.Accepted == 3) { PatientsData.Rows.Add(line.Nume.ToString().Trim(), line.Date.ToString().Trim(), "Refuzat"); } } } else { throw new Exception("Nu sunt programari in asteptare!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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_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(); }
void FillCombo() { using (var context = new Cabinet_MedicalEntities()) { var query = from emp in context.Diseases select emp.Denumire; if (query.Count() != 0) { foreach (var dis in query) { diseaseBox.Items.Add(dis.ToString().Trim()); } } } }
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); } }
void FillCombo() { using (var context = new Cabinet_MedicalEntities()) { var query = from emp in context.Employees where emp.Specializare != "Asistent" && emp.Nume != "admin" select emp.Nume; if (query.Count() != 0) { foreach (var doc in query) { Doctors.Items.Add(doc.ToString()); } } } }
bool userExists(string user) { var context = new Cabinet_MedicalEntities(); var query = from username in context.Patients select new { username.Username }; foreach (var usr in query) { if (usr.Username.ToString().Trim().Equals(user)) { return(true); } } return(false); }
private void Medic_Form_Load(object sender, EventArgs e) { this.Text = Abouts.Nume.ToString().Trim() + " Window"; Name_Label.Text = Abouts.Nume.ToString().Trim(); Specs_Label.Text = Abouts.Specializare.ToString().Trim(); using (var context = new Cabinet_MedicalEntities()) { var query = from emp in context.Patients select new { emp.Nume, emp.CNP, emp.Serie_Buletin, emp.Numar_Buletin, emp.Data_Nasterii }; foreach (var row in query) { PacientsData.Rows.Add(row.Nume.ToString().Trim(), row.CNP.ToString().Trim(), row.Serie_Buletin.ToString().Trim(), row.Numar_Buletin.ToString().Trim(), row.Data_Nasterii.ToString().Trim()); } } using (var context = new Cabinet_MedicalEntities()) { var query = from app in context.Appointments where app.ID_Medic.Equals(Abouts.ID) && app.Accepted == 1 select app; Request_Label.Text = query.Count().ToString().Trim() + " Appointments"; if (query.Count() != 0) { Request_Label.BackColor = Color.Red; } } if (Equals(Abouts.Specializare.ToString().Trim(), "Asistent") == true) { Add_Button.Enabled = false; Delete_Button.Enabled = false; } }
private void historyButton_Click(object sender, EventArgs e) { try { History.Enabled = true; Doctors.Enabled = false; saveAppointment.Enabled = false; dateTime.Enabled = false; using (var cont = new Cabinet_MedicalEntities()) { var quer = from hist in cont.HistViews where hist.ID.Equals(Abouts.ID) select new { hist.Denumire, hist.Nume, hist.Specializare, hist.Data }; DataTable tabel = new DataTable(); tabel.Columns.Add("Afectiune", typeof(string)); tabel.Columns.Add("Medic", typeof(string)); tabel.Columns.Add("Specializare", typeof(string)); tabel.Columns.Add("Data examinare", typeof(DateTime)); foreach (var item in quer) { DataRow Row = null; Row = tabel.NewRow(); Row["Afectiune"] = item.Denumire.ToString().Trim(); Row["Medic"] = item.Nume.ToString().Trim(); Row["Specializare"] = item.Specializare.ToString().Trim(); Row["Data examinare"] = item.Data; tabel.Rows.Add(Row); } History.DataSource = tabel; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Eroare!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void PdfExport(string filename) { var Text = new StringBuilder(); var pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); var htmlparser = new HTMLWorker(pdfDoc); using (var context = new Cabinet_MedicalEntities()) { var query = from emp in context.Patients select new { emp.Nume, emp.CNP, emp.Serie_Buletin, emp.Numar_Buletin, emp.Data_Nasterii }; foreach (var row in query) { var newline = string.Format("{0},{1},{2},{3},{4},\r\n", row.Nume.ToString().Trim(), row.CNP.ToString().Trim(), row.Serie_Buletin.ToString().Trim(), row.Numar_Buletin.ToString().Trim(), row.Data_Nasterii.ToString().Trim()); Text.AppendLine(newline); } } using (var memory = new MemoryStream()) { var writer = PdfWriter.GetInstance(pdfDoc, memory); pdfDoc.Open(); htmlparser.Parse(new StringReader(Text.ToString())); pdfDoc.Close(); byte[] bytes = memory.ToArray(); File.WriteAllBytes(filename, bytes); memory.Close(); } }
bool checkAppointment(int medic, int pacient, DateTime date) { var context = new Cabinet_MedicalEntities(); var app = from cab in context.Appointments where cab.ID_Pacient.Equals(pacient) && cab.ID_Medic.Equals(medic) && cab.Date.Equals(date) select new { cab.ID_Medic, cab.ID_Pacient, cab.Date }; if (app.Count() != 0) { return(true); } else { return(false); } }
private void Login_Button_Click(object sender, EventArgs e) { try { if (Password_Box.Text.Length == 0) { throw new Exception("Introduceti parola!"); } string username = "******"; string password = getMD5(Password_Box.Text.Trim()); using (var context = new Cabinet_MedicalEntities()) { var query = from app in context.Employees where app.Username.Equals(username) && app.Parola.Equals(password) select app; if (query.Count() == 0) { throw new Exception("Parola este incorecta!"); } User_Label.Visible = false; Password_Label.Visible = false; admin_label.Visible = false; Password_Box.Visible = false; Login_Button.Visible = false; Cancel_Button.Visible = false; DatePick.Visible = false; Exit.Visible = true; AddMed.Visible = true; AddPill.Visible = true; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
bool checkExists(string nume, string cnp, string Serie, string numar) { var context = new Cabinet_MedicalEntities(); var query = from pat in context.Patients select new { pat.Nume, pat.CNP, pat.Serie_Buletin, pat.Numar_Buletin, //pat.Data_Nasterii }; foreach (var patient in query) { if (nume.Equals(patient.Nume.Trim()) && cnp.Equals(patient.CNP.Trim()) && Serie.Equals(patient.Serie_Buletin.Trim()) && numar.Equals(patient.Numar_Buletin.Trim()) /*&& p.Data_Nasterii.Equals(patient.Data_Nasterii)*/) { return(true); } } return(false); }
public Vew_Stoc_Form(Form parentForm) { InitializeComponent(); f = parentForm; using (var context = new Cabinet_MedicalEntities()) { var query = from i in context.Drugs_Diseases join m in context.Diseases on i.ID_Afectiune equals m.ID join p in context.Drugs on i.ID_Medicament equals p.ID select new { m.Denumire, den = p.Denumire, p.Data_Expirarii, p.Stoc }; foreach (var j in query) { if (DateTime.Compare(DateTime.Now, j.Data_Expirarii) < 0) { StocView.Rows.Add(j.Denumire.ToString().Trim(), j.den.ToString().Trim(), j.Data_Expirarii.ToString().Trim(), j.Stoc.ToString().Trim()); } } } }
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 buttonAfisare_Click(object sender, EventArgs e) { try { button1.Hide(); string tipConsutatie = comboBoxTipC.SelectedItem.ToString(); if (comboBoxTipC.SelectedItem != null) { using (var context = new Cabinet_MedicalEntities()) { RetetaData.Show(); ViewData.Hide(); BiletData.Hide(); var q = from i in context.History_Patients where i.ID_Pacient.Equals(Pacient.ID) select i; if (Equals(tipConsutatie, "Reteta")) { foreach (var reteta in q) { var query = (from r in context.Recipes where r.ID_Istoric.Equals(reteta.ID) select new { r.ID_Medicament, r.Numar_Flacoane }).FirstOrDefault(); if (query != null) { var afect = (from a in context.Diseases where a.ID.Equals(reteta.ID_Afectiune) select a).FirstOrDefault(); var med = (from m in context.Employees where m.ID.Equals(reteta.ID_Medic) select m).FirstOrDefault(); var medicament = (from d in context.Drugs where d.ID.Equals(query.ID_Medicament) select d).FirstOrDefault(); RetetaData.Rows.Add(reteta.Data.ToString().Trim(), med.Nume.ToString().Trim(), afect.Denumire.ToString().Trim(), medicament.Denumire.ToString().Trim(), query.Numar_Flacoane.ToString().Trim()); } } } else if (Equals(tipConsutatie, "Bilet internare")) { RetetaData.Hide(); ViewData.Hide(); BiletData.Show(); foreach (var bilet in q) { var query = (from b in context.Internment_Tickets where b.ID_Istoric.Equals(bilet.ID) select new { b.Descriere, b.Numar_Bilet, }).FirstOrDefault(); if (query != null) { var afect = (from af in context.Diseases where af.ID.Equals(bilet.ID_Afectiune) select af).FirstOrDefault(); var med = (from mm in context.Employees where mm.ID.Equals(bilet.ID_Medic) select mm).FirstOrDefault(); BiletData.Rows.Add(bilet.Data.ToString().Trim(), med.Nume.ToString().Trim(), afect.Denumire.ToString().Trim(), query.Descriere.ToString().Trim(), query.Numar_Bilet.ToString().Trim()); } } } else if (Equals(tipConsutatie, "Scutire")) { ViewData.Show(); RetetaData.Hide(); BiletData.Hide(); foreach (var scutire in q) { var query = (from s in context.Exemptions where s.ID_Istoric.Equals(scutire.ID) select new { s.Zile_Repaus, s.Tip }).FirstOrDefault(); if (query != null) { var afect = (from aa in context.Diseases where aa.ID.Equals(scutire.ID_Afectiune) select aa).FirstOrDefault(); var med = (from n in context.Employees where n.ID.Equals(scutire.ID_Medic) select n).FirstOrDefault(); ViewData.Rows.Add(scutire.Data.ToString().Trim(), med.Nume.ToString().Trim(), afect.Denumire.ToString().Trim(), query.Tip.ToString().Trim(), query.Zile_Repaus.ToString().Trim()); } } } } } else { throw new Exception("Selectati un camp!"); } } 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 Login_Button_Click(object sender, EventArgs e) { try { if (Username_Box.Text.Length == 0) { throw new Exception("Nu ati introdus numele utilizatorului!"); } else if (Password_Box.Text.Length == 0) { throw new Exception("Nu ati introdus parola utilizatorului!"); } else if (Login_Type.SelectedItem == null) { throw new Exception("Nu ati selectat tipul de utilizator!"); } else { string Username = Username_Box.Text.ToString(); string Password = getMD5(Password_Box.Text.ToString()); string Type = Login_Type.SelectedItem.ToString(); using (var context = new Cabinet_MedicalEntities()) { if (Equals(Type, "Pacient")) { var employee = (from emp in context.Patients where emp.Username.Equals(Username) && emp.Parola.Equals(Password) select emp).ToList(); if (employee.Count == 0) { throw new Exception("Utilizatorul nu exista!"); } else if (employee.Count == 1) { MessageBox.Show("Logarea s-a efectuat cu succes!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); Hide(); new Patient_Form(employee[0], this); Username_Box.Text = ""; Password_Box.Text = ""; // Show(); } } else if (Equals(Type, "Medic/Asistent")) { var employee = (from emp in context.Employees where emp.Username.Equals(Username) && emp.Parola.Equals(Password) select emp).ToList(); if (employee.Count == 0) { throw new Exception("Utilizatorul nu exista!"); } else if (employee.Count == 1) { MessageBox.Show("Logarea s-a efectuat cu succes!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); Hide(); new Medic_Form(employee[0], this); // Show(); Username_Box.Text = ""; Password_Box.Text = ""; } } } } } 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 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); } }