using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Utils; using SiteCore; public partial class MasterPage_Tree : System.Web.UI.MasterPage { TreeBasePage _bp = null; ITreePage _it = null; protected override void OnInit(EventArgs e) { _bp = this.Page as TreeBasePage; _it = this.Page as ITreePage; //时间 _bp._searchDate = _bp.GetString("dt"); if (_bp._searchDate == "") { _bp._filterDate = DateTime.Now; _bp._searchDate = _bp._filterDate.ToString("yyyy-MM-dd"); } else _bp._filterDate = Convert.ToDateTime(_bp._searchDate); if (!IsPostBack) { if (!_bp.CheckRights()) return; if (!_bp._selfCheckPermission) { //权限 if (!InitPermission()) return; } //_bp.leftWidth m_tree_div.Attributes.Add("Width", _bp.leftWidth.ToString()); m_tree_div.Attributes.Add("MaxWidth", (_bp.leftWidth+100).ToString()); //加载树形数据 InitTree(_it.GetTreeData()); } string path = CommonHelper.GetPrePath(); StringBuilder str = new StringBuilder(); str.AppendFormat("", path, BasePage.SiteVer); str.AppendFormat("", path, BasePage.SiteVer); str.AppendFormat("", path, BasePage.SiteVer); Literal lt = new Literal(); lt.Text = str.ToString(); Page.Header.Controls.AddAt(1, lt); base.OnInit(e); } protected void Page_Load(object sender, EventArgs e) { m_tree_div.Attributes.Add("title", _bp.TreeTitle); filterPanel.Visible = _bp._showFilter; if (!IsPostBack) { hDate.Value = _bp._searchDate; initSearch(_bp._searchFilter); //keyPlace.Visible = _bp._keyFilterVisible; if (_bp.TreeSelValue != null) _bp._script.AppendFormat("treeSel=\"{0}\";", _bp.TreeSelValue); if(_bp._script.Length>0) litScript.Text = ""; } } private void initSearch(string filter) { if (filter == "") return; string[] sArr = filter.Split(','); StringBuilder str = new StringBuilder(); switch (_bp._searchDateEnum) { case SearchDateEnum.OneDay: { str.AppendLine("日期:"); break; } case SearchDateEnum.OneMonth: { str.AppendLine("日期:"); break; } default: { str.AppendLine("日期:"); str.AppendLine("- "); break; } } str.AppendLine(""); for (int i = 0; i < sArr.Length; i++) { str.AppendLine("  " + sArr[i] + ""); } str.AppendLine(""); litSearch.Text = str.ToString(); } // 初始化树 private void InitTree(object tree) { if (tree == null) { m_tree_div.Visible = false; return; } StringBuilder str = new StringBuilder(); string tId = Request.QueryString["tId"]; if (!string.IsNullOrEmpty(tId)) _bp.TreeSelValue = tId; if (tree.ToString()!="")str.AppendFormat("treeData={0};", tree); _bp.AppendScript(str.ToString()); } #region 初始化权限 private bool InitPermission() { if (_bp.PmTag == "") { _bp.ShowError("您当前没有权限查看该页面"); return false; } DataTable dt = WebUser.GetPermission(_bp.PKey); System.Data.DataView dv = new System.Data.DataView(dt); dv.RowFilter = string.Format("tag='{0}' or tag like '{0}_%'", _bp.PmTag); if (dv.Count < 1) { _bp.ShowError("您当前没有权限查看该页面"); return false; } string tag; StringBuilder str = new StringBuilder(); int i = 0; foreach (DataRowView drv in dv) { tag = drv["Tag"].ToString(); if (tag.IndexOf("_") == -1) continue; tag = tag.Replace(_bp.PmTag + "_", ""); _bp._permissions.Add(tag);//加入权限 if (tag == "view") continue; str.Append((i > 0 ? "|" : "") + tag + "," + drv["Name"]); i++; } if (str.Length > 0) _bp.AppendScript("actionData=\"" + str.ToString() + "\";"); return true; } #endregion }