Example #1
0
        private void btnInStorage_Click(object sender, EventArgs e)
        {
            if (waybillList.Count <= 0)
            {
                MessageBox.Show("入库数据不能为空!");
                return;
            }

            InStorageSaveModel saveModel = new InStorageSaveModel();

            saveModel.CustomerCode     = this.txtCustomers.Text.Trim();
            saveModel.OperatorUserName = LoginHelper.CurrentUserName;
            saveModel.ReceivingDate    = txtReceivingDate.Text;
            if (waybillList != null && waybillList.Count > 0)
            {
                //遍历每个运单
                foreach (var waybill in waybillList)
                {
                    WayBillInfoSaveModel w = new WayBillInfoSaveModel();
                    w.WayBillNumber     = waybill.WayBillNumber;
                    w.Length            = waybill.Length.Value;
                    w.Width             = waybill.Width.Value;
                    w.Height            = waybill.Height.Value;
                    w.SettleWeight      = waybill.SettleWeight == null ? 0 : waybill.SettleWeight.Value;
                    w.Weight            = waybill.Weight.Value;
                    w.PriceResult       = waybill.PriceResult;
                    w.GoodsTypeID       = waybill.GoodsTypeID.Value;
                    w.ShippingMethodId  = waybill.InShippingMethodID.Value;
                    w.IsBusinessExpress = waybill.ShippingMethodTypeId == 2;
                    w.IsBattery         = waybill.IsBattery;
                    w.SensitiveType     = waybill.SensitiveType;

                    //遍历运单的每个包裹
                    foreach (var dateil in waybill.WaybillPackageDetaillList)
                    {
                        WaybillPackageDetailModel wayDetailModel = new WaybillPackageDetailModel();
                        wayDetailModel.WayBillNumber = dateil.WayBillNumber;
                        wayDetailModel.Weight        = dateil.Weight;
                        wayDetailModel.AddWeight     = dateil.AddWeight;
                        wayDetailModel.SettleWeight  = dateil.SettleWeight;
                        wayDetailModel.Length        = dateil.Length;
                        wayDetailModel.Width         = dateil.Width;
                        wayDetailModel.Height        = dateil.Height;
                        wayDetailModel.LengthFee     = dateil.LengthFee == null ? 0 : dateil.LengthFee.Value;
                        wayDetailModel.WeightFee     = dateil.WeightFee == null ? 0 : dateil.WeightFee.Value;
                        w.waybillPackageDetailList.Add(wayDetailModel);
                    }

                    saveModel.WayBillInfoSaveList.Add(w);
                }
            }


            ResponseResult responseResult = null;

            new BackgroundLoading(this, () =>
            {
                responseResult = InvokeWebApiHelper.CreateInStorageCS(saveModel);
            }, "正在提交到服务器...", "正在提交到服务器...").Show();

            if (responseResult == null)
            {
                MessageBox.Show("保存失败,请重试!");
                return;
            }

            if (responseResult.Result)
            {
                waybillList = new List <WayBillInfoModel>();
                this.dgvWaybillList.Rows.Clear();
                this.lblCount.Text       = "0";
                this.lblCountWeight.Text = "0";
                FrmInStorageInfo inStoragt = new FrmInStorageInfo(responseResult.Message);
                inStoragt.ShowDialog();
                //inStoragt.MdiParent = this;
            }
            else
            {
                MessageBox.Show(responseResult.Message);
            }
        }
Example #2
0
        /// <summary>
        /// 添加件
        /// </summary>
        private void AddPiece()
        {
            #region 检查数据

            if (waybillList.Exists(p => p.WayBillNumber.Equals(this.txtNumber.Text.Trim()) || p.CustomerOrderNumber.Equals(this.txtNumber.Text.Trim())))
            {
                lblTsg.Text = "数据已经存在,不能重复添加";
                return;
            }

            if (string.IsNullOrWhiteSpace(this.txtPieces.Text))
            {
                return;
            }

            if (int.Parse(this.txtPieces.Text.Trim()) == dgvPackageList.Rows.Count)
            {
                lblTsg.Text = "输入件数与行数相等,请确认提交!";
                btnSubmit.Focus();
                return;
            }

            if (int.Parse(this.txtPieces.Text.Trim()) < dgvPackageList.Rows.Count)
            {
                lblTsg.Text = "行数与列表数不对!";
                return;
            }


            if (string.IsNullOrWhiteSpace(this.txtNumber.Text))
            {
                this.lblTsg.Text = "请输入订单号/运单号!";
                this.txtNumber.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(this.txtPieces.Text))
            {
                this.lblTsg.Text = "请输入件数!";
                this.txtPieces.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(this.txtWeights.Text))
            {
                this.lblTsg.Text = "请输入重量!";
                this.txtWeights.Focus();
                return;
            }

            double weightValue;
            double.TryParse(this.txtWeights.Text, out weightValue);
            if (Convert.ToDouble(weightValue) < 0.005)
            {
                this.lblTsg.Text = "重量不能小于0.005!";
                this.txtWeights.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(this.txtLong.Text))
            {
                this.lblTsg.Text = "请输入长!";
                this.txtLong.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(this.txtWidth.Text))
            {
                this.lblTsg.Text = "请输入宽!";
                this.txtWidth.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(this.txtHeight.Text))
            {
                this.lblTsg.Text = "请输入高!";
                this.txtHeight.Focus();
                return;
            }

            #endregion

            decimal[] wlw       = new decimal[] { decimal.Parse(txtLong.Text.Trim()), decimal.Parse(txtWidth.Text.Trim()), decimal.Parse(txtHeight.Text.Trim()) };
            decimal[] wlwSorted = wlw.OrderByDescending(m => m).ToArray();
            WaybillPackageDetailModel waybillDetailModel = new WaybillPackageDetailModel()
            {
                PackageDetailID = Guid.NewGuid().ToString(),     //唯一包裹序号
            };

            requestModel.CustomerCode         = this.txtCustomers.Text.Trim();
            requestModel.GoodsTypeID          = (int)cbbGoodsType.SelectedValue;
            requestModel.ShippingMethodId     = (int)cbbInStorage.SelectedValue;
            requestModel.IsBusinessExpress    = ((ShippingMethodModel)cbbInStorage.SelectedItem).ShippingMethodTypeId == 2;
            requestModel.OperatorUserName     = LoginHelper.CurrentUserName;
            requestModel.WayBillNumber        = this.txtNumber.Text.Trim();
            requestModel.CustomerType         = int.Parse(CustomerTypeID);
            requestModel.Weight               = decimal.Parse(txtWeights.Text.Trim());
            requestModel.Length               = wlwSorted[0];
            requestModel.Width                = wlwSorted[1];
            requestModel.Height               = wlwSorted[2];
            waybillDetailModel.ShippingMethod = cbbInStorage.SelectedText;
            waybillDetailModel.WayBillNumber  = txtWaybillNumber.Text.Trim();
            waybillDetailModel.Weight         = decimal.Parse(txtWeights.Text.Trim());
            waybillDetailModel.Length         = wlwSorted[0];
            waybillDetailModel.Width          = wlwSorted[1];
            waybillDetailModel.Height         = wlwSorted[2];

            //检查单个包裹
            ResponseModel = InvokeWebApiHelper.CheckOnInStorage(requestModel);
            if (ResponseModel == null)
            {
                return;
            }

            //检查失败
            if (!ResponseModel.IsSuccess)
            {
                this.lblTsg.Text = ResponseModel.Message.Replace("<br/>", "");
                PlayFailSound();
                return;
            }

            if (ResponseModel.SettleWeight == 0)
            {
                MessageBox.Show("错误:结算重量为零");
                return;
            }


            waybilldetailList.Add(waybillDetailModel);
            this.dgvPackageList.Rows.Insert(0, new object[] { 0, waybillDetailModel.PackageDetailID, waybillDetailModel.Weight, waybillDetailModel.Length, waybillDetailModel.Width, waybillDetailModel.Height });

            #region 清空数据,重新定位光标

            if (!cbxWeight.Checked)
            {
                txtWeights.Focus();
            }
            else if (cbxVolume.Checked)
            {
                txtHeight.Focus();
            }
            else
            {
                txtLong.Focus();
            }

            if (!cbxWeight.Checked && txtWeights.Enabled)
            {
                txtWeights.Text = "";
            }
            if (!cbxVolume.Checked && (txtLong.Enabled && txtWidth.Enabled && txtHeight.Enabled))
            {
                txtLong.Text   = "";
                txtWidth.Text  = "";
                txtHeight.Text = "";
            }

            #endregion


            //如果件数与已录入的件数相等,直接提交
            if (int.Parse(this.txtPieces.Text.Trim()) == dgvPackageList.Rows.Count)
            {
                if (btnSubmit.Enabled)
                {
                    btnSubmit_Click(null, null);
                }
            }
        }
Example #3
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            #region 检查输入数据

            if (string.IsNullOrWhiteSpace(this.txtPieces.Text))
            {
                this.lblTsg.Text = "请输入件数!";
                this.txtPieces.Focus();
                return;
            }

            if (int.Parse(this.txtPieces.Text.Trim()) != dgvPackageList.Rows.Count)
            {
                this.lblTsg.Text = "输入的件数与行数不正确!请检查";
                return;
            }

            #endregion

            WayBillInfoModel waybillModel = new WayBillInfoModel();

            CustomerInfoPackageRequest waybillRequest     = new CustomerInfoPackageRequest();
            List <PackageRequest>      packageRequestList = new List <PackageRequest>();

            //生成运费请求
            foreach (var package in waybilldetailList)
            {
                PackageRequest packageRequest = new PackageRequest();
                packageRequest.Weight = package.Weight.Value;
                packageRequest.Length = package.Length.Value;
                packageRequest.Width  = package.Width.Value;
                packageRequest.Height = package.Height.Value;
                packageRequestList.Add(packageRequest);
            }

            waybillRequest.CustomerId         = Guid.Parse(this.CustomerId);
            waybillRequest.CountryCode        = ResponseModel.CountryCode;
            waybillRequest.ShippingMethodId   = (int)cbbInStorage.SelectedValue;
            waybillRequest.ShippingTypeId     = (int)cbbGoodsType.SelectedValue;
            waybillRequest.Packages           = packageRequestList;
            waybillRequest.EnableTariffPrepay = ResponseModel.EnableTariffPrepay;//是否启用运费预付服务
            waybillRequest.ShippingInfo       = inStorageModel.ShippingInfo;

            //计算运费
            PriceProviderExtResult priceResult = InvokeWebApiHelper.PostCustomerPriceAuto(waybillRequest);

            if (priceResult == null)
            {
                this.lblTsg.Text = "网络错误,请重试";
                return;
            }

            //如果不能邮寄
            if (!priceResult.CanShipping)
            {
                this.lblTsg.Text = priceResult.Message;

                clearLeft();

                txtNumber.Focus();
                return;
            }

            var sumSettleWeight = priceResult.Weight;//结算重量
            var sumWeight       = priceResult.Weight;

            #region 包裹长宽高求和

            decimal sumLeng   = 0;
            decimal sumWidth  = 0;
            decimal sumHeight = 0;
            if (priceResult.PackageDetails.Count() > 0)
            {
                sumLeng = (from s in priceResult.PackageDetails
                           select s.Length).Sum();
                sumWidth = (from s in priceResult.PackageDetails
                            select s.Width).Sum();
                sumHeight = (from s in priceResult.PackageDetails
                             select s.Height).Sum();
            }

            #endregion

            if (!waybillList.Exists(p => p.WayBillNumber.Equals(ResponseModel.WayBillNumber)))
            {
                waybillModel.CountryCode = ResponseModel.CountryCode;
                waybillModel.Pieces      = Convert.ToInt32(txtPieces.Text.Trim());

                waybillModel.SettleWeight         = sumSettleWeight;
                waybillModel.Length               = sumLeng;
                waybillModel.Width                = sumWidth;
                waybillModel.Height               = sumHeight;
                waybillModel.WayBillNumber        = ResponseModel.WayBillNumber;
                waybillModel.TrackingNumber       = ResponseModel.TrackingNumber;
                waybillModel.CustomerOrderNumber  = ResponseModel.CustomerOrderNumber;
                waybillModel.InShippingMethodID   = (int)cbbInStorage.SelectedValue;
                waybillModel.ShippingMethodTypeId = ((ShippingMethodModel)cbbInStorage.SelectedItem).ShippingMethodTypeId;
                waybillModel.InShippingMethodName = cbbInStorage.Text;
                waybillModel.GoodsTypeID          = (int)cbbGoodsType.SelectedValue;
                waybillModel.PriceResult          = priceResult;
                waybillModel.IsBattery            = cbxBattery.Checked;
                waybillModel.SensitiveType        = cbxBattery.Checked?(int?)cbbSensitiveType.SelectedValue:null;

                //以下方便测试
                #region 弹出费用明细

                if (File.Exists(Application.StartupPath + @"\debug.txt"))
                {
                    showPriceProviderResult(priceResult);
                }

                #endregion

                #region 包裹明细赋值

                for (int j = 0; j < waybilldetailList.Count; j++)
                {
                    var r = waybilldetailList[j];
                    WaybillPackageDetailModel model = new WaybillPackageDetailModel();
                    model.WayBillNumber = r.WayBillNumber;
                    model.Pieces        = r.Pieces;
                    model.Weight        = priceResult.PackageDetails[j].Weight;
                    model.AddWeight     = priceResult.PackageDetails[j].AddWeight;
                    model.SettleWeight  = priceResult.PackageDetails[j].SettleWeight;
                    model.Length        = r.Length;
                    model.Width         = r.Width;
                    model.Height        = r.Height;
                    model.LengthFee     = priceResult.PackageDetails[j].OverGirthFee;
                    model.WeightFee     = priceResult.PackageDetails[j].OverWeightOrLengthFee;
                    waybillModel.WaybillPackageDetaillList.Add(model);
                }

                waybillModel.Weight = waybillModel.WaybillPackageDetaillList.Sum(p => (p.Weight + (p.AddWeight ?? 0)));

                #endregion


                waybillList.Add(waybillModel);
            }

            if (cbxPrintLable.Checked)//打印报表
            {
                string frxPath = Application.StartupPath + @"\Resource\PackageLable.frx";

                if (!File.Exists(frxPath))
                {
                    MessageBox.Show("找不到货物标签打印模板:" + frxPath);
                    return;
                }

                Report report = new Report();

                report.Load(frxPath);
                report.RegisterData(waybilldetailList, "waybilldetailList");
                var      datasource = report.GetDataSource("waybilldetailList");
                DataBand data1      = report.FindObject("data1") as DataBand;
                if (data1 != null)
                {
                    data1.DataSource = datasource;
                }
                report.Prepare();
                report.PrintSettings.ShowDialog = true;
                //report.Show();
                report.Print();
                report.Dispose();
            }

            updateScanInfo();

            this.dgvWaybillList.Rows.Add(new object[] { waybillModel.WayBillNumber, waybillModel.TrackingNumber, waybillModel.CustomerOrderNumber, waybillModel.InShippingMethodName, waybillModel.Pieces, waybillModel.SettleWeight, waybillModel.CountryCode, "删除" });
            clearLeft();
            txtNumber.Focus();

            PlaySuccessSound();
        }