PageRenderTime 61ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/AKDOA28/ZX.Web.UI.Controls/UserControl/TreeView.cs

#
C# | 671 lines | 563 code | 60 blank | 48 comment | 107 complexity | 3efd04371fd9020ad4f33259fb1f1b17 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, Apache-2.0, GPL-2.0, BSD-3-Clause, LGPL-2.0, MIT, GPL-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ZX.BLL.Extend;
  6. using ZX.DBModule;
  7. using System.Web.UI.WebControls;
  8. using System.ComponentModel;
  9. namespace ZX.Web.UI.Controls
  10. {
  11. public class TreeView : Literal
  12. {
  13. private string _tableName = "";
  14. [Description("数据来源的表名")]
  15. public string TableName
  16. {
  17. get { return _tableName; }
  18. set { _tableName = value; }
  19. }
  20. private string _caption = "";
  21. [Description("文本")]
  22. public string Caption
  23. {
  24. get { return _caption; }
  25. set { _caption = value; }
  26. }
  27. [Description("长名称")]
  28. public string LCaption
  29. {
  30. get;
  31. set;
  32. }
  33. private string _key = "";
  34. [Description("主键")]
  35. public string Key
  36. {
  37. get { return _key; }
  38. set { _key = value; }
  39. }
  40. private string _parentKey = "";
  41. [Description("父节点主键")]
  42. public string ParentKey
  43. {
  44. get { return _parentKey; }
  45. set { _parentKey = value; }
  46. }
  47. private string _path = "";
  48. [Description("节点路径")]
  49. public string path
  50. {
  51. get { return _path; }
  52. set { _path = value; }
  53. }
  54. private bool _isAllowCheck = false;
  55. [Description("是否允许多选")]
  56. public bool AllowCheck
  57. {
  58. get { return _isAllowCheck; }
  59. set { _isAllowCheck = value; }
  60. }
  61. private int _IsOutDepartment = 0;
  62. [Description("组织架构类型")]
  63. public int IsOutDepartment
  64. {
  65. get { return _IsOutDepartment; }
  66. set { _IsOutDepartment = value; }
  67. }
  68. private Guid _userID = Guid.Empty;
  69. [Description("外部人员ID")]
  70. public Guid userID
  71. {
  72. get { return _userID; }
  73. set { _userID = value; }
  74. }
  75. private int _IsVirtual=0;
  76. [Description("是否虚拟部门")]
  77. public int IsVirtual
  78. {
  79. get { return _IsVirtual; }
  80. set { _IsVirtual = value; }
  81. }
  82. private string _Condition = "";
  83. [Description("自定义查询条件")]
  84. public string Condition
  85. {
  86. get { return _Condition; }
  87. set { _Condition = value; }
  88. }
  89. /// <summary>
  90. /// 实体类
  91. /// </summary>
  92. public string Entity
  93. {
  94. get
  95. {
  96. return ParentPage.GetStringFromQueryString("entity", "");
  97. }
  98. }
  99. /// <summary>
  100. ///
  101. /// </summary>
  102. public Guid FunctionID
  103. {
  104. get
  105. {
  106. return ParentPage.GetGuidFromQueryString("functionid");
  107. }
  108. }
  109. /// <summary>
  110. ///
  111. /// </summary>
  112. public BasePage ParentPage
  113. {
  114. get
  115. {
  116. return this.Page as BasePage;
  117. }
  118. }
  119. public string DeptPath(IList<TreeViewData> list)
  120. {
  121. IList<ZX.EHR.Library.SysRoleFunction> list1 = (new ZX.BLL.BUser()).GetRoleFunction((this.Page as BasePage).UserId, this.FunctionID);
  122. if (list1.Count == 0)
  123. return "@001";
  124. else
  125. {
  126. int deptType = 0;
  127. var _DeptID = ParentPage.EmpPropertyValues.DeptID;
  128. var dept = list.Where(p => p.Key.ToString() == _DeptID).First();
  129. IList<TreeViewData> _list = list.Where(p => dept.LCaption.Contains(p.LCaption)).ToList();
  130. return _list.Where(p => p.DeptType == 0).ToList()[0].Path;
  131. }
  132. //return "@001";
  133. }
  134. public void GetDeptType(out int deptType, int rangeType)
  135. {
  136. switch (rangeType)
  137. {
  138. case 0: //本人
  139. deptType = 0;
  140. break;
  141. case 1://本部门
  142. deptType = 1;
  143. break;
  144. case 2://
  145. deptType = 2;
  146. break;
  147. case 3:
  148. deptType = 3;
  149. break;
  150. }
  151. deptType = 4;
  152. }
  153. /// <summary>
  154. /// 获取部门过滤条件
  155. /// </summary>
  156. /// <returns></returns>
  157. public string GetDeptCondition()
  158. {
  159. IList<ZX.EHR.Library.SysRoleFunction> list = (new ZX.BLL.BUser()).GetRoleFunction(this.ParentPage.UserId, this.FunctionID);
  160. string condition = "";
  161. foreach (var e in list)
  162. {
  163. if (e.OperateRangeType == "" || e.OperateRangeType=="2")//全部
  164. {
  165. condition =condition ==""?"1=1": " or 1=1";
  166. }
  167. if (e.OperateRangeType.Trim() == "1")//本部门
  168. {
  169. ZX.EHR.Library.DatDepartment dept = this.ParentPage._bll.GetEntityBySqlComm<ZX.EHR.Library.DatDepartment>(string.Format("select * from DatDepartment where DeptID = '{0}'", this.ParentPage.EmpPropertyValues.DeptID));
  170. condition =(condition==""?"":" or ") + "DeptPath like '" + dept.DeptPath + "%'"; ;
  171. }
  172. if (e.OperateRangeType.Trim() == "5") //本大区
  173. {
  174. ZX.EHR.Library.DatDepartment dept = this.ParentPage._bll.GetEntityBySqlComm<ZX.EHR.Library.DatDepartment>(string.Format("exec sp_getDeptPath '{0}','{1}'",
  175. this.ParentPage.EmpPropertyValues.DeptID,
  176. 5));
  177. condition =(condition==""?"":" or ") + "DeptPath like '" + dept.DeptPath + "%'"; ;
  178. }
  179. if (e.OperateRangeType.Trim() == "6")//本分公司
  180. {
  181. ZX.EHR.Library.DatDepartment dept = this.ParentPage._bll.GetEntityBySqlComm<ZX.EHR.Library.DatDepartment>(string.Format("exec sp_getDeptPath '{0}','{1}'",
  182. this.ParentPage.EmpPropertyValues.DeptID,
  183. 1));
  184. condition = (condition == "" ? "" : " or ") + "DeptPath like '" + dept.DeptPath + "%'"; ;
  185. }
  186. if (e.OperateRangeType.Trim() == "7")//本中心
  187. {
  188. ZX.EHR.Library.DatDepartment dept = this.ParentPage._bll.GetEntityBySqlComm<ZX.EHR.Library.DatDepartment>(string.Format("exec sp_getDeptPath '{0}','{1}'",
  189. this.ParentPage.EmpPropertyValues.DeptID,
  190. 4));
  191. condition = (condition == "" ? "" : " or ") + "DeptPath like '" + dept.DeptPath + "%'"; ;
  192. }
  193. if (e.OperateRangeType.Trim() == "3")//自定义部门
  194. {
  195. condition = (condition == "" ? "" : " or ") + "'" + e.Depts + "' like '%'+ Cast(DeptID as varchar(38)) + '%'";
  196. }
  197. }
  198. return condition;
  199. }
  200. private string CreateOrgData(string DeptPath, IList<TreeViewData> list)
  201. {
  202. StringBuilder _orgString = new StringBuilder();
  203. IList<TreeViewData> rootlist = list.Where(p => p.Path.Contains(DeptPath)==true && p.Path!=DeptPath).ToList();
  204. if (rootlist == null)
  205. {
  206. return _orgString.ToString();
  207. }
  208. else
  209. {
  210. TreeViewData tv = list.Where(p => p.Path == DeptPath).First();
  211. IList<TreeViewData> _rootlist = rootlist.Where(p => p.ParentKey == tv.Key).ToList();
  212. _orgString.Append("<li>\r\n");
  213. _orgString.Append(tv.Caption);
  214. if (_rootlist == null)
  215. {
  216. return _orgString.ToString();
  217. }
  218. else
  219. {
  220. _orgString.Append("<ul>\r\n");
  221. foreach (var _tv in _rootlist)
  222. {
  223. _orgString.Append(CreateOrgData(_tv.Path,list));
  224. }
  225. _orgString.Append("</ul>\r\n");
  226. }
  227. _orgString.Append("</li>\r\n");
  228. return _orgString.ToString();
  229. //throw new Exception(_orgString.ToString());
  230. //IList<TreeViewData> rootlist
  231. }
  232. }
  233. private string CreateOrgData()
  234. {
  235. string sql = "select DeptID as [key],dept.DeptName as Caption,b.deptname as LCaption,ParentID as ParentKey,DeptPath as [Path],DeptType from DatDepartment dept,dbo.fn_GetOrganizeAll('333FE8ED-CA2A-497A-A88C-3BB4FB3A1A57') b where (IsVirtualDepartment<>1 or IsVirtualDepartment is null) and ([ExpireDate]>=getdate() or [ExpireDate]='1900-01-01 00:00:00.000') and dept.DeptID=b.id";
  236. sql = string.Format(sql, DateTime.Now.ToLongTimeString());
  237. IList<TreeViewData> list = new EnttityBLL().GetEntitysBySqlComm<TreeViewData>(sql);
  238. System.Guid DeptID = (this.Page as BasePage).GetGuidFromQueryString("deptID");
  239. var data = list.Where(p => p.Key == DeptID);
  240. if (data.Count() == 0)
  241. {
  242. return CreateOrgData("@001", list);
  243. }
  244. return CreateOrgData(data.First().Path, list);
  245. }
  246. //private string
  247. private string createTree(string DeptPath, IList<TreeViewData> list)
  248. {
  249. StringBuilder _strHtml = new StringBuilder();
  250. string sql = "";
  251. if (AllowCheck)
  252. _strHtml.Append("<div id='" + this.ID + "' class='whitebg ygtv-checkbox'>");
  253. else
  254. _strHtml.Append("<div id='" + this.ID + "' class='whitebg'>");
  255. _strHtml.Append("<ul>");
  256. //得到一级菜单
  257. //IList<TreeViewData> rootlist = list.Where(p => p.Path.Split('-').Length == 2).OrderBy(p => p.Path).ToList();
  258. IList<TreeViewData> rootlist = null;
  259. //判断是否是外部机构的用户
  260. //sql="select * from datdepartment where deptid in (select deptid from TrCustomer where TrCustomerID='"+userID+"')";
  261. rootlist = list.Where(p => p.Path == DeptPath).OrderBy(p => p.Path).ToList();
  262. int i = 0;
  263. if (rootlist != null)
  264. {
  265. foreach (TreeViewData tree in rootlist)
  266. {
  267. _strHtml.Append("<li>");
  268. if (!AllowCheck)
  269. {
  270. _strHtml.Append("<span><a href=\"#" + tree.Key + "\" style='display:block;cursor:hand' onclick=\"Native('" + tree.Caption + "','" + tree.Key + "','" + tree.DeptType + "')\">" + tree.Caption + "</a></span>");
  271. }
  272. else
  273. {
  274. _strHtml.Append("<a href='#@" + tree.Key + "'>" + tree.Caption + "</a>");
  275. }
  276. //功能明细
  277. AddNode(list, tree.Key, _strHtml);
  278. _strHtml.Append("</li>");
  279. i++;
  280. }
  281. }
  282. else
  283. {
  284. _strHtml.Append("<li>权限不足或数据不存在</li>");
  285. }
  286. _strHtml.Append("</ul>");
  287. _strHtml.Append("</div>");
  288. return _strHtml.ToString();
  289. }
  290. private string CreateDeptTree(bool IsShowSub)
  291. {
  292. string sql = "select DeptID as [key],dept.DeptName as Caption,b.deptname as LCaption,ParentID as ParentKey,DeptPath as [Path],DeptType from DatDepartment dept,dbo.fn_GetOrganizeAll('333FE8ED-CA2A-497A-A88C-3BB4FB3A1A57') b where (IsVirtualDepartment<>1 or IsVirtualDepartment is null) and ([ExpireDate]>=getdate() or [ExpireDate]='1900-01-01 00:00:00.000') and dept.DeptID=b.id";
  293. sql = string.Format(sql, DateTime.Now.ToLongTimeString());
  294. IList<TreeViewData> list = new EnttityBLL().GetEntitysBySqlComm<TreeViewData>(sql);
  295. if (IsShowSub)
  296. {
  297. string deptPath = "@001";
  298. //
  299. //System.Data.DataRow row =(this.Page as BasePage).User.GetEmployeePostDept();
  300. //if (row == null)
  301. //{
  302. // //deptPath = "";
  303. // return createTree("001", list);
  304. //}
  305. //deptPath=row["DeptPath"].ToString();
  306. System.Data.DataTable dt = (this.Page as BasePage).User.GetUserPostDept();
  307. StringBuilder _treeHtml = new StringBuilder("");
  308. if (dt == null)
  309. {
  310. return createTree("001", list);
  311. }
  312. else
  313. {
  314. foreach (System.Data.DataRow row in dt.Rows)
  315. {
  316. deptPath = row["DeptPath"].ToString();
  317. string treeTag = createTree(deptPath, list).ToString().Replace("<div id='treeDiv1' class='whitebg ygtv-highlight'>", "").Replace("<div id='treeDiv1' class='whitebg'>", "").Replace("</div>", "");
  318. treeTag = treeTag.Remove(0, 4);
  319. treeTag = treeTag.Remove(treeTag.Length - 5, 5);
  320. _treeHtml.Append(treeTag);
  321. }
  322. }
  323. return "<div id='treeDiv1' class='whitebg'><ul>" + (_treeHtml) + "</ul></div>";
  324. }
  325. else
  326. {
  327. return CreateDeptTree();
  328. }
  329. }
  330. private string CreateDeptTree()
  331. {
  332. string sql = "select DeptID as [key],dept.DeptName as Caption,b.deptname as LCaption,ParentID as ParentKey,DeptPath as [Path],DeptType from DatDepartment dept,dbo.fn_GetOrganizeAll('333FE8ED-CA2A-497A-A88C-3BB4FB3A1A57') b where (IsVirtualDepartment<>1 or IsVirtualDepartment is null) and ([ExpireDate]>=getdate() or [ExpireDate]='1900-01-01 00:00:00.000') and dept.DeptID=b.id";
  333. sql = string.Format(sql, DateTime.Now.ToLongTimeString());
  334. IList<TreeViewData> list = new EnttityBLL().GetEntitysBySqlComm<TreeViewData>(sql);
  335. //只需要显示部门树支的实体
  336. List<string> lstMyDeptEntity = new List<string>() { "V_xzEmpGJJ", "V_xzEmpGJJDeptTotal", "V_wkProjectWorkResult","V_salEmployeeSalaryResult" };
  337. //菜单里配置参数是否只需要显示部门树支的实体
  338. bool isOnlyDisplayDept = false;
  339. if (ParentPage.GetStringFromQueryString("isOnlyDisplayDept", "false") == "true")
  340. {
  341. isOnlyDisplayDept = true;
  342. }
  343. string deptPath = "@001";
  344. //配置只显示登录者所属部门的树状,或固定部门分支
  345. if ((this.Entity.IndexOf("Employee") > 0 || this.Entity.IndexOf("Department") > 0 || this.Entity.IndexOf("Post") > 0 || lstMyDeptEntity.Contains(this.Entity) || isOnlyDisplayDept) && this.FunctionID != Guid.Empty)
  346. {
  347. var _DeptID = ParentPage.EmpPropertyValues.DeptID;
  348. var dept = list.Where(p => p.Key.ToString() == _DeptID).First();
  349. //咨询中心考勤列表固定显示咨询中心分支树状
  350. if (this.Entity == "V_wkProjectWorkResult")
  351. {
  352. dept = list.Where(p => p.Caption.ToString().Trim() == "咨询中心").First();
  353. deptPath = dept.Path;
  354. }
  355. else
  356. {
  357. if (dept.LCaption.IndexOf("学校") > 0 || dept.LCaption.IndexOf("分公司") > 0 || dept.LCaption.IndexOf("推广中心") > 0 || dept.LCaption.IndexOf("咨询中心") > 0)
  358. {
  359. string[] _strDept = dept.LCaption.Replace("->", "_").Split('_');
  360. string[] _strPath = dept.Path.Replace("->", "_").Split('-');
  361. for (int i = 0; i < _strDept.Length; i++)
  362. {
  363. if (_strDept[i].IndexOf("分公司") >= 0 || _strDept[i].IndexOf("推广中心") >= 0 || _strDept[i].IndexOf("学校") >= 0 || _strDept[i].IndexOf("咨询中心") >= 0)
  364. {
  365. deptPath += "-" + _strPath[i];
  366. break;
  367. }
  368. if (i > 0)
  369. {
  370. deptPath += "-" + _strPath[i];
  371. }
  372. }
  373. }
  374. }
  375. }
  376. //(this.Page as BasePage).EmpPropertyValues.DeptID
  377. return createTree(deptPath, list);
  378. }
  379. protected override void Render(System.Web.UI.HtmlTextWriter writer)
  380. {
  381. if (!DesignMode )
  382. {
  383. if (this.ParentPage.GetStringFromQueryString("showOrg", "false") == "true")
  384. {
  385. writer.Write(CreateOrgData());
  386. //return;
  387. }
  388. else
  389. {
  390. if (this.ParentPage.GetStringFromQueryString("right", "N") == "Y")
  391. {
  392. createRightTree(writer);
  393. }
  394. else
  395. {
  396. createTree(writer);
  397. }
  398. }
  399. }
  400. else
  401. {
  402. writer.Write("树型菜单");
  403. }
  404. }
  405. private void createRightTree(System.Web.UI.HtmlTextWriter writer)
  406. {
  407. //只需要显示本部门树支
  408. string sql = "";
  409. IList<TreeViewData> list = null;
  410. StringBuilder sbChilds = new StringBuilder();
  411. StringBuilder _strHtml = new StringBuilder();
  412. _strHtml.Append("<div id='" + this.ID + "' class='whitebg'>");
  413. _strHtml.Append("<ul>");
  414. IList<TreeViewData> rootlist = null;
  415. //sql="select * from datdepartment where deptid in (select deptid from TrCustomer where TrCustomerID='"+userID+"')";
  416. sql = "select DeptID as [Key],ParentID as ParentKey,DeptName as Caption,DeptPath as [path],LDeptName as LCaption,DeptType from datdepartment where (IsVirtualDepartment<>1 or IsVirtualDepartment is null) and ([ExpireDate]>=getdate() or [ExpireDate]='1900-01-01 00:00:00.000') and " + GetDeptCondition();
  417. list = new EnttityBLL().GetEntitysBySqlComm<TreeViewData>(sql).OrderBy(p => p.Path).ToList();
  418. if(list != null){
  419. sql = @"select * from (select DeptID as [Key],ParentID as ParentKey,DeptName as Caption,DeptPath as [path],LDeptName as LCaption,DeptType from datdepartment where (IsVirtualDepartment<>1 or IsVirtualDepartment is null) and ([ExpireDate]>=getdate() or [ExpireDate]='1900-01-01 00:00:00.000') and {0})
  420. a
  421. where a.ParentKey not in (select DeptID as [Key] from datdepartment where (IsVirtualDepartment<>1 or IsVirtualDepartment is null) and ([ExpireDate]>=getdate() or [ExpireDate]='1900-01-01 00:00:00.000') and {0})";
  422. sql = string.Format(sql, GetDeptCondition());
  423. rootlist = new EnttityBLL().GetEntitysBySqlComm<TreeViewData>(sql).OrderBy(p => p.Path).ToList(); ;
  424. }
  425. int i = 0;
  426. if (rootlist != null)
  427. {
  428. foreach (TreeViewData tree in rootlist)
  429. {
  430. _strHtml.Append("<li>");
  431. if (!AllowCheck)
  432. {
  433. _strHtml.Append("<span><a href=\"#" + tree.Key + "\" style='display:block;cursor:hand' onclick=\"Native('" + tree.Caption + "','" + tree.Key + "')\">" + tree.Caption + "</a></span>");
  434. }
  435. else
  436. {
  437. _strHtml.Append("<a href='#@" + tree.Key + "'>" + tree.Caption + "</a>");
  438. }
  439. //功能明细
  440. AddNode(list, tree.Key, _strHtml);
  441. _strHtml.Append("</li>");
  442. i++;
  443. }
  444. }
  445. else
  446. {
  447. _strHtml.Append("<li>权限不足或数据不存在</li>");
  448. }
  449. _strHtml.Append("</ul>");
  450. _strHtml.Append("</div>");
  451. writer.Write(_strHtml.ToString());
  452. base.Render(writer);
  453. }
  454. private void createTree(System.Web.UI.HtmlTextWriter writer)
  455. {
  456. //只需要显示本部门树支
  457. List<string> lstMyDeptEntity = new List<string>() { "V_wkOverTimeLeaveTotal","V_hrEmployee", "V_hrEmployeeDeparture", "V_DatPost", "DatDepartment", "V_wkWorkResult", "V_wkEmpMonthWorkResult", "V_xzEmpInsurance", "V_xzEmpInsuranceDeptTotal", "V_xzEmpGJJ", "V_xzEmpGJJDeptTotal", "V_wkConfirmWorkResult", "V_wkProjectWorkResult" };
  458. bool IsOnlyMyDept =false;
  459. if (lstMyDeptEntity.Contains(ParentPage.GetStringFromQueryString("entity", "")) || ParentPage.GetStringFromQueryString("IsOnlyMyDept", "") == "true")
  460. {
  461. IsOnlyMyDept = true;
  462. }
  463. string sql = "";
  464. IList<TreeViewData> list = null;
  465. StringBuilder sbChilds = new StringBuilder();
  466. StringBuilder _strHtml = new StringBuilder();
  467. if (AllowCheck)
  468. _strHtml.Append("<div id='" + this.ID + "' class='whitebg ygtv-checkbox'>");
  469. else
  470. _strHtml.Append("<div id='" + this.ID + "' class='whitebg'>");
  471. _strHtml.Append("<ul>");
  472. //得到一级菜单
  473. //IList<TreeViewData> rootlist = list.Where(p => p.Path.Split('-').Length == 2).OrderBy(p => p.Path).ToList();
  474. IList<TreeViewData> rootlist = null;
  475. //判断是否是外部机构的用户
  476. if (IsOutDepartment == 0)
  477. {
  478. if (IsOnlyMyDept) //只需要显示本部门树支
  479. {
  480. writer.Write(CreateDeptTree(ParentPage.GetStringFromQueryString("IsSelfHelp", "false") == "true"));
  481. base.Render(writer);
  482. return;
  483. }
  484. sql = "Exec sp_TreeView '{0}','{1}','{2}','{3}','{4}','{5}'";
  485. if (TableName.ToLower() == "datdepartment")
  486. {
  487. //Condition = GetDeptCondition();
  488. Condition =Condition ==""?"((IsVirtualDepartment<>1 or IsVirtualDepartment is null) and ([ExpireDate]>=getdate() or [ExpireDate]=''1900-01-01 00:00:00.000''))":"("+Condition+") and ((IsVirtualDepartment<>1 or IsVirtualDepartment is null) and ([ExpireDate]>=getdate() or [ExpireDate]=''1900-01-01 00:00:00.000''))";
  489. }
  490. sql = string.Format(sql, TableName, Key, Caption, ParentKey, path, Condition);
  491. list = new EnttityBLL().GetEntitysBySqlComm<TreeViewData>(sql);
  492. if (list != null)
  493. {
  494. rootlist = list.Where(p => p.Path == "@001").OrderBy(p => p.Path).ToList();
  495. if (rootlist.Count == 0)
  496. {
  497. rootlist = list.Where(p => p.ParentKey == Guid.Empty || p.ParentKey == null).OrderBy(p => p.Caption).ToList();
  498. }
  499. }
  500. }
  501. else if (IsVirtual == 1)
  502. {
  503. sql = "Exec sp_TreeView '{0}','{1}','{2}','{3}','{4}','IsVirtualDepartment=1'";
  504. sql = string.Format(sql, TableName, Key, Caption, ParentKey, path);
  505. list = new EnttityBLL().GetEntitysBySqlComm<TreeViewData>(sql);
  506. rootlist = list.Where(p => p.Path == "@002").OrderBy(p => p.Path).ToList();
  507. }
  508. else
  509. {
  510. //sql="select * from datdepartment where deptid in (select deptid from TrCustomer where TrCustomerID='"+userID+"')";
  511. sql = "select *,LDeptName as LCaption from datdepartment where (IsVirtualDepartment<>1 or IsVirtualDepartment is null)";
  512. list = new EnttityBLL().GetEntitysBySqlComm<TreeViewData>(sql);
  513. rootlist = list.Where(p => p.Path.Split('-').Length == 2 && (!p.Path.Contains("@001"))).OrderBy(p => p.Path).ToList();
  514. }
  515. int i = 0;
  516. if (rootlist != null)
  517. {
  518. foreach (TreeViewData tree in rootlist)
  519. {
  520. _strHtml.Append("<li>");
  521. if (!AllowCheck)
  522. {
  523. _strHtml.Append("<span><a href=\"#" + tree.Key + "\" style='display:block;cursor:hand' onclick=\"Native('" + tree.Caption + "','" + tree.Key + "')\">" + tree.Caption + "</a></span>");
  524. }
  525. else
  526. {
  527. _strHtml.Append("<a href='#@" + tree.Key + "'>" + tree.Caption + "</a>");
  528. }
  529. //功能明细
  530. AddNode(list, tree.Key, _strHtml);
  531. _strHtml.Append("</li>");
  532. i++;
  533. }
  534. }
  535. else
  536. {
  537. _strHtml.Append("<li>权限不足或数据不存在</li>");
  538. }
  539. _strHtml.Append("</ul>");
  540. _strHtml.Append("</div>");
  541. writer.Write(_strHtml.ToString());
  542. base.Render(writer);
  543. }
  544. private void AddNode(IList<TreeViewData> list, Guid? key,StringBuilder sb)
  545. {
  546. var detail = list.Where(p => p.ParentKey == key).OrderBy(p => p.Path).ToList();
  547. if (detail.ToList().Count > 0)
  548. {
  549. sb.Append("<ul>");
  550. foreach (TreeViewData v in detail)
  551. {
  552. sb.Append("<li>");
  553. if (!AllowCheck)
  554. {
  555. sb.Append("<span><a href=\"#" + v.Key + "\" style='display:block;cursor:hand' onclick=\"Native('" + v.Caption + "','" + v.Key + "','" + v.DeptType + "')\">" + v.Caption + "</a></span>");
  556. }
  557. else
  558. {
  559. sb.Append("<a href='#@" + v.Key + "'>" + v.Caption + "</a>");
  560. }
  561. AddNode(list, v.Key, sb);
  562. sb.Append("</li>");
  563. }
  564. sb.Append("</ul>");
  565. }
  566. //childName += "</ul>";
  567. }
  568. public string createTreeHtml(string xDeptPath)
  569. {
  570. IList<TreeViewData> list = null;
  571. IList<TreeViewData> rootlist = null;
  572. StringBuilder sbChilds = new StringBuilder();
  573. StringBuilder _strHtml = new StringBuilder();
  574. string DeptPath = xDeptPath;//"@001-001";
  575. string sql = "select DeptID as [key],DeptName as Caption,LDeptName as LCaption,ParentID as ParentKey,DeptPath as [Path],DeptType from datdepartment where (isvirtualdepartment=0 or isvirtualdepartment is null) and (isoutdepartment=0 or isoutdepartment is null)";
  576. list = new EnttityBLL().GetEntitysBySqlComm<TreeViewData>(sql);
  577. rootlist = list.Where(p => p.Path == DeptPath).OrderBy(p => p.Path).ToList();
  578. int i = 0;
  579. if (rootlist != null)
  580. {
  581. foreach (TreeViewData tree in rootlist)
  582. {
  583. _strHtml.Append("<ul id=\"test_tree_list\"><li>");
  584. _strHtml.Append(tree.Caption);
  585. //功能明细
  586. AddNodeHtml(list, tree.Key, _strHtml);
  587. _strHtml.Append("</ul>");
  588. i++;
  589. }
  590. }
  591. return _strHtml.ToString();
  592. }
  593. private void AddNodeHtml(IList<TreeViewData> list, Guid? key, StringBuilder sb)
  594. {
  595. var detail = list.Where(p => p.ParentKey == key).OrderBy(p => p.Path).ToList();
  596. if (detail.ToList().Count > 0)
  597. {
  598. sb.Append("<ul>");
  599. sb.Append("<li></li>");
  600. foreach (TreeViewData v in detail)
  601. {
  602. sb.Append("<li>");
  603. sb.Append( v.Caption );
  604. AddNodeHtml(list, v.Key, sb);
  605. sb.Append("</li>");
  606. }
  607. sb.Append("</ul>");
  608. }
  609. }
  610. }
  611. }