using System; using System.Collections; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Text; using System.IO; using System.Net; using DSWeb.Models; using DSWeb.EntityDA; using DSWeb.Filter; using DSWeb.Authority; namespace DSCustomer { public partial class _Default : System.Web.UI.Page { //private string strUserName; private string strUserID; private string strShowName; private string strRoleName; StringBuilder leftNav = new StringBuilder(); StringBuilder leftTree = new StringBuilder(); StringBuilder tmpLeftTree = new StringBuilder(); //用户权限信息 IList userActionEntities = new List(); protected void Page_Load(object sender, EventArgs e) { if (Session["USERID"] != null) { strUserID = Session["USERID"].ToString(); } if (Session["SHOWNAME"] != null) { strShowName = Session["SHOWNAME"].ToString(); } #region //else //{ // Response.Write(""); // Response.End(); //} //if (strUserID != null) //{ // UserAttributeDA userAttributeDA = new UserAttributeDA(); // IList userAttributeEntities = new List(); // userAttributeEntities = userAttributeDA.GetUserAttributeValue(strUserID); // strRoleName = ""; // if (userAttributeEntities.Count > 0) // { // foreach (UserAttributeEntity userAttributeEntity in userAttributeEntities) // { // if (!userAttributeEntity.Description.Trim().Equals("")) // { // if (!strRoleName.Trim().Equals("")) // { // strRoleName = userAttributeEntity.Description.Trim().Replace("是否", ""); // } // else // { // strRoleName += "、"+userAttributeEntity.Description.Trim().Replace("是否", ""); // } // } // } // } //} #endregion if (strUserID != null) { HttpRequest request = Page.Request; LeftTreeCssFilter myFilter = new LeftTreeCssFilter(request); DoGet(); } else { Response.Redirect("login.aspx"); } } /// /// /// /// /// private List ActionFilter(List moduleEntites) { List ActionFilter = new List(); foreach (ModuleEntity moduleEntity in moduleEntites) { if (moduleEntity.Gid == "34B7EFA1-AAA8-4576-95C7-7891B6252398") { ActionFilter.Add(moduleEntity); } } return ActionFilter; } public void DoGet() { ModuleDA moduleDA = new ModuleDA(); List moduleEntites = moduleDA.GetParentModule(); #region 获取用户权限 //UserDA userDA = new UserDA(); //UserEntity userEntity = new UserEntity(); //userEntity = userDA.GetUserSignByID(strUserID); CRMClientDA crmClientDA = new CRMClientDA(); CRMClientEntity crmClientEntity = new CRMClientEntity(); crmClientEntity = crmClientDA.GetCrmClientInfoByGID(strUserID); object obj = (object)crmClientEntity; AuthorityManage authorityManage = new AuthorityManage(AuthorityManage.AuthorityType.CRMCLIENT, obj); userActionEntities = authorityManage.GetCrmClientAction(); #endregion //遍历用户权限信息对比当前模块信息,只显示模块权限内的主模块信息 int modCount = 0; modCount = moduleEntites.Count; for (int i = 0; i < modCount; i++) { int iCount = 0; foreach (UserActionEntity userActionEntity in userActionEntities) { if (userActionEntity.ActionEntity.ModuleEntity.ParentID.Trim() == "0" && userActionEntity.ActionEntity.ModuleEntity.ModuleType == 0) { //遍历所有顶层模块,所有PARENTID = 0的模块,如果没有属于权限范围内的模块则自动删除 if (userActionEntity.ActionEntity.ModuleEntity.Gid.Trim() == moduleEntites[i].Gid) { iCount++; break; } } } if (iCount == 0) { moduleEntites.Remove(moduleEntites[i]); i = -1; modCount = moduleEntites.Count; } else { continue; } } StringBuilder htmlBuilder = new StringBuilder(); LeftTreeCssFilter cssFilter = new LeftTreeCssFilter(Page.Request); //测试用数据 //string testUserGID = "1BEC90E1-9780-472F-90C2-0C6390C044A4"; //RoleDA roleDA = new RoleDA(); //RoleEntity roleEntity = roleDA.LoadUsingDynamicCode(testUserGID); string strBVersion = cssFilter.Version.Trim(); string strBName = cssFilter.BrowserName.ToLower().Trim(); htmlBuilder.Append(""); htmlBuilder.Append("Manager"); //根据不同的浏览器加载不同的css样式 if (strBVersion.Equals("6.0") && strBName.Equals("ie")) { htmlBuilder.Append(""); htmlBuilder.Append(""); } //if (strBName.Equals("firefox")) //{ // htmlBuilder.Append(""); // htmlBuilder.Append(""); //} else { htmlBuilder.Append(""); htmlBuilder.Append(""); } htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append(""); //htmlBuilder.Append(""); //htmlBuilder.Append(""); htmlBuilder.Append(""); string strIntervalCount = System.Configuration.ConfigurationSettings.AppSettings["messageinterval"].ToString() as string; if (strIntervalCount != null) { int iTempCount = int.Parse(strIntervalCount); if (iTempCount < 1000) { strIntervalCount = "1500"; } } htmlBuilder.Append(""); /*htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append("");*/ htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append("
"); htmlBuilder.Append("");// htmlBuilder.Append(""); htmlBuilder.Append("
"); htmlBuilder.Append(""); htmlBuilder.Append(""); htmlBuilder.Append("
"); htmlBuilder.Append(""); htmlBuilder.Append("
 "); MessageDA messageDA = new MessageDA(); MessageTotalEntity messageTotalEntity = messageDA.GetMessageTotalByReceiver(strUserID); string strReadTotal = ""; if (messageTotalEntity != null) { strReadTotal = "我的消息(" + messageTotalEntity.ReadTotal + "/" + messageTotalEntity.Total + ")"; } htmlBuilder.Append("
用户名: " + strShowName + "        " + strReadTotal + "    "); htmlBuilder.Append("下载    "); htmlBuilder.Append("[退出]    
      "); htmlBuilder.Append("
    • "); htmlBuilder.Append("
    "); htmlBuilder.Append("
      "); string strValue = GetTreeView(moduleEntites); htmlBuilder.Append(leftNav.ToString()); htmlBuilder.Append("
    ");//
    htmlBuilder.Append(strValue); htmlBuilder.Append(""); //htmlBuilder.Append("
    "); htmlBuilder.Append(""); Response.Clear(); Response.Write(htmlBuilder.ToString()); } /// /// 获取左侧展开树内容 /// /// 实体类ModuleEntity /// public String GetTreeView(List tempEntities) { //StringBuilder leftNav = new StringBuilder(); StringBuilder leftTree = new StringBuilder(); StringBuilder tmpLeftTree = new StringBuilder(); //树型菜单第一级菜单 StringBuilder leftTreeData = new StringBuilder(); StringBuilder treesJS = new StringBuilder(); foreach (ModuleEntity mdel in tempEntities) { leftNav.Append("
  • "); leftNav.Append(" "); leftNav.Append(mdel.ModuleDescription); leftNav.Append("
  • "); tmpLeftTree = new StringBuilder();// class=\"TreeMenu\" tmpLeftTree.Append("
    "); tmpLeftTree.Append("
    "); leftTreeData.Append(LeftTreeNodeData(mdel)); leftTree.Append(tmpLeftTree.ToString()); } //treesJS.append(LeftTreeNodeRender(modelsList,appModelsList.get(i),user.getTokenID())); //leftTreeData.Append(LeftTreeNodeData(modelsList, appModelsList.get(i), user.getTokenID())); //leftTreeData.Append(LeftTreeNodeData()); //leftTree.Append(tmpLeftTree.ToString()); return leftTreeData.ToString(); } #region /*public string GetLeftNav(List tempEntities) { StringBuilder navBuilder = new StringBuilder(); if (tempEntities.Count > 0) { foreach (ModuleEntity mdel in tempEntities) { if (mdel.ParentID.Trim().Equals(0)) { navBuilder.Append("
  • "); navBuilder.Append(" "); navBuilder.Append(mdel.ModuleName); navBuilder.Append("
  • "); } else { } } } return navBuilder.ToString(); }*/ #endregion public String ConvertToJS(JSTreeNodeEntity tempJSTreeEntity) { StringBuilder nodeJS = new StringBuilder(); nodeJS.Append("{"); nodeJS.Append("\"id\":\"root" + tempJSTreeEntity.Gid + "\""); nodeJS.Append(","); nodeJS.Append("\"text\":\"" + tempJSTreeEntity.Text + "\""); nodeJS.Append(","); nodeJS.Append("\"value\":\"" + tempJSTreeEntity.Value + "\""); nodeJS.Append(","); nodeJS.Append("\"showcheck\":" + (tempJSTreeEntity.SetShowCheck ? 1 : 0).ToString() + ""); nodeJS.Append(","); nodeJS.Append("\"complete\":1"); nodeJS.Append(","); nodeJS.Append("\"isexpand\":1"); //+ (tempJSTreeEntity.IsExpand ? 1 : 0).ToString() + ""); nodeJS.Append(","); nodeJS.Append("\"checkstate\":" + tempJSTreeEntity.CheckState + ""); nodeJS.Append(","); nodeJS.Append("\"hasChildren\":" + (tempJSTreeEntity.SetHasChild ? 1 : 0).ToString() + ""); nodeJS.Append(","); string classes = tempJSTreeEntity.SetClasses; string ChildNodes = ""; if (classes != null && !classes.Equals("")) { int ilen = classes.IndexOf('.'); classes = classes.Substring(0, ilen); if (classes.Length > 1) { nodeJS.Append("\"classes\":\"" + classes + "\""); nodeJS.Append(","); } } nodeJS.Append("\"ChildNodes\":\"null\""); nodeJS.Append("}"); return nodeJS.ToString(); } #region /* public String LeftTreeNodeData(ModuleEntity tempEntity) { StringBuilder appTreeData = new StringBuilder(); StringBuilder childerData = new StringBuilder(); ModuleDA moduleDA = new ModuleDA(); List subModule = moduleDA.GetSubModule(tempEntity.Gid); List tempEntities = moduleDA.GetAllSubModules(); appTreeData.Append(""); return appTreeData.ToString(); }*/ #endregion public String LeftTreeNodeData(ModuleEntity tempEntity) { StringBuilder appTreeData = new StringBuilder(); StringBuilder childerData = new StringBuilder(); ModuleDA moduleDA = new ModuleDA(); //List subModule = moduleDA.GetSubModule(tempEntity.Gid); //List tempEntities = moduleDA.GetAllUserBaseSubModules(); List subModule = moduleDA.GetSubModule(tempEntity.Gid); List tempEntities = moduleDA.GetAllSubModules(); if (userActionEntities.Count > 0) { tempEntities = null; tempEntities = new List(); foreach (UserActionEntity userActionEntity in userActionEntities) { if (userActionEntity.ActionEntity.ModuleEntity.ParentID.Trim() != "0") { tempEntities.Add(userActionEntity.ActionEntity.ModuleEntity); } } } appTreeData.Append(""); return appTreeData.ToString(); } /// /// 返回 /// /// /// /// public String GetSubJs(string parentGid, List tempEntities, string tempJSON) { StringBuilder valBuilder = new StringBuilder(); StringBuilder childBuilder = new StringBuilder(); foreach (ModuleEntity mdle in tempEntities) { if (parentGid.Trim().Equals(mdle.ParentID)) { bool isParentNode = IsParent(tempEntities, mdle.Gid); string strTempNode = GetNodeJs(mdle, isParentNode); string strTempValue = ""; if (isParentNode) { strTempValue = GetSubJs(mdle.Gid, tempEntities, strTempNode); childBuilder.Append(strTempValue); } if (strTempValue.Trim().Equals("")) { childBuilder.Append(strTempNode); } } } if (childBuilder.Length > 1) { string strChilds = childBuilder.ToString(); strChilds = strChilds.Substring(0, strChilds.Length - 1);//去除末尾逗号 if (!tempJSON.Equals("")) { tempJSON = tempJSON.Replace("\"null\"", "[" + strChilds + "]"); valBuilder.Append(tempJSON); } else { valBuilder.Append(strChilds); } } return valBuilder.ToString(); } /*public String GetSubJs(string parentGid, List tempEntities) { StringBuilder tempJSON = new StringBuilder(); StringBuilder tempBuilder = new StringBuilder(); foreach (ModuleEntity mdle in tempEntities) { if (parentGid.Trim().Equals(mdle.ParentID)) { tempJSON.Append(GetNodeJs(mdle, true)); tempJSON.Append("-"); tempJSON.Append(GetSubJs(mdle.Gid, tempEntities)); } } return tempJSON.ToString(); }*/ /// /// 遍历模块查看此模块是否为父模块 /// /// /// /// public bool IsParent(List tempEntities, string strGID) { bool IsExist = false; foreach (ModuleEntity mdle in tempEntities) { if (mdle.ParentID.Trim().Equals(strGID)) { IsExist = true; } } return IsExist; } #region 获取节点JSON值 /// /// 获取节点JSON值 /// /// /// /// public String GetNodeJs(ModuleEntity tempEntity, bool hasChild) { StringBuilder tempNodeBuilder = new StringBuilder(); JSTreeNodeEntity modelData = new JSTreeNodeEntity(); modelData.Gid = tempEntity.Gid.Replace("-", ""); modelData.Text = tempEntity.ModuleDescription; modelData.SetShowCheck = false; modelData.CheckState = 0; modelData.IsExpand = false; modelData.SetClasses = tempEntity.ModuleIcon; String tmpUrl = tempEntity.ModuleUrl.Trim(); //如果数据库模板表Module字段Url设置为"#"则不提供链接 if (!tmpUrl.Equals("#")) { tmpUrl += "?mod=" + tempEntity.ModuleName; tmpUrl = "../" + tmpUrl; modelData.Value = "CreateTab('" + tempEntity.ModuleDescription + "','H','" + tmpUrl + "');"; } else { modelData.Value = "javascript:void(0);"; } //设置是否有子菜单 if (hasChild) { modelData.SetChildNode = 0; modelData.SetHasChild = true; } else { modelData.SetChildNode = 0; modelData.SetHasChild = false; } //recording++; // Response.Write(ConvertToJS(modelData) + ","); return (ConvertToJS(modelData) + ","); } #endregion } }