/// <summary> /// Callback for when the Add Labor button is clicked. /// </summary> /// <param name="sender">Object that triggered the event.</param> /// <param name="e">Arguments for the click event.</param> private async void AddLaborButton_Clicked(object sender, EventArgs e) { // Check if the maximum number of entries for the day is // already reached if (this.entries.Count >= MAX_ENTRIES_PER_DAY) { ToastController.ShortToast("Cannot add any more records for the day!"); return; } // Create a new record book entry and insert it into the // database to obtain a unique Id LaborRecordEntry entry = new LaborRecordEntry() { HorseId = HorseManager.GetInstance().ActiveHorse.Id, Date = date }; await AppDatabase.GetInstance().Save <LaborRecordEntry>(entry); // Add a new record view to the stack this.entries.Add(entry); LaborRecordView view = new LaborRecordView(entry); this.LaborRecordStack.Children.Add(view); }
/// <summary> /// Method for when the page appears. /// </summary> protected override async void OnAppearing() { // Invoke the base OnAppearing method base.OnAppearing(); // Set the horse/date display at the page bottom this.SelectedDateLabel.Text = RecordBookTabbedPage.SelectedDate.ToString("MMM. dd, yyyy"); this.SelectedHorseLabel.Text = HorseManager.GetInstance().ActiveHorse.Name; // Get all of the records for the page this.entries.Clear(); this.entries = await RecordBookEntry.GetInRange <LaborRecordEntry>(HorseManager.GetInstance().ActiveHorse.Id, this.date, this.date.AddDays(1)); // Clear all of the contents from the labor record stack this.LaborRecordStack.Children.Clear(); // Render all of the entries on the screen foreach (LaborRecordEntry entry in this.entries) { // Add a new record frame for each labor Device.BeginInvokeOnMainThread(() => { LaborRecordView view = new LaborRecordView(entry); this.LaborRecordStack.Children.Add(view); }); } }