Esempio n. 1
0
 private void btnDelete_Click(object sender, RoutedEventArgs e)
 {
     WeightDB wdb = new WeightDB();
     WeightRecord wr = (from rec in wdb.weightrecords where (rec.id == idarray[lbHistory.SelectedIndex]) select rec).First();
     wdb.weightrecords.DeleteOnSubmit(wr);
     wdb.SubmitChanges();
     // Navigate back to main page, chart will update (hitting Back won't work)
     NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
 }
Esempio n. 2
0
        private void btnAccept_Click(object sender, RoutedEventArgs e)
        {
            WeightRecord rec = new WeightRecord();

            // OK to update profile?
            bool isOkToUpdate = true;

            // Validate weigh-in date.
            if (DataValidation.IsValidWeighInDate(dpDate))
            {
                rec.date = (DateTime)dpDate.Value;
                txtDateMsg.Text = "";
            }
            else
            {
                isOkToUpdate = false;
                txtDateMsg.Text = "Invalid date.";
            }

            // Validate start weight.
            if (DataValidation.IsValidWeight(tbWeight))
            {
                rec.weight = Convert.ToDouble(tbWeight.Text);
                txtWeightMsg.Text = "";
            }
            else
            {
                isOkToUpdate = false;
                txtWeightMsg.Text = "Weight must be greater than 0.";
            }

            if (isOkToUpdate)
            {
                // Data has been validated, store in db.
                WeightDB db = new WeightDB();
                rec.daysOut = Convert.ToInt32((rec.date - startDate).TotalDays);
                db.weightrecords.InsertOnSubmit(rec);
                db.SubmitChanges();
                somaAdViewer.StopAds();
                NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            }
        }
Esempio n. 3
0
        public static void UpdateWeightDB(RemoteProfileRecordV2 pr)
        {
            // Load the weight db.
            WeightDB wdb = new WeightDB();
            WeightRecord wr = null;

            try
            {
                // Retrieve the initial weigh-in (isStartWeight is true) and update.
                wr = (from rec in wdb.weightrecords where (rec.isStartWeight) select rec).First();
                wr.weight = pr.startweight;
            }
            catch
            {
                // No existing WeightDB. Insert a new record.
                wr = new WeightRecord();
                wr.date = DailyCalories.GetToday();
                wr.weight = pr.startweight;
                wr.isStartWeight = true;
                wdb.weightrecords.InsertOnSubmit(wr);
            }

            // Submit changes to WeightDB.
            wdb.SubmitChanges();
        }