SF打印

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using OMS_Client.SFService;

namespace OMS_Client.ots.SFPrint
{
    public partial class Form2 : Form
    {
        #region 初始化
        CommonWB.CommonWB Conn = new OMS_Client.CommonWB.CommonWB();
        //DataBaseAccessWB.DataBaseAccess db = new DataBaseAccessWB.DataBaseAccess();
        DataTable dt = new DataTable();
        XmlDocument xd = new XmlDocument();
        List<RDCConfigModel> RDC_cfg = new List<RDCConfigModel>();
        SuccessOrdersList successOrdersList = new SuccessOrdersList();
        BarCode.Code128 bc = new BarCode.Code128();
        string[] asql = new string[2];
        DataTable dtSelect = new DataTable();//选中的订单
        string path = Application.StartupPath + "/ots/SFPrint/Resources/";//顺丰LOGO位置
        string ConfigsPath = Application.StartupPath + "/ots/SFPrint/SFConfigs/RDC_Config.json";
        //string ConfigsPath = @"E:/OMS_Config/RDC_Config.json";
        //string ConfigsPath = Application.CommonAppDataPath + @"\ots\SFPrint\SFConfigs\RDC_Config.json";

        int count = 0;
        int num = 0;
        double sumWeight = 0;//选择订单的总重量
        string issue_Name = string.Empty;//发货人名称(公司名)
        string receive_name = string.Empty;//收件人名称(公司名)

        string IsFixedIssueInfo = string.Empty;
        string FixedISSUE_PARTY_ADDR = string.Empty;
        string FixedISSUE_PARTY_CONTACT = string.Empty;
        string FixedISSUE_PARTY_TEL = string.Empty;

        ArrayList sta_remark_List = new ArrayList();//多单保存的备注
        ArrayList orderIdList = new ArrayList();//多单保存的订单号
        ArrayList oms_noList = new ArrayList();//多单保存的OMS号
        ArrayList order_received_dteList = new ArrayList();//订单创建日期
        bool ordersParcelSuccess = false;//多单一裹的打印结果标记

        //bool isCanParcel = false;//是否可以一单多裹,只有选中一行的时候true
        ArrayList isPrintSuccess = new ArrayList();//多裹是否全部打印成功
        string[] mailnoArray;//多裹保存的运单号

        bool isNeedReturn_tracking_no = false;//会签回单标记    
        string xmlResultHead = string.Empty;//xml返回Head的结果
        string err = string.Empty;//存放xml返回的错误信息
        string errCode = string.Empty;//存放xml返回的错误代码

        int successNum = 0;//成功打印订单数
        int falseNum = 0;//失败打印订单数

        string customer = string.Empty;//客户
        const string JRM = "7573424493";//接入编码,测试:OSL(ZG)ZM  
        const string Checkword = "9MmqrWmQAidmt3wtvpjfvhnlsCoqYnHr";//校验码,测试:FKpdZauuU4O4  
        string mailno = "";//运单号
        string destcode = "";//目的地代码
        //string origincode = "";//原寄地代码

        string client_c = string.Empty;//客户代码
        string RDC = string.Empty;//运作RDC
        string custid;//月结账号,OSR : 7573424493  LAM:7575883916
        string dotCode;//网点代码
        string Day;//要查询多少天前的数据
        int express_type;//快件产品类别,业务类型,目前仅有的1.顺丰次日;5.顺丰次晨
        int pay_method;//付款方式,1:寄方付,2:收方付,3:第三方付
        string need_return_tracking_no;//是否要求签回单号:1:要求,其它为不要求
        string parcel_quantity;//包裹数,一个包裹对应一个运单号

        int INSURE_flag = 0;//保价标志,0否1是
        //string INSURE_Money;//保价价值
        ExpressServiceClient sf = new ExpressServiceClient();
        #region 打印面单150规格
        static float x = 0;//起点X坐标
        static float y = 0;//起点Y坐标
        static float w = 100;//宽度
        static float h = 150;//长度
        Brush b = new SolidBrush(Color.Black);
        #region 横线条1-12d的Y坐标,从上到下
        static float y1 = 0;
        static float y2 = y1 + 13;
        static float y3 = y2 + 20;
        static float y4 = y3 + 14;
        static float y5 = y4 + 13;
        static float y6 = y5 + 9;
        static float y7 = y6 + 12;
        static float y8 = y7 + 9;
        static float y9 = y8 + 15;
        static float y10 = y9 + 10;
        static float y11 = y10 + 13;
        static float y12 = y11 + 25;
        #endregion
        #region 竖线条1-12d的X坐标,从上到下
        static float x1 = x + 70;
        static float x2 = x + 10;
        static float x3 = x + 80;
        static float x4 = x + 10;
        static float x5 = x + 50;
        static float x6 = x + 40;
        static float x7 = x + 10;
        #endregion
        #endregion
        #endregion
        public Form2()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            RDC_cfg = JsonHelper.JsonToModel(RDC_cfg, JsonHelper.GetJsonFile(ConfigsPath));//Json反序列化
            for (int i = 0; i < dgv_print.ColumnCount; i++)
            {
                if (dgv_print.Columns[i].DataPropertyName.Length <= 0)
                {
                    dgv_print.Columns[i].DataPropertyName = dgv_print.Columns[i].Name;
                }
            }
            RightsManagement();
            //新增LIUZ
            //this.comboBox_customer.Items.Add("");
            //foreach (DataRow dr in User.dsUserInfo.Tables["OMS_SYS_ROLE_PARTY"].Rows)
            //{
            //    if (dr[User.Rights.CanRead.ToString()].ToString().Equals("0")) { continue; }
            //    if (dr["BELONG_DEP"].ToString() == "OSR" || dr["BELONG_DEP"].ToString() == "LAM" || dr["BELONG_DEP"].ToString() == "HSF" || dr["BELONG_DEP"].ToString() == "HWL")
            //    {
            //        this.comboBox_customer.Items.Add(dr["BELONG_DEP"].ToString());
            //    }
            //}
            //comboBox_customer.Items.Add("欧司朗");
            //comboBox_customer.Items.Add("朗德万斯");
            comboBox_customer.SelectedIndex = 0;
        }

        /// <summary>
        /// 权限管理
        /// </summary>
        public void RightsManagement()
        {
            string sql = @"select * from oms_sf_print_role where IsEnable='Y' and lower(EKPAccount)='" + User.UserAD.ToLower() + "'";
            DataTable DTUserRole = Conn.getDataSet(new string[] { sql }).Tables[0];
            //管理员拥有所有客户代码权限
            if (DTUserRole.Rows[0]["IsAdmin"].ToString().Trim() == "Y")
            {
                foreach (var item in RDC_cfg[0].RDCInfo)
                {
                    comboBox_customer.Items.Add(item.Client_c);
                }
            }
            else
            {
                foreach (var item in RDC_cfg[0].RDCInfo)
                {
                    if (DTUserRole.Select("Client_cs like '%" + item.Client_c + "%'").Length > 0)
                    {
                        comboBox_customer.Items.Add(item.Client_c);
                    }
                }
            }
            if (comboBox_customer.Items.Count==0)
            {
                MessageBox.Show("权限不足!");
            }
        }

        //选择付款方式
        private void comboBox_pay_type_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox_pay_type.SelectedIndex)
            {
                #region pay_method赋值
                case 0:
                    pay_method = 1;
                    break;
                case 1:
                    pay_method = 2;
                    break;
                case 2:
                    pay_method = 3;
                    break;
                #endregion
            }
            //让该控件失去焦点
            groupBox1.Focus();
        }

        //选择业务类型
        private void comboBox_express_type_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox_express_type.SelectedIndex)
            {
                case 0:
                    express_type = 1;
                    break;
                case 1:
                    express_type = 5;
                    break;
                case 2:
                    express_type = 2;
                    break;
                case 3:
                    express_type = 13;
                    break;
                default:
                    break;
            }
            //让该控件失去焦点
            groupBox1.Focus();
        }

        //保价
        private void checkBox_INSURE_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox_INSURE.CheckState == CheckState.Checked)
            {
                label_INSURE.Visible = true;
                textBox_INSURE.Visible = true;
                INSURE_flag = 1;
            }
            if (checkBox_INSURE.CheckState == CheckState.Unchecked)
            {
                label_INSURE.Visible = false;
                textBox_INSURE.Visible = false;
                INSURE_flag = 0;
                textBox_INSURE.Text = "";
            }
        }

        //一单多裹
        private void checkBox_parcel_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox_parcel.CheckState == CheckState.Checked)
            {
                label1_parcelNum.Visible = true;
                textBox_parcelNum.Visible = true;
                //if (isCanParcel)
                //{
                //    label1_parcelNum.Visible = true;
                //    textBox_parcelNum.Visible = true;
                //}
                //else
                //{
                //    MessageBox.Show("一单多裹只针对一个订单有效!");
                //    checkBox_parcel.CheckState = CheckState.Unchecked;
                //    return;
                //}
            }
            if (checkBox_parcel.CheckState == CheckState.Unchecked)
            {
                label1_parcelNum.Visible = false;
                textBox_parcelNum.Visible = false;
                textBox_parcelNum.Text = "1";
            }
        }

        //从OMS_ORDER_HEAD和OMS_SF_PRINT表获取符合条件需要打印的订单
        public DataTable GetTableByOMS_ORDER_HEAD(string dateA, string c, string code)
        {
            DataTable dt = new DataTable();
            string sql = "select H.OMS_NO,H.CLIENT_ORDER_NO,H.total_order_amt," +
    //-- OMS号,订单号,运作数量,
    "H.RECEIVE_PARTY_CONTACT_NAME,H.RECEIVE_PARTY_ADDR1,H.RECEIVE_PARTY_NAME,H.RECEIVE_PARTY_CITY,H.RECEIVE_PARTY_PHONE,h.receive_party_code,h.total_wt,h.sta_remark," +
    //-- 收货联系人,收货地址,收货人名称(公司名),城市,电话 ,收件人代码,总重量,备注信息
    "H.ISSUE_PARTY_NAME,H.ISSUE_PARTY_ADDR,H.ISSUE_PARTY_CONTACT,H.ISSUE_PARTY_CITY,H.ISSUE_PARTY_TEL,H.order_received_dte " +
    //-- 发货人名称(公司名),地址,联系人,城市,电话,邮编
    "from oms_order_head h where " +
    //--订单创建日期
    "h.order_received_dte >= to_date('" + dateA + "','YYYY-MM-DD') " +
    //"and h.order_received_dte <= to_date('" + dateB + "','YYYY-MM-DD') " +
    //"h.order_received_dte > to_date('2016-9-2','YYYY-MM-DD') " +
    //--客户代码
    "AND H.CLIENT_C ='" + c + "' " +
    //--运作仓库
    "AND H.OPERATING_WAREHOUSE_CODE ='" + code + "' " +
    //-- STA 备注需要注明是顺丰自提
    "AND H.sta_remark LIKE '%顺丰自提%' " +
    //不在顺丰打印表里的
    "AND H.CLIENT_ORDER_NO not in (select CLIENT_ORDER_NO from oms_sf_print) " +
    //"and h.wms_report_02 is null " +
    "order by h.total_order_amt desc ";

            //            //测试
//            string sql = "select H.OMS_NO,H.CLIENT_ORDER_NO,H.total_order_amt," +
////-- OMS号,订单号,运作数量,
//"H.RECEIVE_PARTY_CONTACT_NAME,H.RECEIVE_PARTY_ADDR1,H.RECEIVE_PARTY_NAME,H.RECEIVE_PARTY_CITY,H.RECEIVE_PARTY_PHONE,h.receive_party_code,h.total_wt,h.sta_remark," +
////-- 收货联系人,收货地址,收货人名称(公司名),城市,电话 ,收件人代码,总重量,备注信息
//"H.ISSUE_PARTY_NAME,H.ISSUE_PARTY_ADDR,H.ISSUE_PARTY_CONTACT,H.ISSUE_PARTY_CITY,H.ISSUE_PARTY_TEL,H.order_received_dte " +
////-- 发货人名称(公司名),地址,联系人,城市,电话,邮编
//"from oms_order_head h where " +
////--订单创建日期
//"h.order_received_dte >= to_date('2016-06-20','YYYY-MM-DD') " +
//                "and h.order_received_dte <= to_date('2017-06-22','YYYY-MM-DD') " +
////"h.order_received_dte > to_date('2016-9-2','YYYY-MM-DD') " +
////--客户代码
//"AND H.CLIENT_C ='" + c + "' " +
////--运作仓库
//"AND H.OPERATING_WAREHOUSE_CODE ='STA GUANGZHOU1' " +
////-- STA 备注需要注明是顺丰自提
////"AND H.sta_remark LIKE '%顺丰自提%' " +
////不在顺丰打印表里的
//"AND H.CLIENT_ORDER_NO not in (select CLIENT_ORDER_NO from oms_sf_print) " +
////"and h.wms_report_02 is null " +
//"order by h.total_order_amt desc ";


            dt = Conn.getDataSet(new string[] { sql }).Tables[0];
            return dt;
        }

        //选择客户
        private void comboBox_customer_SelectedIndexChanged(object sender, EventArgs e)
        {
            string dateA;
            foreach (var item in RDC_cfg[0].RDCInfo)
            {
                //if (comboBox_customer.Text == item.Name)
                //{
                //用客户代码匹配 修改liuz
                if (comboBox_customer.Text == item.Client_c)
                {
                    IsFixedIssueInfo = item.FixedIssueInfo.IsFixedIssueInfo.Trim();
                    FixedISSUE_PARTY_ADDR = item.FixedIssueInfo.ISSUE_PARTY_ADDR;
                    FixedISSUE_PARTY_CONTACT = item.FixedIssueInfo.ISSUE_PARTY_CONTACT;
                    FixedISSUE_PARTY_TEL = item.FixedIssueInfo.ISSUE_PARTY_TEL;

                    client_c = item.Client_c;
                    RDC = item.RDC;
                    custid = item.CusId;
                    dotCode = item.DotCode;
                    Day = item.Day;
                    express_type = Convert.ToInt32(item.AllPrint_express_type);
                    pay_method = Convert.ToInt32(item.AllPrint_pay_method);
                    need_return_tracking_no = item.AllPrint_need_return_tracking_no;
                    parcel_quantity = item.AllPrint_parcel_quantity;
                    dateA = DateTime.Now.AddDays(-Convert.ToDouble(Day)).ToString("yyyy-MM-dd");
                    dt = GetTableByOMS_ORDER_HEAD(dateA, client_c, RDC);
                    dgv_print.DataSource = dt;
                    lab_orderNum.Text = dt.Rows.Count.ToString() + "";
                    label1.Text = item.Name + "尚未打印的订单:";
                    customer = item.Name;
                    break;
                }
            }
            dgv_print.Focus();
            ClearOrderPage();
        }

        //清空订单详细页面
        public void ClearOrderPage()
        {
            foreach (Control c in tabPage2.Controls)
            {
                if (c is TextBox)
                {
                    c.Text = "";
                }
                if (c is GroupBox)
                {
                    foreach (Control t in c.Controls)
                    {
                        if (t is TextBox)
                        {
                            t.Text = "";
                        }
                    }
                }
            }
        }

        // 控制只能输入整数或小数,小数位最多位3位
        private void textBox_INSURE_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
            {
                if (e.KeyChar == '.')
                {
                    if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                        e.Handled = true;
                }
                else
                    e.Handled = true;
            }
            else
            {
                if (e.KeyChar <= 31)
                {
                    e.Handled = false;
                }
                else if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                {
                    if (((TextBox)sender).Text.Trim().Substring(((TextBox)sender).Text.Trim().IndexOf('.') + 1).Length >= 3)
                        e.Handled = true;
                }
            }
        }

        //控制只能输入数字
        private void textBox_parcelNum_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((!Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)8)
            {
                e.Handled = true;
            }
        }

        //付款方式转换
        public string Pay_method(int pay_method)
        {
            string e = string.Empty;
            switch (pay_method)
            {
                case 1:
                    e = "寄付月结";
                    break;
                case 2:
                    e = "到付";
                    break;
                case 3:
                    e = "第三方付";
                    break;
                default:
                    e = "";
                    break;
            }
            return e;
        }

        //业务类型转换
        public string Express_type(int express_type)
        {
            string e = string.Empty;
            switch (express_type)
            {
                case 1:
                    e = "顺丰次日";
                    break;
                case 2:
                    e = "顺丰隔日";
                    break;
                case 5:
                    e = "顺丰次晨";
                    break;
                //case 6:
                //    e = "顺丰即日";
                //    break;
                case 13:
                    e = "物流普运";
                    break;
                default:
                    e = "";
                    break;
            }
            return e;
        }

        /// <summary>
        /// 字体大小pt转px
        /// </summary>
        /// <param name="pt"></param>
        /// <returns></returns>
        public double GetPx(float pt)
        {
            double px = pt * 1.3;
            return px;
        }

        //全部打印按钮
        private void button_print_Click(object sender, EventArgs e)
        {
            PrintDocument pdCheck = new PrintDocument();
            PrintDialog pDialogCheck = new PrintDialog();
            pDialogCheck.Document = pdCheck;
            if (DialogResult.OK == pDialogCheck.ShowDialog())
            {
                if (pdCheck.PrinterSettings.IsValid)
                {
                    #region 初始化
                    Cursor.Current = Cursors.WaitCursor;

                    int _express_type = 1;//快件产品类别
                    int _pay_method = 2;//付款方式,1:寄付月结,2:到付,3:第三方付
                    string _need_return_tracking_no = "1";//是否要求签回单号:1:要求,其它为不要求
                    string _parcel_quantity = "1";//包裹数,一个包裹对应一个运单号
                    foreach (var item in RDC_cfg[0].RDCInfo)
                    {
                        if (comboBox_customer.Text == item.Client_c)
                        {
                            custid = item.CusId;
                            _express_type = Convert.ToInt32(item.AllPrint_express_type);
                            _pay_method = Convert.ToInt32(item.AllPrint_pay_method);
                            _need_return_tracking_no = item.AllPrint_need_return_tracking_no;
                            _parcel_quantity = item.AllPrint_parcel_quantity;
                            break;
                        }
                    }

                    successOrdersList.sol = new List<SuccessOrders>();
                    string xml = string.Empty;
                    string verifyCode1 = string.Empty;
                    string verifyCode = string.Empty;
                    string xmlResult = string.Empty;
                    mailno = "";
                    successNum = 0;
                    falseNum = 0;
                    dgv_result.Rows.Clear();
                    lab_success.Visible = false;
                    lab_false.Visible = false;
                    #endregion
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        try
                        {
                            if (IsFixedIssueInfo == "Y")
                            {
                                dt.Rows[i]["ISSUE_PARTY_ADDR"] = FixedISSUE_PARTY_ADDR;
                                dt.Rows[i]["ISSUE_PARTY_CONTACT"] = FixedISSUE_PARTY_CONTACT;
                                dt.Rows[i]["ISSUE_PARTY_TEL"] = FixedISSUE_PARTY_TEL;
                            }
                            xml = GetOrderReport.GetWebXml(dt, i, _express_type, _pay_method, _need_return_tracking_no, _parcel_quantity, "", JRM, client_c);
                            verifyCode1 = xml + Checkword;
                            verifyCode = MD5Encrypt.MD5ToBase64String(verifyCode1);
                            xmlResult = sf.sfexpressService(xml, verifyCode);
                            //test
                            //xmlResult = @"<?xml version='1.0' encoding='UTF-8'?><Response service='OrderService'><Head>OK</Head><Body><OrderResponse filter_result='2' destcode='010' mailno='444745479592' origincode='020' orderid='0360020339'/></Body></Response>";

                            #region 解析XML
                            xd.LoadXml(xmlResult);
                            var xnList = xd.SelectNodes("//Head");
                            foreach (XmlNode item in xnList)
                            {
                                xmlResultHead = item.InnerText;
                            }
                            if (xmlResultHead == "OK")//成功
                            {
                                SuccessOrders successOrders = new SuccessOrders();
                                var xnListMailNo = xd.SelectNodes("//OrderResponse");
                                foreach (XmlNode item in xnListMailNo)
                                {
                                    //获取运单号
                                    mailno = item.Attributes["mailno"].Value;
                                    destcode = item.Attributes["destcode"].Value;
                                    if (_need_return_tracking_no == "1")
                                    {
                                        successOrders.return_tracking_no = item.Attributes["return_tracking_no"].Value;
                                        successOrders.origincode = item.Attributes["origincode"].Value;
                                        isNeedReturn_tracking_no = true;
                                    }
                                }
                                successOrders.id = i;
                                successOrders.mailno = mailno;
                                successOrders.destcode = destcode;
                                successOrders.OMS_NO = dt.Rows[i]["OMS_NO"].ToString();
                                successOrders.CLIENT_ORDER_NO = dt.Rows[i]["CLIENT_ORDER_NO"].ToString();
                                successOrders.receive_party_code = dt.Rows[i]["receive_party_code"].ToString();
                                successOrders.total_wt = dt.Rows[i]["total_wt"].ToString();
                                successOrders.ISSUE_PARTY_NAME = dt.Rows[i]["ISSUE_PARTY_NAME"].ToString().Trim();

                                successOrders.ISSUE_PARTY_ADDR = dt.Rows[i]["ISSUE_PARTY_ADDR"].ToString().Trim();
                                successOrders.ISSUE_PARTY_CONTACT = dt.Rows[i]["ISSUE_PARTY_CONTACT"].ToString().Trim();
                                successOrders.ISSUE_PARTY_TEL = dt.Rows[i]["ISSUE_PARTY_TEL"].ToString().Trim();
                                //successOrders.ISSUE_PARTY_ADDR = "广州市经济技术开发区云埔工业区云埔三路12号";//广州RDC                             
                                //successOrders.ISSUE_PARTY_CONTACT = "秦沃初";//广州RDC  
                                //successOrders.ISSUE_PARTY_TEL = "020-82253451";//广州RDC  

                                successOrders.ISSUE_PARTY_CITY = dt.Rows[i]["ISSUE_PARTY_CITY"].ToString().Trim();
                                //successOrders.ISSUE_PARTY_ZIP = dt.Rows[i]["ISSUE_PARTY_ZIP"].ToString();
                                successOrders.RECEIVE_PARTY_NAME = dt.Rows[i]["RECEIVE_PARTY_NAME"].ToString().Trim();
                                successOrders.RECEIVE_PARTY_ADDR1 = dt.Rows[i]["RECEIVE_PARTY_ADDR1"].ToString().Trim();
                                successOrders.RECEIVE_PARTY_CONTACT_NAME = dt.Rows[i]["RECEIVE_PARTY_CONTACT_NAME"].ToString().Trim();
                                if (successOrders.RECEIVE_PARTY_CONTACT_NAME.Length > 6)
                                {
                                    successOrders.RECEIVE_PARTY_CONTACT_NAME = successOrders.RECEIVE_PARTY_CONTACT_NAME.Substring(0, 3);
                                }
                                successOrders.RECEIVE_PARTY_CITY = dt.Rows[i]["RECEIVE_PARTY_CITY"].ToString().Trim();
                                successOrders.RECEIVE_PARTY_PHONE = dt.Rows[i]["RECEIVE_PARTY_PHONE"].ToString().Trim();
                                //successOrders.RECEIVE_PARTY_ZIP = dt.Rows[i]["RECEIVE_PARTY_ZIP"].ToString();
                                successOrders.sta_remark = dt.Rows[i]["sta_remark"].ToString();
                                successOrders.order_received_dte = dt.Rows[i]["order_received_dte"].ToString();
                                successOrders.pay_method = _pay_method;
                                successOrders.express_type = _express_type;

                                successOrdersList.sol.Add(successOrders);
                            }
                            if (xmlResultHead == "ERR")//失败
                            {
                                errCode = "";
                                err = "";
                                var xnListErr = xd.SelectNodes("//ERROR");
                                foreach (XmlNode item in xnListErr)
                                {
                                    errCode = item.Attributes["code"].Value;
                                    err = item.InnerText;
                                }
                                dgv_result.Rows.Add(dt.Rows[i]["CLIENT_ORDER_NO"].ToString(), "下单错误:" + errCode, err);
                                falseNum++;
                            }
                            #endregion
                        }
                        catch (Exception ex)
                        {
                            dgv_result.Rows.Add(dt.Rows[i]["CLIENT_ORDER_NO"].ToString(), "系统错误", ex.ToString());
                            falseNum++;
                        }
                    }
                    if (successOrdersList.sol.Count > 0)
                    {
                        //pd.BeginPrint += new PrintEventHandler(printDocument_BeginPrint);
                        PrintDocument pd = new PrintDocument();
                        PrintPreviewDialog ppd = new PrintPreviewDialog();
                        PrintDialog pDialog = new PrintDialog();
                        pd.PrintPage += new PrintPageEventHandler(this.printDocument_PrintPage);
                        pd.EndPrint += new PrintEventHandler(printDocument_EndPrint);
                        pd.DocumentName = "SF打印";
                        ppd.Document = pd;
                        pDialog.Document = pd;
                        //print
                        //ppd.ShowDialog();//测试
                        pd.Print();
                    }

                    //打印完成后输出结果
                    lab_success.Visible = true;
                    lab_false.Visible = true;
                    lab_success.Text = "成功" + successNum + "";
                    lab_false.Text = "失败" + falseNum + "";
                    Cursor.Current = Cursors.Default;
                }
                else
                {
                    MessageBox.Show("打印机不可用!");
                    return;
                }
            }
        }

        //选择打印此批清单
        private void PrintSelected_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgv_print.SelectedRows.Count > 0)
                {
                    sumWeight = 0;
                    sta_remark_List.Clear();
                    orderIdList.Clear();
                    oms_noList.Clear();
                    order_received_dteList.Clear();
                    DataRow dr = null;
                    dtSelect = dt.Clone();
                    for (int i = dgv_print.SelectedRows.Count - 1; i >= 0; i--)
                    {
                        dr = dtSelect.NewRow();
                        dr = (dgv_print.SelectedRows[i].DataBoundItem as DataRowView).Row;
                        dtSelect.Rows.Add(dr.ItemArray);
                    }
                    textBox_OMS_selected.Text = "";
                    textBox_orderId_selected.Text = "";
                    textBox_beizhu.Text = "";

                    if (IsFixedIssueInfo == "Y")
                    {
                        dtSelect.Rows[0]["ISSUE_PARTY_ADDR"] = FixedISSUE_PARTY_ADDR;
                        dtSelect.Rows[0]["ISSUE_PARTY_CONTACT"] = FixedISSUE_PARTY_CONTACT;
                        dtSelect.Rows[0]["ISSUE_PARTY_TEL"] = FixedISSUE_PARTY_TEL;
                    }
                    textBox_ISSUE_PARTY_CONTACT.Text = dtSelect.Rows[0]["ISSUE_PARTY_CONTACT"].ToString().Trim();
                    textBox_ISSUE_PARTY_TEL.Text = dtSelect.Rows[0]["ISSUE_PARTY_TEL"].ToString().Trim();
                    textBox_issue_addr.Text = dtSelect.Rows[0]["ISSUE_PARTY_ADDR"].ToString().Trim();
                    //textBox_ISSUE_PARTY_CONTACT.Text = "秦沃初";//广州rdc
                    //textBox_ISSUE_PARTY_TEL.Text = "020-82253451";//广州rdc
                    //textBox_issue_addr.Text = "广州市经济技术开发区云埔工业区云埔三路12号";//广州rdc

                    if (dtSelect.Rows[0]["RECEIVE_PARTY_CONTACT_NAME"].ToString().Trim().Length > 8)
                    {
                        textBox_RECEIVE_PARTY_CONTACT_NAME.Text = dtSelect.Rows[0]["RECEIVE_PARTY_CONTACT_NAME"].ToString().Trim().Substring(0, 3);
                    }
                    else
                    {
                        textBox_RECEIVE_PARTY_CONTACT_NAME.Text = dtSelect.Rows[0]["RECEIVE_PARTY_CONTACT_NAME"].ToString().Trim();
                    }
                    textBox_RECEIVE_PARTY_PHONE.Text = dtSelect.Rows[0]["RECEIVE_PARTY_PHONE"].ToString().Trim();
                    textBox_receive_addr.Text = dtSelect.Rows[0]["RECEIVE_PARTY_ADDR1"].ToString().Trim();

                    issue_Name = dt.Rows[0]["ISSUE_PARTY_NAME"].ToString().Trim();
                    receive_name = dt.Rows[0]["RECEIVE_PARTY_NAME"].ToString().Trim();

                    for (int i = 0; i < dtSelect.Rows.Count; i++)
                    {
                        sumWeight += Convert.ToDouble(dtSelect.Rows[i]["total_wt"]);
                        sta_remark_List.Add(dtSelect.Rows[i]["sta_remark"].ToString());
                        orderIdList.Add(dtSelect.Rows[i]["CLIENT_ORDER_NO"].ToString());
                        oms_noList.Add(dtSelect.Rows[i]["OMS_NO"].ToString());
                        order_received_dteList.Add(dtSelect.Rows[i]["order_received_dte"].ToString());
                        if (i == dtSelect.Rows.Count - 1)
                        {
                            textBox_OMS_selected.Text += dtSelect.Rows[i]["OMS_NO"].ToString();
                            textBox_orderId_selected.Text += dtSelect.Rows[i]["CLIENT_ORDER_NO"].ToString();
                        }
                        else
                        {
                            textBox_OMS_selected.Text += dtSelect.Rows[i]["OMS_NO"].ToString() + ",";
                            textBox_orderId_selected.Text += dtSelect.Rows[i]["CLIENT_ORDER_NO"].ToString() + ",";
                        }
                    }
                    //if (dtSelect.Rows.Count == 1)
                    //{
                    //    isCanParcel = true;
                    //}
                    //else
                    //{
                    //    isCanParcel = false;
                    //}
                    checkBox_parcel.CheckState = CheckState.Unchecked;
                    comboBox_pay_type.SelectedIndex = 1;
                    comboBox_express_type.SelectedIndex = 0;
                    textBox_parcelNum.Text = "1";
                    tabControl1.SelectedIndex = 1;
                }
                else
                {
                    MessageBox.Show("你要选中一整行才能打印!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }

        //下单并打印
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox_pay_type.SelectedIndex == -1)
            {
                MessageBox.Show("请选择付款方式!");
                return;
            }
            else
            {
                if (comboBox_express_type.SelectedIndex == -1)
                {
                    MessageBox.Show("请选择业务类型!");
                    return;
                }
                else
                {
                    if (checkBox_INSURE.CheckState == CheckState.Checked && textBox_INSURE.Text.Trim() == "")
                    {
                        MessageBox.Show("请输入声明价值!");
                        return;
                    }
                    else
                    {
                        if (checkBox_parcel.CheckState == CheckState.Checked && textBox_parcelNum.Text.Trim() == "")
                        {
                            MessageBox.Show("请输入包裹数!");
                            return;
                        }
                        else
                        {
                            if (checkBox_parcel.CheckState == CheckState.Checked && Convert.ToInt32(textBox_parcelNum.Text.Trim()) < 2)
                            {
                                MessageBox.Show("包裹数必须大于2!");
                                return;
                            }
                            else
                            {
                                if (textBox_RECEIVE_PARTY_CONTACT_NAME.Text.Trim() == "" || textBox_RECEIVE_PARTY_PHONE.Text.Trim() == "" || textBox_receive_addr.Text.Trim() == "")
                                {
                                    MessageBox.Show("收件人信息不完整!");
                                    return;
                                }
                                else
                                {
                                    PrintDocument pdState = new PrintDocument();
                                    PrintDialog pDialog = new PrintDialog();
                                    if (DialogResult.OK == pDialog.ShowDialog())
                                    {
                                        if (pdState.PrinterSettings.IsValid)
                                        {

                                            Cursor.Current = Cursors.WaitCursor;
                                            #region 初始化
                                            string xml = string.Empty;
                                            string verifyCode1 = string.Empty;
                                            string verifyCode = string.Empty;
                                            string xmlResult = string.Empty;

                                            isNeedReturn_tracking_no = false;
                                            successOrdersList.sol = new List<SuccessOrders>();
                                            dgv_result.Rows.Clear();
                                            successNum = 0;
                                            falseNum = 0;
                                            lab_success.Visible = false;
                                            lab_false.Visible = false;
                                            mailno = "";
                                            destcode = "";

                                            if (checkBox_return_tracking_no.CheckState == CheckState.Checked)
                                            {
                                                need_return_tracking_no = "1";
                                            }
                                            else
                                            {
                                                need_return_tracking_no = "";
                                            }
                                            #endregion
                                            try
                                            {
                                                xml = GetOrderReport.GetWebXmlSelected(dtSelect, express_type, pay_method, need_return_tracking_no, textBox_parcelNum.Text.Trim(), custid, INSURE_flag, textBox_receive_addr.Text.Trim(), textBox_INSURE.Text.Trim(), JRM, sumWeight.ToString(), client_c);
                                                verifyCode1 = xml + Checkword;
                                                verifyCode = MD5Encrypt.MD5ToBase64String(verifyCode1);
                                                xmlResult = sf.sfexpressService(xml, verifyCode);
                                                #region 解析XML
                                                xd.LoadXml(xmlResult);
                                                var xnList = xd.SelectNodes("//Head");
                                                foreach (XmlNode item in xnList)
                                                {
                                                    xmlResultHead = item.InnerText;
                                                }
                                                if (xmlResultHead == "OK")//成功
                                                {
                                                    SuccessOrders so = new SuccessOrders();
                                                    var xnListMailNo = xd.SelectNodes("//OrderResponse");
                                                    foreach (XmlNode item in xnListMailNo)
                                                    {
                                                        //获取运单号
                                                        mailno = item.Attributes["mailno"].Value;
                                                        destcode = item.Attributes["destcode"].Value;
                                                        if (need_return_tracking_no == "1")
                                                        {
                                                            so.return_tracking_no = item.Attributes["return_tracking_no"].Value;
                                                            //origincode = item.Attributes["origincode"].Value;
                                                            //so.origincode = origincode;
                                                            so.origincode = item.Attributes["origincode"].Value;
                                                            isNeedReturn_tracking_no = true;
                                                        }
                                                    }
                                                    //textBox_mailno.Text = mailno;
                                                    #region 打印赋值
                                                    so.OMS_NO = textBox_OMS_selected.Text;
                                                    so.CLIENT_ORDER_NO = textBox_orderId_selected.Text;
                                                    so.total_wt = sumWeight.ToString();
                                                    so.ISSUE_PARTY_NAME = issue_Name.Trim();
                                                    so.ISSUE_PARTY_ADDR = textBox_issue_addr.Text.Trim();
                                                    so.ISSUE_PARTY_CONTACT = textBox_ISSUE_PARTY_CONTACT.Text.Trim();
                                                    so.ISSUE_PARTY_TEL = textBox_ISSUE_PARTY_TEL.Text.Trim();
                                                    so.RECEIVE_PARTY_NAME = receive_name.Trim();
                                                    so.RECEIVE_PARTY_ADDR1 = textBox_receive_addr.Text.Trim();
                                                    so.RECEIVE_PARTY_CONTACT_NAME = textBox_RECEIVE_PARTY_CONTACT_NAME.Text.Trim();
                                                    if (so.RECEIVE_PARTY_CONTACT_NAME.Length > 6)
                                                    {
                                                        so.RECEIVE_PARTY_CONTACT_NAME = so.RECEIVE_PARTY_CONTACT_NAME.Substring(0, 3);
                                                    }
                                                    so.RECEIVE_PARTY_PHONE = textBox_RECEIVE_PARTY_PHONE.Text.Trim();
                                                    so.pay_method = pay_method;
                                                    so.express_type = express_type;
                                                    so.INSURE_Money = textBox_INSURE.Text;
                                                    so.custid = custid;
                                                    //so.sta_remark = textBox_orderId_selected.Text;

                                                    so.mailno = mailno;
                                                    so.destcode = destcode;
                                                    successOrdersList.sol.Add(so);
                                                    #endregion
                                                    //多裹
                                                    if (Convert.ToInt32(textBox_parcelNum.Text) > 1)
                                                    {
                                                        //so.sta_remark = dtSelect.Rows[0]["sta_remark"].ToString();
                                                        //so.order_received_dte = order_received_dteList[0].ToString();
                                                        mailnoArray = mailno.Split(',');
                                                        #region 打印
                                                        PrintDocument pd2 = new PrintDocument();
                                                        pd2.PrintPage += new PrintPageEventHandler(this.pd2_PrintPage);
                                                        pd2.EndPrint += new PrintEventHandler(this.pd2__EndPrint);
                                                        PrintPreviewDialog ppd2 = new PrintPreviewDialog();
                                                        ppd2.Document = pd2;
                                                        if (pd2.PrinterSettings.IsValid)
                                                        {
                                                            //ppd2.ShowDialog();//测试
                                                            pd2.Print();
                                                        }
                                                        else
                                                        {
                                                            MessageBox.Show("打印机不可用!");
                                                            return;
                                                        }
                                                        #endregion
                                                    }
                                                    else
                                                    {
                                                        //一裹
                                                        #region 打印
                                                        PrintDocument pd1 = new PrintDocument();
                                                        pd1.PrintPage += new PrintPageEventHandler(this.pd1_PrintPage);
                                                        pd1.EndPrint += new PrintEventHandler(this.pd1_EndPrint);
                                                        PrintPreviewDialog ppd1 = new PrintPreviewDialog();
                                                        ppd1.Document = pd1;
                                                        if (pd1.PrinterSettings.IsValid)
                                                        {
                                                            //ppd1.ShowDialog();//测试
                                                            pd1.Print();
                                                        }
                                                        else
                                                        {
                                                            MessageBox.Show("打印机不可用!");
                                                            return;
                                                        }
                                                        #endregion
                                                    }
                                                }
                                                if (xmlResultHead == "ERR")//失败
                                                {
                                                    errCode = "";
                                                    err = "";
                                                    var xnListErr = xd.SelectNodes("//ERROR");
                                                    foreach (XmlNode item in xnListErr)
                                                    {
                                                        errCode = item.Attributes["code"].Value;
                                                        err = item.InnerText;
                                                    }
                                                    dgv_result.Rows.Add(textBox_orderId_selected.Text, "下单错误", "错误代码:" + errCode + "。错误信息:" + err);
                                                    tabControl1.SelectedIndex = 0;
                                                    //textBox_mailno.Text = "!下单失败,错误代码" + errCode + "。错误信息:" + err;
                                                }
                                                #endregion
                                            }
                                            catch (Exception ex)
                                            {
                                                dgv_result.Rows.Add(textBox_orderId_selected.Text, "系统错误", ex.ToString());
                                                tabControl1.SelectedIndex = 0;
                                            }

                                        }
                                        else
                                        {
                                            MessageBox.Show("打印机不可用!");
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        //全部打印内容
        void printDocument_PrintPage(object sender, PrintPageEventArgs e)
        {
            e.Graphics.PageUnit = GraphicsUnit.Millimeter;//毫米单位
            Graphics g = OnPaint(e);
            if (isNeedReturn_tracking_no)
            {
                e.HasMorePages = true;
                e.Graphics.DrawString("POD", new Font("黑体", (float)GetPx(36)), b, new PointF(x + 40, y1 - 2));
                e.Graphics.DrawString("寄件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y4 + 3), new StringFormat(StringFormatFlags.DirectionVertical));
                e.Graphics.DrawString("收件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y5), new StringFormat(StringFormatFlags.DirectionVertical));
                e.Graphics.DrawString("收件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y9), new StringFormat(StringFormatFlags.DirectionVertical));
                e.Graphics.DrawString("寄件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y10 + 3), new StringFormat(StringFormatFlags.DirectionVertical));
                #region 回单联打印内容 收寄人信息互换
                try
                {
                    e.Graphics.DrawString("签回运单", new Font("黑体", (float)GetPx(14)), b, new PointF(x1 + 1, y2));
                    e.Graphics.DrawString(successOrdersList.sol[count].origincode, new Font("Arial", (float)GetPx(36)), b, new PointF(x2, y3 - 2));//目的代码
                    //一联收件人名字,电话,公司,地址                             
                    e.Graphics.DrawString(successOrdersList.sol[count].RECEIVE_PARTY_CONTACT_NAME, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y4));
                    e.Graphics.DrawString(successOrdersList.sol[count].RECEIVE_PARTY_PHONE, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 39, y4));
                    //e.Graphics.DrawString(successOrdersList.sol[count].RECEIVE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y4));
                    string r = successOrdersList.sol[count].RECEIVE_PARTY_ADDR1;
                    if (r.Length > 25)
                    {
                        string a1 = r.Substring(0, 25);
                        string a2 = r.Substring(25, r.Length - 25);
                        //一联收件人地址
                        e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 5));
                        e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 9));
                        //二联收件人地址
                        e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                        e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 9));
                    }
                    else
                    {
                        //一联收件人地址
                        e.Graphics.DrawString(r, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 5));
                        //二联收件人地址
                        e.Graphics.DrawString(r, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                    }
                    //一联寄件人名字,电话,公司,地址 
                    e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_CONTACT, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y5));
                    e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_TEL, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 19, y5));
                    //e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y5));
                    e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_ADDR, new Font("黑体", (float)GetPx(7)), b, new PointF(x2, y5 + 5));

                    //订单详细字段
                    e.Graphics.DrawString("付款方式:" + Pay_method(successOrdersList.sol[count].pay_method), new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6));
                    e.Graphics.DrawString("计费重量:" + successOrdersList.sol[count].total_wt + "g", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6));
                    //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6));

                    e.Graphics.DrawString("月结账号:" + custid, new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 3));
                    e.Graphics.DrawString("声明价值:" + successOrdersList.sol[count].INSURE_Money, new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 3));
                    //e.Graphics.DrawString("运费:", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 3));

                    e.Graphics.DrawString("签回单号:" + successOrdersList.sol[count].return_tracking_no, new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 6));
                    //e.Graphics.DrawString("计费重量:", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 6));
                    //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 6));

                    //e.Graphics.DrawString("付款方式:转第三方付", new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 9));
                    //e.Graphics.DrawString("计费重量:", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 9));
                    //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 9));
                    //二连寄件人信息
                    e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_CONTACT, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y9));
                    e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_TEL, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 19, y9));
                    //e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y9));
                    e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_ADDR, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y9 + 5));
                    //二连收件人信息
                    e.Graphics.DrawString(successOrdersList.sol[count].RECEIVE_PARTY_CONTACT_NAME, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y10));
                    e.Graphics.DrawString(successOrdersList.sol[count].RECEIVE_PARTY_PHONE, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 39, y10));
                    //e.Graphics.DrawString(successOrdersList.sol[count].RECEIVE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y10));
                    //e.Graphics.DrawString(successOrdersList.sol[count].RECEIVE_PARTY_ADDR1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                    //一联条形码
                    e.Graphics.DrawString(successOrdersList.sol[count].return_tracking_no, new Font("Arial", (float)GetPx(10)), b, new PointF(x + 15, y3 - 7));
                    e.Graphics.DrawImage(bc.GetCodeImage(successOrdersList.sol[count].return_tracking_no), x + 5, (float)(y2 + 2), 60, 10);
                    //二联条形码
                    e.Graphics.DrawString(successOrdersList.sol[count].return_tracking_no, new Font("Arial", (float)GetPx(8)), b, new PointF(x6 + 15, y9 - 5));
                    e.Graphics.DrawImage(bc.GetCodeImage(successOrdersList.sol[count].return_tracking_no), x6 + 5, y8 + 2, 50, 8);
                    //备注
                    e.Graphics.DrawString("订单号:" + successOrdersList.sol[count].CLIENT_ORDER_NO, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2));
                }
                catch (Exception ex)
                {
                    dgv_result.Rows.Add(successOrdersList.sol[count].CLIENT_ORDER_NO, "系统错误:签回单出错", ex.ToString());
                }
                #endregion
                isNeedReturn_tracking_no = false;
            }
            else
            {
                #region 全部打印
                if (successOrdersList.sol.Count > 1 && count < successOrdersList.sol.Count - 1)
                {
                    e.HasMorePages = true;
                }
                else
                {
                    e.HasMorePages = false;
                }
                while (count < successOrdersList.sol.Count)
                {
                    #region 每页的打印内容
                    try
                    {
                        e.Graphics.DrawString("收件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y4 + 3), new StringFormat(StringFormatFlags.DirectionVertical));
                        e.Graphics.DrawString("寄件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y5), new StringFormat(StringFormatFlags.DirectionVertical));
                        e.Graphics.DrawString("寄件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y9), new StringFormat(StringFormatFlags.DirectionVertical));
                        e.Graphics.DrawString("收件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y10 + 3), new StringFormat(StringFormatFlags.DirectionVertical));
                        e.Graphics.DrawString(Express_type(successOrdersList.sol[count].express_type), new Font("黑体", (float)GetPx(14)), b, new PointF(x1 + 1, y2));
                        e.Graphics.DrawString(successOrdersList.sol[count].destcode, new Font("Arial", (float)GetPx(36)), b, new PointF(x2, y3 - 2));//目的代码
                        //一联收件人名字,电话,公司,地址                             
                        e.Graphics.DrawString(successOrdersList.sol[count].RECEIVE_PARTY_CONTACT_NAME, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y4));
                        e.Graphics.DrawString(successOrdersList.sol[count].RECEIVE_PARTY_PHONE, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 39, y4));
                        //e.Graphics.DrawString(item.RECEIVE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y4));
                        string r = successOrdersList.sol[count].RECEIVE_PARTY_ADDR1;
                        if (r.Length > 25)
                        {
                            string a1 = r.Substring(0, 25);
                            string a2 = r.Substring(25, r.Length - 25);
                            //一联收件人地址
                            e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 5));
                            e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 9));
                            //二联收件人地址
                            e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                            e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 9));
                        }
                        else
                        {
                            //一联收件人地址
                            e.Graphics.DrawString(r, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 5));
                            //二联收件人地址
                            e.Graphics.DrawString(r, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                        }
                        //一联寄件人名字,电话,公司,地址 
                        e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_CONTACT, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y5));
                        e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_TEL, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 19, y5));
                        //e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y5));
                        e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_ADDR, new Font("黑体", (float)GetPx(7)), b, new PointF(x2, y5 + 5));

                        //订单详细字段
                        e.Graphics.DrawString("付款方式:" + Pay_method(successOrdersList.sol[count].pay_method), new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6));
                        e.Graphics.DrawString("计费重量:" + successOrdersList.sol[count].total_wt + "g", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6));
                        //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6));

                        e.Graphics.DrawString("月结账号:", new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 3));
                        e.Graphics.DrawString("声明价值:" + successOrdersList.sol[count].INSURE_Money, new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 3));
                        //e.Graphics.DrawString("运费:", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 3));

                        e.Graphics.DrawString("签回单号:" + successOrdersList.sol[count].return_tracking_no, new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 6));
                        //e.Graphics.DrawString("计费重量:", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 6));
                        //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 6));

                        //e.Graphics.DrawString("付款方式:转第三方付", new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 9));
                        //e.Graphics.DrawString("计费重量:", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 9));
                        //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 9));
                        //二连寄件人信息
                        e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_CONTACT, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y9));
                        e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_TEL, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 19, y9));
                        //e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y9));
                        e.Graphics.DrawString(successOrdersList.sol[count].ISSUE_PARTY_ADDR, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y9 + 5));
                        //二连收件人信息
                        e.Graphics.DrawString(successOrdersList.sol[count].RECEIVE_PARTY_CONTACT_NAME, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y10));
                        e.Graphics.DrawString(successOrdersList.sol[count].RECEIVE_PARTY_PHONE, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 39, y10));
                        //e.Graphics.DrawString(successOrdersList.sol[count].RECEIVE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y10));
                        //一联条形码
                        e.Graphics.DrawString(successOrdersList.sol[count].mailno, new Font("Arial", (float)GetPx(10)), b, new PointF(x + 15, y3 - 7));
                        e.Graphics.DrawImage(bc.GetCodeImage(successOrdersList.sol[count].mailno), x + 5, (float)(y2 + 2), 60, 10);
                        //二联条形码
                        e.Graphics.DrawString(successOrdersList.sol[count].mailno, new Font("Arial", (float)GetPx(8)), b, new PointF(x6 + 15, y9 - 5));
                        e.Graphics.DrawImage(bc.GetCodeImage(successOrdersList.sol[count].mailno), x6 + 5, y8 + 2, 50, 8);
                        //备注
                        e.Graphics.DrawString("订单号:" + successOrdersList.sol[count].CLIENT_ORDER_NO, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2));
                        successNum++;
                        // do sql
                        string update1 = "update oms_order_head h set h.sta_remark='" + successOrdersList.sol[count].sta_remark + ",运单号:" + successOrdersList.sol[count].mailno + "' where h.CLIENT_ORDER_NO='" + successOrdersList.sol[count].CLIENT_ORDER_NO + "'";
                        string insert1 = "insert into OMS_SF_PRINT (CLIENT_ORDER_NO,OMS_NO,CLIENT_C,OPERATING_WAREHOUSE_CODE,ORDER_RECEIVED_DTE,SPRINT_TYPE,MAIL_NO,CREATE_DATE) " +
                                         "values('" + successOrdersList.sol[count].CLIENT_ORDER_NO + "','" + successOrdersList.sol[count].OMS_NO + "','" + client_c + "','" + RDC + "',to_date('" + successOrdersList.sol[count].order_received_dte + "','yyyy-MM-dd HH24-mi-ss'),'OTO','" + successOrdersList.sol[count].mailno + "',to_date('" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + "','yyyy-MM-dd HH24-mi-ss'))";
                        asql[0] = update1;
                        asql[1] = insert1;
                        try
                        {
                            int k = Conn.doTran(asql);
                        }
                        catch (Exception ex1)
                        {
                            dgv_result.Rows.Add(successOrdersList.sol[count].CLIENT_ORDER_NO, "数据写入错误", "打印成功,但数据没写入数据库(提示:" + ex1.Message + ")。");
                        }
                    }
                    catch (Exception ex)
                    {
                        dgv_result.Rows.Add(successOrdersList.sol[count].CLIENT_ORDER_NO, "系统错误", ex.ToString());
                        falseNum++;
                    }
                    #endregion
                    count++;
                    isNeedReturn_tracking_no = true;
                    return;

                }
                #endregion
            }
        }

        //全部打印后
        private void printDocument_EndPrint(object sender, PrintEventArgs e)
        {
            count = 0;
        }

        //N单一裹的打印内容
        private void pd1_PrintPage(object sender, PrintPageEventArgs e)
        {
            e.Graphics.PageUnit = GraphicsUnit.Millimeter;//毫米单位
            Graphics g = OnPaint(e);
            if (comboBox_pay_type.Text == "第三方付")
            {
                e.Graphics.DrawString("第三方地区:" + dotCode, new Font("黑体", (float)GetPx(6)), b, new PointF(x + 40, y6 + 6));
            }
            if (isNeedReturn_tracking_no)
            {
                e.HasMorePages = true;
                e.Graphics.DrawString("POD", new Font("黑体", (float)GetPx(36)), b, new PointF(x + 40, y1 - 2));
                e.Graphics.DrawString("寄件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y4 + 3), new StringFormat(StringFormatFlags.DirectionVertical));
                e.Graphics.DrawString("收件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y5), new StringFormat(StringFormatFlags.DirectionVertical));
                e.Graphics.DrawString("收件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y9), new StringFormat(StringFormatFlags.DirectionVertical));
                e.Graphics.DrawString("寄件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y10 + 3), new StringFormat(StringFormatFlags.DirectionVertical));
                #region 回单联打印内容 收寄人信息互换
                foreach (var item in successOrdersList.sol)
                {
                    try
                    {
                        e.Graphics.DrawString("签回运单", new Font("黑体", (float)GetPx(14)), b, new PointF(x1 + 1, y2));
                        e.Graphics.DrawString(item.origincode, new Font("Arial", (float)GetPx(36)), b, new PointF(x2, y3 - 2));//目的代码
                        //一联收件人名字,电话,公司,地址                             
                        e.Graphics.DrawString(item.RECEIVE_PARTY_CONTACT_NAME, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y4));
                        e.Graphics.DrawString(item.RECEIVE_PARTY_PHONE, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 39, y4));
                        //e.Graphics.DrawString(item.RECEIVE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y4));
                        string r = item.RECEIVE_PARTY_ADDR1;
                        if (r.Length > 25)
                        {
                            string a1 = r.Substring(0, 25);
                            string a2 = r.Substring(25, r.Length - 25);
                            //一联收件人地址
                            e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 5));
                            e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 9));
                            //二联收件人地址
                            e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                            e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 9));
                        }
                        else
                        {
                            //一联收件人地址
                            e.Graphics.DrawString(r, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 5));
                            //二联收件人地址
                            e.Graphics.DrawString(r, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                        }
                        //一联寄件人名字,电话,公司,地址 
                        e.Graphics.DrawString(item.ISSUE_PARTY_CONTACT, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y5));
                        e.Graphics.DrawString(item.ISSUE_PARTY_TEL, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 19, y5));
                        //e.Graphics.DrawString(item.ISSUE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y5));
                        e.Graphics.DrawString(item.ISSUE_PARTY_ADDR, new Font("黑体", (float)GetPx(7)), b, new PointF(x2, y5 + 5));

                        //订单详细字段
                        e.Graphics.DrawString("付款方式:" + Pay_method(item.pay_method), new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6));
                        e.Graphics.DrawString("计费重量:" + item.total_wt + "g", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6));
                        //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6));

                        e.Graphics.DrawString("月结账号:" + item.custid, new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 3));
                        e.Graphics.DrawString("声明价值:" + item.INSURE_Money, new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 3));
                        //e.Graphics.DrawString("运费:", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 3));

                        e.Graphics.DrawString("签回单号:" + item.return_tracking_no, new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 6));
                        //e.Graphics.DrawString("计费重量:", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 6));
                        //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 6));

                        //e.Graphics.DrawString("付款方式:转第三方付", new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 9));
                        //e.Graphics.DrawString("计费重量:", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 9));
                        //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 9));
                        //二连寄件人信息
                        e.Graphics.DrawString(item.ISSUE_PARTY_CONTACT, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y9));
                        e.Graphics.DrawString(item.ISSUE_PARTY_TEL, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 19, y9));
                        //e.Graphics.DrawString(item.ISSUE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y9));
                        e.Graphics.DrawString(item.ISSUE_PARTY_ADDR, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y9 + 5));
                        //二连收件人信息
                        e.Graphics.DrawString(item.RECEIVE_PARTY_CONTACT_NAME, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y10));
                        e.Graphics.DrawString(item.RECEIVE_PARTY_PHONE, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 39, y10));
                        //e.Graphics.DrawString(item.RECEIVE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y10));
                        //e.Graphics.DrawString(item.RECEIVE_PARTY_ADDR1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                        //一联条形码
                        e.Graphics.DrawString(item.return_tracking_no, new Font("Arial", (float)GetPx(10)), b, new PointF(x + 15, y3 - 7));
                        e.Graphics.DrawImage(bc.GetCodeImage(item.return_tracking_no), x + 5, (float)(y2 + 2), 60, 10);
                        //二联条形码
                        e.Graphics.DrawString(item.return_tracking_no, new Font("Arial", (float)GetPx(8)), b, new PointF(x6 + 15, y9 - 5));
                        e.Graphics.DrawImage(bc.GetCodeImage(item.return_tracking_no), x6 + 5, y8 + 2, 50, 8);
                        //备注
                        #region 备注栏控制不超出打印范围
                        string sta = "订单号:" + item.CLIENT_ORDER_NO;
                        string[] orderIDPrint = sta.Split(',');
                        int beizhuYflag = 1;
                        if (sta.Length > 24 && orderIDPrint.Length > 2)
                        {
                            string a1 = "";
                            string a2 = "";
                            for (int i = 0; i < 2; i++)
                            {
                                a1 += orderIDPrint[i] + ',';
                            }
                            e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2));
                            beizhuYflag = 1;
                            if (orderIDPrint.Length >= 3)
                            {
                                a1 = "";
                                a2 = "";
                                for (int i = 2; i < orderIDPrint.Length; i++)
                                {
                                    if (i >= 5)
                                    {
                                        a2 += orderIDPrint[i] + ',';
                                    }
                                    else
                                    {
                                        a1 += orderIDPrint[i] + ',';
                                    }
                                }
                                e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2 + 5));
                                beizhuYflag = 2;
                                if (!string.IsNullOrWhiteSpace(a2))
                                {
                                    e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                    beizhuYflag = 3;
                                }

                            }
                        }
                        else
                        {
                            e.Graphics.DrawString(sta, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2));
                            beizhuYflag = 1;
                        }
                        string beizhu = textBox_beizhu.Text.Trim();
                        switch (beizhuYflag)
                        {
                            case 1:
                                if (beizhu.Length > 25)
                                {
                                    string a1 = beizhu.Substring(0, 25);
                                    string a2 = beizhu.Substring(25, beizhu.Length - 25);
                                    e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5));
                                    if (a2.Length > 25)
                                    {
                                        string b1 = a2.Substring(0, 25);
                                        string b2 = a2.Substring(25, a2.Length - 25);
                                        e.Graphics.DrawString(b1, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                        e.Graphics.DrawString(b2, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5 + 5));
                                    }
                                    else
                                    {
                                        e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                    }
                                }
                                else
                                {
                                    e.Graphics.DrawString(beizhu, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5));
                                }
                                break;
                            case 2:
                                if (beizhu.Length > 25)
                                {
                                    string a1 = beizhu.Substring(0, 25);
                                    string a2 = beizhu.Substring(25, beizhu.Length - 25);
                                    e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                    e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5 + 5));
                                }
                                else
                                {
                                    e.Graphics.DrawString(beizhu, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                }
                                break;
                            case 3:
                                e.Graphics.DrawString(beizhu, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5 + 5));
                                break;
                            default:
                                break;
                        }
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        dgv_result.Rows.Add(item.CLIENT_ORDER_NO, "系统错误:签回单出错", ex.ToString());
                    }
                }
                #endregion
                isNeedReturn_tracking_no = false;
            }
            else
            {
                e.HasMorePages = false;
                #region 面单打印内容
                foreach (var item in successOrdersList.sol)
                {
                    e.Graphics.DrawString("收件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y4 + 3), new StringFormat(StringFormatFlags.DirectionVertical));
                    e.Graphics.DrawString("寄件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y5), new StringFormat(StringFormatFlags.DirectionVertical));
                    e.Graphics.DrawString("寄件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y9), new StringFormat(StringFormatFlags.DirectionVertical));
                    e.Graphics.DrawString("收件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y10 + 3), new StringFormat(StringFormatFlags.DirectionVertical));
                    //aSql.Clear();
                    try
                    {
                        e.Graphics.DrawString(Express_type(item.express_type), new Font("黑体", (float)GetPx(14)), b, new PointF(x1 + 1, y2));
                        e.Graphics.DrawString(item.destcode, new Font("Arial", (float)GetPx(36)), b, new PointF(x2, y3 - 2));//目的代码
                        //一联收件人名字,电话,公司,地址                             
                        e.Graphics.DrawString(item.RECEIVE_PARTY_CONTACT_NAME, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y4));
                        e.Graphics.DrawString(item.RECEIVE_PARTY_PHONE, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 39, y4));
                        //e.Graphics.DrawString(item.RECEIVE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y4));
                        string r = item.RECEIVE_PARTY_ADDR1;
                        if (r.Length > 25)
                        {
                            string a1 = r.Substring(0, 25);
                            string a2 = r.Substring(25, r.Length - 25);
                            //一联收件人地址
                            e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 5));
                            e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 9));
                            //二联收件人地址
                            e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                            e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 9));
                        }
                        else
                        {
                            //一联收件人地址
                            e.Graphics.DrawString(r, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 5));
                            //二联收件人地址
                            e.Graphics.DrawString(r, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                        }
                        //一联寄件人名字,电话,公司,地址 
                        e.Graphics.DrawString(item.ISSUE_PARTY_CONTACT, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y5));
                        e.Graphics.DrawString(item.ISSUE_PARTY_TEL, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 19, y5));
                        //e.Graphics.DrawString(item.ISSUE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y5));
                        e.Graphics.DrawString(item.ISSUE_PARTY_ADDR, new Font("黑体", (float)GetPx(7)), b, new PointF(x2, y5 + 5));

                        //订单详细字段
                        e.Graphics.DrawString("付款方式:" + Pay_method(item.pay_method), new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6));
                        e.Graphics.DrawString("计费重量:" + item.total_wt + "g", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6));
                        //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6));
                        if (comboBox_pay_type.Text == "到付")
                        {
                            e.Graphics.DrawString("月结账号:", new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 3));
                        }
                        else
                        {
                            e.Graphics.DrawString("月结账号:" + item.custid, new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 3));
                        }
                        e.Graphics.DrawString("声明价值:" + item.INSURE_Money, new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 3));
                        //e.Graphics.DrawString("运费:", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 3));

                        e.Graphics.DrawString("签回单号:" + item.return_tracking_no, new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 6));
                        //e.Graphics.DrawString("计费重量:", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 6));
                        //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 6));

                        //e.Graphics.DrawString("付款方式:转第三方付", new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 9));
                        //e.Graphics.DrawString("计费重量:", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 9));
                        //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 9));
                        //二连寄件人信息
                        e.Graphics.DrawString(item.ISSUE_PARTY_CONTACT, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y9));
                        e.Graphics.DrawString(item.ISSUE_PARTY_TEL, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 19, y9));
                        //e.Graphics.DrawString(item.ISSUE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y9));
                        e.Graphics.DrawString(item.ISSUE_PARTY_ADDR, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y9 + 5));
                        //二连收件人信息
                        e.Graphics.DrawString(item.RECEIVE_PARTY_CONTACT_NAME, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y10));
                        e.Graphics.DrawString(item.RECEIVE_PARTY_PHONE, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 39, y10));
                        //e.Graphics.DrawString(item.RECEIVE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y10));
                        //e.Graphics.DrawString(item.RECEIVE_PARTY_ADDR1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                        //一联条形码
                        e.Graphics.DrawString(item.mailno, new Font("Arial", (float)GetPx(10)), b, new PointF(x + 15, y3 - 7));
                        e.Graphics.DrawImage(bc.GetCodeImage(item.mailno), x + 5, (float)(y2 + 2), 60, 10);
                        //二联条形码
                        e.Graphics.DrawString(item.mailno, new Font("Arial", (float)GetPx(8)), b, new PointF(x6 + 15, y9 - 5));
                        e.Graphics.DrawImage(bc.GetCodeImage(item.mailno), x6 + 5, y8 + 2, 50, 8);
                        //备注
                        #region 备注栏控制不超出打印范围
                        string sta = "订单号:" + item.CLIENT_ORDER_NO;
                        string[] orderIDPrint = sta.Split(',');
                        int beizhuYflag = 1;
                        if (sta.Length > 24 && orderIDPrint.Length > 2)
                        {
                            string a1 = "";
                            string a2 = "";
                            for (int i = 0; i < 2; i++)
                            {
                                a1 += orderIDPrint[i] + ',';
                            }
                            e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2));
                            beizhuYflag = 1;
                            if (orderIDPrint.Length >= 3)
                            {
                                a1 = "";
                                a2 = "";
                                for (int i = 2; i < orderIDPrint.Length; i++)
                                {
                                    if (i >= 5)
                                    {
                                        a2 += orderIDPrint[i] + ',';
                                    }
                                    else
                                    {
                                        a1 += orderIDPrint[i] + ',';
                                    }
                                }
                                e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2 + 5));
                                beizhuYflag = 2;
                                if (!string.IsNullOrWhiteSpace(a2))
                                {
                                    e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                    beizhuYflag = 3;
                                }

                            }
                        }
                        else
                        {
                            e.Graphics.DrawString(sta, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2));
                            beizhuYflag = 1;
                        }
                        string beizhu = textBox_beizhu.Text.Trim();
                        switch (beizhuYflag)
                        {
                            case 1:
                                if (beizhu.Length > 25)
                                {
                                    string a1 = beizhu.Substring(0, 25);
                                    string a2 = beizhu.Substring(25, beizhu.Length - 25);
                                    e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5));
                                    if (a2.Length > 25)
                                    {
                                        string b1 = a2.Substring(0, 25);
                                        string b2 = a2.Substring(25, a2.Length - 25);
                                        e.Graphics.DrawString(b1, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                        e.Graphics.DrawString(b2, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5 + 5));
                                    }
                                    else
                                    {
                                        e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                    }
                                }
                                else
                                {
                                    e.Graphics.DrawString(beizhu, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5));
                                }
                                break;
                            case 2:
                                if (beizhu.Length > 25)
                                {
                                    string a1 = beizhu.Substring(0, 25);
                                    string a2 = beizhu.Substring(25, beizhu.Length - 25);
                                    e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                    e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5 + 5));
                                }
                                else
                                {
                                    e.Graphics.DrawString(beizhu, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                }
                                break;
                            case 3:
                                e.Graphics.DrawString(beizhu, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5 + 5));
                                break;
                            default:
                                break;
                        }
                        #endregion
                        ordersParcelSuccess = true;
                    }
                    catch (Exception ex)
                    {
                        dgv_result.Rows.Add(item.CLIENT_ORDER_NO, "系统错误", ex.ToString());
                        ordersParcelSuccess = false;
                    }
                }
                #endregion
            }
        }

        //N单一裹打印结束
        private void pd1_EndPrint(object sender, PrintEventArgs e)
        {
            if (ordersParcelSuccess && orderIdList.Count == sta_remark_List.Count)
            {
                for (int i = 0; i < orderIdList.Count; i++)
                {
                    string update1 = "update oms_order_head h set h.sta_remark='" + sta_remark_List[i] + ",运单号:" + mailno + "'" +
                        ",h.RECEIVE_PARTY_CONTACT_NAME='" + textBox_RECEIVE_PARTY_CONTACT_NAME.Text.Trim() + "',h.RECEIVE_PARTY_PHONE='" + textBox_RECEIVE_PARTY_PHONE.Text.Trim() + "'" +
                        ",h.RECEIVE_PARTY_ADDR1='" + textBox_receive_addr.Text.Trim() + "' where h.CLIENT_ORDER_NO='" + orderIdList[i] + "'";
                    string insert1 = "";
                    if (orderIdList.Count == 1)
                    {
                        //一单一裹
                        insert1 = "insert into OMS_SF_PRINT (CLIENT_ORDER_NO,OMS_NO,CLIENT_C,OPERATING_WAREHOUSE_CODE,ORDER_RECEIVED_DTE,SPRINT_TYPE,MAIL_NO,CREATE_DATE) " +
                                  "values('" + orderIdList[i] + "','" + oms_noList[i] + "','" + client_c + "','" + RDC + "',to_date('" + order_received_dteList[i] + "','yyyy-MM-dd HH24-mi-ss'),'OTO','" + mailno + "',to_date('" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + "','yyyy-MM-dd HH24-mi-ss'))";
                    }
                    else
                    {
                        //多单一裹
                        insert1 = "insert into OMS_SF_PRINT (CLIENT_ORDER_NO,OMS_NO,CLIENT_C,OPERATING_WAREHOUSE_CODE,ORDER_RECEIVED_DTE,SPRINT_TYPE,MAIL_NO,CREATE_DATE) " +
                                  "values('" + orderIdList[i] + "','" + oms_noList[i] + "','" + client_c + "','" + RDC + "',to_date('" + order_received_dteList[i] + "','yyyy-MM-dd HH24-mi-ss'),'MTO','" + mailno + "',to_date('" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + "','yyyy-MM-dd HH24-mi-ss'))";
                    }
                    asql[0] = update1;
                    asql[1] = insert1;
                    try
                    {
                        //测试时注释数据库操作
                        int k = Conn.doTran(asql);
                    }
                    catch (Exception ex)
                    {
                        dgv_result.Rows.Add(orderIdList[i], "数据写入错误", "打印成功,但数据没写入数据库(提示:" + ex.Message + ")。");
                    }
                }
            }
            ordersParcelSuccess = false;
            tabControl1.SelectedIndex = 0;
        }

        //N单多裹的打印内容
        private void pd2_PrintPage(object sender, PrintPageEventArgs e)
        {
            e.Graphics.PageUnit = GraphicsUnit.Millimeter;//毫米单位
            Graphics g = OnPaint(e);
            if (comboBox_pay_type.Text == "第三方付")
            {
                e.Graphics.DrawString("第三方地区:" + dotCode, new Font("黑体", (float)GetPx(6)), b, new PointF(x + 40, y6 + 6));
            }
            if (isNeedReturn_tracking_no)
            {
                e.HasMorePages = true;
                e.Graphics.DrawString("POD", new Font("黑体", (float)GetPx(36)), b, new PointF(x + 40, y1 - 2));

                e.Graphics.DrawString("寄件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y4 + 3), new StringFormat(StringFormatFlags.DirectionVertical));
                e.Graphics.DrawString("收件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y5), new StringFormat(StringFormatFlags.DirectionVertical));
                e.Graphics.DrawString("收件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y9), new StringFormat(StringFormatFlags.DirectionVertical));
                e.Graphics.DrawString("寄件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y10 + 3), new StringFormat(StringFormatFlags.DirectionVertical));
                #region 回单联打印内容 收寄人信息互换
                foreach (var item in successOrdersList.sol)
                {
                    try
                    {
                        e.Graphics.DrawString("签回运单", new Font("黑体", (float)GetPx(14)), b, new PointF(x1 + 1, y2));
                        e.Graphics.DrawString(item.origincode, new Font("Arial", (float)GetPx(36)), b, new PointF(x2, y3 - 2));//目的代码
                        //一联收件人名字,电话,公司,地址                             
                        e.Graphics.DrawString(item.RECEIVE_PARTY_CONTACT_NAME, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y4));
                        e.Graphics.DrawString(item.RECEIVE_PARTY_PHONE, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 39, y4));
                        //e.Graphics.DrawString(item.RECEIVE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y4));
                        string r = item.RECEIVE_PARTY_ADDR1;
                        if (r.Length > 25)
                        {
                            string a1 = r.Substring(0, 25);
                            string a2 = r.Substring(25, r.Length - 25);
                            //一联收件人地址
                            e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 5));
                            e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 9));
                            //二联收件人地址
                            e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                            e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 9));
                        }
                        else
                        {
                            //一联收件人地址
                            e.Graphics.DrawString(r, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 5));
                            //二联收件人地址
                            e.Graphics.DrawString(r, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                        }
                        //一联寄件人名字,电话,公司,地址 
                        e.Graphics.DrawString(item.ISSUE_PARTY_CONTACT, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y5));
                        e.Graphics.DrawString(item.ISSUE_PARTY_TEL, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 19, y5));
                        //e.Graphics.DrawString(item.ISSUE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y5));
                        e.Graphics.DrawString(item.ISSUE_PARTY_ADDR, new Font("黑体", (float)GetPx(7)), b, new PointF(x2, y5 + 5));

                        //订单详细字段
                        e.Graphics.DrawString("付款方式:" + Pay_method(item.pay_method), new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6));
                        e.Graphics.DrawString("计费重量:" + item.total_wt + "g", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6));
                        //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6));

                        e.Graphics.DrawString("月结账号:" + item.custid, new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 3));
                        e.Graphics.DrawString("声明价值:" + item.INSURE_Money, new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 3));
                        //e.Graphics.DrawString("运费:", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 3));

                        e.Graphics.DrawString("签回单号:" + item.return_tracking_no, new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 6));
                        //e.Graphics.DrawString("计费重量:", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 6));
                        //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 6));

                        //e.Graphics.DrawString("付款方式:转第三方付", new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 9));
                        //e.Graphics.DrawString("计费重量:", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 9));
                        //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 9));
                        //二连寄件人信息
                        e.Graphics.DrawString(item.ISSUE_PARTY_CONTACT, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y9));
                        e.Graphics.DrawString(item.ISSUE_PARTY_TEL, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 19, y9));
                        //e.Graphics.DrawString(item.ISSUE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y9));
                        e.Graphics.DrawString(item.ISSUE_PARTY_ADDR, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y9 + 5));
                        //二连收件人信息
                        e.Graphics.DrawString(item.RECEIVE_PARTY_CONTACT_NAME, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y10));
                        e.Graphics.DrawString(item.RECEIVE_PARTY_PHONE, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 39, y10));
                        //e.Graphics.DrawString(item.RECEIVE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y10));
                        //e.Graphics.DrawString(item.RECEIVE_PARTY_ADDR1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                        //一联条形码
                        e.Graphics.DrawString(item.return_tracking_no, new Font("Arial", (float)GetPx(10)), b, new PointF(x + 15, y3 - 7));
                        e.Graphics.DrawImage(bc.GetCodeImage(item.return_tracking_no), x + 5, (float)(y2 + 2), 60, 10);
                        //二联条形码
                        e.Graphics.DrawString(item.return_tracking_no, new Font("Arial", (float)GetPx(8)), b, new PointF(x6 + 15, y9 - 5));
                        e.Graphics.DrawImage(bc.GetCodeImage(item.return_tracking_no), x6 + 5, y8 + 2, 50, 8);
                        //备注
                        #region 备注栏控制不超出打印范围
                        string sta = "订单号:" + item.CLIENT_ORDER_NO;
                        string[] orderIDPrint = sta.Split(',');
                        int beizhuYflag = 1;
                        if (sta.Length > 24 && orderIDPrint.Length > 2)
                        {
                            string a1 = "";
                            string a2 = "";
                            for (int i = 0; i < 2; i++)
                            {
                                a1 += orderIDPrint[i] + ',';
                            }
                            e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2));
                            beizhuYflag = 1;
                            if (orderIDPrint.Length >= 3)
                            {
                                a1 = "";
                                a2 = "";
                                for (int i = 2; i < orderIDPrint.Length; i++)
                                {
                                    if (i >= 5)
                                    {
                                        a2 += orderIDPrint[i] + ',';
                                    }
                                    else
                                    {
                                        a1 += orderIDPrint[i] + ',';
                                    }
                                }
                                e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2 + 5));
                                beizhuYflag = 2;
                                if (!string.IsNullOrWhiteSpace(a2))
                                {
                                    e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                    beizhuYflag = 3;
                                }

                            }
                        }
                        else
                        {
                            e.Graphics.DrawString(sta, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2));
                            beizhuYflag = 1;
                        }
                        string beizhu = textBox_beizhu.Text.Trim();
                        switch (beizhuYflag)
                        {
                            case 1:
                                if (beizhu.Length > 25)
                                {
                                    string a1 = beizhu.Substring(0, 25);
                                    string a2 = beizhu.Substring(25, beizhu.Length - 25);
                                    e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5));
                                    if (a2.Length > 25)
                                    {
                                        string b1 = a2.Substring(0, 25);
                                        string b2 = a2.Substring(25, a2.Length - 25);
                                        e.Graphics.DrawString(b1, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                        e.Graphics.DrawString(b2, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5 + 5));
                                    }
                                    else
                                    {
                                        e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                    }
                                }
                                else
                                {
                                    e.Graphics.DrawString(beizhu, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5));
                                }
                                break;
                            case 2:
                                if (beizhu.Length > 25)
                                {
                                    string a1 = beizhu.Substring(0, 25);
                                    string a2 = beizhu.Substring(25, beizhu.Length - 25);
                                    e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                    e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5 + 5));
                                }
                                else
                                {
                                    e.Graphics.DrawString(beizhu, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                }
                                break;
                            case 3:
                                e.Graphics.DrawString(beizhu, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5 + 5));
                                break;
                            default:
                                break;
                        }
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        dgv_result.Rows.Add(item.CLIENT_ORDER_NO, "系统错误:签回单出错", ex.ToString());
                    }
                }
                #endregion
                isNeedReturn_tracking_no = false;
            }
            else
            {
                if (mailnoArray.Length > 1 && num < mailnoArray.Length - 1)
                {
                    e.HasMorePages = true;
                }
                else
                {
                    e.HasMorePages = false;
                }
                while (num < mailnoArray.Length)
                {
                    #region 打印内容字母单
                    foreach (var item in successOrdersList.sol)
                    {
                        e.Graphics.DrawString("收件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y4 + 3), new StringFormat(StringFormatFlags.DirectionVertical));
                        e.Graphics.DrawString("寄件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y5), new StringFormat(StringFormatFlags.DirectionVertical));
                        e.Graphics.DrawString("寄件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y9), new StringFormat(StringFormatFlags.DirectionVertical));
                        e.Graphics.DrawString("收件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y10 + 3), new StringFormat(StringFormatFlags.DirectionVertical));
                        //aSql.Clear();
                        try
                        {
                            e.Graphics.DrawString(Express_type(item.express_type), new Font("黑体", (float)GetPx(14)), b, new PointF(x1 + 1, y2));
                            e.Graphics.DrawString(item.destcode, new Font("Arial", (float)GetPx(36)), b, new PointF(x2, y3 - 2));//目的代码
                            //一联收件人名字,电话,公司,地址                             
                            e.Graphics.DrawString(item.RECEIVE_PARTY_CONTACT_NAME, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y4));
                            e.Graphics.DrawString(item.RECEIVE_PARTY_PHONE, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 39, y4));
                            //e.Graphics.DrawString(item.RECEIVE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y4));
                            string r = item.RECEIVE_PARTY_ADDR1;
                            if (r.Length > 25)
                            {
                                string a1 = r.Substring(0, 25);
                                string a2 = r.Substring(25, r.Length - 25);
                                //一联收件人地址
                                e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 5));
                                e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 9));
                                //二联收件人地址
                                e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                                e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 9));
                            }
                            else
                            {
                                //一联收件人地址
                                e.Graphics.DrawString(r, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y4 + 5));
                                //二联收件人地址
                                e.Graphics.DrawString(r, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y10 + 5));
                            }
                            //一联寄件人名字,电话,公司,地址 
                            e.Graphics.DrawString(item.ISSUE_PARTY_CONTACT, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y5));
                            e.Graphics.DrawString(item.ISSUE_PARTY_TEL, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 19, y5));
                            //e.Graphics.DrawString(item.ISSUE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y5));
                            e.Graphics.DrawString(item.ISSUE_PARTY_ADDR, new Font("黑体", (float)GetPx(7)), b, new PointF(x2, y5 + 5));

                            //订单详细字段
                            e.Graphics.DrawString("付款方式:" + Pay_method(item.pay_method), new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6));
                            e.Graphics.DrawString("计费重量:" + item.total_wt + "g", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6));
                            //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6));
                            if (comboBox_pay_type.Text == "到付")
                            {
                                e.Graphics.DrawString("月结账号:", new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 3));
                            }
                            else
                            {
                                e.Graphics.DrawString("月结账号:" + item.custid, new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 3));
                            }
                            e.Graphics.DrawString("声明价值:" + item.INSURE_Money, new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 3));
                            //e.Graphics.DrawString("运费:", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 3));

                            e.Graphics.DrawString("签回单号:" + item.return_tracking_no, new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 6));
                            //e.Graphics.DrawString("计费重量:", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 6));
                            //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 6));

                            //e.Graphics.DrawString("付款方式:转第三方付", new Font("黑体", (float)GetPx(6)), b, new PointF(x, y6 + 9));
                            //e.Graphics.DrawString("计费重量:", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 30, y6 + 9));
                            //e.Graphics.DrawString("包装费用:10元", new Font("黑体", (float)GetPx(6)), b, new PointF((float)(x + 58.5), y6 + 9));
                            //二连寄件人信息
                            e.Graphics.DrawString(item.ISSUE_PARTY_CONTACT, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y9));
                            e.Graphics.DrawString(item.ISSUE_PARTY_TEL, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 19, y9));
                            //e.Graphics.DrawString(item.ISSUE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y9));
                            e.Graphics.DrawString(item.ISSUE_PARTY_ADDR, new Font("黑体", (float)GetPx(8)), b, new PointF(x2, y9 + 5));
                            //二连收件人信息
                            e.Graphics.DrawString(item.RECEIVE_PARTY_CONTACT_NAME, new Font("黑体", (float)GetPx(7)), b, new PointF(x2 + 3, y10));
                            e.Graphics.DrawString(item.RECEIVE_PARTY_PHONE, new Font("Arial", (float)GetPx(7)), b, new PointF(x2 + 39, y10));
                            //e.Graphics.DrawString(item.RECEIVE_PARTY_NAME, new Font("黑体", (float)GetPx(6)), b, new PointF(x2 + 27, y10));
                            //一联条形码
                            e.Graphics.DrawString((num + 1) + "/" + mailnoArray.Length, new Font("Arial", (float)GetPx(10)), b, new PointF(x + 1, y3 - 7));
                            if (num == 0)
                            {
                                e.Graphics.DrawString("母单号  " + mailnoArray[0], new Font("Arial", (float)GetPx(10)), b, new PointF(x + 9, y3 - 8));

                                e.Graphics.DrawString("母单号  " + mailnoArray[0], new Font("Arial", (float)GetPx(8)), b, new PointF(x6 + 7, y9 - 5));//二联条形码
                            }
                            else
                            {
                                e.Graphics.DrawString("子单号  " + mailnoArray[num], new Font("Arial", (float)GetPx(8)), b, new PointF(x + 9, y3 - 8));
                                e.Graphics.DrawString("母单号  " + mailnoArray[0], new Font("Arial", (float)GetPx(8)), b, new PointF(x + 9, y3 - 4));

                                e.Graphics.DrawString("子单号  " + mailnoArray[num], new Font("Arial", (float)GetPx(8)), b, new PointF(x6 + 7, y9 - 5));//二联条形码
                            }
                            e.Graphics.DrawImage(bc.GetCodeImage(mailnoArray[num]), x + 5, (float)(y2 + 2), 60, 10);

                            e.Graphics.DrawImage(bc.GetCodeImage(mailnoArray[num]), x6 + 5, y8 + 2, 50, 8);//二联条形码
                            //备注
                            #region 备注栏控制不超出打印范围
                            string sta = "订单号:" + item.CLIENT_ORDER_NO;
                            string[] orderIDPrint = sta.Split(',');
                            int beizhuYflag = 1;
                            if (sta.Length > 24 && orderIDPrint.Length > 2)
                            {
                                string a1 = "";
                                string a2 = "";
                                for (int i = 0; i < 2; i++)
                                {
                                    a1 += orderIDPrint[i] + ',';
                                }
                                e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2));
                                beizhuYflag = 1;
                                if (orderIDPrint.Length >= 3)
                                {
                                    a1 = "";
                                    a2 = "";
                                    for (int i = 2; i < orderIDPrint.Length; i++)
                                    {
                                        if (i >= 5)
                                        {
                                            a2 += orderIDPrint[i] + ',';
                                        }
                                        else
                                        {
                                            a1 += orderIDPrint[i] + ',';
                                        }
                                    }
                                    e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2 + 5));
                                    beizhuYflag = 2;
                                    if (!string.IsNullOrWhiteSpace(a2))
                                    {
                                        e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                        beizhuYflag = 3;
                                    }

                                }
                            }
                            else
                            {
                                e.Graphics.DrawString(sta, new Font("黑体", (float)GetPx(12)), b, new PointF(x + 2, y11 + 2));
                                beizhuYflag = 1;
                            }
                            string beizhu = textBox_beizhu.Text.Trim();
                            switch (beizhuYflag)
                            {
                                case 1:
                                    if (beizhu.Length > 25)
                                    {
                                        string a1 = beizhu.Substring(0, 25);
                                        string a2 = beizhu.Substring(25, beizhu.Length - 25);
                                        e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5));
                                        if (a2.Length > 25)
                                        {
                                            string b1 = a2.Substring(0, 25);
                                            string b2 = a2.Substring(25, a2.Length - 25);
                                            e.Graphics.DrawString(b1, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                            e.Graphics.DrawString(b2, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5 + 5));
                                        }
                                        else
                                        {
                                            e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                        }
                                    }
                                    else
                                    {
                                        e.Graphics.DrawString(beizhu, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5));
                                    }
                                    break;
                                case 2:
                                    if (beizhu.Length > 25)
                                    {
                                        string a1 = beizhu.Substring(0, 25);
                                        string a2 = beizhu.Substring(25, beizhu.Length - 25);
                                        e.Graphics.DrawString(a1, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                        e.Graphics.DrawString(a2, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5 + 5));
                                    }
                                    else
                                    {
                                        e.Graphics.DrawString(beizhu, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5));
                                    }
                                    break;
                                case 3:
                                    e.Graphics.DrawString(beizhu, new Font("黑体", (float)GetPx(8)), b, new PointF(x + 2, y11 + 2 + 5 + 5 + 5));
                                    break;
                                default:
                                    break;
                            }
                            #endregion
                            num++;
                            isPrintSuccess.Add("success");
                        }
                        catch (Exception ex)
                        {
                            dgv_result.Rows.Add(item.CLIENT_ORDER_NO, "系统错误:第" + (num + 1) + "个单打印出错,请稍后再试.", ex.ToString());
                            isPrintSuccess.Add("false");
                        }
                        break;
                    }
                    return;
                    #endregion
                }
            }
            //e.HasMorePages = false;//分页关闭
        }

        //N单多裹打印结束
        private void pd2__EndPrint(object sender, PrintEventArgs e)
        {
            num = 0;
            if (!isPrintSuccess.Contains("false") && orderIdList.Count == sta_remark_List.Count)
            {
                for (int i = 0; i < orderIdList.Count; i++)
                {
                    string update1 = "update oms_order_head h set h.sta_remark='" + sta_remark_List[i] + ",运单号:" + mailno + "'" +
                        ",h.RECEIVE_PARTY_CONTACT_NAME='" + textBox_RECEIVE_PARTY_CONTACT_NAME.Text.Trim() + "',h.RECEIVE_PARTY_PHONE='" + textBox_RECEIVE_PARTY_PHONE.Text.Trim() + "'" +
                        ",h.RECEIVE_PARTY_ADDR1='" + textBox_receive_addr.Text.Trim() + "' where h.CLIENT_ORDER_NO='" + orderIdList[i] + "'";
                    string insert1 = "";
                    if (orderIdList.Count == 1)
                    {
                        insert1 = "insert into OMS_SF_PRINT (CLIENT_ORDER_NO,OMS_NO,CLIENT_C,OPERATING_WAREHOUSE_CODE,ORDER_RECEIVED_DTE,SPRINT_TYPE,MAIL_NO,CREATE_DATE) " +
                                  "values('" + orderIdList[i] + "','" + oms_noList[i] + "','" + client_c + "','" + RDC + "',to_date('" + order_received_dteList[i] + "','yyyy-MM-dd HH24-mi-ss'),'OTM','" + mailno + "',to_date('" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + "','yyyy-MM-dd HH24-mi-ss'))";
                    }
                    else
                    {
                        insert1 = "insert into OMS_SF_PRINT values('" + orderIdList[i] + "','" + oms_noList[i] + "','" + client_c + "','" + RDC + "',to_date('" + order_received_dteList[i] + "','yyyy-MM-dd HH24-mi-ss'),'MTM','" + mailno + "',to_date('" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + "','yyyy-MM-dd HH24-mi-ss'))";
                    }
                    asql[0] = update1;
                    asql[1] = insert1;
                    try
                    {
                        //测试注释数据库操作
                        int k = Conn.doTran(asql);
                    }
                    catch (Exception ex)
                    {
                        dgv_result.Rows.Add(orderIdList[i], "数据写入错误", "打印成功,但数据没写入数据库(提示:" + ex.Message + ")。");
                    }
                }
            }
            isPrintSuccess.Clear();
            tabControl1.SelectedIndex = 0;
        }

        /// <summary>
        /// 打印模板
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public Graphics OnPaint(PrintPageEventArgs e)
        {
            #region 打印模板
            e.Graphics.PageUnit = GraphicsUnit.Millimeter;//毫米单位
            //string str = System.Environment.CurrentDirectory;
            //DirectoryInfo info = new DirectoryInfo(str);
            //string path = info.Parent.Parent.FullName;
            Image img1 = Image.FromFile(path + @"顺丰logo简体.jpg");
            Image img2 = Image.FromFile(path + @"95338.png");
            e.Graphics.DrawString("目的地", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y3 + 3), new StringFormat(StringFormatFlags.DirectionVertical));

            //e.Graphics.DrawString("收件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y4 + 3), new StringFormat(StringFormatFlags.DirectionVertical));
            //e.Graphics.DrawString("寄件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y5), new StringFormat(StringFormatFlags.DirectionVertical));
            //e.Graphics.DrawString("托寄物", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y7), new StringFormat(StringFormatFlags.DirectionVertical));
            //e.Graphics.DrawString("寄件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y9), new StringFormat(StringFormatFlags.DirectionVertical));
            //e.Graphics.DrawString("收件人", new Font("黑体", (float)GetPx(6)), b, new PointF(x + 3, y10 + 3), new StringFormat(StringFormatFlags.DirectionVertical));

            e.Graphics.DrawString("签名:", new Font("黑体", (float)GetPx(6)), b, new PointF(x3, y6));
            e.Graphics.DrawString("月   日", new Font("黑体", (float)GetPx(6)), b, new PointF(x3 + 10, y8 - 3));
            e.Graphics.DrawString("收件员:", new Font("黑体", (float)GetPx(6)), b, new PointF(x5, y7));
            e.Graphics.DrawString("寄件日期:  月  日", new Font("黑体", (float)GetPx(6)), b, new PointF(x5, y7 + 3));
            e.Graphics.DrawString("派件员:", new Font("黑体", (float)GetPx(6)), b, new PointF(x5, y7 + 6));

            //e.Graphics.DrawImage(img1, x + 1, y + 2, 30, 10);
            //e.Graphics.DrawImage(img2, x + 70, y + 2, 30, 10);
            SolidBrush drawBrush = null;
            drawBrush = new SolidBrush(Color.Black);
            Pen line = new Pen(drawBrush, (float)0.1);
            e.Graphics.DrawLine(line, x, y, x + w, y);//横1,最上横
            e.Graphics.DrawLine(line, x, y, x, y + h);//最左竖
            e.Graphics.DrawLine(line, x + w, y, x + w, y + h);//最右竖
            e.Graphics.DrawLine(line, x, y + h, x + w, y + h);//横12,最下横
            e.Graphics.DrawLine(line, x, y2, x + w, y2);//横2
            e.Graphics.DrawLine(line, x, y3, x + w, y3);//横3
            e.Graphics.DrawLine(line, x1, y2, x1, y3);//竖1
            e.Graphics.DrawLine(line, x1, y + 13 + 7, x + w, y + 13 + 7);//电商专配下线
            e.Graphics.DrawLine(line, x, y4, x + w, y4);//横4
            e.Graphics.DrawLine(line, x, y5, x + w, y5);//横5
            e.Graphics.DrawLine(line, x, y6, x + w, y6);//横6
            e.Graphics.DrawLine(line, x2, y3, x2, y6);//竖2
            e.Graphics.DrawLine(line, x, y7, x3, y7);//横7
            e.Graphics.DrawLine(line, x, y8, x + w, y8);//横8
            e.Graphics.DrawLine(line, x4, y7, x4, y8);//竖4
            e.Graphics.DrawLine(line, x5, y7, x5, y8);//竖5
            e.Graphics.DrawLine(line, x3, y5, x3, y8);//竖3
            e.Graphics.DrawLine(line, x, y9, x + w, y9);//横9
            e.Graphics.DrawLine(line, x, y10, x + w, y10);//横10
            e.Graphics.DrawLine(line, x, y11, x + w, y11);//横11
            e.Graphics.DrawLine(line, x6, y8, x6, y9);//竖6
            e.Graphics.DrawLine(line, x7, y9, x7, y11);//竖7
            e.Graphics.DrawImage(img1, x + 2, (float)(y8 + 0.5), 30, 7);
            e.Graphics.DrawImage(img2, x + 2, y8 + 7, 30, 8);
            #endregion
            Graphics g = e.Graphics;
            return g;
        }
    }
}
[
    {
        "RDCInfo": [
            {
                "Name": "欧司朗",
                "Client_c": "OSR",
                "RDC": "STA GUANGZHOU1",
                "CusId": "7573424493",
                "DotCode": "757BH",
                "Day": "2",
                "AllPrint_express_type": "1",
                "AllPrint_pay_method": "2",
                "AllPrint_need_return_tracking_no": "1",
                "AllPrint_parcel_quantity": "1",
                "FixedIssueInfo":{
                    "IsFixedIssueInfo":"Y",
                    "ISSUE_PARTY_ADDR":"广州市经济技术开发区云埔工业区云埔三路12号",
                    "ISSUE_PARTY_CONTACT":"秦沃初",
                    "ISSUE_PARTY_TEL":"020-82253451"
                }
            },
            {
                "Name": "朗德万斯",
                "Client_c": "LAM",
                "RDC": "STA GUANGZHOU1",
                "CusId": "7575883916",
                "DotCode": "757BH",
                "Day": "2",
                "AllPrint_express_type": "1",
                "AllPrint_pay_method": "2",
                "AllPrint_need_return_tracking_no": "1",
                "AllPrint_parcel_quantity": "1",
                "FixedIssueInfo":{
                    "IsFixedIssueInfo":"Y",
                    "ISSUE_PARTY_ADDR":"广州市经济技术开发区云埔工业区云埔三路12号",
                    "ISSUE_PARTY_CONTACT":"秦沃初",
                    "ISSUE_PARTY_TEL":"020-82253451"
                }
            }, {
                "Name": "HSF",
                "Client_c": "HSF",
                "RDC": "STA GUANGZHOU1",
                "CusId": "0215373977",//月结账号
                "DotCode": "757BH",//网店代码
                "Day": "2",//要查询多少天前的数据
                "AllPrint_express_type": "1",//快件产品类别,业务类型,目前仅有的1.顺丰次日;5.顺丰次晨
                "AllPrint_pay_method": "1",//付款方式,1:寄方付,2:收方付,3:第三方付
                "AllPrint_need_return_tracking_no": "1",//是否要求签回单号:1:要求,其它为不要求
                "AllPrint_parcel_quantity": "1",//包裹数,一个包裹对应一个运单号
                "FixedIssueInfo":{
                    "IsFixedIssueInfo":"Y",
                    "ISSUE_PARTY_ADDR":"广州萝岗区云埔工业区云埔三路12号",
                    "ISSUE_PARTY_CONTACT":"许志平",
                    "ISSUE_PARTY_TEL":"18928933693"
                }
            }
        ]
    }
]

 

posted @ 2017-03-08 15:04  花生打代码会头痛  阅读(334)  评论(0)    收藏  举报