private void Timer_Elapsed(object sender, ElapsedEventArgs e) { if (interval > 0) { timer.Stop(); timer.Interval = interval; timer.Start(); } DateTime date = DateTime.Now; //Get current date time //Write log start job: logUtil.WriteLog(""); logUtil.WriteLog("Job started"); AAMLib.DevideInfoLib devLib = new AAMLib.DevideInfoLib(ConnStr); DBLib dbLib = new DBLib(ConnStrCC); //Get list device List <DeviceInfo> listDevice = devLib.GetListDevice(); if (listDevice.Count > 0) { logUtil.WriteLog(""); for (int i = 0; i < listDevice.Count; i++) { UserAttLib attendanceLib = new UserAttLib(listDevice[i].DeviceName, listDevice[i].DeviceIP, listDevice[i].DevicePort, listDevice[i].DeviceID, listDevice[i].LastAccessDateTime); date = DateTime.Now; List <AttendanceInfo> lAttInfo = attendanceLib.GetAttInfoByDate(); if (lAttInfo == null) { continue; } if (lAttInfo.Count() > 0) { logUtil.WriteLog("New records found: " + lAttInfo.Count()); dbLib.InsertAttLog(lAttInfo); //Insert att log to database devLib.Update_DuLieuDocLanCuoi(listDevice[i].DeviceID, date); //Update DuLieuDocLanCuoi } else { logUtil.WriteLog("No new record found"); } } dbLib.ExecStoreUpdateNhanVienID(); //update employeeid } }
private void btnGetAttLogFromDevice_Click(object sender, EventArgs e) { DateTime date = DateTime.Now.AddDays(-2); if (listDevice.Items.Count > 0) { foreach (ListViewItem item in listDevice.Items) { UserAttLib attendanceLib = new UserAttLib(item.SubItems[1].Text, item.SubItems[2].Text, Convert.ToInt16(item.SubItems[3].Text), Convert.ToInt16(item.SubItems[0].Text), date); List <AttendanceInfo> lAttInfo = attendanceLib.GetAttInfoByDate(); if (lAttInfo == null) { continue; } if (lAttInfo.Count() > 0) { Console.WriteLine("Total att logs count: " + lAttInfo.Count()); DBLib dbLib = new DBLib(""); //dbLib.InsertAttLog(lAttInfo); } } using (SqlConnection con = new SqlConnection(ConnStrCC)) { con.Open(); try { string sql = "DECLARE @RC int EXECUTE @RC = [dbo].[UpdateNhanVienID] "; using (SqlCommand command = new SqlCommand(sql, con)) { command.ExecuteNonQuery(); } } catch (Exception Ex) { MessageBox.Show(Ex.Message.ToString()); } finally { con.Close(); } } } }
private void btnGetAttLog_Click(object sender, EventArgs e) { DateTime date = DateTime.Now; bIsConnected = connLib.ConnectDev(txtIP.Text, Convert.ToInt16(txtPort.Text)); Console.WriteLine("Connected status: " + bIsConnected.ToString()); connLib.DisconnectDev(); Console.WriteLine("Connected status: Disconnected"); UserAttLib attendanceLib = new UserAttLib("DeviceName", txtIP.Text, Convert.ToInt16(txtPort.Text), Convert.ToInt16(txtDeviceID.Text), date); List <AttendanceInfo> lAttInfo = attendanceLib.GetAttInfoByDate(); if (lAttInfo.Count() > 0) { Console.WriteLine("Total att logs count: " + lAttInfo.Count()); DBLib dbLib = new DBLib(""); dbLib.InsertAttLog(lAttInfo); MessageBox.Show("Insert completed"); } }