private void bwLoadFingerPrints_DoWork(object sender, DoWorkEventArgs e) { if (fingerPrintDB != null) { e.Cancel = true; return; } fingerPrintDB = new List<Customer>(); if (AccountManage.customerDT == null) { AccountManage.customerDT = new CustomerTableAdapter().GetData(); } foreach (DataRow row in AccountManage.customerDT.Rows) { if (row.Field<bool>("IsActive") && row.Field<byte[]>("FingerPrintIMG") != null && row.Field<string>("TypeShortName") != "DF") { Customer customer = new Customer() { Username = row.Field<string>("Username"), TypetShortName = row.Field<string>("TypeShortName"), MealValue = row.Field<int>("MealValue"), CanDebt = row.Field<bool>("CanDebt"), CanEatMore = row.Field<bool>("CanEatMore"), MoreMealValue = row.Field<int?>("MoreMealValue") }; Fingerprint fp = new Fingerprint(); MemoryStream ms = new MemoryStream(row.Field<byte[]>("FingerPrintIMG")); Image returnImage = Image.FromStream(ms); fp.AsBitmap = (Bitmap)returnImage; customer.Fingerprints.Add(fp); afis.Extract(customer); fingerPrintDB.Add(customer); } } e.Result = e.Argument; }
private void bwStart_DoWork(object sender, DoWorkEventArgs e) { DeviceModel device = e.Argument as DeviceModel; try { string path = Application.StartupPath; BackgroundWorker bw = device.backgroundWokder; if (device.scheduleMealSetDetailID != null) { DeviceControl.setLCDText(device.serial, "Phuc vu suat: " + device.mealSetLabel.ToString()); } else { DeviceControl.setLCDText(device.serial, "Phuc vu suat\ntu do"); } while (true) { Customer cus = new Customer(); string IMGPath = DeviceControl.getImage(device.scannerAddress, bw); if (bw.CancellationPending) { DeviceControl.setLCDText(device.serial, "Da dung lai."); } if (IMGPath == null) { return; } Fingerprint fp = new Fingerprint(); fp.AsBitmapSource = new BitmapImage(new Uri(IMGPath, UriKind.RelativeOrAbsolute)); cus.Fingerprints.Add(fp); afis.Extract(cus); Customer matchCus = afis.Identify(cus, fingerPrintDB).FirstOrDefault() as Customer; if (matchCus == null) { DeviceControl.setLCDText(device.serial, "Khong tim thay\nvan tay phu hop"); Thread.Sleep(500); DeviceControl.setLED(device.serial, 1, true); Thread.Sleep(1500); DeviceControl.setLED(device.serial, 1, false); } else { Bill bill = DataAccess.PayForFood(matchCus, device.eatMoreFlag, device.scheduleMealSetDetailID, device.mealSetName); DeviceControl.setLCDText(device.serial, matchCus.TypetShortName + ":" + matchCus.Username + "\n" + bill.alert); device.eatMoreFlag = false; MainForm.transactionViewForm.AddRow(bill); if (bill.isSuccess) { IncreaseTransactinCount(); DeviceControl.setLED(device.serial, 2, true); } else { DeviceControl.setLED(device.serial, 1, true); } Thread.Sleep(1500); if (bill.isSuccess) { DeviceControl.setLED(device.serial, 2, false); } else { DeviceControl.setLED(device.serial, 1, false); } } } } catch (Exception ex) { MessageBox.Show("Có lỗi khi lấy vân tay."); Log.ErrorLog(ex.Message); return; } }
internal static Bill PayForFood(Customer customer, bool eatMoreFlag, int? scheduleMealSetDetailID, string mealSetName) { UserInfoTableAdapter userInfoTA = new UserInfoTableAdapter(); DataTable userInfo = userInfoTA.GetUserInfoWithoutFingerPrint(customer.Username); if (userInfo.Rows.Count != 1) { throw new Exception("Can't get User Info."); } DateTime lastUpdatedMoney = userInfo.Rows[0].Field<DateTime>("LastUpdatedMoney"); int amountOfMoney = userInfo.Rows[0].Field<int>("AmountOfMoney"); TransactionHistoryTableAdapter transactionHistoryTA = new TransactionHistoryTableAdapter(); int? sumOfMoney = transactionHistoryTA.GetCurrentMoney(customer.Username, lastUpdatedMoney); if (sumOfMoney == null) { sumOfMoney = 0; } int curMoney = sumOfMoney.Value + amountOfMoney; int payMoney = customer.MealValue; bool isEatMore = false; if (customer.CanEatMore && eatMoreFlag && customer.MoreMealValue != null) { payMoney += customer.MoreMealValue.Value; isEatMore = true; } int remainMoney = curMoney - payMoney; if (remainMoney < 0) { if (!customer.CanDebt) { return new Bill() { alert = "TK da het tien", isSuccess = false }; } } DateTime insertedDate = DateTime.Now; string transactionContent = isEatMore ? "Ăn thêm + " + customer.MoreMealValue.Value : "Ăn"; string TransactionHistoryIDStr = transactionHistoryTA.InsertScalar(customer.Username, 1, (-1) * payMoney, transactionContent , scheduleMealSetDetailID, true, insertedDate, CTMF_Desktop_App.Forms.MainForm.username, insertedDate).ToString(); int TransactionHistoryID = int.Parse(TransactionHistoryIDStr); XmlSync.SaveTransactionHistoryXml(TransactionHistoryID, customer.Username, 1, (-1) * payMoney, transactionContent , scheduleMealSetDetailID, true, insertedDate, CTMF_Desktop_App.Forms.MainForm.username, insertedDate); return new Bill() { username = customer.Username, transactionContent = transactionContent, mealSetName = mealSetName, insertedDate = insertedDate, isSuccess = true, alert = "Con lai:" + remainMoney }; }