public ActionResult ShortcutSet(FormCollection collection)
 {
     RoadFlow.Platform.UserShortcut userShortcut = new RoadFlow.Platform.UserShortcut();
     if (collection != null)
     {
         if (!base.Request.Form["issort"].IsNullOrEmpty())
         {
             string[] array = (base.Request.Form["sort"] ?? "").Split(',');
             for (int i = 0; i < array.Length; i++)
             {
                 RoadFlow.Data.Model.UserShortcut userShortcut2 = userShortcut.Get(array[i].ToGuid());
                 if (userShortcut2 != null)
                 {
                     userShortcut2.Sort = i;
                     userShortcut.Update(userShortcut2);
                 }
             }
             base.ViewBag.script = "alert('排序保存成功!');window.location=window.location;";
         }
         else
         {
             Guid   currentUserID = RoadFlow.Platform.Users.CurrentUserID;
             string text          = base.Request.Form["menuid"] ?? "";
             using (TransactionScope transactionScope = new TransactionScope())
             {
                 userShortcut.DeleteByUserID(currentUserID);
                 int      num    = 0;
                 string[] array2 = text.Split(',');
                 foreach (string str in array2)
                 {
                     if (str.IsGuid())
                     {
                         RoadFlow.Data.Model.UserShortcut userShortcut3 = new RoadFlow.Data.Model.UserShortcut();
                         userShortcut3.ID     = Guid.NewGuid();
                         userShortcut3.MenuID = str.ToGuid();
                         userShortcut3.Sort   = num++;
                         userShortcut3.UserID = currentUserID;
                         userShortcut.Add(userShortcut3);
                     }
                 }
                 transactionScope.Complete();
                 base.ViewBag.script = "alert('保存成功!');window.location=window.location;";
             }
         }
         userShortcut.ClearCache();
     }
     return(View());
 }
示例#2
0
        public string GetUserMenuJsonString(Guid userID, string rootDir = "", bool showSource = false)
        {
            Menu menu = new Menu();

            new AppLibrary();
            DataTable allDataTable = menu.GetAllDataTable();

            if (allDataTable.Rows.Count == 0)
            {
                return("[]");
            }
            DataRow[] array = allDataTable.Select(string.Format("ParentID='{0}'", Guid.Empty.ToString()));
            if (array.Length == 0)
            {
                return("[]");
            }
            List <RoadFlow.Data.Model.MenuUser> all = new MenuUser().GetAll();

            DataRow[]     array2        = allDataTable.Select(string.Format("ParentID='{0}'", array[0]["ID"].ToString()));
            StringBuilder stringBuilder = new StringBuilder("", 1000);
            DataRow       dataRow       = array[0];
            string        empty         = string.Empty;

            stringBuilder.Append("{");
            stringBuilder.AppendFormat("\"id\":\"{0}\",", dataRow["ID"].ToString());
            stringBuilder.AppendFormat("\"title\":\"{0}\",", dataRow["Title"].ToString().Trim());
            stringBuilder.AppendFormat("\"ico\":\"{0}\",", dataRow["AppIco"].ToString());
            stringBuilder.AppendFormat("\"color\":\"{0}\",", dataRow["IcoColor"].ToString());
            stringBuilder.AppendFormat("\"link\":\"{0}\",", getAddress(dataRow).ToString(), empty);
            stringBuilder.AppendFormat("\"model\":\"{0}\",", dataRow["OpenMode"].ToString());
            stringBuilder.AppendFormat("\"width\":\"{0}\",", dataRow["Width"].ToString());
            stringBuilder.AppendFormat("\"height\":\"{0}\",", dataRow["Height"].ToString());
            stringBuilder.AppendFormat("\"hasChilds\":\"{0}\",", (array2.Length != 0) ? "1" : "0");
            stringBuilder.AppendFormat("\"childs\":[");
            StringBuilder stringBuilder2 = new StringBuilder(array2.Length * 100);
            string        source         = string.Empty;

            if (!showSource)
            {
                List <RoadFlow.Data.Model.UserShortcut> allByUserID = new UserShortcut().GetAllByUserID(userID, true);
                if (allByUserID.Count > 0)
                {
                    stringBuilder2.Append("{");
                    stringBuilder2.AppendFormat("\"id\":\"{0}\",", Guid.NewGuid());
                    stringBuilder2.AppendFormat("\"title\":\"{0}\",", "快捷菜单");
                    stringBuilder2.AppendFormat("\"ico\":\"{0}\",", "");
                    stringBuilder2.AppendFormat("\"color\":\"{0}\",", "");
                    stringBuilder2.AppendFormat("\"link\":\"{0}\",", "");
                    stringBuilder2.AppendFormat("\"model\":\"{0}\",", "");
                    stringBuilder2.AppendFormat("\"width\":\"{0}\",", "");
                    stringBuilder2.AppendFormat("\"height\":\"{0}\",", "");
                    stringBuilder2.AppendFormat("\"hasChilds\":\"1\",");
                    stringBuilder2.AppendFormat("\"childs\":[");
                    StringBuilder stringBuilder3 = new StringBuilder();
                    foreach (RoadFlow.Data.Model.UserShortcut item in allByUserID)
                    {
                        string @params = string.Empty;
                        List <RoadFlow.Data.Model.MenuUser> list = all.FindAll(delegate(RoadFlow.Data.Model.MenuUser p)
                        {
                            if (p.MenuID == item.MenuID && p.SubPageID == Guid.Empty)
                            {
                                return(p.Users.Contains(userID.ToString(), StringComparison.CurrentCultureIgnoreCase));
                            }
                            return(false);
                        });
                        if (list.Count > 0)
                        {
                            StringBuilder stringBuilder4 = new StringBuilder();
                            foreach (IGrouping <string, RoadFlow.Data.Model.MenuUser> item2 in from p in list.FindAll((RoadFlow.Data.Model.MenuUser p) => !p.Params.IsNullOrEmpty())
                                     group p by p.Params)
                            {
                                stringBuilder4.Append(item2.Key.Trim1());
                                stringBuilder4.Append("&");
                            }
                            @params = stringBuilder4.ToString().TrimEnd('&');
                        }
                        if (HasUse(item.MenuID, userID, all, out source, out @params, showSource))
                        {
                            DataRow[] array3 = allDataTable.Select(string.Format("ID='{0}'", item.MenuID.ToString()));
                            if (array3.Length != 0)
                            {
                                DataRow   dataRow2 = array3[0];
                                DataRow[] array4   = allDataTable.Select("ParentID='" + dataRow2["ID"].ToString() + "'");
                                stringBuilder3.Append("{");
                                stringBuilder3.AppendFormat("\"id\":\"{0}\",", dataRow2["ID"].ToString());
                                stringBuilder3.AppendFormat("\"title\":\"{0}\",", dataRow2["Title"].ToString().Trim1());
                                stringBuilder3.AppendFormat("\"ico\":\"{0}\",", dataRow2["AppIco"].ToString());
                                stringBuilder3.AppendFormat("\"color\":\"{0}\",", dataRow2["IcoColor"].ToString());
                                stringBuilder3.AppendFormat("\"link\":\"{0}\",", getAddress(dataRow2, @params));
                                stringBuilder3.AppendFormat("\"model\":\"{0}\",", dataRow2["OpenMode"].ToString());
                                stringBuilder3.AppendFormat("\"width\":\"{0}\",", dataRow2["Width"].ToString());
                                stringBuilder3.AppendFormat("\"height\":\"{0}\",", dataRow2["Height"].ToString());
                                stringBuilder3.AppendFormat("\"hasChilds\":\"{0}\",", (array4.Length != 0) ? "1" : "0");
                                stringBuilder3.AppendFormat("\"childs\":[]");
                                stringBuilder3.Append("},");
                            }
                        }
                    }
                    stringBuilder2.Append((stringBuilder3.Length > 0) ? stringBuilder3.ToString().TrimEnd(',') : "");
                    stringBuilder2.Append("]");
                    stringBuilder2.Append("}");
                    if (array2.Length != 0)
                    {
                        stringBuilder2.Append(",");
                    }
                }
            }
            for (int i = 0; i < array2.Length; i++)
            {
                string  params2  = string.Empty;
                DataRow dataRow3 = array2[i];
                if (HasUse(dataRow3["ID"].ToString().ToGuid(), userID, all, out source, out params2, showSource))
                {
                    DataRow[] array5 = allDataTable.Select("ParentID='" + dataRow3["ID"].ToString() + "'");
                    bool      flag   = false;
                    DataRow[] array6 = array5;
                    foreach (DataRow dataRow4 in array6)
                    {
                        if (HasUse(dataRow4["ID"].ToString().ToGuid(), userID, all, out source, out params2, showSource))
                        {
                            flag = true;
                            break;
                        }
                    }
                    stringBuilder2.Append("{");
                    stringBuilder2.AppendFormat("\"id\":\"{0}\",", dataRow3["ID"].ToString());
                    stringBuilder2.AppendFormat("\"title\":\"{0}{1}\",", dataRow3["Title"].ToString().Trim1(), showSource ? ("<span style='margin-left:4px;color:#666;'>[" + source + "]</span>") : "");
                    stringBuilder2.AppendFormat("\"ico\":\"{0}\",", dataRow3["AppIco"].ToString());
                    stringBuilder2.AppendFormat("\"color\":\"{0}\",", dataRow3["IcoColor"].ToString());
                    stringBuilder2.AppendFormat("\"link\":\"{0}\",", getAddress(dataRow3, params2));
                    stringBuilder2.AppendFormat("\"model\":\"{0}\",", dataRow3["OpenMode"].ToString());
                    stringBuilder2.AppendFormat("\"width\":\"{0}\",", dataRow3["Width"].ToString());
                    stringBuilder2.AppendFormat("\"height\":\"{0}\",", dataRow3["Height"].ToString());
                    stringBuilder2.AppendFormat("\"hasChilds\":\"{0}\",", flag ? "1" : "0");
                    stringBuilder2.AppendFormat("\"childs\":[");
                    stringBuilder2.Append("]");
                    stringBuilder2.Append("}");
                    stringBuilder2.Append(",");
                }
            }
            stringBuilder.Append(stringBuilder2.ToString().TrimEnd(','));
            stringBuilder.Append("]");
            stringBuilder.Append("}");
            return(stringBuilder.ToString());
        }