Esempio n. 1
0
    private void LoadPropertiesTable()
    {
        if (ddlObjectName.SelectedValue != "")
        {
            //Add header
            TableRow  trHeader = new TableRow();
            TableCell tc1      = new TableCell();
            tc1.Text = "Property";
            trHeader.Cells.Add(tc1);

            TableCell tc2 = new TableCell();
            tc2.Text = "Audit this property";
            trHeader.Cells.Add(tc2);

            tblProperties.Rows.Add(trHeader);

            //Create an instance of the type.
            PropertyInfo[] properties = Type.GetType(ddlObjectName.SelectedValue).GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);

            //Populate the table with all the fields.
            foreach (PropertyInfo prop in properties)
            {
                //Only show properties the have a public set property.
                MethodInfo[] methodInfo = prop.GetAccessors();

                //Get the set method
                IEnumerable <MethodInfo> set =
                    from m in methodInfo
                    where m.Name.StartsWith("set")
                    select m;

                if (set.Count() > 0)
                {
                    if (set.Single <MethodInfo>().IsPublic)
                    {
                        ENTWFStatePropertyEO entWFStateProperty = new ENTWFStatePropertyEO();

                        TableRow tr = new TableRow();

                        //Name of property
                        TableCell tcName = new TableCell();
                        tcName.Text = prop.Name;
                        tr.Cells.Add(tcName);

                        //Checkbox
                        TableCell tcAudit  = new TableCell();
                        CheckBox  chkAudit = new CheckBox();
                        chkAudit.Enabled = !ReadOnly;
                        chkAudit.ID      = "chk" + prop.Name;
                        tcAudit.Controls.Add(chkAudit);
                        tr.Cells.Add(tcAudit);

                        tblProperties.Rows.Add(tr);
                    }
                }
            }
        }
        else
        {
            tblProperties.Rows.Clear();
        }
    }
    private void LoadPropertiesTable(int entWorkflowId, ENTWFStateEO entWFStateEO)
    {
        if (entWorkflowId != 0)
        {
            var workflow = new ENTWorkflowEO();
            if (workflow.Load(entWorkflowId))
            {
                tblProperties.Rows.Clear();

                //Add header
                var trHeader = new TableRow();
                var tc1      = new TableCell();
                tc1.Text = "Property";
                trHeader.Cells.Add(tc1);

                var tc2 = new TableCell();
                tc2.Text = "Read Only";
                trHeader.Cells.Add(tc2);

                var tc3 = new TableCell();
                tc3.Text = "Required";
                trHeader.Cells.Add(tc3);

                tblProperties.Rows.Add(trHeader);

                //Create an instance of the type.
                var type = Type.GetType(workflow.ENTWorkflowObjectName);
                if (type != null)
                {
                    var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);

                    //Populate the table with all the fields.
                    foreach (var prop in properties)
                    {
                        //Only show properties the have a public set property.
                        var methodInfo = prop.GetAccessors();

                        //Get the set method
                        var set =
                            from m in methodInfo
                            where m.Name.StartsWith("set")
                            select m;

                        if (set.Any())
                        {
                            if (set.Single().IsPublic)
                            {
                                var entWFStateProperty = new ENTWFStatePropertyEO();

                                if (entWFStateEO.ENTWorkflowId == Convert.ToInt32(ddlWorkflow.SelectedValue))
                                {
                                    //Try to find this property in the ENTWFStateObject
                                    entWFStateProperty = entWFStateEO.ENTWFStateProperties.GetByPropertyName(prop.Name);

                                    if (entWFStateProperty == null)
                                    {
                                        entWFStateProperty = new ENTWFStatePropertyEO();
                                    }
                                }

                                var tr = new TableRow();

                                //Name of property
                                var tcName = new TableCell();
                                tcName.Text = prop.Name;
                                tr.Cells.Add(tcName);

                                //Read Only checkbox
                                var tcReadOnly  = new TableCell();
                                var chkReadOnly = new CheckBox();
                                chkReadOnly.Enabled = !ReadOnly;
                                chkReadOnly.Checked = entWFStateProperty.ReadOnly;
                                tcReadOnly.Controls.Add(chkReadOnly);
                                tr.Cells.Add(tcReadOnly);

                                //Required checkbox
                                var tcRequired  = new TableCell();
                                var chkRequired = new CheckBox();
                                chkRequired.Enabled = !ReadOnly;
                                chkRequired.Checked = entWFStateProperty.Required;
                                tcRequired.Controls.Add(chkRequired);
                                tr.Cells.Add(tcRequired);
                                tblProperties.Rows.Add(tr);
                            }
                        }
                    }
                }
            }
            else
            {
                throw new Exception("The workflow can not be found in the database.");
            }
        }
    }