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();
        }
Пример #2
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;");
                    }
                }
            }
        }
Пример #3
0
        private void BindGrid()
        {
            if (!this.Visible)
            {
                return;
            }

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

            dt.Locale = CultureInfo.InvariantCulture;
            dt.Columns.Add(idColumn, typeof(string));
            dt.Columns.Add(roleColumn, typeof(string));
            dt.Columns.Add(classColumn, typeof(string));

            CustomTableRow[] classRights = CustomTableRow.List(SqlContext.Current.Database.Tables[Mediachase.Ibn.Data.Services.Security.BaseRightsTableName],
                                                               FilterElement.EqualElement("ClassOnly", 1));

            foreach (SecurityRight right in Mediachase.Ibn.Data.Services.Security.GetMetaClassRights(mc.Name))
            {
                // Check for Class Right (ex. Create)
                bool   isClassRight = false;
                string rightUid     = right.BaseRightUid.ToString();
                foreach (CustomTableRow r in classRights)
                {
                    if (r["BaseRightUid"].ToString() == rightUid)
                    {
                        isClassRight = true;
                        break;
                    }
                }
                if (isClassRight)
                {
                    continue;
                }

                dt.Columns.Add(right.RightName, typeof(string));
            }
            dt.Columns.Add(editColumn, typeof(string));

            // Fill data
            DataRow dr;

            foreach (MetaObject mo in Mediachase.Ibn.Data.Services.RoleManager.GetObjectRoleItems(mc.Name))
            {
                string roleName = mo.Properties["RoleName"].Value.ToString();

                dr             = dt.NewRow();
                dr[idColumn]   = mo.PrimaryKeyId;
                dr[roleColumn] = CHelper.GetResFileString(mo.Properties["FriendlyName"].Value.ToString());
                if (mo.Properties["ClassName"].Value != null)
                {
                    string className = (string)mo.Properties["ClassName"].Value;
                    if (className.Contains("::"))
                    {
                        string[] s = new string[] { "::" };
                        className = className.Split(s, StringSplitOptions.None)[0];
                    }
                    dr[classColumn] = className;
                    dr[roleColumn] += String.Format(CultureInfo.InvariantCulture,
                                                    " ({0})",
                                                    CHelper.GetResFileString(MetaDataWrapper.GetMetaClassByName(className).PluralName));
                }

                for (int i = 1; i < MainGrid.Columns.Count - 1; 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}&Role={2}&quot;, {3}, {4});",
                                           mc.Name,
                                           Page.ClientScript.GetPostBackEventReference(RefreshButton, ""),
                                           roleName,
                                           dialogWidth, dialogHeight,
                                           ResolveUrl("~/Apps/Security/Pages/Admin/ObjectRoleEdit.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();
        }
Пример #4
0
        private void BindGrid()
        {
            if (sm == null)
            {
                sm = StateMachineManager.GetStateMachine(mc, int.Parse(ddlStateMachine.SelectedValue));
            }

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

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

            foreach (State state in sm.States)
            {
                dt.Columns.Add(state.Name, typeof(string));
            }
            dt.Columns.Add(editColumn, typeof(string));
            dt.Columns.Add(deleteColumn, typeof(string));

            // Fill data
            DataRow dr;

            foreach (State fromState in sm.States)
            {
                MetaObject mo = StateMachineManager.GetState(mc, fromState.Name);

                dr = dt.NewRow();

                dr[idColumn]        = fromState.Name;
                dr[fromStateColumn] = CHelper.GetResFileString(mo.Properties["FriendlyName"].Value.ToString());

                foreach (State toState in sm.States)
                {
                    if (fromState.Name == toState.Name)
                    {
                        continue;
                    }

                    StateTransition st = sm.FindTransition(fromState, toState);
                    if (st != null)
                    {
                        dr[toState.Name] = String.Format(CultureInfo.InvariantCulture,
                                                         "{0} {1}",
                                                         CHelper.GetPermissionImage((int)Security.Rights.Allow),
                                                         CHelper.GetResFileString(st.Name));
                    }
                    else
                    {
                        dr[toState.Name] = CHelper.GetPermissionImage((int)Security.Rights.Forbid);
                    }
                }

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

                dt.Rows.Add(dr);
            }

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

            for (int i = 0; i < grdMain.Rows.Count; i++)
            {
                grdMain.Rows[i].Cells[i + 1].BackColor = System.Drawing.Color.FromArgb(240, 240, 240);
            }
        }
Пример #5
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));
            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();
        }