protected void FormViewCommonName_ItemInserting(object sender, FormViewInsertEventArgs e) { TextBox txtCommonName = (TextBox)formViewCommonName.FindControl("txtCommonName"); TextBox txtScientificName = (TextBox)formViewCommonName.FindControl("txtScientificName"); CommonNameActionStatus status = Validate(txtCommonName.Text, txtScientificName.Text, actionType.insert); if (status == CommonNameActionStatus.Success) { User user = new UserBLL().GetUserByUserName((HttpContext.Current.User.Identity).Name); int groupID = new Group_UsersBLL().GetGroup_UsersByUserID(user.UserID)[0].GroupID; CommonName commonName = new CommonNameBLL().GetOrCreateCommonName(txtCommonName.Text, user); ScientificName scientificName = new ScientificNameBLL().GetScientificNameByScientificNameID(Convert.ToInt32(Page.RouteData.Values["scientificname_id"] as string)); OrganismType organismType = new OrganismTypeBLL().GetOrganismTypeByOrganismTypeID(2); Group group = new GroupBLL().GetGroupByGroupID(groupID); e.Values["CommonNameID"] = commonName.CommonNameID; e.Values["ScientificNameID"] = scientificName.ScientificNameID; e.Values["OrganismTypeID"] = organismType.OrganismTypeID; e.Values["GroupID"] = group.GroupID; e.Values["CreatedDate"] = DateTime.Now; e.Values["CreatorUserID"] = user.UserID; e.Values["EditedDate"] = DateTime.Now; e.Values["EditorUserID"] = user.UserID; } else { ltlMessage.Text = MessageFormatter.GetFormattedErrorMessage(GetErrorMessage(status)); e.Cancel = true; } }
protected void formViewScientificName_DataBinding(object sender, EventArgs e) { string scientificNameID = Page.RouteData.Values["ScientificName_id"] as string; if (scientificNameID != null && scientificNameID != "0") { ScientificName scientificName = new ScientificNameBLL().GetScientificNameByScientificNameID(Convert.ToInt32(scientificNameID)); this.editor = new Eisk.BusinessLogicLayer.UserBLL().GetUserByUserID(scientificName.EditorUserID); this.creator = new Eisk.BusinessLogicLayer.UserBLL().GetUserByUserID(scientificName.CreatorUserID); this.scientificName = scientificName; } }
private static ScientificNameActionStatus Validate(string scientificName, actionType act) { ScientificNameBLL scientificNameBLL = new ScientificNameBLL(); List <ScientificName> scientificNames = scientificNameBLL.GetScientificNameByFilter(scientificName.Trim()); if (scientificNames.Count > 0 && act == actionType.insert) { return(ScientificNameActionStatus.Duplicate); } else if (scientificNames.Count > 0 && scientificNames[0].ScientificNameDesc == scientificName && act == actionType.update) { return(ScientificNameActionStatus.Duplicate); } else { return(ScientificNameActionStatus.Success); } }
protected void ButtonDeleteSelected_Click(object sender, System.EventArgs e) { try { // Create a List to hold the ScientificNameID values to delete List <Int32> ScientificNameIDsToDelete = new List <Int32>(); // Iterate through the ScientificNames.Rows property foreach (GridViewRow row in gridViewScientificNames.Rows) { // Access the CheckBox CheckBox cb = (CheckBox)(row.FindControl("chkScientificNameSelector")); if (cb != null && cb.Checked) { // Save the ScientificNameID value for deletion // First, get the ScientificNameID for the selected row Int32 ScientificNameID = (Int32)gridViewScientificNames.DataKeys[row.RowIndex].Value; ScientificNameBLL scientificNameBLL = new ScientificNameBLL(); Eisk.BusinessEntities.ScientificName scientificName = scientificNameBLL.GetScientificNameByScientificNameID(ScientificNameID); // Add it to the List... ScientificNameIDsToDelete.Add(ScientificNameID); // Add a confirmation message ltlMessage.Text += String.Format(MessageFormatter.GetFormattedSuccessMessage("Delete successful. Scientific Name <b>{0}</b> has been deleted"), scientificName.ScientificNameDesc); } } //perform the actual delete new ScientificNameBLL().DeleteScientificNames(ScientificNameIDsToDelete); } catch (Exception ex) { ltlMessage.Text = ExceptionManager.DoLogAndGetFriendlyMessageForException(ex); } //binding the grid gridViewScientificNames.PageIndex = 0; gridViewScientificNames.DataBind(); }
protected void FormViewScientificName_ItemUpdating(object sender, FormViewUpdateEventArgs e) { TextBox txtScientificName = (TextBox)formViewScientificName.FindControl("txtScientificName"); ScientificNameActionStatus status = Validate(txtScientificName.Text, actionType.update); if (status == ScientificNameActionStatus.Success) { Type myType = (typeof(ScientificName)); PropertyInfo[] props = myType.GetProperties(); string[] arrNewValues = new string[e.NewValues.Keys.Count]; e.NewValues.Keys.CopyTo(arrNewValues, 0); ScientificNameBLL scientificNameBLL = new ScientificNameBLL(); ScientificName scientificName = scientificNameBLL.GetScientificNameByScientificNameId2((int)e.Keys["ScientificNameId"]); foreach (var prop in props) { if (("System.String,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(scientificName, null); } } } User editor = new UserBLL().GetUserByUserName((HttpContext.Current.User.Identity).Name); e.NewValues["EditorUserId"] = editor.UserID.ToString(); e.NewValues["EditedDate"] = DateTime.Now; } else { ltlMessage.Text = MessageFormatter.GetFormattedErrorMessage(GetErrorMessage(status)); e.Cancel = true; } }
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; } }