added clearlog after successful data post

main
muhammad.faique 2025-04-04 12:29:30 +05:00
parent fc3823feb8
commit 6b03af550f
5 changed files with 60 additions and 45 deletions

View File

@ -80,7 +80,7 @@ namespace ZktecoAttendenceService
foreach (var machine in machines)
{
//if (machine.MachineIp == "192.168.50.8")
if (machine.MachineIp == "192.168.50.8")
{
bool isConnected = axCZKEM1.Connect_Net(machine.MachineIp, Convert.ToInt32(machine.PortNumber));
if (isConnected)
@ -160,75 +160,90 @@ namespace ZktecoAttendenceService
public List<string> poolMachineDataColony(string ip, int port, int machineId, MySqlConnection connection)
{
List<string> responses = new List<string>();
int idwErrorCode = 0;
int countAttendance = 0;
bool allRecordsSaved = true; // Flag to track if all records are saved successfully
string mPath = string.Empty;
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;
int CountAttendance = 0;
//Cursor = Cursors.WaitCursor;
//Bconnect = axCZKEM1.Connect_Net(ip, Convert.ToInt32(port));
//axCZKEM1.EnableDevice(machineId, false);//disable the device
// Ensure axCZKEM1 is initialized before using it
if (axCZKEM1 == null)
{
responses.Add($"MACHINE: {ip} - ERROR: SDK Not Initialized");
return responses;
}
try
{
//axCZKEM1.RegEvent(Convert.ToInt32(machineId), 65535);//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
if (axCZKEM1.ReadAllGLogData(machineId))//read all the attendance records to the memory
// Connect to the machine
bool isConnected = axCZKEM1.Connect_Net(ip, port);
if (!isConnected)
{
axCZKEM1.GetLastError(ref idwErrorCode);
responses.Add($"MACHINE: {ip} - ERROR: Unable to connect (Code {idwErrorCode})");
return responses;
}
// Disable the device during data retrieval
axCZKEM1.EnableDevice(machineId, false);
string sdwEnrollNumber;
int idwVerifyMode, idwInOutMode, idwYear, idwMonth, idwDay, idwHour, idwMinute, idwSecond, idwWorkcode = 0;
if (axCZKEM1.ReadAllGLogData(machineId)) // Read all attendance logs
{
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 the memory
out idwInOutMode, out idwYear, out idwMonth, out idwDay, out idwHour, out idwMinute, out idwSecond, ref idwWorkcode))
{
DateTime date = new DateTime(idwYear, idwMonth, idwDay, idwHour, idwMinute, idwSecond);
try
{
DateTime date = new DateTime(idwYear, idwMonth, idwDay, idwHour, idwMinute, idwSecond);
Attendance log = new Attendance(sdwEnrollNumber, date, false, machineId.ToString(), "1", ip, DateTime.Now);
attendanceDAO.AddColony(log, connection);
CountAttendance++;
responses.Add("MACHINE : " + ip + " : , EMP NO : " + sdwEnrollNumber + " , TIME : " + date + "");
//return response;
countAttendance++;
responses.Add($"MACHINE: {ip} - EMP NO: {sdwEnrollNumber} - TIME: {date}");
}
catch (Exception ex)
{
responses.Add(ex.Message.ToString());
responses.Add($"MACHINE: {ip} - ERROR: {ex.Message}");
allRecordsSaved = false; // Mark as false if any record fails
}
}
// responses.Add(GetTotalFromMachine(machineId));
axCZKEM1.ClearGLog(machineId);
//axCZKEM1.EnableDevice(machineId, true);
// axCZKEM1.Disconnect();
// **Clear Attendance Logs Only If All Records Are Saved**
if (allRecordsSaved)
{
if (axCZKEM1.ClearGLog(machineId))
{
responses.Add($"MACHINE: {ip} - ATTENDANCE LOGS CLEARED SUCCESSFULLY");
}
else
{
axCZKEM1.GetLastError(ref idwErrorCode);
responses.Add($"MACHINE: {ip} - ERROR: Failed to clear logs (Code {idwErrorCode})");
}
}
else
{
responses.Add($"MACHINE: {ip} - LOGS NOT CLEARED: Some records failed to save.");
}
}
else
{
responses.Add("MACHINE : " + ip + " : NO DATA");
return responses;
axCZKEM1.GetLastError(ref idwErrorCode);
responses.Add($"MACHINE: {ip} - NO DATA (Error Code {idwErrorCode})");
}
return responses;
}
catch (Exception ex)
{
responses.Add(ex.Message.ToString());
return responses;
responses.Add($"MACHINE: {ip} - ERROR: {ex.Message}");
}
finally
{
// Re-enable the device and disconnect
axCZKEM1.EnableDevice(machineId, true);
axCZKEM1.Disconnect();
}
return responses;
}
int errorCode = 0;
public List<string> poolMachineData(string ip, int port, int machineId, MySqlConnection connection)