protected void FormViewProject_ItemUpdating(object sender, FormViewUpdateEventArgs e) { TextBox txtProject = (TextBox)formViewProject.FindControl("txtProject"); ProjectActionStatus status = Validate(txtProject.Text, actionType.update); if (status == ProjectActionStatus.Success) { Type myType = (typeof(Project)); PropertyInfo[] props = myType.GetProperties(); string[] arrNewValues = new string[e.NewValues.Keys.Count]; e.NewValues.Keys.CopyTo(arrNewValues, 0); ProjectBLL scientificNameBLL = new ProjectBLL(); Project scientificName = scientificNameBLL.GetProjectByProjectId2((int)e.Keys["ProjectId"]); 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(scientificName, null); } } } } else { ltlMessage.Text = MessageFormatter.GetFormattedErrorMessage(GetErrorMessage(status)); e.Cancel = true; } }
public string GetErrorMessage(ProjectActionStatus status) { switch (status) { case ProjectActionStatus.Duplicate: return("Project Name address already exists. Please enter a different one."); default: return("Error"); } }
protected void FormViewProject_ItemInserting(object sender, FormViewInsertEventArgs e) { TextBox txtProject = (TextBox)formViewProject.FindControl("txtProject"); ProjectActionStatus status = Validate(txtProject.Text, actionType.insert); if (status == ProjectActionStatus.Success) { e.Values["CreatedDate"] = DateTime.Now; e.Values["EditedDate"] = DateTime.Now; } else { ltlMessage.Text = MessageFormatter.GetFormattedErrorMessage(GetErrorMessage(status)); e.Cancel = true; } }
protected void FormViewTlProject_ItemInserting(object sender, FormViewInsertEventArgs e) { UserBLL userBLL = new UserBLL(); TextBox txtProject = (TextBox)formViewTlProject.FindControl("txtProject"); ProjectActionStatus status = Validate(txtProject.Text, actionType.insert); if (status == ProjectActionStatus.Success) { User creator = userBLL.GetUserByUserName((HttpContext.Current.User.Identity).Name); e.Values["CreatedDate"] = DateTime.Now; e.Values["CreatorUserID"] = creator.UserID; e.Values["EditedDate"] = DateTime.Now; e.Values["EditorUserId"] = creator.UserID; } else { ltlMessage.Text = MessageFormatter.GetFormattedErrorMessage(GetErrorMessage(status)); e.Cancel = true; } }
protected void FormViewProject_ItemUpdating(object sender, FormViewUpdateEventArgs e) { TextBox txtProjectName = (TextBox)formViewProject.FindControl("txtProjectName"); ProjectActionStatus status = Validate(txtProjectName.Text, actionType.update); if (status == ProjectActionStatus.Success) { Project project = new ProjectBLL().GetProjectByProjectId2((int)e.Keys["ProjectId"]); using (DatabaseContext _DatabaseContext = new DatabaseContext()) { TextBox txtClient = (TextBox)formViewProject.FindControl("txtClient"); TextBox txtAddress1 = (TextBox)formViewProject.FindControl("txtAddress1"); TextBox txtAddress2 = (TextBox)formViewProject.FindControl("txtAddress2"); DropDownList ddlCity = (DropDownList)formViewProject.FindControl("ddlCity"); TextBox txtState = (TextBox)formViewProject.FindControl("txtState"); TextBox txtZipCode = (TextBox)formViewProject.FindControl("txtZipCode"); TextBox txtDescription = (TextBox)formViewProject.FindControl("txtDescription"); TextBox txtComments = (TextBox)formViewProject.FindControl("txtComments"); ProjectInfo projectInfo = _DatabaseContext.ProjectInfoes.First(instance => instance.ProjectID == project.ProjectID); projectInfo.ProjectName = txtProjectName.Text; projectInfo.Client = txtClient.Text; projectInfo.Address1 = txtAddress1.Text; projectInfo.Address2 = txtAddress2.Text; projectInfo.CityID = Convert.ToInt32(ddlCity.SelectedValue); projectInfo.State = txtState.Text; projectInfo.ZipCode = txtZipCode.Text.Replace("-", ""); projectInfo.Description = txtDescription.Text.Substring(0, Math.Min(txtDescription.Text.Length, 5000)); projectInfo.Comments = txtComments.Text.Substring(0, Math.Min(txtComments.Text.Length, 5000)); _DatabaseContext.SaveChanges(); } Type myType = (typeof(Project)); 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").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(project, 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; } }