/// <summary> /// Callback for when the Add Bedding 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 AddBeddingButton_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 BeddingRecordEntry entry = new BeddingRecordEntry() { HorseId = HorseManager.GetInstance().ActiveHorse.Id, Date = date }; await AppDatabase.GetInstance().Save <BeddingRecordEntry>(entry); // Add a new record view to the stack this.entries.Add(entry); BeddingRecordView view = new BeddingRecordView(entry); this.BeddingRecordStack.Children.Add(view); }
/// <summary> /// Method to save the current horse. /// </summary> private async Task SaveHorse() { // Save the horse information fields this.Horse.Name = this.HorseNameEntry.Text; this.Horse.Age = int.Parse(this.HorseAgeEntry.Text); this.Horse.Sex = (HorseSex)(this.HorseSexPicker.SelectedIndex); this.Horse.Breed = this.HorseBreedPicker.Breed; // Save the horse appearance fields this.Horse.Height = float.Parse(this.HorseHeightEntry.Text); this.Horse.Weight = float.Parse(this.HorseWeightEntry.Text); this.Horse.Color = this.HorseColorEditor.Text; this.Horse.Markings = this.HorseMarkingsEditor.Text; // Save the horse pedigree fields this.Horse.Pedigree = this.PedigreeEntry.Text; this.Horse.Sire = this.SireEntry.Text; this.Horse.PaternalGrandSire = this.PaternalGrandSireEntry.Text; this.Horse.PaternalGrandDam = this.PaternalGrandDamEntry.Text; this.Horse.Dam = this.DamEntry.Text; this.Horse.MaternalGrandSire = this.MaternalGrandSireEntry.Text; this.Horse.MaternalGrandDam = this.MaternalGrandDamEntry.Text; // Save the horse to the database await AppDatabase.GetInstance().Save <Horse>(this.Horse); }
/// <summary> /// Method that is called when the page first appears. /// </summary> protected override async void OnAppearing() { // Invoke the base OnAppearing method base.OnAppearing(); // Check if the user is not in the first level of the program if (AppSettings.HorseProgram.Level != AppSettings.HorseProgram.ProgramLevel.First) { // Disable the "other experiences" fields this.OtherExperiencesGrid.IsVisible = false; this.OtherExperiencesSeparator.IsVisible = false; } // Load the current active horse and bind it to the page. this._horse = HorseManager.GetInstance().ActiveHorse; int year = (DateTime.Now.Month < 7) ? DateTime.Now.Year - 1 : DateTime.Now.Year; // Attempt to get the existing set of project experiences for the // current horse at the current program level List <ProjectExperiences> experiences = await AppDatabase.GetInstance().Query <ProjectExperiences>( "SELECT * FROM ProjectExperiences WHERE HorseId = ? AND Level = ? AND Year = ?", this._horse.Id, AppSettings.HorseProgram.Level, year); // Check if no experiences exist if (experiences.Count == 0) { // Create a new ProjectExperiences collection and add it to the database this._experiences = new ProjectExperiences() { HorseId = this._horse.Id, Level = AppSettings.HorseProgram.Level, Year = (DateTime.Now.Month < 7) ? DateTime.Now.Year - 1 : DateTime.Now.Year, }; await AppDatabase.GetInstance().Save <ProjectExperiences>(this._experiences); // Handle if the experiences already existed } else { this._experiences = experiences[0]; } // Populate the editors on the page. this.FeedCareEditor.Text = this._experiences.FeedCareExperiences; this.HealthEditor.Text = this._experiences.HealthExperiences; this.LearningEditor.Text = this._experiences.LearningExperiences; this.GoalsEditor.Text = this._experiences.GoalsExperiences; this.OtherEditor.Text = this._experiences.OtherExperiences; // Set the "modified" property of the page to false this._modified = false; }
/// <summary> /// Method that is called when the save button is pressed. /// </summary> /// <param name="sender">Object that sent the event.</param> /// <param name="e">Event arguments for the event.</param> private async void SaveButton_Clicked(object sender, EventArgs e) { // Save the entry with the values that are entered this.entry.Description = this.DescriptionEditor.Text; this.entry.Cost = this.CostEntry.Value; await AppDatabase.GetInstance().Save <ExpenseRecordEntry>(this.entry); // Return to the previous page await this.Navigation.PopAsync(true); }
/// <summary> /// Method that is called when the save button is clicked. /// </summary> /// <param name="sender">Object that sent the click event.</param> /// <param name="e">Event arguments for the click event.</param> private async void SaveButton_Clicked(object sender, System.EventArgs e) { // Save the text in the editor this._story.Story = this.ProjectStoryEditor.Text; // Get all of the content of the page and save it to the project // story database element await AppDatabase.GetInstance().Save <ProjectStory>(this._story); // Navigate to the previous page after the save operation await this.Navigation.PopAsync(true); }
/// <summary> /// Method that is called when the save button is pressed. /// </summary> /// <param name="sender">Object that sent the event.</param> /// <param name="e">Event arguments for the event.</param> private async void SaveButton_Clicked(object sender, EventArgs e) { // Save the entry with the values that are entered this.Entry.Type = (BeddingType) this.TypePicker.SelectedIndex; this.Entry.Amount = this.AmountEntry.Value; this.Entry.Cost = this.CostEntry.Value; await AppDatabase.GetInstance().Save <BeddingRecordEntry>(this.Entry); // Return to the previous page await this.Navigation.PopAsync(true); }
/// <summary> /// Method that is called when the save button is clicked. /// </summary> /// <param name="sender">Object that sent the click event.</param> /// <param name="e">Event arguments for the click event.</param> private async void SaveButton_Clicked(object sender, System.EventArgs e) { // Save the text in the editors this._plan.HorsePlans = this.HorsePlanEditor.Text; this._plan.CaringPlans = this.CaringPlanEditor.Text; this._plan.LearningPlans = this.LearningPlanEditor.Text; // Get all of the content of the page and save it to the project // plans database element await AppDatabase.GetInstance().Save <ProjectPlan>(this._plan); // Navigate to the previous page after the save operation await this.Navigation.PopAsync(true); }
/// <summary> /// Method to get a list of records for the given type in a range. /// </summary> /// <typeparam name="T">The type of record entry.</typeparam> /// <param name="start">The start date.</param> /// <param name="end">The end date.</param> /// <returns>A list of records in the specified range.</returns> public static async Task <List <T> > GetInRange <T>( int horseId, DateTime start, DateTime end) where T : RecordBookEntry, new() { // Generate the SQL query to get the records string query = "SELECT * FROM " + typeof(T).Name + " WHERE " + "HorseId = ? AND Date >= ? AND Date < ?"; // Return a promise with the specified records return(await AppDatabase.GetInstance().Query <T>( query, horseId, start.Ticks, end.Ticks)); }
/// <summary> /// Method that is called when the save button is clicked. /// </summary> /// <param name="sender">Object that sent the click event.</param> /// <param name="e">Event arguments for the click event.</param> private async void SaveButton_Clicked(object sender, System.EventArgs e) { // Save the text in the editors this._experiences.FeedCareExperiences = this.FeedCareEditor.Text; this._experiences.HealthExperiences = this.HealthEditor.Text; this._experiences.LearningExperiences = this.LearningEditor.Text; this._experiences.GoalsExperiences = this.GoalsEditor.Text; this._experiences.OtherExperiences = this.OtherEditor.Text; // Get all of the content of the page and save it to the project // experiences database element await AppDatabase.GetInstance().Save <ProjectExperiences>(this._experiences); // Navigate to the previous page after the save operation await this.Navigation.PopAsync(true); }
/// <summary> /// Method that is called when the page first appears. /// </summary> protected override async void OnAppearing() { // Call the base OnAppearing method base.OnAppearing(); // Load the current active horse and bind it to the page this._horse = HorseManager.GetInstance().ActiveHorse; int year = (DateTime.Now.Month < 7) ? DateTime.Now.Year - 1 : DateTime.Now.Year; // Attempt to get the existing project story for the current horse List <ProjectStory> stories = await AppDatabase.GetInstance().Query <ProjectStory>( "SELECT * FROM ProjectStory WHERE HorseId = ? AND Year = ?", this._horse.Id, year); // Check if no story exists for the current horse if (stories.Count == 0) { // Create a new story and then add it to the database this._story = new ProjectStory() { HorseId = this._horse.Id, Year = (DateTime.Now.Month < 7) ? DateTime.Now.Year - 1 : DateTime.Now.Year, }; await AppDatabase.GetInstance().Save <ProjectStory>(this._story); // Set the plan if it already exists } else { this._story = stories[0]; } // Populate the project story editor this.ProjectStoryEditor.Text = this._story.Story; this.ProjectStoryEditor.Keyboard = Keyboard.Create( KeyboardFlags.All); // Set the "modified" property of the page to false this._modified = false; }
/// <summary> /// Method that is called when the page first appears. /// </summary> protected override async void OnAppearing() { // Call the base OnAppearing method base.OnAppearing(); // Load the current active horse and bind it to the page. this._horse = HorseManager.GetInstance().ActiveHorse; int year = (DateTime.Now.Month < 7) ? DateTime.Now.Year - 1 : DateTime.Now.Year; // Attempt to get an existing project plan for the current horse List <ProjectPlan> plans = await AppDatabase.GetInstance().Query <ProjectPlan>( "SELECT * FROM ProjectPlan WHERE HorseId = ? AND Year = ?", this._horse.Id, year); // Check if no plan exists for the current horse if (plans.Count == 0) { // Create a new plan and then add it to the database this._plan = new ProjectPlan() { HorseId = this._horse.Id, Year = (DateTime.Now.Month < 7) ? DateTime.Now.Year - 1: DateTime.Now.Year, }; await AppDatabase.GetInstance().Save <ProjectPlan>(this._plan); // Set the plan if it already exists } else { this._plan = plans[0]; } // Populate the editors on the page this.HorsePlanEditor.Text = this._plan.HorsePlans; this.CaringPlanEditor.Text = this._plan.CaringPlans; this.LearningPlanEditor.Text = this._plan.LearningPlans; // Set the "modified" property of the page to false this._modified = false; }
/// <summary> /// Method that will remove a picture from the database. /// </summary> /// <param name="picture">The picture to remove.</param> public async Task Remove(Picture picture) { // Ensure that the picture is not null if (picture == null) { return; } // Check if the picture is not in the list if (!this._Pictures.Contains(picture)) { return; } // Remove the picture from the list of pictures that are currently // loaded, and then remove it from the database this._Pictures.Remove(picture); await AppDatabase.GetInstance().Delete <Picture>(picture); }
/// <summary> /// Method that is called when the save button is pressed. /// </summary> /// <param name="sender">Object that sent the event.</param> /// <param name="e">Event arguments for the event.</param> private async void SaveButton_Clicked(object sender, EventArgs e) { // Make sure the end time is greater than the start time if (this.StartTimePicker.Time > this.EndTimePicker.Time) { ToastController.ShortToast("Error: End time must come after start time."); return; } // Save the entry with the values that are entered this.Entry.Description = this.DescriptionEditor.Text; this.Entry.Start = this.StartTimePicker.Time; this.Entry.End = this.EndTimePicker.Time; await AppDatabase.GetInstance().Save <RidingRecordEntry>(this.Entry); // Return to the previous page await this.Navigation.PopAsync(true); }
/// <summary> /// Method that will save/update a picture to the database. /// </summary> /// <param name="picture">The picture to save/update.</param> public async Task Save(Picture picture) { // Ensure that the picture is not null if (picture == null) { throw new NullReferenceException(); } // Check if the picture has any incomplete fields // Each picture must have a filepath that is non-null. In the // instance that a "Picture" references a non-existing file, it // will be simply cleaned from the database as an entry. if (picture.FilePath == string.Empty) { throw new Exception("Malformed filepath"); } // Add the picture to the database - the information will // be added to the object automatically await AppDatabase.GetInstance().Save <Picture>(picture); }
/// <summary> /// Method to remove the specified horse from the list. /// </summary> /// <param name="horse">The horse to remove.</param> /// <returns>An indication of task completion.</returns> /// <exception cref="HorseNotFoundException">Thrown if the horse doesn't exist.</exception> public async Task Delete(Horse horse) { // Check if the horse exists in the list of horses if (!this.Horses.Contains(horse)) { throw new HorseNotFoundException(); } // Delete any references to the current horse this.Horses.Remove(horse); await AppDatabase.GetInstance().Delete <Horse>(horse); // Set the new active horse based on how many horses there are if (this.Horses.Count == 0) { this.ActiveHorse = null; } else { this.ActiveHorse = this.Horses[0]; } }
/// <summary> /// Method to load the list of horses from the database. /// </summary> /// <returns>A void task, for awaiting purposes.</returns> private async Task LoadHorses() { // Get a list of horses from the database List <Horse> horses = await AppDatabase.GetInstance().GetAll <Horse>(); this.Horses = new ObservableCollection <Horse>(horses); // Do not set an active horse if there is no presently active // horse available. if (this.Horses.Count == 0) { this.ActiveHorse = null; return; } // If the active horse is currently set to null, set it to the // first horse in the list. if (this.ActiveHorse == null) { this.ActiveHorse = this.Horses[0]; } // If the active horse already exists, make sure that its Id is // present in some horse in the list. foreach (Horse horse in this.Horses) { if (horse.Id == this.ActiveHorse.Id) { return; } } // If this point has been reached, then an invalid Id was set for // the active horse and the active horse should be set to the first // horse in the list. this.ActiveHorse = this.Horses[0]; }
/// <summary> /// Method that is called when the delete button is pressed. /// </summary> /// <param name="sender">Object that sent the event.</param> /// <param name="e">Event arguments for the event.</param> private void DeleteButton_Clicked(object sender, System.EventArgs e) { Device.BeginInvokeOnMainThread(async() => { // Display a confirmation dialog asking whether the user actually // wants to delete the specified entry. bool result = await this.DisplayAlert( "Confirmation", "Are you sure you want to delete this entry? This action cannot be undone and all associated data will be deleted.", "Delete", "Cancel"); // If the user selected cancel, exit from the lambda if (!result) { return; } // Delete the entry, then navigate back a page await AppDatabase.GetInstance().Delete <ServiceRecordEntry>(this.Entry); await Navigation.PopAsync(true); }); }
/// <summary> /// Method to create a new horse in the horse manager. /// </summary> /// <returns>The new horse that has been created.</returns> /// <exception cref="TooManyHorsesException">Thrown if there are too many horses.</exception> public async Task <Horse> Create(HorseType type) { // Check if the maximum number of horses is already met if (this.Horses.Count == HorseManager.MAX_HORSES) { throw new TooManyHorsesException(); } // Create a new horse entity with default values and add it to the // database (this will give it an Id automatically). Horse horse = new Horse() { Type = type, }; await AppDatabase.GetInstance().Save <Horse>(horse); // Add the horse to the list of horses and set it as the active // horse in the application. this.Horses.Add(horse); this.ActiveHorse = horse; // Return the new horse return(horse); }
/// <summary> /// Method that is called when the test button is clicked. /// </summary> /// <param name="sender">Object that sent the click event.</param> /// <param name="e">Arguments for the click event.</param> private async void TestExportButton_Clicked(object sender, EventArgs e) { var db = AppDatabase.GetInstance(); // gets the database Horse horse = HorseManager.GetInstance().ActiveHorse; //selects the active horse int currentYear = (DateTime.Now.Month < 7) ? DateTime.Now.Year - 1 : DateTime.Now.Year; if (horse == null) //determines if an active horse is selected { return; } // Test the PdfSharp.Xamarin functionality IFileHelper director = DependencyService.Get <IFileHelper>(); IExportHelper helper = DependencyService.Get <IExportHelper>(); //establishes the 4-H document path string path = director.GenerateLocalAsset("level1book.pdf", horse.Name); if (!IsFirstLevel()) { path = director.GenerateLocalAsset("level2-5book.pdf", horse.Name); } //opens the document for modification PdfDocument document = PdfReader.Open(path, PdfDocumentOpenMode.Modify); // gets the document's form fillable components PdfAcroForm acroForm = document.AcroForm; #region Photos // get Photos from Picture manager and print onto pages 11&12 // ***supports upto 6 currently*** List <Picture> pics = PictureManager.Instance.Pictures; int len = 6; if (pics.Count < len) { len = pics.Count; } int pageNo = 10; double[,] poses = new double[, ] { { 1, 5 }, { 4.25, 5 }, { 1, 10 }, { 4.25, 10 }, { 1, 5.5 }, { 4.25, 5.5 } }; for (int i = 0; i < len; i++) { XImage img = XImage.FromFile(pics[i].FilePath); double xPos = poses[i, 0] * 71; double yPos = (11 * 71) - (poses[i, 1] * 71); if (i >= 2) { pageNo = 11; } XGraphics gfx = XGraphics.FromPdfPage(document.Pages[pageNo]); // each photo has up to 3.25 in by 4 in // 71 pixels per inch for pdfsharp stuff double maxWidth = 3.25 * 71, maxHeight = 4 * 71; var ratioX = (double)maxWidth / img.PixelWidth; var ratioY = (double)maxHeight / img.PixelHeight; var ratio = Math.Min(ratioX, ratioY); var newWidth = (int)(img.PixelWidth * ratio); var newHeight = (int)(img.PixelHeight * ratio); gfx.DrawImage(img, xPos, yPos, newWidth, newHeight); gfx.Dispose(); } #endregion #region Project Plans // Sets the project plans page var plans = await db.Query <ProjectPlan>( "SELECT * FROM ProjectPlan WHERE HorseId = ? AND Year = ?", horse.Id, currentYear); if (plans.Count > 0) { acroForm.Fields["horseList"].Value = new PdfString(plans[0].HorsePlans); acroForm.Fields["careList"].Value = new PdfString(plans[0].CaringPlans); acroForm.Fields["experienceList"].Value = new PdfString(plans[0].LearningPlans); } #endregion #region Horse Info // Sets the horse info section acroForm.Fields["name"].Value = new PdfString(horse.Name); acroForm.Fields["breed"].Value = new PdfString(horse.Breed); acroForm.Fields["sex"].Value = new PdfString(horse.Sex.ToString()); acroForm.Fields["height"].Value = new PdfString(horse.Height.ToString()); acroForm.Fields["weight"].Value = new PdfString(horse.Weight.ToString()); acroForm.Fields["age"].Value = new PdfString(horse.Age.ToString()); acroForm.Fields["color"].Value = new PdfString(horse.Color); acroForm.Fields["markings"].Value = new PdfString(horse.Markings); // add pedigree information for year 1 book if (IsFirstLevel()) { acroForm.Fields["pedigree"].Value = new PdfString(horse.Pedigree); acroForm.Fields["sire"].Value = new PdfString(horse.Sire); acroForm.Fields["dam"].Value = new PdfString(horse.Dam); acroForm.Fields["paternalGrandSire"].Value = new PdfString(horse.PaternalGrandSire); acroForm.Fields["paternalGrandDam"].Value = new PdfString(horse.PaternalGrandDam); acroForm.Fields["maternalGrandSire"].Value = new PdfString(horse.MaternalGrandSire); acroForm.Fields["maternalGrandDam"].Value = new PdfString(horse.MaternalGrandDam); } #endregion #region Activities // Sets the Participation in activities section // set the upper limit on allowed activities int activityLimit = (IsFirstLevel()) ? 8 : 11; // get the activity records var activities = await RecordBookEntry.GetInRange <ActivityRecordEntry>( horse.Id, new DateTime(currentYear, 7, 1), new DateTime(currentYear + 1, 6, 30)); // populate the activites until you hit the limit or you run out of activities for (int i = 0; i < activityLimit && i < activities.Count; i++) { acroForm.Fields["activityDate" + i].Value = new PdfString(activities[i].Date.ToString()); acroForm.Fields["activity" + i].Value = new PdfString(activities[i].Description); acroForm.Fields["activityLocation" + i].Value = new PdfString(activities[i].Location); } #endregion #region Stable, Feed, Other // In book 1: fills out the Stable Record page // In book 2: fills out the Feed record page, the Stable record page, and the Other Expenses section int yearCrossover = 0; // helps the program jump the gap from Dec to Jan // Year-long aggregates float book1OverallCost = 0; float book2OverallFeedCost = 0; float book2OverallStableCost = 0; float overallBedWeight = 0; float overallBedCost = 0; var overallFeedAmounts = new Dictionary <FeedType, float> { { FeedType.Grain, 0 }, { FeedType.Hay, 0 }, { FeedType.Pasture, 0 }, { FeedType.SaltAndMinerals, 0 } }; var overallFeedCosts = new Dictionary <FeedType, float> { { FeedType.Grain, 0 }, { FeedType.Hay, 0 }, { FeedType.Pasture, 0 }, { FeedType.SaltAndMinerals, 0 }, { FeedType.Other, 0 } }; float overallOtherExpenses = 0; var overallServiceCosts = new Dictionary <ServiceType, float> { { ServiceType.Farrier, 0 }, { ServiceType.HealthCare, 0 }, { ServiceType.RidingInstruction, 0 }, { ServiceType.Other, 0 }, }; TimeSpan overallLaborHours = new TimeSpan(0, 0, 0); for (int j = 6; j < 18; j++) { int index = (j % 12); if (index == 0) { yearCrossover = 1; } // get current month's first/last date var firstOfTheMonth = new DateTime(currentYear + yearCrossover, index + 1, 1); var lastOfTheMonth = firstOfTheMonth.AddMonths(1).AddDays(-1); string fullMonthName = new DateTime(2015, index + 1, 1).ToString("MMMM"); // monthly aggregate values float book1TotalCost = 0; float book2TotalFeedCost = 0; float book2TotalStableCost = 0; #region Bedding // get the bedding records var bedding = await RecordBookEntry.GetInRange <BeddingRecordEntry>( horse.Id, firstOfTheMonth, lastOfTheMonth); // Aggregate and export bedding records var totalBeddingWeight = new Dictionary <BeddingType, float> { { BeddingType.Hay, 0 }, { BeddingType.Hemp, 0 }, { BeddingType.Moss, 0 }, { BeddingType.Paper, 0 }, { BeddingType.Sawdust, 0 }, { BeddingType.Shavings, 0 }, { BeddingType.StallMats, 0 }, { BeddingType.Straw, 0 }, { BeddingType.WoodPellets, 0 } }; float totalBeddingCost = 0; foreach (BeddingRecordEntry bed in bedding) { totalBeddingWeight[bed.Type] += bed.Amount; totalBeddingCost += bed.Cost; overallBedWeight += bed.Amount; overallBedCost += bed.Cost; book1TotalCost += bed.Cost; book2TotalStableCost += bed.Cost; } // format the kind/amount string string weightString = ""; if (totalBeddingWeight[BeddingType.Hay] > 0) { weightString = String.Format("{0}Hay, {1}\n", weightString, totalBeddingWeight[BeddingType.Hay]); } if (totalBeddingWeight[BeddingType.Hemp] > 0) { weightString = String.Format("{0}Hemp, {1}\n", weightString, totalBeddingWeight[BeddingType.Hemp]); } if (totalBeddingWeight[BeddingType.Moss] > 0) { weightString = String.Format("{0}Moss, {1}\n", weightString, totalBeddingWeight[BeddingType.Moss]); } if (totalBeddingWeight[BeddingType.Paper] > 0) { weightString = String.Format("{0}Paper, {1}\n", weightString, totalBeddingWeight[BeddingType.Paper]); } if (totalBeddingWeight[BeddingType.Sawdust] > 0) { weightString = String.Format("{0}Sawdust, {1}\n", weightString, totalBeddingWeight[BeddingType.Sawdust]); } if (totalBeddingWeight[BeddingType.Shavings] > 0) { weightString = String.Format("{0}Shavings, {1}\n", weightString, totalBeddingWeight[BeddingType.Shavings]); } if (totalBeddingWeight[BeddingType.StallMats] > 0) { weightString = String.Format("{0}Stall Mats, {1}\n", weightString, totalBeddingWeight[BeddingType.StallMats]); } if (totalBeddingWeight[BeddingType.Straw] > 0) { weightString = String.Format("{0}Straw, {1}\n", weightString, totalBeddingWeight[BeddingType.Straw]); } if (totalBeddingWeight[BeddingType.WoodPellets] > 0) { weightString = String.Format("{0}Wood Pellets, {1}\n", weightString, totalBeddingWeight[BeddingType.WoodPellets]); } // commit this month's records acroForm.Fields["bedding" + index].Value = new PdfString(weightString); acroForm.Fields["beddingCost" + index].Value = new PdfString(String.Format("{0:C2}", totalBeddingCost)); #endregion #region Feed // get the feed records var feed = await RecordBookEntry.GetInRange <FeedRecordEntry>( horse.Id, firstOfTheMonth, lastOfTheMonth); // Aggregate the records var totalFeedAmounts = new Dictionary <FeedType, float> { { FeedType.Grain, 0 }, { FeedType.Hay, 0 }, { FeedType.Pasture, 0 }, { FeedType.SaltAndMinerals, 0 } }; var totalFeedCosts = new Dictionary <FeedType, float> { { FeedType.Grain, 0 }, { FeedType.Hay, 0 }, { FeedType.Pasture, 0 }, { FeedType.SaltAndMinerals, 0 }, { FeedType.Other, 0 } }; foreach (FeedRecordEntry food in feed) { if (food.Type != FeedType.Other) { totalFeedAmounts[food.Type] += food.Amount; overallFeedAmounts[food.Type] += food.Amount; } totalFeedCosts[food.Type] += food.Cost; overallFeedCosts[food.Type] += food.Cost; book1OverallCost += food.Cost; book2OverallFeedCost += food.Cost; } // commit this month's feed records acroForm.Fields["grain" + index].Value = new PdfString(totalFeedAmounts[FeedType.Grain].ToString()); acroForm.Fields["grainCost" + index].Value = new PdfString(String.Format("{0:C2}", totalFeedCosts[FeedType.Grain])); acroForm.Fields["hay" + index].Value = new PdfString(totalFeedAmounts[FeedType.Hay].ToString()); acroForm.Fields["hayCost" + index].Value = new PdfString(String.Format("{0:C2}", totalFeedCosts[FeedType.Hay])); acroForm.Fields["salt" + index].Value = new PdfString(totalFeedAmounts[FeedType.SaltAndMinerals].ToString()); acroForm.Fields["saltCost" + index].Value = new PdfString(String.Format("{0:C2}", totalFeedCosts[FeedType.SaltAndMinerals])); acroForm.Fields["pasture" + index].Value = new PdfString(totalFeedAmounts[FeedType.Pasture].ToString()); // these do not go into tier 1 record book if (!IsFirstLevel()) { acroForm.Fields["pastureCost" + index].Value = new PdfString(String.Format("{0:C2}", totalFeedCosts[FeedType.Pasture])); acroForm.Fields["otherFeedCost" + index].Value = new PdfString(String.Format("{0:C2}", totalFeedCosts[FeedType.Other])); } #endregion #region Service // get the service records var service = await RecordBookEntry.GetInRange <ServiceRecordEntry>( horse.Id, firstOfTheMonth, lastOfTheMonth); // aggregate the service record information string otherExpenses = ""; float otherExpensesCost = 0; var serviceStrings = new Dictionary <ServiceType, string> { { ServiceType.Farrier, "" }, { ServiceType.HealthCare, "" }, { ServiceType.RidingInstruction, "" }, { ServiceType.Other, "" }, }; var serviceCosts = new Dictionary <ServiceType, float> { { ServiceType.Farrier, 0 }, { ServiceType.HealthCare, 0 }, { ServiceType.RidingInstruction, 0 }, { ServiceType.Other, 0 }, }; foreach (ServiceRecordEntry serve in service) { // fills in "other expenses" for a year 1 book if (IsFirstLevel()) { if (!serve.Description.Equals(String.Empty)) { otherExpenses = String.Format("{0}; {1}", otherExpenses, serve.Description); } otherExpensesCost += serve.Cost; overallOtherExpenses += serve.Cost; } else // fills in "Stable Record" for a year 2-5 book { if (!serve.Description.Equals(String.Empty)) { serviceStrings[serve.Type] = String.Format( "{0}; {1}", serviceStrings[serve.Type], serve.Description); } serviceCosts[serve.Type] += serve.Cost; overallServiceCosts[serve.Type] += serve.Cost; } book1OverallCost += serve.Cost; book2OverallStableCost += serve.Cost; } // commit the service record information to the pdf if (IsFirstLevel()) { acroForm.Fields["otherExpenses" + index].Value = new PdfString(otherExpenses); acroForm.Fields["otherExpensesCost" + index].Value = new PdfString(String.Format("{0:C2}", otherExpensesCost)); } else { acroForm.Fields["ridingCost" + index].Value = new PdfString( String.Format("{0}, {1:C2}", serviceStrings[ServiceType.RidingInstruction], serviceCosts[ServiceType.RidingInstruction])); acroForm.Fields["healthCare" + index].Value = new PdfString(serviceStrings[ServiceType.HealthCare]); acroForm.Fields["healthCareCost" + index].Value = new PdfString( String.Format("{0:C2}", serviceCosts[ServiceType.HealthCare])); acroForm.Fields["farrier" + index].Value = new PdfString(serviceStrings[ServiceType.Farrier]); acroForm.Fields["farrierCost" + index].Value = new PdfString( String.Format("{0:C2}", serviceCosts[ServiceType.Farrier])); acroForm.Fields["equipment" + index].Value = new PdfString(serviceStrings[ServiceType.Other]); acroForm.Fields["equipmentCost" + index].Value = new PdfString( String.Format("{0:C2}", serviceCosts[ServiceType.Other])); } #endregion #region Riding // Get the riding records var rides = await RecordBookEntry.GetInRange <RidingRecordEntry>( horse.Id, firstOfTheMonth, lastOfTheMonth); // set the riding month if the book level is 2-5 if (!IsFirstLevel()) { acroForm.Fields["ridingMonth" + index].Value = new PdfString(fullMonthName); } // aggregate riding hours and descriptions TimeSpan rideHours = new TimeSpan(0, 0, 0); string rideDescriptions = ""; foreach (RidingRecordEntry ride in rides) { rideHours.Add(ride.End.Subtract(ride.Start)); if (!ride.Description.Equals(String.Empty)) { rideDescriptions = String.Format("{0}; {1}", rideDescriptions, ride.Description); } } // commit aggregates acroForm.Fields["ridingHours" + index].Value = new PdfString(rideHours.ToString(@"hh\:mm")); acroForm.Fields["riding" + index].Value = new PdfString(rideDescriptions); #endregion #region Labor // Get the labor records var labor = await RecordBookEntry.GetInRange <LaborRecordEntry>( horse.Id, firstOfTheMonth, lastOfTheMonth); // aggregate labor hours and descriptions // aggregate riding hours and descriptions TimeSpan laborHours = new TimeSpan(0, 0, 0); string laborDescriptions = ""; foreach (LaborRecordEntry job in labor) { laborHours.Add(job.End.Subtract(job.Start)); if (!job.Description.Equals(String.Empty)) { laborDescriptions = String.Format("{0}; {1}", laborDescriptions, job.Description); } } // commit aggregates if (IsFirstLevel()) { acroForm.Fields["labor" + index].Value = new PdfString(laborDescriptions); acroForm.Fields["laborHours" + index].Value = new PdfString(laborHours.ToString(@"hh\:mm")); } else { acroForm.Fields["labor" + index].Value = new PdfString(laborHours.ToString(@"hh\:mm")); } #endregion #region monthly aggregate commit // Commit any aggregated totals for the current month if (IsFirstLevel()) { acroForm.Fields["totalCost" + index].Value = new PdfString( String.Format("{0:C2}", book1TotalCost)); } else { acroForm.Fields["totalFeedCost" + index].Value = new PdfString( String.Format("{0:C2}", book2TotalFeedCost)); acroForm.Fields["totalFeedCostS" + index].Value = new PdfString( String.Format("{0:C2}", book2TotalFeedCost)); acroForm.Fields["totalStableCost" + index].Value = new PdfString( String.Format("{0:C2}", book2TotalStableCost)); } #endregion #region aggregate yearly // Add aggregate monthly values to their respective year-long totals book1OverallCost += book1TotalCost; book2OverallFeedCost += book2TotalFeedCost; book2OverallStableCost += book2TotalStableCost; overallBedCost += totalBeddingCost; overallBedWeight += totalBeddingWeight[BeddingType.Hay]; overallBedWeight += totalBeddingWeight[BeddingType.Hemp]; overallBedWeight += totalBeddingWeight[BeddingType.Moss]; overallBedWeight += totalBeddingWeight[BeddingType.Paper]; overallBedWeight += totalBeddingWeight[BeddingType.Sawdust]; overallBedWeight += totalBeddingWeight[BeddingType.Shavings]; overallBedWeight += totalBeddingWeight[BeddingType.StallMats]; overallBedWeight += totalBeddingWeight[BeddingType.Straw]; overallBedWeight += totalBeddingWeight[BeddingType.WoodPellets]; overallFeedAmounts[FeedType.Grain] += totalFeedAmounts[FeedType.Grain]; overallFeedAmounts[FeedType.Hay] += totalFeedAmounts[FeedType.Hay]; overallFeedAmounts[FeedType.Pasture] += totalFeedAmounts[FeedType.Pasture]; overallFeedAmounts[FeedType.SaltAndMinerals] += totalFeedAmounts[FeedType.SaltAndMinerals]; overallFeedCosts[FeedType.Grain] += totalFeedCosts[FeedType.Grain]; overallFeedCosts[FeedType.Hay] += totalFeedCosts[FeedType.Hay]; overallFeedCosts[FeedType.Pasture] += totalFeedCosts[FeedType.Pasture]; overallFeedCosts[FeedType.SaltAndMinerals] += totalFeedCosts[FeedType.SaltAndMinerals]; overallFeedCosts[FeedType.Other] += totalFeedCosts[FeedType.Other]; overallLaborHours.Add(laborHours); #endregion } #region Year long aggregates commit // Commit aggragated totals for the year // Universal to both books acroForm.Fields["beddingTotal"].Value = new PdfString(overallBedWeight.ToString()); acroForm.Fields["beddingCostTotal"].Value = new PdfString( String.Format("{0:C2}", overallBedCost)); if (IsFirstLevel()) // first book only { acroForm.Fields["hayTotal"].Value = new PdfString( overallFeedAmounts[FeedType.Hay].ToString()); acroForm.Fields["hayCostTotal"].Value = new PdfString( String.Format("{0:C2}", overallFeedCosts[FeedType.Hay])); acroForm.Fields["grainTotal"].Value = new PdfString( overallFeedAmounts[FeedType.Grain].ToString()); acroForm.Fields["grainCostTotal"].Value = new PdfString( String.Format("{0:C2}", overallFeedCosts[FeedType.Grain])); acroForm.Fields["saltTotal"].Value = new PdfString( overallFeedAmounts[FeedType.SaltAndMinerals].ToString()); acroForm.Fields["saltCostTotal"].Value = new PdfString( String.Format("{0:C2}", overallFeedCosts[FeedType.SaltAndMinerals])); acroForm.Fields["pastureTotal"].Value = new PdfString( overallFeedCosts[FeedType.Pasture].ToString()); acroForm.Fields["otherExpensesCostTotal"].Value = new PdfString( String.Format("{0:C2}", overallOtherExpenses)); acroForm.Fields["totalCostTotal"].Value = new PdfString( String.Format("{0:C2}", book1OverallCost)); } else // second book only { acroForm.Fields["totalFeedCostTotal"].Value = new PdfString( String.Format("{0:C2}", book2OverallFeedCost)); acroForm.Fields["totalFeedCostSTotal"].Value = new PdfString( String.Format("{0:C2}", book2OverallFeedCost)); acroForm.Fields["laborTotal"].Value = new PdfString( overallLaborHours.ToString(@"hh\:mm")); acroForm.Fields["ridingCostTotal"].Value = new PdfString( String.Format("{0:C2}", overallServiceCosts[ServiceType.RidingInstruction])); acroForm.Fields["healthCareCostTotal"].Value = new PdfString( String.Format("{0:C2}", overallServiceCosts[ServiceType.HealthCare])); acroForm.Fields["farrierCostTotal"].Value = new PdfString( String.Format("{0:C2}", overallServiceCosts[ServiceType.Farrier])); acroForm.Fields["equipmentCostTotal"].Value = new PdfString( String.Format("{0:C2}", overallServiceCosts[ServiceType.Other])); acroForm.Fields["totalStableCostTotal"].Value = new PdfString( String.Format("{0:C2}", book2OverallStableCost)); } #endregion #region Other Expenses (book 2 only) if (!IsFirstLevel()) { // Get the expense records var expense = await RecordBookEntry.GetInRange <ExpenseRecordEntry>( horse.Id, new DateTime(currentYear, 7, 1), new DateTime(currentYear + 1, 6, 30)); float otherExpensesTotal = 0; // Commit the extra expenses to the record book for (int i = 0; i < 6 && i < expense.Count; i++) { acroForm.Fields["otherDate" + i].Value = new PdfString(expense[i].Date.ToString()); acroForm.Fields["other" + i].Value = new PdfString(expense[i].Description); acroForm.Fields["otherCost" + i].Value = new PdfString(String.Format("{0:C2", expense[i].Cost)); otherExpensesTotal += expense[i].Cost; } acroForm.Fields["otherCostTotal"].Value = new PdfString(String.Format("{0:C2}", otherExpensesTotal)); } #endregion #endregion #region Experiences // get the project experiences var experiences = await db.Query <ProjectExperiences>( "SELECT * FROM ProjectExperiences WHERE HorseId = ? AND Year = ?", horse.Id, currentYear); // if there are experiences, set them into the PDF if (experiences.Count > 0) { acroForm.Fields["feedSummary"].Value = new PdfString(experiences[0].FeedCareExperiences); acroForm.Fields["healthSummary"].Value = new PdfString(experiences[0].HealthExperiences); acroForm.Fields["learnSummary"].Value = new PdfString(experiences[0].LearningExperiences); acroForm.Fields["goalSummary"].Value = new PdfString(experiences[0].GoalsExperiences); if (IsFirstLevel()) { acroForm.Fields["otherSummary"].Value = new PdfString(experiences[0].OtherExperiences); } } #endregion #region Story // get the project story var story = await db.Query <ProjectStory>( "SELECT * FROM ProjectStory WHERE HorseId = ? AND Year = ?", horse.Id, currentYear); if (story.Count > 0) { acroForm.Fields["projectStory"].Value = new PdfString(story[0].Story); } #endregion #region User Information acroForm.Fields["userName"].Value = new PdfString( AppSettings.User.UserName); var today = DateTime.Today; var age = today.Year - AppSettings.User.DateOfBirth.Year; if (AppSettings.User.DateOfBirth > today.AddYears(-age)) { age--; } acroForm.Fields["userAge"].Value = new PdfString(age.ToString()); acroForm.Fields["userBirthday"].Value = new PdfString( AppSettings.User.DateOfBirth.ToString("MM/dd/yyyy")); acroForm.Fields["userAddress0"].Value = new PdfString( AppSettings.User.Address); acroForm.Fields["county"].Value = new PdfString( AppSettings.HorseClub.County); acroForm.Fields["clubName"].Value = new PdfString( AppSettings.HorseClub.ClubName); acroForm.Fields["clubLeaderName"].Value = new PdfString( AppSettings.HorseClub.LeaderName); acroForm.Fields["projectHelperName"].Value = new PdfString( AppSettings.HorseProgram.HelperName); acroForm.Fields["startDate"].Value = new PdfString( AppSettings.HorseProgram.StartDate.ToString("MM/dd/yyyy")); acroForm.Fields["endDate"].Value = new PdfString( AppSettings.HorseProgram.CloseDate.ToString("MM/dd/yyyy")); #endregion // Save the file to the device document directory string file = Path.Combine(helper.GetDocumentsDirectory(), horse.Name + "4-HRecordBook.pdf"); document.Save(file); helper.SendEmail(file); // Set the filepath of the WebView to the new PDF //this.PdfView.Path = file; }
/// <summary> /// Asynchronous method to reload the pictures. /// </summary> /// <returns></returns> public async Task LoadPictures() { this._Pictures = await AppDatabase.GetInstance().GetAll <Picture>(); }