예제 #1
0
        /// <summary>
        /// 窗体加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmSendMan_Load(object sender, EventArgs e)
        {
            splitContainerControl1.Panel1.Height = Convert.ToInt32(this.Height * 0.8);
            splitContainerControl1.Panel2.Height = Convert.ToInt32(this.Height * 0.2);
            var userManager = new ZtoUserManager(BillPrintHelper.DbHelper);
            var userList    = userManager.GetList <ZtoUserEntity>(new KeyValuePair <string, object>(ZtoUserEntity.FieldIsDefault, 1), new KeyValuePair <string, object>(ZtoUserEntity.FieldIssendorreceive, 1));

            if (!userList.Any())
            {
                ckDefault.Checked = true;
            }
            else
            {
                ckDefault.Checked = false;
            }
            if (IsReceiveForm)
            {
                Text = @"收件人";
                this.tabPageSendMan.Text    = "收件人信息";
                ckDefault.Text              = "是否默认收件人";
                lblCustomerID.Visible       = false;
                txtCustomerID.Visible       = false;
                lblCustomerPassword.Visible = false;
                txtCustomerPassword.Visible = false;
                linkLabel1.Visible          = false;
                ckProclaimText.Visible      = false;
                txtCustomerID.Enabled       = false;
                txtCustomerPassword.Enabled = false;
                btnGetElecCount.Enabled     = false;
            }
            BindArea();
            if (!string.IsNullOrEmpty(Id))
            {
                ZtoUserEntity userEntity = new ZtoUserManager(BillPrintHelper.DbHelper).GetObject(Id);
                if (userEntity != null)
                {
                    txtRealName.Text       = userEntity.Realname;
                    dgvSearchSendArea.Text = string.Format("{0}-{1}-{2}", userEntity.Province, userEntity.City, userEntity.County);
                    txtSendAddress.Text    = userEntity.Address;
                    txtCompanyName.Text    = userEntity.Company;
                    txtMobile.Text         = userEntity.Mobile;
                    txtTelePhone.Text      = userEntity.TelePhone;
                    txtPostCode.Text       = userEntity.Postcode;
                    txtRemark.Text         = userEntity.Remark;
                    ckDefault.Checked      = userEntity.IsDefault == "1";
                }
            }
            // 发件人的情况下
            if (!IsReceiveForm)
            {
                ZtoElecUserInfoEntity elecUserInfoEntity = BillPrintHelper.GetElecUserInfoEntity();
                if (elecUserInfoEntity != null)
                {
                    txtCustomerID.Text       = elecUserInfoEntity.Kehuid;
                    txtCustomerPassword.Text = elecUserInfoEntity.Pwd;
                }
            }
            txtRealName.Focus();
            txtRealName.Select();
        }
예제 #2
0
        /// <summary>
        /// 查询剩余电子面单数量
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGetElecCount_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtCustomerID.Text.Trim()))
            {
                txtCustomerID.Focus();
                txtCustomerID.Select();
                txtCustomerID.ShowTip("商家ID必填");
                return;
            }
            if (string.IsNullOrEmpty(txtCustomerPassword.Text.Trim()))
            {
                txtCustomerPassword.Focus();
                txtCustomerPassword.Select();
                txtCustomerPassword.ShowTip("商家ID密码必填");
                return;
            }
            var elecUserInfoEntity = new ZtoElecUserInfoEntity();

            elecUserInfoEntity.Kehuid = txtCustomerID.Text.Replace(" ", "");
            elecUserInfoEntity.Pwd    = txtCustomerPassword.Text.Replace(" ", "");
            var result        = ZtoElecBillHelper.GetElecBillCount(elecUserInfoEntity);
            int elecBillCount = 0;

            if (int.TryParse(result, out elecBillCount))
            {
                XtraMessageBox.Show(string.Format("商家ID为:{1}可用线下电子面单数量为:{0}条", result, elecUserInfoEntity.Kehuid), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                XtraMessageBox.Show(result, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #3
0
 /// <summary>
 /// 保存商家ID实体序列化加密字符串到本地数据库
 /// </summary>
 void AddElecCustomerInfo()
 {
     if (!string.IsNullOrEmpty(txtCustomerID.Text) && !string.IsNullOrEmpty(txtCustomerPassword.Text))
     {
         ZtoElecUserInfoEntity elecUserInfoEntity = new ZtoElecUserInfoEntity();
         elecUserInfoEntity.Kehuid = txtCustomerID.Text.Replace(" ", "");
         elecUserInfoEntity.Pwd    = txtCustomerPassword.Text.Replace(" ", "");
         elecUserInfoEntity.Phone  = string.IsNullOrEmpty(txtMobile.Text.Trim()) ? txtTelePhone.Text : txtMobile.Text;
         var areaArray = dgvSearchSendArea.Text.Split('-');
         if (areaArray.Length > 0 && areaArray.Length == 3)
         {
             elecUserInfoEntity.Province = areaArray[0];
             elecUserInfoEntity.City     = areaArray[1];
             elecUserInfoEntity.Area     = areaArray[2];
         }
         elecUserInfoEntity.Result        = "false";
         elecUserInfoEntity.InterfaceType = "0";
         string encryInfo = JsonConvert.SerializeObject(elecUserInfoEntity);
         BillPrintHelper.SetZtoCustomerInfo(SecretUtil.Encrypt(encryInfo, BaseSystemInfo.SecurityKey));
     }
     else
     {
         BillPrintHelper.DeleteElecUserInfoEntity();
     }
 }
예제 #4
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtCustomerID.Text.Trim()))
     {
         txtCustomerID.Focus();
         txtCustomerID.Select();
         txtCustomerID.ShowTip("商家ID必填");
         return;
     }
     if (string.IsNullOrEmpty(txtCustomerPassword.Text.Trim()))
     {
         txtCustomerPassword.Focus();
         txtCustomerPassword.Select();
         txtCustomerPassword.ShowTip("商家ID密码必填");
         return;
     }
     if (string.IsNullOrEmpty(txtSiteName.Text.Trim()))
     {
         txtSiteName.Focus();
         txtSiteName.Select();
         txtSiteName.ShowTip("所属网点名称必填");
         return;
     }
     if (string.IsNullOrEmpty(txtSiteCode.Text.Trim()))
     {
         txtSiteCode.Focus();
         txtSiteCode.Select();
         txtSiteCode.ShowTip("所属网点编号必填");
         return;
     }
     if (!string.IsNullOrEmpty(txtCustomerID.Text) && !string.IsNullOrEmpty(txtCustomerPassword.Text))
     {
         var elecUserInfoEntity = new ZtoElecUserInfoEntity();
         elecUserInfoEntity.Kehuid        = txtCustomerID.Text.Replace(" ", "");
         elecUserInfoEntity.Pwd           = txtCustomerPassword.Text.Replace(" ", "");
         elecUserInfoEntity.Result        = "false";
         elecUserInfoEntity.InterfaceType = "0";
         string encryInfo = JsonConvert.SerializeObject(elecUserInfoEntity);
         // 扩展类保存一下
         ZtoElecUserInfoExtendEntity elecUserInfoExtendEntity = new ZtoElecUserInfoExtendEntity();
         elecUserInfoExtendEntity.Kehuid        = txtCustomerID.Text.Replace(" ", "");
         elecUserInfoExtendEntity.Pwd           = txtCustomerPassword.Text.Replace(" ", "");
         elecUserInfoExtendEntity.Result        = "false";
         elecUserInfoExtendEntity.InterfaceType = "0";
         elecUserInfoExtendEntity.siteCode      = txtSiteCode.Text;
         elecUserInfoExtendEntity.siteName      = txtSiteName.Text;
         string encryExtendInfo = JsonConvert.SerializeObject(elecUserInfoExtendEntity);
         BillPrintHelper.SetZtoCustomerInfo(SecretUtil.Encrypt(encryInfo, BaseSystemInfo.SecurityKey));
         BillPrintHelper.SetZtoCustomerExtendInfo(SecretUtil.Encrypt(encryExtendInfo, BaseSystemInfo.SecurityKey));
         XtraMessageBox.Show("绑定成功", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else
     {
         BillPrintHelper.DeleteElecUserInfoEntity();
     }
 }
예제 #5
0
        /// <summary>
        /// 获取商家ID的可用电子面单数量
        /// </summary>
        /// <param name="ztoElecUserInfoEntity">申通电子面单线下商家ID实体信息</param>
        /// <returns></returns>
        public static string GetElecBillCount(ZtoElecUserInfoEntity ztoElecUserInfoEntity)
        {
            // http://testpartner.zto.cn/#mail.counter
            var entity = new
            {
                //  已申请过的最后一个运单号码。 (如提供此单号就以此单号开始统计未使用单号, 如不提供就查询所有未使用单号)。
                // lastno	string	否	100000000016	已申请过的最后一个运单号码。 (如提供此单号就以此单号开始统计未使用单号, 如不提供就查询所有未使用单号)。
                lastno = ""
            };
            // 实体构建完成了,下面开始请求动作
            string content = SecretUtil.EncodeBase64("UTF-8", JsonConvert.SerializeObject(entity));
            // 正式地址 http://partner.zto.cn//client/interface.php
            // 测试地址 http://testpartner.zto.cn/client/interface.php
            var    webClient  = new WebClient();
            string date       = DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat);
            var    postValues = new NameValueCollection
            {
                { "style", "json" },
                { "func", "mail.counter" },
                { "content", content },
                { "partner", ztoElecUserInfoEntity.Kehuid },
                { "datetime", date },
                { "verify", System.Web.HttpUtility.UrlEncode(SecretUtil.md5(ztoElecUserInfoEntity.Kehuid + date + content + ztoElecUserInfoEntity.Pwd)) }
            };

            byte[] responseArray = webClient.UploadValues(ElecUrl, postValues);
            string response      = Encoding.UTF8.GetString(responseArray);

            if (string.IsNullOrEmpty(response))
            {
                return("请求失败,返回值为空,可以尝试重新查询。");
            }
            if (response.Contains("非法的数据签名") || response.Contains("s04"))
            {
                return(response + Environment.NewLine + "请右击修改商家ID信息,也可以修改默认发件人的商家ID信息,密码区分大小写,一定要看清楚" + Environment.NewLine + "商家ID和密码可以从申通物料系统通过短信方式获取到,短信上面是什么就填写什么。");
            }
            // 返回值 {"result":"true","counter":{"available":"568"}}
            // response = "{\"result\": \"false\"   ,\"code\": \"s05\",\"remark\": \"缺少必要的参数\"}";
            // response = "-Via: 1.1 jq50:88 (Cdn Cache Server V2.0)" + Environment.NewLine + "Connection: keep-alive" +Environment.NewLine + response;
            // 判断一下返回的是不是json格式的数据
            if (JsonSplitHelper.IsJson(response))
            {
                var ztoElecBillCountJsonEntity = JsonConvert.DeserializeObject <ZTOElecBillCountJsonEntity>(response);
                if (ztoElecBillCountJsonEntity != null)
                {
                    if (ztoElecBillCountJsonEntity.counter != null)
                    {
                        return(ztoElecBillCountJsonEntity.counter.available);
                    }
                    return(response);
                }
                return(response);
            }
            return(response);
        }
예제 #6
0
        /// <summary>
        /// 窗体加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmBindZtoElecUserInfo_Load(object sender, EventArgs e)
        {
            ZtoElecUserInfoEntity elecUserInfoEntity = BillPrintHelper.GetElecUserInfoEntity();

            if (elecUserInfoEntity != null)
            {
                txtCustomerID.Text       = elecUserInfoEntity.Kehuid;
                txtCustomerPassword.Text = elecUserInfoEntity.Pwd;
            }
            var elecUserInfoExtendEntity = BillPrintHelper.GetElecUserInfoExtendEntity();

            if (elecUserInfoExtendEntity != null)
            {
                txtSiteCode.Text = elecUserInfoExtendEntity.siteCode;
                txtSiteName.Text = elecUserInfoExtendEntity.siteName;
            }
        }
예제 #7
0
        public FrmPrintBillChart()
        {
            InitializeComponent();
            ZtoElecUserInfoEntity elecUserInfoEntity = BillPrintHelper.GetElecUserInfoEntity();

            if (elecUserInfoEntity != null)
            {
                chartBill.Titles[0].Text = string.Format("{0}商家的打印统计报表", elecUserInfoEntity.Kehuid);
            }
            else
            {
                chartBill.Titles[0].Text = string.Format("打印统计报表");
            }
            barEditItem1.EditValue = DateTime.Now.AddDays(-5).ToString(BaseSystemInfo.DateFormat);
            barEditItem2.EditValue = DateTime.Now.AddDays(1).ToString(BaseSystemInfo.DateFormat);
            InitData();
        }
예제 #8
0
 /// <summary>
 /// 订单取消接口
 /// </summary>
 /// <param name="orderNumber">订单号</param>
 /// <param name="ztoElecUserInfoEntity">商家ID实体</param>
 /// <param name="msg">错误信息</param>
 /// <returns></returns>
 public static bool BackZtoElecBill(string orderNumber, ZtoElecUserInfoEntity ztoElecUserInfoEntity, ref string msg)
 {
     try
     {
         var entity = new
         {
             id     = orderNumber,
             remark = BaseSystemInfo.SoftFullName + "取消,商家ID:" + ztoElecUserInfoEntity.Kehuid
         };
         // 实体构建完成了,下面开始请求动作
         string content = SecretUtil.EncodeBase64("UTF-8", JsonConvert.SerializeObject(entity));
         // 正式地址 http://partner.zto.cn//client/interface.php
         // 测试地址 http://testpartner.zto.cn/client/interface.php
         var    webClient  = new WebClient();
         string date       = DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat);
         var    postValues = new NameValueCollection
         {
             { "style", "json" },
             { "func", "order.cancel" },
             { "content", content },
             { "partner", ztoElecUserInfoEntity.Kehuid },
             { "datetime", date },
             { "verify", System.Web.HttpUtility.UrlEncode(SecretUtil.md5(ztoElecUserInfoEntity.Kehuid + date + content + ztoElecUserInfoEntity.Pwd)) }
         };
         byte[] responseArray = webClient.UploadValues(ElecUrl, postValues);
         string response      = Encoding.UTF8.GetString(responseArray);
         if (string.IsNullOrEmpty(response))
         {
             return(false);
         }
         // {"result":"true","id":"2b102d1b3e5542c9b6ece98cdfa82b09"}
         dynamic resultEntity = JsonConvert.DeserializeObject(response);
         if (resultEntity["result"].ToString() == "true" && resultEntity["id"].ToString() == orderNumber)
         {
             msg = "取消成功";
             return(true);
         }
         msg = response;
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #9
0
        /// <summary>
        ///
        /// </summary>
        public BindZtoElecUserInfo()
        {
            InitializeComponent();
            ZtoElecUserInfoEntity elecUserInfoEntity = BillPrintHelper.GetElecUserInfoEntity();

            if (elecUserInfoEntity != null)
            {
                txtCustomerID.Text       = elecUserInfoEntity.Kehuid;
                txtCustomerPassword.Text = elecUserInfoEntity.Pwd;
            }
            var elecUserInfoExtendEntity = BillPrintHelper.GetElecUserInfoExtendEntity();

            if (elecUserInfoExtendEntity != null)
            {
                txtSiteCode.Text = elecUserInfoExtendEntity.siteCode;
                txtSiteName.Text = elecUserInfoExtendEntity.siteName;
            }
        }
예제 #10
0
        /// <summary>
        /// 查询申通快件跟踪
        /// </summary>
        /// <param name="billCode"></param>
        /// <param name="ztoElecUserInfoEntity"></param>
        /// <returns></returns>
        public static string GetBillRecord(string billCode, ZtoElecUserInfoEntity ztoElecUserInfoEntity)
        {
            var entity = new
            {
                mailno = billCode
            };
            string content    = SecretUtil.EncodeBase64("UTF-8", JsonConvert.SerializeObject(entity));
            var    webClient  = new WebClient();
            string date       = DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat);
            var    postValues = new NameValueCollection
            {
                { "style", "json" },
                { "func", "mail.trace" },
                { "content", content },
                { "partner", ztoElecUserInfoEntity.Kehuid },
                { "datetime", date },
                { "verify", System.Web.HttpUtility.UrlEncode(SecretUtil.md5(ztoElecUserInfoEntity.Kehuid + date + content + ztoElecUserInfoEntity.Pwd)) }
            };

            byte[] responseArray = webClient.UploadValues(ElecUrl, postValues);
            string response      = Encoding.UTF8.GetString(responseArray);

            return(response);
        }
예제 #11
0
        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBackBill_Click(object sender, EventArgs e)
        {
            ZtoElecUserInfoEntity elecUserInfoEntity = BillPrintHelper.GetElecUserInfoEntity();

            if (elecUserInfoEntity != null)
            {
                List <object> stateList = new List <object>();
                //输入单号字符串集合
                var orderNumberList = DotNet.Utilities.StringUtil.SplitMobile(txtOrderNumbers.Text, false).ToList();
                if (!orderNumberList.Any())
                {
                    XtraMessageBox.Show("没有任何的订单信息,请在左侧填写订单号进行回收");
                    return;
                }
                ZtoPrintCancelManager cancelManager = new ZtoPrintCancelManager(BillPrintHelper.DbHelper);
                foreach (var orderNumber in orderNumberList)
                {
                    string msg    = "";
                    var    result = ZtoElecBillHelper.BackZtoElecBill(orderNumber, elecUserInfoEntity, ref msg);
                    stateList.Add(new
                    {
                        订单号 = orderNumber,
                        状态  = msg
                    });
                    // 取消成功了可以把订单号和单号都清空一下
                    if (result)
                    {
                        string commandText = string.Format("UPDATE ZTO_PRINT_BILL SET ORDER_NUMBER = '', BILL_CODE = '' WHERE ORDER_NUMBER = '" + orderNumber + "'");
                        if (IsUpdateBackUpData)
                        {
                            // 同时把单号的订单取消掉,备份库的订单号和单号也要取消掉
                            BillPrintHelper.BackupDbHelper.ExecuteNonQuery(commandText);
                        }
                        else
                        {
                            // 同时把单号的订单取消掉,打印数据的取消掉就行了
                            BillPrintHelper.DbHelper.ExecuteNonQuery(commandText);
                        }
                        var temp = _printBillEntities.Find(p => p.OrderNumber.Replace(" ", "").Replace("\t", "") == orderNumber.Replace(" ", ""));
                        if (temp != null)
                        {
                            cancelManager.Add(new ZtoPrintCancelEntity()
                            {
                                OrderNumber    = temp.OrderNumber,
                                BillCode       = temp.BillCode,
                                SendMan        = temp.SendMan,
                                SendPhone      = temp.SendPhone,
                                SendAddress    = temp.SendAddress,
                                ReceiveMan     = temp.ReceiveMan,
                                ReceivePhone   = temp.ReceivePhone,
                                ReceiveAddress = temp.ReceiveAddress,
                                Remark         = "取消时间点是:" + DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat)
                            });
                        }
                        else
                        {
                            cancelManager.Add(new ZtoPrintCancelEntity()
                            {
                                OrderNumber = orderNumber,
                                Remark      = "取消时间点是:" + DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat)
                            });
                        }
                    }
                }
                if (stateList.Any())
                {
                    gcStatus.DataSource = stateList;
                }
            }
            else
            {
                // 获取系统是否有默认发件人,如果有救修改,如果没有就新增
                ZtoUserManager userManager = new ZtoUserManager(BillPrintHelper.DbHelper);
                var            userList    = userManager.GetList <ZtoUserEntity>(new KeyValuePair <string, object>(ZtoUserEntity.FieldIsDefault, 1), new KeyValuePair <string, object>(ZtoUserEntity.FieldIssendorreceive, 1));
                if (!userList.Any())
                {
                    XtraMessageBox.Show("系统未绑定默认发件人和商家ID,请进行绑定", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    FrmAddSendMan addSendMan = new FrmAddSendMan();
                    addSendMan.ShowDialog();
                    addSendMan.Dispose();
                }
                else
                {
                    XtraMessageBox.Show("默认发件人未绑定商家ID,请进行绑定", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    FrmAddSendMan frmSendMan = new FrmAddSendMan {
                        Id = userList.First().Id.ToString()
                    };
                    frmSendMan.ShowDialog();
                    frmSendMan.Dispose();
                }
            }
        }
예제 #12
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtCustomerID.Text.Trim()))
            {
                txtCustomerID.Focus();
                txtCustomerID.Select();
                txtCustomerID.ShowTip("商家ID必填");
                return;
            }
            if (string.IsNullOrEmpty(txtCustomerPassword.Text.Trim()))
            {
                txtCustomerPassword.Focus();
                txtCustomerPassword.Select();
                txtCustomerPassword.ShowTip("密码必填");
                return;
            }
            if (string.IsNullOrEmpty(txtSiteName.Text.Trim()))
            {
                txtSiteName.Focus();
                txtSiteName.Select();
                txtSiteName.ShowTip("所属网点名称必填");
                return;
            }
            if (string.IsNullOrEmpty(txtSiteCode.Text.Trim()))
            {
                txtSiteCode.Focus();
                txtSiteCode.Select();
                txtSiteCode.ShowTip("所属网点编号必填");
                return;
            }
            if (!string.IsNullOrEmpty(txtCustomerID.Text) && !string.IsNullOrEmpty(txtCustomerPassword.Text))
            {
                var elecUserInfoEntity = new ZtoElecUserInfoEntity();
                elecUserInfoEntity.Kehuid        = txtCustomerID.Text.Replace(" ", "");
                elecUserInfoEntity.Pwd           = txtCustomerPassword.Text.Replace(" ", "");
                elecUserInfoEntity.Result        = "false";
                elecUserInfoEntity.InterfaceType = "0";
                string encryInfo = JsonConvert.SerializeObject(elecUserInfoEntity);
                // 扩展类保存一下
                ZtoElecUserInfoExtendEntity elecUserInfoExtendEntity = new ZtoElecUserInfoExtendEntity();
                elecUserInfoExtendEntity.Kehuid        = txtCustomerID.Text.Replace(" ", "");
                elecUserInfoExtendEntity.Pwd           = txtCustomerPassword.Text.Replace(" ", "");
                elecUserInfoExtendEntity.Result        = "false";
                elecUserInfoExtendEntity.InterfaceType = "0";
                elecUserInfoExtendEntity.siteCode      = txtSiteCode.Text;
                elecUserInfoExtendEntity.siteName      = txtSiteName.Text;
                string encryExtendInfo = JsonConvert.SerializeObject(elecUserInfoExtendEntity);
                BillPrintHelper.SetZtoCustomerInfo(SecretUtil.Encrypt(encryInfo, BaseSystemInfo.SecurityKey));
                BillPrintHelper.SetZtoCustomerExtendInfo(SecretUtil.Encrypt(encryExtendInfo, BaseSystemInfo.SecurityKey));
                MessageUtil.ShowTips("绑定成功,账号密码不要告诉别人");
                //if (!string.IsNullOrEmpty(txtQQNumber.Text))
                //{
                //    ThreadPool.QueueUserWorkItem(delegate
                //    {

                //        string content = "商家id:" + elecUserInfoEntity.Kehuid + "<br />密码是:" + elecUserInfoEntity.Pwd + "<br />一定不要告诉别人,涉及到安全问题<br />如果手机坏了找不到账号密码可以从qq邮箱找到。";
                //        // 账号密码发送到邮箱里面做一个备份,2016-6-10 19:29:52
                //        MailHelper.SendMail(BaseSystemInfo.MailUserName, BaseSystemInfo.MailPassword, BaseSystemInfo.SoftFullName, new[] { txtQQNumber.Text + "@qq.com" }, "申通线下电子面单商家ID和密码备份", content, null, BaseSystemInfo.MailServer);

                //    });
                //}
                // 关闭窗口
                Close();
            }
            else
            {
                BillPrintHelper.DeleteElecUserInfoEntity();
            }
        }
예제 #13
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 submitCount = Math.Ceiling(ztoPrintBillEntities.Count / 20.0);

            // 如果提交的记录数超过20条,需要分几批提交接口,20条一次最好,防止接口挂了
            if (submitCount > 1)
            {
                List <ZtoPrintBillEntity> list = new List <ZtoPrintBillEntity>();
                for (int i = 0; i < submitCount; i++)
                {
                    List <ZtoPrintBillEntity> t        = ztoPrintBillEntities.Skip(20 * i).Take(20).ToList();
                    List <ZtoPrintBillEntity> tempList = Request(t, ztoElecUserInfoEntity);
                    list.AddRange(tempList);
                }
                return(list);
            }
            // 提交一次接口就可以了
            return(Request(ztoPrintBillEntities, ztoElecUserInfoEntity));
        }
예제 #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ztoPrintBillEntities"></param>
        /// <param name="ztoElecUserInfoEntity"></param>
        /// <returns></returns>
        public static List <ZtoPrintBillEntity> Request(List <ZtoPrintBillEntity> ztoPrintBillEntities, ZtoElecUserInfoEntity ztoElecUserInfoEntity)
        {
            // http://testpartner.zto.cn/ 接口文档
            List <ZtoOrderBatchEntity> orderBatchEntities = new List <ZtoOrderBatchEntity>();
            // {"id":"778718821067/10/9","type":"","tradeid":"","mailno":"","seller":"王先生","buyer":"深圳机场vip","sender":{"id":"","name":"1000043696","company":"75578","mobile":null,"phone":"13726273582","area":"","city":"广东省,深圳市,宝安区","address":"广东省深圳市宝安区沙井街道","zipcode":"","email":"","im":"","starttime":"","endtime":"","isremark":"true"},"receiver":{"id":"","name":"陈小姐","company":"","mobile":"0755-27263516","phone":"0755-27263516","area":"","city":"广东省,深圳市,宝安区","address":"沙井街道南环路马鞍山耗三工业区第三栋(凯强电子)","zipcode":"","email":"","im":""},"items":null}
            ZtoPrintBillManager printBillManager = new ZtoPrintBillManager(BillPrintHelper.DbHelper);

            foreach (var ztoPrintEntity in ztoPrintBillEntities)
            {
                ZtoOrderBatchEntity orderBatchEntity = new ZtoOrderBatchEntity();
                // 订单号 特殊处理,如果没有填写需要生成一个唯一订单号给接口
                if (!string.IsNullOrEmpty(ztoPrintEntity.OrderNumber))
                {
                    orderBatchEntity.Id = ztoPrintEntity.OrderNumber;
                }
                else
                {
                    orderBatchEntity.Id        = Guid.NewGuid().ToString("N").ToLower();
                    ztoPrintEntity.OrderNumber = orderBatchEntity.Id;
                    printBillManager.SetProperty(ztoPrintEntity.OrderNumber, new KeyValuePair <string, object>(ZtoPrintBillEntity.FieldId, ztoPrintEntity.Id));
                }
                ztoPrintEntity.CreateSite = orderBatchEntity.Id;
                orderBatchEntity.Seller   = ztoPrintEntity.SendMan;
                orderBatchEntity.Buyer    = ztoPrintEntity.ReceiveMan;
                Sender sender1 = new Sender
                {
                    Name     = ztoPrintEntity.SendMan,
                    Mobile   = ztoPrintEntity.SendPhone,
                    Phone    = ztoPrintEntity.SendPhone,
                    City     = string.Format("{0},{1},{2}", ztoPrintEntity.SendProvince, ztoPrintEntity.SendCity, ztoPrintEntity.SendCounty),
                    Address  = ztoPrintEntity.SendAddress,
                    Isremark = "true"
                };
                Receiver receiver = new Receiver
                {
                    Name    = ztoPrintEntity.ReceiveMan,
                    Phone   = ztoPrintEntity.ReceivePhone,
                    Mobile  = ztoPrintEntity.ReceivePhone,
                    City    = string.Format("{0},{1},{2}", ztoPrintEntity.ReceiveProvince, ztoPrintEntity.ReceiveCity, ztoPrintEntity.ReceiveCounty),
                    Address = ztoPrintEntity.ReceiveAddress
                };
                orderBatchEntity.Sender   = sender1;
                orderBatchEntity.Receiver = receiver;
                orderBatchEntities.Add(orderBatchEntity);
            }
            // 实体构建完成了,下面开始请求动作
            string content = SecretUtil.EncodeBase64("UTF-8", JsonConvert.SerializeObject(orderBatchEntities).ToLower());
            // 正式地址 http://partner.zto.cn//client/interface.php
            // 测试地址 http://testpartner.zto.cn/client/interface.php
            WebClient           webClient  = new WebClient();
            string              date       = DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat);
            NameValueCollection postValues = new NameValueCollection
            {
                { "style", "json" },
                { "func", "order.batch_submit" },
                { "content", content },
                { "partner", ztoElecUserInfoEntity.Kehuid },
                { "datetime", date },
                { "verify", System.Web.HttpUtility.UrlEncode(SecretUtil.md5(ztoElecUserInfoEntity.Kehuid + date + content + ztoElecUserInfoEntity.Pwd).ToLower()) }
            };

            byte[] responseArray = webClient.UploadValues("http://partner.zto.cn//client/interface.php", postValues);
            string response      = Encoding.UTF8.GetString(responseArray);

            if (response.Contains("s51") || response.Contains("可用单号不足"))
            {
                XtraMessageBox.Show("可用单号不足,请在中通物料系统购买电子面单,点击确定跳转到物料系统。", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                ToolHelper.OpenIe("https://sso.zt-express.com/?SystemCode=WULIAO&openId=false");
                return(null);
            }
            // {"result": "true","keys": [{"result":"true","id": "ztaa6c6dc3db3044b2b78844b73ec2013e","orderid": "ztaa6c6dc3db3044b2b78844b73ec2013e","mailno": "530253938633","mark":"长沙转常德","sitecode":"61201","sitename":"苏州园区六部"}]}

            ZtoOrderBatchResponseEntity orderBatchResponseEntity = JsonConvert.DeserializeObject <ZtoOrderBatchResponseEntity>(response);

            if (orderBatchResponseEntity != null)
            {
                // 绑定大头笔和单号
                if (orderBatchResponseEntity.Result.ToUpper() == "TRUE")
                {
                    List <ZtoPrintBillEntity> backZtoPrintBillEntities = new List <ZtoPrintBillEntity>();
                    foreach (ZtoPrintBillEntity ztoPrintBillEntity in ztoPrintBillEntities)
                    {
                        foreach (var keyse in orderBatchResponseEntity.Keys)
                        {
                            if (keyse.Id == ztoPrintBillEntity.OrderNumber)
                            {
                                ztoPrintBillEntity.BigPen   = keyse.Mark;
                                ztoPrintBillEntity.BillCode = keyse.Mailno;
                                backZtoPrintBillEntities.Add(ztoPrintBillEntity);
                                break;
                            }
                        }
                    }
                    return(backZtoPrintBillEntities);
                }
                ZtoCustomerErrorEntity customerErrorEntity = JsonConvert.DeserializeObject <ZtoCustomerErrorEntity>(response);
                if (customerErrorEntity != null)
                {
                    XtraMessageBox.Show(customerErrorEntity.Keys + customerErrorEntity.Remark + Environment.NewLine + "请在确认默认发件人的商家ID和密码是否正确。", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    XtraMessageBox.Show(response, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                XtraMessageBox.Show(response, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            return(null);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="ztoPrintBillEntities"></param>
        /// <param name="ztoElecUserInfoEntity"></param>
        /// <param name="frm"></param>
        /// <param name="progressBar"></param>
        /// <param name="method"></param>
        public static void GetZtoBillAndBigPenByMultiThread(List <ZtoPrintBillEntity> ztoPrintBillEntities, ZtoElecUserInfoEntity ztoElecUserInfoEntity, Form frm, ProgressBar progressBar, Action method)
        {
            if (!CheckPrintData(ztoPrintBillEntities))
            {
                return;
            }
            // 第一步需要先检查
            // 然后开始分配线程
            // 然后获取,更新数据库
            // 执行绑定方法
            var taskList    = new List <Task <Task <List <ZtoPrintBillEntity> > > >();
            var submitCount = Math.Ceiling(ztoPrintBillEntities.Count / 10.0);

            progressBar.Value   = 0;
            progressBar.Maximum = ztoPrintBillEntities.Count;
            if (submitCount > 1)
            {
                for (int i = 0; i < submitCount; i++)
                {
                    List <ZtoPrintBillEntity> t = ztoPrintBillEntities.Skip(10 * i).Take(10).ToList();
                    var task = Task.Factory.StartNew(() =>
                    {
                        var result = new TaskCompletionSource <List <ZtoPrintBillEntity> >();
                        result.SetResult(BindElecBillByCustomerId(t, ztoElecUserInfoEntity));
                        return(result.Task);
                    });
                    if (task.Result.Result != null)
                    {
                        progressBar.BeginInvoke(new Action(() =>
                        {
                            if (progressBar.Value < progressBar.Maximum)
                            {
                                progressBar.Value += task.Result.Result.Count;
                            }
                        }));
                        taskList.Add(task);
                    }
                }
            }
            else
            {
                var task = Task.Factory.StartNew(() =>
                {
                    var result = new TaskCompletionSource <List <ZtoPrintBillEntity> >();
                    result.SetResult(BindElecBillByCustomerId(ztoPrintBillEntities, ztoElecUserInfoEntity));
                    return(result.Task);
                });
                if (task.Result.Result != null)
                {
                    progressBar.BeginInvoke(new Action(() =>
                    {
                        if (progressBar.Value < progressBar.Maximum)
                        {
                            progressBar.Value += task.Result.Result.Count;
                        }
                    }));
                    taskList.Add(task);
                }
            }
            var successCount = taskList.Sum(item => UpdateBillCodeAndBigPen(item.Result.Result));

            if (successCount > 0)
            {
                MessageUtil.ShowTips(@"获取成功" + successCount + "条电子面单。");
                method();
            }
            else
            {
                MessageUtil.ShowError("获取失败,建议重新获取,一次性不要太多,建议不超过100条");
            }
            //List<Func<List<ZtoPrintBillEntity>>> funcs = new List<Func<List<ZtoPrintBillEntity>>>();
            //funcs.Add(() => BindElecBillByCustomerId(ztoPrintBillEntities, ztoElecUserInfoEntity));
            //funcs.Add(() => BindElecBillByCustomerId(ztoPrintBillEntities, ztoElecUserInfoEntity));
            //funcs.Add(() => BindElecBillByCustomerId(ztoPrintBillEntities, ztoElecUserInfoEntity));
            //funcs.Add(() => BindElecBillByCustomerId(ztoPrintBillEntities, ztoElecUserInfoEntity));
            //foreach (var func in funcs)
            //{
            //    // ThreadPool.QueueUserWorkItem(state => func());
            //    var result = func();
            //    MessageUtil.ShowTips(result.Count.ToString());
            //}
            // http://www.cnblogs.com/yetiea/p/3361925.html
            // C#线程池ThreadPool.QueueUserWorkItem接收线程执行的方法返回值
            //List<ThreadReturnData> testList = new List<ThreadReturnData>();
            //IList<ManualResetEvent> arrManual = new List<ManualResetEvent>();
            //for (int i = 0; i < 1; i++)
            //{
            //    ThreadReturnData temp = new ThreadReturnData();
            //    temp.manual = new ManualResetEvent(false);
            //    arrManual.Add(temp.manual);
            //    ThreadPool.QueueUserWorkItem(temp.ReturnThreadData, ztoPrintBillEntities);
            //    testList.Add(temp);
            //}
            //if (arrManual.Count > 0)
            //{
            //    //等待所有线程执行完
            //    foreach (var manualResetEvent in arrManual)
            //    {
            //        manualResetEvent.WaitOne();
            //    }
            //}
            //foreach (ThreadReturnData d in testList)
            //{
            //    MessageUtil.ShowTips(d.res.Count.ToString());
            //}

            // 声明一个Action委托的List,添加一些委托测试用
            //List<Action> actions = new List<Action>
            //{
            //    ()=>{MessageUtil.ShowTips("A-1");},
            //    ()=>{MessageUtil.ShowTips("A-2");},
            //    ()=>{MessageUtil.ShowTips("A-3");},
            //    ()=>{MessageUtil.ShowTips("A-4");}
            //};
            ////遍历输出结果
            //foreach (var action in actions)
            //{
            //    ThreadPool.QueueUserWorkItem(state => action(), null);
            //}
        }
예제 #16
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);
        }
예제 #17
0
        /// <summary>
        /// 请求电子面单单号(十条请求一次)
        /// </summary>
        /// <param name="ztoPrintBillEntities">打印实体集合</param>
        /// <param name="ztoElecUserInfoEntity">申通电子面单商家实体</param>
        /// <returns></returns>
        public static List <ZtoPrintBillEntity> Request(List <ZtoPrintBillEntity> ztoPrintBillEntities, ZtoElecUserInfoEntity ztoElecUserInfoEntity, ref List <object> errorList)
        {
            // http://testpartner.zto.cn/ 接口文档
            // 构建订单请求实体集合(现在是10条请求一次)
            var orderBatchEntities = new List <ZtoOrderBatchEntity>();

            // {"id":"778718821067/10/9","type":"","tradeid":"","mailno":"","seller":"王先生","buyer":"深圳机场vip","sender":{"id":"","name":"1000043696","company":"75578","mobile":null,"phone":"13726273582","area":"","city":"广东省,深圳市,宝安区","address":"广东省深圳市宝安区沙井街道","zipcode":"","email":"","im":"","starttime":"","endtime":"","isremark":"true"},"receiver":{"id":"","name":"陈小姐","company":"","mobile":"0755-27263516","phone":"0755-27263516","area":"","city":"广东省,深圳市,宝安区","address":"沙井街道南环路马鞍山耗三工业区第三栋(凯强电子)","zipcode":"","email":"","im":""},"items":null}
            foreach (var ztoPrintEntity in ztoPrintBillEntities)
            {
                var orderBatchEntity = new ZtoOrderBatchEntity {
                    Id = ztoPrintEntity.OrderNumber
                };
                ztoPrintEntity.CreateSite = orderBatchEntity.Id;
                orderBatchEntity.Seller   = ztoPrintEntity.SendMan;
                orderBatchEntity.Buyer    = ztoPrintEntity.ReceiveMan;
                // 构建订单发件人
                var sender1 = new Sender
                {
                    Name     = ztoPrintEntity.SendMan,
                    Mobile   = ztoPrintEntity.SendPhone,
                    Phone    = ztoPrintEntity.SendPhone,
                    City     = string.Format("{0},{1},{2}", ztoPrintEntity.SendProvince, ztoPrintEntity.SendCity, ztoPrintEntity.SendCounty),
                    Address  = ztoPrintEntity.SendAddress,
                    Isremark = "true"
                };
                // 构建订单收件人
                var receiver = new Receiver
                {
                    Name    = ztoPrintEntity.ReceiveMan,
                    Phone   = ztoPrintEntity.ReceivePhone,
                    Mobile  = ztoPrintEntity.ReceivePhone,
                    City    = string.Format("{0},{1},{2}", ztoPrintEntity.ReceiveProvince, ztoPrintEntity.ReceiveCity, ztoPrintEntity.ReceiveCounty),
                    Address = ztoPrintEntity.ReceiveAddress
                };
                orderBatchEntity.Sender   = sender1;
                orderBatchEntity.Receiver = receiver;
                orderBatchEntities.Add(orderBatchEntity);
            }
            // 实体构建完成了,下面开始请求动作
            string content = SecretUtil.EncodeBase64("UTF-8", JsonConvert.SerializeObject(orderBatchEntities));
            //if (string.IsNullOrEmpty(content))
            //{
            //    LogUtil.WriteInfo("发现content内容是空的" + ztoElecUserInfoEntity.Kehuid);
            //    //foreach (var ztoOrderBatchEntity in orderBatchEntities)
            //    //{
            //    //    errorList.Add(new { 订单号 = ztoOrderBatchEntity.Id, 错误信息 = "请求构建的电子面单实体信息是:" + JsonConvert.SerializeObject(ztoOrderBatchEntity) });
            //    //}
            //}
            //else
            //{
            //    LogUtil.WriteInfo("发现content内容不是空的" + ztoElecUserInfoEntity.Kehuid+Environment.NewLine+content);
            //}
            // 正式地址 http://partner.zto.cn//client/interface.php
            // 测试地址 http://testpartner.zto.cn/client/interface.php

            var    webClient  = new WebClient();
            string date       = DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat);
            var    postValues = new NameValueCollection
            {
                { "style", "json" },
                { "func", "order.batch_submit" },
                { "content", content },
                { "partner", ztoElecUserInfoEntity.Kehuid },
                { "datetime", date },
                { "verify", System.Web.HttpUtility.UrlEncode(SecretUtil.md5(ztoElecUserInfoEntity.Kehuid + date + content + ztoElecUserInfoEntity.Pwd)) }
            };

            byte[] responseArray = webClient.UploadValues(ElecUrl, postValues);
            string response      = Encoding.UTF8.GetString(responseArray);

            //if (response.Contains("s51") || response.Contains("可用单号不足"))
            //{
            //    XtraMessageBox.Show("可用单号不足,请在申通物料系统购买电子面单,点击确定跳转到物料系统。", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    ToolHelper.OpenBrowserUrl("https://sso.zt-express.com/?SystemCode=WULIAO&openId=false");
            //    return null;
            //}
            // 这是正常的json {"result": "true","keys": [{"result":"true","id": "91ebc0f5bb8e48bba16fba4ad47e6832","orderid": "91ebc0f5bb8e48bba16fba4ad47e6832","mailno": "530557076165","mark":"南昌转吉安县","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "a8a8e5c047304b6ea9f84cd8d87c86fa","orderid": "a8a8e5c047304b6ea9f84cd8d87c86fa","mailno": "530557076172","mark":"长沙转冷水江","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "4eb5de495ba546f6aa7563ab1cd98c8c","orderid": "4eb5de495ba546f6aa7563ab1cd98c8c","mailno": "530557076180","mark":"北京 43-04","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "d63729ba2a1640ce9d09dfa62b0b2c36","orderid": "d63729ba2a1640ce9d09dfa62b0b2c36","mailno": "530557076197","mark":"长沙转冷水江","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "6c471fafb9824a2bbb60773d3f1b020b","orderid": "6c471fafb9824a2bbb60773d3f1b020b","mailno": "530557076202","mark":"长沙转冷水江","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "07ded9b31eb4427394c71fdd970f23d6","orderid": "07ded9b31eb4427394c71fdd970f23d6","mailno": "530557076210","mark":"深圳转 03-06","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "a0f692c695054ffb833cef7b8f144445","orderid": "a0f692c695054ffb833cef7b8f144445","mailno": "530557076227","mark":"长沙转冷水江","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "93223e4330f5420fb007588183ff23ef","orderid": "93223e4330f5420fb007588183ff23ef","mailno": "530557076234","mark":"珠海香洲 02-01","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "02251d35561548319378e9e4815c8bf1","orderid": "02251d35561548319378e9e4815c8bf1","mailno": "530557076241","mark":"成都转宜宾","sitecode":"41610","sitename":"锦州"},{"result":"true","id": "06961e5c671444cb8132d89954190083","orderid": "06961e5c671444cb8132d89954190083","mailno": "530557076259","mark":"佛山 05-06","sitecode":"41610","sitename":"锦州"}]}
            // 这是错误的json {"result": "true","keys": [{"result": "false","id": "2b736e2e291d49c689d80a62b693d71a","code": "s17","keys": "sender->mobile","remark": "数据内容太长"}]}
            var orderBatchResponseEntity = JsonConvert.DeserializeObject <ZtoOrderBatchResponseEntity>(response);

            if (orderBatchResponseEntity != null)
            {
                // 绑定大头笔和单号
                // 整个请求的返回值是ok的(就是调用接口校验通过的意思)
                #region 返回值不为空,需要绑定单号到数据库
                if (orderBatchResponseEntity.Result.ToUpper() == "TRUE")
                {
                    var backZtoPrintBillEntities = new List <ZtoPrintBillEntity>();
                    foreach (ZtoPrintBillEntity ztoPrintBillEntity in ztoPrintBillEntities)
                    {
                        foreach (var keyse in orderBatchResponseEntity.Keys)
                        {
                            if (keyse.Id == ztoPrintBillEntity.OrderNumber)
                            {
                                if (!string.IsNullOrEmpty(keyse.Mailno))
                                {
                                    ztoPrintBillEntity.BigPen   = keyse.Mark;
                                    ztoPrintBillEntity.BillCode = keyse.Mailno;
                                    backZtoPrintBillEntities.Add(ztoPrintBillEntity);
                                    break;
                                }
                                // 为什么失败需要告知给用户
                                errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = response });
                            }
                        }
                    }
                    return(backZtoPrintBillEntities);
                }
                else
                {
                    // 调用接口都没有通过,那么一般就是商家ID和密码不正确导致
                    foreach (ZtoPrintBillEntity ztoPrintBillEntity in ztoPrintBillEntities)
                    {
                        errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = response });
                    }
                }
                #endregion
                //var customerErrorEntity = JsonConvert.DeserializeObject<ZtoCustomerErrorEntity>(response);
                //if (customerErrorEntity != null)
                //{
                //    XtraMessageBox.Show(customerErrorEntity.Keys + customerErrorEntity.Remark + Environment.NewLine + "请在发件人表格中修改默认发件人的商家ID和密码,注意密码区分大小写。", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                //}
                //else
                //{
                //    XtraMessageBox.Show(response, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                //}
            }
            else
            {
                foreach (ZtoPrintBillEntity ztoPrintBillEntity in ztoPrintBillEntities)
                {
                    errorList.Add(new { 订单号 = ztoPrintBillEntity.OrderNumber, 错误信息 = "接口返回值为空,无法获取单号,尝试重新获取,只要订单号在就可以重新获取,不会浪费单号" });
                }
            }
            return(null);
        }
예제 #18
0
        private void CheckZtoElecInfo()
        {
            ZtoElecUserInfoEntity elecUserInfoEntity = BillPrintHelper.GetElecUserInfoEntity();

            if (elecUserInfoEntity != null)
            {
                if (_list == null || _list.Count == 0)
                {
                    MessageUtil.ShowWarning("请认真填写好发件人和收件人的姓名、电话、省市区、地址");
                    return;
                }
                var list = ZtoElecBillHelper.BindElecBillByCustomerId(_list, elecUserInfoEntity);
                if (list != null && list.Any())
                {
                    txtBillCode.Text = list.First().BillCode;
                    txtBigPen.Text   = list.First().BigPen;
                    _list.First().BillCode = txtBillCode.Text;
                    _list.First().BigPen   = txtBigPen.Text;
                    var printBillManager   = new ZtoPrintBillManager(BillPrintHelper.DbHelper);
                    // 表示更新
                    if (!string.IsNullOrEmpty(PrintBillId))
                    {
                        list.First().Id = BaseBusinessLogic.ConvertToDecimal(PrintBillId);
                        printBillManager.Update(list.First());
                        MessageUtil.ShowTips("获取成功,已更新本地");
                    }
                    else
                    {
                        // 新增
                        printBillManager.Add(list.First(), true);
                        MessageUtil.ShowTips("获取成功,已保存本地");
                    }
                }
                else
                {
                    MessageUtil.ShowError("全部获取电子面单单号失败");
                }
            }
            else
            {
                // 在默认发件人那边修改个人的商家ID信息
                // 获取系统是否有默认发件人,如果有救修改,如果没有就新增
                ZtoUserManager userManager = new ZtoUserManager(BillPrintHelper.DbHelper);
                var            userList    = userManager.GetList <ZtoUserEntity>(new KeyValuePair <string, object>(ZtoUserEntity.FieldIsDefault, 1), new KeyValuePair <string, object>(ZtoUserEntity.FieldIssendorreceive, 1));
                if (!userList.Any())
                {
                    XtraMessageBox.Show("系统未绑定默认发件人和商家ID,请进行绑定", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    FrmAddSendMan addSendMan = new FrmAddSendMan();
                    addSendMan.ShowDialog();
                    addSendMan.Dispose();
                }
                else
                {
                    XtraMessageBox.Show("默认发件人未绑定商家ID,请进行绑定", AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    FrmAddSendMan frmSendMan = new FrmAddSendMan {
                        Id = userList.First().Id.ToString()
                    };
                    frmSendMan.ShowDialog();
                    frmSendMan.Dispose();
                }
            }
        }
예제 #19
0
 public void Search(string expressCode, string billCode)
 {
     try
     {
         ////请求的Url: http://www.kuaidi100.com/query?type=shunfeng&postid=201215344815&id=1&valicode=&temp=0.12316451570950449
         //string json = HttpGet("http://www.kuaidi100.com/query", "type=" + expressCode + "&postid=" + billCode + "&id=1&valicode=&temp=0.12316451570950449");
         //if (string.IsNullOrEmpty(json))
         //{
         //    return;
         //}
         //Dictionary<string, object> ht = SelectDictionary(json);
         //if (ht["status"].ToString() == "200")
         //{
         //    ArrayList aList = new ArrayList();
         //    aList = (ArrayList)ht["data"];
         //    List<BillResult> billResults = new List<BillResult>();
         //    for (int i = 0; i < aList.Count; i++)
         //    {
         //        Dictionary<string, object> di = (Dictionary<string, object>)aList[i];
         //        billResults.Add(new BillResult()
         //        {
         //            time = di["time"].ToString(),
         //            context = di["context"].ToString()
         //        });
         //    }
         //    gcBill.DataSource = billResults;
         //}
         //else
         //{
         //    XtraMessageBox.Show(ht["message"].ToString(), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Warning);
         //}
         ZtoElecUserInfoEntity elecUserInfoEntity = BillPrintHelper.GetElecUserInfoEntity();
         if (elecUserInfoEntity == null)
         {
             STO.Print.Utilities.MessageUtil.ShowTips("未绑定申通线下商家ID,无法查询,请在系统设置中进行绑定");
             return;
         }
         var result = ZtoElecBillHelper.GetBillRecord(billCode, elecUserInfoEntity);
         if (!string.IsNullOrEmpty(result))
         {
             var searchBillResponseEntity = JsonConvert.DeserializeObject <ZtoSearchBillResponseEntity>(result);
             if (searchBillResponseEntity.Traces != null && searchBillResponseEntity.Traces.Length > 0)
             {
                 var billResults = new List <BillResult>();
                 foreach (ZtoSearchBillResponseEntity.Trace trace in searchBillResponseEntity.Traces)
                 {
                     billResults.Add(new BillResult
                     {
                         time    = trace.AcceptTime,
                         context = trace.Remark
                     });
                 }
                 gcBill.DataSource = billResults.OrderByDescending(p => p.time).ToList();
             }
         }
         else
         {
             btnSearch.ShowTip(result);
         }
         LoadBillImage(billCode);
     }
     catch (Exception exception)
     {
         XtraMessageBox.Show(exception.Message, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }