/// <summary>
        /// 指令记录到数据库
        /// </summary>
        /// <param name="PM"></param>
        /// <param name="TicketLP"></param>
        /// <returns></returns>
        public string WriteLogDB(ParamObject PM, ListParam TicketLP)
        {
            string         Recvdata = "";
            Tb_SendInsData sendins  = new Tb_SendInsData();

            try
            {
                sendins.SendTime = System.DateTime.Now;
                Recvdata         = SendNewPID.SendCommand(PM);
                sendins.RecvTime = System.DateTime.Now;
            }
            catch (Exception ex)
            {
            }
            finally
            {
                try
                {
                    //指令记入数据库
                    sendins.SendIns         = PM.code;
                    sendins.RecvData        = Recvdata;
                    sendins.SendInsType     = 18;
                    sendins.Office          = PM.Office;
                    sendins.ServerIPAndPort = PM.ServerIP + ":" + PM.ServerPort;
                    sendins.UserAccount     = "BSP";
                    sendins.CpyNo           = TicketLP.CpyNo;
                    //插入数据库
                    Manage.ExecuteNonQuerySQLInfo(PbProject.Dal.Mapping.MappingHelper <Tb_SendInsData> .CreateInsertModelSql(sendins, new List <string>()
                    {
                        "id"
                    }));
                }
                catch (Exception)
                {
                }
            }
            return(Recvdata);
        }
        /// <summary>
        /// 支付宝自动出票
        /// </summary>
        /// <param name="passengerManage"></param>
        /// <param name="order"></param>
        /// <param name="Log"></param>
        private void AlipayTicketWork(Tb_Ticket_PassengerBLL passengerManage, Tb_Ticket_Order order, ListParam LPm, B2BShowLog Log)
        {
            PbProject.Logic.Pay.AliPay alipay             = new PbProject.Logic.Pay.AliPay();
            PbProject.Model.definitionParam.BaseSwitch BS = new PbProject.Model.definitionParam.BaseSwitch();
            string GYCpyNo = order.CPCpyNo;

            if (GYCpyNo.Length >= 12)
            {
                GYCpyNo = GYCpyNo.Substring(0, 12);
                PbProject.Model.User_Company mTopcom = new PbProject.Logic.User.User_CompanyBLL().GetCompany(GYCpyNo);
                PbProject.Logic.ControlBase.Bd_Base_ParametersBLL Bp      = new PbProject.Logic.ControlBase.Bd_Base_ParametersBLL();
                List <PbProject.Model.Bd_Base_Parameters>         ParList = Bp.GetParametersListByCpyNo(mTopcom.UninCode.ToString());
                BS = PbProject.WebCommon.Utility.BaseParams.getParams(ParList);

                string msg         = "";
                string UpdateFiled = "";
                string sql         = "";
                try
                {
                    //锁定订单
                    sql = string.Format(" update Tb_Ticket_Order set LockCpyNo='{0}' ,LockTime='{1}',LockLoginName='系统管理员' where OrderId='{2}' ", GYCpyNo, System.DateTime.Now, order.OrderId);
                    Manage.ExecuteNonQuerySQLInfo(sql);

                    bool IsOk = alipay.AutoPay(order, BS, ref msg);
                    //失败请求次数默认
                    int times = 3;
                    try
                    {
                        times = string.IsNullOrEmpty(BS.AutoPayAccount.Split('^')[1]) ? 1 : Convert.ToInt32(BS.AutoPayAccount.Split('^')[1]);
                    }
                    catch (Exception)
                    {
                        Log(2, "错误:失败次数未取到, 订单号:" + order.OrderId + " " + BS.AutoPayAccount + "\r\n");
                    }
                    //请求成功
                    if (IsOk)
                    {
                        //添加操作订单的内容
                        string LogCon = "于 " + DateTime.Now + " 自动出票启动成功,请等待航空公司出票后系统自动回帖票号";
                        OrderLog(order.OrderId, LogCon, LPm, "1");
                        Log(2, string.Format("出票成功,订单ID{0}", order.OrderId) + "\r\n");
                        UpdateFiled = " A10=1 ,";//标识已请求成功
                    }
                    else
                    {
                        Log(2, string.Format("订单ID{0},出票信息:{1}", order.OrderId, msg) + "\r\n");
                        for (int i = 0; i < times; i++)
                        {
                            IsOk = alipay.AutoPay(order, BS, ref msg);
                            Log(2, string.Format("订单ID{0},出票信息:{1}", order.OrderId, msg) + "\r\n");
                            if (IsOk)
                            {
                                //添加操作订单的内容
                                string LogCon = "于 " + DateTime.Now + " 自动出票启动成功,请等待航空公司出票后系统自动回帖票号";
                                OrderLog(order.OrderId, LogCon, LPm, "1");
                                Log(2, string.Format("出票成功,订单ID{0}", order.OrderId) + "\r\n");
                                UpdateFiled = " A10=1 ,";//标识已请求成功
                                break;
                            }
                            if (i >= times - 1)
                            {
                                #region 记录操作日志
                                //记录日志
                                if (msg == "未查到符合支付价格的政策")
                                {
                                    msg = "与航空公司网站价格不符合";
                                }
                                string LogCon = "于 " + DateTime.Now + " 第" + (i + 1).ToString() + "次调用自动出票失败,失败原因:" + msg;
                                OrderLog(order.OrderId, LogCon, LPm, "1");
                                #endregion
                                UpdateFiled = " A10=2,AutoPrintFlag=0 ,";//标识已请求成功
                            }
                            Thread.Sleep(1);
                        }
                    }
                }
                catch (Exception ex)
                {
                    try
                    {
                        Log(2, "发生不可预料的异常:" + ex.Message + "该功能停止,请重新启动,如果继续发生请联系开发人员解决,谢谢!\r\n");
                        if (ex is ThreadAbortException)
                        {
                            return;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                finally
                {
                    //解锁订单
                    sql = string.Format(" update Tb_Ticket_Order set " + UpdateFiled + " LockCpyNo='',LockLoginName='' ,LockTime='{0}' where OrderId='{1}' ", System.DateTime.Now, order.OrderId);
                    Manage.ExecuteNonQuerySQLInfo(sql);
                }
            }
        }
        private void AlipayWork(List <string> CpyNoList, List <ListParam> LPList, B2BShowLog Log)
        {
            try
            {
                List <string> removeList = new List <string>();
                foreach (string CpyNo in CpyNoList)
                {
                    string KonZhiXT = GetGYParameters(CpyNo);
                    if (KonZhiXT != null && !KonZhiXT.Contains("|22|"))//开启B2B自动出票
                    {
                        removeList.Add(CpyNo);
                    }
                }
                //移除掉没有开启的B2B运营商
                if (removeList.Count > 0)
                {
                    foreach (string item in removeList)
                    {
                        if (CpyNoList.Contains(item))
                        {
                            Log(2, string.Format("公司编号:{0} B2B自动出票未开启\r\n", item));
                            CpyNoList.Remove(item);
                        }
                    }
                }

                PbProject.Logic.Order.Tb_Ticket_OrderBLL     orderMange      = new PbProject.Logic.Order.Tb_Ticket_OrderBLL();
                PbProject.Logic.Order.Tb_Ticket_PassengerBLL passengerManage = new PbProject.Logic.Order.Tb_Ticket_PassengerBLL();
                while (true)
                {
                    try//避免异常跳出循环 2013-6-9添加
                    {
                        //王永磊修改语句
                        string sqlWhere = string.Format(" left(CPCpyNo,12) in({0}) and  cast( isnull(AutoPrintTimes,'0') as int) < 3 and PolicyType=1 and AutoPrintFlag=2 and A10<>1  and OrderStatusCode=3 ", string.Join(",", CpyNoList.ToArray()));
                        List <PbProject.Model.Tb_Ticket_Order> orderList = Manage.CallMethod("Tb_Ticket_Order", "GetList", null, new object[] { sqlWhere }) as List <PbProject.Model.Tb_Ticket_Order>;

                        if (orderList == null || orderList.Count == 0)
                        {
                            Thread.Sleep(1);
                            continue;
                        }

                        if (orderList.Count > 0)
                        {
                            Log(2, "支付宝本票通自动出票开始 订单数:" + orderList.Count + "\r\n");
                            for (int i = 0; i < orderList.Count; i++)
                            {
                                PbProject.Model.Tb_Ticket_Order order = orderList[i];
                                ListParam LPM = LPList.Find(delegate(ListParam _pm)
                                {
                                    return(_pm.CpyNo == order.CPCpyNo.Substring(0, 12));
                                });
                                if (LPM != null)
                                {
                                    AlipayTicketWork(passengerManage, order, LPM, Log);
                                }
                                Thread.Sleep(1);
                            }
                            Log(2, "支付宝本票通自动出票结束 订单数:" + orderList.Count + "\r\n");
                        }
                        Thread.Sleep(m_AlipayRefreshTime * 1000);
                    }
                    catch (Exception ex)
                    {
                        Log(2, "AlipayWork  while发生不可预料的异常:" + ex.Message + "" + "\r\n");
                    }
                }
            }
            catch (Exception ex)
            {
                Log(2, "AlipayWork发生不可预料的异常:" + ex.Message + "" + "\r\n");
            }
        }
        //不能自动出票,设置为手动
        private void ChinapnrAutofailed(PbProject.Model.Tb_Ticket_Order order, string msg, ListParam LPM, B2BShowLog Log)
        {
            string SQL = " update Tb_Ticket_Order set A10=2,AutoPrintFlag=0 where OrderId='" + order.OrderId + "'";

            PbProject.Logic.SQLEXBLL.SQLEXBLL_Base ss = new PbProject.Logic.SQLEXBLL.SQLEXBLL_Base();
            ss.ExecuteNonQuerySQLInfo(SQL);
            // ShowChinapnrMsg(msg);
            //infoLog.Info(msg);
            Log(3, msg);
        }
        /// <summary>
        /// 出票Socket调用
        /// </summary>
        /// <param name="orderMange"></param>
        /// <param name="client"></param>
        /// <param name="order"></param>
        /// <param name="comModel"></param>
        /// <param name="data"></param>
        private void ChinapnrTicketWork(PbProject.Logic.Order.Tb_Ticket_OrderBLL orderMange, ChinaPnrClient client, PbProject.Model.Tb_Ticket_Order order, string data, int AutoCount, ListParam Pm, B2BShowLog Log)
        {
            int times = AutoCount;          //至少一次

            for (int i = 0; i < times; i++) //调用次数
            {
                //调用ChinaPnrClient对象的Send方法,获取发送结果
                string result = client.Send(data);//合法请求:0011QUERY_VALID;非法请求:0021QUERY_INVALID 错误描述。
                if (result.Contains("0011QUERY_VALID"))
                {
                    order.A10 = "1";//标识出票成功
                    string SQL = " update Tb_Ticket_Order set A10=1 where OrderId='" + order.OrderId + "'";

                    PbProject.Logic.SQLEXBLL.SQLEXBLL_Base ss = new PbProject.Logic.SQLEXBLL.SQLEXBLL_Base();
                    ss.ExecuteNonQuerySQLInfo(SQL);

                    //ShowChinapnrMsg("出票请求成功,订单ID:" + order.OrderId);
                    //infoLog.Info("出票请求成功,订单ID:" + order.OrderId);
                    Log(3, "出票请求成功,订单ID:" + order.OrderId);
                    break;
                }
                else
                {
                    string logDbMsg = "";
                    if (string.IsNullOrEmpty(result))
                    {
                        logDbMsg = "出票请求失败。原因:服务器响应超时";
                        string msg = string.Format("出票请求失败。原因:服务器响应超时,订单ID:{0}", order.OrderId);
                        //ShowChinapnrMsg(msg);
                        //infoLog.Info(msg);
                        Log(3, msg);
                    }
                    else
                    {
                        string errorStr = result.Substring(17, result.Length - 17).Trim();
                        if (errorStr.ToLower().IndexOf("airlines") > 0)
                        {
                            logDbMsg = string.Format("出票请求失败。原因:{0},航空公司二字码:{1}", errorStr, order.CarryCode);
                            string msg = string.Format("出票请求失败。原因:{0},航空公司二字码:{1},订单ID:{2}", errorStr, order.CarryCode, order.OrderId);
                            //ShowChinapnrMsg(msg);
                            //infoLog.Info(msg);
                            Log(3, msg);
                        }
                        else
                        {
                            logDbMsg = string.Format("出票请求失败。原因:{0}", errorStr);
                            string msg = string.Format("出票请求失败。原因:{0},订单ID:{1}", errorStr, order.OrderId);
                            //ShowChinapnrMsg(msg);
                            //infoLog.Info(msg);
                            Log(3, msg);
                        }
                    }
                    if (i == times - 1)
                    {
                        string msg = string.Format("已达到最大失败次数,已改为手动出票,订单ID:{0}", order.OrderId);
                        ChinapnrAutofailed(order, msg, Pm, Log);
                        //FailedLogToDb(order, logDbMsg + ",已改为手动出票");
                        OrderLog(order.OrderId, logDbMsg + ",已改为手动出票", Pm, "2");
                    }
                }
                Thread.Sleep(3000);
            }
        }
        /// <summary>
        /// 出票流程
        /// </summary>
        private void ChinapnrWork(List <string> CpyNoList, List <ListParam> LPList, B2BShowLog Log)
        {
            try
            {
                List <string> removeList = new List <string>();
                foreach (string CpyNo in CpyNoList)
                {
                    string KonZhiXT = GetGYParameters(CpyNo);
                    if (KonZhiXT != null && !KonZhiXT.Contains("|22|"))//开启B2B自动出票
                    {
                        removeList.Add(CpyNo);
                    }
                }
                if (removeList.Count > 0)
                {
                    foreach (string item in removeList)
                    {
                        if (CpyNoList.Contains(item))
                        {
                            Log(3, string.Format("公司编号:{0} B2B自动出票未开启\r\n", item));
                            CpyNoList.Remove(item);
                        }
                    }
                }
                PbProject.Logic.Order.Tb_Ticket_OrderBLL     orderMange      = new PbProject.Logic.Order.Tb_Ticket_OrderBLL();
                PbProject.Logic.Order.Tb_Ticket_PassengerBLL passengerManage = new PbProject.Logic.Order.Tb_Ticket_PassengerBLL();

                ChinaPnrClient client = new ChinaPnrClient(System.Configuration.ConfigurationManager.AppSettings["HuifuAutoIP"]);
                while (true)
                {
                    try
                    {
                        PbProject.Model.definitionParam.BaseSwitch BS = new PbProject.Model.definitionParam.BaseSwitch();

                        string sqlWhere = string.Format(" left(CPCpyNo,12) in({0}) and  cast( isnull(AutoPrintTimes,'0') as int) < 3 and PolicyType=1 and AutoPrintFlag=2  and OrderStatusCode=3 and A10<>1 ", string.Join(",", CpyNoList.ToArray()));
                        List <PbProject.Model.Tb_Ticket_Order> orderList = Manage.CallMethod("Tb_Ticket_Order", "GetList", null, new object[] { sqlWhere }) as List <PbProject.Model.Tb_Ticket_Order>;


                        if (orderList.Count == 0)
                        {
                            Thread.Sleep(m_ChinapnrRefreshTime * 1000);
                            continue;
                        }

                        foreach (PbProject.Model.Tb_Ticket_Order order in orderList)
                        {
                            if (order.CPCpyNo.Length >= 12)
                            {
                                PbProject.Model.User_Company mTopcom = new PbProject.Logic.User.User_CompanyBLL().GetCompany(order.CPCpyNo.Substring(0, 12));
                                PbProject.Logic.ControlBase.Bd_Base_ParametersBLL Bp      = new PbProject.Logic.ControlBase.Bd_Base_ParametersBLL();
                                List <PbProject.Model.Bd_Base_Parameters>         ParList = Bp.GetParametersListByCpyNo(mTopcom.UninCode.ToString());
                                BS = PbProject.WebCommon.Utility.BaseParams.getParams(ParList);
                            }
                            else
                            {
                                continue;
                            }

                            ListParam LPM = LPList.Find(delegate(ListParam _pm)
                            {
                                return(_pm.CpyNo == order.CPCpyNo.Substring(0, 12));
                            });

                            IList <PbProject.Model.Tb_Ticket_Passenger> orderPassenger = passengerManage.GetPasListByOrderID(order.OrderId);
                            decimal faceValue = 0;
                            foreach (PbProject.Model.Tb_Ticket_Passenger passenger in orderPassenger)
                            {
                                faceValue += passenger.PMFee;
                            }

                            //格式:自动出票方式(1,支付宝本票通;2,汇付天下出票窗)^帐号|是否签约(1,已签约;2,未签)^帐号|密码|支付方式(1,信用账户;2,付款账户)
                            if (string.IsNullOrEmpty(BS.AutoPayAccount.Split('^')[3]) || BS.AutoPayAccount.Split('^')[3].Split('|').Length < 3)
                            {
                                string msg = "未绑定汇付天下账号,不能自动出票,该共功能已停止!,订单ID:" + order.OrderId;
                                //StopChinapnrThread(msg);
                                Log(3, msg);
                                continue;
                            }

                            //格式:CA:xxx//xxx^^^CZ:xxx//xxx^^^MU:xxx//xxx
                            string   Acc      = "";
                            string   pwd      = "";
                            string[] CarrList = BS.AutoAccount.Split(new string[] { "^^^" }, StringSplitOptions.RemoveEmptyEntries);//Regex.Split(BS.AutoAccount, "^^^", RegexOptions.IgnoreCase);
                            for (int i = 0; i < CarrList.Length; i++)
                            {
                                if (CarrList[i].Contains(order.CarryCode))
                                {
                                    Acc = CarrList[i].Split(new string[] { "//" }, StringSplitOptions.None)[0].Split(':')[1]; //Regex.Split(CarrList[i].Split(':')[1], "//", RegexOptions.IgnoreCase)[0];
                                    pwd = CarrList[i].Split(new string[] { "//" }, StringSplitOptions.None)[1];               //Regex.Split(CarrList[i].Split(':')[1], "//", RegexOptions.IgnoreCase)[1];
                                    break;
                                }
                            }
                            if (string.IsNullOrEmpty(Acc) || string.IsNullOrEmpty(pwd))
                            {
                                string msg = "航空公司帐号和密码为空,不能自动出票,改为手动出票,订单ID:" + order.OrderId;
                                ChinapnrAutofailed(order, msg, LPM, Log);
                                continue;
                            }

                            //根据订单信息,构造参数实体类ChinaPnrParams,参数构造见接口文档
                            ChinaPnrParams chinaPnrParams = new ChinaPnrParams();
                            chinaPnrParams.PNRNo       = order.BigCode;
                            chinaPnrParams.GUID        = order.OrderId;
                            chinaPnrParams.Airlines    = order.CarryCode.Split('/')[0];
                            chinaPnrParams.FaceValue   = faceValue.ToString();
                            chinaPnrParams.Username    = Acc;
                            chinaPnrParams.B2BPswd     = pwd;
                            chinaPnrParams.CPNROper    = BS.AutoPayAccount.Split('^')[3].Split('|')[0];
                            chinaPnrParams.CPNRPswd    = StringUtils.GetMd5(BS.AutoPayAccount.Split('^')[3].Split('|')[1]);
                            chinaPnrParams.PayType     = BS.AutoPayAccount.Split('^')[3].Split('|')[2];
                            chinaPnrParams.PartnerCode = "63";

                            string data = ChinaPnrParams.ChinaPnrParamsToString(chinaPnrParams);


                            ChinapnrTicketWork(orderMange, client, order, data, Convert.ToInt32(BS.AutoPayAccount.Split('^')[1]), LPM, Log);
                        }

                        //在出票结果会出现在ChinaPnrParams中配置的RetURL链接中,在对应的RetURL里执行返回操作,这里业务逻辑结束
                        Thread.Sleep(m_ChinapnrRefreshTime * 1000);
                    }
                    catch (Exception e)
                    {
                        try
                        {
                            if (e is ThreadAbortException)
                            {
                                return;
                            }
                            // errorLog.Error(e.Message, e);
                            Log(3, e.Message);
                            //ShowChinapnrMsg(string.Format("发生不可预料的异常:{0}该功能暂停,1分钟后重新开始!", e.Message));
                            Log(3, string.Format("发生不可预料的异常:{0}该功能暂停,1分钟后重新开始!", e.Message));
                            Thread.Sleep(60000);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            catch (Exception e)
            {
                try
                {
                    if (e is ThreadAbortException)
                    {
                        return;
                    }
                    // errorLog.Error(e.Message, e);
                    // ShowChinapnrMsg(string.Format("发生不可预料的异常:{0}该功能停止,如果继续发生请联系开发人员解决,谢谢!", e.Message));
                    Log(3, "发生不可预料的异常:" + e.Message + "该功能停止,如果继续发生请联系开发人员解决,谢谢!");
                }
                catch (Exception)
                {
                }
            }
        }
        /* BSP常见错误信息
         * MRT:HT0LYJ IGNORED
         * INCOMPLETE PNR/FN
         * PLEASE CHECK TKT ELEMENT
         * CHECK BLINK CODE
         * ELE NBR
         */
        /// <summary>
        /// BSP订单处理
        /// </summary>
        /// <param name="Order"></param>
        private void BspHandle(Tb_Ticket_Order Order, List <ListParam> LPList, BSPShowLog Log)
        {  //订单日志
            StringBuilder sbLog = new StringBuilder();

            if (Order != null)
            {
                //订单出票公司信息
                ListParam TicketLP = LPList.Find(delegate(ListParam _tempLP)
                {
                    return(Order.OwnerCpyNo.Contains(_tempLP.CpyNo));
                });

                //编码解析类
                PnrAnalysis.FormatPNR pnrFormat = new PnrAnalysis.FormatPNR();
                //判断标识
                List <string> NumTickList          = new List <string>();
                List <string> PTList               = null;
                List <Tb_Ticket_Passenger> PasList = null;
                try
                {
                    Log(0, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "订单号:" + Order.OrderId + "=======================start=====================\r\n");
                    string GYCpyNo = Order.OwnerCpyNo;
                    if (GYCpyNo.Length >= 12)
                    {
                        GYCpyNo = GYCpyNo.Substring(0, 12);
                    }
                    string CarrayCode = Order.CarryCode.Split('/')[0];
                    Tb_Ticket_PrintOffice PrintOffice = GetPrintOffice(GYCpyNo, CarrayCode);
                    if (PrintOffice == null || PrintOffice.PrintCode == "")
                    {
                        Log(0, string.Format("{0}未设置打票机号,请手动出票!", CarrayCode));
                        sbLog.Append(string.Format("{0}未设置打票机号,请手动出票!", CarrayCode));
                        return;
                    }
                    //出票Office
                    string pOffice   = string.IsNullOrEmpty(PrintOffice.OfficeCode) ? Order.PrintOffice : PrintOffice.OfficeCode;
                    string PrintCode = PrintOffice.PrintCode;
                    string Pnr       = Order.PNR;//Pnr编码
                    if (pOffice == "")
                    {
                        Log(0, string.Format("{0}出票Office不能为空!", CarrayCode));
                        sbLog.Append(string.Format("{0}出票Office不能为空!", CarrayCode));
                        return;
                    }
                    //获取乘客
                    string sqlWhere           = string.Format(" OrderId='{0}' order by PassengerType", Order.OrderId);
                    Tb_Ticket_Passenger pMode = null;
                    PasList = Manage.CallMethod("Tb_Ticket_Passenger", "GetList", null, new object[] { sqlWhere }) as List <Tb_Ticket_Passenger>;
                    if (PasList == null || PasList.Count == 0)
                    {
                        Log(0, string.Format("订单号:{0}没有找到对应的乘客信息!", Order.OrderId));
                        sbLog.Append(string.Format("订单号:{0}没有找到对应的乘客信息!", Order.OrderId));
                        return;
                    }
                    else
                    {
                        pMode = PasList[0];
                    }
                    List <Bd_Base_Parameters> baseParamList = Manage.CallMethod("Bd_Base_Parameters", "GetList", null, new Object[] { "CpyNo='" + GYCpyNo + "'" }) as List <Bd_Base_Parameters>;
                    ConfigParam config = Bd_Base_ParametersBLL.GetConfigParam(baseParamList);
                    //指令管理类
                    //SendInsManage SendManage = new SendInsManage(Order.OwnerCpyNo, GYCpyNo, config);
                    if (config == null)
                    {
                        Log(0, string.Format("订单号{0},公司{1}未设置使用配置信息,请设置!", Order.OrderId, CarrayCode));
                        sbLog.Append(string.Format("订单号{0},公司{1}未设置使用配置信息,请设置!", Order.OrderId, CarrayCode));
                        return;
                    }
                    if (string.IsNullOrEmpty(Order.PNR))
                    {
                        Log(0, string.Format("订单号{0}中没有PNR,请检查!", Order.OrderId));
                        sbLog.Append(string.Format("订单号{0}中没有PNR,请检查!", Order.OrderId));
                        return;
                    }

                    ParamObject PM = new ParamObject();
                    PM.ServerIP   = config.WhiteScreenIP;
                    PM.ServerPort = int.Parse(config.WhiteScreenPort);
                    PM.Office     = pOffice;

                    //发送指令
                    string SendIns = "RT" + Pnr;
                    //返回数据
                    string Recvdata = string.Empty;
                    PM.code = SendIns;
                    PM.IsPn = true;
                    //  Recvdata = SendNewPID.SendCommand(PM);
                    Recvdata = WriteLogDB(PM, TicketLP);
                    //指令日志
                    Log(0, string.Format("\r\n【订单号{0}】发送指令>{1}\r\n接收数据:\r\n{2}\r\n", Order.OrderId, SendIns, Recvdata));
                    //授权检查
                    if (Recvdata.ToUpper().Contains("授权"))
                    {
                        Log(0, string.Format("订单号{0},编码{1} 出票Office{2},发送指令需要授权!", Order.OrderId, Pnr, pOffice));
                        sbLog.Append(string.Format("订单号{0},编码{1} 出票Office{2},发送指令需要授权!", Order.OrderId, Pnr, pOffice));
                        return;
                    }
                    else if (Recvdata.ToUpper().Contains("CANCELLED"))
                    {
                        Log(0, string.Format("订单号{0},编码{1} 出票Office{2},编码已取消,出票失败!", Order.OrderId, Pnr, pOffice));
                        sbLog.Append(string.Format("订单号{0},编码{1} 出票Office{2},编码已取消,出票失败!", Order.OrderId, Pnr, pOffice));
                        return;
                    }
                    string Msg = "";
                    string Xe = "", RR = "";
                    string PnrStatus = pnrFormat.GetPnrStatus(Recvdata, out Msg);
                    if (PnrStatus.Contains("NO"))
                    {
                        Log(0, string.Format("订单号{0},编码{1} 出票Office{2},编码状态为{3},不能自动出票!!", Order.OrderId, Pnr, pOffice, PnrStatus));
                        sbLog.Append(string.Format("订单号{0},编码{1} 出票Office{2},编码状态为{3},不能自动出票!!", Order.OrderId, Pnr, pOffice, PnrStatus));
                        return;
                    }
                    //存在的票号
                    PTList = GetTicketNum(Pnr, Recvdata.ToUpper(), pnrFormat);
                    List <string> RRList = null;
                    List <string> XEList = null;
                    if (PTList.Count == 0)
                    {
Start:
                        {
                            //进行出票
                            HashObject hash = GetNumList(Recvdata);
                            XEList = hash["XEList"] as List <string>;
                            RRList = hash["RRList"] as List <string>;
                            List <string> StartXeList = hash["StartXeList"] as List <string>;
                            //XE项
                            if (StartXeList.Count > 0)
                            {
                                for (int i = 0; i < StartXeList.Count; i++)
                                {
                                    string XeStr = StartXeList[i];
                                    if (XeStr != "")
                                    {
                                        //发送指令
                                        SendIns = "RT" + Pnr + "|XE" + XeStr + "|@";
                                        PM.code = SendIns;
                                        PM.IsPn = false;
                                        //Recvdata = SendNewPID.SendCommand(PM);//MRT:JG61M2 IGNORED
                                        Recvdata = WriteLogDB(PM, TicketLP);
                                        //指令日志
                                        Log(0, string.Format("\r\n【订单号{0}】发送指令>{1}\r\n接收数据:\r\n{2}\r\n", Order.OrderId, SendIns, Recvdata));

                                        //判断是否XE成功
                                        if (pnrFormat.INFMarkIsOK(Recvdata, out Msg))
                                        {
                                            /*  3U8881  E TU30APR  CTUPEK HK1   0730 1005
                                             * JG61M2 -  航空公司使用自动出票时限, 请检查PNR
                                             *** 预订酒店指令HC, 详情  HC:HELP   ***
                                             */
                                            //发送指令
                                            SendIns = "RT" + Pnr;
                                            PM.code = SendIns;
                                            PM.IsPn = true;
                                            //Recvdata = SendNewPID.SendCommand(PM);
                                            Recvdata = WriteLogDB(PM, TicketLP);
                                            //指令日志
                                            Log(0, string.Format("\r\n【订单号{0}】发送指令>{1}\r\n接收数据:\r\n{2}\r\n", Order.OrderId, SendIns, Recvdata));
                                            goto Start;
                                        }
                                    }
                                }
                            }
                        }



                        string patPrice = "pat:a";
                        if (!Order.IsChdFlag)
                        {
                            //成人
                            patPrice = "pat:a";
                        }
                        else
                        {
                            //儿童
                            patPrice = "pat:a*ch";
                        }
                        //发送指令
                        SendIns = "RT" + Pnr + "|" + patPrice;
                        PM.code = SendIns;
                        PM.IsPn = false;
                        //Recvdata = SendNewPID.SendCommand(PM);
                        Recvdata = WriteLogDB(PM, TicketLP);
                        //指令日志
                        Log(0, string.Format("\r\n【订单号{0}】发送指令>{1}\r\n接收数据:\r\n{2}\r\n", Order.OrderId, SendIns, Recvdata));
                        if (Recvdata.IndexOf("PAT") == -1)
                        {
                            //发送指令
                            Log(0, string.Format("订单号{0},编码{1} 出票Office{2},编码已取消,未能PAT出票价,出票失败!", Order.OrderId, Pnr, pOffice));
                            sbLog.Append(string.Format("订单号{0},编码{1} 出票Office{2},编码已取消,未能PAT出票价,出票失败!", Order.OrderId, Pnr, pOffice));
                            return;
                        }

                        //比较
                        string  xuhao = "", Seat = "", Err = "";
                        decimal _xsFare          = 0m;
                        bool    IsExistParice    = false;
                        PnrAnalysis.PatModel PAT = pnrFormat.GetPATInfo(Recvdata.Replace("\r", ""), out Err);
                        foreach (PatInfo pat in PAT.UninuePatList)
                        {
                            decimal.TryParse(pat.Fare, out _xsFare);
                            //存在此价格
                            if (_xsFare == pMode.PMFee)
                            {
                                IsExistParice = true;
                                xuhao         = pat.SerialNum;
                                Seat          = pat.SeatGroup;
                                break;
                            }
                        }
                        if (!IsExistParice)
                        {
                            Log(0, string.Format("订单号{0},编码{1} 出票Office{2},舱位价{3}与Pat价格{4}不一致,出票失败!", Order.OrderId, Pnr, pOffice, pMode.PMFee, _xsFare));
                            sbLog.Append(string.Format("订单号{0},编码{1} 出票Office{2},舱位价{3}与Pat价格{4}不一致,出票失败!", Order.OrderId, Pnr, pOffice, pMode.PMFee, _xsFare));
                            return;
                        }

                        //做价格进去
                        SendIns = "RT" + Pnr + "|" + patPrice + "|SFC:" + xuhao + "|@";
                        PM.code = SendIns;
                        PM.IsPn = false;
                        //Recvdata = SendNewPID.SendCommand(PM);
                        Recvdata = WriteLogDB(PM, TicketLP);
                        //指令日志
                        Log(0, string.Format("\r\n【订单号{0}】发送指令>{1}\r\n接收数据:\r\n{2}\r\n", Order.OrderId, SendIns, Recvdata));
                        if (Recvdata.Contains("超时") || Recvdata.Contains("NO PNR"))
                        {
                            //Recvdata = SendNewPID.SendCommand(PM);
                            Recvdata = WriteLogDB(PM, TicketLP);
                            //指令日志
                            Log(0, string.Format("\r\n【订单号{0}】发送指令>{1}\r\n接收数据:\r\n{2}\r\n", Order.OrderId, SendIns, Recvdata));
                        }

                        //做备注
                        decimal _Discount = 0m;
                        if (decimal.TryParse(Order.Discount, out _Discount) && Order.Space.IndexOf("Y") == -1 && Order.Space.IndexOf("C") == -1 && Order.Space.IndexOf("F") == -1 && _Discount < 100)
                        {
                            //做价格进去
                            SendIns = "RT" + Pnr + "|EI:不得签转|@";
                            PM.code = SendIns;
                            PM.IsPn = false;
                            //Recvdata = SendNewPID.SendCommand(PM);
                            Recvdata = WriteLogDB(PM, TicketLP);
                            //指令日志
                            Log(0, string.Format("\r\n【订单号{0}】发送指令>{1}\r\n接收数据:\r\n{2}\r\n", Order.OrderId, SendIns, Recvdata));
                            if (Recvdata != "" && Recvdata.Contains("超时"))
                            {
                                //Recvdata = SendNewPID.SendCommand(PM);
                                Recvdata = WriteLogDB(PM, TicketLP);
                                //指令日志
                                Log(0, string.Format("\r\n【订单号{0}】发送指令>{1}\r\n接收数据:\r\n{2}\r\n", Order.OrderId, SendIns, Recvdata));
                            }
                        }



                        foreach (string item in XEList)
                        {
                            if (item != "")
                            {
                                Xe += "XE" + item + "|";
                            }
                        }
                        foreach (string item in RRList)
                        {
                            if (item != "")
                            {
                                RR += item + "RR" + "|";
                            }
                        }
                        if (Xe.Trim(new char[] { '|' }) == "")
                        {
                            Xe = "";
                        }
                        else
                        {
                            Xe = "|" + Xe.Trim('|') + "|";
                        }
                        if (RR.Trim(new char[] { '|' }) == "")
                        {
                            RR = "";
                        }
                        else
                        {
                            RR = "|" + RR.Trim('|') + "|";
                        }
                        if (RR == "")
                        {
                            RR = "|";
                        }
                        if (XEList == null || XEList.Count == 0 || Xe == "")
                        {
                            Log(0, string.Format("订单号{0},编码{1} 出票Office{2},编码状态为{3},未能取出出票时限!!", Order.OrderId, Pnr, pOffice, PnrStatus));
                            sbLog.Append(string.Format("订单号{0},编码{1} 出票Office{2},编码状态为{3},未能取出出票时限!!", Order.OrderId, Pnr, pOffice, PnrStatus));
                            return;
                        }

                        //组合打票指令
                        string etdz = "rt" + Pnr + Xe + RR.TrimEnd('|') + "|ETDZ " + PrintCode;
                        etdz = etdz.Replace("||", "|");

                        //出票
                        SendIns = etdz;
                        PM.code = SendIns;
                        PM.IsPn = false;
                        // Recvdata = SendNewPID.SendCommand(PM);
                        Recvdata = WriteLogDB(PM, TicketLP);
                        //指令日志
                        Log(0, string.Format("\r\n【订单号{0}】发送指令>{1}\r\n接收数据:\r\n{2}\r\n", Order.OrderId, SendIns, Recvdata));


                        if (Recvdata.Contains("超时") || Recvdata.Contains("NO PNR"))
                        {
                            //Recvdata = SendNewPID.SendCommand(PM);
                            Recvdata = WriteLogDB(PM, TicketLP);
                            //指令日志
                            Log(0, string.Format("\r\n【订单号{0}】发送指令>{1}\r\n接收数据:\r\n{2}\r\n", Order.OrderId, SendIns, Recvdata));
                        }
                        if (Recvdata.Contains("请输入证件信息"))
                        {
                            Log(0, string.Format("订单号{0},编码{1} 出票Office{2},编码状态为{3},编码中没有证件号,请输入证件信息,否则不能出票!", Order.OrderId, Pnr, pOffice, PnrStatus));
                            sbLog.Append(string.Format("订单号{0},编码{1} 出票Office{2},编码状态为{3},编码中没有证件号,请输入证件信息,否则不能出票!", Order.OrderId, Pnr, pOffice, PnrStatus));
                            return;
                        }
                        if (Recvdata.ToUpper().Contains("STOCK"))
                        {
                            Log(0, string.Format("订单号{0},编码{1} 出票Office{2},编码状态为{3}," + Recvdata + "没有票号了!", Order.OrderId, Pnr, pOffice, PnrStatus));
                            sbLog.Append(string.Format("订单号{0},编码{1} 出票Office{2},编码状态为{3}," + Recvdata + "没有票号了!", Order.OrderId, Pnr, pOffice, PnrStatus));
                            return;
                        }
                        //出票成功
                        if (Recvdata.Contains("CNY") && Recvdata.ToUpper().Contains(Pnr.ToUpper()))
                        {
                            /*CNY2730.00      HF9550
                             * 876-3250823439         876-3250823441  */

                            SendIns = "RT" + Pnr;
                            PM.code = SendIns;
                            PM.IsPn = true;
                            //Recvdata = SendNewPID.SendCommand(PM);
                            Recvdata = WriteLogDB(PM, TicketLP);
                            //指令日志
                            Log(0, string.Format("\r\n【订单号{0}】发送指令>{1}\r\n接收数据:\r\n{2}\r\n", Order.OrderId, SendIns, Recvdata));
                            //存在的票号
                            PTList = GetTicketNum(Pnr, Recvdata.ToUpper(), pnrFormat);
                        }
                        else
                        {
                            //出票失败 重试
                            if (!Recvdata.ToUpper().Contains("**ELECTRONIC TICKET PNR**") &&
                                Recvdata.ToUpper().Contains("SSR TKNE") &&
                                Recvdata.ToUpper().Contains("/DPN") &&
                                Recvdata.ToUpper().Contains("RMK " + CarrayCode + "/"))
                            {
                                //"ETRY:"   重试指令
                                SendIns = "RT" + Pnr + "|ETRY:";
                                PM.code = SendIns;
                                PM.IsPn = false;
                                //Recvdata = SendNewPID.SendCommand(PM);
                                Recvdata = WriteLogDB(PM, TicketLP);
                                //指令日志
                                Log(0, string.Format("\r\n【订单号{0}】发送指令>{1}\r\n接收数据:\r\n{2}\r\n", Order.OrderId, SendIns, Recvdata));
                            }
                            else
                            {
                                Log(0, string.Format("订单号{0},编码{1} 出票Office{2},编码状态为{3}," + "出票失败,{4}", Order.OrderId, Pnr, pOffice, PnrStatus, Recvdata));
                                sbLog.Append(string.Format("订单号{0},编码{1} 出票Office{2},编码状态为{3}," + "出票失败,{4}", Order.OrderId, Pnr, pOffice, PnrStatus, Recvdata));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log(0, string.Format("订单号{0},出票异常:{1}", Order.OrderId, ex.Message + ex.Source + ex.StackTrace.ToString()));
                    sbLog.Append(string.Format("订单号{0},出票异常:{1}", Order.OrderId, ex.Message + ex.Source + ex.StackTrace.ToString()));
                }
                finally
                {
                    string          TicketMsg = "";
                    Log_Tb_AirOrder OrderLog  = new Log_Tb_AirOrder();
                    //执行SQl语句
                    List <string> sqlList = new List <string>();
                    //修改订单数据列表
                    List <string> OrderList = new List <string>();
                    if (TicketLP != null)
                    {
                        //解锁
                        OrderList.Add(" LockCpyNo='' ");
                        OrderList.Add(" LockLoginName='' ");
                        OrderList.Add(" LockTime='1900-01-01' ");

                        OrderList.Add(" CPTime=getdate() ");
                        OrderList.Add(" CPName='管理员' ");
                        OrderList.Add(string.Format(" CPCpyNo='{0}' ", TicketLP.CpyNo));
                        OrderList.Add(" CPRemark='BSP自动出票' ");
                        OrderList.Add(string.Format(" CPCpyName='{0}' ", TicketLP.UninAllName));

                        //日志
                        OrderLog.id            = Guid.NewGuid();
                        OrderLog.OrderId       = Order.OrderId;
                        OrderLog.OperType      = "出票";
                        OrderLog.OperTime      = DateTime.Now;
                        OrderLog.OperLoginName = "管理员";
                        OrderLog.OperUserName  = "******";
                        OrderLog.CpyNo         = TicketLP.CpyNo;
                        OrderLog.CpyType       = 1;
                        OrderLog.CpyName       = TicketLP.UninAllName;
                    }

                    if (PTList != null && PTList.Count > 0 && PasList != null && PasList.Count > 0)
                    {
                        string PasName = "", TicketNumber = "";
                        for (int i = 0; i < PTList.Count; i++)
                        {
                            if (PTList[i].Split('|').Length == 2)
                            {
                                TicketNumber = PTList[i].Split('|')[0];
                                PasName      = PTList[i].Split('|')[1];
                                Tb_Ticket_Passenger Passenger = PasList.Find(delegate(Tb_Ticket_Passenger _tempPassenger)
                                {
                                    return(PTList[i].ToUpper().Trim().Contains(_tempPassenger.PassengerName.ToUpper().Trim()));
                                });
                                if (Passenger != null)
                                {
                                    sqlList.Add(string.Format(" update Tb_Ticket_Passenger set TicketNumber='{0}',TicketStatus=2 where id='{1}' and PassengerName='{2}' ", TicketNumber, Passenger.id.ToString(), Passenger.PassengerName));
                                }
                            }
                        }
                        //修改订单数据
                        OrderList.Add(" TicketStatus=2 ");
                        OrderList.Add(" OrderStatusCode=4 ");
                        if (OrderList.Count > 0)
                        {
                            sqlList.Add(string.Format(" update Tb_Ticket_Order set {0} where id='{1}' ", string.Join(",", OrderList.ToArray()), Order.id.ToString()));
                        }

                        //出票成功
                        TicketMsg          = "出票成功";
                        OrderLog.WatchType = 5;
                        //日志
                        OrderLog.OperContent = "订单号:" + Order.OrderId + " BSP自动出票成功," + string.Format(",", PasList.ToArray());
                        //修改数据库状态
                    }
                    else
                    {
                        //出票失败
                        TicketMsg = "出票失败";
                        //修改订单自动出票尝试次数
                        if (Order.AutoPrintTimes > 3)//尝试次数大于3改为手动出票
                        {
                            sqlList.Add(string.Format(" update Tb_Ticket_Order set AutoPrintFlag=0,AutoPrintTimes=CAST(AutoPrintTimes as int)+1  where id='{0}' ", Order.id.ToString()));
                        }
                        else
                        {
                            sqlList.Add(string.Format(" update Tb_Ticket_Order set AutoPrintTimes=CAST(AutoPrintTimes as int)+1  where id='{0}' ", Order.id.ToString()));
                        }
                        OrderLog.WatchType = 2;
                        //日志
                        OrderLog.OperContent = "BSP自动出票失败," + sbLog.ToString();
                    }
                    //日志
                    string tempSql = Dal.Mapping.MappingHelper <Log_Tb_AirOrder> .CreateInsertModelSql(OrderLog);

                    sqlList.Add(tempSql);

                    string Msg = "";
                    //修改数据库
                    if (!Manage.ExecuteSqlTran(sqlList, out Msg))
                    {
                        Log(0, string.Format("订单号{0},修改数据库失败:{1}", Order.OrderId, Msg));
                    }
                    Log(0, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "订单号:" + Order.OrderId + "  " + TicketMsg + "=======================end=====================\r\n");
                }
            }
        }