private static OrganismActionStatus Validate(string commonName, string scientificName, int organismTypeID, actionType act) { OrganismBLL organismBLL = new OrganismBLL(); Organism organismCommonName = organismBLL.GetOrganismByScientificName(scientificName.Trim()); if (organismCommonName != null) { if (organismCommonName.ScientificName.Trim() == scientificName.Trim() && act == actionType.insert) { return(OrganismActionStatus.DuplicateScientificName); } else if (organismCommonName.CommonName.Trim() == commonName.Trim() && organismCommonName.ScientificName.Trim() == scientificName.Trim() && organismCommonName.OrganismTypeID == organismTypeID) { return(OrganismActionStatus.DuplicateCommonName); } else { return(OrganismActionStatus.Success); } } else { return(OrganismActionStatus.Success); } }
protected void gridViewOrganisms_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName != "Page") { ProjectBLL projectBLL = new ProjectBLL(); Project project = projectBLL.GetProjectByProjectID(Convert.ToInt32(Page.RouteData.Values["project_id"])); OrganismBLL organismBLL = new OrganismBLL(); Organism organism = organismBLL.GetOrganismByOrganismID(Convert.ToInt32(e.CommandArgument)); Project_OrganismsBLL project_OrganismsBLL = new Project_OrganismsBLL(); Project_Organisms project_Organism = new Project_Organisms(); project_Organism.ProjectID = project.ProjectID; project_Organism.ProjectReference.EntityKey = project.EntityKey; project_Organism.OrganismID = organism.OrganismID; project_Organism.OrganismReference.EntityKey = organism.EntityKey; project_Organism.CreatedDate = DateTime.Now; project_Organism.EditedDate = DateTime.Now; project_OrganismsBLL.CreateNewProject_Organisms(project_Organism); Response.RedirectToRoute("organismsinproject", new { project_id = (Page.RouteData.Values["project_id"] as string) }); } }
protected void SetScientificName() { HiddenField hfOrganism = (HiddenField)formViewTlProject_Organism.FindControl("hfOrganism"); if (!string.IsNullOrEmpty(hfOrganism.Value)) { TextBox txtScientificName = (TextBox)formViewTlProject_Organism.FindControl("txtScientificName"); Organism organism = new OrganismBLL().GetOrganismByOrganismID(Convert.ToInt32(hfOrganism.Value)); txtScientificName.Text = organism.ScientificName.ScientificNameDesc; } }
public string[] GetOrganismByFilter(string prefixText, int count) { Eisk.BusinessEntities.User user = new UserBLL().GetUserByUserName((HttpContext.Current.User.Identity).Name); List <Eisk.BusinessEntities.Group> groups = user.Group_Users.Select(instance => instance.Group).ToList(); List <Eisk.BusinessEntities.Organism> organisms = new OrganismBLL().GetOrganismByFilter2(prefixText, default(string), 0, count, 0, groups[0].GroupID).ToList(); List <string> items = new List <string>(); for (int i = 0; i < organisms.Count; i++) { items.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(organisms[i].CommonName.CommonNameDesc.ToString() + " - " + organisms[i].ScientificName.ScientificNameDesc.ToString(), organisms[i].OrganismID.ToString())); } return(items.ToArray()); }
protected void FormViewOrganism_ItemUpdating(object sender, FormViewUpdateEventArgs e) { TextBox txtCommonName = (TextBox)formViewOrganism.FindControl("txtCommonName"); TextBox txtScientificName = (TextBox)formViewOrganism.FindControl("txtScientificName"); DropDownList ddlOrganismType = (DropDownList)formViewOrganism.FindControl("ddlOrganismType"); OrganismActionStatus status = Validate(txtCommonName.Text, txtScientificName.Text, Convert.ToInt32(ddlOrganismType.SelectedValue), actionType.update); if (status == OrganismActionStatus.Success) { Type myType = (typeof(Organism)); PropertyInfo[] props = myType.GetProperties(); string[] arrNewValues = new string[e.NewValues.Keys.Count]; e.NewValues.Keys.CopyTo(arrNewValues, 0); OrganismBLL organismBLL = new OrganismBLL(); OrganismTypeBLL organismTypeBLL = new OrganismTypeBLL(); OrganismType organismType = organismTypeBLL.GetOrganismTypeByOrganismTypeID(Convert.ToInt32(ddlOrganismType.SelectedValue)); Organism organism = organismBLL.GetOrganismByOrganismId2((int)e.Keys["OrganismId"]); foreach (var prop in props) { if (("System.String,System.Int32,System.Int,System.DateTime,System.Guid").IndexOf((prop.PropertyType).FullName) >= 0) // Si la propiedad es de tipo Guid, String, Int o DateTime { if (!arrNewValues.Contains(prop.Name)) { e.NewValues[prop.Name] = prop.GetValue(organism, null); } } } e.NewValues["OrganismTypeID"] = organismType.OrganismTypeID; Page.RouteData.Values["organismtype_id"] = organismType.OrganismTypeID.ToString(); } else { ltlMessage.Text = MessageFormatter.GetFormattedErrorMessage(GetErrorMessage(status)); e.Cancel = true; } }
protected void ButtonDeleteSelected_Click(object sender, System.EventArgs e) { try { // Create a List to hold the OrganismID values to delete List <Int32> OrganismIDsToDelete = new List <Int32>(); // Iterate through the Organisms.Rows property foreach (GridViewRow row in gridViewCommonNames.Rows) { // Access the CheckBox CheckBox cb = (CheckBox)(row.FindControl("chkCommonNameSelector")); if (cb != null && cb.Checked) { // Save the OrganismID value for deletion // First, get the OrganismID for the selected row Int32 OrganismID = (Int32)gridViewCommonNames.DataKeys[row.RowIndex].Value; OrganismBLL commonNameBLL = new OrganismBLL(); Eisk.BusinessEntities.Organism organism = commonNameBLL.GetOrganismByOrganismID(OrganismID); // Add it to the List... OrganismIDsToDelete.Add(OrganismID); // Add a confirmation message ltlMessage.Text += String.Format(MessageFormatter.GetFormattedSuccessMessage("Delete successful. Organism <b>{0}</b> has been deleted"), organism.CommonName.CommonNameDesc); } } //perform the actual delete new OrganismBLL().DeleteOrganisms(OrganismIDsToDelete); } catch (Exception ex) { ltlMessage.Text = ExceptionManager.DoLogAndGetFriendlyMessageForException(ex); } //binding the grid gridViewCommonNames.PageIndex = 0; gridViewCommonNames.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Page.RouteData.Values["organism_id"] as string)) { if (Page.RouteData.Values["organism_id"] as string != "0") { Organism organism = new OrganismBLL().GetOrganismByOrganismID(Convert.ToInt32(Page.RouteData.Values["organism_id"] as string)); lblScientificName.Text = organism.ScientificName.ScientificNameDesc; lblCommonName.Text = organism.CommonName.CommonNameDesc; } else { if (!string.IsNullOrWhiteSpace(Page.RouteData.Values["commonname"] as string) && Page.RouteData.Values["commonname"] as string != "new") { lblCommonName.Text = Page.RouteData.Values["commonname"] as string; } else { pnlCommonName.Visible = false; } pnlScientificName.Visible = false; } } }
private static CommonNameActionStatus Validate(string commonName, string scientificName, actionType act) { User user = new UserBLL().GetUserByUserName((HttpContext.Current.User.Identity).Name); int groupID = new Group_UsersBLL().GetGroup_UsersByUserID(user.UserID)[0].GroupID; Organism organism = new OrganismBLL().GetOrganismByScientificNameCommonName(scientificName.Trim(), commonName.Trim()); if (organism != null && organism.GroupID == groupID) { if (act == actionType.insert) { return(CommonNameActionStatus.Duplicate); } else { return(CommonNameActionStatus.Success); } } else { return(CommonNameActionStatus.Success); } }
protected void FormViewCommonName_ItemUpdating(object sender, FormViewUpdateEventArgs e) { TextBox txtCommonName = (TextBox)formViewCommonName.FindControl("txtCommonName"); TextBox txtScientificName = (TextBox)formViewCommonName.FindControl("txtScientificName"); CommonNameActionStatus status = Validate(txtCommonName.Text, txtScientificName.Text, actionType.update); if (status == CommonNameActionStatus.Success) { Type myType = (typeof(Organism)); PropertyInfo[] props = myType.GetProperties(); string[] arrNewValues = new string[e.NewValues.Keys.Count]; e.NewValues.Keys.CopyTo(arrNewValues, 0); Organism organism = new OrganismBLL().GetOrganismByOrganismID((int)e.Keys["OrganismId"]); User editor = new UserBLL().GetUserByUserName((HttpContext.Current.User.Identity).Name); CommonName commonName = new CommonNameBLL().GetOrCreateCommonName(txtCommonName.Text, editor); ScientificName scientificName = new ScientificNameBLL().GetScientificNameByScientificName(txtScientificName.Text); using (DatabaseContext _DatabaseContext = new DatabaseContext()) { if (commonName.CommonNameID == organism.CommonNameID) { CommonName dbContCommonName = _DatabaseContext.CommonNames.First(instance => instance.CommonNameID == organism.CommonNameID); dbContCommonName.CommonNameDesc = txtCommonName.Text; dbContCommonName.EditorUserID = editor.UserID; dbContCommonName.EditedDate = DateTime.Now; } else { Organism dbContOrganism = _DatabaseContext.Organisms.First(instance => instance.OrganismID == organism.OrganismID); dbContOrganism.CommonNameID = commonName.CommonNameID; dbContOrganism.CommonNameReference.EntityKey = commonName.EntityKey; } if (scientificName.ScientificNameID != organism.ScientificNameID) { Organism dbContOrganism = _DatabaseContext.Organisms.First(instance => instance.OrganismID == organism.OrganismID); dbContOrganism.ScientificNameID = scientificName.ScientificNameID; dbContOrganism.ScientificNameReference.EntityKey = scientificName.EntityKey; } _DatabaseContext.SaveChanges(); } foreach (var prop in props) { if (("System.String,System.Int32,System.Int,System.DateTime,System.Guid").IndexOf((prop.PropertyType).FullName) >= 0) // Si la propiedad es de tipo Guid, String, Int o DateTime { if (!arrNewValues.Contains(prop.Name)) { e.NewValues[prop.Name] = prop.GetValue(organism, null); } } } e.NewValues["ScientificNameID"] = scientificName.ScientificNameID.ToString(); e.NewValues["CommonNameID"] = commonName.CommonNameID.ToString(); e.NewValues["EditorUserID"] = editor.UserID.ToString(); e.NewValues["EditedDate"] = DateTime.Now; } else { ltlMessage.Text = MessageFormatter.GetFormattedErrorMessage(GetErrorMessage(status)); e.Cancel = true; } }
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)); }
protected void btnExportData_Click(object sender, EventArgs e) { string projectID = (Page.RouteData.Values["project_id"] as string); List <ExportData> ExportDataList = new OrganismBLL().GetExportData("", Convert.ToInt32(projectID)); List <OrganismType> OrganismTypes = new OrganismTypeBLL().GetAllOrganismTypesList(); Project project = new ProjectBLL().GetProjectByProjectID(Convert.ToInt32(projectID)); string name = Translate(project.ProjectName); name = Translate(name); string path = System.Web.HttpContext.Current.Server.MapPath(@System.Configuration.ConfigurationManager.AppSettings["ProjectsRoot"]) + projectID.ToString(); // check folder exists if (!Directory.Exists(path)) { Directory.CreateDirectory(path); System.IO.File.WriteAllText(path + "/" + name + ".xlsx", ""); } FileInfo newFile = new FileInfo(path + @"\" + name + ".xlsx"); File.Delete(path + @"\" + name + ".xlsx"); using (ExcelPackage pck = new ExcelPackage(newFile)) { foreach (OrganismType OrganismType in OrganismTypes) { List <ExportData> OrganismTypeList = ExportDataList.Where(instance => instance.OrganismTypeID == OrganismType.OrganismTypeID).ToList(); if (OrganismTypeList.Count > 0) { //Add the Content sheet var ws = pck.Workbook.Worksheets.Add(OrganismType.OrganismTypeName); ws.Cells["A1"].Value = OrganismType.OrganismTypeName; ws.Cells["A1"].Style.Font.Bold = true; ws.Cells["A1"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; ws.Cells["A1:B1"].Merge = true; ws.Cells["A1:B1"].Style.Border.BorderAround(ExcelBorderStyle.Medium); //Headers ws.Cells["A2"].Value = "Common Name"; ws.Cells["A2"].Style.Border.BorderAround(ExcelBorderStyle.Medium); ws.Cells["B2"].Value = "Scientific Name"; ws.Cells["B2"].Style.Border.BorderAround(ExcelBorderStyle.Medium); ws.Cells["A2:B2"].Style.Font.Bold = true; ws.Column(1).Width = 35.00d; ws.Column(2).Width = 35.00d; int row = 3; foreach (ExportData Organism in OrganismTypeList) { ws.Cells["A" + row].Value = Organism.CommonName; ws.Cells["A" + row].Style.Border.BorderAround(ExcelBorderStyle.Thin); ws.Cells["A" + row].Style.Border.Right.Style = ExcelBorderStyle.Medium; ws.Cells["B" + row].Value = Organism.ScientificName; ws.Cells["B" + row].Style.Border.BorderAround(ExcelBorderStyle.Thin); row++; } ws.Cells["A3:B" + (row - 1)].Style.Border.BorderAround(ExcelBorderStyle.Medium); } } pck.Save(); pck.Dispose(); } System.Web.HttpResponse response = System.Web.HttpContext.Current.Response; response.ClearContent(); response.Clear(); response.ContentType = "application/vnd.ms-excel"; response.AddHeader("Content-Disposition", "attachment; filename=" + name + ".xlsx"); response.TransmitFile(path + @"/" + name + ".xlsx"); response.End(); }