123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using System.Data;
- using System.Windows.Forms;
- using UAS_LabelMachine;
- using UAS_LabelMachine.Entity;
- using UAS_LabelMachine.PublicMethod;
- namespace UAS_Labeling.PublicMethod
- {
- /// <summary>
- /// Author zhangz 2016/12/30
- /// 全局事件处理,通过句柄获取触发事件的控件
- /// 结合捕获的全局的键盘事件来验证用户进行的操作
- /// </summary>
- class GlobalEventsHandler : IMessageFilter
- {
- DataHelper dh;
- //鼠标左键点击
- public const int WM_LBUTTONDOWN = 0x0201;
- //键盘敲击事件
- public const int WM_KEYDOWN = 0x100;
- public bool PreFilterMessage(ref Message m)
- {
- //通过句柄去获取具体触发事件的控件
- Control c = Control.FromHandle(m.HWnd);
- //可进行数据操作的控件需要进行权限的判断,结合WM_LBUTTONDOWN对按钮进行判断
- if (c != null && m.Msg == WM_LBUTTONDOWN && c is Button)
- {
- LogManager.DoLog("点击【" + c.Text+"】");
- return CheckPower(c);
- }
- else
- return false;
- }
- /// <summary>
- /// 返回True表示消息已处理,不再往后传递
- /// 返回False表示消息未处理,后续程序处理此事件
- /// </summary>
- /// <param name="c"></param>
- /// <returns></returns>
- private bool CheckPower(Control c)
- {
- dh = new DataHelper();
- if (User.UserAccountType != "admin")
- {
- if (dh.getRowCount("labelprintpower") > 0)
- {
- string sql = " select LPP_CLEANDETAIL,LPP_GENCODE,LPP_LABELMATAIN,LPP_SAVEDETAIL,LPP_COLLECTSTRATEGY,LPP_ALLCOLLECT from labelprintpower left join employee on em_code = lpp_emcode where lpp_emcode = '" + User.UserCode + "'";
- DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
- if (dt.Rows.Count > 0)
- {
- switch (c.Text)
- {
- case "采集策略设置":
- if (dt.Rows[0]["LPP_COLLECTSTRATEGY"].ToString() != "1")
- {
- MessageBox.Show("没有" + c.Text + "的权限");
- return true;
- }
- break;
- case "生成条码":
- if (dt.Rows[0]["LPP_GENCODE"].ToString() != "1")
- {
- MessageBox.Show("没有" + c.Text + "的权限");
- return true;
- }
- break;
- case "标签维护":
- if (dt.Rows[0]["LPP_LABELMATAIN"].ToString() != "1")
- {
- MessageBox.Show("没有" + c.Text + "的权限");
- return true;
- }
- break;
- case "保存明细":
- if (dt.Rows[0]["LPP_SAVEDETAIL"].ToString() != "1")
- {
- MessageBox.Show("没有" + c.Text + "的权限");
- return true;
- }
- break;
- case "清除明细":
- if (dt.Rows[0]["LPP_CLEANDETAIL"].ToString() != "1")
- {
- MessageBox.Show("没有" + c.Text + "的权限");
- return true;
- }
- break;
- case "全部已采":
- if (dt.Rows[0]["LPP_ALLCOLLECT"].ToString() != "1")
- {
- MessageBox.Show("没有" + c.Text + "的权限");
- return true;
- }
- break;
- default:
- break;
- }
- }
- else {
- MessageBox.Show("尚未配置权限,请与管理员联系");
- return true;
- }
- }
- }
- return false;
- }
- }
- }
|