Exemple #1
0
    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;
        }
    }