public static void AdNewJournal(Journal journal) { HealthCareEntities hlthCareContext = new HealthCareEntities(); hlthCareContext.Journals.Add(journal); hlthCareContext.SaveChanges(); }
private void btDelete_Click(object sender, EventArgs e) { int index = cbChoiceContext.SelectedIndex; try { switch (index) { case 0: Clinic.DeleteClinic(((Clinic)inputData.SelectedItem).Id); break; case 1: Doctor.DeleteDoctor(((Doctor)inputData.SelectedItem).Id); break; case 2: Patient.DeletePatient(((Patient)inputData.SelectedItem).Id); break; case 3: { Journal jr = new Journal(); Journal.DeleteJournal(jr.IdDoctor, jr.IdPatient, jr.Date); break; } default: throw new Exception("Error! Not correct choice!"); } inputData.SelectedIndex = 0; Form1_Load(null, null); } catch (Exception exp) { MessageBox.Show("Error!" + exp.ToString()); } }
public JournalForm() { InitializeComponent(); jr = new Journal(); flagEdit = false; cbDoctor.Items.AddRange(Doctor.AllDoctors().ToArray()); cbPatient.Items.AddRange(Patient.AllPatients().ToArray()); }
public JournalForm(int cmd, Journal jr) { InitializeComponent(); this.jr = jr; flagEdit = false; cbDoctor.Items.AddRange(Doctor.AllDoctors().ToArray()); cbPatient.Items.AddRange(Patient.AllPatients().ToArray()); switch (cmd) { case 0: FormForEdit(); break; case 1: FormForAdd(); break; default: throw new Exception("Not correct parametr to constructor for DoctorForm!"); } }
//Journal journalPast, Journal journalNew ) public static void UpdateJournal(Journal journal) { HealthCareEntities hlthCareContext = new HealthCareEntities(); var jr = hlthCareContext.Journals.Where(j => (j.IdDoctor == journal.IdDoctor && j.IdPatient == journal.IdPatient && j.Date == journal.Date)).First(); //jr.IdDoctor = journalNew.IdDoctor; //jr.IdPatient = journalNew.IdPatient; //jr.SomeInfo = journalNew.SomeInfo; //jr.Date = journalNew.Date; jr.SomeInfo = journal.SomeInfo; hlthCareContext.SaveChanges(); }
public static void DeleteJournal(int idDoctor, int idPatient, DateTime date) { HealthCareEntities hlthCareContext = new HealthCareEntities(); Journal journal = new Journal { IdDoctor = idDoctor, IdPatient = idPatient, Date = date }; hlthCareContext.Journals.Attach(journal); hlthCareContext.Journals.Remove(journal); hlthCareContext.SaveChanges(); }
private void SetChangesToDB() { using (HealthCareEntities healthCareContext = new HealthCareEntities()) { try { //Journal journalBeforeChanged = new Journal() //{ // IdDoctor = jr.IdDoctor, // IdPatient = jr.IdPatient, // Date = jr.Date, // SomeInfo = jr.SomeInfo //}; if (jr.IdDoctor != 0) { GetDataFromForms(); Journal.UpdateJournal(jr); } else { GetDataFromForms(); Journal journal = new Journal() { IdDoctor = jr.IdDoctor, IdPatient = jr.IdPatient, Date = jr.Date, SomeInfo = jr.SomeInfo }; Journal.AdNewJournal(journal); } } catch (Exception exp) { MessageBox.Show("Error! " + exp.Message); } } }