protected void ResetRblActionProposedColors() { RadioButtonList rblActionProposed = (RadioButtonList)formViewTlProject_Organism.FindControl("rblActionProposed"); foreach (ListItem li in rblActionProposed.Items) { ActionProposed ap = new ActionProposedBLL().GetActionProposedByActionProposedID(Convert.ToInt32(li.Value)); li.Attributes.Add("style", "background-color: #" + ap.Color.Code + ";"); } }
protected void rblActionProposed_DataBound(object sender, EventArgs e) { int select = 5; string project_organismID = Page.RouteData.Values["project_organism_id"] as string; if (project_organismID != null && project_organismID != "0") { select = (int)treeDetail.ActionProposedID; } foreach (ListItem li in ((RadioButtonList)sender).Items) { ActionProposed ap = new ActionProposedBLL().GetActionProposedByActionProposedID(Convert.ToInt32(li.Value)); li.Attributes.Add("style", "background-color: #" + ap.Color.Code + ";"); if (li.Value == select.ToString()) { li.Selected = true; } } }
protected void FormViewTlProject_Organism_ItemUpdating(object sender, FormViewUpdateEventArgs e) { User editor = new UserBLL().GetUserByUserName((HttpContext.Current.User.Identity).Name); Project_Organisms project_Organisms = new Project_OrganismsBLL().GetProject_OrganismsByProjectOrganismID((int)e.Keys["ProjectOrganismID"]); using (DatabaseContext _DatabaseContext = new DatabaseContext()) { // TreeDetail TextBox txtVaras = (TextBox)formViewTlProject_Organism.FindControl("txtVaras"); HiddenField hfDap = (HiddenField)formViewTlProject_Organism.FindControl("hfDap"); TextBox txtHeight = (TextBox)formViewTlProject_Organism.FindControl("txtHeight"); TextBox txtCommentary = (TextBox)formViewTlProject_Organism.FindControl("txtCommentary"); Label lblNumber = (Label)formViewTlProject_Organism.FindControl("lblNumber"); TextBox txtX = (TextBox)formViewTlProject_Organism.FindControl("txtX"); TextBox txtY = (TextBox)formViewTlProject_Organism.FindControl("txtY"); TextBox txtLat = (TextBox)formViewTlProject_Organism.FindControl("txtLat"); TextBox txtLon = (TextBox)formViewTlProject_Organism.FindControl("txtLon"); RadioButtonList rblActionProposed = (RadioButtonList)formViewTlProject_Organism.FindControl("rblActionProposed"); RadioButtonList rblCondition = (RadioButtonList)formViewTlProject_Organism.FindControl("rblCondition"); // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Edgardo Ramos - 20130928 CheckBox chkLittoral = (CheckBox)formViewTlProject_Organism.FindControl("chkLittoral"); CheckBox chkMaritimeZone = (CheckBox)formViewTlProject_Organism.FindControl("chkMaritimeZone"); CheckBox cbCepa = (CheckBox)formViewTlProject_Organism.FindControl("cbCepa"); // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- TreeDetail treeDetail = _DatabaseContext.TreeDetails.First(instance => instance.ProjectOrganismID == project_Organisms.ProjectOrganismID); //Delete existing Daps foreach (Dap item in _DatabaseContext.Daps.Where(instance => instance.TreeDetailsID == treeDetail.TreeDetailsID).ToList()) { _DatabaseContext.Daps.DeleteObject(item); } if (cbCepa.Checked)// Is Cepa { treeDetail.Dap = 0; treeDetail.Dap_Counter = 0; treeDetail.Varas = Convert.ToInt32(string.IsNullOrEmpty(txtVaras.Text) ? "0" : txtVaras.Text); } else { treeDetail.Varas = 0; var dapsList = hfDap.Value.Split(',').ToList(); if (dapsList.Count == 1) // Solo un Dap { decimal dap = Convert.ToDecimal(dapsList[0]); treeDetail.Dap = dap; treeDetail.Dap_Counter = 1; Dap dapObj = new Dap(); dapObj.DapValue = dap; dapObj.TreeDetailsID = treeDetail.TreeDetailsID; dapObj.TreeDetailReference.EntityKey = treeDetail.EntityKey; _DatabaseContext.Daps.AddObject(dapObj); } else // 1 o Mas de un Dap { string[] daps = hfDap.Value.Split(','); double dapTotal = 0; foreach (string dap in daps) { dapTotal += Convert.ToDouble(dap); } treeDetail.Dap = Convert.ToDecimal(Math.Round(Math.Sqrt(Math.Pow(dapTotal, 2D) / Convert.ToDouble(daps.Count())) * 100) / 100); treeDetail.Dap_Counter = daps.Count(); foreach (string dapString in daps) { Dap dap = new Dap(); dap.DapValue = Convert.ToDecimal(dapString); dap.TreeDetailsID = treeDetail.TreeDetailsID; dap.TreeDetailReference.EntityKey = treeDetail.EntityKey; _DatabaseContext.Daps.AddObject(dap); } } } treeDetail.Height = Convert.ToDecimal(txtHeight.Text); treeDetail.Commentary = (txtCommentary.Text.Length > txtCommentary.MaxLength) ? txtCommentary.Text.Substring(0, txtCommentary.MaxLength) : txtCommentary.Text; treeDetail.Number = Convert.ToInt32(lblNumber.Text); // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Edgardo Ramos - 20130928 decimal dec; RadioButtonList rblPosition = (RadioButtonList)formViewTlProject_Organism.FindControl("rblPosition"); if (rblPosition.SelectedValue == "0") // Nad83 { treeDetail.X = decimal.TryParse(txtX.Text, out dec) ? Convert.ToDecimal(txtX.Text) : 0; treeDetail.Y = decimal.TryParse(txtY.Text, out dec) ? Convert.ToDecimal(txtY.Text) : 0; if (treeDetail.X != 0 && treeDetail.Y != 0) { Dictionary <string, object> anewpointObj = Utility.ConvertToLatLng(treeDetail.X.ToString(), treeDetail.Y.ToString(), @"~/App_Resources/client-scripts/tl/"); treeDetail.Lat = Convert.ToDecimal(anewpointObj["y"]); txtLat.Text = treeDetail.Lat.ToString(); treeDetail.Lon = Convert.ToDecimal(anewpointObj["x"]); txtLon.Text = treeDetail.Lon.ToString(); } else { treeDetail.Lat = 0; treeDetail.Lon = 0; } } else // StatePlanes { treeDetail.Lat = decimal.TryParse(txtLat.Text, out dec) ? Convert.ToDecimal(txtLat.Text) : 0; treeDetail.Lon = decimal.TryParse(txtLon.Text, out dec) ? Convert.ToDecimal(txtLon.Text) : 0; if (treeDetail.Lat != 0 && treeDetail.Lon != 0) { Dictionary <string, object> anewpointObj = Utility.ConvertToStatePlane(treeDetail.Lon.ToString(), treeDetail.Lat.ToString(), @"~/App_Resources/client-scripts/tl/"); treeDetail.X = Convert.ToDecimal(anewpointObj["x"]); txtX.Text = treeDetail.X.ToString(); treeDetail.Y = Convert.ToDecimal(anewpointObj["y"]); txtY.Text = treeDetail.Y.ToString(); } else { treeDetail.X = 0; treeDetail.Y = 0; } } //treeDetail.X = Convert.ToDecimal(txtX.Text); //treeDetail.Y = Convert.ToDecimal(txtY.Text); //treeDetail.Lat = Convert.ToDecimal(txtLat.Text); //treeDetail.Lon = Convert.ToDecimal(txtLon.Text); treeDetail.Littoral = chkLittoral.Checked; treeDetail.MaritimeZone = chkMaritimeZone.Checked; // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- treeDetail.EditedDate = DateTime.Now; treeDetail.EditorUserID = editor.UserID; ActionProposed actionProposed = new ActionProposedBLL().GetActionProposedByActionProposedID(Convert.ToInt32(rblActionProposed.SelectedValue)); treeDetail.ActionProposedID = actionProposed.ActionProposedID; treeDetail.ActionProposedReference.EntityKey = actionProposed.EntityKey; Condition condition = new ConditionBLL().GetConditionByConditionID(Convert.ToInt32(rblCondition.SelectedValue)); treeDetail.ConditionID = condition.ConditionID; treeDetail.ConditionReference.EntityKey = condition.EntityKey; treeDetail.ProjectOrganismID = project_Organisms.ProjectOrganismID; treeDetail.Project_OrganismsReference.EntityKey = project_Organisms.EntityKey; _DatabaseContext.SaveChanges(); // } Type myType = (typeof(Project_Organisms)); PropertyInfo[] props = myType.GetProperties(); string[] arrNewValues = new string[e.NewValues.Keys.Count]; e.NewValues.Keys.CopyTo(arrNewValues, 0); foreach (var prop in props) { if (("System.String,System.Int,System.DateTime,System.Guid,System.Boolean").IndexOf((prop.PropertyType).FullName) >= 0) // Si la propiedad es de tipo Guid, String, Int, Boolean o DateTime { if (!arrNewValues.Contains(prop.Name)) { e.NewValues[prop.Name] = prop.GetValue(project_Organisms, null); } } } e.NewValues["ProjectID"] = RouteData.Values["Project_id"].ToString(); e.NewValues["OrganismID"] = ((HiddenField)formViewTlProject_Organism.FindControl("hfOrganism")).Value; e.NewValues["EditorUserId"] = editor.UserID.ToString(); e.NewValues["EditedDate"] = DateTime.Now; }
protected void OdsProject_Organism_Details_Inserted(object sender, System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs e) { int result = Convert.ToInt32(e.ReturnValue, System.Globalization.CultureInfo.CurrentCulture.NumberFormat); //string lat = ""; //string lon = ""; if (result != 0) { Project_Organisms project_Organisms = new Project_OrganismsBLL().GetProject_OrganismsByProjectOrganismID(result); ProjectInfoTreeLocation projectInfoTreeLocation = new ProjectInfoTreeLocationBLL().GetProjectInfoTreeLocationsByProjectID(project_Organisms.ProjectID)[0]; bool fromInventory = false; UserBLL userBLL = new UserBLL(); Eisk.BusinessEntities.User user = userBLL.GetUserByUserName((HttpContext.Current.User.Identity).Name); if (user != null) { // TreeDetail TextBox txtVaras = (TextBox)formViewTlProject_Organism.FindControl("txtVaras"); HiddenField hfDap = (HiddenField)formViewTlProject_Organism.FindControl("hfDap"); TextBox txtDap = (TextBox)formViewTlProject_Organism.FindControl("txtDap"); TextBox txtDapCounter = (TextBox)formViewTlProject_Organism.FindControl("txtDapCounter"); TextBox txtHeight = (TextBox)formViewTlProject_Organism.FindControl("txtHeight"); TextBox txtCommentary = (TextBox)formViewTlProject_Organism.FindControl("txtCommentary"); Label lblNumber = (Label)formViewTlProject_Organism.FindControl("lblNumber"); TextBox txtX = (TextBox)formViewTlProject_Organism.FindControl("txtX"); TextBox txtY = (TextBox)formViewTlProject_Organism.FindControl("txtY"); TextBox txtLat = (TextBox)formViewTlProject_Organism.FindControl("txtLat"); TextBox txtLon = (TextBox)formViewTlProject_Organism.FindControl("txtLon"); RadioButtonList rblActionProposed = (RadioButtonList)formViewTlProject_Organism.FindControl("rblActionProposed"); RadioButtonList rblCondition = (RadioButtonList)formViewTlProject_Organism.FindControl("rblCondition"); // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Edgardo Ramos - 20130928 CheckBox chkLittoral = (CheckBox)formViewTlProject_Organism.FindControl("chkLittoral"); CheckBox chkMaritimeZone = (CheckBox)formViewTlProject_Organism.FindControl("chkMaritimeZone"); // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- TreeDetail treeDetail = new TreeDetail(); if (!string.IsNullOrEmpty(txtVaras.Text) && txtVaras.Text != "0") // Is Cepa { treeDetail.Dap = 0; treeDetail.Dap_Counter = 0; } else if (txtDapCounter.Text == "1") // Solo un Dap { //treeDetail.Dap = Convert.ToDecimal(txtDap.Text);// new DapBLL().GetDap(0); //treeDetail.Dap_Counter = Convert.ToInt32(txtDapCounter.Text); //new DapBLL().GetDapCount(0); treeDetail.Dap = Convert.ToDecimal(hfDap.Value); // new DapBLL().GetDap(0); treeDetail.Dap_Counter = Convert.ToInt32(1); //new DapBLL().GetDapCount(0); } else // Mas de un Dap { string[] daps = hfDap.Value.Split(','); double dapTotal = 0; foreach (string dap in daps) { dapTotal += Convert.ToDouble(dap); }//dapTotal;// new DapBLL().GetDap(0); treeDetail.Dap = Convert.ToDecimal(Math.Round(Math.Sqrt(Math.Pow(dapTotal, 2D) / Convert.ToDouble(daps.Count())) * 100) / 100); treeDetail.Dap_Counter = Convert.ToInt32(txtDapCounter.Text); //new DapBLL().GetDapCount(0); } treeDetail.Varas = Convert.ToInt32(string.IsNullOrEmpty(txtVaras.Text) ? "0" : txtVaras.Text); treeDetail.Height = Convert.ToDecimal(txtHeight.Text); treeDetail.Commentary = (txtCommentary.Text.Length > txtCommentary.MaxLength) ? txtCommentary.Text.Substring(0, txtCommentary.MaxLength) : txtCommentary.Text; treeDetail.Number = Convert.ToInt32(lblNumber.Text); // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Edgardo Ramos - 20130928 decimal dec; RadioButtonList rblPosition = (RadioButtonList)formViewTlProject_Organism.FindControl("rblPosition"); if (rblPosition.SelectedValue == "0") // Nad83 { treeDetail.X = decimal.TryParse(txtX.Text, out dec) ? Convert.ToDecimal(txtX.Text) : 0; treeDetail.Y = decimal.TryParse(txtY.Text, out dec) ? Convert.ToDecimal(txtY.Text) : 0; if (treeDetail.X != 0 && treeDetail.Y != 0) { Dictionary <string, object> anewpointObj = Utility.ConvertToLatLng(treeDetail.X.ToString(), treeDetail.Y.ToString(), @"~/App_Resources/client-scripts/tl/"); treeDetail.Lat = Convert.ToDecimal(anewpointObj["y"]); txtLat.Text = treeDetail.Lat.ToString(); treeDetail.Lon = Convert.ToDecimal(anewpointObj["x"]); txtLon.Text = treeDetail.Lon.ToString(); } else { treeDetail.Lat = 0; treeDetail.Lon = 0; } } else // StatePlanes { treeDetail.Lat = decimal.TryParse(txtLat.Text, out dec) ? Convert.ToDecimal(txtLat.Text) : 0; treeDetail.Lon = decimal.TryParse(txtLon.Text, out dec) ? Convert.ToDecimal(txtLon.Text) : 0; if (treeDetail.Lat != 0 && treeDetail.Lon != 0) { Dictionary <string, object> anewpointObj = Utility.ConvertToStatePlane(treeDetail.Lon.ToString(), treeDetail.Lat.ToString(), @"~/App_Resources/client-scripts/tl/"); treeDetail.X = Convert.ToDecimal(anewpointObj["x"]); txtX.Text = treeDetail.X.ToString(); treeDetail.Y = Convert.ToDecimal(anewpointObj["y"]); txtY.Text = treeDetail.Y.ToString(); } else { treeDetail.X = 0; treeDetail.Y = 0; } } //treeDetail.X = Convert.ToDecimal(txtX.Text); //treeDetail.Y = Convert.ToDecimal(txtY.Text); //treeDetail.Lat = Convert.ToDecimal(txtLat.Text); //treeDetail.Lon = Convert.ToDecimal(txtLon.Text); treeDetail.Littoral = chkLittoral.Checked; treeDetail.MaritimeZone = chkMaritimeZone.Checked; // --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- treeDetail.CreatedDate = DateTime.Now; treeDetail.CreatorUserID = user.UserID; treeDetail.EditedDate = DateTime.Now; treeDetail.EditorUserID = user.UserID; ActionProposed actionProposed = new ActionProposedBLL().GetActionProposedByActionProposedID(Convert.ToInt32(rblActionProposed.SelectedValue)); treeDetail.ActionProposedID = actionProposed.ActionProposedID; treeDetail.ActionProposedReference.EntityKey = actionProposed.EntityKey; Condition condition = new ConditionBLL().GetConditionByConditionID(Convert.ToInt32(rblCondition.SelectedValue)); treeDetail.ConditionID = condition.ConditionID; treeDetail.ConditionReference.EntityKey = condition.EntityKey; treeDetail.ProjectOrganismID = project_Organisms.ProjectOrganismID; treeDetail.Project_OrganismsReference.EntityKey = project_Organisms.EntityKey; int treeDetailID = new TreeDetailBLL().CreateNewTreeDetail(treeDetail); if (treeDetail.Varas != null && treeDetail.Varas > 0) // Is Cepa { // } else if (txtDapCounter.Text == "1") // Solo un Dap { Dap dap = new Dap(); dap.DapValue = Convert.ToDecimal(hfDap.Value); dap.TreeDetailsID = treeDetailID; dap.TreeDetailReference.EntityKey = treeDetail.EntityKey; new DapBLL().CreateNewDap(dap); } else // Mas de un Dap { string[] daps = hfDap.Value.Split(','); foreach (string dapString in daps) { Dap dap = new Dap(); dap.DapValue = Convert.ToDecimal(dapString); dap.TreeDetailsID = treeDetailID; dap.TreeDetailReference.EntityKey = treeDetail.EntityKey; new DapBLL().CreateNewDap(dap); } } fromInventory = Convert.ToDecimal(projectInfoTreeLocation.X) == Convert.ToDecimal(treeDetail.X) && Convert.ToDecimal(projectInfoTreeLocation.Y) == Convert.ToDecimal(treeDetail.Y); // } if (fromInventory) { Response.RedirectToRoute("tl-treeinventory", new { project_id = RouteData.Values["project_id"] }); } else { Response.RedirectToRoute("tl", new { Project_id = RouteData.Values["Project_id"] }); Response.RedirectLocation += "?poid=" + project_Organisms.ProjectOrganismID + "&lat=0&lon=0"; } //Response.RedirectToRoute("tl-tree-details_edit", new { edit_mode = "edit", project_id = Page.RouteData.Values["project_id"] as string, project_organism_id = result }); } }
protected void btnCloneSelected_Click(object sender, EventArgs e) { pnlCloneError.Style["display"] = "none"; lblCloneError.Text = ""; string invalidMessage = ""; string successMessage = ""; bool dapOrVaras = false; if (pnlCloneDap.Visible) { dapOrVaras = chkCloneDap.Checked; } else { dapOrVaras = chkCloneVaras.Checked; } #region Validate Characteristics if ( !chkCloneNombre.Checked && !dapOrVaras && !chkAltura.Checked && !chkAcciónPropuesta.Checked && !chkCondicion.Checked && !chkLitoral.Checked && !chkMaritimoTerrestre.Checked && !chkComentarios.Checked ) { invalidMessage += " • Seleccione al menos una característica <br />"; } #endregion #region Validate Árbol a ser Clonado Project_Organisms project_OrganismBase; if (!Project_OrganismsBLL.TryParse_ByNumber(txtCloneBase.Text, out project_OrganismBase)) { invalidMessage = " • Número del Árbol a ser Copiado Inválido<br />"; } #endregion List <Project_Organisms> ProjectOrganismsIDsToClone = new List <Project_Organisms>(); Project_Organisms project_OrganismFROM = null; Project_Organisms project_OrganismTO = null; if (!rbtCloneRange.Checked && rbtCloneSelect.Checked) {// Selected #region validate selected // Iterate through the Projects.Rows property foreach (GridViewRow row in gridViewTreeDetails.Rows) { // Access the CheckBox CheckBox cb = (CheckBox)(row.FindControl("chkTreeDetailsSelector")); if (cb != null && cb.Checked) { // Save the ProjectID value for deletion // First, get the ProjectID for the selected row Int32 treeDetailsID = (Int32)gridViewTreeDetails.DataKeys[row.RowIndex].Value; Eisk.BusinessEntities.TreeDetail treeDetail = new TreeDetailBLL().GetTreeDetailByTreeDetailsID(treeDetailsID); ProjectOrganismsIDsToClone.Add(treeDetail.Project_Organisms); } } if (ProjectOrganismsIDsToClone.Count == 0) { invalidMessage += " • Para copiar las características a los árboles previamente seleccionados debe seleccionar al menos uno <br />"; } #endregion } else {// Range #region validate range if (!Project_OrganismsBLL.TryParse_ByNumber(txtCloneFrom.Text, out project_OrganismFROM)) { invalidMessage += " • Número del Árbol " + '"' + "Desde" + '"' + " Inválido <br />"; } if (!Project_OrganismsBLL.TryParse_ByNumber(txtCloneTo.Text, out project_OrganismTO)) { invalidMessage += " • Número del Árbol " + '"' + "Hasta" + '"' + " Inválido <br />"; } if (project_OrganismFROM != null && project_OrganismTO != null) { if (project_OrganismFROM.TreeDetails.First().Number > project_OrganismTO.TreeDetails.First().Number) { invalidMessage += " • Número del Árbol " + '"' + "Desde" + '"' + " menor que " + '"' + "Hasta" + '"' + " <br />"; } } #endregion } if (!string.IsNullOrEmpty(invalidMessage)) { pnlCloneError.Style["display"] = "block"; pnlLoading.Style["display"] = "block"; pnlClone.Style["display"] = "block"; pnlCloneRange.Style["display"] = (rbtCloneRange.Checked) ? "block" : "none"; lblCloneError.Text = "<strong>Favor validar los siguientes detalles:</strong><br />" + invalidMessage; return; } else { using (DatabaseContext _DatabaseContext = new DatabaseContext()) { var treeDetailBASE = project_OrganismBase.TreeDetails.First(); if (!rbtCloneRange.Checked && rbtCloneSelect.Checked) {// Selected foreach (var projectOrganism in ProjectOrganismsIDsToClone) { var projectOrganismTHIS = _DatabaseContext.Project_Organisms.Where(i => i.ProjectOrganismID == projectOrganism.ProjectOrganismID).First(); var treeDetailTHIS = _DatabaseContext.TreeDetails.First(i => i.ProjectOrganismID == projectOrganismTHIS.ProjectOrganismID); if (chkCloneNombre.Checked) { Organism organism = new OrganismBLL().GetOrganismByOrganismID(project_OrganismBase.OrganismID); projectOrganismTHIS.OrganismID = organism.OrganismID; projectOrganismTHIS.OrganismReference.EntityKey = organism.EntityKey; } foreach (var item in _DatabaseContext.Daps.Where(instance => instance.TreeDetailsID == treeDetailTHIS.TreeDetailsID).ToList()) { _DatabaseContext.Daps.DeleteObject(item); } if (chkCloneVaras.Checked) { treeDetailTHIS.Varas = treeDetailBASE.Varas; } if (chkCloneDap.Checked) { treeDetailTHIS.Dap = treeDetailBASE.Dap; treeDetailTHIS.Dap_Counter = treeDetailBASE.Dap_Counter; foreach (var dap in treeDetailBASE.Daps) { Dap dapTHIS = new Dap(); dapTHIS.DapValue = dap.DapValue; dapTHIS.TreeDetailsID = treeDetailTHIS.TreeDetailsID; dapTHIS.TreeDetailReference.EntityKey = treeDetailTHIS.EntityKey; _DatabaseContext.Daps.AddObject(dapTHIS); } } if (chkAltura.Checked) { treeDetailTHIS.Height = treeDetailBASE.Height; } if (chkAcciónPropuesta.Checked) { ActionProposed actionProposed = new ActionProposedBLL().GetActionProposedByActionProposedID(Convert.ToInt32(treeDetailBASE.ActionProposedID)); treeDetailTHIS.ActionProposedID = actionProposed.ActionProposedID; treeDetailTHIS.ActionProposedReference.EntityKey = actionProposed.EntityKey; } if (chkCondicion.Checked) { Condition condition = new ConditionBLL().GetConditionByConditionID(Convert.ToInt32(treeDetailBASE.ConditionID)); treeDetailTHIS.ConditionID = condition.ConditionID; treeDetailTHIS.ConditionReference.EntityKey = condition.EntityKey; } if (chkLitoral.Checked) { treeDetailTHIS.Littoral = treeDetailBASE.Littoral; } if (chkMaritimoTerrestre.Checked) { treeDetailTHIS.MaritimeZone = treeDetailBASE.MaritimeZone; } if (chkComentarios.Checked) { treeDetailTHIS.Commentary = treeDetailBASE.Commentary; } } successMessage = "Las siguientes cararcterísticas del árbol #" + txtCloneBase.Text + " han sido copiadas satisfactóriamente a los " + ProjectOrganismsIDsToClone.Count + " árboles seleccionados: "; } else {// Range int from = project_OrganismFROM.TreeDetails.FirstOrDefault().Number.Value; int to = project_OrganismTO.TreeDetails.FirstOrDefault().Number.Value; for (int i = from; i <= to; i++) { var projectOrganismTHIS = _DatabaseContext.Project_Organisms.Where(instance => instance.TreeDetails.FirstOrDefault().Number == i).First(); var treeDetailTHIS = _DatabaseContext.TreeDetails.First(instance => instance.ProjectOrganismID == projectOrganismTHIS.ProjectOrganismID); if (chkCloneNombre.Checked) { Organism organism = new OrganismBLL().GetOrganismByOrganismID(project_OrganismBase.OrganismID); projectOrganismTHIS.OrganismID = organism.OrganismID; projectOrganismTHIS.OrganismReference.EntityKey = organism.EntityKey; } foreach (var item in _DatabaseContext.Daps.Where(instance => instance.TreeDetailsID == treeDetailTHIS.TreeDetailsID).ToList()) { _DatabaseContext.Daps.DeleteObject(item); } if (chkCloneVaras.Checked) { treeDetailTHIS.Varas = treeDetailBASE.Varas; } if (chkCloneDap.Checked) { treeDetailTHIS.Dap = treeDetailBASE.Dap; treeDetailTHIS.Dap_Counter = treeDetailBASE.Dap_Counter; foreach (var dap in treeDetailBASE.Daps) { Dap dapTHIS = new Dap(); dapTHIS.DapValue = dap.DapValue; dapTHIS.TreeDetailsID = treeDetailTHIS.TreeDetailsID; dapTHIS.TreeDetailReference.EntityKey = treeDetailTHIS.EntityKey; _DatabaseContext.Daps.AddObject(dapTHIS); } } if (chkAltura.Checked) { treeDetailTHIS.Height = treeDetailBASE.Height; } if (chkAcciónPropuesta.Checked) { ActionProposed actionProposed = new ActionProposedBLL().GetActionProposedByActionProposedID(Convert.ToInt32(treeDetailBASE.ActionProposedID)); treeDetailTHIS.ActionProposedID = actionProposed.ActionProposedID; treeDetailTHIS.ActionProposedReference.EntityKey = actionProposed.EntityKey; } if (chkCondicion.Checked) { Condition condition = new ConditionBLL().GetConditionByConditionID(Convert.ToInt32(treeDetailBASE.ConditionID)); treeDetailTHIS.ConditionID = condition.ConditionID; treeDetailTHIS.ConditionReference.EntityKey = condition.EntityKey; } if (chkLitoral.Checked) { treeDetailTHIS.Littoral = treeDetailBASE.Littoral; } if (chkMaritimoTerrestre.Checked) { treeDetailTHIS.MaritimeZone = treeDetailBASE.MaritimeZone; } if (chkComentarios.Checked) { treeDetailTHIS.Commentary = treeDetailBASE.Commentary; } } successMessage = "Las siguientes cararcterísticas del árbol <b>#" + txtCloneBase.Text + "</b> han sido copiadas satisfactóriamente a los árboles desde el árbol <b>#" + from + "</b> al árbol <b>#" + to + "</b>: <br />"; } if (chkCloneNombre.Checked) { successMessage += "<b> • Nombre Común - Nombre Científico</b><br />"; } if (chkCloneVaras.Checked) { successMessage += "<b> • Varas</b><br />"; } if (chkCloneDap.Checked) { successMessage += "<b> • D.A.P</b><br />"; } if (chkAltura.Checked) { successMessage += "<b> • Altura (pies)</b><br />"; } if (chkAcciónPropuesta.Checked) { successMessage += "<b> • Acción Propuesta</b><br />"; } if (chkCondicion.Checked) { successMessage += "<b> • Condición</b><br />"; } if (chkLitoral.Checked) { successMessage += "<b> • Árbol en la Servidumbre de Vigilancia de Litoral</b><br />"; } if (chkMaritimoTerrestre.Checked) { successMessage += "<b> • Árbol en la Zona Marítimo Terrestre</b><br />"; } if (chkComentarios.Checked) { successMessage += "<b> • Comentarios</b>"; } _DatabaseContext.SaveChanges(); pnlCloneRange.Style["display"] = (rbtCloneRange.Checked) ? "block" : "none"; gridViewTreeDetails.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); gridViewTreeDetails.DataBind(); ltlMessage.Text += MessageFormatter.GetFormattedSuccessMessage(successMessage); btnClear_Click(null, null); pnlClone.Style["display"] = "none"; pnlLoading.Style["display"] = "none"; } } }
public object Update([FromBody] ProjectOrganismUpdateModel projectOrganismUpdate) { //var projectOrganism = (Project_Organisms)HttpContext.Current.Items["projectOrganism"]; //var organism = (Organism)HttpContext.Current.Items["organism"]; var project = (Project)HttpContext.Current.Items["project"]; var groups = (List <Group>)HttpContext.Current.Items["groups"]; var user = (User)HttpContext.Current.Items["user"]; //var actionProposed = (ActionProposed)HttpContext.Current.Items["actionProposed"]; //var condition = (Condition)HttpContext.Current.Items["condition"]; var daps = (int[])HttpContext.Current.Items["daps"]; var varas = (int)HttpContext.Current.Items["varas"]; using (DatabaseContext _DatabaseContext = new DatabaseContext()) { // TreeDetail Project_Organisms projectOrganism = _DatabaseContext.Project_Organisms.First(instance => instance.ProjectOrganismID == projectOrganismUpdate.ProjectOrganismID); TreeDetail treeDetail = _DatabaseContext.TreeDetails.First(instance => instance.ProjectOrganismID == projectOrganism.ProjectOrganismID); //Delete existing Daps foreach (Dap item in _DatabaseContext.Daps.Where(instance => instance.TreeDetailsID == treeDetail.TreeDetailsID).ToList()) { _DatabaseContext.Daps.DeleteObject(item); } if (varas != 0) // Is Cepa { treeDetail.Dap = 0; treeDetail.Dap_Counter = 0; } else if (daps.Length == 1) // Solo un Dap { treeDetail.Dap = Convert.ToDecimal(daps[0]); treeDetail.Dap_Counter = 1; Dap dapObj = new Dap(); dapObj.DapValue = Convert.ToDecimal(daps[0]); dapObj.TreeDetailsID = treeDetail.TreeDetailsID; dapObj.TreeDetailReference.EntityKey = treeDetail.EntityKey; _DatabaseContext.Daps.AddObject(dapObj); } else // 1 o Mas de un Dap { double dapTotal = 0; foreach (int dap in daps) { dapTotal += Convert.ToDouble(dap); } //dapTotal;// new DapBLL().GetDap(0); treeDetail.Dap = Convert.ToDecimal(Math.Round(Math.Sqrt(Math.Pow(dapTotal, 2D) / Convert.ToDouble(daps.Count())) * 100) / 100); treeDetail.Dap_Counter = Convert.ToInt32(daps.Length); //new DapBLL().GetDapCount(0); foreach (int dapInt in daps) { Dap dap = new Dap(); dap.DapValue = Convert.ToDecimal(dapInt); dap.TreeDetailsID = treeDetail.TreeDetailsID; dap.TreeDetailReference.EntityKey = treeDetail.EntityKey; _DatabaseContext.Daps.AddObject(dap); } } //treeDetail.Dap = new DapBLL().GetDap(treeDetail.TreeDetailsID); //Convert.ToDecimal(hfDap.Value); //treeDetail.Dap_Counter = new DapBLL().GetDapCount(treeDetail.TreeDetailsID); //Convert.ToInt32(hfDapCounter.Value); treeDetail.Varas = projectOrganismUpdate.Varas; treeDetail.Height = Convert.ToDecimal(projectOrganismUpdate.Height); int CommentaryMaxLength = Convert.ToInt32(ConfigurationManager.AppSettings["CommentaryMaxLength"]); if (!string.IsNullOrEmpty(projectOrganismUpdate.Commentary)) { treeDetail.Commentary = (projectOrganismUpdate.Commentary.Length > CommentaryMaxLength) ? projectOrganismUpdate.Commentary.Substring(0, CommentaryMaxLength) : projectOrganismUpdate.Commentary; } else { treeDetail.Commentary = ""; } treeDetail.Number = Convert.ToInt32(treeDetail.Number); treeDetail.Lat = Convert.ToDecimal(projectOrganismUpdate.Lat); treeDetail.Lon = Convert.ToDecimal(projectOrganismUpdate.Lon); Dictionary <string, object> anewpointObj = Utility.ConvertToStatePlane(projectOrganismUpdate.Lon.ToString(), projectOrganismUpdate.Lat.ToString(), @"~/Javascript/"); treeDetail.X = Convert.ToDecimal(anewpointObj["x"]); treeDetail.Y = Convert.ToDecimal(anewpointObj["y"]); // treeDetail.EditedDate = DateTime.Now; treeDetail.EditorUserID = user.UserID; //projectOrganism Organism organism = new OrganismBLL().GetOrganismByOrganismID(Convert.ToInt32(projectOrganismUpdate.OrganismID)); projectOrganism.OrganismID = organism.OrganismID; projectOrganism.OrganismReference.EntityKey = organism.EntityKey; //ActionProposed ActionProposed actionProposed = new ActionProposedBLL().GetActionProposedByActionProposedID(Convert.ToInt32(projectOrganismUpdate.ActionProposedID)); treeDetail.ActionProposedID = actionProposed.ActionProposedID; treeDetail.ActionProposedReference.EntityKey = actionProposed.EntityKey; //Condition Condition condition = new ConditionBLL().GetConditionByConditionID(Convert.ToInt32(projectOrganismUpdate.ConditionID)); treeDetail.ConditionID = condition.ConditionID; treeDetail.ConditionReference.EntityKey = condition.EntityKey; treeDetail.ProjectOrganismID = (int)projectOrganismUpdate.ProjectOrganismID; treeDetail.Project_OrganismsReference.EntityKey = projectOrganism.EntityKey; _DatabaseContext.SaveChanges(); // } var updatedProjectOrganism = new Project_OrganismsBLL().GetProject_OrganismsByProjectOrganismID((int)projectOrganismUpdate.ProjectOrganismID); return(ProjectOrganismModel.GetProjectOrganismObject(updatedProjectOrganism)); }