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()); }
public string GetUserMenu1(Guid userID) { Menu menu = new Menu(); new AppLibrary(); DataTable allDataTable = menu.GetAllDataTable(); if (allDataTable.Rows.Count == 0) { return(""); } StringBuilder stringBuilder = new StringBuilder(); string source = string.Empty; List <RoadFlow.Data.Model.MenuUser> all = new MenuUser().GetAll(); foreach (RoadFlow.Data.Model.UserShortcut item in new UserShortcut().GetAllByUserID(userID, true)) { 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 stringBuilder2 = 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) { stringBuilder2.Append(item2.Key.Trim1()); stringBuilder2.Append("&"); } @params = stringBuilder2.ToString().TrimEnd('&'); } if (HasUse(item.MenuID, userID, all, out source, out @params)) { DataRow[] array = allDataTable.Select(string.Format("ID='{0}'", item.MenuID.ToString())); if (array.Length != 0) { DataRow dataRow = array[0]; string str = dataRow["IcoColor"].ToString(); if (str.IsNullOrEmpty()) { str = dataRow["IcoColor1"].ToString(); } DataRow[] array2 = allDataTable.Select("ParentID='" + dataRow["ID"].ToString() + "'"); stringBuilder.Append("<div class=\"menulistdiv11\" title=\"" + dataRow["Title"].ToString().Trim1() + "\" onclick=\"menuClick1(this);\" data-id=\"" + dataRow["ID"].ToString() + "\" data-title=\"" + dataRow["Title"].ToString().Trim() + "\" data-model=\"" + dataRow["OpenMode"].ToString() + "\" data-width=\"" + dataRow["Width"].ToString() + "\" data-height=\"" + dataRow["Height"].ToString() + "\" data-childs=\"" + ((array2.Length != 0) ? "1" : "0") + "\" data-url=\"" + getAddress(dataRow, @params) + "\" data-parent=\"" + Guid.Empty.ToString() + "\" style=\"" + (str.IsNullOrEmpty() ? "" : ("color:" + str.Trim1() + ";")) + "\">"); stringBuilder.Append("<div class=\"menulistdiv1\">"); string text = dataRow["Ico"].ToString(); if (text.IsNullOrEmpty()) { text = dataRow["AppIco"].ToString(); } if (text.IsNullOrEmpty()) { stringBuilder.Append("<i class=\"fa fa-list-ul\" style=\"margin-right:3px;vertical-align:middle\"></i>"); } else if (text.IsFontIco()) { stringBuilder.Append("<i class=\"fa " + text + "\" style=\"margin-right:3px;vertical-align:middle\"></i>"); } else { stringBuilder.Append("<img src=\"" + Config.BaseUrl + text + "\" style=\"vertical-align:middle\" alt=\"\"/>"); } stringBuilder.Append("</div>"); stringBuilder.Append("</div>"); } } } DataRow[] array3 = allDataTable.Select(string.Format("ParentID='{0}'", Guid.Empty.ToString())); if (array3.Length == 0) { return(stringBuilder.ToString()); } DataRow[] array4 = allDataTable.Select(string.Format("ParentID='{0}'", array3[0]["ID"].ToString())); for (int i = 0; i < array4.Length; i++) { string params2 = string.Empty; DataRow dataRow2 = array4[i]; if (HasUse(dataRow2["ID"].ToString().ToGuid(), userID, all, out source, out params2)) { DataRow[] array5 = allDataTable.Select("ParentID='" + dataRow2["ID"].ToString() + "'"); bool flag = false; DataRow[] array6 = array5; foreach (DataRow dataRow3 in array6) { if (HasUse(dataRow3["ID"].ToString().ToGuid(), userID, all, out source, out params2)) { flag = true; break; } } string str2 = dataRow2["IcoColor"].ToString(); if (str2.IsNullOrEmpty()) { str2 = dataRow2["IcoColor1"].ToString(); } stringBuilder.Append("<div class=\"menulistdiv11\" title=\"" + dataRow2["Title"].ToString().Trim1() + "\" onclick=\"menuClick1(this);\" data-id=\"" + dataRow2["ID"].ToString() + "\" data-title=\"" + dataRow2["Title"].ToString().Trim() + "\" data-model=\"" + dataRow2["OpenMode"].ToString() + "\" data-width=\"" + dataRow2["Width"].ToString() + "\" data-height=\"" + dataRow2["Height"].ToString() + "\" data-childs=\"" + (flag ? "1" : "0") + "\" data-url=\"" + getAddress(dataRow2, params2) + "\" data-parent=\"" + Guid.Empty.ToString() + "\" style=\"" + (str2.IsNullOrEmpty() ? "" : ("color:" + str2.Trim1() + ";")) + "\">"); stringBuilder.Append("<div class=\"menulistdiv1\">"); string text2 = dataRow2["Ico"].ToString(); if (text2.IsNullOrEmpty()) { text2 = dataRow2["AppIco"].ToString(); } if (text2.IsNullOrEmpty()) { stringBuilder.Append("<i class=\"fa fa-th-list\" style=\"margin-right:3px;vertical-align:middle\"></i>"); } else if (text2.IsFontIco()) { stringBuilder.Append("<i class=\"fa " + text2 + "\" style=\"margin-right:3px;vertical-align:middle\"></i>"); } else { stringBuilder.Append("<img src=\"" + Config.BaseUrl + text2 + "\" style=\"vertical-align:middle\" alt=\"\"/>"); } stringBuilder.Append("</div>"); stringBuilder.Append("</div>"); } } return(stringBuilder.ToString()); }