/// <summary> /// 全选 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CkAll_Click(object sender, EventArgs e) { int count = 0; for (int j = 0; j < CkListBox.Items.Count; j++) { // string itemText = CkListBox.GetItemText(j); string itemText = CkListBox.Items[j].ToString(); // 需要判断文本框里面有的值则过滤 // if (0 == j) // { // MessageBox.Show( itemText + "->" + filterTextBox.Text); // } if (acceptFilter(itemText)) { CkListBox.SetItemChecked(j, CkAll.Checked); count++; } else { } } // this.lblSelectRes.Text = string.Format(selectedTableDesc, CkListBox.CheckedItems.Count); this.lblSelectRes.Text = string.Format(selectedTableDesc, count); }
/// <summary> /// 反选 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CkReverse_Click(object sender, EventArgs e) { for (int j = 0; j < CkListBox.Items.Count; j++) { var ck = CkListBox.GetItemChecked(j); CkListBox.SetItemChecked(j, !ck); } CkAll.Checked = CkListBox.Items.Count == CkListBox.CheckedItems.Count; this.lblSelectRes.Text = string.Format(selectedTableDesc, CkListBox.CheckedItems.Count); }
/// <summary> /// 模糊搜索数据表名 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TxtSearchWords_TextChanged(object sender, EventArgs e) { string searchWords = TxtSearchWords.Text.Trim().ToLower(); var lstTableName = DBUtils.Instance?.Info?.TableNames ?? new List <string>(); this.lblSelectRes.Text = string.Format(selectedTableDesc, 0); if (!string.IsNullOrWhiteSpace(searchWords)) { var lstContains = new HashSet <string>(); var words = searchWords.Split(new string[] { ",", "," }, StringSplitOptions.RemoveEmptyEntries); foreach (var word in words) { foreach (var tabName in lstTableName) { if (tabName.ToLower().Contains(word.ToLower())) { lstContains.Add(tabName); } } } // TODO 清空重置 CkListBox.DataSource = null; CkListBox.Items.Clear(); var lstNotContains = lstTableName.Except(lstContains).ToList(); if (lstContains.Any()) { CkAll.Checked = false; // TODO 搜索到的表名 靠前显示 CkListBox.Items.AddRange(lstContains.ToArray()); CkListBox.Items.AddRange(lstNotContains.ToArray()); for (int j = 0; j < CkListBox.Items.Count; j++) { var item = CkListBox.Items[j].ToString(); // TODO 作为排除 参与导出的表名 并且默认不选中 if (lstContains.Contains(item)) { CkListBox.SetItemChecked(j, true); } else { CkListBox.SetItemChecked(j, false); } } this.lblSelectRes.Text = string.Format(selectedTableDesc, CkListBox.CheckedItems.Count); } } else { CkListBox.DataSource = DBUtils.Instance?.Info?.TableNames; CkAll.Checked = true; CkAll_Click(null, null); } if (CkListBox.Items.Count > 0) { //默认选择第一张表 CkListBox.SelectedIndex = 0; LabCurrTabName.Text = CkListBox.SelectedItems[0].ToString(); TxtCurrTabComment.Text = DBUtils.Instance?.Info?.TableComments[LabCurrTabName.Text]; } }