Form1.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace UAS_CheckWork
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. //Create Standalone SDK class dynamicly.
  19. public zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass();
  20. private bool bIsConnected = false;//the boolean value identifies whether the device is connected
  21. private int iMachineNumber = 1;//the serial number of the device.After connecting the device ,this value will be changed.
  22. private void btnConnect_Click(object sender, EventArgs e)
  23. {
  24. if (txtIP.Text.Trim() == "" || txtPort.Text.Trim() == "")
  25. {
  26. MessageBox.Show("请先输入IP和端口", "Error");
  27. return;
  28. }
  29. int idwErrorCode = 0;
  30. Cursor = Cursors.WaitCursor;
  31. if (btnConnect.Text == "断开连接")
  32. {
  33. axCZKEM1.Disconnect();
  34. bIsConnected = false;
  35. btnConnect.Text = "连接";
  36. lblState.Text = "状态:未连接";
  37. Cursor = Cursors.Default;
  38. return;
  39. }
  40. bIsConnected = axCZKEM1.Connect_Net(txtIP.Text, Convert.ToInt32(txtPort.Text));
  41. if (bIsConnected)
  42. {
  43. btnConnect.Text = "断开连接";
  44. btnConnect.Refresh();
  45. lblState.Text = "状态:已连接";
  46. iMachineNumber = 1;//In fact,when you are using the tcp/ip communication,this parameter will be ignored,that is any integer will all right.Here we use 1.
  47. axCZKEM1.RegEvent(iMachineNumber, 65535);//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
  48. }
  49. else
  50. {
  51. axCZKEM1.GetLastError(ref idwErrorCode);
  52. MessageBox.Show("无法连接设备,ErrorCode=" + idwErrorCode.ToString(), "Error");
  53. }
  54. Cursor = Cursors.Default;
  55. }
  56. private void getAllData_Click(object sender, EventArgs e)
  57. {
  58. if (bIsConnected)
  59. {
  60. MessageBox.Show("请先连接设备", "Error");
  61. return;
  62. }
  63. int idwErrorCode = 0;
  64. //获取所有的考勤记录
  65. if (axCZKEM1.ReadAllGLogData(iMachineNumber))
  66. {
  67. //循环获取
  68. DataTable dt = new DataTable();
  69. string enrollNumber = "";//记录用户ID
  70. int verifyCode = 0;//记录用户验证方式 0 为密码验证,1 为指纹验证,2 为卡验证
  71. int inoutMode = 0;//考勤状态,具体含义如下: 默认 0—Check-In 1—Check-Out 2—Break-Out 3—Break-In 4—OT-In 5—OT-Out
  72. int year = 0;//记录考勤年份
  73. int month = 0;//记录考勤月份
  74. int day = 0;//记录考勤日期
  75. int hour = 0;//记录考勤小时
  76. int minute = 0;//记录考勤分钟
  77. int second = 0;//记录考勤秒
  78. int workCode = 0; //记录workCode
  79. while (axCZKEM1.SSR_GetGeneralLogData(iMachineNumber, out enrollNumber, out verifyCode, out inoutMode, out year, out month, out day, out hour, out minute, out second, ref workCode))
  80. {
  81. //将数据加入DataTable中
  82. DataRow dr = dt.NewRow();
  83. dr["cl_emcode"] = enrollNumber;
  84. dr["cl_time"] = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
  85. dt.Rows.Add(dr);
  86. allData.DataSource = dt;
  87. //显示
  88. showDataGrid.DataSource = (DataTable)allData.DataSource;
  89. }
  90. }
  91. else
  92. {
  93. axCZKEM1.GetLastError(ref idwErrorCode);
  94. MessageBox.Show("Unable to get data,ErrorCode=" + idwErrorCode.ToString(), "Error");
  95. }
  96. }
  97. private void Form1_Load(object sender, EventArgs e)
  98. {
  99. //设定全选按钮
  100. chooseAll.ChooseAll(showDataGrid);
  101. }
  102. private void saveData_Click(object sender, EventArgs e)
  103. {
  104. //点击保存数据
  105. }
  106. }
  107. }