//Transfer image async void OnTransferImageClicked(object sender, EventArgs e) { //scroll to the top of the page await ChildScrollView.ScrollToAsync(0, 0, false).ConfigureAwait(false); child = (Child)BindingContext; //Create a new PDF document PdfDocument document = new PdfDocument(); //Add page to the PDF document PdfPage page = document.Pages.Add(); //Create graphics instance PdfGraphics graphics = page.Graphics; Stream imageStream = null; //Captures the XAML page as image and returns the image in memory stream imageStream = new MemoryStream(DependencyService.Get <IScreenshotService>().Capture()); //Load the image in PdfBitmap PdfBitmap image = new PdfBitmap(imageStream); //scroll to the second page await ChildScrollView.ScrollToAsync(0, 940, false).ConfigureAwait(true); //Add page to the PDF document PdfPage page2 = document.Pages.Add(); //Create graphics instance PdfGraphics graphics2 = page2.Graphics; imageStream = new MemoryStream(DependencyService.Get <IScreenshotService>().Capture()); PdfBitmap image2 = new PdfBitmap(imageStream); //Set layout property to make the element break across the pages PdfLayoutFormat format = new PdfLayoutFormat(); format.Break = PdfLayoutBreakType.FitPage; format.Layout = PdfLayoutType.Paginate; //Draw the image to the page graphics.DrawImage(image, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height); graphics2.DrawImage(image2, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height); //Save the document into memory stream MemoryStream stream = new MemoryStream(); document.Save(stream); stream.Position = 0; //Save the stream as a file in the device and invoke it for viewing DependencyService.Get <ISave>().Save("TuitionFees.pdf", "application/pdf", stream); }
//Transfer image async void OnTransferImageClicked(object sender, EventArgs e) { string childName; //get the full name to name the pdf file child = (Child)BindingContext; Family family = await App.Database.GetFamilyByIdAsync(child.familyId); childName = family.familyName + child.childName; string fileName = string.Join("", childName.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries)); //scroll to the top of the page await ChildScrollView.ScrollToAsync(0, 0, false).ConfigureAwait(false); // Create a new PDF document PdfDocument document = new PdfDocument(); //Captures the XAML page as image and returns the image in memory stream var image = UIScreen.MainScreen.Capture(); // Create a page with the printscreen PdfPage page1 = new PdfPage(image); document.InsertPage(page1, 0); //scroll to the second page await ChildScrollView.ScrollToAsync(0, 940, false).ConfigureAwait(true); //Captures the XAML page as UIIMage image = UIScreen.MainScreen.Capture(); // Create a page with the printscreen PdfPage page2 = new PdfPage(image); document.InsertPage(page2, 1); //Write file in temp foleder document.Write(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "TuitionFees" + fileName + ".pdf")); string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "TuitionFees" + fileName + ".pdf"); //get memory stream MemoryStream stream = new MemoryStream(); using (FileStream fileStream = File.OpenRead(filePath)) { stream.SetLength(fileStream.Length); fileStream.Read(stream.GetBuffer(), 0, (int)fileStream.Length); } //save file DependencyService.Get <ISave>().Save("TuitionFees" + fileName + ".pdf", "application/pdf", stream); }
//Calculate the total and display errors async void Button_Calculate(object sender, EventArgs e) { //scroll to the end await ChildScrollView.ScrollToAsync(ResultLabel, ScrollToPosition.End, true).ConfigureAwait(true); //set all pickers Picker yearPicker = YearPicker as Picker; Picker termDiscountPicker = TermDiscountPicker as Picker; Picker zonePicker = ZonePicker as Picker; Picker supervisionPicker = SupervisionPicker as Picker; Picker supportPicker = SupportPicker as Picker; //set all picked parameters string year; string zone; string assistanceDicountName; string siblingDicountName; string termDiscountName; string supervisionName; string supportName; child = (Child)BindingContext; try { year = yearPicker.SelectedItem.ToString(); if (year == "<Empty>") { child.yearName = null; child.tuitionFees = 0; child.fixedCharges = 0; child.externalExaminationFees = 0; child.schoolMeals = 0; child.wednesdayMeals = 0; } //Get all corresponding cost EnrolementFees enrolementFee = await App.Database.GetEnrolementFeesAsync(0); TuitionFees tuitionFees = await App.Database.GetTuitionFeesAsync(year); FixedCharges fixedCharges = await App.Database.GetFixedChargesAsync(year); ExternalExaminationFees examinationFees = await App.Database.GetExternalExaminationFeesAsync(year); //set mandatory fees Child with entries provided by user child.yearName = year; child.enrolementFee = enrolementFee.cost; child.tuitionFees = tuitionFees.cost; child.recalculatedTuitionFees = tuitionFees.cost; child.fixedCharges = fixedCharges.cost; child.externalExaminationFees = examinationFees.cost; // enrolementFeeValue.Text = n.ToNumberFormat() + devise; enrolementFeeValue.Text = n.ToNumberFormat(child.enrolementFee) + devise; tuitionFeesValue.Text = n.ToNumberFormat(child.tuitionFees) + devise; fixedChargesValue.Text = n.ToNumberFormat(child.fixedCharges) + devise; externalExaminationFeesValue.Text = n.ToNumberFormat(child.externalExaminationFees) + devise; } catch (Exception) { } // set Optionnal assistance discount try { assistanceDicountName = childrenNr[0]; if (assistanceDiscountCheckBox.IsChecked == false) { child.assistanceDiscountName = null; child.assistanceDiscount = 0; } else { AssistanceDiscount assistanceDiscount = await App.Database.GetAssistanceDiscountAsync(assistanceDicountName); child.assistanceDiscount = assistanceDiscount.discountPercentage; child.assistanceDiscountName = assistanceDicountName; } assistanceDiscountValue.Text = n.ToNumberFormat(child.assistanceDiscount * child.tuitionFees / 100) + devise; child.recalculatedTuitionFees = child.tuitionFees * (100 + child.assistanceDiscount) / 100; } catch (Exception) { } // set Optionnal sibling discount try { siblingDicountName = childrenNr[1]; if (siblingDiscountCheckBox.IsChecked == false) { child.siblingDiscountName = null; child.siblingDiscount = 0; } else { AssistanceDiscount siblingDiscount = await App.Database.GetAssistanceDiscountAsync(siblingDicountName); child.siblingDiscount = siblingDiscount.discountPercentage; child.siblingDiscountName = siblingDicountName; } siblingDiscountValue.Text = n.ToNumberFormat(child.siblingDiscount * (child.recalculatedTuitionFees) / 100) + devise; child.recalculatedTuitionFees = child.recalculatedTuitionFees * (100 + child.siblingDiscount) / 100; } catch (Exception) { } // set Optionnal term discount try { termDiscountName = termDiscountPicker.SelectedItem.ToString(); if (termDiscountName == "<Empty>") { child.termDiscountName = null; child.termDiscount = 0; } else { TermDiscount termDiscount = await App.Database.GetTermDiscountAsync(termDiscountName); child.termDiscount = termDiscount.discountPercentage; child.termDiscountName = termDiscountName; } termDiscountValue.Text = n.ToNumberFormat(child.termDiscount * (child.tuitionFees - child.assistanceDiscount) / 100) + devise; child.recalculatedTuitionFees = (child.recalculatedTuitionFees - child.assistanceDiscount - child.siblingDiscount) * (100 + child.termDiscount) / 100; } catch (Exception) { } // set Optionnal school meal try { if (schoolMealsCheckBox.IsChecked) { year = yearPicker.SelectedItem.ToString(); SchoolMeals schoolMeals = await App.Database.GetSchoolMealsAsync(year); child.schoolMeals = schoolMeals.cost; } else { child.schoolMeals = 0; } schoolMealsValue.Text = n.ToNumberFormat(child.schoolMeals) + devise; } catch (Exception) { } // set Optionnal wednesday meal try { if (wednesdayMealsCheckBox.IsChecked) { year = yearPicker.SelectedItem.ToString(); WednesdayMeals wednesdayMeals = await App.Database.GetWednesdayMealsAsync(year); child.wednesdayMeals = wednesdayMeals.cost; } else { child.wednesdayMeals = 0; } wednesdayMealsValue.Text = n.ToNumberFormat(child.wednesdayMeals) + devise; } catch (Exception) { } // set Optionnal school transport try { zone = zonePicker.SelectedItem.ToString(); if (zone == "<Empty>") { child.zoneName = null; child.schoolTransport = 0; } else { SchoolTransport schoolTransport = await App.Database.GetSchoolTransportAsync(zone); child.schoolTransport = schoolTransport.cost; child.zoneName = zone; } schoolTransportValue.Text = n.ToNumberFormat(child.schoolTransport) + devise; } catch (Exception) { } // set Optionnal supervision try { supervisionName = supervisionPicker.SelectedItem.ToString(); if (supervisionName == "<Empty>") { child.supervisionName = null; child.supervision = 0; } else { Supervision supervision = await App.Database.GetSupervisionAsync(supervisionName); child.supervision = supervision.cost; child.supervisionName = supervisionName; } supervisionValue.Text = n.ToNumberFormat(child.supervision) + devise; } catch (Exception) { } // set Optionnal support transport try { supportName = supportPicker.SelectedItem.ToString(); if (supportName == "<Empty>") { child.supportName = null; child.support = 0; } else { Support support = await App.Database.GetSupportAsync(supportName); child.support = support.cost; child.supportName = supportName; } supportValue.Text = n.ToNumberFormat(child.support) + devise; } catch (Exception) { } child.childName = ChildNameValue.Text; //set the child name if it has been modified //set total child cost child.cost = (child.fixedCharges + child.recalculatedTuitionFees + child.enrolementFee + child.externalExaminationFees + child.schoolMeals + child.schoolTransport + child.supervision + child.support); Family family = await App.Database.GetFamilyByIdAsync(child.familyId); family.totalCost = family.totalCost + child.cost; await App.Database.SaveFamilyAsync(family); //save child in database await App.Database.SaveChildAsync(child); //Display result ResultLabel.Text = n.ToNumberFormat(child.cost) + devise; }