Esempio n. 1
0
        void HandleSession(Session session)
        {
            session.AddPropertyChangedEventHandler(_ => _.FaceCheckStatus,
                                                   (_1, _2) =>
            {
                var s1 = _1 as Session;
                if (s1.FaceCheckStatus == false)
                {
                    var msg = $"账号【{s1.UserName}】没有通过12306人脸认证哦,请尽快通过12306官方APP完成认证,否则部分功能无法使用唷。";
                    this.ShowWarningToast(msg);
                    ni.ShowBalloonTip(5000, "人脸验证提醒", msg, ToolTipIcon.Warning);
                }
            });
            var hip = session.GetService <IHbInfoProvider>();

            hip.TrainHbAvailable += this.SafeInvoke(new EventHandler <TrainHbAvailableEventArgs>((s, e) =>
            {
                var msg = $"车次 {e.ResultItem.Code} 的 【{ParamData.GetSeatTypeName(e.TicketData.Code)}】候补状态已变更为可候补({e.CacheItem.Info}),请留意哦";
                this.ShowInfoToastMini(msg);
                ni.ShowBalloonTip(5000, "可候补提示", msg, ToolTipIcon.Info);
            }));
        }
Esempio n. 2
0
        void InitUi()
        {
            SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
            SuspendLayout();
            BeginUpdate();

            AllowAutoToolTips = true;
            CacheImages       = true;
            DoubleBuffered    = true;
            GridLines         = (BetterListViewGridLines)QueryViewConfiguration.Instance.QueryResultListGridLine;
            SmoothScroll      = true;

            Columns.AddRange(new[] {
                new BetterListViewColumnHeader("")
                {
                    Text = "车次", Width = 120, Tag = "TC", AlignHorizontal = TextAlignmentHorizontal.Center
                },
                new BetterListViewColumnHeader("")
                {
                    Text = "发站/时间", Width = 80, Tag = "TS", AlignHorizontal = TextAlignmentHorizontal.Center
                },
                new BetterListViewColumnHeader("")
                {
                    Text = "到站/时间", Width = 80, Tag = "TR", AlignHorizontal = TextAlignmentHorizontal.Center
                },
                new BetterListViewColumnHeader("")
                {
                    Text = "天数/历时", Width = 70, Tag = "TE", AlignHorizontal = TextAlignmentHorizontal.Center
                }
            });
            Columns.AddRange(_viewConfiguration.SeatOrder.Select(s => new BetterListViewColumnHeader("")
            {
                Text = ParamData.SeatType[s], Width = ParamData.SeatType[s].Length > 3 ? 65 : 53, Tag = "S" + s, AlignHorizontal = TextAlignmentHorizontal.Center
            }).ToArray());
            Columns.Add(new BetterListViewColumnHeader("")
            {
                Text = "备注", Width = 120, AlignHorizontal = TextAlignmentHorizontal.Center
            });
            Groups.AddRange(new[]
            {
                _valid,
                _noneedticket,
                _notiket,
                _ignored,
                _underControl
            });
            _hourSellListGroup         = new Dictionary <string, BetterListViewGroup>();
            ShowGroups                 = tsUseGroup.Checked = _viewConfiguration.ShowGroups;
            tsUseGroup.CheckedChanged += (s, e) =>
            {
                _viewConfiguration.ShowGroups = tsUseGroup.Checked;
                ShowGroups = tsUseGroup.Checked;
                if (ShowGroups)
                {
                    var items = Items.Cast <QueryResultListViewItem>().ToArray();
                    Items.Clear();
                    items.ForEach(AssignItemGroup);
                    Items.AddRange(items);
                }
            };
            RefreshColumnVisibility();

            //图标状态
            if (_viewConfiguration.UseStatusIcon)
            {
                tsIconTypeS.Checked = true;
            }
            else
            {
                tsIconTypeT.Checked = true;
            }
            tsIconTypeT.Click += (s, e) =>
            {
                if (tsIconTypeT.Checked)
                {
                    return;
                }

                tsIconTypeT.Checked = true;
                tsIconTypeS.Checked = false;
                _viewConfiguration.UseStatusIcon = false;
                RefreshItemIcon();
            };
            tsIconTypeS.Click += (s, e) =>
            {
                if (tsIconTypeS.Checked)
                {
                    return;
                }

                tsIconTypeS.Checked = true;
                tsIconTypeT.Checked = false;
                _viewConfiguration.UseStatusIcon = true;
                RefreshItemIcon();
            };
            SortedColumnsRowsHighlight = BetterListViewSortedColumnsRowsHighlight.ShowAlways;
            ColorSortedColumn          = Color.FromArgb(255, 245, 245, 245);
            MultiSelect = false;
            AutoSizeItemsInDetailsView = true;
            ctxResult.Opening         += (s, e) =>
            {
                var item = GetSubItemAt(PointToClient(MousePosition));
                var row  = (QueryResultListViewItem)item?.Item;

                if (row == null)
                {
                    tsmiAddToSubmit.Tag     = null;
                    tsmiAddToSubmit.Enabled = false;
                    tsmiAddToSubmit.Text    = "添加所选车次到预定列表...";
                }
                else
                {
                    tsmiAddToSubmit.Enabled = true;

                    var ticketItem = item as TicketCellSubItem;
                    if (ticketItem == null || row.ResultItem.TicketCount.GetTicketData(ticketItem.Code) == null)
                    {
                        tsmiAddToSubmit.Text = $"添加车次 [{row.ResultItem.Code}] 到预定列表";
                        tsmiAddToSubmit.Tag  = Tuple.Create(row.ResultItem, (char?)null);
                    }
                    else
                    {
                        tsmiAddToSubmit.Text = $"添加车次 [{row.ResultItem.Code}] 的 [{ParamData.GetSeatTypeName(ticketItem.Code)}] 到预定列表";
                        tsmiAddToSubmit.Tag  = Tuple.Create(row.ResultItem, (char?)ticketItem.Code);
                    }
                }

                if (DisableContextMenu)
                {
                    e.Cancel = true;
                }
            };
            //添加到预定列表
            tsmiAddToSubmit.Click += (sender, args) =>
            {
                var(train, code) = (Tuple <QueryResultItem, char?>)tsmiAddToSubmit.Tag;

                QueryParam.AutoPreSubmitConfig.AddTrainCode(train.Code);
                if (code.HasValue)
                {
                    QueryParam.AutoPreSubmitConfig.AddSeat(code.Value);
                }
            };

            //排序
            InitSortInfo();

            //拖放支持
            InitDragDrop();

            //停靠站提示
            InitTrainStopPrompt();

            EndUpdate();
            ResumeLayout();

            AppContext.MainForm.IsWindowVisibleChanged += DetectReloadData;
            VisibleChanged += DetectReloadData;
        }
        ButtonX CreateButton(BackupCartItem item)
        {
            string GetText() => $"<div><b><font color=\"#ED1C24\">{item.Train.QueryResult.Date:MM-dd}</font> <font color=\"#BA1419\">{item.Train.Code}</font> <font color=\"#8066A0\">{ParamData.GetSeatTypeName(item.Seat)}</font> <font color=\"#4BACC6\">{item.Train.FromStation.StationName}-{item.Train.ToStation.StationName}</font></b></div><div><font color=\"{_rateColors[item.SuccessLevel]}\" size =\"-1\">{item.SuccessRateInfoMessage.DefaultForEmpty("候补人数查询中...")}</font></div>";

            var btn = new ButtonX()
            {
                EnableMarkup = true,
                Text         = GetText(),
                Tag          = item,
                ColorTable   = eButtonColor.Flat
            };

            btn.CreateControl();
            btn.Size = btn.PreferredSize;

            item.SuccessRateChanged += (_1, _2) =>
            {
                btn.Text = GetText();
            };

            btn.Click += (_1, _2) => Session.BackupOrderCart.Items.Remove(item);

            if (item.SuccessLevel == 0)
            {
                Session.GetService <IBackupOrderService>().GetSuccessRateAsync(item);
            }

            return(btn);
        }
        void RefreshTrains()
        {
            var items = _cart.Items;

            if (items.Count == 0)
            {
                Close();
                return;
            }

            tList.BeginUpdate();
            tList.SuspendLayout();

            var lvItems    = tList.Items.Cast <ListViewItem>().ToArray();
            var lvItemTags = lvItems.Select(s => s.Tag as BackupCartItem).MapToHashSet();

            //删除没有的
            lvItems.Where(s => !items.Contains(s.Tag as BackupCartItem)).ToArray().ForEach(tList.Items.Remove);

            //插入没有的
            items.Except(lvItemTags).ForEach(s =>
            {
                var lvi            = new ListViewItem(s.Train.QueryResult.Date.ToShortDateString());
                var(days, strinfo) = s.Train.ElapsedTimeInfo;

                lvi.SubItems.AddRange(new[]
                {
                    s.Train.FromStation.StationName,
                    s.Train.ToStation.StationName,
                    s.Train.Code,
                    ParamData.GetSeatTypeName(s.Seat),
                    s.Train.FromStation.DepartureTime.Value.ToShortTimeString(),
                    s.Train.ToStation.ArriveTime.Value.ToShortTimeString(),
                    strinfo + (days > 0 ? $" (+{days + 1})" : "")
                });

                tList.Items.Add(lvi);
            });

            tList.ResumeLayout(true);
            tList.EndUpdate();

            //候选车次
            var allSeats      = items.Select(s => s.Seat).ToArray().Distinct();
            var allSeatChecks = allSeats.Select(s =>
            {
                var chk = new CheckBox()
                {
                    Tag      = s,
                    Text     = ParamData.GetSeatTypeName(s),
                    AutoSize = true
                };

                return((Control)chk);
            }).
                                ToArray();

            flpLkList.Controls.Clear();
            flpLkList.Controls.AddRange(allSeatChecks);
            lnkLkSelAll.Click  += (_1, _2) => { flpLkList.Controls.OfType <CheckBox>().ForEach(s => s.Checked = true); };
            lnkLkSelNone.Click += (_1, _2) => { flpLkList.Controls.OfType <CheckBox>().ForEach(s => s.Checked = false); };

            //兑换截止时间
            //var endTime = _cart.Items.Select(s => s.Train.FromStation.DepartureTime.Value).Min();
            //endTime = endTime.Date.AddDays(endTime.Hour <= 6 ? -2 : -1).AddHours(19);
            //backupEndDate.MaxDate = endTime.Date;
            //backupEndDate.MinDate = DateTime.Now;
            //backupEndDate.Value = endTime.Date;
            //backupEndTime.MinDate = DateTime.Now;
            //backupEndTime.MaxDate = endTime;
            //backupEndTime.Value = endTime;
            backupEndDate.MinDate = _cart.HbStartTime;
            backupEndDate.MaxDate = _cart.HbEndTime;
            backupEndDate.Value   = _cart.HbEndTime;
        }