⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmselectdictitem.cs

📁 以构建的方式来实现对通用的查询统计
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Windows.Forms;

namespace dist.hb.EnvQueryStat.Pub
{
  public partial class frmSelectDictItem : Form
  {
    public bool IsOK;
    public frmSelectDictItem()
    {
      InitializeComponent();
      m_OleDbConn = null;
      IsOK = false;
      m_array = new ArrayList();
    }
    private OleDbConnection m_OleDbConn;//数据库链接
    public OleDbConnection OleDbConn
    {
      get { return m_OleDbConn; }
      set
      {
        if (value == null) return;
        if (value == m_OleDbConn) return;
        m_OleDbConn = value;
      }
    }
    private string m_strDict;
    public string DICT
    {
      get { return m_strDict; }
      set
      {
        m_strDict = value;
      }
    }//词典

    private void btnOK_Click(object sender, EventArgs e)
    {
      SaveSel();
      IsOK = true;
      this.Close();
    }

    private void btnCancel_Click(object sender, EventArgs e)
    {
      m_array.Clear();
      IsOK = false;
      this.Close();
    }

    private void frmSelectDictItem_Load(object sender, EventArgs e)
    {
      DataSet ds = new DataSet();
      System.Data.OleDb.OleDbDataAdapter Adapter = new System.Data.OleDb.OleDbDataAdapter(m_strDict, m_OleDbConn);
      checkedListBox1.Items.Clear();
      Adapter.Fill(ds, "DICT");
      DataTable dt = ds.Tables["DICT"];
      foreach (DataRow dr in dt.Rows)
	    {
        clsDictItem item = new clsDictItem();
		    item.strCode = dr["code"].ToString();
        item.strName = dr["name"].ToString();
        checkedListBox1.Items.Add(item);
	    }
    }

   //储存选择的对象
   public ArrayList m_array;
   void SaveSel()
   {
    m_array.Clear();
    for (int i = 0; i < checkedListBox1.Items.Count ; i++)
		{
		 if(!checkedListBox1.GetItemChecked(i)) continue;
     clsDictItem item = (clsDictItem)checkedListBox1.Items[i];
     m_array.Add(item);
		}
   }

    private void btnAllSelect_Click(object sender, EventArgs e)
    {
      for (int i = 0; i < checkedListBox1.Items.Count; i++)
      {
        checkedListBox1.SetItemChecked(i,true);
      }
    }

    private void btnCancelSel_Click(object sender, EventArgs e)
    {
      for (int i = 0; i < checkedListBox1.Items.Count; i++)
      {
        checkedListBox1.SetItemChecked(i, false);
      }
    }

    public void SaveSel(ListBox ListBox1)
    {
      if (ListBox1 == null) return;
      if (m_array == null) return;
      ListBox1.Items.Clear();
      for (int i = 0; i < m_array.Count; i++)
      {
        clsDictItem  DictItem = m_array[i] as clsDictItem;
        DictItem Item = new DictItem();
        Item.code = DictItem.strCode;
        Item.name = DictItem.strName;
        ListBox1.Items.Add(Item);
      }
    }

    public void SaveSel(ArrayList list)
    {
      if (list == null) return;
      list.Clear();
      for (int i = 0; i < m_array.Count; i++)
      {
        clsDictItem dictItem = (clsDictItem)m_array[i];
        DictItem Item = new DictItem();
        Item.code = dictItem.strCode;
        Item.name = dictItem.strName;
        list.Add(Item);
      }
    }

  }

  //



  class clsDictItem : Object
  {

    public string strCode;
    public string strName;
    public override string ToString()
    {
      return strName;
    }
  }


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -