Exemple #1
0
        /// <summary>
        /// 更新牌組表單顯示
        /// </summary>
        /// <param name="reflashType">刷新類型</param>
        private void UpdateDeckView(ReflashType reflashType)
        {
            var source = DataHelper.Decks
                         .Where(x => x.Name.IndexOf(txtSearchName.Text, StringComparison.OrdinalIgnoreCase) >= 0)              //名稱
                         .Where(x => string.IsNullOrEmpty(cbSearchClass.Text) ? true : x.Class == cbSearchClass.Text)          //職業
                         .Where(x => string.IsNullOrEmpty(cbSearchFormat.Text) ? true : x.Format == cbSearchFormat.Text)       //模式
                         .Where(x => string.IsNullOrEmpty(cbSearchCategory.Text) ? true : x.Category == cbSearchCategory.Text) //分類
                         .Where(x => x.Note.IndexOf(txtSearchNote.Text, StringComparison.OrdinalIgnoreCase) >= 0)              //備註
                         .ToList();


            lbDeckCount.Text = $"牌組數量: {source.Count}";

            //紀錄當前位置
            var currentRow = dgvDeck.FirstDisplayedScrollingRowIndex;

            //刷新表單
            dgvDeck.DataSource = new BindingSource
            {
                DataSource = source
            };;

            if (dgvDeck.RowCount < 1)
            {
                return;
            }

            switch (reflashType)
            {
            case ReflashType.Top:
                dgvDeck.FirstDisplayedScrollingRowIndex = 0;
                break;

            case ReflashType.Keep:
                //設回此位置
                dgvDeck.FirstDisplayedScrollingRowIndex = currentRow > 0 && dgvDeck.RowCount > currentRow ? currentRow : 0;
                break;

            case ReflashType.Bottom:
                dgvDeck.FirstDisplayedScrollingRowIndex = dgvDeck.RowCount - 1;
                break;
            }
        }
Exemple #2
0
        /// <summary>
        /// 更新顯示
        /// </summary>
        /// <param name="reflashType">刷新類型</param>
        /// <param name="clearSort">清除排序</param>
        public void UpdateView(ReflashType reflashType, bool clearSort = false)
        {
            string selected;

            if (clearSort)
            {
                ClearSort(true);
            }

            //更新職業選框
            cbSearchClass.SelectedIndexChanged -= SearchChanged;
            selected = cbSearchClass.Text;
            cbSearchClass.Items.Clear();
            cbSearchClass.Items.Add("");
            cbSearchClass.Items.AddRange(DataHelper.Decks.Where(x => !string.IsNullOrEmpty(x.Class))
                                         .Select(x => x.Class).Distinct().OrderBy(x => x).Cast <object>().ToArray());
            cbSearchClass.Text = selected;
            cbSearchClass.SelectedIndexChanged += SearchChanged;

            //更新模式選框
            cbSearchFormat.SelectedIndexChanged -= SearchChanged;
            selected = cbSearchFormat.Text;
            cbSearchFormat.Items.Clear();
            cbSearchFormat.Items.Add("");
            cbSearchFormat.Items.AddRange(DataHelper.Decks.Where(x => !string.IsNullOrEmpty(x.Format))
                                          .Select(x => x.Format).Distinct().OrderBy(x => x).Cast <object>().ToArray());
            cbSearchFormat.Text = selected;
            cbSearchFormat.SelectedIndexChanged += SearchChanged;

            //更新分類選框
            cbSearchCategory.SelectedIndexChanged -= SearchChanged;
            selected = cbSearchCategory.Text;
            cbSearchCategory.Items.Clear();
            cbSearchCategory.Items.Add("");
            cbSearchCategory.Items.AddRange(DataHelper.Decks.Where(x => !string.IsNullOrEmpty(x.Category))
                                            .Select(x => x.Category).Distinct().OrderBy(x => x).Cast <object>().ToArray());
            cbSearchCategory.Text = selected;
            cbSearchCategory.SelectedIndexChanged += SearchChanged;

            //更新牌組表單顯示
            UpdateDeckView(reflashType);
        }