/// <summary> /// Nhận dữ liệu từ máy quẹt thẻ /// </summary> private void ReceiveData() { string sdwEnrollNumber = ""; //int idwTMachineNumber = 0; //int idwEMachineNumber = 0; 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 idwErrorCode = 0; int iGLCount = 0; int iIndex = 0; string CardID = string.Empty; DateTime WorkingDay = DateTime.Now; string CheckIn = string.Empty; Cursor = Cursors.WaitCursor; lvLogs.Items.Clear(); axCZKEM1.EnableDevice(iMachineNumber, false); //disable the device if (axCZKEM1.ReadGeneralLogData(iMachineNumber)) //read all the attendance records to the memory { while (axCZKEM1.SSR_GetGeneralLogData(iMachineNumber, 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 { iGLCount++; lvLogs.Items.Add(iGLCount.ToString()); lvLogs.Items[iIndex].SubItems.Add(sdwEnrollNumber);//modify by Darcy on Nov.26 2009 lvLogs.Items[iIndex].SubItems.Add(idwVerifyMode.ToString()); lvLogs.Items[iIndex].SubItems.Add(idwInOutMode.ToString()); lvLogs.Items[iIndex].SubItems.Add(idwYear.ToString() + "-" + idwMonth.ToString() + "-" + idwDay.ToString() + " " + idwHour.ToString() + ":" + idwMinute.ToString() + ":" + idwSecond.ToString()); lvLogs.Items[iIndex].SubItems.Add(idwWorkcode.ToString()); iIndex++; CardID = sdwEnrollNumber; //giờ vào // string CheckIn = str1.Substring(20,4); //ngày làm việc // DateTime WorkingDay = ConvertString2Day("20"+str1.Substring(12,6)); WorkingDay = DateTime.Parse(idwYear.ToString() + "/" + idwMonth.ToString() + "/" + idwDay.ToString()); CheckIn = idwHour.ToString() + ":" + idwMinute.ToString(); try { WriteLog.WriteTimeLog(CardID, WorkingDay.ToString("yyyyMMdd"), CheckIn); } catch { // axCZKEM1.Disconnect();//disconnect device incase exception } int employeeID = 0; DataSet dataSet = pp6750.GetEmployeeInfo(CardID); DataTable dbtable = dataSet.Tables[0]; if (dbtable.Rows.Count == 0) { ///MessageBox.Show((" Thẻ "+CardID+ " không hợp lệ !!!"),"Thông báo"); } else { foreach (DataRow dataRow in dbtable.Rows) { // Lấy mã thẻ của nhân viên vừa quẹt employeeID = (int)dataRow["EmployeeID"]; DateTime gioQuetthe = ConvertString2Time(idwHour, idwMinute); } ///// Lấy giờ quẹt thẻ //String TimeInOut = ConvertString2Time(idwHour, idwMinute).ToShortTimeString(); ///// Kiểm tra thời gian quẹt thẻ là giờ vào hay ra //string TimeIn = pp6750.GetTimeIn(employeeID, WorkingDay); ///// Lưu dữ liệu quẹt thẻ vào cơ sở dữ liệu //pp6750.SaveCardData(WorkingDay.ToString(), employeeID, TimeInOut, TimeIn); DateTime dtCheckCardTime = new DateTime(idwYear, idwMonth, idwDay, idwHour, idwMinute, idwSecond); x628.SaveCheckCardData(employeeID, dtCheckCardTime); } } //xoa du lieu sau khi doc xong if (axCZKEM1.ClearGLog(iMachineNumber)) { axCZKEM1.RefreshData(iMachineNumber);//the data in the device should be refreshed //MessageBox.Show("All att Logs have been cleared from teiminal!", "Success"); } } else { Cursor = Cursors.Default; axCZKEM1.GetLastError(ref idwErrorCode); if (idwErrorCode != 0) { MessageBox.Show("Reading data from terminal failed,ErrorCode: " + idwErrorCode.ToString(), "Error"); disconnectToDevice(); aTimer.Interval = 120000; } else { // MessageBox.Show("No data from terminal returns!", "Error"); } } axCZKEM1.EnableDevice(iMachineNumber, true);//enable the device Cursor = Cursors.Default; }
/// <summary> /// Nhận dữ liệu từ máy quẹt thẻ /// </summary> private void ReceiveData() { short temp_short = 1; string temp_string = "4800"; // SetCom.OpenCom(ref temp_short, ref temp_string); SetCom.OpenCom(ref temp_short); // thông số của máy quẹt thẻ string temp_string14 = "00"; // Độ trễ khi máy quẹt thẻ trừ bỏ đi một bản ghi int temp_int2 = 500; int RecordCount = 0; string temp = ""; // xptMessage.TableModel.Rows.Clear(); temp = SetCom.ReceiveData(ref temp_string14, ref temp_int2); if (temp.Length < 20) { RecordCount = 0; } else { try { RecordCount = int.Parse(temp.Substring(37, 4)) + 1; } catch (Exception) { //ko lam gi khi du lieu bi sai } } ///Lấy cho đến hết các bản ghi từ máy quẹt thẻ while (RecordCount > 0) { string str1 = string.Empty; string CardID = string.Empty; DateTime WorkingDay = DateTime.Now; string CheckIn = string.Empty; try { str1 = temp.Substring(temp.Length - 39, 39); // mã thẻ // string CardID = str1.Substring(4,6); CardID = "0" + str1.Substring(7, 5); //giờ vào // string CheckIn = str1.Substring(20,4); //ngày làm việc // DateTime WorkingDay = ConvertString2Day("20"+str1.Substring(12,6)); WorkingDay = ConvertString2Day("20" + str1.Substring(16, 6)); CheckIn = str1.Substring(24, 4); WriteLog.WriteTimeLog(CardID, WorkingDay.ToString("yyyyMMdd"), CheckIn); } catch {} // Lấy thông tin nhân viên dựa trên mã thẻ vừa quẹt string EmployeeName = ""; string DepartmentName = ""; string PictureFileName = ""; string PictureFileNameDefault = Application.StartupPath + "/IMAGES/noimage3.jpg"; int employeeID = 0; DataSet dataSet = pp6750.GetEmployeeInfo(CardID); DataTable dbtable = dataSet.Tables[0]; if (dbtable.Rows.Count == 0) { ///MessageBox.Show((" Thẻ "+CardID+ " không hợp lệ !!!"),"Thông báo"); } else { foreach (DataRow dataRow in dbtable.Rows) { // Lấy mã thẻ của nhân viên vừa quẹt employeeID = (int)dataRow["EmployeeID"]; if (dataRow["Picture"] != DBNull.Value) { PictureFileName = Utils.settings.PicturePath + '\\' + dataRow["Picture"].ToString(); } else { PictureFileName = PictureFileNameDefault; } EmployeeName = dataRow["EmployeeName"].ToString(); DepartmentName = dataRow["DepartmentName"].ToString(); DateTime gioQuetthe = ConvertString2Time(CheckIn); try { PopulateEmployee(count, EmployeeName, DepartmentName, CardID, WorkingDay, gioQuetthe, PictureFileName); } catch { PopulateEmployee(count, EmployeeName, DepartmentName, CardID, WorkingDay, gioQuetthe, PictureFileNameDefault); } } /// Lấy giờ quẹt thẻ String TimeInOut = ConvertString2Time(CheckIn).ToShortTimeString(); /// Kiểm tra thời gian quẹt thẻ là giờ vào hay ra string TimeIn = pp6750.GetTimeIn(employeeID, WorkingDay); /// Lưu dữ liệu quẹt thẻ vào cơ sở dữ liệu pp6750.SaveCardData(WorkingDay.ToString(), employeeID, TimeInOut, TimeIn); } count++; RecordCount--; temp = SetCom.ReceiveData(ref temp_string14, ref temp_int2); } }
/// <summary> /// Nhận dữ liệu từ máy quẹt thẻ va hien thi thong tin nhan vien len grid /// </summary> private void ReceiveData() { try { SetCom = new Protocal.Call(); short temp_short = 1; string temp_string = "4800"; // SetCom.OpenCom(ref temp_short, ref temp_string); SetCom.OpenCom(ref temp_short); // thông số của máy quẹt thẻ string temp_string14 = "00"; // Độ trễ khi máy quẹt thẻ trừ bỏ đi một bản ghi int temp_int2 = 500; int RecordCount = 0; string temp = ""; // xptMessage.TableModel.Rows.Clear(); temp = SetCom.ReceiveData(ref temp_string14, ref temp_int2); if (temp.Length < 20) { RecordCount = 0; } else { try { RecordCount = int.Parse(temp.Substring(26, 4)) + 1; } catch (Exception) { //ko lam gi khi du lieu bi sai } } ///Lấy tung ban ghi theo stack cho đến hết các bản ghi từ máy quẹt thẻ while (RecordCount > 0) { string str1 = string.Empty; string CardID = string.Empty; string CheckIn = string.Empty; DateTime WorkingDay = DateTime.Now; try { str1 = temp.Substring(temp.Length - 39, 39); // mã thẻ CardID = str1.Substring(4, 6); //giờ quet the CheckIn = str1.Substring(20, 4); //ngày làm việc WorkingDay = ConvertString2Day("20" + str1.Substring(12, 6)); WriteLog.WriteTimeLog(CardID, WorkingDay.ToString("yyyyMMdd"), CheckIn); } catch { } // Lấy thông tin nhân viên dựa trên mã thẻ vừa quẹt string EmployeeName = ""; string DepartmentName = ""; string PictureFileName = ""; string DefaultPicturePath = Application.StartupPath + "/IMAGES/noimage3.jpg"; int employeeID = 0; //lay thong tin nhan vien theo ma the nhan duoc tu may doc the DataSet dataSet = pp3750.GetEmployeeInfo(CardID); DataTable dbtable = dataSet.Tables[0]; if (dbtable.Rows.Count == 0) //ko co nhan vien nao co ma the nay` { ///MessageBox.Show((" Thẻ "+CardID+ " không hợp lệ !!!"),"Thông báo"); } else //co nhan vien trung ma the { foreach (DataRow dataRow in dbtable.Rows) { // Lấy mã thẻ của nhân viên vừa quẹt employeeID = (int)dataRow["EmployeeID"]; if (dataRow["Picture"] != DBNull.Value) //trong database co duong dan anh { PictureFileName = Utils.settings.PicturePath + '\\' + dataRow["Picture"].ToString(); } else //database chua co duong dan anh nhan vien, lay anh mac dinh { PictureFileName = DefaultPicturePath; } EmployeeName = dataRow["EmployeeName"].ToString(); DepartmentName = dataRow["DepartmentName"].ToString(); DateTime timeInOut = ConvertString2Time(CheckIn); try { //Hien thi thong tin nhan vien len Grid PopulateEmployee(count, EmployeeName, DepartmentName, CardID, WorkingDay, timeInOut, PictureFileName); } catch { //Hien thi thong tin nhan vien len Grid voi anh mac dinh PopulateEmployee(count, EmployeeName, DepartmentName, CardID, WorkingDay, timeInOut, DefaultPicturePath); } } /// Lấy giờ quẹt thẻ String TimeInOut = ConvertString2Time(CheckIn).ToShortTimeString(); /// Kiểm tra thời gian quẹt thẻ là giờ vào hay ra string TimeIn = pp3750.GetTimeIn(employeeID, WorkingDay); /// Lưu dữ liệu quẹt thẻ vào cơ sở dữ liệu pp3750.SaveCardData(WorkingDay.ToString(), employeeID, TimeInOut, TimeIn); } count++; RecordCount--; temp = SetCom.ReceiveData(ref temp_string14, ref temp_int2); } } catch (Exception ex) { Console.WriteLine(ex); } }