private void btnRestore_Click(object sender, EventArgs e) { ArrayList arQuery = new ArrayList(); GTRLibrary.clsConnection clsCon = new GTRLibrary.clsConnection(); string sqlQuery = "", DeviceIP = "", GetDeviceIP = ""; Int32 NewId = 0; Int32 RowID; string DeviceIp = "", pDate = "", pTime = ""; int Count = 0; int idwErrorCode = 0; foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in this.gridDetails.Rows) { if (row.Cells["Id"].Text.ToString().Length != 0 && row.Cells["isChecked"].Value.ToString() == "1" && row.Cells["Active"].Value.ToString() == "1") { GetDeviceIP = "" + row.Cells["IpAddress"].Text.ToString() + ""; bIsConnected = axCZKEM1.Connect_Net(GetDeviceIP, 4370); if (bIsConnected == true) { iMachineNumber = 1; axCZKEM1.RegEvent(iMachineNumber, 65535); } Count = Convert.ToInt32(txtRestore.Text); axCZKEM1.EnableDevice(iMachineNumber, false); //disable the device if (axCZKEM1.RestoreLogData(iMachineNumber, Count)) //Here we use the function "RestoreLogData" and Restore Number. { MessageBox.Show("There have Restore " + Count.ToString(), " Attendance Data"); } else { axCZKEM1.GetLastError(ref idwErrorCode); MessageBox.Show("Operation failed,Attendance Data not Restore,Please input less number.ErrorCode=" + idwErrorCode.ToString(), "Error"); } axCZKEM1.EnableDevice(iMachineNumber, true); //enable the device } axCZKEM1.Disconnect(); } // for }
public void ConnectViaNet(List <string> messages) { if (ValidateIpAddress()) { Settings.Default._machineNo = 1; var port = Settings.Default._devicePort; if (port <= 0 || port > 65535) { messages.Add(Resources.LABEL_ILLEGAL_PORT); } var iCommkey = Convert.ToInt32(Settings.Default._commKey); _czkem.SetCommPassword(iCommkey); if (Settings.Default._connected) { _czkem.Disconnect(); UnRegisterEvents(); SetConnected(false); messages.Add(WriteLog(Resources.LABEL_DISCONNECT_WITH_DEVICE)); } if (_czkem.Connect_Net(Settings.Default._deviceIpAddress, Settings.Default._devicePort)) { RegisterEvents(messages); SetConnected(true); messages.Add(WriteLog(Resources.LABEL_DEVICE_CONNECTED)); } else { var idwErrorCode = 0; _czkem.GetLastError(ref idwErrorCode); messages.Add(WriteLog(Resources.LABEL_UNABLE_TO_CONNECT_VIA_NET + idwErrorCode)); } } else { messages.Add(WriteLog(Resources.LABEL_INVALID_DEVICE_IP_ADDRESS)); } }
public StatusReport Connect() { lock (syncRoot) { connectionState.Fire(Trigger.ConnectRequested); axCZKEM1.SetCommPassword(commKey); if (axCZKEM1.Connect_Net(ip, port)) { return(StatusReport.Success()); } else { connectionState.Fire(Trigger.ConnectFailed); int errorCode = 0; axCZKEM1.GetLastError(ref errorCode); return(StatusReport.Fail(errorCode)); } } }
public bool ClearGLog2(int dwMachineNumber) { //////////////// try { if (objCZKEM.ClearGLog(dwMachineNumber)) { objCZKEM.RefreshData(dwMachineNumber); //the data in the device should be refreshed //LogEntry(string.Format("{0} : All att Logs have been cleared from teiminal!, Success", DateTime.Now)); } else { int idwErrorCode = 0; objCZKEM.GetLastError(ref idwErrorCode); // LogEntry(string.Format("{0} : Clear operation failed", DateTime.Now)); } return(true); } catch (Exception ex) { return(false); } ///////////////////////////////// }
public void GetLastError(ref int dwErrorCode) { objCZKEM.GetLastError(dwErrorCode); }
private void prcExecuteDownload() { gridInfo.DataSource = null; ArrayList arQuery = new ArrayList(); GTRLibrary.clsConnection clsCon = new GTRLibrary.clsConnection(); try { string sqlQuery = "", DeviceIP = "", GetDeviceIP = ""; Int32 NewId = 0; Int32 RowID; string sdwEnrollNumber = "", DeviceIp = "", pDate = "", pTime = "", CardNo = "", EnrollID = ""; int idwTMachineNumber = 0, idwEMachineNumber = 0; int idwVerifyMode = 0, idwInOutMode = 0, idwEnrollNumber = 0, EnrollData = 0; int idwYear = 0, idwMonth = 0, idwDay = 0; int idwHour = 0, idwMinute = 0, idwSecond = 0; int idwWorkcode = 0, idwErrorCode = 0; int iGLCount = 0, iIndex = 0; //Raw Data Clear sqlQuery = "Truncate Table tblRawdataMIGTR_Temp"; arQuery.Add(sqlQuery); sqlQuery = "Update tblMachineNo_GTR set Status = 'Disconnect'"; arQuery.Add(sqlQuery); clsCon.GTRSaveDataWithSQLCommand(arQuery); foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in this.gridDetails.Rows) { if (row.Cells["Id"].Text.ToString().Length != 0 && row.Cells["isChecked"].Value.ToString() == "1" && row.Cells["Active"].Value.ToString() == "1") { GetDeviceIP = "" + row.Cells["IpAddress"].Text.ToString() + ""; bIsConnected = axCZKEM1.Connect_Net(GetDeviceIP, 4370); if (bIsConnected == true) { iMachineNumber = 1; axCZKEM1.RegEvent(iMachineNumber, 65535); } else { axCZKEM1.GetLastError(ref idwErrorCode); MessageBox.Show("Device not connected. Please check your device or network connection.Problem IP Address = " + GetDeviceIP.ToString(), "Error"); } //ZK Black & White Device Download Code if (row.Cells["BlackWhite"].Value.ToString() == "1") { sqlQuery = "Update tblMachineNo_GTR set Status = 'Connect' where IpAddress ='" + row.Cells["IpAddress"].Text.ToString() + "'"; arQuery.Add(sqlQuery); clsCon.GTRSaveDataWithSQLCommand(arQuery); Cursor = Cursors.WaitCursor; //lvLogs.Items.Clear(); axCZKEM1.EnableDevice(iMachineNumber, false); //disable the device if (axCZKEM1.ReadGeneralLogData(iMachineNumber)) //read all the attendance records to the memory { while (axCZKEM1.GetGeneralLogData(iMachineNumber, ref idwTMachineNumber, ref idwEnrollNumber, ref idwEMachineNumber, ref idwVerifyMode, ref idwInOutMode, ref idwYear, ref idwMonth, ref idwDay, ref idwHour, ref idwMinute))//get records from the memory { //iGLCount++; DeviceIp = GetDeviceIP.Substring(7); //CardNo = idwEnrollNumber.ToString(); //CardNo = GTRDecToHexCon(CardNo); EnrollData = int.Parse(sdwEnrollNumber); //EnrollID = EnrollData.ToString("0000000000"); //pDate = idwDay + "-" + idwMonth + "-" + idwYear; pDate = idwYear + "-" + idwMonth + "-" + idwDay; pTime = idwHour + ":" + idwMinute + ":" + idwSecond; sqlQuery = "Insert into tblRawdataMIGTR_Temp(ComId,DeviceNo,CardNo,dtPunchDate,dtPunchTime) values(" + Common.Classes.clsMain.intComId + ",'" + DeviceIp + "','" + sdwEnrollNumber + "','" + pDate + "','" + pTime + "')"; arQuery.Add(sqlQuery); sqlQuery = "Insert into tblRawdata(ComId,DeviceNo,CardNo,dtPunchDate,dtPunchTime,LUserID,PCName) values(" + Common.Classes.clsMain.intComId + ",'" + DeviceIp + "','" + sdwEnrollNumber + "','" + pDate + "','" + pTime + "'," + GTRHRIS.Common.Classes.clsMain.intUserId + ",'" + Common.Classes.clsMain.strComputerName + "')"; arQuery.Add(sqlQuery); //iIndex++; } //while } //if if (chkClear.Checked == true) { axCZKEM1.EnableDevice(iMachineNumber, false);//disable the device if (axCZKEM1.ClearGLog(iMachineNumber)) { axCZKEM1.RefreshData(iMachineNumber);//the data in the device should be refreshed //MessageBox.Show("All att Logs have been cleared from teiminal!", "Success"); } } axCZKEM1.EnableDevice(iMachineNumber, true);//enable the device Cursor = Cursors.Default; axCZKEM1.Disconnect(); } //if //ZK Color Device Download Code else { sqlQuery = "Update tblMachineNo_GTR set Status = 'Connect' where IpAddress ='" + row.Cells["IpAddress"].Text.ToString() + "'"; arQuery.Add(sqlQuery); clsCon.GTRSaveDataWithSQLCommand(arQuery); Cursor = Cursors.WaitCursor; //lvLogs.Items.Clear(); axCZKEM1.EnableDevice(iMachineNumber, false); //disable the device if (axCZKEM1.ReadGeneralLogData(iMachineNumber)) //read all the attendance records to the memory { while (axCZKEM1.SSR_GetGeneralLogData(iMachineNumber, 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 { //iGLCount++; DeviceIp = GetDeviceIP.Substring(7); //CardNo = sdwEnrollNumber; //CardNo = GTRDecToHexCon(CardNo); EnrollData = int.Parse(sdwEnrollNumber); EnrollID = EnrollData.ToString("0000000000"); //pDate = idwDay + "-" + idwMonth + "-" + idwYear; pDate = idwYear + "-" + idwMonth + "-" + idwDay; pTime = idwHour + ":" + idwMinute + ":" + idwSecond; sqlQuery = "Insert into tblRawdataMIGTR_Temp(ComId,DeviceNo,CardNo,dtPunchDate,dtPunchTime) values(" + Common.Classes.clsMain.intComId + ",'" + DeviceIp + "','" + EnrollID + "','" + pDate + "','" + pTime + "')"; arQuery.Add(sqlQuery); sqlQuery = "Insert into tblRawdata(ComId,DeviceNo,CardNo,dtPunchDate,dtPunchTime,LUserID,PCName) values(" + Common.Classes.clsMain.intComId + ",'" + DeviceIp + "','" + EnrollID + "','" + pDate + "','" + pTime + "'," + GTRHRIS.Common.Classes.clsMain.intUserId + ",'" + Common.Classes.clsMain.strComputerName + "')"; arQuery.Add(sqlQuery); //iIndex++; } //while } //if if (chkClear.Checked == true) { axCZKEM1.EnableDevice(iMachineNumber, false);//disable the device if (axCZKEM1.ClearGLog(iMachineNumber)) { axCZKEM1.RefreshData(iMachineNumber);//the data in the device should be refreshed //MessageBox.Show("All att Logs have been cleared from teiminal!", "Success"); } } axCZKEM1.EnableDevice(iMachineNumber, true);//enable the device Cursor = Cursors.Default; axCZKEM1.Disconnect(); } //else } //if } //foreach // Insert Information To Log File sqlQuery = "Insert Into tblUser_Trans_Log (LUserId, formName, tranStatement, PCName, tranType)" + " Values (" + GTRHRIS.Common.Classes.clsMain.intUserId + ", '" + this.Name.ToString() + "','" + sqlQuery.Replace("'", "|") + "','" + Common.Classes.clsMain.strComputerName + "','Download')"; arQuery.Add(sqlQuery); clsCon.GTRSaveDataWithSQLCommand(arQuery); prcLoadList(); prcRawData(); } //try catch (Exception ex) { throw (ex); } finally { clsCon = null; } }
private bool clkZKSoft(int pRid, int pNro, string pDes, string pDir, int pPor, long pPsw) { bool clkZKSoft = false; try { string sdwEnrollNumber = ""; int idwVerifyMode; int idwInOutMode; int idwYear; int idwMonth; int idwDay; int idwHour; int idwMinute; int idwSecond; int idwWorkcode = 0; string vFic; bool vClean = false; CZKEM Reloj = new CZKEM(); DevOps devolucionOperacion = new DevOps(); RelojesIngresos objFichada = new RelojesIngresos(); List <RelojResponse> relojResponse = new List <RelojResponse>(); //DevOps devolucionOperacion = new DevOps(); //if (pDir == "192.168.0.241") // pDir = "192.168.5.111"; // Reloj Pilar // If pDir = "192.168.0.241" Then pDir = "200.49.156.125" // If pDir = "200.85.127.22" Then pDir = "192.168.5.125" // If pDir = "192.168.4.240" Then // pDir = "661705e2a569.sn.mynetname.net" // pPor = 64370 // End If //FuncionPrueba(pRid); Logger.GetInstance().AddLog(true, "clkZKSoft()", "Conectandose " + pDir + ":" + pPor); if (Reloj.Connect_Net(pDir, pPor))/* && false)*/ { Logger.GetInstance().AddLog(true, "clkZKSoft()", "Conectado a " + pDir + ":" + pPor); Reloj.EnableDevice(pNro, false); // ----> Leo Datos if (Reloj.ReadGeneralLogData(pNro)) { // SSR_GetGeneralLogData // ----> Leo Datos while (Reloj.SSR_GetGeneralLogData(pNro, out sdwEnrollNumber, out idwVerifyMode, out idwInOutMode, out idwYear, out idwMonth, out idwDay, out idwHour, out idwMinute, out idwSecond, ref idwWorkcode)) { if (!vClean) { Logger.GetInstance().AddLog(true, "clkZKSoft()", "Procesando registros de " + pDir + ":" + pPor); } vClean = true; //Logger.GetInstance().AddLog(true, "clkZKSoft()", "Revisando Legajo: " + sdwEnrollNumber); if (idwYear == DateTime.Now.Year) { RelojResponse relojResponseItem = new RelojResponse(); vFic = string.Format(idwYear.ToString("0000")) + "-" + string.Format(idwMonth.ToString("00")) + "-" + string.Format(idwDay.ToString("00")) + " " + String.Format(idwHour.ToString("00")) + ":" + String.Format(idwMinute.ToString("00")) + ":" + String.Format(idwSecond.ToString("00")); //Logger.GetInstance().AddLog(true, "clkZKSoft()", "Fecha del Registro: " + vFic); relojResponseItem.Fich = vFic; relojResponseItem.Nro = pNro; relojResponseItem.SdwEnrollNumber = sdwEnrollNumber; relojResponseItem.IdwVerifyMode = idwVerifyMode; relojResponseItem.IdwInOutMode = idwInOutMode; relojResponseItem.IdwWorkcode = idwWorkcode; relojResponse.Add(relojResponseItem); } } if (relojResponse.Count > 0) { if (ConnectServer(dBServer1)) { Logger.GetInstance().AddLog(true, "clkZKSoft()", "Envios a Server1: " + dBServer1); Logger.GetInstance().AddLog(true, "clkZKSoft()", "Cantidad de Registros: " + relojResponse.Count); foreach (RelojResponse item in relojResponse) { Logger.GetInstance().AddLog(true, "clkZKSoft()", "Revisando Legajo: " + item.SdwEnrollNumber); Logger.GetInstance().AddLog(true, "clkZKSoft()", "Fecha del Registro: " + item.Fich); try { devolucionOperacion = objFichada.SetFichada(pRid, item.SdwEnrollNumber, item.Fich, "CLOCK"); Logger.GetInstance().AddLog(true, "clkZKSoft()", "SetFichada CacheDebug: " + devolucionOperacion.CacheDebug); if (devolucionOperacion.Resultado) { Logger.GetInstance().AddLog(true, "clkZKSoft()", "SetFichada OK"); } else { Logger.GetInstance().AddLog(false, "clkZKSoft()", "SetFichada Error: " + devolucionOperacion.DescripcionError); } } catch (Exception ex) { Logger.GetInstance().AddLog(false, "clkZKSoft()", "Excepción en SetFichada: " + ex.Message); } } modDeclares.ShamanSession.Cerrar(modDeclares.ShamanSession.PID); } if (ConnectServer(dBServer2)) { Logger.GetInstance().AddLog(true, "clkZKSoft()", "Envios a Server2: " + dBServer2); Logger.GetInstance().AddLog(true, "clkZKSoft()", "Cantidad de Registros: " + relojResponse.Count); foreach (RelojResponse item in relojResponse) { Logger.GetInstance().AddLog(true, "clkZKSoft()", "Revisando Legajo: " + item.SdwEnrollNumber); Logger.GetInstance().AddLog(true, "clkZKSoft()", "Fecha del Registro: " + item.Fich); try { devolucionOperacion = objFichada.SetFichada(pRid, item.SdwEnrollNumber, item.Fich, "CLOCK"); Logger.GetInstance().AddLog(true, "clkZKSoft()", "SetFichada CacheDebug: " + devolucionOperacion.CacheDebug); if (devolucionOperacion.Resultado) { Logger.GetInstance().AddLog(true, "clkZKSoft()", "SetFichada OK"); } else { Logger.GetInstance().AddLog(false, "clkZKSoft()", "SetFichada Error: " + devolucionOperacion.DescripcionError); } } catch (Exception ex) { Logger.GetInstance().AddLog(false, "clkZKSoft()", "Excepción en SetFichada: " + ex.Message); } } modDeclares.ShamanSession.Cerrar(modDeclares.ShamanSession.PID); } if (ConnectServer(dBServer3)) { Logger.GetInstance().AddLog(true, "clkZKSoft()", "Envios a Server3: " + dBServer3); Logger.GetInstance().AddLog(true, "clkZKSoft()", "Cantidad de Registros: " + relojResponse.Count); foreach (RelojResponse item in relojResponse) { Logger.GetInstance().AddLog(true, "clkZKSoft()", "Revisando Legajo: " + item.SdwEnrollNumber); Logger.GetInstance().AddLog(true, "clkZKSoft()", "Fecha del Registro: " + item.Fich); try { devolucionOperacion = objFichada.SetFichada(pRid, item.SdwEnrollNumber, item.Fich, "CLOCK"); Logger.GetInstance().AddLog(true, "clkZKSoft()", "SetFichada CacheDebug: " + devolucionOperacion.CacheDebug); if (devolucionOperacion.Resultado) { Logger.GetInstance().AddLog(true, "clkZKSoft()", "SetFichada OK"); } else { Logger.GetInstance().AddLog(false, "clkZKSoft()", "SetFichada Error: " + devolucionOperacion.DescripcionError); } } catch (Exception ex) { Logger.GetInstance().AddLog(false, "clkZKSoft()", "Excepción en SetFichada: " + ex.Message); } } modDeclares.ShamanSession.Cerrar(modDeclares.ShamanSession.PID); } } if (vClean) { Logger.GetInstance().AddLog(true, "clkZKSoft()", "Vaciar Reloj " + pNro + " Ip: " + pDir + ":" + pPor); if (Reloj.ClearGLog(pNro)) { Reloj.RefreshData(pNro); Logger.GetInstance().AddLog(true, "clkZKSoft()", "Se vació RelojId " + pNro + " Ip: " + pDir + ":" + pPor); } else { int idwErrorCode = 0; Reloj.GetLastError(idwErrorCode); Logger.GetInstance().AddLog(false, "clkZKSoft()", "Error al vaciar " + pDir + ":" + pPor + " " + idwErrorCode); } vClean = false; } else { Logger.GetInstance().AddLog(true, "clkZKSoft()", "No hay fichadas en " + pDir + ":" + pPor); } } else { Logger.GetInstance().AddLog(true, "clkZKSoft()", "No hay fichadas en " + pDir + ":" + pPor); } Logger.GetInstance().AddLog(true, "clkZKSoft()", "Desconectar Reloj " + pDir + ":" + pPor); Reloj.Disconnect(); clkZKSoft = true; } else { Logger.GetInstance().AddLog(true, "clkZKSoft()", "Sin conexión a " + pDir + ":" + pPor); } } catch (Exception ex) { Logger.GetInstance().AddLog(false, "clkZKSoft()", ex.Message); } return(clkZKSoft); }
private bool clkZKSoft(int pRid, int pNro, string pDes, string pDir, int pPor, long pPsw, bool vClean = false, int pCommPassword = 0) { bool clkZKSoft = false; try { string sdwEnrollNumber = ""; int idwVerifyMode; int idwInOutMode; int idwYear; int idwMonth; int idwDay; int idwHour; int idwMinute; int idwSecond; int idwWorkcode = 0; string vFic; CZKEM Reloj = new CZKEM(); DevOps devolucionOperacion = new DevOps(); RelojesIngresos objFichada = new RelojesIngresos(); List <RelojResponse> relojResponse = new List <RelojResponse>(); Logger.GetInstance().AddLog(true, "clkZKSoft()", "Conectandose " + pDir + ":" + pPor); if (pCommPassword > 0) { Reloj.SetCommPassword(pCommPassword); } if (Reloj.Connect_Net(pDir, pPor)) { Logger.GetInstance().AddLog(true, "clkZKSoft()", "Conectado a " + pDir + ":" + pPor); Reloj.EnableDevice(pNro, false); // ----> Leo Datos if (Reloj.ReadGeneralLogData(pNro)) { // SSR_GetGeneralLogData // ----> Leo Datos while (Reloj.SSR_GetGeneralLogData(pNro, out sdwEnrollNumber, out idwVerifyMode, out idwInOutMode, out idwYear, out idwMonth, out idwDay, out idwHour, out idwMinute, out idwSecond, ref idwWorkcode)) { if (idwYear == DateTime.Now.Year) { RelojResponse relojResponseItem = new RelojResponse(); vFic = string.Format(idwYear.ToString("0000")) + "-" + string.Format(idwMonth.ToString("00")) + "-" + string.Format(idwDay.ToString("00")) + " " + String.Format(idwHour.ToString("00")) + ":" + String.Format(idwMinute.ToString("00")) + ":" + String.Format(idwSecond.ToString("00")); //Logger.GetInstance().AddLog(true, "clkZKSoft()", "Fecha del Registro: " + vFic); relojResponseItem.Fich = vFic; relojResponseItem.Nro = pNro; relojResponseItem.SdwEnrollNumber = sdwEnrollNumber; relojResponseItem.IdwVerifyMode = idwVerifyMode; relojResponseItem.IdwInOutMode = idwInOutMode; relojResponseItem.IdwWorkcode = idwWorkcode; relojResponse.Add(relojResponseItem); } } //SAVE IN DATABASE. SaveInDataBase(pRid, relojResponse); if (vClean) { //Logger.GetInstance().AddLog(true, "clkZKSoft()", "BLOQUE COMENTADO: Vaciar Reloj " + pNro + " Ip: " + pDir + ":" + pPor); Logger.GetInstance().AddLog(true, "clkZKSoft()", "Vaciar Reloj " + pNro + " Ip: " + pDir + ":" + pPor); if (Reloj.ClearGLog(pNro)) { Reloj.RefreshData(pNro); Logger.GetInstance().AddLog(true, "clkZKSoft()", "Se vació RelojId " + pNro + " Ip: " + pDir + ":" + pPor); } else { int idwErrorCode = 0; Reloj.GetLastError(idwErrorCode); Logger.GetInstance().AddLog(false, "clkZKSoft()", "Error al vaciar " + pDir + ":" + pPor + " " + idwErrorCode); } } } else { Logger.GetInstance().AddLog(true, "clkZKSoft()", "No hay fichadas en " + pDir + ":" + pPor); } Logger.GetInstance().AddLog(true, "clkZKSoft()", "Desconectar Reloj " + pDir + ":" + pPor); Reloj.Disconnect(); clkZKSoft = true; } else { Logger.GetInstance().AddLog(true, "clkZKSoft()", "Sin conexión a " + pDir + ":" + pPor); } } catch (Exception ex) { Logger.GetInstance().AddLog(false, "clkZKSoft()", ex.Message); } return(clkZKSoft); }