예제 #1
0
        /// <summary>
        /// 初始化界面信息
        /// </summary>
        void InitUiEvents()
        {
            var p = QueryParam;

            //始发站
            pFrom.DataBindings.Add(nameof(TrainStation.Code), p, nameof(QueryParam.FromStationCode), false, DataSourceUpdateMode.OnPropertyChanged);
            pFrom.DataBindings.Add(nameof(TrainStation.Text), p, nameof(QueryParam.FromStationName), false, DataSourceUpdateMode.OnPropertyChanged);
            //到达站
            pTo.DataBindings.Add(nameof(TrainStation.Code), p, nameof(QueryParam.ToStationCode), false, DataSourceUpdateMode.OnPropertyChanged);
            pTo.DataBindings.Add(nameof(TrainStation.Text), p, nameof(QueryParam.ToStationName), false, DataSourceUpdateMode.OnPropertyChanged);

            //学生票?
            pStu.DataBindings.Add("Checked", p, nameof(QueryParam.QueryStudentTicket), false, DataSourceUpdateMode.OnPropertyChanged);
            dep.AddDataBinding(p, s => s.StudentTicket, s => s.QueryStudentTicket);

            //日期
            if (p.DepartureDate < DateTime.Now.Date || p.DepartureDate > dep.MaxDate)
            {
                p.DepartureDate = DateTime.Now.Date;
            }
            dep.DataBindings.Add(nameof(DateComboBox.Date), p, nameof(QueryParam.DepartureDate), false, DataSourceUpdateMode.OnPropertyChanged);
            pbPrev.Click += (s, e) =>
            {
                p.DepartureDate = p.DepartureDate.AddDays(-1);
                p.OnRequireSave();
                p.OnRequestQuery(true);
            };
            pbNext.Click += (s, e) =>
            {
                p.DepartureDate = p.DepartureDate.AddDays(1);
                p.OnRequireSave();
                p.OnRequestQuery(true);
            };


            //发车时间
            pDtFrom.DataBindings.Add("SelectedIndex", p, "DepartureTimeFrom", false, DataSourceUpdateMode.OnPropertyChanged);
            pDtTo.DataBindings.Add("SelectedIndex", p, "DepartureTimeTo", false, DataSourceUpdateMode.OnPropertyChanged);
            pAtFrom.DataBindings.Add("SelectedIndex", p, "ArriveTimeFrom", false, DataSourceUpdateMode.OnPropertyChanged);
            pAtTo.DataBindings.Add("SelectedIndex", p, "ArriveTimeTo", false, DataSourceUpdateMode.OnPropertyChanged);
            //四个显示过滤
            chkHideFromNotSame.DataBindings.Add("Checked", p, "HideFromNotSame", false, DataSourceUpdateMode.OnPropertyChanged);
            chkHideNoTicket.DataBindings.Add("Checked", p, "HideNoTicket", false, DataSourceUpdateMode.OnPropertyChanged);
            chkHideNoValid.DataBindings.Add("Checked", p, "HideNoNeedTicket", false, DataSourceUpdateMode.OnPropertyChanged);
            chkHideToNotSame.DataBindings.Add("Checked", p, "HideToNotSame", false, DataSourceUpdateMode.OnPropertyChanged);

            //自动刷新
            pAutoRefresh.DataBindings.Add("Checked", p, "AutoRefresh", false, DataSourceUpdateMode.OnPropertyChanged);

            //。。。席别
            var seatChecks = pSeatType.Controls.OfType <CheckBox>().ToArray();

            lock (p.SelectedSeatClass)
            {
                if (p.SelectedSeatClass.Count == 0)
                {
                    //默认全选

                    seatChecks.ForEach(s => { s.Checked = true; p.SelectedSeatClass.Add(((string)s.Tag)[0]); p.OnSelectedSeatClassChanged(); });
                }
                else
                {
                    seatChecks.ForEach(s => { s.Checked = p.SelectedSeatClass.Contains(((string)s.Tag)[0]); });
                }
            }
            bool suspendEvent = false;

            seatChecks.ForEach(s =>
            {
                lock (p.SelectedSeatClass)
                {
                    s.CheckedChanged += (x, y) =>
                    {
                        var ck   = x as CheckBox;
                        var code = (ck.Tag as string)[0];
                        if (ck.Checked)
                        {
                            p.SelectedSeatClass.Add(code);
                        }
                        else
                        {
                            p.SelectedSeatClass.Remove(code);
                        }

                        if (!suspendEvent)
                        {
                            p.OnSelectedSeatClassChanged();
                            QueryParam.OnRequireSave();
                        }
                    };
                }
            });
            p.SelectedSeatClass.Added += (s, e) =>
            {
                var code  = e.Item;
                var check = seatChecks.FirstOrDefault(_ => (_.Tag as string)[0] == code);
                if (check?.Checked == false)
                {
                    check.Checked = true;
                }
            };
            p.SelectedSeatClass.Removed += (s, e) =>
            {
                var code  = e.Item;
                var check = seatChecks.FirstOrDefault(_ => (_.Tag as string)[0] == code);
                if (check?.Checked == true)
                {
                    check.Checked = false;
                }
            };
            //全选?
            lnkAllSeatType.Click += (s, e) =>
            {
                suspendEvent = true;
                var check = seatChecks.Any(x => !x.Checked);
                seatChecks.ForEach(x => x.Checked = check);
                suspendEvent = false;
                p.OnSelectedSeatClassChanged();
                QueryParam.OnRequireSave();
            };

            //。。。车型
            var tcChecks = pTrainType.Controls.OfType <CheckBox>().ToArray();

            if (p.SelectedTrainClass.Count == 0)
            {
                //默认全选
                tcChecks.ForEach(s => { s.Checked = true; p.SelectedTrainClass.Add((s.Tag as string)[0]); });
            }
            else
            {
                tcChecks.ForEach(s => { s.Checked = p.SelectedTrainClass.Contains((s.Tag as string)[0]); });
            }
            tcChecks.ForEach(s =>
            {
                s.CheckedChanged += (x, y) =>
                {
                    var ck   = x as CheckBox;
                    var code = (ck.Tag as string)[0];
                    lock (p.SelectedTrainClass)
                    {
                        if (ck.Checked)
                        {
                            p.SelectedTrainClass.Add(code);
                        }
                        else
                        {
                            p.SelectedTrainClass.Remove(code);
                        }
                    }

                    if (!suspendEvent)
                    {
                        p.OnSelecteTrainClassChanged();
                        QueryParam.OnRequireSave();
                    }
                };
            });
            p.SelectedTrainClass.Added += (s, e) =>
            {
                var code  = e.Item;
                var check = tcChecks.FirstOrDefault(_ => (_.Tag as string)[0] == code);
                if (check?.Checked == false)
                {
                    check.Checked = true;
                }
            };
            p.SelectedTrainClass.Removed += (s, e) =>
            {
                var code  = e.Item;
                var check = tcChecks.FirstOrDefault(_ => (_.Tag as string)[0] == code);
                if (check?.Checked == true)
                {
                    check.Checked = false;
                }
            };
            //全选?
            lnkAllTrainType.Click += (s, e) =>
            {
                suspendEvent = true;
                var check = tcChecks.Any(x => !x.Checked);
                tcChecks.ForEach(x => x.Checked = check);
                suspendEvent = false;
                p.OnSelecteTrainClassChanged();
                QueryParam.OnRequireSave();
            };

            //过路类型
            pPassType.SelectedIndex         = QueryParam.PassType == null ? 0 : QueryParam.PassType.Value;
            pPassType.SelectedIndexChanged += (s, e) =>
            {
                QueryParam.PassType = pPassType.SelectedIndex == 0 ? (int?)null : pPassType.SelectedIndex;
                QueryParam.OnRequireSave();
            };

            //交换出发地和到达地
            btnExchange.Click += (s, e) =>
            {
                var code = pFrom.Code;
                var name = pFrom.Text;
                if (code.IsNullOrEmpty() || name.IsNullOrEmpty() || pTo.Code.IsNullOrEmpty() || pTo.Text.IsNullOrEmpty())
                {
                    return;
                }
                pFrom.Code = pTo.Code;
                pFrom.Text = pTo.Text;
                pTo.Code   = code;
                pTo.Text   = name;
                QueryParam.OnRequireSave();
            };

            //请求查询
            btnQuery.Click += (s, e) =>
            {
                QueryParam.QueryCount = 0;
                QueryParam.OnRequireSave();
                if (_sleepTimer.Enabled)
                {
                    QueryParam.OnRequestStop();
                }

                else
                {
                    QueryParam.OnRequestQuery(true);
                }
            };

            //改签
            if (p.Resign)
            {
                pFrom.Enabled = false;
                pTo.Enabled   = p.ResignChangeTs;
                //pDate.Enabled = false;
                btnExchange.Enabled = false;
                pStu.Enabled        = false;
            }

            //请求查询
            p.RequestQuery += (s, e) =>
            {
                if (!IsInAutoRefreshCountDown)
                {
                    Session.UserProfile.Configuration.IncreaseStationQueryFromCount(QueryParam.FromStationCode);
                    Session.UserProfile.Configuration.IncreaseStationQueryToCount(QueryParam.ToStationCode);
                }
            };
            p.RequestStop += (s, e) =>
            {
                StopSleep();
            };
            p.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "DepartureDate" || e.PropertyName == "QueryStudentTicket")
                {
                    CheckNavigateToolbarStatus();
                }
                if (e.PropertyName == nameof(QueryParam.EnableAutoPreSubmit))
                {
                    ResetButtonText();
                }
            };
            CheckNavigateToolbarStatus();
            ResetButtonText();


            if (!Session.IsLogined)
            {
                pAutoRefresh.Checked = false;
                pAutoRefresh.Enabled = false;
                pAutoRefresh.Hide();
            }
        }