private void txtShipmentIdOut_KeyDown(object sender, KeyEventArgs e) { string shipmentinput = txtShipmentIdOut.Text.Trim().ToUpper(); ShipmentEntity shipment = new ShipmentEntity(); try { if (e.KeyCode == Keys.Tab || e.KeyCode == Keys.Enter) { if (String.IsNullOrEmpty(shipmentinput) || String.IsNullOrWhiteSpace(txtShipmentIdOut.Text)) { return; } if (startProcessing) { return; } startProcessing = true; #region Kiểm tra trùng trên lưới nhập if (IsExistsOnTheGridView(grvShipmentListOut, shipmentinput)) { beep7.Play(); txtShipmentIdOut.Enabled = false; int rowIndex = -1; DataGridViewRow row = grvShipmentListOut.Rows .Cast <DataGridViewRow>() .Where(r => r.Cells[0].Value.ToString().Equals(shipmentinput)) .First(); rowIndex = row.Index; grvShipmentListOut.Rows[rowIndex].Selected = true; MessageBox.Show("TRÙNG DỮ LIỆU TRÊN LƯỚI !!!\nBạn hãy kiểm tra dữ liệu vừa nhập!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop); txtShipmentIdOut.Enabled = true; txtShipmentIdOut.Text = String.Empty; txtShipmentNo.Text = ""; txtShipmentIdOut.Focus(); startProcessing = false; return; } #endregion #region Kiểm tra trùng trên thùng đã xuất if (_repositoryShipment.ShipmentOutExist(shipmentinput)) { beep7.Play(); txtShipmentIdOut.Enabled = false; MessageBox.Show("TRÙNG DỮ LIỆU TRÊN THÙNG ĐÃ XUẤT KHO !!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtShipmentIdOut.Enabled = true; txtShipmentIdOut.Text = String.Empty; txtShipmentNo.Text = ""; txtShipmentIdOut.Focus(); startProcessing = false; return; } #endregion #region Kiểm tra vị trí thùng if (_repositoryShipment.ShipmentExist(shipmentinput)) { beep7.Play(); manifestnew = new ManifestEntity(); manifestnew = _repositoryShipment.GetManifestByShipmentNo(shipmentinput); if (manifestnew.BoxID != cbbBoxIdOut.Text.Trim()) { txtShipmentIdOut.Enabled = false; if (MessageBox.Show("LẠC HƯỚNG THÙNG !!! \nDữ liệu bạn nhập có thể nằm ở thùng: " + manifestnew.BoxID + "(" + manifestnew.MasterAirWayBill + ")\nBạn có muốn tiếp tục không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { txtShipmentIdOut.Enabled = true; txtShipmentIdOut.Text = String.Empty; txtShipmentNo.Text = ""; startProcessing = false; return; } } } #endregion #region Kiểm tra hàng thông quan if (!_shipmentOutServices.GetStatusCompletion(shipmentinput)) { beep.Play(); txtShipmentIdOut.BackColor = Color.Tomato; if (MessageBox.Show("Hàng chưa được phép thông quan. \nBạn có muốn tiếp tục không ?", "Hàng chưa được phép thông quan", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) { txtShipmentIdOut.Enabled = true; startProcessing = false; txtShipmentIdOut.Text = ""; txtShipmentIdOut.Focus(); txtShipmentNo.Text = ""; txtShipmentIdOut.BackColor = Color.LightYellow; return; } else { txtShipmentIdOut.BackColor = Color.LightYellow; } } #endregion try { //grvShipmentListOut.Rows.Add(grvShipmentListOut.Rows.Count + 1, shipmentinput, DateTime.Now, Math.Round(manifestnew.Weight, 3)); grvShipmentListOut.Rows.Insert(0, shipmentinput, DateTime.Now, Math.Round(manifestnew.Weight, 3)); // grvShipmentListOut.FirstDisplayedScrollingRowIndex = grvShipmentListOut.RowCount - 1; grvShipmentListOut.FirstDisplayedScrollingRowIndex = 0; lblShipmentScanedOut.Text = "" + grvShipmentListOut.Rows.Count; numberShipmentOut++; grvShipmentListOut.ClearSelection(); grvShipmentListOut.Rows[0].Selected = true; // grvShipmentListOut.Rows[grvShipmentListOut.Rows.Count - 1].Selected = true; // AddOneShipmentToGridView(grvShipmentListOut.Rows.Count + 1, shipmentexport, grvShipmentListOut); } catch { startProcessing = false; } ShipmentOutEntity shipmentOut = new ShipmentOutEntity(); shipmentOut.ShipmentId = shipmentinput; shipmentOut.BoxIdRef = currentBoxOut.Id; shipmentOut.BoxIdString = currentBoxOut.BoxId; shipmentOut.MasterBillId = currentMasterOut.Id; shipmentOut.MasterBillIdString = currentMasterOut.MasterAirwayBill; shipmentOut.DateOut = dtpNgayXuat.Value; shipmentOut.DateCreated = DateTime.Now; shipmentOut.DateInt = _repositoryShipment.DateToInt(DateTime.Now); shipmentOut.EmployeeId = currentEmployee.Id; shipmentOut.WarehouseId = FormLogin.mWarehouse.Id; shipmentOut.Weight = Math.Round(Convert.ToDouble(manifestnew.Weight), 3); shipmentOut.DeclarationNo = _shipmentOutServices.GetDeclarationNo(shipmentinput); shipmentOut.DateOfCompletion = _shipmentOutServices.GetDateOfCompletion(shipmentinput); shipmentOut.Tel = manifestnew.Tel; shipmentOut.Address = manifestnew.Address; shipmentOut.ContactName = manifestnew.ContactName; shipmentOut.CompanyName = manifestnew.CompanyName; shipmentOut.Content = manifestnew.Content; shipmentOut.Country = manifestnew.Country; shipmentOut.Destination = manifestnew.Destination; shipmentOut.Original = manifestnew.Original; shipmentOut.Quantity = manifestnew.Quantity; shipmentOut.TotalValue = manifestnew.TotalValue; _repositoryShipment.CreateShipmentOut(shipmentOut); // SaveShipmentOut(grvShipmentListOut.Rows.Count, shipmentOut); ding.Play(); txtShipmentIdOut.Text = String.Empty; startProcessing = false; } else { return; } } catch (Exception ex) { Ultilities.FileHelper.WriteLog(Ultilities.ExceptionLevel.Function, "txtShipmentIdOut_KeyDown", ex); return; } }