Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        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;
                }
            }
        }