GlobalEventsHandler.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System.Data;
  2. using System.Windows.Forms;
  3. using UAS_LabelMachine;
  4. using UAS_LabelMachine.Entity;
  5. using UAS_LabelMachine.PublicMethod;
  6. namespace UAS_Labeling.PublicMethod
  7. {
  8. /// <summary>
  9. /// Author zhangz 2016/12/30
  10. /// 全局事件处理,通过句柄获取触发事件的控件
  11. /// 结合捕获的全局的键盘事件来验证用户进行的操作
  12. /// </summary>
  13. class GlobalEventsHandler : IMessageFilter
  14. {
  15. DataHelper dh;
  16. //鼠标左键点击
  17. public const int WM_LBUTTONDOWN = 0x0201;
  18. //键盘敲击事件
  19. public const int WM_KEYDOWN = 0x100;
  20. public bool PreFilterMessage(ref Message m)
  21. {
  22. //通过句柄去获取具体触发事件的控件
  23. Control c = Control.FromHandle(m.HWnd);
  24. //可进行数据操作的控件需要进行权限的判断,结合WM_LBUTTONDOWN对按钮进行判断
  25. if (c != null && m.Msg == WM_LBUTTONDOWN && (c is RadioButton || c is Button))
  26. {
  27. LogManager.DoLog("点击【" + c.Text + "】");
  28. return CheckPower(c);
  29. }
  30. else
  31. return false;
  32. }
  33. /// <summary>
  34. /// 返回True表示消息已处理,不再往后传递
  35. /// 返回False表示消息未处理,后续程序处理此事件
  36. /// </summary>
  37. /// <param name="c"></param>
  38. /// <returns></returns>
  39. private bool CheckPower(Control c)
  40. {
  41. dh = SystemInf.dh;
  42. if (User.UserAccountType != "admin")
  43. {
  44. {
  45. string sql = " select nvl(lpp_manual,0)lpp_manual,nvl(lpp_cleandetail,0)lpp_cleandetail from labelprintpower where lpp_emcode = '" + User.UserCode + "'";
  46. DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
  47. if (dt.Rows.Count > 0)
  48. {
  49. switch (c.Name)
  50. {
  51. case "ManualCollection":
  52. if (dt.Rows[0]["lpp_manual"].ToString() == "0")
  53. {
  54. MessageBox.Show("您没有手动采集的权限,请与管理员联系", "提示");
  55. return true;
  56. }
  57. break;
  58. case "ResetBarcode":
  59. if (dt.Rows[0]["lpp_cleandetail"].ToString() == "0")
  60. {
  61. MessageBox.Show("您没有重置条码的权限,请与管理员联系", "提示");
  62. return true;
  63. }
  64. break;
  65. default:
  66. break;
  67. }
  68. }
  69. else
  70. {
  71. MessageBox.Show("尚未配置权限,请与管理员联系", "提示");
  72. return true;
  73. }
  74. }
  75. }
  76. return false;
  77. }
  78. }
  79. }