private void PickerTypeStatsChanged(object sender, EventArgs e) { try { if (!(sender is Picker pk)) { return; } currentFequencyUsedToCalculate = HelperShuffle.ParseEnum <FrequencyOfIncomeExpenses>(pk.Items[pk.SelectedIndex]); CalculateTotals(currentFequencyUsedToCalculate); var fre = pk.Items[pk.SelectedIndex]; if (fre == "Annually") { CurrentViewModel.BreakDownText = "(per Year)"; return; } CurrentViewModel.BreakDownText = $"(per {pk.Items[pk.SelectedIndex].Trim(new char[] { 'l', 'y' })})"; } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
private void PickerTypeChanged(object sender, EventArgs e) { if (!(sender is Picker pk)) { return; } CurrentViewModel.CurrentBudgetItem.Frequency = HelperShuffle.ParseEnum <FrequencyOfIncomeExpenses>(pk.Items[pk.SelectedIndex]); }
private async void PickerTypeChanged(object sender, EventArgs e) { try { if (!(sender is Picker picker)) { return; } //save the selected frequency await SaveFrequencyOfIncomeExpenses(picker.Items[picker.SelectedIndex]); //set the selected frequency CurrentViewModel.FrequencyData = HelperShuffle.ParseEnum <FrequencyOfIncomeExpenses>(picker.Items[picker.SelectedIndex]); } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
private async void CalculateFirstItem(object sender, EventArgs e) { if (CurrentViewModel.BulkCalculator) { if (!string.IsNullOrEmpty(CurrentViewModel.BulkPrice) && !string.IsNullOrEmpty(CurrentViewModel.BulkWeight) && CurrentViewModel.BulkData.ToString() != "") { double.TryParse(CurrentViewModel.BulkPrice, out var pri); double.TryParse(CurrentViewModel.BulkWeight, out var vol); double.TryParse(CurrentViewModel.PerBulkWeight, out var perWeight); var dt = perWeight <= 1 ? CurrentViewModel.BulkData.ToString().Trim('s') : CurrentViewModel.BulkData + ""; var orig = dt; if (vol < perWeight) { var output = string.Empty; switch (CurrentViewModel.BulkData) { case WeightType.Grams: output = WeightType.Kilograms.ToString(); break; case WeightType.Millilitres: output = WeightType.Litres.ToString(); break; } if (!string.IsNullOrEmpty(output)) { dt = output; } var recalc = await DisplayAlert("Continue?", $"Did you mean {vol} {output}?", "Yes", "No"); if (recalc) { vol = vol * 1000; } else { dt = orig; } } if (!(pri > 0) || !(vol > 0) || !(perWeight > 0)) { return; } //calculate var res = (vol / perWeight) * pri; var totalPrice = HelperShuffle.SignificantTruncate(res, 2).ToString(CultureInfo.InvariantCulture); var pricePerThousand = HelperShuffle.SignificantTruncate((pri / perWeight * 1000), 2).ToString(CultureInfo.InvariantCulture); Debug.WriteLine($"result: {res}"); var txt = $"Price per {CurrentViewModel.PerBulkWeight} {CurrentViewModel.BulkData} : ${CurrentViewModel.BulkPrice}\nTotal {dt} : {CurrentViewModel.BulkWeight}\nTotal Price : ${totalPrice}\nPrice per 1000 {CurrentViewModel.BulkData} : ${pricePerThousand}"; CurrentViewModel.Stats = txt; } else { await DisplayAlert("Missing Information", "Please check all the required information is filled in", "OK"); return; } return; } if ((CurrentViewModel.MyData != CurrentViewModel.MyDataTwo) && CurrentViewModel.CompareTwoProducts) { var response = await DisplayAlert("Continue", "You are about to compare two different measurements. Continue?", "OK", "Cancel"); if (!response) { return; } } if (!CurrentViewModel.CompareTwoProducts) { if (string.IsNullOrEmpty(CurrentViewModel.Price)) { await DisplayAlert("Missing Information", "Please check all the required information is filled in", "OK"); return; } ; double.TryParse(CurrentViewModel.Price, out var pri); double.TryParse(CurrentViewModel.Volume, out var vol); if (!(pri > 0) || !(vol > 0)) { return; } //calculate var res = pri / vol; //var totalPrice = HelperShuffle.SignificantTruncate(res, 2).ToString(CultureInfo.InvariantCulture); //var perHundred = HelperShuffle.SignificantTruncate((res * 100), 2).ToString(CultureInfo.InvariantCulture); Debug.WriteLine($"result: {res}"); var txt = $"Price per {CurrentViewModel.MyData.ToString().TrimEnd('s')} : ${HelperShuffle.SignificantTruncate(res, 2).ToString(CultureInfo.InvariantCulture)}\nPrice per 10 {CurrentViewModel.MyData} : ${HelperShuffle.SignificantTruncate((res * 10), 2).ToString(CultureInfo.InvariantCulture)}\nPrice per 100 {CurrentViewModel.MyData} : ${HelperShuffle.SignificantTruncate((res * 100), 2).ToString(CultureInfo.InvariantCulture)}"; CurrentViewModel.Stats = txt; } else { //Calculate Two Prices if (string.IsNullOrEmpty(CurrentViewModel.Price)) { await DisplayAlert("Missing Information", "Please check all the required information is filled in", "OK"); return; } ;; double.TryParse(CurrentViewModel.Price, out var pri); double.TryParse(CurrentViewModel.Volume, out var vol); if (!(pri > 0) || !(vol > 0)) { return; } //calculate var res = pri / vol; if (string.IsNullOrEmpty(CurrentViewModel.PriceTwo)) { await DisplayAlert("Missing Information", "Please check all the required information is filled in", "OK"); return; } ;; double.TryParse(CurrentViewModel.PriceTwo, out var prit); double.TryParse(CurrentViewModel.VolumeTwo, out var volt); if (!(pri > 0) || !(vol > 0)) { await DisplayAlert("Missing Information", "Please check all the required information is filled in", "OK"); return; } ;; //calculate var rest = prit / volt; //var trm = CurrentViewModel.MyData.ToString().TrimEnd('s'); Debug.WriteLine($"result: {res}"); var txt = $"First Item:\nPrice per {CurrentViewModel.MyData.ToString().TrimEnd('s')} : ${Math.Round(res, 4)}\nPrice per 10 {CurrentViewModel.MyData} : ${Math.Round(res * 10, 4)}\nPrice per 100 {CurrentViewModel.MyData} : ${Math.Round(res * 100, 4)}\n\n" + $"Second Item:\nPrice per { CurrentViewModel.MyDataTwo.ToString().TrimEnd('s')} : ${ Math.Round(rest, 4)}\nPrice per 10 { CurrentViewModel.MyDataTwo} : ${ Math.Round(rest * 10, 4).ToString("#.00", CultureInfo.InvariantCulture)}\nPrice per 100 {CurrentViewModel.MyDataTwo} : ${Math.Round(rest * 100, 4).ToString("#.00", CultureInfo.InvariantCulture)}"; CurrentViewModel.Stats = txt; } }
private async void PickerChanged(object sender, EventArgs e) { try { if (!(sender is Picker picker)) { return; } //don't want to load the first item on initialization - let the onappearing figure it out, otherwise select default - 0 if (IsLoading) { return; } if (Device.RuntimePlatform == Device.Android) { picker.TextColor = picker.SelectedIndex == 0 ? Color.FromHex("#C0C0C0") : Color.Black; } else if (Device.RuntimePlatform == Device.iOS) { picker.TextColor = picker.SelectedIndex == 0 ? Color.FromHex("b3b3b3") : Color.Black; } switch (picker.StyleId) { case "WeightPickerStyle": if (picker.SelectedIndex != 0) { CurrentViewModel.MyData = HelperShuffle.ParseEnum <WeightType>(picker.Items[picker.SelectedIndex]); } await CurrentViewModel.SaveAnyString(picker.Items[picker.SelectedIndex], Constants.ProductOneVolumePicker); break; case "WeightBulkPicker": if (picker.SelectedIndex != 0) { CurrentViewModel.BulkData = HelperShuffle.ParseEnum <WeightType>(picker.Items[picker.SelectedIndex]); } await CurrentViewModel.SaveAnyString(picker.Items[picker.SelectedIndex], Constants.ProductBulkVolumePicker); break; case "WeightPickerTwoStyle": if (picker.SelectedIndex != 0) { CurrentViewModel.MyDataTwo = HelperShuffle.ParseEnum <WeightType>(picker.Items[picker.SelectedIndex]); } await CurrentViewModel.SaveAnyString(picker.Items[picker.SelectedIndex], Constants.ProductTwoVolumePicker); break; await CurrentViewModel.SaveAnyString(picker.Items[picker.SelectedIndex], Constants.ProductOneVolumePicker); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }