To acquire attendance logs from a ZKTEco device using their SDK in C#, follow the steps below:
Install the ZKSoftware SDK and its dependencies on your system.
Initialize the SDK by creating an instance of the SDK class in C#.
```# zkemkeeper.CZKEMClass sdk = new zkemkeeper.CZKEMClass();
3. Connect to the ZKTEco device using the Connect_Net() method of the SDK class, which takes the IP address and port number of the device as its arguments.
```#
string ipAddress = "192.168.1.201"; // Example IP address
int port = 4370; // Example port number
bool isConnected = sdk.Connect_Net(ipAddress, port);
```# DateTime startDate = DateTime.Parse("2022-01-01 00:00:00"); // Example start time DateTime endDate = DateTime.Now; // Example end time string userId = ""; // Retrieve logs for all users int totalCount = 0;
// Call GetGeneralLogData() method to retrieve attendance logs bool isRetrieved = sdk.GetGeneralLogData(1, ref userId, ref startDate, ref endDate, ref totalCount);
5. After retrieving the logs, you can loop through the logs and extract the required data. The attendance logs can be retrieved as an array of strings, where each string represents a single attendance log.
```#
if (isRetrieved && totalCount > 0)
{
string[] attendanceLogs = new string[totalCount];
int retrievedLogs = sdk.SSR_GetGeneralLogData(1, out attendanceLogs[0], out userId, out startDate, out endDate, out logOptions, out logStatus);
for (int i = 0; i < retrievedLogs; i++)
{
// Extract the required data from the log
string[] logData = attendanceLogs[i].Split('\t');
string userId = logData[0];
DateTime attendanceTime = DateTime.Parse(logData[1]);
int verifyMode = int.Parse(logData[2]);
int verifyState = int.Parse(logData[3]);
int workCode = int.Parse(logData[4]);
Console.WriteLine($"User ID: {userId}, Attendance Time: {attendanceTime}, Verify Mode: {verifyMode}, Verify State: {verifyState}, Work Code: {workCode}");
}
}
#
sdk.Disconnect();
Note: The above code is an example, and it is advised to modify it as per the requirements of your project.
Asked: 2023-07-16 09:51:05 +0000
Seen: 11 times
Last updated: Jul 16 '23