private void SetDateId(string s)
        {
            DiaryDate diaryDate = new DiaryDate();
            var       task      = Task.Run(async() =>
            {
                diaryDate = await repository.GetDateByString(s);
            });

            task.Wait();
            if (diaryDate != null)
            {
                dateId = diaryDate.DateId;
                // set date rating if in accepted range
                if (diaryDate.Rating >= 1 && diaryDate.Rating <= 5)
                {
                    ratingBar.Rating = (float)diaryDate.Rating;
                }
                else
                {
                    ratingBar.Rating = 0F;
                }
            }
            else
            {
                dateId           = 0;
                ratingBar.Rating = 0F;
            }
        }
Exemple #2
0
        private async void saveButton_Click(object sender, EventArgs e)
        {
            // Check to see if DiaryDate exists for date of this entry. If not, create one
            //DiaryDate diaryDate = await repository.GetDateByString(date);
            //if (diaryDate == null)
            //{
            //    diaryDate.Date = date;
            //    await repository.AddDate(diaryDate);
            //}
            if (dateId == 0)
            {
                DiaryDate diaryDate = new DiaryDate();
                diaryDate.Date = date;
                await repository.AddDate(diaryDate);

                // reassign dateId
                diaryDate = await repository.GetDateByString(date);

                dateId = diaryDate.DateId;
            }
            // build full date
            DateTime fullDate = DateTime.ParseExact(date.PadLeft(10, Convert.ToChar("0")) + " " + hour + ":" + minute, "MM/dd/yyyy HH:mm", null);

            // Assign new entry details
            Entry entry = new Entry();

            entry.EntryDate   = fullDate;
            entry.EntryDateId = dateId;
            entry.Description = descriptionText.Text;
            entry.Quantity    = Convert.ToInt32(quantityText.Text);
            if (foodRadioButton.Checked)
            {
                entry.EntryType = 0;
            }
            else if (eventRadioButton.Checked)
            {
                entry.EntryType = 1;
            }

            // Insert new entry and finish activity
            await repository.AddEntry(entry);

            Toast.MakeText(this, "Entry added!", ToastLength.Short).Show();
            Finish();
        }
        //private async void insertButton_Click(object sender, EventArgs e)
        //{
        //    var newEntry = new Entry
        //    {
        //        EntryDate = DateTime.Today.ToShortDateString(),
        //        Description = entryText.Text
        //    };
        //    await repository.AddEntry(newEntry);
        //    Console.WriteLine("Entry added");
        //    refreshList();
        //    entryText.Text = "";
        //    Toast.MakeText(this, "Entry added, sucka!!!", ToastLength.Short).Show();
        //}

        private async void rateButton_Click(object sender, EventArgs e)
        {
            if (dateId == 0)
            {
                Toast.MakeText(this, "No entries exist for this date!", ToastLength.Short).Show();
            }
            else
            {
                DiaryDate diaryDate = new DiaryDate();
                diaryDate.DateId = dateId;
                diaryDate.Date   = date;
                diaryDate.Rating = (int)ratingBar.Rating;

                try
                {
                    await repository.UpdateDate(diaryDate);
                }
                catch (SQLiteException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
 //add new date to db
 public async Task AddDate(DiaryDate date)
 {
     await db.InsertAsync(date);
 }
 //delete specific date
 public async Task DeleteDate(DiaryDate date)
 {
     await db.DeleteAsync(date);
 }
 public async Task UpdateDate(DiaryDate date)
 {
     await db.UpdateAsync(date);
 }