private void adaugarePacient_Click(object sender, EventArgs e) { try { using (BDISPatients db = new BDISPatients()) { Patients patient = new Patients(); patient.Nume = addTxtNume.Text; patient.Prenume = addTxtPrenume.Text; patient.CNP = long.Parse(addTxtCNP.Text); patient.Adresa = addTxtAdresa.Text; patient.Data_nasterii = addDateTime.Value; patient.Varsta = byte.Parse(addTxtAge.Text); patient.Email = addTxtEmail.Text; patient.UID = Guid.NewGuid(); db.Patients.Add(patient); if (db.SaveChanges() > 0) { MetroFramework.MetroMessageBox.Show(this, "Pacientul a fost adaugat cu succes.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Pacientul nu a putut fi adaugat in baza de date.", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void updateButton_Click(object sender, EventArgs e) { using (BDISPatients db = new BDISPatients()) { var CNP = long.Parse(searchPacient.Text); var originalUser = db.Patients.FirstOrDefault(item => item.CNP == CNP); var updatedUser = originalUser; if (originalUser != null) { updatedUser.Nume = modTxtNume.Text; updatedUser.Prenume = modTxtPrenume.Text; updatedUser.Email = modTxtEmail.Text; updatedUser.Adresa = modTxtAdresa.Text; updatedUser.Data_nasterii = modDateTime.Value; updatedUser.Varsta = byte.Parse(modTxtAge.Text); db.Entry(originalUser).CurrentValues.SetValues(updatedUser); if (db.SaveChanges() > 0) { MetroFramework.MetroMessageBox.Show(this, "Datele pacientului au fost actualizate cu succes.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MetroFramework.MetroMessageBox.Show(this, "Datele pacientului nu au fost actualizate.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void btnDeletePatient_Click(object sender, EventArgs e) { var CNP = long.Parse(patientSearchBox.Text); using (BDISPatients db = new BDISPatients()) { var patientToRemove = db.Patients.SingleOrDefault(x => x.CNP == CNP); user_UID = patientToRemove.UID.ToString(); if (patientToRemove != null) { db.Patients.Remove(patientToRemove); db.SaveChanges(); patientSearchGrid.Hide(); MetroFramework.MetroMessageBox.Show(this, "Pacientul a fost sters.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } using (BDISAppMedicalConditions db = new BDISAppMedicalConditions()) { db.MedicalConditions.RemoveRange(db.MedicalConditions.Where(x => x.Patient_UID == user_UID)); db.SaveChanges(); } }