예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            op = RequestData.Get <string>("op");
            id = RequestData.Get <string>("id");
            string AuthIds = RequestData.Get <string>("AuthIds");

            if (!string.IsNullOrEmpty(id))
            {
                ent = MyShortCut.Find(id);
            }
            switch (RequestActionString)
            {
            case "update":
                ent = GetMergedData <MyShortCut>();
                ent.DoUpdate();
                break;

            case "create":
                ent = GetPostedData <MyShortCut>();
                sql = @"delete from BJKY_IntegratedManage..MyShortCut where CreateId='{0}' and PatIndex('%'+AuthId+'%','{1}')>0";
                sql = string.Format(sql, UserInfo.UserID, ent.AuthId);
                DataHelper.ExecSql(sql);    //删除快捷中已经存在权限模块ID
                if (ent.AuthId.Length > 36)
                {
                    string[] authIdArray   = ent.AuthId.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    string[] authNameArray = ent.AuthName.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < authIdArray.Length; i++)
                    {
                        MyShortCut mscEnt = new MyShortCut();
                        mscEnt.AuthId   = authIdArray[i];
                        mscEnt.AuthName = authNameArray[i];
                        SysAuth   saEnt = SysAuth.Find(ent.AuthId);
                        SysModule smEnt = SysModule.Find(saEnt.ModuleID);
                        mscEnt.ModuleUrl    = smEnt.Url;
                        mscEnt.IconFileId   = ent.IconFileId;
                        mscEnt.IconFileName = ent.IconFileName;
                        mscEnt.DoCreate();
                    }
                }
                else
                {
                    SysAuth   saEnt = SysAuth.Find(ent.AuthId);
                    SysModule smEnt = SysModule.Find(saEnt.ModuleID);
                    ent.ModuleUrl = smEnt.Url;
                    ent.DoCreate();
                }
                break;

            default:
                DoSelect();
                break;
            }
        }
예제 #2
0
        string type = String.Empty; // 查询类型

        protected void Page_Load(object sender, EventArgs e)
        {
            id   = (RequestData.ContainsKey("id") ? RequestData["id"].ToString() : UserInfo.UserID);
            type = (RequestData.ContainsKey("type") ? RequestData["type"].ToString() : String.Empty).ToLower();
            if (this.IsAsyncRequest)
            {
                switch (this.RequestAction)
                {
                case RequestActionEnum.Custom:
                    if (RequestActionString == "querydescendant")
                    {
                        SysAuth[] ents  = null;
                        string    atype = String.Empty;
                        //ents = SysAuth.FindAll("FROM SysAuth as ent WHERE ent.Type = ?", id);
                        SysUser user = SysUser.Find(this.UserInfo.UserID);
                        ents = this.UserContext.Auths.OrderBy(ens => ens.SortIndex).ToArray();
                        //SysAuth.FindAll(Expression.Sql("AuthID in (select AuthID from SysUserPermission where UserID ='" + this.UserInfo.UserID + "')"));
                        //user.Auth.ToArray();
                        string jsonString = JsonHelper.GetJsonString(this.ToExtTreeCollection(ents.OrderBy(v => v.SortIndex).ThenBy(v => v.CreateDate), null));
                        Response.Write(jsonString);
                        Response.End();
                    }
                    else if (RequestActionString == "savechanges")
                    {
                        ICollection authAdded   = RequestData["added"] as ICollection;
                        ICollection authRemoved = RequestData["removed"] as ICollection;

                        if (type == "user" && !String.IsNullOrEmpty(id))
                        {
                            SysAuth[] tAuths = SysAuthRule.GetAuthByIDs(authAdded).ToArray();
                            foreach (SysAuth auth in tAuths)
                            {
                                MyShortCut cut = new MyShortCut();
                                cut.CreateId     = this.UserInfo.UserID;
                                cut.CreateName   = this.UserInfo.Name;
                                cut.CreateTime   = DateTime.Now;
                                cut.ModuleUrl    = SysModule.Find(auth.ModuleID).Url;
                                cut.AuthId       = auth.AuthID;
                                cut.AuthName     = auth.Name;
                                cut.IconFileName = "/images/shared/read.gif";
                                cut.Save();
                            }
                            if (authRemoved.Count > 0)
                            {
                                ICollection myAuthIDs = null;
                                if (authRemoved is JArray)
                                {
                                    JArray arrAuths = authRemoved as JArray;
                                    myAuthIDs = new List <string>(arrAuths.Values <string>());
                                }
                                else
                                {
                                    myAuthIDs = authRemoved;
                                }
                                foreach (string s in myAuthIDs)
                                {
                                    DataHelper.ExecSql("delete from MyShortCut where AuthId like '%" + s + "%' and CreateId='" + this.UserInfo.UserID + "'", DataHelper.GetCurrentDbConnection(typeof(MyShortCut)));
                                }
                            }
                            //SysAuthRule.GrantAuthToUser(authAdded, id);
                            //SysAuthRule.RevokeAuthFromUser(authRemoved, id);
                        }

                        /*else if (type == "group" && !String.IsNullOrEmpty(id))
                         * {
                         *  SysAuthRule.GrantAuthToGroup(authAdded, id);
                         *  SysAuthRule.RevokeAuthFromGroup(authRemoved, id);
                         * }
                         * else if (type == "role" && !String.IsNullOrEmpty(id))
                         * {
                         *  SysAuthRule.GrantAuthToRole(authAdded, id);
                         *  SysAuthRule.RevokeAuthFromRole(authRemoved, id);
                         * }*/
                    }
                    break;
                }
            }
            else
            {
                SysAuthType[] authTypeList = SysAuthTypeRule.FindAll();
                if (this.Request.QueryString["Role"] != null && this.Request.QueryString["Role"] == "User")
                {
                    authTypeList = SysAuthType.FindAllByProperties(SysAuthType.Prop_AuthTypeID, 1);
                }
                this.PageState.Add("DtList", authTypeList);
            }

            // 获取权限列表
            if (RequestAction != RequestActionEnum.Custom)
            {
                this.PageState.Add("EntityID", id);
                IEnumerable <string> authIDs = null;
                IList <MyShortCut>   mscEnts = MyShortCut.FindAllByProperty(MyShortCut.Prop_CreateId, UserInfo.UserID);

                authIDs = mscEnts.Select(s => s.AuthId);
                this.PageState.Add("AtList", new List <string>(authIDs));
                //using (new Castle.ActiveRecord.SessionScope())
                //{
                //    if (type == "user" && !String.IsNullOrEmpty(id))
                //    {
                //        SysUser user = SysUser.Find(id);
                //        if (this.RequestData.Get<string>("Deny") != null && this.RequestData.Get<string>("Deny").Trim() == "Y")
                //        {
                //            authIDs = (user.AuthNo).Select((ent) => { return ent.AuthID; });
                //        }
                //        else
                //            authIDs = (user.Auth).Select((ent) => { return ent.AuthID; });
                //    }
                //    else if (type == "group" && !String.IsNullOrEmpty(id))
                //    {
                //        SysGroup group = SysGroup.Find(id);
                //        authIDs = (group.Auth).Select((ent) => { return ent.AuthID; });
                //    }
                //    else if (type == "role" && !String.IsNullOrEmpty(id))
                //    {
                //        SysRole role = SysRole.Find(id);
                //        authIDs = (role.Auth).Select((ent) => { return ent.AuthID; });
                //    }
                //    this.PageState.Add("AtList", new List<string>(authIDs));
                //}
            }
        }