public void SaveTrees2() { int count = 0; using (ExcelEngine excelEngine = new ExcelEngine()) { excelEngine.Excel.DefaultVersion = ExcelVersion.Excel2013; IWorkbook workbook = excelEngine.Excel.Workbooks.Create(1); workbook.Version = ExcelVersion.Excel97to2003; IWorksheet worksheet = workbook.Worksheets[0]; worksheet.SetValue(1, 1, "Tree ID"); worksheet.SetValue(1, 2, "Plot"); worksheet.SetValue(1, 3, "Date"); worksheet.SetValue(1, 4, "Girth"); worksheet.SetValue(1, 5, "Height"); worksheet.SetValue(1, 6, "Merchantable Height"); worksheet.SetValue(1, 14, "Currency"); worksheet.SetValue(1, 15, "Rate vs USD"); for (int x = 0; x < ((List <(string, double)>)Application.Current.Properties["Currenlist"]).Count(); x++) { try { worksheet.SetValue(2 + x, 14, ((List <(string, double)>)Application.Current.Properties["Currenlist"]).ElementAt(x).Item1); worksheet.SetValue(2 + x, 15, ((List <(string, double)>)Application.Current.Properties["Currenlist"]).ElementAt(x).Item2.ToString()); } catch { worksheet.SetValue(2 + x, 15, "ErrorEventArgs"); } } for (int x = 0; x < ((List <Plot>)Application.Current.Properties["Plots"]).Count(); x++) { int minyear = 0; int maxyear = 0; Plot thisPlot = ((List <Plot>)Application.Current.Properties["Plots"]).ElementAt(x); List <Tree> TreeList = thisPlot.getTrees(); for (int y = 0; y < TreeList.Count; y++) { Tree thisTree = TreeList.ElementAt(y); for (int z = 0; z < thisTree.GetHistory().Count; z++) { if (minyear == 0) { minyear = thisTree.GetHistory().ElementAt(z).Key.Year; } else { minyear = Math.Min(minyear, thisTree.GetHistory().ElementAt(z).Key.Year); } maxyear = Math.Max(maxyear, thisTree.GetHistory().ElementAt(z).Key.Year); worksheet.SetValue(2 + count, 1, thisTree.ID.ToString()); worksheet.SetValue(2 + count, 2, thisPlot.GetName().ToString()); worksheet.SetValue(2 + count, 3, thisTree.GetHistory().ElementAt(z).Key.ToString()); worksheet.SetValue(2 + count, 4, thisTree.GetHistory().ElementAt(z).Value.Item1.ToString()); worksheet.SetValue(2 + count, 5, thisTree.GetHistory().ElementAt(z).Value.Item2.ToString()); worksheet.SetValue(2 + count, 6, thisTree.GetHistory().ElementAt(z).Value.Item3.ToString()); count++; } } } worksheet.SetValue(1, 11, count.ToString()); MemoryStream stream = new MemoryStream(); workbook.SaveAs(stream); workbook.Close(); Xamarin.Forms.DependencyService.Get <ISave>().Save("trees.xls", "application/msexcel", stream); } }
private void ShowGraphpick2() { SummList.IsVisible = false; ListOfTree.IsVisible = false; GirthOT.IsVisible = false; Girtdlab.IsVisible = true; Girtdswitch.IsVisible = true; if (ShowGraph.SelectedIndex > -1) { } else { brac = -1; } //show regular data for each tree if (ShowGraph.SelectedIndex == 0) { SelectPlot(); Earlier.IsVisible = false; Later.IsVisible = false; ShowGraph.SelectedIndex -= 1; } // averages and data by log class else if (ShowGraph.SelectedIndex == 1 || ShowGraph.SelectedIndex == 2) { ObservableCollection <DetailsGraph> Detail = new ObservableCollection <DetailsGraph>(); Plot ThisPlot = ((List <Plot>)Application.Current.Properties["Plots"]).ElementAt(pickPlot.SelectedIndex); if (ThisPlot.getTrees().Count <= 0) { Device.BeginInvokeOnMainThread(async() => { await DisplayAlert(AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("NoTrees"), "This plot contains no trees.", "OK"); return; }); } PriceRange thisRange = ((List <PriceRange>)Application.Current.Properties["Prices"]).ElementAt(PickPrice.SelectedIndex); Calculator Calc = new Calculator(); Calc.SetPrices(thisRange); double total = 0; List <string> Lablels = new List <string>(); List <string> ListLablels = new List <string>(); for (int x = -1; x < thisRange.GetBrack().Count; x++) { if (x == -1) { Lablels.Add("<" + Math.Round((thisRange.GetBrack().ElementAt(0).Key *(Girtdswitch.IsToggled ? 1 : Math.PI)), 2).ToString() + "cm"); } else if (x == thisRange.GetBrack().Count - 1) { Lablels.Add(">" + Math.Round(thisRange.GetBrack().ElementAt(x).Key *(Girtdswitch.IsToggled ? 1 : Math.PI), 2) + "cm"); } else { Lablels.Add(Math.Round(thisRange.GetBrack().ElementAt(x + 1).Key *(Girtdswitch.IsToggled ? 1 : Math.PI), 2) + "cm"); } } Lablels.Add(AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Totals")); int[] logs = new int[thisRange.GetBrack().Count + 1]; int[] logsmerch = new int[thisRange.GetBrack().Count + 1]; double[] vols = new double[thisRange.GetBrack().Count + 1]; double[] volsmerch = new double[thisRange.GetBrack().Count + 1]; double[] vals = new double[thisRange.GetBrack().Count + 1]; double totalvol = 0; double totalvolM = 0; double totalDia = 0; double absVol = 0; double totalTree = 0; int count = 0; int tcount = 0; for (int y = 0; y < ThisPlot.getTrees().Count; y++) { Tree ThisTree = ThisPlot.getTrees().ElementAt(y); SortedList <DateTime, (double, double, double)> Thistory = ThisTree.GetHistory(); try { double[,] result = Calc.Calcs(ThisTree.GetDia(), ThisTree.Merch, ThisTree.ActualMerchHeight); absVol += (0.423 * Math.PI * Math.Pow((ThisTree.GetDia()), 2) * ThisTree.Merch) / 40000; for (int x = 0; x < result.GetLength(0); x++) { logs[(int)result[x, 0] + 1]++; logsmerch[(int)result[x, 0] + 1] += ((result[x, 1] <= 0) ? 0 : 1); vols[(int)result[x, 0] + 1] += result[x, 2]; volsmerch[(int)result[x, 0] + 1] += result[x, 2] * ((result[x, 1] <= 0) ? 0 : 1); vals[(int)result[x, 0] + 1] += result[x, 1]; totalvol += result[x, 2]; totalvolM += ((result[x, 1] <= 0) ? 0 : 1) * result[x, 2]; total += result[x, 1]; totalDia += Math.Max(result[x, 3], 0) * ((result[x, 1] <= 0) ? 0 : 1); count += ((result[x, 1] <= 0) ? 0 : 1); } } catch { } totalTree += ThisTree.GetDia() / Math.PI; tcount++; } // data by log class if (ShowGraph.SelectedIndex == 1) { GirthOT.Text = ""; if (((bool)Application.Current.Properties["Tutorial"]) && (bool)Application.Current.Properties["TLogs"]) { Device.BeginInvokeOnMainThread(async() => { await DisplayAlert("Logs", AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("SummaryTute"), AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Continue")); }); Application.Current.Properties["TLogs"] = false; } Listhadler = 1; for (int x = 1; x < thisRange.GetBrack().Count + 1; x++) { Detail.Add(new DetailsGraph { label = Lablels.ElementAt(x), volume = Math.Round(vols[x], 4), price = Math.Round(vals[x] * (((int)Application.Current.Properties["Currenselect"] == -1 ? 1 : ((List <(string, double)>)Application.Current.Properties["Currenlist"]).ElementAt((int)Application.Current.Properties["Currenselect"]).Item2)), 2), logs = logsmerch[x] });
//activates when index is changed in the plot picker public async void SelectPlot() { string trees = ""; if (pickTree.SelectedIndex != -1) { pickTree.SelectedIndex = -1; return; } SummList.IsVisible = false; Girtdlab.IsVisible = true; Girtdswitch.IsVisible = true; PlotList.IsVisible = false; Listhadler = 0; ShowGraph.IsVisible = true; ObservableCollection <Tree> TreeTails = new ObservableCollection <Tree>(); string girths = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Girth") + "\n"; string heights = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Height") + "\n"; if (pickPlot.SelectedIndex == pickPlot.Items.Count - 1 && pickPlot.SelectedIndex > -1) { await Navigation.PushAsync(new NotPopup()); return; } if (pickPlot.SelectedIndex > -1) { ShowGraph.IsVisible = true; Plot ThisPlot = ((List <Plot>)Application.Current.Properties["Plots"]).ElementAt(pickPlot.SelectedIndex); trees = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Name") + ": " + ThisPlot.GetName() + " "; if (ThisPlot.Owner != null && ThisPlot.Owner != "") { trees += AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Owner") + ": " + ThisPlot.Owner + "\n"; } if (ThisPlot.NearestTown != null && ThisPlot.NearestTown != "") { trees += AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Location") + ": " + ThisPlot.NearestTown + "\n"; } if (ThisPlot.Describe != null && ThisPlot.Describe != "") { trees += AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Comments") + ": " + ThisPlot.Describe + "\n"; } List <string> IDlis = new List <string>(); List <Tree> TreeList = ThisPlot.getTrees(); List <DetailsGraph2> Detailstree = new List <DetailsGraph2>(); Tree ThisTree; // pickTree.Items.Clear(); for (int x = 0; x < TreeList.Count; x++) { ThisTree = TreeList.ElementAt(x); Detailstree.Add(new DetailsGraph2() { girth = Math.Round(ThisTree.Diameter * (Girtdswitch.IsToggled?1 / Math.PI : 1), 2), ID = ThisTree.Id, price = ThisTree.Merch, tree = ThisTree, label2 = (ThisTree.ActualMerchHeight > 0)? ThisTree.ActualMerchHeight.ToString():"?" }); TreeTails.Add(ThisTree); IDlis.Add(ThisTree.ID.ToString()); } pickTree.ItemsSource = IDlis; DetailsList.IsVisible = true; LogClassList.IsVisible = false; LogList.IsVisible = false; ListOfTree.Text = ""; GirthOT.Text = ""; HeightOT.Text = ""; DetailsList.ItemsSource = Detailstree; DetailsList.HeightRequest = (40 * Math.Min(TreeTails.Count, 5)) + (10 * Math.Min(TreeTails.Count, 5)) + 60; PlotTitle.Text = trees; pickTree.IsVisible = false; } else { base.OnAppearing(); } }
public async void RunCalc() { Calculator calc = new Calculator(); Plot thispolt = null; if (pickPlotOne.SelectedIndex > -1) { thispolt = ((List <Plot>)Application.Current.Properties["Plots"]).ElementAt(pickPlotOne.SelectedIndex); } else { try { thispolt = ((List <Plot>)Application.Current.Properties["Plots"]).ElementAt(pickPlot.SelectedIndex); } catch { } } if (PickPrice.SelectedIndex > -1) { double totalv = 0; double totalp = 0; List <DetailsGraph2> Detail = new List <DetailsGraph2>(); calc.SetPrices(((List <PriceRange>)Application.Current.Properties["Prices"]).ElementAt(PickPrice.SelectedIndex)); double[,] result; if (calc.GetPrices() == null) { Device.BeginInvokeOnMainThread(async() => { bool reslut = await DisplayAlert(AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("PSPrice"), AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("PSPrice"), "OK", "Add Price Scheme"); if (!reslut) { await Navigation.PushAsync(new CreatePricing()); } }); return; } if (Double.TryParse(merchheight.Text, out double ans) && ans > 0 && girth.Text != null && height.Text != null) { result = calc.Calcs(double.Parse(girth.Text) * (GirthDBH.IsToggled ? Math.PI : 1), double.Parse(height.Text), ans); } else if (girth.Text != null && height.Text != null) { result = calc.Calcs(double.Parse(girth.Text) * (GirthDBH.IsToggled ? Math.PI : 1), double.Parse(height.Text)); } else { return; } string resText0 = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("LogClass") + "\n"; string resText1 = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Price") + "\n"; string resText2 = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Volume") + "\n"; SortedList <double, double> brack = calc.GetPrices().GetBrack(); string[] unitcm = { "cm" }; string[] unitm = { "m" }; string[] unitm3 = { "m\xB3" }; for (int i = 0; i < result.GetLength(0); i++) { totalv += result[i, 2]; totalp += result[i, 1] * (((int)Application.Current.Properties["Currenselect"] == -1 ? 1 : ((List <(string, double)>)Application.Current.Properties["Currenlist"]).ElementAt((int)Application.Current.Properties["Currenselect"]).Item2)); DetailsGraph2 answer = new DetailsGraph2 { volume = Math.Round(result[i, 2], 4), price = Math.Round(result[i, 1] * (((int)Application.Current.Properties["Currenselect"] == -1 ? 1 : ((List <(string, double)>)Application.Current.Properties["Currenlist"]).ElementAt((int)Application.Current.Properties["Currenselect"]).Item2)), 2), result = result, brack = brack, resultrow = i }; if (result[i, 0] == -1) { answer.label = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("TooSmall"); } else if (result[i, 0] == brack.Count - 1) { answer.label = (Math.Round(brack.ElementAt((int)result[i, 0]).Key *(GirthDBH2.IsToggled ? 1 / Math.PI : 1), 2) + unitcm[0] + AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("OrLarger")); } else { answer.label = (Math.Round(brack.ElementAt((int)result[i, 0]).Key *(GirthDBH2.IsToggled ? 1 / Math.PI : 1), 2)) + "-" + Math.Round(brack.ElementAt((int)result[i, 0] + 1).Key *(GirthDBH2.IsToggled ? 1 / Math.PI : 1), 2) + unitcm[0]; } Detail.Add(answer); } DetailsGraph2 answer2 = new DetailsGraph2 { volume = Math.Round(totalv, 4), price = Math.Round(totalp, 2), label = AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("Totals") }; Detail.Add(answer2); await PopupNavigation.Instance.PushAsync(MeasureResult.GetInstance(Detail)); // LogList.ItemsSource = Detail; //LogList.IsVisible = true; } else { Device.BeginInvokeOnMainThread(async() => { bool result = await DisplayAlert(AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("PSPrice"), AppResource.ResourceManager.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true).GetString("PSPrice"), "OK", "( Price Scheme"); if (!result) { await Navigation.PushAsync(new CreatePricing()); } }); } }