private CZKEMClass axCZKEM1 = new CZKEMClass();
private static bool _bIsConnected = false;
private static int _iMachineNumber = 1;
private static int _errorCode = 0;
public bool GetConnectState()
{
return _bIsConnected;
}
private void SetConnectState(bool state)
{
_bIsConnected = state;
}
private int GetMachineNumber()
{
return _iMachineNumber;
}
public int sta_ConnectTCP(string ip, string port, string commKey)
{
if (ip == "" || port == "" || commKey == "")
{
return -1;// ip or port is null
}
if (Convert.ToInt32(port) <= 0 || Convert.ToInt32(port) > 65535)
{
return -1;
}
if (Convert.ToInt32(commKey) < 0 || Convert.ToInt32(commKey) > 999999)
{
return -1;
}
int idwErrorCode = 0;
axCZKEM1.SetCommPassword(Convert.ToInt32(commKey));
if (_bIsConnected)
{
axCZKEM1.Disconnect();
SetConnectState(false);
return -2; //disconnect
}
if (axCZKEM1.Connect_Net(ip, Convert.ToInt32(port)))
{
SetConnectState(true);
return 1;
}
else
{
axCZKEM1.GetLastError(ref idwErrorCode);
return idwErrorCode;
}
}
public void sta_DisConnect()
{
if (GetConnectState())
{
axCZKEM1.Disconnect();
}
}
public int sta_ReadNewAttLog(DataTable dt_log)
{
if (GetConnectState() == false)
{
//Please connect first!";
return -1024;
}
int ret = 0;
axCZKEM1.EnableDevice(GetMachineNumber(), false);//disable the device
string sdwEnrollNumber = "";
int idwVerifyMode = 0;
int idwInOutMode = 0;
int idwYear = 0;
int idwMonth = 0;
int idwDay = 0;
int idwHour = 0;
int idwMinute = 0;
int idwSecond = 0;
int idwWorkcode = 0;
if (axCZKEM1.ReadNewGLogData(GetMachineNumber()))
{
while (axCZKEM1.SSR_GetGeneralLogData(GetMachineNumber(), out sdwEnrollNumber, out idwVerifyMode,
out idwInOutMode, out idwYear, out idwMonth, out idwDay, out idwHour, out idwMinute, out idwSecond, ref idwWorkcode))//get records from the memory
{
DataRow dr = dt_log.NewRow();
dr["User ID"] = sdwEnrollNumber;
dr["Verify Date"] = idwYear + "-" + idwMonth + "-" + idwDay + " " + idwHour + ":" + idwMinute + ":" + idwSecond;
dr["idwYear"] = idwYear;
dr["idwMonth"] = idwMonth;
dr["idwDay"] = idwDay;
dr["idwHour"] = idwHour;
dr["idwMinute"] = idwMinute;
dr["idwSecond"] = idwSecond;
dr["Verify Type"] = idwVerifyMode;
dr["Verify State"] = idwInOutMode;
dr["WorkCode"] = idwWorkcode;
dt_log.Rows.Add(dr);
}
ret = 1;
}
else
{
axCZKEM1.GetLastError(ref _errorCode);
ret = _errorCode;
if (_errorCode != 0)
{
//"*Read attlog by period failed,ErrorCode: " + idwErrorCode.ToString();
}
else
{
//"No data from terminal returns!";
}
}
//lblOutputInfo.Items.Add("[func ReadNewGLogData]Temporarily unsupported");
axCZKEM1.EnableDevice(GetMachineNumber(), true);//enable the device
return ret;
}