123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
- using UAS_MES_NEW.CustomControl.DataGrid_View;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicForm;
- using UAS_MES_NEW.PublicMethod;
- namespace UAS_MES_NEW.Employee
- {
- public partial class Employee_Power : Form
- {
- DataHelper dh;
- DataTable dt;
- AutoSizeFormClass asc = new AutoSizeFormClass();
- LogStringBuilder sql = new LogStringBuilder();
- Thread thread;
- SetLoadingWindow stw;
- DataTable Dbfind;
- ItemObject item;
- string[] title = new string[] { "读权限", "写权限", "删除权限", "特殊权限", "全部权限" };
- string[] DataPreperty = new string[] { "ugp_ifread", "ugp_ifwrite", "ugp_ifdelete", "ugp_ifspecial", "ugp_ifall" };
- public Employee_Power()
- {
- InitializeComponent();
- }
- public Employee_Power(string GroupCode, string GroupName)
- {
- InitializeComponent();
- ug_code.Text = GroupCode;
- sn_module.Text = GroupName;
- }
- private void 权限控制_Load(object sender, EventArgs e)
- {
- //不检测进程
- asc.controllInitializeSize(this);
- CheckForIllegalCrossThreadCalls = false;
- //界面加载时设置保存按钮不可见
- if (ug_code.Text == "")
- SavePower.Visible = false;
- dh = SystemInf.dh;
- ///手动插入四列含有列头勾选框的列
- for (int i = 0; i < title.Length; i++)
- {
- DataGridViewCheckBoxColumn dgvc = new DataGridViewCheckBoxColumn();
- dgvc.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
- dgvc.Width = 190;
- dgvc.Name = title[i];
- dgvc.DataPropertyName = DataPreperty[i];
- DataGridViewCheckBoxHeaderCell ch1 = new DataGridViewCheckBoxHeaderCell(GroupPowerDGV, dgvc);
- dgvc.HeaderCell = ch1;
- this.GroupPowerDGV.Columns.Insert(i + 3, dgvc);
- }
- //分组放大镜
- ug_code.FormName = Name;
- ug_code.TableName = "CS$USERGROUP";
- ug_code.SelectField = "ug_code # 分组编号,ug_name # 分组名称,ug_inman # 录入人,ug_indate #录入日期";
- ug_code.SetValueField = new string[] { "ug_code" };
- ug_code.DbChange += Ug_code_Dbchage;
- //由于需要额外添加一个全部值,需要手动添加Item
- dt = (DataTable)dh.ExecuteSql("select DISTINCT sn_module from CS$SYSNAVATION where sn_using=1", "select");
- item = new ItemObject("全部", "");
- sn_module.Items.Add(item);
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- string sn_moudle = dt.Rows[i]["sn_module"].ToString();
- item = new ItemObject(sn_moudle, sn_moudle);
- sn_module.Items.Add(item);
- }
- //如果页面加载的时候通过传参的构造函数
- if (ug_code.Text != "")
- Screen.PerformClick();
-
- }
- private void Ug_code_Dbchage(object sender, EventArgs e)
- {
- Dbfind = ug_code.ReturnData;
- BaseUtil.SetFormValue(this.Controls, Dbfind);
- }
- private void Screen_Click(object sender, EventArgs e)
- {
- //拼接条件,获取按照用户输入条件的数据集
- sql.Clear();
- sql.Append("select sn_id,sn_module,sn_displayname,sn_caller,ugp_id,ugp_ifread,ugp_ifwrite,ugp_ifdelete,ugp_ifspecial,ugp_ifall ");
- sql.Append("from cs$sysnavation left join cs$usergrouppower on ugp_groupcode='" + ug_code.Text + "' ");
- 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");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- BaseUtil.FillDgvWithDataTable(GroupPowerDGV, dt);
- }
- private void SavePower_Click(object sender, EventArgs e)
- {
- //保存表格中变更的记录
- dt = (DataTable)GroupPowerDGV.DataSource;
- //删除之前的分组权限
- if (sn_module.Text == "" || sn_module.Text == "全部")
- {
- dh.ExecuteSql("delete from cs$usergrouppower where ugp_groupcode='" + ug_code.Text + "'", "delete");
- }
- else
- {
- dh.ExecuteSql("delete from cs$usergrouppower where ugp_groupcode='" + ug_code.Text + "' and ugp_module='" + sn_module.Text + "'", "delete");
- }
- 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)";
- //获取变化了得DataSource
- DataTable ChangedDT = dt.GetChanges();
- if (ChangedDT != null)
- {
- int ChangedRowCount = ChangedDT.Rows.Count;
- string[] caller = new string[ChangedRowCount];
- string[] ifread = new string[ChangedRowCount];
- string[] ifwrite = new string[ChangedRowCount];
- string[] ifdelete = new string[ChangedRowCount];
- string[] ifspecial = new string[ChangedRowCount];
- string[] ifall = new string[ChangedRowCount];
- for (int i = 0; i < ChangedRowCount; i++)
- {
- caller[i] = ChangedDT.Rows[i]["sn_caller"].ToString();
- ifread[i] = ChangedDT.Rows[i]["ugp_ifread"].ToString();
- ifwrite[i] = ChangedDT.Rows[i]["ugp_ifwrite"].ToString();
- ifdelete[i] = ChangedDT.Rows[i]["ugp_ifdelete"].ToString();
- ifspecial[i] = ChangedDT.Rows[i]["ugp_ifspecial"].ToString();
- ifall[i] = ChangedDT.Rows[i]["ugp_ifall"].ToString();
- }
- dh.BatchInsert(insertsql, new string[] { "ugp_caller", "ugp_ifread", "ugp_ifwrite", "ugp_ifdelete", "ugp_ifspecial", "ugp_ifall" }, caller, ifread, ifwrite, ifdelete, ifspecial, ifall);
- //保存后重新加载权限
- //保存后重置本地权限
- if (User.UserAccountType == "admin")
- {
- sql.Clear();
- sql.Append("select distinct sn_module,sn_caller ugp_caller,1 ugp_ifdelete,1 ugp_ifread,1 ugp_ifspecial,1 ugp_ifall,");
- sql.Append("1 ugp_ifwrite from CS$SYSNAVATION left join CS$USERGROUPPOWER on sn_caller=ugp_caller order by sn_module");
- }
- else
- {
- sql.Clear();
- sql.Append("select distinct sn_module,ugp_caller,ugp_ifdelete,ugp_ifread,ugp_ifspecial,ugp_ifwrite,ugp_ifall ");
- sql.Append("from CS$USERGROUPPOWER left join CS$SYSNAVATION on ");
- sql.Append("sn_caller=ugp_caller where ugp_groupcode in ( select eg_groupcode from cs$empgroup left join ");
- sql.Append("cs$userresource on ur_groupcode = eg_groupcode where eg_emcode = '" + User.UserCode + "') order by sn_module");
- }
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- Dictionary<string, bool> dic = new Dictionary<string, bool>();
- dic.Add("IFDELETE", dt.Rows[i]["UGP_IFDELETE"].ToString() != "1" ? false : true);
- dic.Add("IFREAD", dt.Rows[i]["UGP_IFREAD"].ToString() != "1" ? false : true);
- dic.Add("IFWRITE", dt.Rows[i]["UGP_IFWRITE"].ToString() != "1" ? false : true);
- dic.Add("IFSPECIAL", dt.Rows[i]["UGP_IFSPECIAL"].ToString() != "1" ? false : true);
- dic.Add("IFALL", dt.Rows[i]["UGP_IFALL"].ToString() != "1" ? false : true);
- //之后通过Call来获取页面操作的权限
- if (!SystemInf.Caller.ContainsKey(dt.Rows[i]["ugp_caller"].ToString()))
- SystemInf.Caller.Add(dt.Rows[i]["ugp_caller"].ToString(), dic);
- }
- MessageBox.Show("保存成功!");
- }
- }
- //加载页面的数据
- private void LoadData()
- {
- sql.Clear();
- sql.Append("select sn_id,sn_module,sn_displayname,sn_caller,ugp_id,ugp_ifread,ugp_ifwrite,ugp_ifdelete,ugp_ifspecial,ugp_ifall ");
- sql.Append("from cs$sysnavation left join cs$usergrouppower on ugp_groupcode='" + ug_code.Text + "' and ugp_caller=sn_caller ");
- sql.Append("where sn_using=1 and ugp_groupcode='" + ug_code.Text + "' order by sn_modulecode,sn_detno");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- BaseUtil.FillDgvWithDataTable(GroupPowerDGV, dt);
- }
- private void GroupPower_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
- private void 权限控制_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- private void ug_code_UserControlTextChanged(object sender, EventArgs e)
- {
- if (ug_code.Text == "")
- SavePower.Visible = false;
- else
- {
- SavePower.Visible = true;
- Screen.PerformClick();
- }
- }
- private void sn_module_SelectedIndexChanged(object sender, EventArgs e)
- {
- Screen.PerformClick();
- }
- }
- }
|