Exemplo n.º 1
0
        //add to startup: query for every email address from SettingsDB
        public void startUp()
        {
            settingsDataBase settings = new settingsDataBase();


            settingsItem setItem = settings.GetSetting(PCLMechanics.SQLNames.TherapistEmail.ToString());

            if (setItem != null)
            {
                rawData.therapistEmailAd = setItem.Value;
            }

            #region AdditionalEmail

            setItem = settings.GetSetting(PCLMechanics.SQLNames.Contact1.ToString());

            if (setItem != null)
            {
                rawData.contact1 = setItem.Value;
            }

            setItem = settings.GetSetting(PCLMechanics.SQLNames.Contact2.ToString());

            if (setItem != null)
            {
                rawData.contact2 = setItem.Value;
            }

            setItem = settings.GetSetting(PCLMechanics.SQLNames.Contact3.ToString());

            if (setItem != null)
            {
                rawData.contact3 = setItem.Value;
            }

            setItem = settings.GetSetting(PCLMechanics.SQLNames.Contact4.ToString());

            if (setItem != null)
            {
                rawData.contact4 = setItem.Value;
            }

            setItem = settings.GetSetting(PCLMechanics.SQLNames.Contact5.ToString());

            if (setItem != null)
            {
                rawData.contact5 = setItem.Value;
            }

            #endregion AdditionalEmail

            #region Notifications

            setItem = settings.GetSetting(PCLMechanics.SQLNames.Notifications.ToString());

            if (setItem != null)
            {
                rawData.notificationstate = setItem.Value == "True" ? true : false;
            }


            setItem = settings.GetSetting(PCLMechanics.SQLNames.Medication.ToString());

            if (setItem != null)
            {
                rawData.Medication = setItem.Value == "True" ? true : false;
            }

            setItem = settings.GetSetting(PCLMechanics.SQLNames.Eating.ToString());

            if (setItem != null)
            {
                rawData.Eating = setItem.Value == "True" ? true : false;
            }

            setItem = settings.GetSetting(PCLMechanics.SQLNames.Sleeping.ToString());

            if (setItem != null)
            {
                rawData.Sleeping = setItem.Value == "True" ? true : false;
            }

            setItem = settings.GetSetting(PCLMechanics.SQLNames.Journal.ToString());

            if (setItem != null)
            {
                rawData.Journal = setItem.Value == "True" ? true : false;
            }

            #endregion Notifications


            #region Data

            setItem = settings.GetSetting(PCLMechanics.SQLNames.SleepHours.ToString());
            if (setItem != null)
            {
                rawData.sleepHours = setItem.Value;
            }


            setItem = settings.GetSetting(PCLMechanics.SQLNames.Mania.ToString());
            if (setItem != null)
            {
                rawData.maniaVal = int.Parse(setItem.Value);
            }


            setItem = settings.GetSetting(PCLMechanics.SQLNames.Depression.ToString());
            if (setItem != null)
            {
                rawData.depressionVal = int.Parse(setItem.Value);
            }


            setItem = settings.GetSetting(PCLMechanics.SQLNames.WakeTime.ToString());
            if (setItem != null)
            {
                rawData.WakeTimes = TimeSpan.Parse(setItem.Value);
            }


            setItem = settings.GetSetting(PCLMechanics.SQLNames.EatTime.ToString());
            if (setItem != null)
            {
                rawData.EatTime = TimeSpan.Parse(setItem.Value);
            }
            #endregion Data
        }
        protected override void OnDisappearing()
        {
            settingsDataBase settings = new settingsDataBase();

            #region SleepHours

            settingsItem sleepItem = settings.GetSetting(PCLMechanics.SQLNames.SleepHours.ToString());

            if (sleepItem != null)
            {
                sleepItem.Value = rawData.sleepHours;

                settings.AddSetting(sleepItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.SleepHours.ToString(), Value = rawData.sleepHours
                });
            }

            #endregion SleepHours

            #region Mania

            settingsItem maniaItem = settings.GetSetting(PCLMechanics.SQLNames.Mania.ToString());
            if (maniaItem != null)
            {
                maniaItem.Value = rawData.maniaVal.ToString();

                settings.AddSetting(maniaItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.Mania.ToString(), Value = rawData.maniaVal.ToString()
                });
            }

            #endregion Mania

            #region Depression

            settingsItem depressItem = settings.GetSetting(PCLMechanics.SQLNames.Depression.ToString());
            if (depressItem != null)
            {
                depressItem.Value = rawData.depressionVal.ToString();

                settings.AddSetting(depressItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.Depression.ToString(), Value = rawData.depressionVal.ToString()
                });
            }

            #endregion Depression

            base.OnDisappearing();
        }
        protected override void OnDisappearing()
        {
            settingsDataBase settings = new settingsDataBase();

            settingsItem setItem = new settingsItem();

            #region Email

            #region TherapistEmail
            setItem = settings.GetSetting((int)PCLMechanics.SQLNames.TherapistEmail);

            if (setItem != null)
            {
                setItem.Value = rawData.therapistEmailAd;

                settings.AddSetting(setItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.TherapistEmail.ToString(), Value = rawData.therapistEmailAd
                });
            }
            #endregion TherapistEmail

            #region ContactEmail

            setItem = settings.GetSetting(PCLMechanics.SQLNames.Contact1.ToString());

            if (setItem != null)
            {
                setItem.Value = rawData.contact1;

                settings.AddSetting(setItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.Contact1.ToString(), Value = rawData.contact1
                });
            }

            setItem = settings.GetSetting(PCLMechanics.SQLNames.Contact2.ToString());

            if (setItem != null)
            {
                setItem.Value = rawData.contact2;

                settings.AddSetting(setItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.Contact2.ToString(), Value = rawData.contact2
                });
            }

            setItem = settings.GetSetting(PCLMechanics.SQLNames.Contact3.ToString());

            if (setItem != null)
            {
                setItem.Value = rawData.contact3;

                settings.AddSetting(setItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.Contact3.ToString(), Value = rawData.contact3
                });
            }

            setItem = settings.GetSetting(PCLMechanics.SQLNames.Contact4.ToString());

            if (setItem != null)
            {
                setItem.Value = rawData.contact4;

                settings.AddSetting(setItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.Contact4.ToString(), Value = rawData.contact4
                });
            }

            setItem = settings.GetSetting(PCLMechanics.SQLNames.Contact5.ToString());

            if (setItem != null)
            {
                setItem.Value = rawData.contact5;

                settings.AddSetting(setItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.Contact5.ToString(), Value = rawData.contact5
                });
            }



            #endregion ContactEmail

            #endregion Email


            #region savingNotifications

            //All settings
            setItem = settings.GetSetting(PCLMechanics.SQLNames.Notifications.ToString());

            if (setItem != null)
            {
                setItem.Value = rawData.notificationstate ? "True" : "False";

                settings.AddSetting(setItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.Notifications.ToString(), Value = rawData.notificationstate ? "True" : "False"
                });
            }

            //medication
            setItem = settings.GetSetting(PCLMechanics.SQLNames.Medication.ToString());

            if (setItem != null)
            {
                setItem.Value = rawData.Medication ? "True" : "False";

                settings.AddSetting(setItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.Medication.ToString(), Value = rawData.Medication ? "True" : "False"
                });
            }

            //Eating
            setItem = settings.GetSetting(PCLMechanics.SQLNames.Eating.ToString());

            if (setItem != null)
            {
                setItem.Value = rawData.Eating ? "True" : "False";

                settings.AddSetting(setItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.Eating.ToString(), Value = rawData.Eating ? "True" : "False"
                });
            }

            //Sleeping
            setItem = settings.GetSetting(PCLMechanics.SQLNames.Sleeping.ToString());

            if (setItem != null)
            {
                setItem.Value = rawData.Sleeping ? "True" : "False";

                settings.AddSetting(setItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.Sleeping.ToString(), Value = rawData.Sleeping ? "True" : "False"
                });
            }

            //Journal
            setItem = settings.GetSetting(PCLMechanics.SQLNames.Journal.ToString());

            if (setItem != null)
            {
                setItem.Value = rawData.Journal ? "True" : "False";

                settings.AddSetting(setItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.Journal.ToString(), Value = rawData.Journal ? "True" : "False"
                });
            }

            #endregion savingNotifications

            #region TimePickers

            //Wake up Time
            setItem = settings.GetSetting(PCLMechanics.SQLNames.WakeTime.ToString());

            if (setItem != null)
            {
                setItem.Value = rawData.WakeTimes.ToString();

                settings.AddSetting(setItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.WakeTime.ToString(), Value = rawData.WakeTimes.ToString()
                });
            }

            //Eating Time
            setItem = settings.GetSetting(PCLMechanics.SQLNames.EatTime.ToString());

            if (setItem != null)
            {
                setItem.Value = rawData.EatTime.ToString();

                settings.AddSetting(setItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.EatTime.ToString(), Value = rawData.EatTime.ToString()
                });
            }


            #endregion TimePickers

            setItem = settings.GetSetting(PCLMechanics.SQLNames.EmailReminder.ToString());

            if (setItem != null)
            {
                setItem.Value = rawData.EmailReminder.ToString();

                settings.AddSetting(setItem);
            }
            else
            {
                settings.AddSetting(new settingsItem {
                    Name = PCLMechanics.SQLNames.EmailReminder.ToString(), Value = rawData.EatTime.ToString()
                });
            }


            NotificationCells.Clear();

            base.OnDisappearing();
        }