/// <summary> /// 同步卡机时间 /// </summary> /// <returns></returns> public ResultSet SyncDeviceTime() { ResultSet result = new ResultSet(); int successCount = 0; int errorCount = 0; try { IList <string> providingList = Common.GetDeviceList(); for (int i = 0; i < providingList.Count(); i++) { if (Connect(providingList[i])) { if (axCZKEM1.SetDeviceTime(iMachineNumber)) { log.Debug("sync device [" + providingList[i] + "] is ok."); successCount++; } else { log.Debug("sync device [" + providingList[i] + "] is fail."); errorCount++; } Close(); } } } catch (Exception ex) { log.Fatal(ex); _resultset = new ResultSet { SeccessFlag = false, Result = ErrorCode.ToString(), Description = string.Format("Try Catched Error {0}", ex.Message) }; } return(new ResultSet { SeccessFlag = true, Result = ErrorCode.ToString(), Description = string.Format("Success Count{0}, Error Count {1}", successCount.ToString(), errorCount.ToString()) }); }
public bool SyncTime() { bool result = false; MyLogger.GetInstance.Info("ZKDevice.SyncTime() Device IP: " + this.Device.IP); MyLogger.GetInstance.Info("ZKDevice.SyncTime() - The process for Sync devices is currently running"); ConnectDevice(); if (bIsConnected) { int idwErrorCode = 0; //this line get the local time and update the biometric device if (axCZKEM1.SetDeviceTime(iMachineNumber)) { MyLogger.GetInstance.Debug("ZKDevice.SyncTime() - Syncing ZK devices at " + DateTime.Now); if (axCZKEM1.RefreshData(iMachineNumber)) //the data in the device should be refreshed { MyLogger.GetInstance.Debug("ZKDevice.SyncTime() - Successfully set the time of the machine and the terminal to sync PC! "); } int idwYear = 0; int idwMonth = 0; int idwDay = 0; int idwHour = 0; int idwMinute = 0; int idwSecond = 0; result = true; try { if (axCZKEM1.GetDeviceTime(iMachineNumber, ref idwYear, ref idwMonth, ref idwDay, ref idwHour, ref idwMinute, ref idwSecond))//show the time { var device = context.Devices.Find(Device.DeviceId); device.SyncDate = DateTime.Parse(idwYear.ToString() + "-" + idwMonth.ToString() + "-" + idwDay.ToString() + " " + idwHour.ToString() + ":" + idwMinute.ToString() + ":" + idwSecond.ToString()); //var device = context.Devices.Find(de) context.Entry(device).State = EntityState.Modified; context.SaveChanges(); } } catch (Exception e) { MyLogger.GetInstance.Error("ZKDevice.SyncTime() - Sync operation failed ", e); } } else { axCZKEM1.GetLastError(ref idwErrorCode); MyLogger.GetInstance.Error("ZKDevice.SyncTime() - Sync operation failed, ErrorCode=" + idwErrorCode.ToString()); } } DisconnectDevice(); return(result); }