예제 #1
0
        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;
            }
        }
예제 #2
0
        private void SaveShipment()
        {
            try
            {
                string         boxstring = cbbBoxId.Text.Trim();
                int            count     = 0;
                BoxInforEntity boxEntity = _boxInforServices.GetByBoxId(cbbBoxId.Text.Trim());
                if (boxEntity == null)
                {
                    boxEntity                  = new BoxInforEntity();
                    boxEntity.BoxId            = boxstring;
                    boxEntity.DateCreated      = DateTime.Now;
                    boxEntity.EmployeeId       = currentEmployee.Id;
                    boxEntity.ShipmentQuantity = 0; //manifestList.Where(t => t.BoxID == boxstring).Count();
                    boxEntity.MasterBillId     = currentMasterBillId;
                    currentBoxIdInt            = _boxInforServices.CreateBoxInfor(boxEntity);
                    boxEntity.Id               = currentBoxIdInt;
                    currentBoxId               = boxEntity.BoxId;
                }
                else
                {
                    currentBoxIdInt = boxEntity.Id;
                    currentBoxId    = boxEntity.BoxId;
                }
                if (_repositoryShipment.ShipmentExistByBoxId(boxEntity.Id))
                {
                    return;
                }
                List <ManifestEntity> listManifest = new List <ManifestEntity>();
                listManifest = _repositoryShipment.GetManifestByBoxId(boxstring);
                listManifest = listManifest.GroupBy(t => t.ShipmentNo).Select(p => p.First()).ToList();
                if (listManifest != null && listManifest.Count > 0)
                {
                    List <ShipmentEntity> listShipment = new List <ShipmentEntity>();
                    foreach (var item in listManifest)
                    {
                        if (_repositoryShipment.ShipmentExist(item.ShipmentNo))
                        {
                            continue;
                        }
                        ShipmentEntity shipment = new ShipmentEntity();
                        shipment.Mawb          = item.MasterAirWayBill;
                        shipment.ShipmentId    = item.ShipmentNo;
                        shipment.BoxId         = currentBoxIdInt;
                        shipment.DateCreated   = DateTime.Now;
                        shipment.EmployeeId    = currentEmployee.Id;
                        shipment.WarehouseId   = FormLogin.mWarehouse.Id;
                        shipment.Address       = item.Address;
                        shipment.BoxIdString   = item.BoxID;
                        shipment.Content       = item.Content;
                        shipment.Country       = item.Country;
                        shipment.DeclarationNo = item.DeclarationNo;
                        shipment.Destination   = item.Destination;
                        shipment.NumberPackage = 1;
                        shipment.Sender        = item.CompanyName;
                        shipment.Consignee     = item.Destination;
                        shipment.Receiver      = item.ContactName;
                        shipment.Weight        = Math.Round(item.Weight, 3);
                        shipment.ReceiverTel   = item.Tel;
                        listShipment.Add(shipment);
                    }
                    count += _shipmentServices.CreateOrUpdate(listShipment);
                }

                MessageBox.Show("Đã lưu xác nhận đến thành công!\nTổng số đơn hàng là " + count, "Lưu xác nhận đến", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
            }
        }