Employee_Power.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Windows.Forms;
  7. using UAS_MES_NEW.CustomControl.DataGrid_View;
  8. using UAS_MES_NEW.DataOperate;
  9. using UAS_MES_NEW.Entity;
  10. using UAS_MES_NEW.PublicForm;
  11. using UAS_MES_NEW.PublicMethod;
  12. namespace UAS_MES_NEW.Employee
  13. {
  14. public partial class Employee_Power : Form
  15. {
  16. DataHelper dh;
  17. DataTable dt;
  18. AutoSizeFormClass asc = new AutoSizeFormClass();
  19. LogStringBuilder sql = new LogStringBuilder();
  20. Thread thread;
  21. SetLoadingWindow stw;
  22. DataTable Dbfind;
  23. ItemObject item;
  24. string[] title = new string[] { "读权限", "写权限", "删除权限", "特殊权限", "全部权限" };
  25. string[] DataPreperty = new string[] { "ugp_ifread", "ugp_ifwrite", "ugp_ifdelete", "ugp_ifspecial", "ugp_ifall" };
  26. public Employee_Power()
  27. {
  28. InitializeComponent();
  29. }
  30. public Employee_Power(string GroupCode, string GroupName)
  31. {
  32. InitializeComponent();
  33. ug_code.Text = GroupCode;
  34. sn_module.Text = GroupName;
  35. }
  36. private void 权限控制_Load(object sender, EventArgs e)
  37. {
  38. //不检测进程
  39. asc.controllInitializeSize(this);
  40. CheckForIllegalCrossThreadCalls = false;
  41. //界面加载时设置保存按钮不可见
  42. if (ug_code.Text == "")
  43. SavePower.Visible = false;
  44. dh = SystemInf.dh;
  45. ///手动插入四列含有列头勾选框的列
  46. for (int i = 0; i < title.Length; i++)
  47. {
  48. DataGridViewCheckBoxColumn dgvc = new DataGridViewCheckBoxColumn();
  49. dgvc.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
  50. dgvc.Width = 190;
  51. dgvc.Name = title[i];
  52. dgvc.DataPropertyName = DataPreperty[i];
  53. DataGridViewCheckBoxHeaderCell ch1 = new DataGridViewCheckBoxHeaderCell(GroupPowerDGV, dgvc);
  54. dgvc.HeaderCell = ch1;
  55. this.GroupPowerDGV.Columns.Insert(i + 3, dgvc);
  56. }
  57. //分组放大镜
  58. ug_code.FormName = Name;
  59. ug_code.TableName = "CS$USERGROUP";
  60. ug_code.SelectField = "ug_code # 分组编号,ug_name # 分组名称,ug_inman # 录入人,ug_indate #录入日期";
  61. ug_code.SetValueField = new string[] { "ug_code" };
  62. ug_code.DbChange += Ug_code_Dbchage;
  63. //由于需要额外添加一个全部值,需要手动添加Item
  64. dt = (DataTable)dh.ExecuteSql("select DISTINCT sn_module from CS$SYSNAVATION where sn_using=1", "select");
  65. item = new ItemObject("全部", "");
  66. sn_module.Items.Add(item);
  67. for (int i = 0; i < dt.Rows.Count; i++)
  68. {
  69. string sn_moudle = dt.Rows[i]["sn_module"].ToString();
  70. item = new ItemObject(sn_moudle, sn_moudle);
  71. sn_module.Items.Add(item);
  72. }
  73. //如果页面加载的时候通过传参的构造函数
  74. if (ug_code.Text != "")
  75. Screen.PerformClick();
  76. }
  77. private void Ug_code_Dbchage(object sender, EventArgs e)
  78. {
  79. Dbfind = ug_code.ReturnData;
  80. BaseUtil.SetFormValue(this.Controls, Dbfind);
  81. }
  82. private void Screen_Click(object sender, EventArgs e)
  83. {
  84. //拼接条件,获取按照用户输入条件的数据集
  85. sql.Clear();
  86. sql.Append("select sn_id,sn_module,sn_displayname,sn_caller,ugp_id,ugp_ifread,ugp_ifwrite,ugp_ifdelete,ugp_ifspecial,ugp_ifall ");
  87. sql.Append("from cs$sysnavation left join cs$usergrouppower on ugp_groupcode='" + ug_code.Text + "' ");
  88. sql.Append("and ugp_caller=sn_caller where sn_using=1 and sn_module like '%" + (sn_module.Text == "全部" ? "" : sn_module.Text) + "%' order by sn_modulecode,sn_detno");
  89. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  90. BaseUtil.FillDgvWithDataTable(GroupPowerDGV, dt);
  91. }
  92. private void SavePower_Click(object sender, EventArgs e)
  93. {
  94. //保存表格中变更的记录
  95. dt = (DataTable)GroupPowerDGV.DataSource;
  96. //删除之前的分组权限
  97. if (sn_module.Text == "" || sn_module.Text == "全部")
  98. {
  99. dh.ExecuteSql("delete from cs$usergrouppower where ugp_groupcode='" + ug_code.Text + "'", "delete");
  100. }
  101. else
  102. {
  103. dh.ExecuteSql("delete from cs$usergrouppower where ugp_groupcode='" + ug_code.Text + "' and ugp_module='" + sn_module.Text + "'", "delete");
  104. }
  105. string insertsql = "Insert into cs$usergrouppower (ugp_id,ugp_module,ugp_groupcode,ugp_caller,ugp_ifread,ugp_ifwrite,ugp_ifdelete,ugp_ifspecial,ugp_ifall) values(cs$usergrouppower_seq.nextval,'"+sn_module.Text+"','" + ug_code.Text + "',:ugp_caller,:ugp_ifread,:ugp_ifwrite,:ugp_ifdelete,:ugp_ifspecial,:ugp_ifall)";
  106. //获取变化了得DataSource
  107. DataTable ChangedDT = dt.GetChanges();
  108. if (ChangedDT != null)
  109. {
  110. int ChangedRowCount = ChangedDT.Rows.Count;
  111. string[] caller = new string[ChangedRowCount];
  112. string[] ifread = new string[ChangedRowCount];
  113. string[] ifwrite = new string[ChangedRowCount];
  114. string[] ifdelete = new string[ChangedRowCount];
  115. string[] ifspecial = new string[ChangedRowCount];
  116. string[] ifall = new string[ChangedRowCount];
  117. for (int i = 0; i < ChangedRowCount; i++)
  118. {
  119. caller[i] = ChangedDT.Rows[i]["sn_caller"].ToString();
  120. ifread[i] = ChangedDT.Rows[i]["ugp_ifread"].ToString();
  121. ifwrite[i] = ChangedDT.Rows[i]["ugp_ifwrite"].ToString();
  122. ifdelete[i] = ChangedDT.Rows[i]["ugp_ifdelete"].ToString();
  123. ifspecial[i] = ChangedDT.Rows[i]["ugp_ifspecial"].ToString();
  124. ifall[i] = ChangedDT.Rows[i]["ugp_ifall"].ToString();
  125. }
  126. dh.BatchInsert(insertsql, new string[] { "ugp_caller", "ugp_ifread", "ugp_ifwrite", "ugp_ifdelete", "ugp_ifspecial", "ugp_ifall" }, caller, ifread, ifwrite, ifdelete, ifspecial, ifall);
  127. //保存后重新加载权限
  128. //保存后重置本地权限
  129. if (User.UserAccountType == "admin")
  130. {
  131. sql.Clear();
  132. sql.Append("select distinct sn_module,sn_caller ugp_caller,1 ugp_ifdelete,1 ugp_ifread,1 ugp_ifspecial,1 ugp_ifall,");
  133. sql.Append("1 ugp_ifwrite from CS$SYSNAVATION left join CS$USERGROUPPOWER on sn_caller=ugp_caller order by sn_module");
  134. }
  135. else
  136. {
  137. sql.Clear();
  138. sql.Append("select distinct sn_module,ugp_caller,ugp_ifdelete,ugp_ifread,ugp_ifspecial,ugp_ifwrite,ugp_ifall ");
  139. sql.Append("from CS$USERGROUPPOWER left join CS$SYSNAVATION on ");
  140. sql.Append("sn_caller=ugp_caller where ugp_groupcode in ( select eg_groupcode from cs$empgroup left join ");
  141. sql.Append("cs$userresource on ur_groupcode = eg_groupcode where eg_emcode = '" + User.UserCode + "') order by sn_module");
  142. }
  143. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  144. for (int i = 0; i < dt.Rows.Count; i++)
  145. {
  146. Dictionary<string, bool> dic = new Dictionary<string, bool>();
  147. dic.Add("IFDELETE", dt.Rows[i]["UGP_IFDELETE"].ToString() != "1" ? false : true);
  148. dic.Add("IFREAD", dt.Rows[i]["UGP_IFREAD"].ToString() != "1" ? false : true);
  149. dic.Add("IFWRITE", dt.Rows[i]["UGP_IFWRITE"].ToString() != "1" ? false : true);
  150. dic.Add("IFSPECIAL", dt.Rows[i]["UGP_IFSPECIAL"].ToString() != "1" ? false : true);
  151. dic.Add("IFALL", dt.Rows[i]["UGP_IFALL"].ToString() != "1" ? false : true);
  152. //之后通过Call来获取页面操作的权限
  153. if (!SystemInf.Caller.ContainsKey(dt.Rows[i]["ugp_caller"].ToString()))
  154. SystemInf.Caller.Add(dt.Rows[i]["ugp_caller"].ToString(), dic);
  155. }
  156. MessageBox.Show("保存成功!");
  157. }
  158. }
  159. //加载页面的数据
  160. private void LoadData()
  161. {
  162. sql.Clear();
  163. sql.Append("select sn_id,sn_module,sn_displayname,sn_caller,ugp_id,ugp_ifread,ugp_ifwrite,ugp_ifdelete,ugp_ifspecial,ugp_ifall ");
  164. sql.Append("from cs$sysnavation left join cs$usergrouppower on ugp_groupcode='" + ug_code.Text + "' and ugp_caller=sn_caller ");
  165. sql.Append("where sn_using=1 and ugp_groupcode='" + ug_code.Text + "' order by sn_modulecode,sn_detno");
  166. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  167. BaseUtil.FillDgvWithDataTable(GroupPowerDGV, dt);
  168. }
  169. private void GroupPower_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  170. private void 权限控制_SizeChanged(object sender, EventArgs e)
  171. {
  172. asc.controlAutoSize(this);
  173. }
  174. private void ug_code_UserControlTextChanged(object sender, EventArgs e)
  175. {
  176. if (ug_code.Text == "")
  177. SavePower.Visible = false;
  178. else
  179. {
  180. SavePower.Visible = true;
  181. Screen.PerformClick();
  182. }
  183. }
  184. private void sn_module_SelectedIndexChanged(object sender, EventArgs e)
  185. {
  186. Screen.PerformClick();
  187. }
  188. }
  189. }