using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CY.BLL; using CY.Model; using CY.Infrastructure.Common; using System.Data; namespace CY.WebForm.Pages.personnel { //吴辉 //权限管理 public partial class FirmMenusList : BasePage { Sys_Permissions_MenuBLL bll_Sys_Permissions_MenuBLL = null; public static string treeHtml = ""; //树形参数 public static string selHtml = ""; //下拉框内容 //实例化 public FirmMenusList() { bll_Sys_Permissions_MenuBLL = new Sys_Permissions_MenuBLL(); } //页面加载 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { InitialData(); } } //提交修改 hideKeyId protected void btn_Submit_Config(object sender, EventArgs e) { Sys_Permissions_Menu m_Sys_Permissions_Menu = new Sys_Permissions_Menu(); if (this.hideKeyId.Value.ToInt32() > 0) m_Sys_Permissions_Menu = bll_Sys_Permissions_MenuBLL.SelectModelByKeyId(this.hideKeyId.Value.ToInt32()); m_Sys_Permissions_Menu.ParentId = this.selParentId.Value.ToInt32(); m_Sys_Permissions_Menu.MenuName = this.txtMenuName.Value.ToString2(); m_Sys_Permissions_Menu.MenuPath = this.txtMenuPath.Value.ToString2(); m_Sys_Permissions_Menu.OrderCode = this.txtOrderCode.Value.ToString2(); m_Sys_Permissions_Menu.IsUsed = this.selIsUsed.Value.ToBoolean2(); m_Sys_Permissions_Menu.Operator = CurrentUser.ShortName; m_Sys_Permissions_Menu.LastUpdateTime = DateTime.Now; m_Sys_Permissions_Menu.Remark = ""; //图片上传 CY.WebForm.cs.UploadCS.UpFileResult _UpFileResult2 = CY.WebForm.cs.UploadCS.Upload("fileMenuIcon", m_Sys_Permissions_Menu.MenuIcon); m_Sys_Permissions_Menu.MenuIcon = m_Sys_Permissions_Menu.MenuIcon ?? ""; if (_UpFileResult2.returnerror.Count == 0) { if (_UpFileResult2.returnfilename.Count > 0) m_Sys_Permissions_Menu.MenuIcon = _UpFileResult2.returnfilename[0].ToString2(); } else { JavaScript.MessageBox(string.Join("
", (string[])_UpFileResult2.returnerror.ToArray(typeof(string))), this); return; } if (this.hideKeyId.Value.ToInt32() > 0) bll_Sys_Permissions_MenuBLL.UpdateModel(m_Sys_Permissions_Menu); else bll_Sys_Permissions_MenuBLL.InsertModel(m_Sys_Permissions_Menu); InitialData(); } //获取遍历结果 public void InitialData() { DataTable ds = bll_Sys_Permissions_MenuBLL.SelectList(); selParentId.Items.Clear(); treeHtml = ""; selHtml = ""; if (ds != null && ds.Rows.Count > 0) { selParentId.Items.Insert(0, new ListItem("顶级菜单", "0")); GetDataByLevel(ref treeHtml, selParentId, ds, 0, 1); } treeHtml = treeHtml.Trim(','); } //遍历数据 public static void GetDataByLevel(ref string treeHtmlo, System.Web.UI.HtmlControls.HtmlSelect sel, DataTable data, int parentId, int level) { DataRow[] result = data.Select(string.Format("ParentId={0}", parentId)); int i = -1; while (++i < result.Length) { treeHtmlo = treeHtmlo + "{ id: " + result[i]["Keyid"].ToString2() + ", parentId: " + result[i]["ParentId"].ToString2() + ", name: '" + result[i]["MenuName"].ToString2() + "[" + result[i]["OrderCode"].ToString2() + "]"+ "'" + (level < 2 ? ", open: true" : "") +" },"; if (level < 4) { sel.Items.Add(new ListItem(GetSplitChar(level) + result[i]["MenuName"].ToString2(), result[i]["Keyid"].ToString2())); } GetDataByLevel(ref treeHtmlo, sel, data, result[i]["Keyid"].ToInt32().Value, level + 1); } } //获取隔位符 public static string GetSplitChar(int level) { string res =""; //level.ToString2(); for (int i = 0; i < level; i++) { res += ".."; } return res; } } }