private void buttonAddESC_Click(object sender, EventArgs e) { int firstSavedRepackID = 0; string lastSavedBarcode = ""; RepackController repackController = new RepackController(CommonNinject.Kernel.Get <IRepackService>(), this.repackViewModel); try { if (sender.Equals(this.buttonAddExit)) { foreach (var batchRepack in this.batchRepacks) { lastSavedBarcode = batchRepack.Code; RepackDTO repackDTO = new RepackDTO(); repackDTO.BatchID = this.fillingData.BatchID; repackDTO.PackID = batchRepack.PackID; repackDTO.Code = batchRepack.Code; repackDTO.SerialID = batchRepack.SerialID; if (!repackController.repackService.Save(repackDTO)) { throw new Exception(lastSavedBarcode); } else if (firstSavedRepackID == 0) { firstSavedRepackID = repackDTO.RepackID; } } this.DialogResult = DialogResult.OK; } if (sender.Equals(this.buttonESC)) { this.DialogResult = DialogResult.Cancel; } } catch (Exception exception) { if (firstSavedRepackID > 0) { repackController.repackService.RepackRollback(this.fillingData.BatchID, firstSavedRepackID); } ExceptionHandlers.ShowExceptionMessageBox(this, new Exception("Lỗi lưu barcode: " + lastSavedBarcode, exception)); } }
private void BatchRepackWizard_Load(object sender, EventArgs e) { try { this.batchRepacks = new List <BatchRepackDTO>(); List <MismatchedBarcode> mismatchedBarcodes = new List <MismatchedBarcode>(); string[] barcodes = System.IO.File.ReadAllLines(fileName); int lineIndex = 0; int mismatchedLineNo = 0; int serialID = 0; if (barcodes.Count() > 0) { RepackController repackController = new RepackController(CommonNinject.Kernel.Get <IRepackService>(), this.repackViewModel); foreach (string barcode in barcodes) { IList <BatchRepack> lookupRepacks = repackController.repackService.LookupRepacks(barcode); if (lookupRepacks != null && lookupRepacks.Count > 0) { BatchRepack batchRepack = lookupRepacks.First(); BatchRepackDTO batchRepackDTO = Mapper.Map <BatchRepack, BatchRepackDTO>(batchRepack); if (this.batchRepacks.Where(w => w.Code == batchRepackDTO.Code).Count() == 0) { if (batchRepackDTO.CommodityID == this.fillingData.CommodityID) { batchRepackDTO.LineIndex = ++lineIndex; batchRepackDTO.SerialID = ++serialID; this.batchRepacks.Add(batchRepackDTO); } else { mismatchedBarcodes.Add(new MismatchedBarcode() { LineIndex = ++mismatchedLineNo, SerialID = ++serialID, Barcode = barcode, APICode = batchRepackDTO.APICode, CommodityName = batchRepackDTO.CommodityName, Description = "Không cùng mã sản phẩm." }); } } else { mismatchedBarcodes.Add(new MismatchedBarcode() { LineIndex = ++mismatchedLineNo, SerialID = serialID, Barcode = barcode, APICode = batchRepackDTO.APICode, CommodityName = batchRepackDTO.CommodityName, Description = "Trùng mã vạch lon." }); } } else { mismatchedBarcodes.Add(new MismatchedBarcode() { LineIndex = ++mismatchedLineNo, SerialID = ++serialID, Barcode = barcode, Description = "Không tìm thấy mã vạch." }); } } } this.fastBatchRepacks.SetObjects(this.batchRepacks); //if (this.batchRepacks.Count > 0) this.fastBatchRepacks.Sort(this.olvBatchCode, SortOrder.Descending); this.fastMismatchedBarcodes.SetObjects(mismatchedBarcodes); if (mismatchedBarcodes.Count > 0) { this.fastMismatchedBarcodes.Sort(this.olvDescription, SortOrder.Ascending); } this.customTabBatch.TabPages[0].Text = this.fastBatchRepacks.GetItemCount().ToString("N0") + " Pack" + (this.fastBatchRepacks.GetItemCount() > 1 ? "s" : "") + " found "; this.customTabBatch.TabPages[this.customTabBatch.TabPages.Count - 1].Text = this.fastMismatchedBarcodes.GetItemCount().ToString("N0") + " Mismatched Barcode" + (this.fastMismatchedBarcodes.GetItemCount() > 1 ? "s " : " "); } catch (Exception exception) { ExceptionHandlers.ShowExceptionMessageBox(this, exception); } }