Exemplo n.º 1
0
 private void btnOpenBoxOut_Click(object sender, EventArgs e)
 {
     try
     {
         if (btnOpenBoxOut.Text.Equals("Mở", StringComparison.CurrentCultureIgnoreCase))
         {
             if (String.IsNullOrWhiteSpace(cbbMasterBillOut.Text) || String.IsNullOrWhiteSpace(cbbBoxIdOut.Text))
             {
                 MessageBox.Show("Bạn phải nhập mã Airwaybill", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 return;
             }
             currentMasterOut = _masterBillServices.GetByMasterBillId(cbbMasterBillOut.Text);
             if (currentMasterOut == null)
             {
                 nhapMoiKhongCanXacNhan = true;
                 currentMasterOut       = new MasterAirwayBillEntity
                 {
                     MasterAirwayBill = cbbMasterBillOut.Text,
                     DateArrived      = dtpNgayXuat.Value,
                     EmployeeId       = currentEmployee.Id,
                     DateCreated      = DateTime.Now
                 };
                 currentMasterBillId = _masterBillServices.CreateMasterAirwayBill(currentMasterOut);
                 currentMasterBill   = currentMasterOut.MasterAirwayBill;
                 currentMasterOut.Id = currentMasterBillId;
             }
             else
             {
                 currentMasterBill   = currentMasterOut.MasterAirwayBill;
                 currentMasterBillId = currentMasterOut.Id;
             }
             /// Chuyển sang BOX OUT
             currentBoxOut = _boxOutServices.GetByBoxCodeandAirWaybill(cbbBoxIdOut.Text, currentMasterOut.Id);
             if (currentBoxOut == null)
             {
                 nhapMoiKhongCanXacNhan = true;
                 currentBoxOut          = new BoxOutEntity
                 {
                     BoxId            = cbbBoxIdOut.Text,
                     ShipmentQuantity = 0,
                     MasterBillId     = currentMasterBillId,
                     EmployeeId       = currentEmployee.Id,
                     DateCreated      = DateTime.Now,
                     DateInt          = _repositoryShipment.DateToInt(DateTime.Now)
                 };
                 currentBoxIdInt  = _boxOutServices.CreateBoxOut(currentBoxOut);
                 currentBoxId     = currentBoxOut.BoxId;
                 currentBoxOut.Id = currentBoxIdInt;
             }
             else
             {
                 currentBoxIdInt = currentBoxOut.Id;
                 currentBoxId    = currentBoxOut.BoxId;
             }
             if (!LoadShipmentsByBoxId(currentBoxOut, grvShipmentListOut))
             {
                 return;
             }
             OpenBoxOut();
             // Dữ liệu xác nhận đến
             #region Dữ liệu xác nhận đến
             BoxInforEntity boxEntity = _boxInforServices.GetByBoxId(cbbBoxIdOut.Text.Trim());
             if (boxEntity != null)
             {
                 lblCountIn.Text = _boxInforServices.GetByBoxId(boxEntity.Id).ShipmentQuantity.ToString();
             }
             IEnumerable <ShipmentEntity> lstShipmentInfor = _shipmentServices.GetByBoxId(boxEntity.Id);
             if (lstShipmentInfor != null)
             {
                 lstShipmentInfor  = lstShipmentInfor.Where(t => t.Status == "Check");
                 lblClearance.Text = lstShipmentInfor.Count().ToString();
             }
             #endregion
             txtShipmentIdOut.BackColor = Color.LightYellow;
             btnOpenBoxOut.Text         = "Đóng";
         }
         else
         {
             currentBoxOut = _boxOutServices.GetByBoxCode(cbbBoxIdOut.Text);
             if (currentBoxOut == null)
             {
                 return;
             }
             else
             {
                 IEnumerable <ShipmentOutEntity> lstshipment = _shipmentOutServices.GetByBoxId(currentBoxOut.Id);
                 if (lstshipment == null)
                 {
                     _boxOutServices.Delete(currentBoxOut.Id);
                 }
                 else
                 {
                     _boxOutServices.CreateOrUpdateByQuery(lstshipment.Count(), currentBoxOut.Id);
                 }
             }
             CloseBoxOut();
             btnOpenBoxOut.Text = "Mở";
         }
     }
     catch (Exception ex)
     {
         Ultilities.FileHelper.WriteLog(Ultilities.ExceptionLevel.Function, "btnOpenBoxOut_Click", ex);
         return;
     }
 }
        private void SaveShipment(string masterBill)
        {
            int countTotal = 0;
            List <BoxIdEntity> listBoxid = repositoryShipment.GetBoxIdByAirwaybill(masterBill);

            if (listBoxid.Count > 0)
            {
                foreach (var box in listBoxid)
                {
                    int            countBox  = 0;
                    BoxInforEntity boxEntity = _boxInforServices.GetByBoxId(box.BoxId);
                    if (boxEntity == null)
                    {
                        boxEntity                  = new BoxInforEntity();
                        boxEntity.BoxId            = box.BoxId;
                        boxEntity.DateCreated      = DateTime.Now;
                        boxEntity.EmployeeId       = currentEmployee.Id;
                        boxEntity.ShipmentQuantity = 0;
                        boxEntity.MasterBillId     = currentMasterBillId;
                        currentBoxIdInt            = _boxInforServices.CreateBoxInfor(boxEntity);
                        boxEntity.Id               = currentBoxIdInt;
                        currentBoxId               = boxEntity.BoxId;
                    }
                    else
                    {
                        currentBoxIdInt = boxEntity.Id;
                        currentBoxId    = boxEntity.BoxId;
                    }
                    List <ManifestEntity> listManifest = new List <ManifestEntity>();
                    listManifest = repositoryShipment.GetManifestByBoxId(box.BoxId);
                    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)
                        {
                            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;
                            if (_shipmentOutServices.GetStatusCompletion(item.ShipmentNo))
                            {
                                shipment.Status = "Clearance";
                            }
                            else
                            {
                                shipment.Status = "Check";
                            }
                            shipment.Content       = item.Content;
                            shipment.Country       = item.Country;
                            shipment.DeclarationNo = item.DeclarationNo;
                            shipment.Destination   = item.Destination;
                            shipment.NumberPackage = 1;
                            shipment.TotalValue    = item.TotalValue;
                            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);
                        }
                        countBox = repositoryShipment.CreateShipment(listShipment);
                        if (countBox > 0)
                        {
                            countTotal += countBox;
                            _boxInforServices.CreateOrUpdateByQuery(countBox, boxEntity.Id);
                        }
                    }
                }
                MessageBox.Show("Đã xác nhận đến thành công!\nTổng số đơn hàng là " + countTotal, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 3
0
        private void btnOpenClose_Click(object sender, EventArgs e)
        {
            if (btnOpenClose.Text.Equals("Mở", StringComparison.CurrentCultureIgnoreCase))
            {
                if (!ValidateInputDataConfirmArrived())
                {
                    return;
                }

                MasterAirwayBillEntity masterBill = _masterBillServices.GetByMasterBillId(cbbMasterBill.Text);
                if (masterBill == null)
                {
                    masterBill = new MasterAirwayBillEntity();
                    masterBill.MasterAirwayBill = cbbMasterBill.Text;
                    masterBill.DateArrived      = dtpNgayDen.Value;
                    masterBill.DateCreated      = DateTime.Now;
                    masterBill.EmployeeId       = currentEmployee.Id;
                    currentMasterBillId         = _masterBillServices.CreateMasterAirwayBill(masterBill);
                    currentMasterBill           = masterBill.MasterAirwayBill;
                    masterBill.Id = currentMasterBillId;


                    cbbMasterBill.SelectedText = masterBill.MasterAirwayBill;
                }
                else
                {
                    currentMasterBillId = masterBill.Id;
                    currentMasterBill   = masterBill.MasterAirwayBill;
                }
                BoxInforEntity boxEntity = _boxInforServices.GetByBoxId(cbbBoxId.Text);
                if (boxEntity == null)
                {
                    boxEntity                  = new BoxInforEntity();
                    boxEntity.BoxId            = cbbBoxId.Text;
                    boxEntity.ShipmentQuantity = numberShipment;
                    boxEntity.MasterBillId     = currentMasterBillId;
                    boxEntity.DateCreated      = DateTime.Now;
                    boxEntity.EmployeeId       = currentEmployee.Id;
                    currentBoxIdInt            = _boxInforServices.CreateBoxInfor(boxEntity);
                    boxEntity.Id               = currentBoxIdInt;
                    currentBoxId               = boxEntity.BoxId;
                }
                else
                {
                    currentBoxIdInt = boxEntity.Id;
                    currentBoxId    = boxEntity.BoxId;
                }
                OpenBox();
                LoadShipmentsByBoxIdInXacNhanDen(cbbBoxId.Text, grvShipments);
                btnOpenClose.Text = "Đóng";
            }
            else
            {
                if (!isConfirmed)
                {
                    SaveShipment();
                }
                BoxInforEntity boxEntity = _boxInforServices.GetByBoxId(cbbBoxId.Text);
                if (boxEntity == null)
                {
                    return;
                }
                else
                {
                    IEnumerable <ShipmentEntity> lstshipment = _shipmentServices.GetByBoxId(boxEntity.Id);
                    if (lstshipment == null)
                    {
                        _boxInforServices.Delete(boxEntity.Id);
                    }
                    else
                    {
                        _boxInforServices.CreateOrUpdateByQuery(lstshipment.Count(), boxEntity.Id);
                    }
                }

                CloseBox();
                btnOpenClose.Text = "Mở";
            }
            MasterAirwayBillEntity itemMaster = _masterBillServices.GetByMasterBillId(cbbMasterBill.Text);
        }