//Assistance discount async private void UpdateAssistanceDiscountButton(object sender, EventArgs e) { try { assistanceDiscountPicker = AssistanceDiscountPicker as Picker; var assistanceDiscount = new AssistanceDiscount(); assistanceDiscount.name = assistanceDiscountPicker.SelectedItem.ToString(); try { assistanceDiscount.discountPercentage = int.Parse(AssistanceDiscountCost.Text); } catch (Exception) { DisplayAlert(alertTitle, notNumberErrorMessage, alertCheck); } await App.Database.SaveAssistanceDiscountAsync(assistanceDiscount); toast.ShowToast(uploadSuccessfullMessage); } catch { DisplayAlert(alertTitle, nullNameErrorMessage, alertCheck); } }
async public Task <int> SaveAssistanceDiscountAsync(AssistanceDiscount assistanceDiscount) { var checkIfexists = new AssistanceDiscount(); checkIfexists = await GetAssistanceDiscountAsync(assistanceDiscount.name); if (checkIfexists != null) { return(await _database.UpdateAsync(assistanceDiscount)); } else { return(await _database.InsertAsync(assistanceDiscount)); } }
async private void DeleteAssistanceDiscountButton(object sender, EventArgs e) { try { assistanceDiscountPicker = AssistanceDiscountPicker as Picker; var assistanceDiscount = new AssistanceDiscount(); assistanceDiscount.name = assistanceDiscountPicker.SelectedItem.ToString(); await App.Database.DeleteAssistanceDiscountAsync(assistanceDiscount); toast.ShowToast(deleteMessage); } catch (Exception) { DisplayAlert(alertTitle, nullNameErrorMessage, alertCheck); } }
//set assistance discount button async private void SetAssistanceDiscount(object sender, EventArgs e) { int yearCost = 0; var assistanceDiscount = new AssistanceDiscount();; if (!(string.IsNullOrEmpty(AssistanceDiscountName.Text))) { try { yearCost = int.Parse(AssistanceDiscountCost.Text); } catch (Exception) { DisplayAlert(alertTitle, notNumberErrorMessage, alertCheck); } try { assistanceDiscount.name = AssistanceDiscountName.Text; await App.Database.SaveAssistanceDiscountAsync(assistanceDiscount); assistanceDiscount = await App.Database.GetAssistanceDiscountAsync(AssistanceDiscountName.Text); assistanceDiscount.discountPercentage = yearCost; await Navigation.PushAsync(new SetParameters()); toast.ShowToast(uploadSuccessfullMessage); } catch (Exception) { DisplayAlert(alertTitle, nullNameErrorMessage, alertCheck); } } else { DisplayAlert(alertTitle, nullNameErrorMessage, alertCheck); } }
//Optionnal discounts async public void addAssistanceDiscount(String name, int percentage) { AssistanceDiscount assistanceDiscount = new AssistanceDiscount(); assistanceDiscount.name = name; assistanceDiscount.discountPercentage = percentage; await App.Database.SaveAssistanceDiscountAsync(assistanceDiscount); }
//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; }
public Task <int> DeleteAssistanceDiscountAsync(AssistanceDiscount assistanceDiscount) { return(_database.DeleteAsync(assistanceDiscount)); }