123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using Check.DataOperate;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace UAS_CheckWork
- {
- public partial class Form2 : Form
- {
- public Form2()
- {
- InitializeComponent();
- }
- DataHelper dh = new DataHelper();
- //Create Standalone SDK class dynamicly.
- public zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass();
- private bool bIsConnected = false;//the boolean value identifies whether the device is connected
- private int iMachineNumber = 1;//the serial number of the device.After connecting the device ,this value will be changed.
- private void Form2_Load(object sender, EventArgs e)
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("UserID");
- dt.Columns.Add("AttState");
- dt.Columns.Add("VerifyMethod");
- dt.Columns.Add("Time");
- dt.Columns.Add("WorkCode");
- logInfo.DataSource = dt;
- }
- private void btnConnect_Click(object sender, EventArgs e)
- {
- if (txtIP.Text.Trim() == "" || txtPort.Text.Trim() == "")
- {
- MessageBox.Show("请先输入IP和端口", "Error");
- return;
- }
- int idwErrorCode = 0;
- Cursor = Cursors.WaitCursor;
- if (btnConnect.Text == "断开连接")
- {
- axCZKEM1.Disconnect();
- bIsConnected = false;
- btnConnect.Text = "连接";
- lblState.Text = "状态:未连接";
- startListening.Text = "开始实时事件";
- Cursor = Cursors.Default;
- return;
- }
- bIsConnected = axCZKEM1.Connect_Net(txtIP.Text, Convert.ToInt32(txtPort.Text));
- if (bIsConnected)
- {
- btnConnect.Text = "断开连接";
- btnConnect.Refresh();
- lblState.Text = "状态:已连接";
- 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.
- axCZKEM1.RegEvent(iMachineNumber, 65535);//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
- }
- else
- {
- axCZKEM1.GetLastError(ref idwErrorCode);
- MessageBox.Show("无法连接设备,ErrorCode=" + idwErrorCode.ToString(), "Error");
- }
- Cursor = Cursors.Default;
- }
- private void startListening_Click(object sender, EventArgs e)
- {
- if (!bIsConnected)
- {
- MessageBox.Show("请先连接设备", "Error");
- return;
- }
- if (startListening.Text == "正在实时监听")
- {
- MessageBox.Show("已启动监听", "Error");
- return;
- }
- int idwErrorCode = 0;
- //开始注册考勤机的监听事件
- if (axCZKEM1.RegEvent(iMachineNumber, 1))//65535表示注册所有的事件
- {
- //注册事件
- this.axCZKEM1.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
- //注册成功提示用户
- startListening.Text = "正在实时监听";
- }
- else
- {
- axCZKEM1.GetLastError(ref idwErrorCode);
- MessageBox.Show("注册监听事件失败,ErrorCode=" + idwErrorCode.ToString(), "Error");
- }
- }
- /// <summary>
- /// 考勤机验证通过
- /// </summary>
- /// <param name="sEnrollNumber">UserID</param>
- /// <param name="iIsInValid">1 为无效记录,0 为有效记录</param>
- /// <param name="iAttState">0—Check-In 1—Check-Out 2—Break-Out 3—Break-In 4—OT-In 5—OT-Out </param>
- /// <param name="iVerifyMethod">:0 为密码验证,1 为指纹验证,2 为卡验证 </param>
- /// <param name="iYear"></param>
- /// <param name="iMonth"></param>
- /// <param name="iDay"></param>
- /// <param name="iHour"></param>
- /// <param name="iMinute"></param>
- /// <param name="iSecond"></param>
- /// <param name="iWorkCode">WorkCode 返回验证时 WorkCode 值,当机器无 Workcode 功能时,该值返回 0</param>
- private void axCZKEM1_OnAttTransactionEx(string sEnrollNumber, int iIsInValid, int iAttState, int iVerifyMethod, int iYear, int iMonth, int iDay, int iHour, int iMinute, int iSecond, int iWorkCode)
- {
- //实现实时获取考勤,取有效记录
- if (iIsInValid == 0)
- {
- //显示
- DataTable dt = (DataTable)logInfo.DataSource;
- DataRow dr = dt.NewRow();//新建行
- dr["UserID"] = sEnrollNumber;
- switch (iVerifyMethod)
- {
- case 0:
- dr["VerifyMethod"] = "密码";
- break;
- case 1:
- dr["VerifyMethod"] = "指纹";
- break;
- case 2:
- dr["VerifyMethod"] = "卡";
- break;
- default:
- break;
- }
- string Time = iYear + "-" + iMonth + "-" + iDay + " " + iHour + ":" + iMinute + ":" + iSecond;
- dr["Time"] = Time;
- dr["WorkCode"] = iWorkCode;
- dt.Rows.Add(dr);
- logInfo.DataSource = dt;
- //更新数据库
- dh.ExecuteSql("insert into cardlog (cl_id,cl_cardcode,cl_time,cl_address) values (cardlog_seq.nextval,'" + sEnrollNumber + "',TO_DATE('" + Time + "','yyyy-MM-dd hh24:mi:ss'),'考勤机数据导入')", "insert");
- }
- else
- {
- //记录验证无效
- }
- }
- }
- }
|