Example #1
0
        /// <summary>
        /// 提交到B2C
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static B2CPreAlertLog SubmitB2C(WayBillInfoModel model)
        {
            var result = new B2CPreAlertLog
            {
                WayBillNumber   = model.WayBillNumber,
                PreAlertBatchNo = model.PreAlertBatchNo,
                Status          = 1
            };

            Log.Info("开始预报运单号为{0}到B2C".FormatWith(model.WayBillNumber));
            var prealert = new Prealert();

            prealert.AuthenticationKey  = AuthenticationKey;
            prealert.LayoutPlatform     = "L01";
            prealert.LayoutType         = "P02";
            prealert.LayoutVersion      = "2.0";
            prealert.PrealertReference  = model.PreAlertBatchNo;
            prealert.PrealertValidation = new PrealertValidation()
            {
                Timezone                = "+8",
                TotalShipments          = 1,
                MailAddressConfirmation = Email,
                MailAddressError        = Email
            };
            var street   = (model.Street ?? "").ToDBC().StringSplitLengthWords(40);
            var shipment = new Shipment
            {
                CountryCodeOrigin = "CHN",
                Currency          = "EUR",
                CustomsService    = "DDP",
                OrderNumber       = model.WayBillNumber,
                PurchaseDate      = DateTime.Now.ToString("yyyy-MM-dd"),
                ShippingMethod    =
                    model.ShippingMethodID == DDPRegisterShippingMethodId
                            ? (model.Weight > 2 ? "PPLUSDDP" : "PPAR")
                            : "TMAIL",
                ShipmentAddress =
                {
                    ConsigneeName         = model.ConsigneeName.ToDBC().StripXML(),
                    AddressType           = "DL1",
                    CompanyName           = (model.CompanyName ?? "").ToDBC().StripXML(),
                    Street                = street[0].StripXML(),
                    AdditionalAddressInfo = street.Count > 1?street[1].StripXML():"",
                    CityOrTown            = (model.CityOrTown ?? "").ToDBC().StripXML(),
                    StateOrProvince       = (model.StateOrProvince ?? "").ToDBC().StripXML(),
                    ZIPCode               = (model.ZIPCode).ToDBC().StripXML(),
                    CountryCode           = model.CountryCode
                },
                ShipmentContact = { PhoneNumber = (model.PhoneNumber ?? "").ToDBC().StripXML(), EmailAddress = Email }
            };

            shipment.ShipmentPackages.Add(new ShipmentPackage()
            {
                DimensionHeight = decimal.ToInt32(Math.Round(model.Height, 0)),
                DimensionLength = decimal.ToInt32(Math.Round(model.Length, 0)),
                DimensionWidth  = decimal.ToInt32(Math.Round(model.Width, 0)),
                PackageBarcode  = model.WayBillNumber,
                PackageWeight   = decimal.ToInt32(Math.Round(model.Weight, 3) * 1000),
                PackageNumber   = 1
            });
            model.ApplicationInfos.ForEach(p => shipment.ShipmentContentCustoms.Add(new ShipmentContentCustoms()
            {
                SKUCode        = (p.SKUCode ?? "").ToDBC().StripXML(),
                SKUDescription = (p.SKUDescription ?? "").ToDBC().StripXML(),
                HSCode         = (p.HSCode ?? "").ToDBC().StripXML(),
                ImageUrl       = (p.ImageUrl ?? "").ToDBC().StripXML(),
                PackageNumber  = 1,
                Price          = decimal.Round(p.Price, 2),
                Quantity       = p.Quantity
            }));
            prealert.Shipments.Add(shipment);
            try
            {
                result.ShippingMethod = shipment.ShippingMethod;
                var xdoc = PreAlertB2CService.SubmitB2C(prealert, Url);
                Log.Info(xdoc.InnerText);
                XmlNode root = xdoc.SelectSingleNode("/Error");
                if (root != null && root.HasChildNodes)
                {
                    result.Status = 3;
                    var code = xdoc.SelectSingleNode("/Error/Code");
                    if (code != null)
                    {
                        result.ErrorCode = Int32.Parse(code.InnerText);
                        if (result.ErrorCode == 5001)
                        {
                            result.Status = 2;
                        }
                    }
                    var msg = xdoc.SelectSingleNode("/Error/Message");
                    if (msg != null)
                    {
                        result.ErrorMsg = msg.InnerText;
                    }
                    var detail = xdoc.SelectSingleNode("/Error/Details");
                    if (detail != null)
                    {
                        result.ErrorDetails = detail.InnerText;
                    }
                }
                else
                {
                    XmlNode newroot = xdoc.SelectSingleNode("/Prealert");
                    if (newroot != null && newroot.HasChildNodes)
                    {
                        result.Status = 2;
                        var prealterId = xdoc.SelectSingleNode("/Prealert/PreAlertID");
                        if (prealterId != null)
                        {
                            result.PreAlertID = Int32.Parse(prealterId.InnerText);
                        }
                    }
                    else
                    {
                        Log.Error(xdoc.InnerText);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
            Log.Info("完成预报运单号为{0}到B2C".FormatWith(model.WayBillNumber));
            return(result);
        }
        /// <summary>
        /// 查询该运单号的数据
        /// </summary>
        /// <param name="wayBillNumber"></param>
        /// <returns></returns>
        public static WayBillInfoModel GetWayBillInfoModel(string wayBillNumber)
        {
            Log.Info("开始获取运单号为{0}的数据".FormatWith(wayBillNumber));
            var    model = new WayBillInfoModel();
            string sql   =
                @"SELECT w.WayBillNumber,w.CustomerOrderNumber, ISNULL(s.ShippingFirstName,'')+' '+ ISNULL(s.ShippingLastName,'') ConsigneeName,w.OutShippingMethodID ShippingMethodID
                    ,ISNULL(s.ShippingCompany,'') ShippingCompany,s.ShippingAddress,s.ShippingCity,s.ShippingState,s.ShippingZip,s.ShippingPhone,c.ThreeLetterISOCode CountryCode,
                    ISNULL(w.Weight,0) Weight,ISNULL(w.Length,1) Length,ISNULL(w.Width,1) Width,ISNULL(w.Height,1) Height
                FROM dbo.WayBillInfos w LEFT JOIN dbo.ShippingInfos s ON s.ShippingInfoID = w.ShippingInfoID
                    LEFT JOIN dbo.Countries c ON c.CountryCode = w.CountryCode 
                WHERE w.WayBillNumber='" + wayBillNumber + "'";

            try
            {
                DbUtility dbUtility = new SqlDbUtility(_lmsCon);
                DataTable dt        = dbUtility.ExecuteData(sql);
                if (dt == null || dt.Rows.Count == 0)
                {
                    return(null);
                }

                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    switch (dt.Columns[j].ColumnName)
                    {
                    case "WayBillNumber":
                        model.WayBillNumber = dt.Rows[0][j].ToString();
                        break;

                    case "CustomerOrderNumber":
                        model.CustomerOrderNumber = dt.Rows[0][j].ToString();
                        break;

                    case "ConsigneeName":
                        model.ConsigneeName = dt.Rows[0][j].ToString();
                        break;

                    case "ShippingCompany":
                        model.CompanyName = dt.Rows[0][j].ToString();
                        break;

                    case "ShippingAddress":
                        model.Street = dt.Rows[0][j].ToString();
                        break;

                    case "ShippingCity":
                        model.CityOrTown = dt.Rows[0][j].ToString();
                        break;

                    case "ShippingState":
                        model.StateOrProvince = dt.Rows[0][j].ToString();
                        break;

                    case "ShippingZip":
                        model.ZIPCode = dt.Rows[0][j].ToString();
                        break;

                    case "ShippingPhone":
                        model.PhoneNumber = dt.Rows[0][j].ToString();
                        break;

                    case "CountryCode":
                        model.CountryCode = dt.Rows[0][j].ToString();
                        break;

                    case "Weight":
                        model.Weight = decimal.Parse(dt.Rows[0][j].ToString());
                        break;

                    case "Length":
                        model.Length = decimal.Parse(dt.Rows[0][j].ToString());
                        break;

                    case "Width":
                        model.Width = decimal.Parse(dt.Rows[0][j].ToString());
                        break;

                    case "Height":
                        model.Height = decimal.Parse(dt.Rows[0][j].ToString());
                        break;

                    case "ShippingMethodID":
                        model.ShippingMethodID = Int32.Parse(dt.Rows[0][j].ToString());
                        break;
                        //case "ApplicationInfos":
                        //    model.ApplicationInfos = SerializeUtil.DeserializeFromXml<List<ApplicationInfoModel>>(dt.Rows[0][j].ToString());
                        //    break;
                    }
                }
                sql =
                    @"SELECT ISNULL(a.Remark,'') SKUCode,a.ApplicationName SKUDescription,a.HSCode,
                    ISNULL(a.Qty,1) Quantity,ISNULL(a.UnitPrice,0)*ISNULL(a.Qty,1) Price,a.ProductUrl ImageUrl
                                    FROM dbo.ApplicationInfos a
                                    WHERE a.WayBillNumber='" + wayBillNumber + "' AND a.IsDelete=0";
                DataTable adt = dbUtility.ExecuteData(sql);
                if (adt != null || adt.Rows.Count > 0)
                {
                    for (int i = 0; i < adt.Rows.Count; i++)
                    {
                        var app = new ApplicationInfoModel();
                        for (int j = 0; j < adt.Columns.Count; j++)
                        {
                            switch (adt.Columns[j].ColumnName)
                            {
                            case "SKUCode":
                                app.SKUCode = adt.Rows[i][j].ToString();
                                break;

                            case "SKUDescription":
                                app.SKUDescription = adt.Rows[i][j].ToString();
                                break;

                            case "HSCode":
                                app.HSCode = adt.Rows[i][j].ToString();
                                break;

                            case "Quantity":
                                app.Quantity = Int32.Parse(adt.Rows[i][j].ToString());
                                break;

                            case "Price":
                                app.Price = decimal.Parse(adt.Rows[i][j].ToString());
                                break;

                            case "ImageUrl":
                                app.ImageUrl = adt.Rows[i][j].ToString();
                                break;
                            }
                        }
                        model.ApplicationInfos.Add(app);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
            Log.Info("完成获取运单号为{0}的数据".FormatWith(wayBillNumber));
            return(model);
        }
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();
        }