private async void ModifyDoWork(object sender, DoWorkEventArgs e) { foreach (ScheduleM.Appointment appointment in ScheduleM.Appointments.Where(s => s.IsChanged && s.StoreInDB)) { try { using (me = new MedicalModel(ConfigurationManager.Connect())) { await me.Database.Connection.OpenAsync(); scheduledata dbAppointment = me.scheduledata.Where(s => s.IdSD == appointment.Id).Single(); if (dbAppointment.StillNotVisitedSD != appointment.StillNotVisited) { if (dbAppointment.StillNotVisitedSD) { scheduleperson_st spst = me.scheduleperson_st.Where(sp => sp.IdSP == dbAppointment.PatientIdSD).Single(); me.newperson.Remove(me.newperson.Where(np => np.IdNP == spst.NewPersonIdSP).Single()); spst.NewPersonIdSP = null; spst.ExistedIdSP = ScheduleM.Patients.Where(p => p.TajNumber == appointment.PatientTajNumber).Single().Id; dbAppointment.StillNotVisitedSD = false; await me.SaveChangesAsync(); } else { scheduleperson_st spst = me.scheduleperson_st.Where(sp => sp.IdSP == dbAppointment.PatientIdSD).Single(); spst.ExistedIdSP = null; newperson np = new newperson(); dbAppointment.StillNotVisitedSD = true; np.PatientNameNP = appointment.PatientName; np.TAJNumberNP = appointment.PatientTajNumber; me.newperson.Add(np); await me.SaveChangesAsync(); spst.NewPersonIdSP = np.IdNP; await me.SaveChangesAsync(); } await me.SaveChangesAsync(); } else if (dbAppointment.StillNotVisitedSD) { newperson newp = me.newperson.Where(per => per.IdNP == me.scheduleperson_st.Where(sp => sp.IdSP == dbAppointment.PatientIdSD).FirstOrDefault().NewPersonIdSP).Single(); if (newp.PatientNameNP != appointment.PatientName) { newp.PatientNameNP = appointment.PatientName; } if (newp.TAJNumberNP != appointment.PatientTajNumber) { newp.TAJNumberNP = appointment.PatientTajNumber; } await me.SaveChangesAsync(); } else { scheduleperson_st spst = me.scheduleperson_st.Where(sp => sp.IdSP == dbAppointment.PatientIdSD).Single(); spst.ExistedIdSP = ScheduleM.Patients.Where(p => p.TajNumber == appointment.PatientTajNumber).Single().Id; await me.SaveChangesAsync(); } if (appointment.StillNotVisited != dbAppointment.StillNotVisitedSD) { dbAppointment.StillNotVisitedSD = appointment.StillNotVisited; } if (appointment.StartTime != dbAppointment.StartSD) { dbAppointment.StartSD = appointment.StartTime; } if (appointment.EndTime != dbAppointment.FinishSD) { dbAppointment.FinishSD = appointment.EndTime; } if (appointment.DoctorId != dbAppointment.DoctorIdSD) { dbAppointment.DoctorIdSD = appointment.DoctorId; } if (appointment.Notes != dbAppointment.NotesSD) { dbAppointment.NotesSD = appointment.Notes; } if (appointment.Label != dbAppointment.StatusSD) { dbAppointment.StatusSD = appointment.Label; } await me.SaveChangesAsync(); } workingConn = true; } catch (Exception ex) { Log.WriteException(ex); workingConn = false; } } }
private async void CreateDoWork(object sender, DoWorkEventArgs e) { ScheduleM.Appointment appointment = ScheduleM.Appointments.Where(s => !s.StoreInDB).Single(); try { using (me = new MedicalModel(ConfigurationManager.Connect())) { await me.Database.Connection.OpenAsync(); newperson np = new newperson(); int belong; if (appointment.StillNotVisited) { np.PatientNameNP = appointment.PatientName; np.TAJNumberNP = appointment.PatientTajNumber; me.newperson.Add(np); await me.SaveChangesAsync(); belong = np.IdNP; } else { belong = ScheduleM.Patients.Single(p => p.TajNumber == appointment.PatientTajNumber).Id; } scheduleperson_st spst; if (appointment.StillNotVisited) { spst = new scheduleperson_st() { ExistedIdSP = null, NewPersonIdSP = belong }; me.scheduleperson_st.Add(spst); } else if (!me.scheduleperson_st.Any(sc => sc.ExistedIdSP == belong)) { spst = new scheduleperson_st() { ExistedIdSP = belong, NewPersonIdSP = null }; me.scheduleperson_st.Add(spst); } else { spst = me.scheduleperson_st.Single(sc => sc.ExistedIdSP == belong); } await me.SaveChangesAsync(); scheduledata sd = new scheduledata() { StillNotVisitedSD = appointment.StillNotVisited, StartSD = appointment.StartTime, FinishSD = appointment.EndTime, PatientIdSD = spst.IdSP, DoctorIdSD = appointment.DoctorId, NotesSD = appointment.Notes, StatusSD = appointment.Label }; me.scheduledata.Add(sd); await me.SaveChangesAsync(); NewId = sd.IdSD; } workingConn = true; } catch (Exception ex) { Log.WriteException(ex); workingConn = false; } }
private async void ExecuteDoWork(object sender, DoWorkEventArgs e) { try { using (me = new MedicalModel(ConfigurationManager.Connect())) { await me.Database.Connection.OpenAsync(); if (!newForm) { selected = me.patientdata.Where(a => a.IdPD == selectedId).Single(); } else { selected = new patientdata(); } selected.NamePD = PatientDetailsMViewElements.UserName; if (PatientDetailsMViewElements.BirthName != null) { selected.BirthNamePD = PatientDetailsMViewElements.BirthName; } selected.GenderPD = PatientDetailsMDataSet.FullGenderList.Where(a => a.DataG == PatientDetailsMViewElements.GenderSelected).Select(a => a.IdG).Single(); selected.MotherNamePD = PatientDetailsMViewElements.MotherName; selected.BirthPlacePD = PatientDetailsMDataSet.FullSettlementList.Where(a => a.DataS == PatientDetailsMViewElements.BirthPlaceSelected).Select(a => a.IdS).Single(); selected.BirthDatePD = (DateTime)PatientDetailsMViewElements.BirthDate; selected.TAJNumberPD = PatientDetailsMViewElements.TajNumber; if (!PatientDetailsMViewElements.TaxNumber.Equals(0)) { selected.TAXNumberPD = PatientDetailsMViewElements.TaxNumber; } selected.ZipCodePD = PatientDetailsMDataSet.FullZipCodeList.Where(a => a.DataZC == PatientDetailsMViewElements.ZipCodeSelected).Select(a => a.IdZC).Single(); selected.SettlementPD = PatientDetailsMDataSet.FullSettlementList.Where(a => a.DataS == PatientDetailsMViewElements.SettlementSelected).Select(a => a.IdS).Single(); selected.AddressPD = PatientDetailsMViewElements.Address; if (PatientDetailsMViewElements.Phone != null) { selected.PhonePD = PatientDetailsMViewElements.Phone; } if (PatientDetailsMViewElements.MobilePhone != null) { selected.MobilePhonePD = PatientDetailsMViewElements.MobilePhone; } if (PatientDetailsMViewElements.Email != null) { selected.EmailPD = PatientDetailsMViewElements.Email; } selected.BillingNamePD = PatientDetailsMViewElements.BillingName; selected.BillingZipCodePD = PatientDetailsMDataSet.FullZipCodeList.Where(a => a.DataZC == PatientDetailsMViewElements.BillingZipCode).Select(a => a.IdZC).Single(); selected.BillingSettlementPD = PatientDetailsMDataSet.FullSettlementList.Where(a => a.DataS == PatientDetailsMViewElements.BillingSettlement).Select(a => a.IdS).Single(); selected.BillingAddressPD = PatientDetailsMViewElements.BillingAddress; if (newForm) { selected.CreatedPD = DateTime.Now; } if (PatientDetailsMViewElements.Notes != null) { selected.NotesPD = PatientDetailsMViewElements.Notes; } if (newForm) { me.patientdata.Add(selected); await me.SaveChangesAsync(); if (me.priviledges.Single(p => p.IdP == GlobalVM.GlobalM.PriviledgeID).IsDoctorP) { me.belong_st.Add(new belong_st() { IdUD = (int)GlobalVM.GlobalM.UserID, IdPD = selected.IdPD, WhenBelongBS = DateTime.Now }); } if (newForm && selectedId != null) { scheduleperson_st sp = me.scheduleperson_st.Single(spd => spd.IdSP == me.scheduledata. FirstOrDefault(sd => sd.IdSD == selectedId).PatientIdSD); me.newperson.Remove(me.newperson.Single(np => np.IdNP == sp.NewPersonIdSP)); sp.NewPersonIdSP = null; sp.ExistedIdSP = selected.IdPD; me.scheduledata.Where(sd => sd.IdSD == selectedId).Single().StillNotVisitedSD = false; } } await me.SaveChangesAsync(); } workingConn = true; } catch (Exception ex) { Log.WriteException(ex); workingConn = false; } }