having a problem with ZK SDK download -cannot get the whole log file

Oct 16 2020 11:40 AM
Dear Sir,
 
I am writing a windows service to get attendance log from attendance machine , I am using Visual Studio 2015
and I am working on windows 10 64 bit , the reference file name is ZKEUEmKeeperNet.dll version 1.0.0.0
runtime version v2.0.50727 actually I am facing 2 problems :
 
1- I am getting partial log : I mean not all punch transactions appear (I am taking this data to DB Oracle )!!!!
I tried I do not know why but I have removed the DB connection code and trying to write the data directly to harddisk using writetofile function
2- I am not getting the log file on harddisk this is not an SDK problem as I think this problem happened recently I do not know why!!
 
any suggestions for this problem or is the database connection with oracle caused a problem or the Onstart service time caused a problem I am running the service every 10 seconds and if I increased the time problems happen like if I make it every 100 seconds, please I need support it is taking too much time, thanks in advance
below is my code:
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Diagnostics;  
  6. using System.Linq;  
  7. using System.ServiceProcess;  
  8. using System.Text;  
  9. using System.Timers;  
  10. using System.IO;  
  11. using System.Threading.Tasks;  
  12. using Oracle.ManagedDataAccess.Client;  
  13. using Oracle.ManagedDataAccess;  
  14. namespace Att_Service2  
  15. {  
  16. public partial class Service1 : ServiceBase  
  17. {  
  18. ZkSoftwareEU.CZKEUEMNetClass axCZKEM1 = new ZkSoftwareEU.CZKEUEMNetClass();  
  19. private bool bIsConnected = false;//the boolean value identifies whether the device is connected  
  20. private int iMachineNumber = 1;//the serial number of the device.After connecting the device ,this value will be changed.  
  21. Timer timer = new Timer(); // name space(using System.Timers;)  
  22. string sdwEnrollNumber = "";  
  23. int idwTMachineNumber = 0;  
  24. int idwEMachineNumber = 0;  
  25. int idwVerifyMode = 0;  
  26. int idwInOutMode = 0;  
  27. int idwYear = 0;  
  28. int idwMonth = 0;  
  29. int idwDay = 0;  
  30. int idwHour = 0;  
  31. int idwMinute = 0;  
  32. int idwSecond = 0;  
  33. int idwWorkcode = 0;  
  34. int idwErrorCode = 0;  
  35. int iGLCount = 0;  
  36. int iIndex = 0;  
  37. public Service1()  
  38. {  
  39. InitializeComponent();  
  40. }  
  41. protected override void OnStart(string[] args)  
  42. {  
  43. // WriteToFile("Service is started at " + DateTime.Now);  
  44. timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);  
  45. timer.Interval = 10000; //10 seconds  
  46. timer.Enabled = true;  
  47. }  
  48. protected override void OnStop()  
  49. {  
  50. // WriteToFile("Service is stopped at " + DateTime.Now);  
  51. }  
  52. public void WriteToFile(string Message)  
  53. {  
  54. string path = "D:\\Logs";  
  55. if (!Directory.Exists(path))  
  56. {  
  57. Directory.CreateDirectory(path);  
  58. }  
  59. //AppDomain.CurrentDomain.BaseDirectory +  
  60. string filepath = "D:\\Logs\\ServiceLog_" + DateTime.Now.Date.ToShortDateString().Replace('/''_') + ".txt";  
  61. if (!File.Exists(filepath))  
  62. {  
  63. // Create a file to write to.  
  64. using (StreamWriter sw = File.CreateText(filepath))  
  65. {  
  66. sw.WriteLine(Message);  
  67. }  
  68. }  
  69. else  
  70. {  
  71. using (StreamWriter sw = File.AppendText(filepath))  
  72. {  
  73. sw.WriteLine(Message);  
  74. }  
  75. }  
  76. }  
  77. private void OnElapsedTime(object source, ElapsedEventArgs e)  
  78. {  
  79. ZkSoftwareEU.CZKEUEMNetClass axCZKEM1 = new ZkSoftwareEU.CZKEUEMNetClass();  
  80. string TNS;  
  81. string IP;  
  82. //data in file should be like  
  83. //DATA SOURCE = 192.168.2.240:1521 / ORCL; USER ID = XXXXX; Password = YYYYY-192.168.2.74-  
  84. string totalData = File.ReadAllText(@"c:\Data\Att1.txt"); //read information for attendance Machine1  
  85. try  
  86. {  
  87. int index = totalData.IndexOf("-");  
  88. int lastindex = totalData.LastIndexOf("-");  
  89. int IPlength = lastindex - index - 1;  
  90. TNS = totalData.Substring(0, index).ToString().Trim();  
  91. IP = totalData.Substring(index + 1, IPlength).ToString().Trim();  
  92. }  
  93. catch (Exception ex) { WriteToFile("No file exist or revise the format to be like DATA SOURCE = 192.168.2.240:1521 / ORCL; USER ID = ASCON; Password = ASCON-192.168.2.74- the file path is c:\\data\\Att1.txt");return;}  
  94. /////////////////////////////////////////////////////////////////////////////////////  
  95. string sdwEnrollNumber = "";  
  96. int idwTMachineNumber = 0;  
  97. int idwEMachineNumber = 0;  
  98. int idwVerifyMode = 0;  
  99. int idwInOutMode = 0;  
  100. int idwYear = 0;  
  101. int idwMonth = 0;  
  102. int idwDay = 0;  
  103. int idwHour = 0;  
  104. int idwMinute = 0;  
  105. int idwSecond = 0;  
  106. int idwWorkcode = 0;  
  107. int idwErrorCode = 0;  
  108. int iGLCount = 0;  
  109. int iIndex = 0;  
  110. int Port = 4370;  
  111. bool bIsConnected;  
  112. int iMachineNumber = 1;  
  113. string insertSQL;  
  114. //3- Get Data From Attandance Machine  
  115. try  
  116. {  
  117. while (axCZKEM1.Connect_Net(IP, Port) != true) ;//****New check connection TCP  
  118. WriteToFile("Connected to attendance "+DateTime.Now.ToString());  
  119. axCZKEM1.EnableDevice(iMachineNumber, false);//disable the device today  
  120. WriteToFile("Device Disabled " + DateTime.Now.ToString());  
  121. while (axCZKEM1.ReadGeneralLogData(iMachineNumber) != true) ;//**New i added a loop instead of if  
  122. WriteToFile("Begin Loop " + DateTime.Now.ToString());  
  123. while (axCZKEM1.SSR_GetGeneralLogData(iMachineNumber, ref sdwEnrollNumber, ref idwVerifyMode,  
  124. ref idwInOutMode, ref idwYear, ref idwMonth, ref idwDay, ref idwHour, ref idwMinute, ref idwSecond, ref idwWorkcode))//get records from the memory  
  125. {  
  126. // //insert into Oracle DB  
  127. DateTime Date = Convert.ToDateTime(idwYear.ToString() + "-" + idwMonth.ToString() + "-" + idwDay.ToString() + " " + idwHour.ToString() + ":" + idwMinute.ToString() + ":" + idwSecond.ToString());  
  128. // WriteToFile(Date);  
  129. //MessageBox.Show(iMachineNumber + "-" + sdwEnrollNumber + "-" + Date);  
  130. /*Commented on 18-7-2020  
  131. WriteToFile(iMachineNumber+"-"+ sdwEnrollNumber+"-"+ idwInOutMode+"-"+ Date);  
  132. */  
  133. // MessageBox.Show("inserted Successfully");  
  134. }//end while  
  135. }//end try  
  136. catch (Exception ex)  
  137. {  
  138. WriteToFile("error " + ex.ToString()+ " at "+DateTime.Now.ToString() );  
  139. }//today  
  140. }//end function  
  141. }//end class  
  142. }//end namespace  

Answers (1)