/// <summary> /// 获取航班信息 /// </summary> /// <returns></returns> public void BindData(FlightTotal fInfo) { #region 绑定航空公司 //绑定航空公司 ArrayList airlines = (ArrayList)Session["TicketsSessionKey_Airlines"]; if (airlines != null) { //LogHelper.WriteLog("进入了航空公司绑定:" + airlines.Count); this.rptAirlinesCount.Text = airlines.Count.ToString(); } this.rptAirlines.DataSource = airlines; this.rptAirlines.DataBind(); #endregion pageTickets.Clear(); FlightTotal ft = fInfo; //if (fInfo == null) //{ // ft = GetFlights(); //} //else //{ // ft = fInfo; //} if (Session[string.Format("TicketsSessionKey2_{0}_{1}_{2}_{3}_{4}", this.tripType, fromcityCode, this.tocityCode, Convert.ToDateTime(this.tripDate).ToString("yyyyMMdd"), Convert.ToDateTime(this.backDate).ToString("yyyyMMdd"))] == null) { Session[string.Format("TicketsSessionKey2_{0}_{1}_{2}_{3}_{4}", this.tripType, fromcityCode, this.tocityCode, Convert.ToDateTime(this.tripDate).ToString("yyyyMMdd"), Convert.ToDateTime(this.backDate).ToString("yyyyMMdd"))] = ft; } //绑定航空公司 //ArrayList airlines = (ArrayList)Session["TicketsSessionKey_Airlines"]; //this.rptAirlinesCount.Text = airlines.Count.ToString(); //this.rptAirlines.DataSource = airlines; //this.rptAirlines.DataBind(); //绑定分页控件 this.Pager.RecordCount = ft.result != null ? ft.result.Count : 0; this.Pager.CurrentPageIndex = Convert.ToInt32(Request.QueryString["page"]); int skipCount = this.Pager.PageSize * (Pager.CurrentPageIndex - 1); for (int i = 0, j = 0; i < this.Pager.RecordCount && j < this.Pager.PageSize; i++) { if (i < skipCount) { } else { pageTickets.Add(ft.result[i]); j++; } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { long a = 0; ToCityName = ReadXmlHelper.GetToCityNameByCode(ToCityCode, out a); FromCityName = ReadXmlHelper.GetFromCityNameByCode(FromCityCode, out a); //LogHelper.WriteLog(string.Format("TripType:{0},FromCityCode:{1},ToCityCode:{2},TripDate:{3},BackDate:{4}", this.TripType, this.FromCityCode, this.ToCityCode, this.TripDate, this.BackDate)); FlightTotal ftinfo = (FlightTotal)Session[string.Format("TicketsSessionKey2_{0}_{1}_{2}_{3}_{4}", this.TripType, this.FromCityCode, this.ToCityCode, Convert.ToDateTime(this.TripDate).ToString("yyyyMMdd"), Convert.ToDateTime(this.BackDate).ToString("yyyyMMdd"))]; if (ftinfo != null) { foreach (FlightRoundTrip item in ftinfo.result) { bool isContains = false; foreach (FlightInfo fInfo in item.ListInterFlightInfo) { if (DataGuid == fInfo.dataId) { isContains = true; flightround = item; break; } } if (isContains) { break; } } } else { if (Session[string.Format("TicketsSessionKey_limit_{0}", DataGuid)] != null) { flightround = (FlightRoundTrip)Session[string.Format("TicketsSessionKey_limit_{0}", DataGuid)]; } else { this.GetSource(); } } } catch (Exception ex) { //LogHelper.WriteLog(ex.StackTrace+ex.ToString()+ ex.Message); } } }
/// <summary> /// 分页事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Pager_PageChanged(object sender, EventArgs e) { if (Request.QueryString["page"] == null) { return; } FlightTotal tickets = (FlightTotal)Session[string.Format("TicketsSessionKey2_{0}_{1}_{2}_{3}_{4}", this.tripType, fromcityCode, this.tocityCode, Convert.ToDateTime(this.tripDate).ToString("yyyyMMdd"), Convert.ToDateTime(this.backDate).ToString("yyyyMMdd"))]; if (tickets != null) { this.BindData(tickets); return; } }
/// <summary> /// 获取API数据并存储到session /// </summary> /// <returns></returns> public FlightTotal GetFlights() { FlightParamInfo param = new FlightParamInfo(); param.Startairport = fromcityCode; param.Endairport = tocityCode; param.Startdate = tripDate; //为往返的,加上返回时间 if (tripType == 1) { param.Backdate = backDate; } string jsonTxt = FlightAPI.GetFlight(param); FlightTotal ft = FlightAPI.DeserializeJsonToObject <FlightTotal>(jsonTxt); return(ft); }
/// <summary> /// 获取API接口数据 /// </summary> /// <returns></returns> private FlightRoundTrip GetApi() { try { FlightRoundTrip rtInfo = null; FlightParamInfo param = new FlightParamInfo(); param.Startairport = FromCityCode; param.Endairport = ToCityCode; param.Startdate = TripDate; //为往返的,加上返回时间 if (Convert.ToInt32(TripType) == 1) { param.Backdate = BackDate; } string jsonTxt = FlightAPI.GetFlight(param); FlightTotal ft = FlightAPI.DeserializeJsonToObject <FlightTotal>(jsonTxt); if (ft.result != null) { for (int i = 0; i < ft.result.Count; i++) { bool isContains = false; for (int j = 0; j < ft.result[i].ListInterFlightInfo.Count; j++) { if (DataGuid == ft.result[i].ListInterFlightInfo[j].dataId) { rtInfo = ft.result[i]; isContains = true; break; } } if (isContains) { break; } } } return(rtInfo); } catch (Exception) { return(null); } }
private static string apiUrl; //api地址 #region 2017年改版添加 /// <summary> /// 获取序列化后的航班信息 /// </summary> /// <param name="result"></param> /// <returns></returns> public static FlightTotal GetFlightTotal(string jsonText) { FlightTotal jp = (FlightTotal)JsonConvert.DeserializeObject(jsonText); return(jp); }
/// <summary> /// 异步获取数据 /// </summary> public void AsyncData() { FlightTotal tickets1 = null; if (Session[string.Format("TicketsSessionKey2_{0}_{1}_{2}_{3}_{4}", this.tripType, fromcityCode, this.tocityCode, Convert.ToDateTime(this.tripDate).ToString("yyyyMMdd"), Convert.ToDateTime(this.backDate).ToString("yyyyMMdd"))] == null) { //通知等待 //System.Threading.AutoResetEvent resetEvent = new System.Threading.AutoResetEvent(false); System.Threading.AutoResetEvent[] autoEvents = new System.Threading.AutoResetEvent[] { new System.Threading.AutoResetEvent(false), new System.Threading.AutoResetEvent(false) }; GjrinterFlightHandler d1 = new GjrinterFlightHandler(GetFlights); GFei_580Handler d2 = new GFei_580Handler(getFei580Ticekt); IAsyncResult iar1 = null; IAsyncResult iar2 = null; List <FlightRoundTrip> tickets2 = null; AsyncCallback back1 = delegate(IAsyncResult iar) { try { tickets1 = d1.EndInvoke(iar1); if (iar1 != null && iar1.IsCompleted) { autoEvents[0].Set(); } } catch (Exception) { autoEvents[0].Set(); } }; AsyncCallback back2 = delegate(IAsyncResult iar) { try { tickets2 = d2.EndInvoke(iar2); if (iar2 != null && iar2.IsCompleted) { autoEvents[1].Set(); } } catch (Exception) { autoEvents[1].Set(); } }; iar1 = d1.BeginInvoke(back1, null); iar2 = d2.BeginInvoke(back2, null); //等待通知 //if (resetEvent.WaitOne(12000, true)) if (System.Threading.AutoResetEvent.WaitAll(autoEvents, 10000)) { autoEvents[0].Close(); autoEvents[1].Close(); } //resetEvent.Close(); #region 无数据显示 //没数据 显示提示 if ((tickets1 == null || tickets1.result == null) && (tickets2 == null || tickets2.Count == 0)) //if ((tickets1 == null || (tickets1.result == null ? 0 : tickets1.result.Count) == 0)) { this.panHaveValue2.Visible = false; this.panNoValue.Visible = true; return; } else { this.panHaveValue2.Visible = true; this.panNoValue.Visible = false; } #endregion #region 整合数据 if (tickets1 != null) { if (tickets1.result != null) { foreach (FlightRoundTrip item in tickets2) { tickets1.result.Add(item); } } else { tickets1.result = tickets2; } } else { tickets1 = new FlightTotal(); tickets1.result = tickets2; } #endregion #region 排序 if (true) { if (tickets1.result != null) { airlineList.Clear(); //冒泡排序 for (int i = 0; i < tickets1.result.Count - 1; i++) { for (int j = tickets1.result.Count - 1; j > i; j--) { if (tickets1.result[j].ListInterFlightInfo[0].TicketPrice < tickets1.result[j - 1].ListInterFlightInfo[0].TicketPrice) { FlightRoundTrip finfo = tickets1.result[j]; tickets1.result[j] = tickets1.result[j - 1]; tickets1.result[j - 1] = finfo; } } #region 获取航空公司 if (tickets1.result[i].ListInterFlightInfo.Count > 0) { foreach (FlightInfo item in tickets1.result[i].ListInterFlightInfo) { if (!isInAirlineList(item.ListInterFlightDetails[0].AirCompanyCode)) { airlineList.Add(item.ListInterFlightDetails[0].AirCompanyCode); } } } #endregion } #region 保存查询结果中出现的航空公司 ArrayList arr = this.getAirLines(); ArrayList newArr = new ArrayList(); foreach (string item in airlineList) { foreach (kabe_Airline airlineInfo in arr) { if (item == airlineInfo.airlineCode) { newArr.Add(airlineInfo); } } } Session["TicketsSessionKey_Airlines"] = newArr; #endregion } } #endregion } else { tickets1 = (FlightTotal)Session[string.Format("TicketsSessionKey2_{0}_{1}_{2}_{3}_{4}", this.tripType, fromcityCode, this.tocityCode, Convert.ToDateTime(this.tripDate).ToString("yyyyMMdd"), Convert.ToDateTime(this.backDate).ToString("yyyyMMdd"))]; } this.BindData(tickets1); dvPageCount.InnerHtml = tickets1.result.Count.ToString(); }