Exemple #1
0
        private void submitButton_Clicked(object sender, EventArgs e)
        {
            // Get information from page
            string newBreakfastNotes = breakfastNotes.Text;
            string newLunchNotes     = lunchNotes.Text;
            string newDinnerNotes    = dinnerNotes.Text;
            string newOtherNotes     = otherNotes.Text;
            string newDayState       = "";

            if (goodDay.IsChecked)
            {
                newDayState = "good";
            }
            else if (avgDay.IsChecked)
            {
                newDayState = "avg";
            }
            else if (badDay.IsChecked)
            {
                newDayState = "bad";
            }



            // Create or update log
            if (isInitializedLog)
            {
                foundLogs = App.DatabaseAccess.FindOwnThingLog(logDate);

                foundLogs[0].breakfastNotes = newBreakfastNotes;
                foundLogs[0].lunchNotes     = newLunchNotes;
                foundLogs[0].dinnerNotes    = newDinnerNotes;
                foundLogs[0].otherNotes     = newOtherNotes;
                foundLogs[0].dayState       = newDayState;

                App.DatabaseAccess.UpdateOwnThingLog(foundLogs[0]);
                Console.WriteLine("Updated old log");
            }

            else
            {
                OwnThingLogInfo newLog = new OwnThingLogInfo
                {
                    date           = logDate,
                    isInitialized  = true,
                    breakfastNotes = newBreakfastNotes,
                    lunchNotes     = newLunchNotes,
                    dinnerNotes    = newDinnerNotes,
                    otherNotes     = newOtherNotes,
                    dayState       = newDayState
                };

                isInitializedLog = true;

                App.DatabaseAccess.CreateOwnThingLog(newLog);
                Console.WriteLine("Created new log");
            }
        }
        public void UpdateOwnThingLog(OwnThingLogInfo newLog)
        {
            try
            {
                conn.Update(newLog);
            }

            catch (Exception ex)
            {
                Console.WriteLine($"Failed to update own thing log.\nError message: {ex}");
            }
        }
        public void CreateOwnThingLog(OwnThingLogInfo newLog)
        {
            try
            {
                conn.Insert(newLog);
            }

            catch (Exception ex)
            {
                Console.WriteLine($"Failed to create new own thing log.\nError message: {ex}");
            }
        }