PowerUI.aspx.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. using SysBaseLibs;
  2. using SysDataLibs;
  3. using SysDataLibs.TableClass;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Web;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. namespace GSMarketSys.SystemModule
  12. {
  13. public partial class PowerUI : System.Web.UI.Page
  14. {
  15. UserSession _UserSession;
  16. private DataSet objPowerDs;
  17. private string userID;
  18. private string groupID;
  19. private string as_UserTypeA;
  20. private string ErrCode;
  21. protected void Page_Load(object sender, EventArgs e)
  22. {
  23. _UserSession = WebLibs.CheckLogin();
  24. string PrimaryKey;
  25. as_UserTypeA = (Request["as_UserType"].Trim()).ToLower();
  26. PrimaryKey = Utils.AreaToSQLcs(((Request["PrimaryKey"]).Trim()).ToLower());
  27. if (as_UserTypeA == "")
  28. {
  29. ErrCode = "-311121";
  30. Response.Redirect("../Pub/PubShowMessage.aspx?as_ErrText=&al_ErrCode=" + ErrCode + "&as_ReturnType=C");
  31. }
  32. if (PrimaryKey == "")
  33. {
  34. ErrCode = "-311121";
  35. Response.Redirect("../Pub/PubShowMessage.aspx?as_ErrText=&al_ErrCode=" + ErrCode + "&as_ReturnType=C");
  36. }
  37. //判断操作类型
  38. if (as_UserTypeA == "user")
  39. {
  40. //Sys_Users_info loUsers = new Sys_Users_info(PrimaryKey, _UserSession.DBConn);
  41. userID = PrimaryKey;
  42. if (!IsPostBack)
  43. {
  44. UserNotPostBack();
  45. }
  46. }else if(as_UserTypeA == "group")
  47. {
  48. groupID = PrimaryKey;
  49. if (!IsPostBack)
  50. {
  51. GroupNotPostBack();
  52. }
  53. }
  54. }
  55. public string GetFunctionTree(DataGridItem dgItem)
  56. {
  57. int i = dgItem.ItemIndex;
  58. DataRowView dataRowView;
  59. string outStr;
  60. dataRowView = (DataRowView)dgItem.DataItem;
  61. outStr = "<img height=1 src='../images/space.gif' width=" + 20 * Utils.ValI(UtilStr.StrFromObj(dataRowView["Depth"])) + ">";
  62. //'设置CheckBox权限的值
  63. SetPowerCheckBox(dgItem);
  64. return outStr;
  65. }
  66. //'---设置Checkbox
  67. private void SetPowerCheckBox(DataGridItem item)
  68. {
  69. // '绑定DataGridItem
  70. CheckBox ckBox;
  71. DataRowView dataRowView;
  72. DataRowCollection objFunctionRowColl;
  73. Boolean[] HasFunctionBool = new Boolean[6];
  74. System.Web.UI.HtmlControls.HtmlInputCheckBox ckInputBox;
  75. // ' 从全局变量中取得(objPowerDs)
  76. objFunctionRowColl = objPowerDs.Tables[0].Rows;
  77. dataRowView = (DataRowView)item.DataItem;
  78. if (Utils.ObjToBool(dataRowView["IsLeaf"]))
  79. {
  80. SetHasFunctionBool(objFunctionRowColl, ref HasFunctionBool, UtilStr.StrFromObj(dataRowView["FunctionID"]));
  81. if (Utils.ObjToBool(dataRowView["IsBrowse"]))
  82. {
  83. ckBox = (CheckBox)item.FindControl("ckIsBrowse");
  84. ckBox.Checked = HasFunctionBool[0];
  85. }
  86. else
  87. {
  88. ckBox = (CheckBox)item.FindControl("ckIsBrowse");
  89. ckBox.Enabled = false;
  90. }
  91. if (Utils.ObjToBool(dataRowView["IsAdd"]))
  92. {
  93. ckBox = (CheckBox)item.FindControl("ckIsAdd");
  94. ckBox.Checked = HasFunctionBool[1];
  95. }
  96. else
  97. {
  98. ckBox = (CheckBox)item.FindControl("ckIsAdd");
  99. ckBox.Enabled = false;
  100. }
  101. if (Utils.ObjToBool(dataRowView["IsUpdate"]))
  102. {
  103. ckBox = (CheckBox)item.FindControl("ckIsUpdate");
  104. ckBox.Checked = HasFunctionBool[2];
  105. }
  106. else
  107. {
  108. ckBox = (CheckBox)item.FindControl("ckIsUpdate");
  109. ckBox.Enabled = false;
  110. }
  111. if (Utils.ObjToBool(dataRowView["IsDelete"]))
  112. {
  113. ckBox = (CheckBox)item.FindControl("ckIsDelete");
  114. ckBox.Checked = HasFunctionBool[3];
  115. }
  116. else
  117. {
  118. ckBox = (CheckBox)item.FindControl("ckIsDelete");
  119. ckBox.Enabled = false;
  120. }
  121. if (Utils.ObjToBool(dataRowView["IsPrint"]))
  122. {
  123. ckBox = (CheckBox)item.FindControl("ckIsPrint");
  124. ckBox.Checked = HasFunctionBool[4];
  125. }
  126. else
  127. {
  128. ckBox = (CheckBox)item.FindControl("ckIsPrint");
  129. ckBox.Enabled = false;
  130. }
  131. if (Utils.ObjToBool(dataRowView["IsAudit"]))
  132. {
  133. ckBox = (CheckBox)item.FindControl("ckIsOwner");
  134. ckBox.Checked = HasFunctionBool[5];
  135. }
  136. else
  137. {
  138. ckBox = (CheckBox)item.FindControl("ckIsOwner");
  139. ckBox.Enabled = false;
  140. }
  141. }
  142. else
  143. {
  144. ckInputBox = (System.Web.UI.HtmlControls.HtmlInputCheckBox)item.FindControl("ckItemAll");
  145. ckInputBox.Visible = false;
  146. ckBox = (CheckBox)item.FindControl("ckIsBrowse");
  147. ckBox.Visible = false;
  148. ckBox = (CheckBox)item.FindControl("ckIsAdd");
  149. ckBox.Visible = false;
  150. ckBox = (CheckBox)item.FindControl("ckIsUpdate");
  151. ckBox.Visible = false;
  152. ckBox = (CheckBox)item.FindControl("ckIsDelete");
  153. ckBox.Visible = false;
  154. ckBox = (CheckBox)item.FindControl("ckIsPrint");
  155. ckBox.Visible = false;
  156. ckBox = (CheckBox)item.FindControl("ckIsOwner");
  157. ckBox.Visible = false;
  158. }
  159. }
  160. //' 用户类型 非提交
  161. private void UserNotPostBack()
  162. {
  163. Sys_Users_info loUsers = new Sys_Users_info(userID, _UserSession.DBConn);
  164. //'获取用户姓名
  165. //labTitle.Text = "用户: " + loUsers.UserNo;
  166. //'设置objPowerDs值
  167. String Sql = "select uf." + Sys_UserHasFunction_info.cFunctionId + ", uf." + Sys_UserHasFunction_info.cIsBrowse + " ,uf." + Sys_UserHasFunction_info.cIsAdd + ", uf." + Sys_UserHasFunction_info.cIsUpdate + " ,uf." + Sys_UserHasFunction_info.cIsDelete + " ,uf." + Sys_UserHasFunction_info.cIsAudit + ",uf." + Sys_UserHasFunction_info.cIsPrint + " ";
  168. Sql += "from " + Tn.Sys_UserHasFunction + " as uf join " + Tn.Sys_Users + " as u on(u." + Sys_Users_info.cUserID + "=uf." + Sys_UserHasFunction_info.cUserId + ") where u." + Sys_Users_info.cUserID + "='" + userID + "'";
  169. objPowerDs = _UserSession.DBConn.OpenDataSet(Sql);
  170. if (!string.IsNullOrEmpty(ErrCode))
  171. {
  172. Response.Redirect("../Pub/PubShowMessage.aspx?as_ErrText=&al_ErrCode=" + ErrCode + "&as_ReturnType=C");
  173. }
  174. //'把数据绑定到控件"
  175. DataGridBind();
  176. }
  177. // ' 用户组类型 非提交
  178. private void GroupNotPostBack()
  179. {
  180. //Dim groupPowerDs As DataSet
  181. String sql = "select * from " + Tn.Sys_Groups + " where " + Sys_Groups_info.cGroupID + "='" + groupID + "'";
  182. //'获取用户组名称
  183. rsQuery loQuery = _UserSession.DBConn.OpenQuery(sql);
  184. if(!loQuery.IsOpened||loQuery.RecCount<1)
  185. {
  186. ErrCode = "-311131";
  187. Response.Redirect("../Pub/PubShowMessage.aspx?as_ErrText=&al_ErrCode=" +ErrCode + "&as_ReturnType=C");
  188. }
  189. loQuery.MoveFirst();
  190. labTitle.Text = "用户组: " + UtilStr.StrFromObj(loQuery.GetString(Sys_Groups_info.cNames));
  191. sql = " select uf." + Sys_GroupHasFunction_info.cFunctionID + ", uf." + Sys_GroupHasFunction_info.cIsBrowse + " ,uf." + Sys_GroupHasFunction_info.cIsAdd + ", uf." + Sys_GroupHasFunction_info.cIsUpdate + " ,uf." + Sys_GroupHasFunction_info.cIsDelete + " ,uf." + Sys_GroupHasFunction_info.cIsAudit + ",uf." + Sys_GroupHasFunction_info.cIsPrint + " ";
  192. sql += "from " + Tn.Sys_GroupHasFunction + " as uf join " + Tn.Sys_Groups + " as g on(g." + Sys_Groups_info.cGroupID + "=uf." + Sys_GroupHasFunction_info.cGroupID + ") where g." + Sys_Groups_info.cGroupID + "='" + groupID + "' ";
  193. objPowerDs = _UserSession.DBConn.OpenDataSet(sql);
  194. //'把数据绑定到控件"
  195. DataGridBind();
  196. }
  197. // '绑定DataGrid
  198. private void DataGridBind()
  199. {
  200. DataSet functionDs;
  201. String sql = " select FunctionID ,FunctionName , FatherID ,Depth,IsLeaf ,IsBrowse ,IsAdd ,IsUpdate , IsDelete ,IsAudit ,IsPrint,Sort from [Sys_Functions] where IsBack ='Y' order by Sort asc ";
  202. functionDs = _UserSession.DBConn.OpenDataSet(sql);
  203. gridPower.DataSource = functionDs.Tables[0].DefaultView;
  204. gridPower.DataBind();
  205. }
  206. private void SetHasFunctionBool(DataRowCollection drc, ref Boolean[] HasFunctionBool, String functionID)
  207. {
  208. //DataRow dRow;
  209. HasFunctionBool[0] = false;
  210. HasFunctionBool[1] = false;
  211. HasFunctionBool[2] = false;
  212. HasFunctionBool[3] = false;
  213. HasFunctionBool[4] = false;
  214. HasFunctionBool[5] = false;
  215. functionID = UtilStr.UAndT(functionID);
  216. foreach (DataRow dRow in drc)
  217. {
  218. string lcFcId = UtilStr.UAndT(dRow["FunctionID"]);
  219. if (lcFcId == functionID)
  220. {
  221. HasFunctionBool[0] = Utils.ObjToBool(dRow["IsBrowse"]);
  222. HasFunctionBool[1] = Utils.ObjToBool(dRow["IsAdd"]);
  223. HasFunctionBool[2] = Utils.ObjToBool(dRow["IsUpdate"]);
  224. HasFunctionBool[3] = Utils.ObjToBool(dRow["IsDelete"]);
  225. HasFunctionBool[4] = Utils.ObjToBool(dRow["IsPrint"]);
  226. HasFunctionBool[5] = Utils.ObjToBool(dRow["IsAudit"]);
  227. }
  228. }
  229. }
  230. protected void Button1_Click(object sender, EventArgs e)
  231. {
  232. //DataGridItem item;
  233. CheckBox ck;
  234. String functionStr = "";
  235. Boolean IsLeaf = false;
  236. String insertHeadSqlStr = "";
  237. String insertSqlStr = "";
  238. String insertTempStr = "";
  239. String deleteSqlStr = "";
  240. String FunctionColl = "";
  241. Boolean IsHasFunctionFlag;
  242. String ObjectID = "";
  243. if (as_UserTypeA == "user")
  244. {
  245. insertHeadSqlStr = " INSERT INTO " + Tn.Sys_UserHasFunction + "( " + Sys_UserHasFunction_info.cUserId + "," + Sys_UserHasFunction_info.cFunctionId + "," + Sys_UserHasFunction_info.cIsAdd + "," + Sys_UserHasFunction_info.cIsUpdate + "," + Sys_UserHasFunction_info.cIsDelete + "," + Sys_UserHasFunction_info.cIsPrint + "," + Sys_UserHasFunction_info.cIsAudit + "," + Sys_UserHasFunction_info.cIsBrowse + ") values('" + userID + "'";
  246. deleteSqlStr = " delete " + Tn.Sys_UserHasFunction + " where " + Sys_UserHasFunction_info.cUserId + "='" + userID + "' ";
  247. ObjectID = userID;
  248. }else if (as_UserTypeA == "group")
  249. {
  250. //'组
  251. insertHeadSqlStr = " insert into " + Tn.Sys_GroupHasFunction + "(" + Sys_GroupHasFunction_info.cGroupID + "," + Sys_GroupHasFunction_info.cFunctionID + "," + Sys_GroupHasFunction_info.cIsAdd + "," + Sys_GroupHasFunction_info.cIsUpdate + "," + Sys_GroupHasFunction_info.cIsDelete + "," + Sys_GroupHasFunction_info.cIsPrint + "," + Sys_GroupHasFunction_info.cIsAudit + "," + Sys_GroupHasFunction_info.cIsBrowse + ") values('" + groupID + "'";
  252. deleteSqlStr = " delete " + Tn.Sys_GroupHasFunction + " where " + Sys_GroupHasFunction_info.cGroupID + "='" + groupID + "'";
  253. ObjectID = groupID;
  254. }else
  255. {
  256. ErrCode = "-311121";
  257. Response.Redirect("../Pub/PubShowMessage.aspx?as_ErrText=&al_ErrCode=" + ErrCode + "&as_ReturnType=C");
  258. }
  259. FunctionColl = "";
  260. insertSqlStr = "";
  261. foreach (DataGridItem item in gridPower.Items)
  262. {
  263. functionStr = ((System.Web.UI.HtmlControls.HtmlInputHidden)item.FindControl("hid_FunctionID")).Value;
  264. IsLeaf = Utils.ObjToBool(((System.Web.UI.HtmlControls.HtmlInputHidden)item.FindControl("hid_IsLeaf")).Value);
  265. insertTempStr = "";
  266. insertTempStr = insertHeadSqlStr + ",'" + functionStr + "' ";
  267. IsHasFunctionFlag = false;
  268. if (IsLeaf)
  269. {
  270. ck = (CheckBox)item.FindControl("ckIsAdd");
  271. if (ck.Checked)
  272. {
  273. insertTempStr = insertTempStr + ",'Y'";
  274. IsHasFunctionFlag = true;
  275. }
  276. else
  277. {
  278. insertTempStr = insertTempStr + ",'N'";
  279. }
  280. ck = (CheckBox)item.FindControl("ckIsUpdate");
  281. if (ck.Checked)
  282. {
  283. insertTempStr = insertTempStr + ",'Y'";
  284. IsHasFunctionFlag = true;
  285. }
  286. else
  287. {
  288. insertTempStr = insertTempStr + ",'N'";
  289. }
  290. ck = (CheckBox)item.FindControl("ckIsDelete");
  291. if (ck.Checked)
  292. {
  293. insertTempStr = insertTempStr + ",'Y'";
  294. IsHasFunctionFlag = true;
  295. }
  296. else
  297. {
  298. insertTempStr = insertTempStr + ",'N'";
  299. }
  300. ck = (CheckBox)item.FindControl("ckIsPrint");
  301. if (ck.Checked)
  302. {
  303. insertTempStr = insertTempStr + ",'Y'";
  304. IsHasFunctionFlag = true;
  305. }
  306. else
  307. {
  308. insertTempStr = insertTempStr + ",'N'";
  309. }
  310. ck = (CheckBox)item.FindControl("ckIsOwner");
  311. if (ck.Checked)
  312. {
  313. insertTempStr = insertTempStr + ",'Y'";
  314. IsHasFunctionFlag = true;
  315. }
  316. else
  317. {
  318. insertTempStr = insertTempStr + ",'N'";
  319. }
  320. //'有增 删 改 打印 看自己 就有浏览权
  321. if (IsHasFunctionFlag)
  322. {
  323. insertTempStr = insertTempStr + ",'Y'";
  324. }
  325. else
  326. {
  327. ck = (CheckBox)item.FindControl("ckIsBrowse");
  328. if (ck.Checked)
  329. {
  330. insertTempStr = insertTempStr + ",'Y'";
  331. IsHasFunctionFlag = true;
  332. }
  333. else
  334. {
  335. insertTempStr = insertTempStr + ",'N'";
  336. }
  337. }
  338. if (IsHasFunctionFlag)
  339. {
  340. insertSqlStr = insertSqlStr + insertTempStr + ") ";
  341. FunctionColl = FunctionColl + "'" + functionStr + "',";
  342. }
  343. }
  344. }
  345. if (!string.IsNullOrEmpty(FunctionColl))
  346. {
  347. FunctionColl = FunctionColl.Substring(0, FunctionColl.Length - 1);
  348. }
  349. if (!Sys_Functions_info.UpdatePowerOfGroupAndUser(insertSqlStr, deleteSqlStr, FunctionColl, ObjectID, as_UserTypeA, _UserSession.DBConn))
  350. {
  351. JSComm.ShowMessage(_UserSession.DBConn.ErrorMsg);
  352. }
  353. JSComm.CloseMe();
  354. }
  355. }
  356. }