using BLL; using System; using System.Linq; using System.Web; using System.Web.UI.WebControls; using System.Xml; namespace FineUIPro.Web { public partial class index : PageBase { #region Page_Init private string _menuType = "menu"; private int _examplesCount = 0; private string _searchText = ""; #region Page_Init /// /// /// /// /// protected void Page_Init(object sender, EventArgs e) { //////////////////////////////////////////////////////////////// string themeStr = Request.QueryString["theme"]; string menuStr = Request.QueryString["menu"]; if (!String.IsNullOrEmpty(themeStr) || !String.IsNullOrEmpty(menuStr)) { if (!String.IsNullOrEmpty(themeStr)) { HttpCookie cookie = new HttpCookie("Theme_Pro", "Cupertino") { Expires = DateTime.Now.AddYears(1) }; Response.Cookies.Add(cookie); } if (!String.IsNullOrEmpty(menuStr)) { HttpCookie cookie = new HttpCookie("MenuStyle_Pro", menuStr) { Expires = DateTime.Now.AddYears(1) }; Response.Cookies.Add(cookie); } PageContext.Redirect("~/default.aspx"); return; } //////////////////////////////////////////////////////////////// if (!IsPostBack) { //this.CurrUser.LoginProjectId = null; } } #endregion #region InitTreeMenu /// /// /// /// private Tree InitTreeMenu() { Tree treeMenu = new Tree { ID = "treeMenu", ShowBorder = false, ShowHeader = false, EnableIcons = true, AutoScroll = true, EnableSingleClickExpand = true }; if (_menuType == "tree" || _menuType == "tree_minimode") { treeMenu.HideHScrollbar = true; treeMenu.ExpanderToRight = true; treeMenu.HeaderStyle = true; if (_menuType == "tree_minimode") { treeMenu.MiniMode = true; treeMenu.MiniModePopWidth = Unit.Pixel(300); leftPanelToolGear.Hidden = true; leftPanelToolCollapse.IconFont = IconFont.ChevronCircleRight; leftPanel.Width = Unit.Pixel(50); leftPanel.CssClass = "minimodeinside"; } } leftPanel.Items.Add(treeMenu); XmlDocument doc = XmlDataSource1.GetXmlDocument(); ResolveXmlDocument(doc); // 绑定 XML 数据源到树控件 treeMenu.NodeDataBound += treeMenu_NodeDataBound; treeMenu.PreNodeDataBound += treeMenu_PreNodeDataBound; treeMenu.DataSource = doc; treeMenu.DataBind(); return treeMenu; } #endregion #region ResolveXmlDocument private void ResolveXmlDocument(XmlDocument doc) { ResolveXmlDocument(doc, doc.DocumentElement.ChildNodes); } private int ResolveXmlDocument(XmlDocument doc, XmlNodeList nodes) { // nodes 中渲染到页面上的节点个数 int nodeVisibleCount = 0; foreach (XmlNode node in nodes) { // Only process Xml elements (ignore comments, etc) if (node.NodeType == XmlNodeType.Element) { XmlAttribute removedAttr; // 是否叶子节点 bool isLeaf = node.ChildNodes.Count == 0; // 所有过滤条件均是对叶子节点而言,而是否显示目录,要看是否存在叶子节点 if (isLeaf) { // 存在搜索关键字 if (!String.IsNullOrEmpty(_searchText)) { XmlAttribute textAttr = node.Attributes["Text"]; if (textAttr != null) { if (!textAttr.Value.Contains(_searchText) && isLeaf) { removedAttr = doc.CreateAttribute("Removed"); removedAttr.Value = "true"; node.Attributes.Append(removedAttr); } } } } // 存在子节点 if (!isLeaf) { // 递归 int childVisibleCount = ResolveXmlDocument(doc, node.ChildNodes); if (childVisibleCount == 0) { removedAttr = doc.CreateAttribute("Removed"); removedAttr.Value = "true"; node.Attributes.Append(removedAttr); } } removedAttr = node.Attributes["Removed"]; if (removedAttr == null) { nodeVisibleCount++; } } } return nodeVisibleCount; } #endregion #region treeMenu_NodeDataBound treeMenu_PreNodeDataBound /// /// 树节点的绑定后事件 /// /// /// private void treeMenu_NodeDataBound(object sender, TreeNodeEventArgs e) { // 是否叶子节点 bool isLeaf = e.XmlNode.ChildNodes.Count == 0; if (!String.IsNullOrEmpty(e.Node.Text)) { if (GetIsNewHtml(e.XmlNode)) { e.Node.Text = "" + e.Node.Text + ""; if (e.Node.ParentNode != null) { e.Node.ParentNode.Text = "" + e.Node.ParentNode.Text + ""; } } } if (isLeaf) { // 设置节点的提示信息 e.Node.ToolTip = e.Node.Text; } // 如果仅显示最新示例,或者存在搜索文本 if (!String.IsNullOrEmpty(_searchText)) { e.Node.Expanded = true; } } /// /// 树节点的预绑定事件 /// /// /// private void treeMenu_PreNodeDataBound(object sender, TreePreNodeEventArgs e) { // 是否叶子节点 bool isLeaf = e.XmlNode.ChildNodes.Count == 0; XmlAttribute removedAttr = e.XmlNode.Attributes["Removed"]; if (removedAttr != null) { e.Cancelled = true; } bool isShow = GetIsPowerMenu(e.XmlNode); if (!isShow) { e.Cancelled = true; } if (isLeaf && !e.Cancelled) { _examplesCount++; } } #endregion #region 该节点是否显示 /// /// 该节点是否显示 /// /// /// private bool GetIsPowerMenu(XmlNode node) { bool result = true; XmlAttribute isNewAttr = node.Attributes["id"]; if (isNewAttr != null) { result = BLL.CommonService.ReturnMenuByUserIdMenuId(this.CurrUser.PersonId, isNewAttr.Value.ToString(), this.CurrUser.LoginProjectId); } return result; } #endregion #region GetIsNewHtml 是否必填项 /// /// 是否必填项 /// /// /// private bool GetIsNewHtml(XmlNode xmlNode) { bool isShow = false; if (xmlNode.Attributes["Text"].Value.Contains("*")) { isShow = true; } else { } return isShow; } #endregion #endregion #region Page_Load /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!string.IsNullOrEmpty(Request.Params["PHTUrl"])) { mainTabStrip.ShowTabHeader = true; PageContext.RegisterStartupScript("parent.removeActiveTab();"); //btnPHTGL_Click(null, null); if (!string.IsNullOrEmpty(Request.Params["PHTUserid"])) { var model_user = BLL.Person_PersonsService.GetPerson_PersonsById(Request.Params["PHTUserid"]); var q = BLL.Funs.DB.Person_Persons.FirstOrDefault(x => x.Account == model_user.Account && x.Password == model_user.Password); if (q != null) { Session["CurrUser"] = q; Session["u"] = model_user.Account; Session["p"] = model_user.Password; } } btnZHGL_Click(null, null); PageContext.RegisterStartupScript(mainTabStrip.GetAddTabReference("dynamic_tab4", Request.Params["PHTUrl"], "审批", IconHelper.GetIconUrl(Icon.ApplicationAdd), true)); } else { this.MenuSwitchMethod(Request.Params["menuType"]); } this.MenuSwitchMethod(Request.Params["menuType"]); this.InitMenuStyleButton(); this.InitMenuModeButton(); this.InitLangMenuButton(); this.btnRetweet.Hidden = true; if (this.CurrUser.PersonId == Const.hfnbdId) { this.btnRetweet.Hidden = false; } this.userName.InnerText = this.CurrUser.PersonName; this.spDate.InnerText = DateTime.Now.ToLongDateString().ToString() + " " + WeekDayService.CaculateWeekDayT(DateTime.Now); if (this.CurrUser.Password == Const.MD5pwd) { Alert.ShowInTop("当前密码不安全,请尽快更改!", MessageBoxIcon.Warning); } this.hdHomePage.Text = "1"; if (this.CurrUser.HomePageType == "2") { this.Tab1.IFrameUrl = "~/common/main2.aspx"; this.hdHomePage.Text = "2"; } var getW = WeatherService.GetWeather(null); if (getW != null) { divWeather.InnerHtml = getW.WeatherRef + " " + getW.CurrTem + "°C"; } } } /// /// 菜单树样式 /// private void InitMenuStyleButton() { string menuStyle = "tree"; HttpCookie menuStyleCookie = Request.Cookies["MenuStyle_Pro"]; if (menuStyleCookie != null) { menuStyle = menuStyleCookie.Value; } SetSelectedMenuItem(MenuStyle, menuStyle); } /// /// /// private void InitMenuModeButton() { string menuMode = "normal"; HttpCookie menuModeCookie = Request.Cookies["MenuMode_Pro"]; if (menuModeCookie != null) { menuMode = menuModeCookie.Value; } SetSelectedMenuItem(MenuMode, menuMode); } /// /// 加载菜单语言 /// private void InitLangMenuButton() { string language = "zh_CN"; HttpCookie languageCookie = Request.Cookies["Language_Pro"]; if (languageCookie != null) { language = languageCookie.Value; } SetSelectedMenuItem(MenuLang, language); } /// /// 过滤菜单 /// /// /// private void SetSelectedMenuItem(MenuButton menuButton, string selectedDataTag) { foreach (MenuItem item in menuButton.Menu.Items) { MenuCheckBox checkBox = (item as MenuCheckBox); if (checkBox != null) { checkBox.Checked = checkBox.AttributeDataTag == selectedDataTag; } } } #endregion /// /// 功能模块切换方法 /// /// protected void MenuSwitchMethod(string type) { if (!string.IsNullOrEmpty(type)) { if (CommonService.IsHaveSystemPower(this.CurrUser.PersonId, type, this.CurrUser.LoginProjectId) || type == Const.Menu_Personal) { this.leftPanel.Hidden = false; this.XmlDataSource1.DataFile = "common/" + type + ".xml"; this.Tab1.IFrameUrl = ""; if (type == Const.Menu_Project) { this.Tab1.IFrameUrl = "ProjectData/ProjectList.aspx"; } } else { Alert.ShowInParent("您没有此模块操作权限,请联系管理员授权!", MessageBoxIcon.Warning); return; } } else { this.leftPanel.Hidden = true; this.XmlDataSource1.DataFile = "common/Menu_Personal.xml"; this.Tab1.IFrameUrl = "~/common/main.aspx"; } //if (!string.IsNullOrEmpty(type)) //{ // Person_PersonsService.UpdateLastUserInfo(this.CurrUser.PersonId, type, true, string.Empty); //} InitTreeMenu(); } protected void btnHome_Click(object sender, EventArgs e) { if (this.leftPanel.Hidden) { string url = "~/indexProject.aspx?projectId=" + this.CurrUser.LastProjectId; Person_PersonsService.UpdateLastUserInfo(this.CurrUser.PersonId, null, false, this.CurrUser.LastProjectId); PageContext.Redirect(url, "_top"); } else { this.MenuSwitchMethod(string.Empty); } } /// /// 人员管理 /// /// /// protected void btnPerson_Click(object sender, EventArgs e) { this.MenuSwitchMethod(Const.Menu_Person); } /// /// 通知 /// /// /// protected void btnNotice_Click(object sender, EventArgs e) { this.MenuSwitchMethod(Const.Menu_Notice); } /// /// 项目清单 /// /// /// protected void btnProject_Click(object sender, EventArgs e) { this.MenuSwitchMethod(Const.Menu_Project); } /// /// 合同管理 /// /// /// protected void btnContract_Click(object sender, EventArgs e) { this.MenuSwitchMethod(Const.Menu_Contract); } /// /// 大数据中心 /// /// /// protected void btnDigData_Click(object sender, EventArgs e) { this.MenuSwitchMethod(Const.Menu_DigData); } /// /// 综合管理 /// /// /// protected void btnZHGL_Click(object sender, EventArgs e) { this.MenuSwitchMethod(Const.Menu_ZHGL); } /// /// 协同办公 /// /// /// protected void btnTeamWork_Click(object sender, EventArgs e) { this.MenuSwitchMethod(Const.Menu_TeamWork); } /// /// 智慧工地 /// /// /// protected void btnSmartSite_Click(object sender, EventArgs e) { this.MenuSwitchMethod(Const.Menu_SmartSite); } /// /// 个人信息 /// /// /// protected void btnPersonal_Click(object sender, EventArgs e) { this.MenuSwitchMethod(Const.Menu_Personal); } /// /// 系统设置 /// /// /// protected void btnSysSet_Click(object sender, EventArgs e) { this.MenuSwitchMethod(Const.Menu_SysSet); } /// /// 重新生成系统菜单 /// /// /// protected void btnRetweet_Click(object sender, EventArgs e) { ////设置菜单 CreateMenuXML.getMenuXML(); MenuSwitchMethod(string.Empty); ShowNotify("菜单刷新完成!", MessageBoxIcon.Success); } protected void btnChangeHomePage_Click(object sender, EventArgs e) { if (this.hdHomePage.Text == "1") { this.hdHomePage.Text = "2"; this.Tab1.IFrameUrl = "~/common/main2.aspx"; } else { this.hdHomePage.Text = "1"; this.Tab1.IFrameUrl = "~/common/main.aspx"; } } } }