12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- 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 RadioButton || 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 = SystemInf.dh;
- if (User.UserAccountType != "admin")
- {
- {
- string sql = " select nvl(lpp_manual,0)lpp_manual,nvl(lpp_cleandetail,0)lpp_cleandetail from labelprintpower where lpp_emcode = '" + User.UserCode + "'";
- DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
- if (dt.Rows.Count > 0)
- {
- switch (c.Name)
- {
- case "ManualCollection":
- if (dt.Rows[0]["lpp_manual"].ToString() == "0")
- {
- MessageBox.Show("您没有手动采集的权限,请与管理员联系", "提示");
- return true;
- }
- break;
- case "ResetBarcode":
- if (dt.Rows[0]["lpp_cleandetail"].ToString() == "0")
- {
- MessageBox.Show("您没有重置条码的权限,请与管理员联系", "提示");
- return true;
- }
- break;
- default:
- break;
- }
- }
- else
- {
- MessageBox.Show("尚未配置权限,请与管理员联系", "提示");
- return true;
- }
- }
- }
- return false;
- }
- }
- }
|