GetPurview.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. using BizCom;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Web;
  9. namespace SiteCore.Handler
  10. {
  11. public class GetPurview : BaseHandler, IHttpHandler
  12. {
  13. static string staffJson = "\"state\":\"open\",\"attributes\" : <\"id\" : \"{0}\" >,\"data\" : <\"title\" : \"{1}\",http://localhost:14900/Handler/GetCaptchaImage.ashx?6.71640579441537\"attributes\" : < \"href\" : \"javascript:void(0);\" > >,\"children\" : [{2}]";
  14. static string json = "\"attributes\" : <\"id\" : \"{0}\" >,\"data\" : <\"title\" : \"{1}\",\"attributes\" : < \"href\" : \"javascript:void(0);\" > >,\"children\" : [{2}]";
  15. private string key = "ID";
  16. public void ProcessRequest(HttpContext context)
  17. {
  18. context.Response.ContentType = "application/jason";
  19. if (context.Request.QueryString["type"] != null)
  20. {
  21. string sType = context.Request.QueryString["type"].ToLower();
  22. if (context.Request.QueryString["type"] != null)
  23. {
  24. DataTable dt = null;
  25. switch (sType)
  26. {
  27. case "xmodular":
  28. {
  29. dt = XModular.GetModular();
  30. GetResource(new DataView(dt), "系统模块");
  31. break;
  32. }
  33. case "xpms":
  34. {
  35. if (UrlParmsCheck("oId"))
  36. {
  37. string oId = GetString("oId");
  38. dt = XPermission.GetPermission(oId);
  39. IList<string> list = new List<string>();
  40. foreach (DataRow dr in dt.Rows)
  41. {
  42. list.Add(dr["ID"].ToString());
  43. }
  44. ReturnJsonMsg("success", string.Join(",", list.ToArray()));
  45. return;
  46. }
  47. ReturnJsonMsg("success", "");
  48. break;
  49. }
  50. //case "app_org_pms":
  51. // {
  52. // if (UrlParmsCheck("oId"))
  53. // {
  54. // string oId = GetString("oId");
  55. // dt = CeErpAppPermission.GetPermission("0", oId);
  56. // IList<string> list = new List<string>();
  57. // foreach (DataRow dr in dt.Rows)
  58. // {
  59. // list.Add(dr["ID"].ToString());
  60. // }
  61. // ReturnJsonMsg("success", string.Join(",", list.ToArray()));
  62. // return;
  63. // }
  64. // ReturnJsonMsg("success", "");
  65. // break;
  66. // }
  67. //case "app_org_post":
  68. // {
  69. // if (UrlParmsCheck("oId,pId"))
  70. // {
  71. // string oId = GetString("oId");
  72. // string pId = GetString("pId");
  73. // StringBuilder sql = new StringBuilder();
  74. // sql.AppendFormat("select stuff((select ','+convert(varchar,modularid) from ce_erpapppermission where orgid={0} and postID=0 FOR XML PATH('')), 1, 1, '') ;", oId);
  75. // sql.AppendFormat("select ModularID as ID from ce_erpapppermission where orgid={0} and postID={1} ;", oId, pId);
  76. // DataSet ds = CeErpPost.ExecuteDataset(sql.ToString());
  77. // DataTable pDt = ds.Tables[0];
  78. // if (pDt != null && pDt.Rows.Count > 0)
  79. // {
  80. // string pids = pDt.Rows[0][0].ToString();
  81. // DataTable mdt = getAppModular();
  82. // DataView mDv = new DataView(mdt);
  83. // mDv.RowFilter = "id in (" + pids + ")";
  84. // if (mDv.Count > 0)
  85. // {
  86. // StringBuilder str = new StringBuilder();
  87. // //DataTable nmDt = new DataView(mDv.ToTable());
  88. // string s = string.Format(json, "root", "APP权限", GetResource(new DataView(mDv.ToTable()), 0)).Replace("<", "{").Replace(">", "}");
  89. // str.Append("\"orgData\":[{" + s + ",\"state\":\"open\"" + "}],");
  90. // dt = ds.Tables[1];
  91. // IList<string> list = new List<string>();
  92. // foreach (DataRow dr in dt.Rows)
  93. // {
  94. // list.Add(dr["ID"].ToString());
  95. // }
  96. // str.AppendFormat("\"postData\":\"{0}\"", string.Join(",", list.ToArray()));
  97. // ReturnSuccess("[{" + str.ToString() + "}]");
  98. // }
  99. // }
  100. // }
  101. // break;
  102. // }
  103. case "modular":
  104. {
  105. dt = CeErpModular.GetModular();
  106. GetResource(new DataView(dt), "系统模块");
  107. break;
  108. }
  109. case "org_post":
  110. {
  111. if (UrlParmsCheck("oId,pId"))
  112. {
  113. string oId = GetString("oId");
  114. string pId = GetString("pId");
  115. StringBuilder sql = new StringBuilder();
  116. sql.AppendFormat("select * from CE_ErpModular where ID in( select ModularID from ce_erppermission where orgid=" + oId + " and postID=0) and isDel=0 order by sort asc ;");
  117. sql.AppendFormat("select ModularID as ID from view_erppermission where orgid={0} and postID={1} and isDel=0 ;", oId, pId);
  118. //sql.AppendFormat("select ID,DefaultPageModuleID as pmId,IndexPageReport as ipp from ce_erppost where id={0} ;", pId);
  119. // sql.AppendFormat("select * from view_ErpPostToIndexPage where postid={0} ;", pId);
  120. DataSet ds = CeErpPost.ExecuteDataset(sql.ToString());
  121. StringBuilder str = new StringBuilder();
  122. dt = ds.Tables[0];
  123. DataView dv = new DataView(dt);
  124. string s = string.Format(json, "root", "系统模块", GetResource(dv, 0)).Replace("<", "{").Replace(">", "}");
  125. str.Append("\"orgData\":[{" + s + ",\"state\":\"open\"" + "}],");
  126. dt = ds.Tables[1];
  127. IList<string> list = new List<string>();
  128. foreach (DataRow dr in dt.Rows)
  129. {
  130. list.Add(dr["ID"].ToString());
  131. }
  132. str.AppendFormat("\"postData\":\"{0}\"", string.Join(",", list.ToArray()));
  133. //str.AppendFormat("\"settingData\":{0}", JsonString.DataTable2AjaxJson(ds.Tables[2]));
  134. //str.AppendFormat("\"piData\":{0}", JsonString.DataTable2AjaxJson(ds.Tables[3]));
  135. ReturnSuccess("[{" + str.ToString() + "}]");
  136. }
  137. break;
  138. }
  139. case "org_modular":
  140. {
  141. if (UrlParmsCheck("oId"))
  142. {
  143. string oId = GetString("oId");
  144. dt = CeErpModular.GetOrgModular(oId);
  145. GetResource(new DataView(dt), "系统模块");
  146. }
  147. break;
  148. }
  149. case "org_pms":
  150. {
  151. if (UrlParmsCheck("oId"))
  152. {
  153. string oId = GetString("oId");
  154. dt = CeErpPermission.GetPermission("0", oId);
  155. IList<string> list = new List<string>();
  156. foreach (DataRow dr in dt.Rows)
  157. {
  158. list.Add(dr["ID"].ToString());
  159. }
  160. ReturnJsonMsg("success", string.Join(",", list.ToArray()));
  161. return;
  162. }
  163. ReturnJsonMsg("success", "");
  164. break;
  165. }
  166. case "post_pms":
  167. {
  168. if (UrlParmsCheck("pId,oId"))
  169. {
  170. string oId = GetString("oId");
  171. string pId = GetString("pId");
  172. dt = CeErpPermission.GetPermission(pId, oId);
  173. IList<string> list = new List<string>();
  174. foreach (DataRow dr in dt.Rows)
  175. {
  176. list.Add(dr["ID"].ToString());
  177. }
  178. ReturnJsonMsg("success", string.Join(",", list.ToArray()));
  179. return;
  180. }
  181. ReturnJsonMsg("success", "");
  182. break;
  183. }
  184. }
  185. }
  186. }
  187. else
  188. {
  189. //ReturnJsonMsg("error", "服务器错误");
  190. }
  191. }
  192. private void GetSimpleResource(DataView dv)
  193. {
  194. if (dv != null && dv.Count > 0)
  195. {
  196. string root = dv[0]["Name"].ToString();
  197. int id = Convert.ToInt32(dv[0]["ID"]);
  198. string str = string.Format(staffJson, id, root, GetSimpleResource(dv, id)).Replace("<", "{").Replace(">", "}");
  199. Utils.CommonHelper.ReturnSuccess("[{" + str + ",\"state\":\"open\"" + "}]");
  200. }
  201. }
  202. private string GetSimpleResource(DataView dv, int parentID)
  203. {
  204. dv.RowFilter = "ParentID=" + parentID;
  205. if (dv.Count > 0)
  206. {
  207. ArrayList arrayList = new ArrayList();
  208. foreach (DataRowView drv in dv)
  209. {
  210. string tmp = string.Format(staffJson, drv[key], drv["Name"], GetResource(dv, Convert.ToInt32(drv["ID"])));//.Replace("<", "{").Replace(">", "}");
  211. arrayList.Add("{" + tmp + "}");
  212. }
  213. string[] tArr = (string[])arrayList.ToArray(typeof(string));
  214. return string.Join(",", tArr);
  215. }
  216. else
  217. {
  218. return "";
  219. }
  220. }
  221. private void GetResource(DataView dv, string rootName)
  222. {
  223. if (dv != null && dv.Count > 0)
  224. {
  225. string str = string.Format(json, "root", rootName, GetResource(dv, 0)).Replace("<", "{").Replace(">", "}");
  226. //string str = GetResource(dv, 0);
  227. Utils.CommonHelper.ReturnSuccess("[{" + str + ",\"state\":\"open\"" + "}]");
  228. }
  229. }
  230. //获取系统模块
  231. private string GetResource(DataView dv, int parentID)
  232. {
  233. dv.RowFilter = "ParentID=" + parentID;
  234. if (dv.Count > 0)
  235. {
  236. ArrayList arrayList = new ArrayList();
  237. foreach (DataRowView drv in dv)
  238. {
  239. string tmp = string.Format(json, drv[key], drv["Name"], GetResource(dv, Convert.ToInt32(drv["ID"])));//.Replace("<", "{").Replace(">", "}");
  240. arrayList.Add("{" + tmp + "}");
  241. }
  242. string[] tArr = (string[])arrayList.ToArray(typeof(string));
  243. return string.Join(",", tArr);
  244. }
  245. else
  246. {
  247. return "";
  248. }
  249. }
  250. }
  251. }