Exemplo n.º 1
0
        async void ButtonClicked(object sender, EventArgs e)
        {
            Folders parent;
            User    user;

            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
            {
                parent = conn.GetWithChildren <Folders>(note.ParentFolderId);
                user   = conn.GetWithChildren <User>(note.uId);
                if (editing)
                {
                    conn.Delete <Note>(note.Id);
                    user.Notes.Remove(note);
                    parent.Notes.Remove(note);
                }
            }
            note.Name         = TitleEntry.Text;
            note.Description  = DescriptionEntry.Text;
            note.CreationDate = DateTime.Now;

            if (parent.Notes?.Any() == true)
            {
                parent.Notes.Add(note);
            }
            else
            {
                parent.Notes = new List <Note>()
                {
                    note
                };
            }

            if (user.Notes?.Any() == true)
            {
                user.Notes.Add(note);
            }
            else
            {
                user.Notes = new List <Note>()
                {
                    note
                };
            }

            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
            {
                conn.Insert(note);
                conn.UpdateWithChildren(parent);
                conn.UpdateWithChildren(user);
            }
            await Navigation.PopAsync();
        }
Exemplo n.º 2
0
        async void ButtonClicked(object sender, EventArgs e)
        {
            Conditions cond = new Conditions
            {
                Type = ""
            };

            condition.Type = NameEntry.Text;
            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
            {
                conn.CreateTable <Conditions>();
                {
                    try
                    {
                        var c = conn.Query <Conditions>("select * from Conditions where Type=?", condition.Type);
                        cond = conn.GetWithChildren <Conditions>(condition.Type);
                    }
                    catch (Exception f)
                    {
                    }
                }
            }
            if (cond.Type.Equals(""))
            {
                using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                {
                    conn.CreateTable <Conditions>();
                    conn.CreateTable <User>();
                    conn.Insert(condition);
                    conn.UpdateWithChildren(condition);
                    await Navigation.PopModalAsync();
                }
            }
            else
            {
                foreach (User u in cond.Users)
                {
                    if (u.Id == condition.Users[0].Id)
                    {
                        exists = true;
                    }
                }
                if (exists)
                {
                    await DisplayAlert("Oops!", "You already have this condition listed", "OK");
                }
                else
                {
                    cond.Users.Add(condition.Users[0]);
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        conn.CreateTable <Conditions>();
                        conn.UpdateWithChildren(cond);
                    }
                    await Navigation.PopModalAsync();
                }
            }
        }
Exemplo n.º 3
0
        async void ButtonClicked(object sender, EventArgs e)
        {
            bool    exists = false;
            Allergy a      = new Allergy
            {
                Type = ""
            };

            allergy.Type = NameEntry.Text;
            try
            {
                using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                {
                    conn.CreateTable <Allergy>();
                    var allergies = conn.Query <Allergy>("select * from Allergy where Type=?", allergy.Type);
                    a = conn.GetWithChildren <Allergy>(allergy.Type);
                }
            }
            catch (Exception f)
            {
            }
            if (a.Type.Equals(""))
            {
                using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                {
                    conn.CreateTable <Allergy>();
                    conn.CreateTable <User>();
                    conn.Insert(allergy);
                    conn.UpdateWithChildren(allergy);
                }
                await Navigation.PopModalAsync();
            }
            else
            {
                foreach (User u in a.Users)
                {
                    if (u.Id == allergy.Users[0].Id)
                    {
                        exists = true;
                        break;
                    }
                }
                if (exists)
                {
                    await DisplayAlert("Oops!", "You already have this allergy listed", "OK");
                }
                else
                {
                    a.Users.Add(allergy.Users[0]);
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        conn.CreateTable <Allergy>();
                        conn.UpdateWithChildren(a);
                    }
                    await Navigation.PopModalAsync();
                }
            }
        }
Exemplo n.º 4
0
        async void ButtonClicked(object sender, EventArgs e)
        {
            folder.Name         = TitleEntry.Text;
            folder.CreationDate = DateTime.Now;
            Folders parent;
            User    user;

            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
            {
                parent = conn.GetWithChildren <Folders>(folder.ParentFolderId);
                user   = conn.GetWithChildren <User>(folder.uId);
            }

            if (parent.ChildrenFolders?.Any() == true)
            {
                parent.ChildrenFolders.Add(folder);
            }
            else
            {
                parent.ChildrenFolders = new List <Folders>()
                {
                    folder
                };
            }

            if (user.Folds?.Any() == true)
            {
                user.Folds.Add(folder);
            }
            else
            {
                user.Folds = new List <Folders>()
                {
                    folder
                };
            }

            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
            {
                conn.Insert(folder);
                conn.UpdateWithChildren(parent);
                conn.UpdateWithChildren(user);
            }
            await Navigation.PopAsync();
        }
Exemplo n.º 5
0
 public bool UpdateWithChildren(Client obj)
 {
     using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.DB_PATH))
     {
         conn.CreateTable <Client>();
         conn.UpdateWithChildren(obj);
         return(true);
     }
 }
Exemplo n.º 6
0
 public bool UpdateWithChildren(Construction obj)
 {
     using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.DB_PATH))
     {
         conn.CreateTable <Construction>();
         conn.CreateTable <ConstrucionEmployee>();
         conn.UpdateWithChildren(obj);
         return(true);
     }
 }
Exemplo n.º 7
0
        public NoteRoot(int uid)
        {
            InitializeComponent();
            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
            {
                conn.CreateTable <Folders>();
                conn.CreateTable <Note>();
                conn.CreateTable <Doctor>();
                conn.CreateTable <Allergy>();
                conn.CreateTable <Prescription>();
                conn.CreateTable <Vaccine>();
                conn.CreateTable <Appointment>();
                conn.CreateTable <Conditions>();
                conn.CreateTable <UsersDoctors>();
                conn.CreateTable <UsersConditions>();
                conn.CreateTable <UsersAllergies>();
                user = conn.GetWithChildren <User>(uid);
            }
            if (user.Folds.Count == 0)
            {
                folder.Name           = "Root";
                folder.isRoot         = true;
                folder.ParentFolderId = -1;
                folder.uId            = user.Id;
                user.Folds            = new List <Folders>()
                {
                    folder
                };

                using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                {
                    conn.Insert(folder);
                    fo     = conn.Query <Folders>("select * from Folders");
                    folder = fo[0];
                    conn.UpdateWithChildren(user);
                }
            }
            else
            {
                foreach (Folders f in user.Folds)
                {
                    if (f.isRoot == true)
                    {
                        using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                        {
                            folder = conn.GetWithChildren <Folders>(f.Id);
                        }
                        break;
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void OnDelete(object sender, EventArgs e)
        {
            Allergy allergy;
            var     mi = ((MenuItem)sender);

            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
            {
                allergy = conn.GetWithChildren <Allergy>(mi.CommandParameter);
                user    = conn.GetWithChildren <User>(uid);
                conn.Delete(allergy);
                conn.UpdateWithChildren(user);
            }
            OnAppearing();
        }
Exemplo n.º 9
0
        private void OnDelete(object sender, EventArgs e)
        {
            var mi = ((MenuItem)sender);

            Tables.Conditions condition = new Tables.Conditions
            {
            };
            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
            {
                condition = conn.GetWithChildren <Conditions>(mi.CommandParameter);
                user      = conn.GetWithChildren <User>(uid);
                conn.Delete(condition);
                conn.UpdateWithChildren(user);
            }
            OnAppearing();
        }
Exemplo n.º 10
0
        private bool StartRoundPreCheck(ref bool blnSwiss)
        {
            //Make sure we actually have players
            if (objTournMain.Players.Count == 0)
            {
                DisplayAlert("Warning!", "You must add players first to this tournament!", "D'oh!");
                return(false);
            }

            //Housekeeping with the latest round
            if (objTournMain.Rounds.Count > 0)
            {
                //Grab the latest information before checking the scores and calculating them
                using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.DB_PATH))
                {
                    objTournMain = new TournamentMain();
                    objTournMain = conn.GetWithChildren <TournamentMain>(intTournID, true);
                    Utilities.CalculatePlayerScores(ref objTournMain);

                    conn.UpdateWithChildren(objTournMain); //Update any other information that was saved such as Bye counts and such
                }

                TournamentMainRound latestRound = objTournMain.Rounds[objTournMain.Rounds.Count - 1];
                blnSwiss = latestRound.Swiss; //Check if the last round was a Swiss Round or not

                //Before starting a new round, make sure we're not missing any scores
                foreach (TournamentMainRoundTable table in latestRound.Tables)
                {
                    if (!table.Player1Winner && !table.Player2Winner)
                    {
                        DisplayAlert("Warning!", "Verify that all tables are completed for the current round!", "D'oh!");
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 11
0
        private void saveButton_Clicked(object sender, EventArgs e)
        {
            openTournament.Name      = nameEntry.Text;
            openTournament.StartDate = dateEntry.Date;
            if (!string.IsNullOrWhiteSpace(pointMaxEntry.Text))
            {
                openTournament.MaxPoints = Convert.ToInt32(Math.Round(Convert.ToDecimal(pointMaxEntry.Text)));
            }
            if (!string.IsNullOrWhiteSpace(minutesEntry.Text))
            {
                openTournament.RoundTimeLength = Convert.ToInt32(Math.Round(Convert.ToDecimal(minutesEntry.Text)));
            }

            //Check Name
            if (openTournament.Name == null || openTournament.Name.ToString().Trim() == "")
            {
                DisplayAlert("Warning!", "Please enter a tournament name!", "OK");
                return;
            }

            //Check points
            if (openTournament.MaxPoints <= 0)
            {
                DisplayAlert("Warning!", "Please enter a valid point number!", "OK");
                return;
            }

            //Check time
            if (openTournament.RoundTimeLength <= 0)
            {
                DisplayAlert("Warning!", "Please enter a valid round length!", "OK");
                return;
            }

            //Check Date
            try
            {
                DateTime.Parse(openTournament.StartDate.ToString());
            }
            catch
            {
                DisplayAlert("Warning!", "Please enter a valid tournament date!", "OK");
                return;
            }

            //Update database
            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.DB_PATH))
            {
                //Create
                try
                {
                    if (openTournament.Id == 0)
                    {
                        conn.InsertWithChildren(openTournament);
                        DisplayAlert("Success", "Tournament successfully created", "OK");
                    }
                    else
                    {
                        conn.UpdateWithChildren(openTournament);
                        DisplayAlert("Success", "Tournament successfully updated", "OK");
                    }
                }
                catch
                {
                    DisplayAlert("Failure", "An error occurred when creating this tournament", "OK");
                }

                Navigation.PopAsync();
            }
        }
Exemplo n.º 12
0
        async void ButtonClicked(object sender, EventArgs e)
        {
            Doctor doctor  = new Doctor();
            User   user    = new User();
            bool   vExists = false;
            bool   pExists = false;

            appointment.aptDate        = AppointmentDateEntry.Date + AppointmentTimeEntry.Time;
            appointment.reasonForVisit = Reason.Text;
            appointment.diagnosis      = Diagnosis.Text;
            appointment.followUpAdvice = FollowUpRecsEntry.Text;

            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
            {
                doctor = conn.GetWithChildren <Doctor>(appointment.dId);
            }

            //Creates the prescription 0 item to be inserted in the database
            Prescription p0 = new Prescription()
            {
                RxName    = Rx0Name.Text,
                startDate = Rx0StartDate.Date.ToShortDateString(),
                endDate   = Rx0EndDate.Date.ToShortDateString(),
                dId       = doctor.Id,
                uId       = user.Id,
                aId       = appointment.Id
            };
            //Creates the prescription 1 item to be inserted in the database
            Prescription p1 = new Prescription()
            {
                RxName    = Rx1Name.Text,
                startDate = Rx1StartDate.Date.ToShortDateString(),
                endDate   = Rx1EndDate.Date.ToShortDateString(),
                dId       = doctor.Id,
                uId       = user.Id,
                aId       = appointment.Id
            };
            //Creates the prescription 2 item to be inserted in the database
            Prescription p2 = new Prescription()
            {
                RxName    = Rx2Name.Text,
                startDate = Rx2StartDate.Date.ToShortDateString(),
                endDate   = Rx2EndDate.Date.ToShortDateString(),
                dId       = doctor.Id,
                uId       = user.Id,
                aId       = appointment.Id
            };

            //Creates the vaccine 0 item to be inserted in the database
            Vaccine v0 = new Vaccine()
            {
                VaccineName = Vaccine0Name.Text,
                Date        = AppointmentDateEntry.Date.ToShortDateString(),
                dId         = doctor.Id,
                uId         = user.Id,
                aId         = appointment.Id
            };
            //Creates the vaccine 1 item to be inserted in the database
            Vaccine v1 = new Vaccine()
            {
                VaccineName = Vaccine1Name.Text,
                Date        = AppointmentDateEntry.Date.ToShortDateString(),
                dId         = doctor.Id,
                uId         = user.Id,
                aId         = appointment.Id
            };
            //Creates the vaccine 2 item to be inserted in the database
            Vaccine v2 = new Vaccine()
            {
                VaccineName = Vaccine2Name.Text,
                Date        = AppointmentDateEntry.Date.ToShortDateString(),
                dId         = doctor.Id,
                uId         = user.Id,
                aId         = appointment.Id
            };

            //Creates a future appointment for the user
            Appointment fa = new Appointment()
            {
                aptDate      = FollowUpDateEntry.Date.Add(FollowUpTimeEntry.Time),
                reminderTime = FollowUpDateEntry.Date.Add(FollowUpReminderEntry.Time),
                dId          = doctor.Id,
                uId          = user.Id,
                dName        = doctor.dName
            };

            //Creates a reminder notification for a future appointment and submits it to the Android OS to handle
            if (needReminder == true)
            {
                try
                {
                    CrossLocalNotifications.Current.Cancel(appointment.Id);
                }
                catch (Exception err)
                {
                }
                CrossLocalNotifications.Current.Show("Appointment Reminder", "You have an appointment with Dr. " + doctor.dName + " at " + fa.aptDate.ToShortTimeString(), fa.Id, fa.reminderTime);
            }



            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
            {
                user = conn.GetWithChildren <User>(appointment.uId);
                for (int i = 0; i < user.Appointments.Count; i++)
                {
                    if (user.Appointments[i].Id == appointment.Id)
                    {
                        user.Appointments.RemoveAt(i);
                        break;
                    }
                }
                if (user.Appointments == null)
                {
                    user.Appointments = new List <Appointment>
                    {
                        appointment
                    };
                }
                else
                {
                    user.Appointments.Add(appointment);
                }
                doctor = conn.GetWithChildren <Doctor>(appointment.dId);
                for (int i = 0; i < doctor.Appointments.Count; i++)
                {
                    if (doctor.Appointments[i].Id == appointment.Id)
                    {
                        doctor.Appointments.RemoveAt(i);
                        break;
                    }
                }
                if (doctor.Appointments == null)
                {
                    doctor.Appointments = new List <Appointment>
                    {
                        appointment
                    };
                }
                else
                {
                    doctor.Appointments.Add(appointment);
                }
            }
            //Checks if the first prescription has a null value
            if (!(p0.RxName.Equals("")))
            {
                if (!(appointment.Prescriptions == null))
                {
                    foreach (Prescription vax in appointment.Prescriptions)
                    {
                        if (vax.RxName.Equals(p0.RxName))
                        {
                            pExists = true;
                            break;
                        }
                    }
                }

                if (!pExists)
                {
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        //Ignored if the table already exists
                        conn.CreateTable <Prescription>();
                        conn.Insert(p0);
                    }
                    //If the prescription has a name, check to see if the user already has a log of said prescription
                    //If they do, then just change the end date
                    if (user.Prescriptions != null)
                    {
                        foreach (Prescription rx in user.Prescriptions)
                        {
                            if (rx.RxName.Equals(p0.RxName))
                            {
                                p0renew    = true;
                                rx.endDate = p0.endDate;
                            }
                        }
                        if (p0renew == false)
                        {
                            user.Prescriptions.Add(p0);
                        }
                    }
                    //Otherwise, add the prescription to the user's list
                    else
                    {
                        user.Prescriptions = new List <Prescription>
                        {
                            p0
                        };
                    }
                    //Add the prescription to the doctor's list
                    if (doctor.Prescriptions == null)
                    {
                        doctor.Prescriptions = new List <Prescription>
                        {
                            p0
                        };
                    }
                    else
                    {
                        doctor.Prescriptions.Add(p0);
                    }

                    if (appointment.Prescriptions == null)
                    {
                        appointment.Prescriptions = new List <Prescription>
                        {
                            p0
                        };
                    }
                    else
                    {
                        appointment.Prescriptions.Add(p0);
                    }
                }
            }
            if (!(p1.RxName.Equals("")))
            {
                pExists = false;
                if (!(appointment.Prescriptions == null))
                {
                    foreach (Prescription vax in appointment.Prescriptions)
                    {
                        if (vax.RxName.Equals(p1.RxName))
                        {
                            pExists = true;
                            break;
                        }
                    }
                }

                if (!pExists)
                {
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        //Ignored if the table already exists
                        conn.CreateTable <Prescription>();
                        conn.Insert(p1);
                    }
                    //If the prescription has a name, check to see if the user already has a log of said prescription
                    //If they do, then just change the end date
                    if (user.Prescriptions != null)
                    {
                        foreach (Prescription rx in user.Prescriptions)
                        {
                            if (rx.RxName.Equals(p1.RxName))
                            {
                                p1renew    = true;
                                rx.endDate = p1.endDate;
                            }
                        }
                        if (p1renew == false)
                        {
                            user.Prescriptions.Add(p1);
                        }
                    }
                    //Otherwise, add the prescription to the user's list
                    else
                    {
                        user.Prescriptions = new List <Prescription>
                        {
                            p1
                        };
                    }
                    //Add the prescription to the doctor's list
                    if (doctor.Prescriptions == null)
                    {
                        doctor.Prescriptions = new List <Prescription>
                        {
                            p1
                        };
                    }
                    else
                    {
                        doctor.Prescriptions.Add(p1);
                    }


                    if (appointment.Prescriptions == null)
                    {
                        appointment.Prescriptions = new List <Prescription>
                        {
                            p1
                        };
                    }
                    else
                    {
                        appointment.Prescriptions.Add(p1);
                    }
                }
            }
            if (!(p2.RxName.Equals("")))
            {
                pExists = false;
                if (!(appointment.Prescriptions == null))
                {
                    foreach (Prescription vax in appointment.Prescriptions)
                    {
                        if (vax.RxName.Equals(p2.RxName))
                        {
                            pExists = true;
                            break;
                        }
                    }
                }

                if (!pExists)
                {
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        //Ignored if the table already exists
                        conn.CreateTable <Prescription>();
                        conn.Insert(p2);
                    }
                    //If the prescription has a name, check to see if the user already has a log of said prescription
                    //If they do, then just change the end date
                    if (user.Prescriptions != null)
                    {
                        foreach (Prescription rx in user.Prescriptions)
                        {
                            if (rx.RxName.Equals(p2.RxName))
                            {
                                p2renew    = true;
                                rx.endDate = p2.endDate;
                            }
                        }
                        if (p2renew == false)
                        {
                            user.Prescriptions.Add(p2);
                        }
                    }
                    //Otherwise, add the prescription to the user's list
                    else
                    {
                        user.Prescriptions = new List <Prescription>
                        {
                            p2
                        };
                    }
                    //Add the prescription to the doctor's list
                    if (doctor.Prescriptions == null)
                    {
                        doctor.Prescriptions = new List <Prescription>
                        {
                            p2
                        };
                    }
                    else
                    {
                        doctor.Prescriptions.Add(p2);
                    }

                    if (appointment.Prescriptions == null)
                    {
                        appointment.Prescriptions = new List <Prescription>
                        {
                            p2
                        };
                    }
                    else
                    {
                        appointment.Prescriptions.Add(p2);
                    }
                }
            }

            if (!(v0.VaccineName.Equals("")))
            {
                if (!(appointment.Vaccines == null))
                {
                    foreach (Vaccine vax in appointment.Vaccines)
                    {
                        if (vax.VaccineName.Equals(v0.VaccineName))
                        {
                            vExists = true;
                            break;
                        }
                    }
                }


                if (!vExists)
                {
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        //Ignored if the table already exists
                        conn.CreateTable <Vaccine>();
                        conn.Insert(v0);
                    }
                    if (user.Vaccines != null)
                    {
                        user.Vaccines.Add(v0);
                    }
                    else
                    {
                        user.Vaccines = new List <Vaccine>
                        {
                            v0
                        };
                    }

                    if (appointment.Vaccines != null)
                    {
                        appointment.Vaccines.Add(v0);
                    }
                    else
                    {
                        appointment.Vaccines = new List <Vaccine>
                        {
                            v0
                        };
                    }

                    if (doctor.Vaccines != null)
                    {
                        doctor.Vaccines.Add(v0);
                    }
                    else
                    {
                        doctor.Vaccines = new List <Vaccine>
                        {
                            v0
                        };
                    }
                }
            }
            if (!(v1.VaccineName.Equals("")))
            {
                vExists = false;
                if (!(appointment.Vaccines == null))
                {
                    foreach (Vaccine vax in appointment.Vaccines)
                    {
                        if (vax.VaccineName.Equals(v1.VaccineName))
                        {
                            vExists = true;
                            break;
                        }
                    }
                }

                if (!vExists)
                {
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        //Ignored if the table already exists
                        conn.CreateTable <Vaccine>();
                        conn.Insert(v1);
                    }

                    if (user.Vaccines != null)
                    {
                        user.Vaccines.Add(v1);
                    }
                    else
                    {
                        user.Vaccines = new List <Vaccine>
                        {
                            v1
                        };
                    }
                    if (appointment.Vaccines != null)
                    {
                        appointment.Vaccines.Add(v1);
                    }
                    else
                    {
                        appointment.Vaccines = new List <Vaccine>
                        {
                            v1
                        };
                    }
                    if (doctor.Vaccines != null)
                    {
                        doctor.Vaccines.Add(v1);
                    }
                    else
                    {
                        doctor.Vaccines = new List <Vaccine>
                        {
                            v1
                        };
                    }
                }
            }
            if (!(v2.VaccineName.Equals("")))
            {
                vExists = false;
                if (!(appointment.Vaccines == null))
                {
                    foreach (Vaccine vax in appointment.Vaccines)
                    {
                        if (vax.VaccineName.Equals(v0.VaccineName))
                        {
                            vExists = true;
                            break;
                        }
                    }
                }


                if (!vExists)
                {
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        //Ignored if the table already exists
                        conn.CreateTable <Vaccine>();
                        conn.Insert(v2);
                    }

                    if (user.Vaccines != null)
                    {
                        user.Vaccines.Add(v2);
                    }
                    else
                    {
                        user.Vaccines = new List <Vaccine>
                        {
                            v2
                        };
                    }
                    if (appointment.Vaccines != null)
                    {
                        appointment.Vaccines.Add(v2);
                    }
                    else
                    {
                        appointment.Vaccines = new List <Vaccine>
                        {
                            v2
                        };
                    }
                    if (doctor.Vaccines != null)
                    {
                        doctor.Vaccines.Add(v2);
                    }
                    else
                    {
                        doctor.Vaccines = new List <Vaccine>
                        {
                            v2
                        };
                    }
                }
            }
            if (t6)
            {
                using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                {
                    conn.CreateTable <Appointment>();
                    conn.Insert(fa);
                }

                if (user.Appointments != null)
                {
                    user.Appointments.Add(fa);
                }
                else
                {
                    user.Appointments = new List <Appointment>
                    {
                        fa
                    };
                }

                if (doctor.Appointments != null)
                {
                    doctor.Appointments.Add(fa);
                }
                else
                {
                    doctor.Appointments = new List <Appointment>
                    {
                        fa
                    };
                }
            }
            //Adds the appointment to the database
            //updates the user with its new appointment info
            //Updates the doctor with its new appointment info
            using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
            {
                //Ignored if the table already exists
                conn.CreateTable <Appointment>();
                conn.CreateTable <Doctor>();
                conn.CreateTable <User>();
                conn.UpdateWithChildren(appointment);
                conn.UpdateWithChildren(user);
                conn.UpdateWithChildren(doctor);
                await Navigation.PopModalAsync();
            }
        }
Exemplo n.º 13
0
        async void ButtonClicked(object sender, EventArgs e)
        {
            if (doctor.dName.Equals("12345"))
            {
                await DisplayAlert("Oops!", "Your need to choose a doctor", "OK");
            }
            else
            {
                //Creates the appointment item to be inserted in the database
                Appointment appointment = new Appointment()
                {
                    aptDate        = AppointmentDateEntry.Date.Add(AppointmentTimeEntry.Time),
                    reasonForVisit = Reason.Text,
                    diagnosis      = Diagnosis.Text,
                    followUpAdvice = FollowUpRecsEntry.Text,
                    uId            = user.Id,
                    dName          = doctor.dName
                };

                using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                {
                    doctor = conn.Query <Doctor>("select * from Doctor where dName=?", doctor.dName)[0];
                    doctor = conn.GetWithChildren <Doctor>(doctor.Id);
                }
                appointment.dId = doctor.Id;

                //Creates the prescription 0 item to be inserted in the database
                Prescription p0 = new Prescription()
                {
                    RxName       = Rx0Name.Text,
                    startDate    = Rx0StartDate.Date.ToShortDateString(),
                    endDate      = Rx0EndDate.Date.ToShortDateString(),
                    reminderTime = Rx0StartDate.Date + Rx0ReminderEntry.Time,
                    dId          = doctor.Id,
                    uId          = user.Id,
                    aId          = appointment.Id
                };
                if (t0)
                {   //Set up notifications for the prescription reminder
                    PrescriptionNotifClass.PrescriptionNotifHandler(p0);
                }
                //Creates the prescription 1 item to be inserted in the database
                Prescription p1 = new Prescription()
                {
                    RxName       = Rx1Name.Text,
                    startDate    = Rx1StartDate.Date.ToShortDateString(),
                    endDate      = Rx1EndDate.Date.ToShortDateString(),
                    reminderTime = Rx0StartDate.Date + Rx0ReminderEntry.Time,
                    dId          = doctor.Id,
                    uId          = user.Id,
                    aId          = appointment.Id
                };
                if (t1)
                {   //Set up notifications for the prescription reminder
                    PrescriptionNotifClass.PrescriptionNotifHandler(p0);
                }
                //Creates the prescription 2 item to be inserted in the database
                Prescription p2 = new Prescription()
                {
                    RxName       = Rx2Name.Text,
                    startDate    = Rx2StartDate.Date.ToShortDateString(),
                    endDate      = Rx2EndDate.Date.ToShortDateString(),
                    reminderTime = Rx1StartDate.Date + Rx1ReminderEntry.Time,
                    dId          = doctor.Id,
                    uId          = user.Id,
                    aId          = appointment.Id
                };
                if (t2)
                {   //Set up notifications for the prescription reminder
                    PrescriptionNotifClass.PrescriptionNotifHandler(p2);
                }
                //Creates the vaccine 0 item to be inserted in the database
                Vaccine v0 = new Vaccine()
                {
                    VaccineName = Vaccine0Name.Text,
                    Date        = AppointmentDateEntry.Date.ToShortDateString(),
                    dId         = doctor.Id,
                    uId         = user.Id,
                    aId         = appointment.Id,
                };
                //Creates the vaccine 1 item to be inserted in the database
                Vaccine v1 = new Vaccine()
                {
                    VaccineName = Vaccine1Name.Text,
                    Date        = AppointmentDateEntry.Date.ToShortDateString(),
                    dId         = doctor.Id,
                    uId         = user.Id,
                    aId         = appointment.Id
                };
                //Creates the vaccine 2 item to be inserted in the database
                Vaccine v2 = new Vaccine()
                {
                    VaccineName = Vaccine2Name.Text,
                    Date        = AppointmentDateEntry.Date.ToShortDateString(),
                    dId         = doctor.Id,
                    uId         = user.Id,
                    aId         = appointment.Id
                };

                //Creates a future appointment for the user
                Appointment fa = new Appointment()
                {
                    aptDate      = FollowUpDateEntry.Date.Add(FollowUpTimeEntry.Time),
                    reminderTime = FollowUpDateEntry.Date.Add(FollowUpReminderEntry.Time),
                    dId          = doctor.Id,
                    uId          = user.Id,
                    dName        = doctor.dName
                };

                //Creates a reminder notification for a future appointment and submits it to the Android OS to handle
                if (needReminder == true)
                {
                    CrossLocalNotifications.Current.Show("Appointment Reminder", "You have an appointment with Dr. " + doctor.dName + " at " + fa.aptDate.ToShortTimeString(), fa.Id, fa.reminderTime);
                }

                //Adds the appointment to the user's appointment list
                if (user.Appointments == null)
                {
                    user.Appointments = new List <Appointment>
                    {
                        appointment
                    };
                }
                else
                {
                    user.Appointments.Add(appointment);
                }

                //Adds the appointment to the doctor's appointment list
                if (doctor.Appointments == null)
                {
                    doctor.Appointments = new List <Appointment>
                    {
                        appointment
                    };
                }
                else
                {
                    doctor.Appointments.Add(appointment);
                }

                //Checks if the first prescription has a null value
                if (!(p0.RxName.Equals("")))
                {
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        //Ignored if the table already exists
                        conn.CreateTable <Prescription>();
                        conn.Insert(p0);
                    }
                    //If the prescription has a name, check to see if the user already has a log of said prescription
                    //If they do, then just change the end date
                    if (user.Prescriptions != null)
                    {
                        foreach (Prescription rx in user.Prescriptions)
                        {
                            if (rx.RxName.Equals(p0.RxName))
                            {
                                p0renew    = true;
                                rx.endDate = p0.endDate;
                            }
                        }
                        if (p0renew == false)
                        {
                            user.Prescriptions.Add(p0);
                        }
                    }
                    //Otherwise, add the prescription to the user's list
                    else
                    {
                        user.Prescriptions = new List <Prescription>
                        {
                            p0
                        };
                    }
                    //Add the prescription to the doctor's list
                    if (doctor.Prescriptions == null)
                    {
                        doctor.Prescriptions = new List <Prescription>
                        {
                            p0
                        };
                    }
                    else
                    {
                        doctor.Prescriptions.Add(p0);
                    }

                    if (appointment.Prescriptions == null)
                    {
                        appointment.Prescriptions = new List <Prescription>
                        {
                            p0
                        };
                    }
                    else
                    {
                        appointment.Prescriptions.Add(p0);
                    }
                }
                if (!(p1.RxName.Equals("")))
                {
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        //Ignored if the table already exists
                        conn.CreateTable <Prescription>();
                        conn.Insert(p1);
                    }
                    //If the prescription has a name, check to see if the user already has a log of said prescription
                    //If they do, then just change the end date
                    if (user.Prescriptions != null)
                    {
                        foreach (Prescription rx in user.Prescriptions)
                        {
                            if (rx.RxName.Equals(p1.RxName))
                            {
                                p1renew    = true;
                                rx.endDate = p1.endDate;
                            }
                        }
                        if (p1renew == false)
                        {
                            user.Prescriptions.Add(p1);
                        }
                    }
                    //Otherwise, add the prescription to the user's list
                    else
                    {
                        user.Prescriptions = new List <Prescription>
                        {
                            p1
                        };
                    }
                    //Add the prescription to the doctor's list
                    if (doctor.Prescriptions == null)
                    {
                        doctor.Prescriptions = new List <Prescription>
                        {
                            p1
                        };
                    }
                    else
                    {
                        doctor.Prescriptions.Add(p1);
                    }
                    if (appointment.Prescriptions == null)
                    {
                        appointment.Prescriptions = new List <Prescription>
                        {
                            p1
                        };
                    }
                    else
                    {
                        appointment.Prescriptions.Add(p1);
                    }
                }
                if (!(p2.RxName.Equals("")))
                {
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        //Ignored if the table already exists
                        conn.CreateTable <Prescription>();
                        conn.Insert(p2);
                    }
                    //If the prescription has a name, check to see if the user already has a log of said prescription
                    //If they do, then just change the end date
                    if (user.Prescriptions != null)
                    {
                        foreach (Prescription rx in user.Prescriptions)
                        {
                            if (rx.RxName.Equals(p2.RxName))
                            {
                                p2renew    = true;
                                rx.endDate = p2.endDate;
                            }
                        }
                        if (p2renew == false)
                        {
                            user.Prescriptions.Add(p2);
                        }
                    }
                    //Otherwise, add the prescription to the user's list
                    else
                    {
                        user.Prescriptions = new List <Prescription>
                        {
                            p2
                        };
                    }
                    //Add the prescription to the doctor's list
                    if (doctor.Prescriptions == null)
                    {
                        doctor.Prescriptions = new List <Prescription>
                        {
                            p2
                        };
                    }
                    else
                    {
                        doctor.Prescriptions.Add(p2);
                    }

                    if (appointment.Prescriptions == null)
                    {
                        appointment.Prescriptions = new List <Prescription>
                        {
                            p2
                        };
                    }
                    else
                    {
                        appointment.Prescriptions.Add(p2);
                    }
                }
                if (!(v0.VaccineName.Equals("")))
                {
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        //Ignored if the table already exists
                        conn.CreateTable <Vaccine>();
                        conn.Insert(v0);
                    }

                    if (user.Vaccines != null)
                    {
                        user.Vaccines.Add(v0);
                    }
                    else
                    {
                        user.Vaccines = new List <Vaccine>
                        {
                            v0
                        };
                    }

                    if (appointment.Vaccines != null)
                    {
                        appointment.Vaccines.Add(v0);
                    }
                    else
                    {
                        appointment.Vaccines = new List <Vaccine>
                        {
                            v0
                        };
                    }

                    if (doctor.Vaccines != null)
                    {
                        doctor.Vaccines.Add(v0);
                    }
                    else
                    {
                        doctor.Vaccines = new List <Vaccine>
                        {
                            v0
                        };
                    }
                }
                if (!(v1.VaccineName.Equals("")))
                {
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        //Ignored if the table already exists
                        conn.CreateTable <Vaccine>();
                        conn.Insert(v1);
                    }

                    if (user.Vaccines != null)
                    {
                        user.Vaccines.Add(v1);
                    }
                    else
                    {
                        user.Vaccines = new List <Vaccine>
                        {
                            v1
                        };
                    }
                    appointment.Vaccines.Add(v1);

                    if (doctor.Vaccines != null)
                    {
                        doctor.Vaccines.Add(v1);
                    }
                    else
                    {
                        doctor.Vaccines = new List <Vaccine>
                        {
                            v1
                        };
                    }
                }
                if (!(v2.VaccineName.Equals("")))
                {
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        //Ignored if the table already exists
                        conn.CreateTable <Vaccine>();
                        conn.Insert(v2);
                    }

                    if (user.Vaccines != null)
                    {
                        user.Vaccines.Add(v2);
                    }
                    else
                    {
                        user.Vaccines = new List <Vaccine>
                        {
                            v2
                        };
                    }
                    appointment.Vaccines.Add(v2);
                    if (doctor.Vaccines != null)
                    {
                        doctor.Vaccines.Add(v2);
                    }
                    else
                    {
                        doctor.Vaccines = new List <Vaccine>
                        {
                            v2
                        };
                    }
                }
                if (t6)
                {
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        conn.CreateTable <Appointment>();
                        conn.InsertWithChildren(fa);
                    }

                    if (user.Appointments != null)
                    {
                        user.Appointments.Add(fa);
                    }
                    else
                    {
                        user.Appointments = new List <Appointment>
                        {
                            fa
                        };
                    }

                    if (doctor.Appointments != null)
                    {
                        doctor.Appointments.Add(fa);
                    }
                    else
                    {
                        doctor.Appointments = new List <Appointment>
                        {
                            fa
                        };
                    }
                }
                //Adds the appointment to the database
                //updates the user with its new appointment info
                //Updates the doctor with its new appointment info
                using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                {
                    //Ignored if the table already exists
                    conn.CreateTable <Appointment>();
                    conn.CreateTable <Doctor>();
                    conn.CreateTable <User>();
                    conn.InsertWithChildren(appointment);
                    conn.UpdateWithChildren(user);
                    conn.UpdateWithChildren(doctor);
                }
                await Navigation.PopModalAsync();
            }
        }
Exemplo n.º 14
0
        //Completes the forum necessary to add a new doctor to the list
        async void ButtonClicked(object sender, EventArgs e)
        {
            Doctor  doc;
            Boolean duexists = false;
            Boolean dexists  = false;
            Doctor  doctor   = new Doctor()
            {
                dName     = NameEntry.Text,
                dPractice = PracticeEntry.Text,
                dType     = TypeEntry.Text,
                dAddress  = AddressEntry.Text,
                dPhone    = PhoneEntry.Text,
                dEmail    = EmailEntry.Text
            };

            doctor.dAddress = doctor.dAddress + " " + StateEntry.Text + " " + ZipCodeEntry.Text;

            //Only adds the document to the database if it has a valid marker for the Doctor's name
            if (doctor.dName.Equals(""))
            {
                await DisplayAlert("Oops!", "Your doctor needs to have a name", "OK");
            }
            else if (doctor.dPractice.Equals(""))
            {
                await DisplayAlert("Oops!", "Your doctor needs to have a practice", "OK");
            }
            else
            {
                //Checks to see whether the doctor already exists
                using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                {
                    conn.CreateTable <Doctor>();
                    var doctors = conn.Query <Doctor>("select * from Doctor where dName=?", doctor.dName);
                    //If the doctor already exists, then make sure that the user accessing this doesn't already see that doctor
                    if (doctors?.Any() == true)
                    {
                        doc     = conn.GetWithChildren <Doctor>(doctors[0].Id);
                        dexists = true;
                        foreach (User u in doc.Users)
                        {
                            if (u.Name.Equals(user.Name))
                            {
                                duexists = true;
                            }
                        }
                    }
                }

                //If the doctor-user combination already exists, then display an alert
                if (duexists)
                {
                    await DisplayAlert("Uh-oh!", user.Name + " already sees " + doctor.dName, "OK");
                }

                //If the doctor already exists, but not the doctor-user combination,
                //Then add the user to the doctor's list of patients,
                //and add the doctor to the user's list of doctors
                //Also adds the user's id and the doctor's id to the usersdoctors table required for a manytomany relationship

                //This iterates through a for loop, because it contains a list. But realistically,
                //it will never return a list of a value greater or less than 1
                else if (dexists)
                {
                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        conn.CreateTable <Doctor>();
                        conn.CreateTable <User>();
                        conn.CreateTable <UsersDoctors>();
                        var doctors = conn.Query <Doctor>("select * from Doctor where dName=? AND dPractice=?", doctor.dName, doctor.dPractice);
                        doc = conn.GetWithChildren <Doctor>(doctors[0].Id);
                        doc.Users.Add(user);
                        conn.UpdateWithChildren(doc);
                    }
                    await Navigation.PopModalAsync();
                }
                else
                {
                    doctor.Users = new List <User>
                    {
                    };
                    doctor.Appointments = new List <Appointment>
                    {
                    };
                    doctor.Prescriptions = new List <Prescription>
                    {
                    };
                    doctor.Users.Add(user);


                    using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath))
                    {
                        //Ignored if the table already exists
                        conn.CreateTable <Doctor>();
                        conn.CreateTable <User>();
                        conn.CreateTable <UsersDoctors>();
                        conn.CreateTable <Appointment>();
                        conn.CreateTable <Prescription>();
                        conn.Insert(doctor);
                        conn.UpdateWithChildren(doctor);
                    }
                    await Navigation.PopModalAsync();
                }
            }
        }