/// <summary> /// Detr指令过去数据 /// </summary> /// <param name="detrList"></param> /// <param name="SendIns"></param> /// <param name="pm"></param> /// <returns></returns> public DetrModel GetDetrModel(List <string> detrList, SendDataHandler SendIns, ParamObject pm) { DetrModel DM = new DetrModel(); string DetrFPatern = @"^\s*(?<=detr)[\s|\:|\:]{1}TN\/\d{3,4}(\-?|\s+)\d{10}\,F\s*$"; Match detrch = Regex.Match(pm.code, DetrFPatern, RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase); if (detrch.Success) { #region Detr ,F string pattern = @"^.*\nNAME:\s*(?<Name>[A-Z\u4e00-\u9fa5/ ]+)(INF)?.*?\s+TKTN:\s*(?<Tktn>\d{13})\s+RCPT:\s+\d\s+(?<Number1>.+)\s+(\d\s+(?<Number2>.+))?"; Match match = Regex.Match(detrList[0], pattern); if (match.Success) { DM.PassengerName = match.Groups["Name"].Value; DM.TicketNumber = match.Groups["Tktn"].Value; string[] strArray = new string[] { match.Groups["Number1"].Value, match.Groups["Number2"].Value }; foreach (string str2 in strArray) { if (str2.Length > 2) { if (str2.StartsWith("RP")) { DM.SerialNumber = str2.Substring(2).Trim(new char[] { ' ', '\r', '\n' }); if (DM.SerialNumber.Length > 4) { DM.CheckVate = DM.SerialNumber.Substring(DM.SerialNumber.Length - 4, 4); } } else if ((str2.StartsWith("NI") || str2.StartsWith("PP")) || str2.StartsWith("ID")) { DM.SsrCard = str2.Substring(2).Trim(new char[] { ' ', '\r', '\n' }); } } } } #endregion } else { //TakeTicketInfo(); } return(null); }
/// <summary> /// 返回全部内容:DETR TN/票号,S /// </summary> /// <param name="strTicketNumber"></param> /// <param name="SendIns"></param> /// <param name="pm"></param> /// <returns></returns> private string TakeTicketInfo(string strTicketNumber, SendDataHandler SendIns, ParamObject pm) { string str3 = string.Empty;; try { pm.code = string.Format("DETR TN/{0},S", strTicketNumber); int num = 0; string str2 = string.Empty; StringBuilder builder = new StringBuilder(); while (num < 3) { str2 = SendIns(pm); if (string.IsNullOrEmpty(str2)) { throw new Exception("获取数据时发生异常!"); } if (((str2 == "通道忙") || str2.Contains("INCORRECT MESSAGE BACK,RETRY FOR ITINERARY PRINT")) || str2.Contains("ELECTRONIC TICKET TRANSACTION TIME OUT!!")) { Thread.Sleep(pm.PNSleep); num++; } else { builder.Append(str2); if (Regex.IsMatch(str2, @"\+\s+")) { pm.code = "PN1"; } else { break; } } Thread.Sleep(pm.PNSleep); } str3 = builder.ToString(); } catch (Exception ex) { return(""); } return(str3); }
/// <summary> /// 格式化具体指令返回 /// </summary> /// <param name="SendIns"></param> /// <param name="code"></param> /// <param name="type"></param> /// <returns></returns> public InsModel FormatIns(SendDataHandler SendIns, ParamObject pm, InsType type) { InsModel IModel = new InsModel(); if (SendIns != null) { if (!pm.code.ToLower().Trim().StartsWith("detr:")) { //发送指令 string strRecvData = SendIns(pm); int MaxPNCount = 6;//最大PN数 if (type == InsType.AVH) { List <string> avhList = new List <string>(); avhList.Add(strRecvData); pm.code = "PN"; Thread.Sleep(pm.PNSleep); strRecvData = SendIns(pm); int i = 0; while (i < MaxPNCount) { if (strRecvData.Contains("下一页") || strRecvData == avhList[avhList.Count - 1]) { break; } else { if (!strRecvData.Contains("指令频繁")) { avhList.Add(strRecvData); } strRecvData = SendIns(pm); Thread.Sleep(pm.PNSleep); i++; } } IModel._avh = GetAVHData(avhList); } else if (type == InsType.FD) { #region 获取FD数据 if (!strRecvData.Contains("没有适用运价")) { //FD数据列表 List <string> FdList = new List <string>(); FdList.Add(strRecvData); int PageIndex = 1, PageCount = 1; string PagePattern = @"(?<=PAGE)\s*(?<PageIndex>\d+)\/(?<PageCount>\d+)\s*"; Match PageMch = Regex.Match(strRecvData, PagePattern, RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase); if (PageMch.Success) { int.TryParse(PageMch.Groups["PageIndex"].Value.Trim(), out PageIndex); int.TryParse(PageMch.Groups["PageCount"].Value.Trim(), out PageCount); } if (PageIndex != PageCount) { for (int i = PageIndex; i < PageCount; i++) { pm.code = "PN"; strRecvData = SendIns(pm); FdList.Add(strRecvData); } } IModel._fd = GetFDData(FdList); } #endregion } else if (type == InsType.PAT) { FormatPNR pnr = new FormatPNR(); string errMsg = ""; IModel._pat = pnr.GetPATInfo(strRecvData, out errMsg); } } else { if (type == InsType.Detr) { List <string> avhList = new List <string>(); IModel._detr = GetDetrModel(avhList, SendIns, pm); } } } return(IModel); }