diff --git a/DevicePolling/Attendance/AttendanceDAO.cs b/DevicePolling/Attendance/AttendanceDAO.cs index 4a9602c..5708fba 100644 --- a/DevicePolling/Attendance/AttendanceDAO.cs +++ b/DevicePolling/Attendance/AttendanceDAO.cs @@ -51,6 +51,8 @@ namespace ZktecoAttendenceService { if (attendanceLogs == null || attendanceLogs.Count == 0) return; + + // Start building the INSERT statement StringBuilder queryBuilder = new StringBuilder("INSERT INTO attendance_log (ac_no, checktime, processed, machine_id, in_out_type_id, machine_ip, date) VALUES "); @@ -69,6 +71,7 @@ namespace ZktecoAttendenceService { cmd.ExecuteNonQuery(); } + } } } diff --git a/DevicePolling/AttendanceMachine/AttendanceMachineDAO.cs b/DevicePolling/AttendanceMachine/AttendanceMachineDAO.cs index 08cb50c..9094916 100644 --- a/DevicePolling/AttendanceMachine/AttendanceMachineDAO.cs +++ b/DevicePolling/AttendanceMachine/AttendanceMachineDAO.cs @@ -12,7 +12,7 @@ namespace ZktecoAttendenceService public void update(AttendanceMachine attendanceMachine, MySqlConnection connection) { - connection.Open(); + string query = "UPDATE `hrms`.`attendance_machine` SET `machine_ip` = @machine_ip, `port_number` = @port_number, `machine_name` = @machine_name, `site_id` = @site_id, `status` = @status, `last_sync_date` = @last_sync_date WHERE `machine_id` = @machine_id"; MySqlCommand cmd = new MySqlCommand(query, connection); cmd.Parameters.AddWithValue("@machine_ip", attendanceMachine.MachineIp); @@ -24,7 +24,7 @@ namespace ZktecoAttendenceService cmd.Parameters.AddWithValue("@machine_id", attendanceMachine.MachineId); cmd.ExecuteNonQuery(); - connection.Close(); + } public void updateColony(AttendanceMachine attendanceMachine, MySqlConnection connection) { diff --git a/DevicePolling/MachineUsers/AttendanceMachineUserDAO.cs b/DevicePolling/MachineUsers/AttendanceMachineUserDAO.cs index 65d5f61..93f0bfe 100644 --- a/DevicePolling/MachineUsers/AttendanceMachineUserDAO.cs +++ b/DevicePolling/MachineUsers/AttendanceMachineUserDAO.cs @@ -133,7 +133,9 @@ namespace ZktecoAttendenceService axCZKEM1.Disconnect(); } else - { } + { + + } } @@ -216,20 +218,19 @@ namespace ZktecoAttendenceService public void UpdateTotalEmpInMachines(string machine_id, int total_users, MySqlConnection connection) { - connection.Open(); + string query = "UPDATE `hrms`.`attendance_machine` SET `total_users` =" + total_users + " WHERE `machine_id` = '" + machine_id + "'"; MySqlCommand cmd = new MySqlCommand(query, connection); cmd.ExecuteNonQuery(); - connection.Close(); + } public void UpdateFlag_InMachineUsers(string machine_id, string serial_no, MySqlConnection connection) { - connection.Open(); string query = "UPDATE `hrms`.`attendance_machine_user` SET `is_deleted` = 1 WHERE `machine_id` = '" + machine_id + "' and serial_number = " + serial_no + ""; MySqlCommand cmd = new MySqlCommand(query, connection); cmd.ExecuteNonQuery(); - connection.Close(); + } } } diff --git a/DevicePolling/Polling.cs b/DevicePolling/Polling.cs index c6dd784..2d39b16 100644 --- a/DevicePolling/Polling.cs +++ b/DevicePolling/Polling.cs @@ -25,7 +25,11 @@ namespace ZktecoAttendenceService WriteToTxtFile WriteFile_obj = new WriteToTxtFile(); + public zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass(); + + + private bool bIsConnected = false;//the boolean value identifies whether the device is connected private int iMachineNumber = 0;//the serial number of the device.After connecting the device ,this value will be changed. DataTable dtMachines = new DataTable(); @@ -59,6 +63,8 @@ namespace ZktecoAttendenceService public List StartPooling() { + try + { List responses = new List(); AttendanceMachineDAO attendanceMachineDAO = new AttendanceMachineDAO(); AttendanceMachineUserDAO attendanceMachineUserDAO = new AttendanceMachineUserDAO(); @@ -72,7 +78,7 @@ namespace ZktecoAttendenceService foreach (var machine in machines) { - // if (machine.MachineIp == "192.168.85.202") + //if (machine.MachineIp == "192.168.52.16") { bool isConnected = axCZKEM1.Connect_Net(machine.MachineIp, Convert.ToInt32(machine.PortNumber)); if (isConnected) @@ -82,17 +88,10 @@ namespace ZktecoAttendenceService if (machine.MachineId != "100") { - - //Saving the templates to the database - SaveTemplateDb saveTemplateDb = new SaveTemplateDb(); - saveTemplateDb.InsertFaceIntoDb(machine, connection,axCZKEM1); - - - machine.Status = "SYNCING"; attendanceMachineDAO.update(machine, connection); - responses.AddRange(poolMachineData(machine.MachineIp, machine.PortNumber, Convert.ToInt16(machine.MachineId))); + responses.AddRange(poolMachineData(machine.MachineIp, machine.PortNumber, Convert.ToInt16(machine.MachineId), connection)); machine.Status = "IDLE"; DateTime now = DateTime.Now.AddMinutes(-5); @@ -111,8 +110,9 @@ namespace ZktecoAttendenceService responses.AddRange(newResponses); } - - + //Saving the templates to the database + //SaveTemplateDb saveTemplateDb = new SaveTemplateDb(); + //saveTemplateDb.InsertFaceIntoDb(machine, connection,axCZKEM1); empList = new List(); axCZKEM1.EnableDevice(Convert.ToInt32(machine.MachineId), true); @@ -147,6 +147,12 @@ namespace ZktecoAttendenceService } return responses; + } + catch + { + Exception ex = new Exception(); + return null; + } } public List poolMachineDataColony(string ip, int port, int machineId) @@ -222,7 +228,8 @@ namespace ZktecoAttendenceService } } - public List poolMachineData(string ip, int port, int machineId) + int errorCode = 0; + public List poolMachineData(string ip, int port, int machineId, MySqlConnection connection) { List responses = new List(); List attendanceLogs = new List(); @@ -239,8 +246,22 @@ namespace ZktecoAttendenceService try { + + DateTime today = DateTime.Today; + DateTime startTime = new DateTime(today.Year, today.Month, today.Day, 4, 0, 0); // 4:00 AM + DateTime endTime = new DateTime(today.Year, today.Month, today.Day, 16, 0, 0); // 4:00 PM + + string startTimeFormatted = startTime.ToString("yyyy-MM-dd HH:mm:ss"); + string endTimeFormatted = endTime.ToString("yyyy-MM-dd HH:mm:ss"); + + + + //if(axCZKEM1.ReadGeneralLogData(machineId)) + + if(axCZKEM1.ReadAllGLogData(machineId)) + // Connect and read attendance records - if (axCZKEM1.ReadAllGLogData(machineId)) // read all the attendance records into memory + //if (axCZKEM1.ReadTimeGLogData(machineId, startTimeFormatted, endTimeFormatted)) // read all the attendance records into memory { while (axCZKEM1.SSR_GetGeneralLogData(machineId, out sdwEnrollNumber, out idwVerifyMode, out idwInOutMode, out idwYear, out idwMonth, out idwDay, out idwHour, out idwMinute, out idwSecond, ref idwWorkcode)) // get records from memory @@ -252,32 +273,39 @@ namespace ZktecoAttendenceService // Optionally log the retrieved record responses.Add($"MACHINE: {ip}, EMP NO: {sdwEnrollNumber}, TIME: {date}"); } - - // Perform bulk insert for all records + + // Perform bulk insert for all records2 try { if (attendanceLogs.Count > 0) { attendanceDAO.BulkInsert(attendanceLogs, connection); // Bulk insert method responses.Add($"Successfully inserted {attendanceLogs.Count} records for MACHINE: {ip}"); + // Clear logs from the machine + axCZKEM1.ClearGLog(machineId); } else { responses.Add($"MACHINE: {ip} - No attendance logs found."); } + + } catch (Exception ex) { responses.Add($"Error during bulk insert: {ex.Message}"); } - // Clear logs from the machine - axCZKEM1.ClearGLog(machineId); + + + } else { + axCZKEM1.GetLastError(ref errorCode); // Get the last error code responses.Add($"MACHINE: {ip} - No data available."); - } + //MessageBox.Show(errorCode.ToString()); +; } return responses; } diff --git a/DevicePolling/SaveTemplate/SaveTemplateDb.cs b/DevicePolling/SaveTemplate/SaveTemplateDb.cs index a769c13..3fdcd31 100644 --- a/DevicePolling/SaveTemplate/SaveTemplateDb.cs +++ b/DevicePolling/SaveTemplate/SaveTemplateDb.cs @@ -53,8 +53,8 @@ namespace ZktecoAttendenceService } - axCZKEM1.EnableDevice(machineNo, true); - axCZKEM1.Disconnect(); + //axCZKEM1.EnableDevice(machineNo, true); + //axCZKEM1.Disconnect(); SaveInDb(empTemplateList, connection); @@ -99,7 +99,7 @@ namespace ZktecoAttendenceService Console.WriteLine("Employee already exist"); } } - connection.Close(); + } public (long EmpExist, long TemplateExist) CheckEmpInDb(string empId, MySqlConnection connection) diff --git a/DevicePolling/ZktecoAttendenceService.csproj b/DevicePolling/ZktecoAttendenceService.csproj index 7156e46..42fcab6 100644 --- a/DevicePolling/ZktecoAttendenceService.csproj +++ b/DevicePolling/ZktecoAttendenceService.csproj @@ -62,7 +62,8 @@ False - D:\UtilityForFingerIdentity\bin\Debug\Interop.zkemkeeper.dll + False + bin\Debug\Interop.zkemkeeper.dll ..\packages\K4os.Compression.LZ4.1.3.5\lib\net462\K4os.Compression.LZ4.dll diff --git a/DevicePolling/bin/Debug/DevicePolling.exe b/DevicePolling/bin/Debug/DevicePolling.exe index 95103bb..0476703 100644 Binary files a/DevicePolling/bin/Debug/DevicePolling.exe and b/DevicePolling/bin/Debug/DevicePolling.exe differ diff --git a/DevicePolling/bin/Debug/DevicePolling.pdb b/DevicePolling/bin/Debug/DevicePolling.pdb index aa77aed..dcd49d3 100644 Binary files a/DevicePolling/bin/Debug/DevicePolling.pdb and b/DevicePolling/bin/Debug/DevicePolling.pdb differ diff --git a/DevicePolling/bin/Debug/Interop.zkemkeeper.dll b/DevicePolling/bin/Debug/Interop.zkemkeeper.dll index 854f844..57d45ad 100644 Binary files a/DevicePolling/bin/Debug/Interop.zkemkeeper.dll and b/DevicePolling/bin/Debug/Interop.zkemkeeper.dll differ diff --git a/DevicePolling/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/DevicePolling/obj/Debug/DesignTimeResolveAssemblyReferences.cache index 78eb585..e84a4b7 100644 Binary files a/DevicePolling/obj/Debug/DesignTimeResolveAssemblyReferences.cache and b/DevicePolling/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/DevicePolling/obj/Debug/DevicePolling.exe b/DevicePolling/obj/Debug/DevicePolling.exe index 95103bb..0476703 100644 Binary files a/DevicePolling/obj/Debug/DevicePolling.exe and b/DevicePolling/obj/Debug/DevicePolling.exe differ diff --git a/DevicePolling/obj/Debug/DevicePolling.pdb b/DevicePolling/obj/Debug/DevicePolling.pdb index aa77aed..dcd49d3 100644 Binary files a/DevicePolling/obj/Debug/DevicePolling.pdb and b/DevicePolling/obj/Debug/DevicePolling.pdb differ diff --git a/DevicePolling/obj/Debug/ZktecoAttendenceService.csproj.AssemblyReference.cache b/DevicePolling/obj/Debug/ZktecoAttendenceService.csproj.AssemblyReference.cache index c7fd9df..caf002c 100644 Binary files a/DevicePolling/obj/Debug/ZktecoAttendenceService.csproj.AssemblyReference.cache and b/DevicePolling/obj/Debug/ZktecoAttendenceService.csproj.AssemblyReference.cache differ