protected void FormViewOrganismType_ItemUpdating(object sender, FormViewUpdateEventArgs e) { TextBox txtOrganismType = (TextBox)formViewOrganismType.FindControl("txtOrganismType"); OrganismTypeActionStatus status = Validate(txtOrganismType.Text, actionType.update); if (status == OrganismTypeActionStatus.Success) { Type myType = (typeof(OrganismType)); PropertyInfo[] props = myType.GetProperties(); string[] arrNewValues = new string[e.NewValues.Keys.Count]; e.NewValues.Keys.CopyTo(arrNewValues, 0); OrganismTypeBLL organismTypeBLL = new OrganismTypeBLL(); OrganismType organismType = organismTypeBLL.GetOrganismTyeByOrganismTypeId2((int)e.Keys["OrganismTypeId"]); 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(organismType, null); } } } } else { ltlMessage.Text = MessageFormatter.GetFormattedErrorMessage(GetErrorMessage(status)); e.Cancel = true; } }
public string GetErrorMessage(OrganismTypeActionStatus status) { switch (status) { case OrganismTypeActionStatus.Duplicate: return("Scientific Name address already exists. Please enter a different one."); default: return("Error"); } }
protected void FormViewOrganismType_ItemInserting(object sender, FormViewInsertEventArgs e) { TextBox txtOrganismType = (TextBox)formViewOrganismType.FindControl("txtOrganismType"); OrganismTypeActionStatus status = Validate(txtOrganismType.Text, actionType.insert); if (status == OrganismTypeActionStatus.Success) { e.Values["CreatedDate"] = DateTime.Now; e.Values["EditedDate"] = DateTime.Now; } else { ltlMessage.Text = MessageFormatter.GetFormattedErrorMessage(GetErrorMessage(status)); e.Cancel = true; } }