예제 #1
0
        /// <summary>
        /// 刷新起售站预售时间提醒
        /// </summary>
        void LoadStartStationTip(TOBA.Query.Entity.QueryResult result)
        {
            if (!IsControlVisible)
            {
                return;
            }

            var cacheKey = $"{result.Date.DayOfYear}{QueryParam.FromStationCode}{QueryParam.ToStationCode}{DateTime.Now.Minute / 30}";

            if (!Configuration.QueryConfiguration.Current.EnableStartStationTip)
            {
                pSellTipContainer.Visible = false;
                btnEnableSellTip.Visible  = false;
                return;
            }

            if (cacheKey == _tipCacheKey)
            {
                return;
            }

            var list = new List <ListViewItem>();

            if (result.Date >= ParamData.GetMaxTicketDate(QueryParam.QueryStudentTicket))
            {
                foreach (var train in result.Where(s => s.StartStationSellInfo != null).GroupBy(s => s.StartStation.StationName))
                {
                    var item = new ListViewItem()
                    {
                        ImageIndex = 0
                    };
                    var trains = train.ToArray();
                    item.Tag = trains;

                    var info = trains[0].StartStationSellInfo;
                    item.Text = $"车次【{trains.Select(s => s.Code).JoinAsString("/")}】的始发站【{train.Key}】的起售时间为【{info.SellTime.ToShortTimeString()}】,{(info.IsInSell ? "已经起售" : info.IsEarly ? "时间早一些,可以提前关注" : "可以稍后关注")}";
                    if (info.IsInSell)
                    {
                        item.ForeColor = Color.Red;
                    }
                    else if (info.IsEarly)
                    {
                        item.ForeColor = Color.RoyalBlue;
                    }
                    else
                    {
                        item.ForeColor = Color.Green;
                    }

                    list.Add(item);
                }
            }
            //是否车次过少?
            if (result.Count <= 3)
            {
                list.Add(new ListViewItem("车次较少,建议更改查询条件。如果两站之间没有更多的车次,可试试中转查询。")
                {
                    ImageIndex = 0, ForeColor = Color.BlueViolet
                });
            }
            var feCount = result.Count(s => s.FromStation.IsFirst && s.ToStation.IsEnd);

            if (feCount < 3 && feCount < result.Count / 3)
            {
                list.Add(new ListViewItem("大多数车次为过路车。如果站不大容易导致车票难买,可考虑跨站购票。")
                {
                    ImageIndex = 0, ForeColor = Color.BlueViolet
                });
            }
            var notSellList = result.Where(s => s.BeginSellTime != null && !s.FromStation.IsFirst).ToArray();

            if (notSellList.Length > 0)
            {
                list.Add(new ListViewItem($"车次【{notSellList.Select(s => s.Code).JoinAsString("/")}】尚未起售,但不是始发站。建议留意对应车次之前几站以及始发站的起售时间,可以碰碰运气是否能拿到票。")
                {
                    ImageIndex = 0, ForeColor = Color.BlueViolet
                });
            }

            lvSellTip.Items.Clear();
            lvSellTip.Items.AddRange(list.ToArray());

            var hasTip = lvSellTip.Items.Count > 0;

            if (QueryParam.UiSetting.EnableSellTip)
            {
                pSellTipContainer.Visible = hasTip;
            }
            else
            {
                btnEnableSellTip.Visible = hasTip;
            }

            _tipCacheKey = cacheKey;
        }
 public QueryResultItem(QueryResult parent)
 {
     QueryResult = parent;
     Date        = parent.Query.CurrentDepartureDate;
 }