反射+自定义属性拼接sql

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
 
    <add key="StrConn" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/Access/changqing.mdb;Persist Security Info=True"/>
 
  </appSettings>
</configuration>

 

 

 

 public class AuthorAttribute:Attribute
    {
        public string name;
        public string codeName;
        public string dataType;
        public string dataWidth;
        public string dataPrecision;
    }

    [AttributeUsageAttribute(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
    public class TableAttribute : Attribute
    {
        private string name;

       
        //保存表名的字段
        private string _tableName;

        public TableAttribute()
        {
        }

        public TableAttribute(string name, string tableName)
        {
            this.name = name;
            this._tableName = tableName;
        }

        /// <summary>
        /// 映射的表名(表的全名:模式名.表名)
        /// </summary>
        public string TableName
        {
            set
            {
                this._tableName = value;
            }
            get
            {
                return this._tableName;
            }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
    }

    public class DataClass
    {
        [Table("钻井基本数据","WEBSYSOLD_E001")]
        public class E001
        {

            #region  字段定义

            private string jh;       //井号
            private string dlwz;     //地理位置
            private string gzwz;     //构造位置
            private string sywz;      //水域位置
            private string dmhb;      //地面海拔
            private string jb;         //井别
            private string jx;          //井型
            private string zjfs;        //钻井方式
            private string jkzzbx;      //井口纵坐标X
            private string jkhzby;      //井口横坐标Y
            private string zymdc;       //主要目的层
            private string ktbl;        //勘探类别

            #endregion

            #region  属性定义
            [Author(name ="井号", codeName ="JH", dataType="C", dataWidth="16")]
            public string Jh
            {
                get { return jh; }
                set { jh = value; }
            }

            [Author(name = "地理位置", codeName = "DLWZ", dataType = "C", dataWidth = "50")]
            public string Dlwz
            {
                get { return dlwz; }
                set { dlwz = value; }
            }

            [Author(name = "构造位置", codeName = "GZWZ", dataType = "C", dataWidth = "50")]
            public string Gzwz
            {
                get { return gzwz; }
                set { gzwz = value; }
            }

            [Author(name = "水域位置", codeName = "SYWZ", dataType = "C", dataWidth = "40")]
            public string Sywz
            {
                get { return sywz; }
                set { sywz = value; }
            }

            [Author(name = "地面海拔", codeName = "DMHB", dataType = "N", dataWidth = "6",dataPrecision="2")]
            public string Dmhb
            {
                get { return dmhb; }
                set { dmhb = value; }
            }

            [Author(name = "井别", codeName = "JB", dataType = "C", dataWidth = "10")]
            public string Jb
            {
                get { return jb; }
                set { jb = value; }
            }

            [Author(name = "井型", codeName = "JX", dataType = "C", dataWidth = "10")]
            public string Jx
            {
                get { return jx; }
                set { jx = value; }
            }

            [Author(name = "钻井方式", codeName = "ZJFS", dataType = "C", dataWidth = "14")]
            public string Zjfs
            {
                get { return zjfs; }
                set { zjfs = value; }
            }

            [Author(name = "井口纵坐标X", codeName = "JKZZBX", dataType = "N", dataWidth = "10",dataPrecision="2")]
            public string Jkzzbx
            {
                get { return jkzzbx; }
                set { jkzzbx = value; }
            }

            [Author(name = "井口横坐标Y", codeName = "JKHZBY", dataType = "N", dataWidth = "11", dataPrecision = "2")]
            public string Jkhzby
            {
                get { return jkhzby; }
                set { jkhzby = value; }
            }

            [Author(name = "主要目的层", codeName = "ZYMDC", dataType = "C", dataWidth = "40")]
            public string Zymdc
            {
                get { return zymdc; }
                set { zymdc = value; }
            }

            [Author(name = "勘探类别", codeName = "KTLB", dataType = "C", dataWidth = "50")]
            public string Ktbl
            {
                get { return ktbl; }
                set { ktbl = value; }
            }
            #endregion
        }

        [Table("钻井完井基本数据","WEBSYSOLD_E002")]
        public class E002
        {
            #region  字段定义

            private string jh;      //井号
            private string zjsgdw;   //钻井施工单位
            private string kzrq;      //开钻日期
            private string wzrq;     //完钻日期
            private string wjrq;     //完井日期
            private string bxhb;     //补心海拔
            private string wzjs;     //完钻井深
            private string wzcw;     //完钻层位
            private string jj;       //井径
            private string ybj;      //油补距
            private string tbj;      //套补距
            private string rgjd;     //人工井底
            private string snsfsd;   //水泥上返深度
            private string jdwy;     //井底位移
            private string wyfw;      //位移方位
            private string gjzl;      //固井质量
            private string wjff;      //完井方法代码

            #endregion


            #region  属性定义

            [Author(name = "井号", codeName = "JH", dataType = "C", dataWidth = "16")]
            public string Jh
            {
                get { return jh; }
                set { jh = value; }
            }

            [Author(name = "钻井施工单位", codeName = "ZJSGDW", dataType = "C", dataWidth = "40")]
            public string Zjsgdw
            {
            get { return zjsgdw; }
            set { zjsgdw = value; }
            }

            [Author(name = "开钻日期", codeName = "KZRQ", dataType = "D")]
            public string Kzrq
            {
                get { return kzrq; }
                set { kzrq = value; }
            }

            [Author(name = "完钻日期", codeName = "WZRQ", dataType = "D")]
            public string Wzrq
            {
                get { return wzrq; }
                set { wzrq = value; }
            }

            [Author(name = "完井日期", codeName = "WJRQ", dataType = "D")]
            public string Wjrq
            {
                get { return wjrq; }
                set { wjrq = value; }
            }

            [Author(name = "补心海拔", codeName = "BXHB", dataType = "N", dataWidth = "7",dataPrecision="2")]
            public string Bxhb
            {
                get { return bxhb; }
                set { bxhb = value; }
            }

            [Author(name = "完钻井深", codeName = "WZJS", dataType = "N", dataWidth = "7", dataPrecision = "2")]
            public string Wzjs
            {
                get { return wzjs; }
                set { wzjs = value; }
            }

            [Author(name = "完钻层位", codeName = "WZCW", dataType = "C", dataWidth = "20")]
            public string Wzcw
            {
                get { return wzcw; }
                set { wzcw = value; }
            }

            [Author(name = "井径", codeName = "JJ", dataType = "N", dataWidth = "5", dataPrecision = "2")]
            public string Jj
            {
                get { return jj; }
                set { jj = value; }
            }

            [Author(name = "油补距", codeName = "YBJ", dataType = "N", dataWidth = "5", dataPrecision = "2")]
            public string Ybj
            {
                get { return ybj; }
                set { ybj = value; }
            }

            [Author(name = "套补距", codeName = "TBJ", dataType = "N", dataWidth = "5", dataPrecision = "2")]
            public string Tbj
            {
                get { return tbj; }
                set { tbj = value; }
            }


            [Author(name = "人工井底", codeName = "RGJD", dataType = "N", dataWidth = "7", dataPrecision = "2")]
            public string Rgjd
            {
                get { return rgjd; }
                set { rgjd = value; }
            }

            [Author(name = "水泥上返深度", codeName = "SNSFSD", dataType = "N", dataWidth = "7", dataPrecision = "2")]
            public string Snsfsd
            {
                get { return snsfsd; }
                set { snsfsd = value; }
            }

            [Author(name = "井底位移", codeName = "JDWY", dataType = "N", dataWidth = "7", dataPrecision = "2")]
            public string Jdwy
            {
                get { return jdwy; }
                set { jdwy = value; }
            }

            [Author(name = "位移方位", codeName = "WYFW", dataType = "N", dataWidth = "6", dataPrecision = "2")]
            public string Wyfw
            {
                get { return wyfw; }
                set { wyfw = value; }
            }

            [Author(name = "固井质量", codeName = "GJZL", dataType = "C", dataWidth = "8")]
            public string Gjzl
            {
                get { return gjzl; }
                set { gjzl = value; }
            }

            [Author(name = "完井方法代码", codeName = "WJFF", dataType = "C", dataWidth = "2")]
            public string Wjff
            {
                get { return wjff; }
                set { wjff = value; }
            }
            #endregion
        }


        [Table("套管程序数据","WEBSYSOLD_E004")]
        public class E004
        {
            #region

            private string jh;  //井号
            private string tgmc; //套管名称
            private string tgwj; //套管外径
            private string ldjfr; //联顶节方入
            private string cxdw;  //磁性定位
            private string fzqgs; //扶正器个数
            private string xrjs;  //下入井深
            private string tbj;   //套补距
            private string tgzc;  //套管总长
            private string zlhsd1; //阻流环深度11
            private string zlhsd2; //阻流环深度2
            private string zlhsd3; //阻流环深度3

            #endregion

            #region
            [Author(name = "井号", codeName = "JH", dataType = "C", dataWidth = "16")]
            public string Jh
            {
                get { return jh; }
                set { jh = value; }
            }

            [Author(name = "套管名称", codeName = "TGMC", dataType = "C", dataWidth = "12")]
            public string Tgmc
            {
                get { return tgmc; }
                set { tgmc = value; }
            }

       
            [Author(name = "套管外径", codeName = "TGWJ", dataType = "N", dataWidth = "5", dataPrecision = "2")]
            public string Tgwj
            {
                get { return tgwj; }
                set { tgwj = value; }
            }


            [Author(name = "联顶节方入", codeName = "LDJFR", dataType = "N", dataWidth = "5", dataPrecision = "2")]
            public string Ldjfr
            {
                get { return ldjfr; }
                set { ldjfr = value; }
            }

            [Author(name = "磁性定位", codeName = "CXDW", dataType = "N", dataWidth = "7", dataPrecision = "2")]
            public string Cxdw
            {
                get { return cxdw; }
                set { cxdw = value; }
            }

            [Author(name = "扶正器个数", codeName = "FZQGS", dataType = "N", dataWidth = "2")]
            public string Fzqgs
            {
                get { return fzqgs; }
                set { fzqgs = value; }
            }

            [Author(name = "下入井深", codeName = "XRJS", dataType = "N", dataWidth = "7", dataPrecision = "2")]
            public string Xrjs
            {
                get { return xrjs; }
                set { xrjs = value; }
            }

            [Author(name = "套补距", codeName = "TBJ", dataType = "N", dataWidth = "5", dataPrecision = "2")]
            public string Tbj
            {
                get { return tbj; }
                set { tbj = value; }
            }

            [Author(name = "套管总长", codeName = "TGZC", dataType = "N", dataWidth = "7", dataPrecision = "2")]
            public string Tgzc
            {
                get { return tgzc; }
                set { tgzc = value; }
            }

            [Author(name = "阻流环深度1", codeName = "ZLHSD1", dataType = "N", dataWidth = "7", dataPrecision = "2")]
            public string Zlhsd1
            {
                get { return zlhsd1; }
                set { zlhsd1 = value; }
            }

            [Author(name = "阻流环深度2", codeName = "ZLHSD2", dataType = "N", dataWidth = "7", dataPrecision = "2")]
            public string Zlhsd2
            {
                get { return zlhsd2; }
                set { zlhsd2 = value; }
            }

            [Author(name = "阻流环深度3", codeName = "ZLHSD3", dataType = "N", dataWidth = "7", dataPrecision = "2")]
            public string Zlhsd3
            {
                get { return zlhsd3; }
                set { zlhsd3 = value; }
            }

            #endregion
        }

      
    }

 

 

 


    public class TableInfo
    {
        private Type type;
        private string name;
        private string codeName;

        public string CodeName
        {
            get { return codeName; }
            set { codeName = value; }
        }

 

        public string Name
        {
            get { return name; }
            set { name = value; }
        }


        public Type Type
        {
            get { return type; }
            set { type = value; }
        }
    }

    /// <summary>
    /// 表信息类
    /// </summary>
    public class ReflectionData
    {
       
        private TableInfo tb_Info;
        private ArrayList tableInfos = new ArrayList();
        private ArrayList fieldInfos = new ArrayList();

        /// <summary>
        /// 表字段信息组
        /// </summary>
        public ArrayList FieldInfos
        {
            get { return fieldInfos; }
            set { fieldInfos = value; }
        }


        /// <summary>
        /// 表信息组
        /// </summary>
        public ArrayList TableInfos
        {
            get { return tableInfos; }
            set { tableInfos = value; }
        }

        /// <summary>
        /// 根据字符串反射类型集
        /// </summary>
        /// <param name="str"></param>
        public void GetTableNames(string str)
        {
            Assembly asm = Assembly.Load(str);
            Type[] type = asm.GetTypes();
            foreach (Type temp in type)
            {
                           
                TableAttribute[] attributes = (TableAttribute[])temp.GetCustomAttributes(typeof(TableAttribute), false);
                if (attributes.Length == 1)
                {
                    tb_Info = new TableInfo();
                    tb_Info.Type = temp;
                    tb_Info.Name = attributes[0].Name;
                    tb_Info.CodeName = attributes[0].TableName;
                    tableInfos.Add(tb_Info);
                }

            }
        }

        /// <summary>
        /// 根据类型得到属性自定义属性信息
        /// </summary>
        /// <param name="type"></param>
        public void GetFieldNames(Type type)
        {
            PropertyInfo[] myProperty = type.GetProperties();
         
            foreach (PropertyInfo property in myProperty)
            {
                AuthorAttribute[] p_Temp=( AuthorAttribute[])property.GetCustomAttributes(typeof( AuthorAttribute), false);
                if (p_Temp.Length == 1)
                {
                    fieldInfos.Add(p_Temp);
                }
            }
           
        }

 
    }

 

 

 

 

 public  interface IDataAccess
    {
       int SelectFullId(ref ArrayList list);
       int SelectInfo(ref ArrayList list, string id);
       int SelectInfo(ref ArrayList list, ArrayList m_list);
       int SelectFullInfo(ref ArrayList list);

    }

   public class OperateAccess : IDataAccess
   {
        #region 声明操作对象
       /// <summary>
       ///
       /// </summary>
       public ReflectionData RefData = new ReflectionData();

       /// <summary>
       /// 记录当前表名
       /// </summary>
       public string nowTable = null;
       
        /// <summary>
        /// 声明连接对象
        /// </summary>
        protected OleDbConnection oleConn=null;

        /// <summary>
        /// 命令对象
        /// </summary>
        protected OleDbCommand oleCmd=null;

        /// <summary>
        /// 适配器对象
        /// </summary>
        protected OleDbDataAdapter oleDataAdapter=null;

        /// <summary>
        /// 读取器对象
        /// </summary>
        protected OleDbDataReader oleDataReader = null;


        #endregion


        /// <summary>
        /// 打开数据库连接
        /// </summary>
        /// <param name="strCon">连接字符串</param>
        /// <returns>操作是否成功</returns>
        public int OpenConnection()
        {
            try
            {
                if (oleConn.State == ConnectionState.Closed)
                {
                
                    this.oleConn.Open();
                }
                return 0;
            }
            catch
            {
                return -1;
            }
        }
        /// <summary>
        /// 关闭数据库连接
        /// </summary>
        /// <returns>操作是否成功</returns>
        public int CloseConnection()
        {
            try
            {
                if (oleConn.State == ConnectionState.Open)
                {
                    oleConn.Close();
                }
                return 0;
            }
            catch
            {
                return -1;
            }

        }

        /// <summary>
        /// 数据库是否连接
        /// </summary>
        public bool IsDbopen
        {
            get
            {
                return oleConn.State == ConnectionState.Open ? true : false;
            }
        }

    

        #region 默认构造函数
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public OperateAccess()
        {

            oleConn = new OleDbConnection(ConfigurationSettings.AppSettings["StrConn"].ToString());
            oleCmd = new OleDbCommand();
        }
        #endregion


        #region IDataAccess 成员

        public int SelectFullId(ref ArrayList list)
        {
            if (nowTable != null)
            {
                StringBuilder sb = new StringBuilder();
                AuthorAttribute[] a_temp = (AuthorAttribute[])RefData.FieldInfos[0];
                sb.Append("select " + a_temp[0].codeName + " from " + nowTable);
                if (oleConn.State == ConnectionState.Closed)
                {
                    oleConn.Open();
                }
                oleCmd.Connection = oleConn;
                oleCmd.CommandType = CommandType.Text;
                oleCmd.CommandText = sb.ToString(); ;
                oleDataReader = oleCmd.ExecuteReader();
                while (oleDataReader.Read())
                {
                    object[] values = new object[oleDataReader.FieldCount];
                    oleDataReader.GetValues(values);
                    list.Add(values);

                }
                oleDataReader.Dispose();
                oleConn.Close();
                return 0;
            }
            else
            {
                MessageBox.Show("请选择数据表");
                return -1;
            }

        }

     

        public int SelectInfo(ref ArrayList list, string id)
        {
            if (nowTable != null)
            {
                StringBuilder sb = new StringBuilder();
               
                AuthorAttribute[] a_temp = (AuthorAttribute[])RefData.FieldInfos[0];
                sb.Append("select ");

                for (int i = 0; i < RefData.FieldInfos.Count; i++)
                {
                    if (RefData.FieldInfos[i] is AuthorAttribute[])
                    {
                      
                        AuthorAttribute[] temp = (AuthorAttribute[])RefData.FieldInfos[i];
                        sb.Append(temp[0].codeName);
                        if (i != RefData.FieldInfos.Count - 1)
                        {
                            sb.Append(",");
                        }
                    }
                  
                }
               
                sb.Append(" from " + nowTable);
                sb.Append(" where " + a_temp[0].codeName + "=" + "'"+id+"'");

                if (oleConn.State == ConnectionState.Closed)
                {
                    oleConn.Open();
                }
                oleCmd.Connection = oleConn;
                oleCmd.CommandType = CommandType.Text;
                oleCmd.CommandText = sb.ToString(); ;
                oleDataReader = oleCmd.ExecuteReader();
                while (oleDataReader.Read())
                {
                    object[] values = new object[oleDataReader.FieldCount];
                    oleDataReader.GetValues(values);
                    list.Add(values);

                }
                oleDataReader.Dispose();
                oleConn.Close();
                return 0;
            }
            else
            {
                MessageBox.Show("请选择数据表");
                return -1;
            }
        }

        public int SelectInfo(ref ArrayList list, ArrayList m_list)
        {
            if (nowTable != null)
            {
                StringBuilder sb = new StringBuilder();
                AuthorAttribute[] a_temp = (AuthorAttribute[])RefData.FieldInfos[0];
                foreach (object str in m_list)
                {
                    sb.Remove(0, sb.Length);
                    sb.Append("select ");

                    for (int i = 0; i < RefData.FieldInfos.Count; i++)
                    {
                        if (RefData.FieldInfos[i] is AuthorAttribute[])
                        {

                            AuthorAttribute[] temp = (AuthorAttribute[])RefData.FieldInfos[i];
                            sb.Append(temp[0].codeName);
                            if (i != RefData.FieldInfos.Count - 1)
                            {
                                sb.Append(",");
                            }
                        }

                    }
                    sb.Append(" from " + nowTable);
                    sb.Append(" where " + a_temp[0].codeName + "=" + "'" + str.ToString() + "'");
                    if (oleConn.State == ConnectionState.Closed)
                    {
                        oleConn.Open();
                    }
                    oleCmd.Connection = oleConn;
                    oleCmd.CommandType = CommandType.Text;
                    oleCmd.CommandText = sb.ToString(); ;
                    oleDataReader = oleCmd.ExecuteReader();
                    while (oleDataReader.Read())
                    {
                        object[] values = new object[oleDataReader.FieldCount];
                        oleDataReader.GetValues(values);
                        list.Add(values);

                    }
                    oleDataReader.Dispose();
                    oleConn.Close();
                }
              
              
                return 0;
            }
            else
            {
                MessageBox.Show("请选择数据表");
                return -1;
            }
        }

        public int SelectFullInfo(ref ArrayList list)
        {
            if (nowTable != null)
            {
                StringBuilder sb = new StringBuilder();
                AuthorAttribute[] a_temp = (AuthorAttribute[])RefData.FieldInfos[0];
                sb.Append("select ");

                for (int i = 0; i < RefData.FieldInfos.Count; i++)
                {
                    if (RefData.FieldInfos[i] is AuthorAttribute[])
                    {

                        AuthorAttribute[] temp = (AuthorAttribute[])RefData.FieldInfos[i];
                        sb.Append(temp[0].codeName);
                        if (i != RefData.FieldInfos.Count - 1)
                        {
                            sb.Append(",");
                        }
                    }

                }
                sb.Append(" from " + nowTable);
                if (oleConn.State == ConnectionState.Closed)
                {
                    oleConn.Open();
                }
                oleCmd.Connection = oleConn;
                oleCmd.CommandType = CommandType.Text;
                oleCmd.CommandText = sb.ToString(); ;
                oleDataReader = oleCmd.ExecuteReader();
                while (oleDataReader.Read())
                {
                    object[] values = new object[oleDataReader.FieldCount];
                    oleDataReader.GetValues(values);
                    list.Add(values);

                }
                oleDataReader.Dispose();
                oleConn.Close();
                return 0;
            }
            else
            {
                MessageBox.Show("请选择数据表");
                return -1;
            }

        }

        #endregion
   }

 

 

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace WindowsForms827
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

       private OperateAccess mypop = new OperateAccess();
       private ArrayList m_List = new ArrayList();
    

        private void Form1_Load(object sender, EventArgs e)
        {
           
            mypop.RefData.GetTableNames("WindowsForms827");

            foreach (object obj in mypop.RefData.TableInfos)
            {
                if (obj is TableInfo)
                {
                    TableInfo temp = (TableInfo)obj;
                    TreeNode node = new TreeNode(temp.Name);
                    node.Tag = temp;
                    this.treeView1.Nodes.Add(node);
                }
            }
           
        }

        /// <summary>
        /// 双击选择当前操作表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {


            if (e.Node.Tag is TableInfo)
            {

               TableInfo m_tableInfo = (TableInfo)e.Node.Tag;

                if (mypop.nowTable != "" && mypop.nowTable != m_tableInfo.CodeName)//判断当前表名与上一次表名是否相同
                {
                    //  this.textBox1.Text = m_tableInfo.Name;
                    mypop.RefData.FieldInfos.Clear();//清空
                    listView2.Items.Clear();     //清空
                    listView1.Columns.Clear();   //清空   防止数据叠加
                    mypop.nowTable = m_tableInfo.CodeName;//获取当前操作表
                    this.label1.Visible = true;
                    this.label1.Text = m_tableInfo.Name;
                    mypop.RefData.GetFieldNames(m_tableInfo.Type);  //得到当前表的字段信息  存在FieldInfos中
                    foreach (object obj in mypop.RefData.FieldInfos)
                    {
                        if (obj is AuthorAttribute[])
                        {

                            AuthorAttribute[] a_temp = (AuthorAttribute[])obj;
                            this.listView1.Columns.Add(a_temp[0].name, 80);
                        }
                    }
                    ListViewItem item;
                    this.listView1.Items.Clear();
                    m_List.Clear();
                    mypop.SelectFullId(ref  m_List);

                    if (m_List != null)
                    {
                        foreach (object obj in m_List)//循环填充数据
                        {
                            object[] objArray = (object[])obj;
                            item = new ListViewItem(objArray[0].ToString());
                            for (int i = 1; i < objArray.Length; i++)
                            {

                                item.SubItems.Add(objArray[i].ToString());

                            }
                            if (item != null)
                            {
                                listView2.Items.Add(item);
                                item = null;
                            }
                        }

                    }


                }
            }
            else
            {
                MessageBox.Show("请选择数据表");
            }
        }

        /// <summary>
        /// 查询选中得到井号信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
           
            ArrayList tempList = new ArrayList();
            if (mypop.nowTable != null)
            {
               
                for (int i = 0; i < listView2.Items.Count; i++)
                {
                    if (listView2.Items[i].Checked)
                    {
                        tempList.Add(listView2.Items[i].Text);
                    }
                }
                ListViewItem item;
                this.listView1.Items.Clear();
                m_List.Clear();
                mypop.SelectInfo(ref m_List, tempList);

                if (m_List != null)
                {
                    foreach (object obj in m_List)
                    {
                        object[] objArray = (object[])obj;
                        item = new ListViewItem(objArray[0].ToString());
                        for (int i = 1; i < objArray.Length; i++)
                        {

                            item.SubItems.Add(objArray[i].ToString());

                        }
                        if (item != null)
                        {
                            listView1.Items.Add(item);
                            item = null;
                        }
                    }

                }
          
 
            }
            else
            {
                MessageBox.Show("请选择数据表");
            }
           
        }

        /// <summary>
        /// 查询表全部信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {

            if (mypop.nowTable != null)
            {
                ListViewItem item;
                this.listView1.Items.Clear();
                m_List.Clear();
                mypop.SelectFullInfo(ref  m_List);

                if (m_List != null)
                {
                    foreach (object obj in m_List)
                    {
                        object[] objArray = (object[])obj;
                        item = new ListViewItem(objArray[0].ToString());
                        for (int i = 1; i < objArray.Length; i++)
                        {

                            item.SubItems.Add(objArray[i].ToString());

                        }
                        if (item != null)
                        {
                            listView1.Items.Add(item);
                            item = null;
                        }
                    }

                }
            }
            else
            {
                MessageBox.Show("请选择数据表");
            }
        }


        /// <summary>
        /// 双击事件(当双击listView2中的井号,查询双击的井号信息)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listView2_MouseDoubleClick(object sender, MouseEventArgs e)
        {
           
               
                ListViewItem item; 
                ListViewItem tempItem = this.listView2.GetItemAt(e.X, e.Y);
                if (tempItem != null)
                {
                   this.listView1.Items.Clear();
                    m_List.Clear();
                    mypop.SelectInfo(ref m_List, tempItem.Text);

                    if (m_List != null)
                    {
                        foreach (object obj in m_List)
                        {
                            object[] objArray = (object[])obj;
                            item = new ListViewItem(objArray[0].ToString());
                            for (int i = 1; i < objArray.Length; i++)
                            {

                                item.SubItems.Add(objArray[i].ToString());

                            }
                            if (item != null)
                            {
                                listView1.Items.Add(item);
                                item = null;
                            }
                        }

                    }
                }
           
         
        }

       
    }
}

 

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值