Example #1
0
 public ZTree(Webpages_Roles role)
 {
     ID = role.Code;
     Name = role.RoleName;
     NodeType = "Role";
     ICON = "Content/zTreeStyle/img/role.gif";
 }
Example #2
0
 public ActionResult CreateRole(string parentNodeCode = null)
 {
     if (!string.IsNullOrEmpty(parentNodeCode))
     {
         var parent = db.WebPagesRoles.Find(parentNodeCode);
         if (parent == null)
             return HttpNotFound();
         ViewBag.ParentCode = parent.Code;
         ViewBag.ParentName = parent.RoleName;
     }
     Webpages_Roles role = new Webpages_Roles()
     {
         IndexOrder = 1
     };
     return View(role);
 }
Example #3
0
        public ActionResult CreateRole(Webpages_Roles role, string parentNodeCode = null)
        {
            if (!string.IsNullOrEmpty(parentNodeCode))
            {

                var parent = db.WebPagesRoles.Find(parentNodeCode);
                if (parent == null)
                {
                    return HttpNotFound();
                }
                if (parent.GetSubRoleByName(role.RoleName, db) != null)
                {
                    return Content(role.RoleName + " Exist!");
                }
                //生成新的编码
                string codeHead = parent.Code + "-";
                var curLevelCodes = (from r in db.WebPagesRoles
                                     where r.Code.IndexOf(codeHead) == 0
                                     orderby r.Code
                                     select r.Code).ToList();

                if (curLevelCodes.Count == 0)
                {
                    role.Code = codeHead + "1";
                }
                else
                {
                    //只申请这么多个(groups.Length)标志位足够了,
                    //因为,如果全占了,就返回groups.Length+1,
                    //如果没有全占,那么中间肯定有空位
                    System.Collections.BitArray ba = new BitArray(curLevelCodes.Count);
                    //找空号
                    int ValidID = -1;
                    foreach (var c in curLevelCodes)
                    {
                        string[] ary = c.Split('-');
                        int tmp = Convert.ToInt32(ary[ary.Length - 1]);
                        if (tmp > curLevelCodes.Count)//超出的不予理会
                            continue;
                        ba[tmp - 1] = true;//打标
                    }
                    for (int i = 0; i < ba.Length; i++)
                    {//从中查找空位
                        if (!ba[i])
                        {
                            ValidID = i + 1;
                            break;
                        }

                    }
                    if (ValidID == -1)//位全占
                        ValidID = curLevelCodes.Count + 1;
                    role.Code = codeHead + ValidID;
                }
            }
            else
            {
                role.Code = role.Type.ToString();
            }
            var tmpAry = role.Code.Split('-');
            role.Type = Convert.ToInt32(tmpAry[0]);
            role.Deep = tmpAry.Length - 1;
            db.WebPagesRoles.Add(role);
            db.SaveChanges();
            return Content(Boolean.TrueString);
        }
Example #4
0
 public ActionResult EditRole(Webpages_Roles role)
 {
     if (ModelState.IsValid)
     {
         db.Entry(role).State = System.Data.EntityState.Modified;
         db.SaveChanges();
     }
     return Content(Boolean.TrueString);
 }
Example #5
0
        public static Webpages_Roles GetOrCreateRoot(int type=1,string rootName="Root",WebPagesContext db=null)
        {
            bool flag = db == null;
            try
            {
                string code = type.ToString();
                if (flag) db = new WebPagesContext();
                var root = db.WebPagesRoles.Where(o => o.Type == type && o.RoleName == rootName &&
                    o.Deep == 0 && o.Code == code).FirstOrDefault();
                if (root == null)
                {
                    root = new Webpages_Roles()
                    {
                        Type = type,
                        RoleName = rootName,
                        Deep = 0,
                        Code = type.ToString(),
                    };
                    db.WebPagesRoles.Add(root);
                    db.SaveChanges();
                }
                return root;

            }
            finally
            {
                if (flag)
                    db.Dispose();
            }
        }