예제 #1
0
        private bool ValidateInputDataConfirmArrived()
        {
            isConfirmed = false;
            if (String.IsNullOrWhiteSpace(cbbMasterBill.Text) || String.IsNullOrWhiteSpace(cbbBoxId.Text))
            {
                MessageBox.Show("Bạn cần phải nhập Master airway bill (MAWB) và Mã thùng trước", "Thông báo", MessageBoxButtons.OK);
                cbbMasterBill.Focus();
                return(false);
            }
            if (!CheckIsBoxIdExistsInManifest(cbbBoxId.Text))
            {
                MessageBox.Show("Không tồn tại dữ liệu.", "Thông báo", MessageBoxButtons.OK);
                cbbBoxId.Focus();
                return(false);
            }
            BoxInforEntity box = _boxInforServices.GetByBoxId(cbbBoxId.Text);

            if (box == null)
            {
                listManifest = _repositoryShipment.GetManifestByBoxId(cbbBoxId.Text.Trim());
                listManifest = listManifest.GroupBy(t => t.ShipmentNo).Select(p => p.First()).ToList();
                var result = MessageBox.Show("Tổng số đơn hàng: " + listManifest.Count + "\nBạn có muốn xác nhận không?", cbbBoxId.Text, MessageBoxButtons.YesNo);
                return(result == DialogResult.Yes);
            }
            else
            {
                lstShipmentInfor = (List <ShipmentEntity>)_shipmentServices.GetByBoxId(box.Id);
                var result = MessageBox.Show("Tổng số đơn hàng: " + lstShipmentInfor.Count + "\nBạn có muốn mở không?", cbbBoxId.Text, MessageBoxButtons.YesNo);
                return(result == DialogResult.Yes);
            }
        }
        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);
            }
        }