public static bool CheckPrintData(List <ZtoPrintBillEntity> ztoPrintBillEntities)
        {
            return(true);

            var errorList = new List <object>();

            // 调用接口都没有通过,那么一般就是商家ID和密码不正确导致
            foreach (ZtoPrintBillEntity ztoPrintBillEntity in ztoPrintBillEntities)
            {
                if (string.IsNullOrEmpty(ztoPrintBillEntity.SendMan))
                {
                    errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "发件人姓名必填" });
                }
                else if (string.IsNullOrEmpty(ztoPrintBillEntity.SendPhone))
                {
                    errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "发件人电话必填" });
                }
                else if (!string.IsNullOrEmpty(ztoPrintBillEntity.SendPhone) && ztoPrintBillEntity.SendPhone.Length > 30)
                {
                    errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "发件人电话太长了" });
                }
                else if (string.IsNullOrEmpty(ztoPrintBillEntity.SendProvince))
                {
                    errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "发件人省份必填" });
                }
                else if (string.IsNullOrEmpty(ztoPrintBillEntity.SendCity))
                {
                    errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "发件人城市必填" });
                }
                else if (string.IsNullOrEmpty(ztoPrintBillEntity.SendCounty))
                {
                    errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "发件人区县必填" });
                }
                else if (string.IsNullOrEmpty(ztoPrintBillEntity.SendAddress))
                {
                    errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "发件人详细地址必填" });
                }
                else if (string.IsNullOrEmpty(ztoPrintBillEntity.ReceiveMan))
                {
                    errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "收件人姓名必填" });
                }
                else if (string.IsNullOrEmpty(ztoPrintBillEntity.ReceivePhone))
                {
                    errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "收件人电话必填" });
                }
                else if (!string.IsNullOrEmpty(ztoPrintBillEntity.ReceivePhone) && ztoPrintBillEntity.ReceivePhone.Length > 30)
                {
                    errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "收件人电话太长了" });
                }
                else if (string.IsNullOrEmpty(ztoPrintBillEntity.ReceiveProvince))
                {
                    errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "收件人省份必填" });
                }
                else if (string.IsNullOrEmpty(ztoPrintBillEntity.ReceiveCity))
                {
                    errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "收件人城市必填" });
                }
                else if (string.IsNullOrEmpty(ztoPrintBillEntity.ReceiveCounty))
                {
                    errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "收件人区县必填" });
                }
                else if (string.IsNullOrEmpty(ztoPrintBillEntity.ReceiveAddress))
                {
                    errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "收件人详细地址必填" });
                }
            }
            if (errorList.Any())
            {
                var frmImportError = new FrmImportError()
                {
                    errorList = errorList
                };
                frmImportError.ShowDialog();
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取申通电子面单
        /// </summary>
        /// <param name="ztoPrintBillEntities">打印实体泛型集合</param>
        /// <param name="ztoElecUserInfoEntity">电子面单线下商家ID实体信息</param>
        /// <returns></returns>
        public static List <ZtoPrintBillEntity> BindElecBillByCustomerId(List <ZtoPrintBillEntity> ztoPrintBillEntities, ZtoElecUserInfoEntity ztoElecUserInfoEntity)
        {
            var errorList = new List <object>();
            // 全部生成订单号,然后重复获取都没关系了不怕
            var printBillManager = new ZtoPrintBillManager(BillPrintHelper.DbHelper);

            foreach (var ztoPrintBillEntity in ztoPrintBillEntities)
            {
                // 订单号 特殊处理,如果没有填写需要生成一个唯一订单号给接口
                if (string.IsNullOrEmpty(ztoPrintBillEntity.OrderNumber))
                {
                    var orderNumber = Guid.NewGuid().ToString("N").ToLower();
                    ztoPrintBillEntity.OrderNumber = orderNumber;
                    var updateParameters = new List <KeyValuePair <string, object> >
                    {
                        new KeyValuePair <string, object>(ZtoPrintBillEntity.FieldOrderNumber, ztoPrintBillEntity.OrderNumber),
                        new KeyValuePair <string, object>(ZtoPrintBillEntity.FieldModifiedOn, DateTime.Now)
                    };
                    var whereParameters = new List <KeyValuePair <string, object> >
                    {
                        new KeyValuePair <string, object>(ZtoPrintBillEntity.FieldId, ztoPrintBillEntity.Id)
                    };
                    printBillManager.SetProperty(whereParameters, updateParameters);
                }
            }
            // 需要提交接口次数
            var submitCount = Math.Ceiling(ztoPrintBillEntities.Count / 10.0);

            // 如果提交的记录数超过10条,需要分几批提交接口,10条一次最好,防止接口挂了
            if (submitCount > 1)
            {
                var list = new List <ZtoPrintBillEntity>();
                for (int i = 0; i < submitCount; i++)
                {
                    List <ZtoPrintBillEntity> t        = ztoPrintBillEntities.Skip(10 * i).Take(10).ToList();
                    List <ZtoPrintBillEntity> tempList = Request(t, ztoElecUserInfoEntity, ref errorList);
                    if (tempList == null)
                    {
                        if (list.Any())
                        {
                            return(list);
                        }
                        return(null);
                    }
                    list.AddRange(tempList);
                }
                if (errorList.Any())
                {
                    var frmImportError = new FrmImportError()
                    {
                        errorList = errorList
                    };
                    frmImportError.ShowDialog();
                }
                return(list);
            }
            // 提交一次接口就可以了
            var resultList = Request(ztoPrintBillEntities, ztoElecUserInfoEntity, ref errorList);

            if (errorList.Any())
            {
                var frmImportError = new FrmImportError()
                {
                    errorList = errorList
                };
                frmImportError.ShowDialog();
            }
            return(resultList);
        }