private void guardarLineaBtn_Click(object sender, EventArgs e) { try { PROYECTO p = (PROYECTO)Program.Cache.Get("project"); LINEAINVENTARIO newLine = new LINEAINVENTARIO(); LINEAINVENTARIO currentLine = (LINEAINVENTARIO)lineaInvBS.Current; FORMULARIO f = form.GetForm(newForm.NROFORMULARIO); bool error = false; if (especieCbx.SelectedItem == null) { controladorErrores.SetError(especieCbx, "Seleccione una especie."); error = true; } if (estadoCbx.SelectedItem == null) { controladorErrores.SetError(estadoCbx, "Seleccione una estado sanitario."); error = true; } if (calidadCbx.SelectedItem == null) { controladorErrores.SetError(calidadCbx, "Asocie una calidad al arbol."); error = true; } if (decimal.Parse(nroArbolTxt.Text) < 1) { controladorErrores.SetError(nroArbolTxt, "El numero de arbol debe ser mayor que cero."); error = true; } if (decimal.Parse(alturaComercialTxt.Text) < 0) { controladorErrores.SetError(alturaComercialTxt, "La altura comercial del arbol debe ser mayor que cero."); error = true; } if (decimal.Parse(alturaTotalTxt.Text) < 0) { controladorErrores.SetError(alturaTotalTxt, "La altura total del arbol debe ser mayor que cero."); error = true; } if (decimal.Parse(cAPDAPTxt.Text) < 0) { controladorErrores.SetError(cAPDAPTxt, "El valor de la circufernecia de arbol debe ser mayor o igual a cero."); error = true; } if (error) return; controladorErrores.Clear(); if (currentLine.LINEAINV == Guid.Empty) { newLine.LINEAINV = Guid.NewGuid(); newLine.FORMULARIO = f; newLine.ESPECIE = (ESPECIE)especieCbx.SelectedItem; newLine.CALIDAD = (CALIDAD)calidadCbx.SelectedItem; newLine.ESTADOSANITARIO = (ESTADOSANITARIO)estadoCbx.SelectedItem; newLine.NROARB = int.Parse(nroArbolTxt.Text); newLine.TIPOARBOL = ((KeyValuePair<string, string>)tipoArbolCbx.SelectedItem).Key; newLine.ALTCOMER_M = decimal.Parse(alturaComercialTxt.Text); newLine.ALTTOT_M = decimal.Parse(alturaTotalTxt.Text); newLine.CAP = CAPRbtn.Checked ? decimal.Parse(cAPDAPTxt.Text) : (decimal)Math.Round(decimal.Parse(cAPDAPTxt.Text) * (decimal)Math.PI, 3); newLine.DAP = DAPRbtn.Checked ? decimal.Parse(cAPDAPTxt.Text) : (decimal)Math.Round(decimal.Parse(cAPDAPTxt.Text) / (decimal)Math.PI, 3); newLine.AREABASAL = Math.Round((decimal)(ForestCalculatorHelper.BasalAreaCAP((double)newLine.CAP)),3); Dictionary<string, double> valores = new Dictionary<string, double>(); valores.Add("H", (double)newLine.ALTTOT_M); valores.Add("FF", (double)p.FACTORDEFORMA); valores.Add("AB", (double)newLine.AREABASAL); Evaluador_Expressiones evaluador= new Evaluador_Expressiones(); AleTermResult val = evaluador.EvaluarExpresion(p.FORMULA.EXPRESION, valores, ParentForm); valores["DAP"]=(double)newLine.ALTCOMER_M; val = evaluador.EvaluarExpresion(p.FORMULA.EXPRESION, valores, ParentForm); newLine.VOLCOM = Math.Round((decimal)(ForestCalculatorHelper.TreeVolumeByBasalArea((double)newLine.AREABASAL, (double)newLine.ALTCOMER_M, (double)p.FACTORDEFORMA)),3); newLine.VOLTOT = Math.Round((decimal)(ForestCalculatorHelper.TreeVolumeByBasalArea((double)newLine.AREABASAL, (double)newLine.ALTTOT_M, (double)p.FACTORDEFORMA)),3); lineInv.InsertInventoryLine(newLine); f = form.GetForm(newForm.NROFORMULARIO); string resultSaveChangues = lineInv.SaveChanges(); if (resultSaveChangues == "") { lineaInvBS.DataSource = f.LINEAINVENTARIO.ToList(); lineaInvBN.Refresh(); MessageBox.Show("Los datos fueron almacenados de manera exitosa.", "Operacion exitosa", MessageBoxButtons.OK, MessageBoxIcon.Information); lineaInvBS.AddNew(); especieCbx.SelectedItem = newLine.ESPECIE; if (newLine.TIPOARBOL == "BFB") { nroArbolTxt.Text = newLine.NROARB.ToString(); alturaComercialTxt.Text = newLine.ALTCOMER_M.ToString(); alturaTotalTxt.Text = newLine.ALTTOT_M.ToString(); tipoArbolCbx.SelectedValue = "BFB"; } else tipoArbolCbx.SelectedValue = "NBF"; } else { Error_Form errorForm = new Error_Form(resultSaveChangues); errorForm.MdiParent = ParentForm; errorForm.Show(); } } else { currentLine.ESPECIE = (ESPECIE)especieCbx.SelectedItem; currentLine.CALIDAD = (CALIDAD)calidadCbx.SelectedItem; currentLine.ESTADOSANITARIO = (ESTADOSANITARIO)estadoCbx.SelectedItem; currentLine.NROARB = int.Parse(nroArbolTxt.Text); currentLine.TIPOARBOL = ((KeyValuePair<string, string>)tipoArbolCbx.SelectedItem).Key; currentLine.ALTCOMER_M = decimal.Parse(alturaComercialTxt.Text); currentLine.ALTTOT_M = decimal.Parse(alturaTotalTxt.Text); newLine.CAP = CAPRbtn.Checked ? decimal.Parse(cAPDAPTxt.Text) : (decimal)Math.Round(decimal.Parse(cAPDAPTxt.Text) * (decimal)Math.PI, 3); newLine.DAP = DAPRbtn.Checked ? decimal.Parse(cAPDAPTxt.Text) : (decimal)Math.Round(decimal.Parse(cAPDAPTxt.Text) / (decimal)Math.PI, 3); currentLine.AREABASAL = (decimal)(ForestCalculatorHelper.BasalAreaDAP((double)newLine.DAP)); currentLine.VOLCOM = (decimal)(ForestCalculatorHelper.TreeVolumeByBasalArea((double)newLine.AREABASAL, (double)newLine.ALTCOMER_M, (double)p.FACTORDEFORMA)); currentLine.VOLTOT = (decimal)(ForestCalculatorHelper.TreeVolumeByBasalArea((double)newLine.AREABASAL, (double)newLine.ALTTOT_M, (double)p.FACTORDEFORMA)); lineInv.UpdateInventoryLine(currentLine); f = form.GetForm(newForm.NROFORMULARIO); string resultSaveChangues = lineInv.SaveChanges(); if (resultSaveChangues == "") { lineaInvBS.DataSource = f.LINEAINVENTARIO.ToList(); lineaInvBN.Refresh(); MessageBox.Show("Los datos fueron actualizados de manera exitosa.", "Operacion exitosa", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { Error_Form errorForm = new Error_Form(resultSaveChangues); errorForm.MdiParent = ParentForm; errorForm.Show(); } } modified = true; PROYECTO result = project.GetProject(newForm.PROYECTO.NROPROY); Program.Cache.Add("project", result, new CacheItemPolicy()); } catch (Exception ex) { Error_Form errorForm = new Error_Form(ex.Message); errorForm.MdiParent = ParentForm; errorForm.Show(); } }
private void calcularParametros() { PROYECTO p = (PROYECTO)Program.Cache.Get("project"); if (p!=null) { double areaBasal = cAPDAPTxt.Text != string.Empty && CAPRbtn.Checked ? Math.Round(ForestCalculatorHelper.BasalAreaCAP(double.Parse(cAPDAPTxt.Text)), 3) : cAPDAPTxt.Text != string.Empty && DAPRbtn.Checked ?Math.Round(ForestCalculatorHelper.BasalAreaDAP(double.Parse(cAPDAPTxt.Text)), 3):0; Dictionary<string, double> valores = new Dictionary<string, double>(); valores.Add("H", double.Parse(alturaComercialTxt.Text)); valores.Add("FF", (double)p.FACTORDEFORMA); valores.Add("AB", areaBasal); Evaluador_Expressiones evaluador = new Evaluador_Expressiones(); AleTermResult val = evaluador.EvaluarExpresion(p.FORMULA.EXPRESION, valores, ParentForm); valores["DAP"] = double.Parse(alturaTotalTxt.Text); val = evaluador.EvaluarExpresion(p.FORMULA.EXPRESION, valores, ParentForm); double diametroAP = cAPDAPTxt.Text != string.Empty ? Math.Round(double.Parse(cAPDAPTxt.Text) / Math.PI, 3) : 0; double circuferenciaAP = cAPDAPTxt.Text != string.Empty ? Math.Round(double.Parse(cAPDAPTxt.Text) * Math.PI, 3) : 0; double volumenComercial =alturaComercialTxt.Text!=string.Empty? Math.Round(ForestCalculatorHelper.TreeVolumeByBasalArea(areaBasal, double.Parse(alturaComercialTxt.Text), (double)p.FACTORDEFORMA), 3):0; double volumenTotal = alturaTotalTxt.Text != string.Empty ? Math.Round(ForestCalculatorHelper.TreeVolumeByBasalArea(areaBasal, double.Parse(alturaTotalTxt.Text), (double)p.FACTORDEFORMA), 3) : 0; if (DAPRbtn.Checked) parametrosLineaTxt.Text = "1) Factor de Forma: " + (double)p.FACTORDEFORMA + Environment.NewLine + "2) Circunferencia A.P: " + circuferenciaAP + Environment.NewLine + "3) Area basal: " + areaBasal + Environment.NewLine + "4) Volumen comercial: " + volumenComercial + Environment.NewLine + "5) Volumen total: " + volumenTotal; else parametrosLineaTxt.Text = "1) Factor de Forma: " + (double)p.FACTORDEFORMA + Environment.NewLine + "2) Diametro A.P: " + diametroAP + Environment.NewLine + "3) Area basal: " + areaBasal + Environment.NewLine + "4) Volumen comercial: " + volumenComercial + Environment.NewLine + "5) Volumen total: " + volumenTotal; } }