private void InsertCarton() { double actualWeightFirstCarton = 0; Double.TryParse(tblActualWeight.Tag.ToString(), out actualWeightFirstCarton); var modelInsert = new StoringModel() { ProductNo = productNo, Barcode = barcode, SizeNo = sizeNo, CartonNo = cartonNo, ActualWeight = actualWeightFirstCarton, GrossWeight = 0, IsComplete = completeCarton, DifferencePercent = 0, IsPass = true, IssuesId = 0, WorkerId = account.UserName, }; StoringController.Insert(modelInsert); if (completeCarton == true) { DefaultStatus(); } else { IncompleteStatus(); } // Highlight tblResult.Dispatcher.Invoke(new Action(() => { tblResult.Foreground = Brushes.White; tblResult.Text = string.Format("{0} - Add", modelInsert.CartonNo); })); brResult.Dispatcher.Invoke(new Action(() => { brResult.Background = Brushes.Green; })); StoringCurrent insertCurrent = new StoringCurrent(); insertCurrent.StoringModel = modelInsert; storingCurrentList.Add(insertCurrent); }
private void CompareWeight() { var currentCarton = new StoringModel() { ProductNo = productNo, Barcode = barcode, SizeNo = sizeNo, CartonNo = cartonNo, WorkerId = account.UserName, IsComplete = true, }; // get gross weight of the carton has same size with this carton. tblGrossWeight.Text = string.Format("{0}", firstCarton_Size_PO.ActualWeight); tblGrossWeight.Tag = string.Format("{0}", firstCarton_Size_PO.ActualWeight); double grossWeight = 0; Double.TryParse(tblGrossWeight.Tag.ToString(), out grossWeight); double actualWeight = 0; Double.TryParse(tblActualWeight.Tag.ToString(), out actualWeight); if (grossWeight <= 0) { grossWeight = actualWeight; } currentCarton.GrossWeight = grossWeight; currentCarton.ActualWeight = actualWeight; double percentDifference = actualWeight / grossWeight; tblDifferencePercent.Dispatcher.Invoke(new Action(() => tblDifferencePercent.Text = string.Format("{0}", Math.Round(100 * (percentDifference - 1), 2)) )); currentCarton.DifferencePercent = Math.Round(100 * (percentDifference - 1), 2); // if carton is OK if (percentDifference >= LIMITED_MIN && percentDifference <= LIMITED_MAX) { tblResult.Dispatcher.Invoke(new Action(() => { tblResult.Foreground = Brushes.White; tblResult.Text = string.Format("{0} - Pass", currentCarton.CartonNo); })); brResult.Dispatcher.Invoke(new Action(() => { brResult.Background = Brushes.Green; })); currentCarton.IsPass = true; currentCarton.IssuesId = 0; StoringController.Insert(currentCarton); StoringCurrent storingCurrentModel = new StoringCurrent(); storingCurrentModel.StoringModel = currentCarton; storingCurrentList.Add(storingCurrentModel); } // If current carton has problem (the weight is lower or higher than firstcarton) else { // Show highlight. if (percentDifference < LIMITED_MIN) { tblResult.Dispatcher.Invoke(new Action(() => { tblResult.Foreground = Brushes.Black; tblResult.Text = string.Format("{0} - Low", currentCarton.CartonNo); })); brResult.Dispatcher.Invoke(new Action(() => { brResult.Background = Brushes.Yellow; })); } else { tblResult.Dispatcher.Invoke(new Action(() => { tblResult.Foreground = Brushes.White; tblResult.Text = string.Format("{0} - Hi", currentCarton.CartonNo); })); brResult.Dispatcher.Invoke(new Action(() => { brResult.Background = Brushes.Red; })); } // tranfer this model to check problem, after that insert to db currentCarton.IsPass = false; Dispatcher.BeginInvoke(new Action(() => { CheckIssuesWindow window = new CheckIssuesWindow(null, currentCarton, IssuesType.Issues.IssuesCompareWeight, factory); window.ShowDialog(); StoringModel storingRecieve = window.storingCurrent; StoringCurrent storingCurrent = new StoringCurrent(); storingCurrent.StoringModel = storingRecieve; storingCurrentList.Add(storingCurrent); })); } DefaultStatus(); }
private void BarcodeProcess() { serialPortReceive.Close(); firstCarton_Size_PO = new StoringModel(); ComPortHelper.WriteToPort(portWrite, "DIO[0]:VALUE=0\r\n"); ComPortHelper.WriteToPort(portWrite, "DIO[3]:VALUE=0\r\n"); if (double.TryParse(txtMinActualWeight.Text, out minActualWeight) == false) { txtMinActualWeight.BorderBrush = Brushes.Red; } else { txtMinActualWeight.ClearValue(TextBox.BorderBrushProperty); } if (double.TryParse(txtMaxActualWeight.Text, out maxActualWeight) == false) { txtMaxActualWeight.BorderBrush = Brushes.Red; } else { txtMaxActualWeight.ClearValue(TextBox.BorderBrushProperty); } tblProductNo.Text = productNo; tblSizeItemQuantityCartonNo.Text = String.Format("Size: {0}\nCartonNo: {1} of {2}", sizeNo, cartonNo, GetMaxCarton(productNo)); // check first carton of size of productno if (completeCarton == true) { var storingCurrent_POList = storingCurrentList.Where(w => w.StoringModel.ProductNo == productNo).Select(s => s.StoringModel).ToList(); firstCarton_Size_PO = storingCurrent_POList.Where(w => w.SizeNo == sizeNo && w.IsPass == true && w.IsComplete == true).FirstOrDefault(); var firstCartonProblem = new StoringModel() { ProductNo = productNo, Barcode = barcode, SizeNo = sizeNo, CartonNo = cartonNo, WorkerId = account.UserName, ActualWeight = 0, GrossWeight = 0, DifferencePercent = 0, IsComplete = true }; if (firstCarton_Size_PO == null) { MessageBoxResult result = MessageBox.Show(string.Format("Đây Là Thùng Đầu Tiên Của Size: {0} ; PO#: {1}\n\nMở Thùng Và Kiểm Tra\n- SỐ LƯỢNG GIÀY\n- SIZE.\n\nClick OK để CÂN và tiếp tục, Nếu có vấn đề Click Cancel! ", sizeNo, productNo), "Kiểm tra thùng đầu tiên của Size", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (result == MessageBoxResult.OK) { serialPortReceive.Open(); insertFirstCarton_Size_PO = true; } if (result == MessageBoxResult.Cancel) { Dispatcher.Invoke(new Action(() => { CheckIssuesWindow window = new CheckIssuesWindow(null, firstCartonProblem, IssuesType.Issues.IssuesFirstCartonOfSizeOfPO, factory); window.ShowDialog(); StoringModel storingRecieve = window.storingCurrent; StoringCurrent storingCurrent = new StoringCurrent(); storingCurrent.StoringModel = storingRecieve; storingCurrentList.Add(storingCurrent); })); } } else { serialPortReceive.Open(); compareCartonSameSize = true; } } else { serialPortReceive.Open(); insertIncompleteCarton = true; } popInputSubPO.IsOpen = false; btnBarcodeComplete.IsEnabled = false; btnCartonNo.IsEnabled = false; }
private void bwLoad_DoWork(object sender, DoWorkEventArgs e) { storingWeighedList = StoringController.SelectIsNotLoad(); outputtedList = OutputingController.SelectIsNotLoad(); int storingIndex = 1; foreach (StoringModel storing in storingWeighedList) { var current = new StoringCurrent() { StoringModel = storing, }; storingCurrentList.Add(current); Dispatcher.Invoke(new Action(() => { tempTitle = string.Format("Downloading Carton: {0} / {1}", storingIndex, storingWeighedList.Count); this.Title = tempTitle; })); storingIndex++; } // If this carton was outputted, allow reweigh if (outputtedList.Count > 0) { var barcodeOutputedList = outputtedList.Select(s => s.Barcode).Distinct().ToList(); storingCurrentList.RemoveAll(r => barcodeOutputedList.Contains(r.StoringModel.Barcode)); } var POScannedList = storingWeighedList.Where(w => w.Barcode.Contains(",") == false).Select(s => s.ProductNo).Distinct().ToList(); // Create barcode temp int poCreatedIndex = 1; foreach (var PO in POScannedList) { var cartonNumberingDetail_POScannedList = CartonNumberingDetailController.Select(PO); // If total carton current in po equals total carton in cartonnumberingdetail. PO will be ignore. if (storingWeighedList.Where(w => w.ProductNo == PO).Count() == cartonNumberingDetail_POList.Count()) { poCreatedIndex++; continue; } var firstStoringWeighedList = storingWeighedList.Where(w => w.ProductNo == PO).FirstOrDefault(); int serialCarton_0 = ConvertBarcodeToSerial(firstStoringWeighedList.Barcode) - firstStoringWeighedList.CartonNo; int cartonIndex = 1; foreach (var cartonDetail in cartonNumberingDetail_POScannedList) { var storingTemp = new StoringTemp() { SizeNo = cartonDetail.SizeNo, ProductNo = cartonDetail.ProductNo, CartonNo = cartonDetail.CartonNo, SerialNo = serialCarton_0 + cartonDetail.CartonNo, }; storingTempList.Add(storingTemp); Dispatcher.Invoke(new Action(() => { tempTitle = String.Format("Creating Barcode: {0} of {1} for {2} / {3} PO#", cartonIndex, cartonNumberingDetail_POScannedList.Select(s => s.CartonNo).Max(), poCreatedIndex, POScannedList.Count); this.Title = tempTitle; })); cartonIndex++; } poCreatedIndex++; } }