Beispiel #1
0
        private void BindGrid()
        {
            // DataTable structure
            DataTable dt = new DataTable();

            dt.Locale = CultureInfo.InvariantCulture;
            dt.Columns.Add(idColumn, typeof(string));
            dt.Columns.Add(principalColumn, typeof(string));
            foreach (SecurityRight right in Mediachase.Ibn.Data.Services.Security.GetMetaClassRights(mc.Name))
            {
                dt.Columns.Add(right.RightName, typeof(string));
            }
            dt.Columns.Add(editColumn, typeof(string));
            dt.Columns.Add(deleteColumn, typeof(string));

            // Fill data
            DataRow dr;

            foreach (MetaObject mo in Mediachase.Ibn.Data.Services.Security.GetGlobalAcl(mc.Name))
            {
                int principalId = (PrimaryKeyId)mo.Properties["PrincipalId"].Value;

                dr                  = dt.NewRow();
                dr[idColumn]        = mo.PrimaryKeyId;
                dr[principalColumn] = CHelper.GetUserName(principalId);

                for (int i = 1; i < MainGrid.Columns.Count - 2; i++)
                {
                    BoundField rightsField = MainGrid.Columns[i] as BoundField;
                    if (rightsField != null)
                    {
                        string fieldName = rightsField.DataField;
                        dr[fieldName] = CHelper.GetPermissionImage((int)mo.Properties[fieldName].Value);
                    }
                }

                string url = String.Format(CultureInfo.InvariantCulture,
                                           "javascript:ShowWizard(&quot;{5}?ClassName={0}&btn={1}&PrincipalId={2}&quot;, {3}, {4});",
                                           mc.Name, Page.ClientScript.GetPostBackEventReference(RefreshButton, ""),
                                           principalId, dialogWidth, dialogHeight,
                                           ResolveUrl("~/Apps/Security/Pages/Admin/GlobalRoleAclEdit.aspx"));
                dr[editColumn] = String.Format(CultureInfo.InvariantCulture,
                                               "<a href=\"{0}\"><img src=\"{1}\" title=\"{2}\" width=\"16\" height=\"16\" border=\"0\" /></a>", url, ResolveUrl("~/Images/IbnFramework/edit.gif"), GetGlobalResourceObject("IbnFramework.GlobalMetaInfo", "Edit").ToString());

                dt.Rows.Add(dr);
            }

            MainGrid.DataSource = dt;
            MainGrid.DataBind();

            foreach (GridViewRow row in MainGrid.Rows)
            {
                if (row.Cells[row.Cells.Count - 1].Controls.Count > 0)
                {
                    WebControl ctrl = (WebControl)row.Cells[row.Cells.Count - 1].Controls[0];
                    if (ctrl != null)
                    {
                        ctrl.Attributes.Add("onclick", "if (!confirm('" + GetGlobalResourceObject("IbnFramework.GlobalMetaInfo", "Delete").ToString() + "?')) return false;");
                    }
                }
            }
        }
        private void BindGrid()
        {
            if (sm == null)
            {
                sm = new Mediachase.Ibn.Data.Services.StateMachine(mc, int.Parse(ddlStateMachine.SelectedValue));
            }

            // DataTable structure
            DataTable dt = new DataTable();

            dt.Locale = CultureInfo.InvariantCulture;
            dt.Columns.Add(principalColumn, typeof(string));

            MetaObject moState   = StateMachineManager.GetState(mc, int.Parse(ddlState.SelectedValue));
            string     fromState = moState.Properties["Name"].Value.ToString();

            foreach (State state in sm.States)
            {
                StateTransition st = sm.FindTransition(fromState, state.Name);
                if (st != null)
                {
                    dt.Columns.Add(state.Name, typeof(string));
                }
            }
            dt.Columns.Add(editColumn, typeof(string));

            // Fill data
            DataRow dr;

            foreach (MetaObject mo in Mediachase.Ibn.Data.Services.Security.GetGlobalAcl(mc.Name))
            {
                int principalId = (PrimaryKeyId)mo.Properties["PrincipalId"].Value;

                dr = dt.NewRow();
                dr[principalColumn] = CHelper.GetUserName(principalId);

                MetaObject obj = StateMachineUtil.GetGlobalAclStateItem(mc.Name, mo.PrimaryKeyId.Value, int.Parse(ddlStateMachine.SelectedValue), int.Parse(ddlState.SelectedValue));

                for (int i = 1; i < grdMain.Columns.Count - 1; i++)
                {
                    BoundField rightsField = grdMain.Columns[i] as BoundField;
                    if (rightsField != null)
                    {
                        string fieldName = rightsField.DataField;
                        if (obj != null)
                        {
                            dr[fieldName] = CHelper.GetPermissionImage((int)obj.Properties[fieldName].Value);
                        }
                        else
                        {
                            dr[fieldName] = CHelper.GetPermissionImage((int)Mediachase.Ibn.Data.Services.Security.Rights.None);
                        }
                    }
                }

                string url = String.Format("javascript:ShowWizard(&quot;{7}?ClassName={0}&btn={1}&PrincipalId={2}&SmId={3}&StateId={4}&quot;, {5}, {6});",
                                           mc.Name, Page.ClientScript.GetPostBackEventReference(btnRefresh, ""),
                                           principalId, ddlStateMachine.SelectedValue, ddlState.SelectedValue,
                                           dialogWidth, dialogHeight,
                                           ResolveClientUrl("~/Apps/Security/Pages/Admin/GlobalRoleAclStateTransitionEdit.aspx"));
                dr[editColumn] = String.Format("<a href=\"{0}\"><img src=\"{1}\" title=\"{2}\" width=\"16\" height=\"16\" border=\"0\" /></a>", url, ResolveUrl("~/Images/IbnFramework/edit.gif"), GetGlobalResourceObject("IbnFramework.GlobalMetaInfo", "Edit").ToString());

                dt.Rows.Add(dr);
            }

            grdMain.DataSource = dt;
            grdMain.DataBind();
        }
        private void BindGrid()
        {
            // DataTable structure
            DataTable dt = new DataTable();

            dt.Locale = CultureInfo.InvariantCulture;
            dt.Columns.Add(idColumn, typeof(string));
            dt.Columns.Add(principalColumn, typeof(string));
            dt.Columns.Add(isInheritedColumn, typeof(bool));
            foreach (SecurityRight right in Mediachase.Ibn.Data.Services.Security.GetMetaClassRights(mc.Name))
            {
                dt.Columns.Add(right.RightName, typeof(string));
            }
            dt.Columns.Add(editColumn, typeof(string));
            dt.Columns.Add(resetColumn, typeof(string));

            // Fill data
            DataRow dr;

            foreach (MetaObject mo in Mediachase.Ibn.Data.Services.Security.GetGlobalAcl(mc.Name))
            {
                int principalId = (PrimaryKeyId)mo.Properties["PrincipalId"].Value;

                dr                  = dt.NewRow();
                dr[idColumn]        = mo.PrimaryKeyId.Value;
                dr[principalColumn] = CHelper.GetUserName(principalId);

                bool       isInhereted = false;
                MetaObject obj         = StateMachineUtil.GetGlobalAclStateItem(mc.Name, mo.PrimaryKeyId.Value, int.Parse(StateMachineList.SelectedValue), int.Parse(StateList.SelectedValue));
                if (obj == null)
                {
                    obj         = mo;
                    isInhereted = true;
                }

                dr[isInheritedColumn] = isInhereted;

                for (int i = 1; i < MainGrid.Columns.Count - 2; i++)
                {
                    BoundField rightsField = MainGrid.Columns[i] as BoundField;
                    if (rightsField != null)
                    {
                        string fieldName = rightsField.DataField;
                        dr[fieldName] = CHelper.GetPermissionImage((int)obj.Properties[fieldName].Value, isInhereted);
                    }
                }

                string url = String.Format(CultureInfo.InvariantCulture,
                                           "javascript:ShowWizard(&quot;{7}?ClassName={0}&btn={1}&PrincipalId={2}&SmId={3}&StateId={4}&quot;, {5}, {6});",
                                           mc.Name, Page.ClientScript.GetPostBackEventReference(RefreshButton, ""),
                                           principalId, StateMachineList.SelectedValue, StateList.SelectedValue,
                                           dialogWidth, dialogHeight,
                                           ResolveClientUrl("~/Apps/Security/Pages/Admin/GlobalRoleAclStateEdit.aspx"));
                dr[editColumn] = String.Format(CultureInfo.InvariantCulture,
                                               "<a href=\"{0}\"><img src=\"{1}\" title=\"{2}\" width=\"16\" height=\"16\" border=\"0\" /></a>", url, ResolveUrl("~/Images/IbnFramework/edit.gif"), GetGlobalResourceObject("IbnFramework.GlobalMetaInfo", "Edit").ToString());

                dt.Rows.Add(dr);
            }


            MainGrid.DataSource = dt;
            MainGrid.DataBind();
        }