private void button12_Click(object sender, EventArgs e)
        {
            EnumGloabParas.EnumConnectionType connectionType = EnumGloabParas.EnumConnectionType.None;
            if (raExportMSSQL.Checked)
            {
                connectionType = EnumGloabParas.EnumConnectionType.ExportMSSQL;
            }
            else if (raExportMySql.Checked)
            {
                connectionType = EnumGloabParas.EnumConnectionType.ExportMySql;
            }
            else if (raExportAccess.Checked)
            {
                connectionType = EnumGloabParas.EnumConnectionType.ExportAccess;
            }
            else
            {
                MessageBoxHelper.ShowError("请设置数据库类型!");
                return;
            }
            frmDataConfig frmData = new frmDataConfig(connectionType);

            frmData.e_OnReturnDataSource += new NETSpider.Controls.OnReturnDataSource(frmData_e_OnReturnDataSource);
            frmData.ShowDialog();
        }
        void frmData_e_OnReturnDataSource(EnumGloabParas.EnumConnectionType connectionType, string ConnectionString)
        {
            lbConnectionString.DataViewValue = ConnectionString;
            cbPubDataTable.Items.Clear();
            List <string> items = ConectionTables.GetProcedures(connectionType, ConnectionString);

            foreach (string item in items)
            {
                cbPubDataTable.Items.Add(item);
            }
            if (cbPubDataTable.Items.Count > 0)
            {
                cbPubDataTable.SelectedIndex = 0;
            }
        }
Exemple #3
0
        public frmDataConfig(EnumGloabParas.EnumConnectionType _connectionType)
        {
            InitializeComponent();
            this.connectionType = _connectionType;
            switch (_connectionType)
            {
            case EnumGloabParas.EnumConnectionType.ExportMSSQL:
            default:
                NETSpider.Controls.MSPanel msPanel1 = new NETSpider.Controls.MSPanel();
                msPanel1.Location = new System.Drawing.Point(3, 5);
                msPanel1.Name     = "msPanel1";
                msPanel1.Size     = new System.Drawing.Size(365, 134);
                msPanel1.TabIndex = 43;
                conPanel          = msPanel1;
                this.Controls.Add(msPanel1);
                break;

            case EnumGloabParas.EnumConnectionType.ExportMySql:
                NETSpider.Controls.MySqlPanel myPanel1 = new NETSpider.Controls.MySqlPanel();
                myPanel1.Location = new System.Drawing.Point(3, 5);
                myPanel1.Name     = "myPanel1";
                myPanel1.Size     = new System.Drawing.Size(365, 134);
                myPanel1.TabIndex = 43;
                conPanel          = myPanel1;
                this.Controls.Add(myPanel1);
                break;

            case EnumGloabParas.EnumConnectionType.ExportAccess:
                NETSpider.Controls.AccessPanel accPanel1 = new NETSpider.Controls.AccessPanel();
                accPanel1.Location = new System.Drawing.Point(3, 5);
                accPanel1.Name     = "accPanel1";
                accPanel1.Size     = new System.Drawing.Size(365, 134);
                accPanel1.TabIndex = 43;
                conPanel           = accPanel1;
                this.Controls.Add(accPanel1);
                break;
            }
        }
        public static List <string> GetProcedures(EnumGloabParas.EnumConnectionType connectionType, string sql)
        {
            List <string> items = new List <string>();
            DbConnection  conn  = null;
            DataTable     tb    = null;

            try
            {
                switch (connectionType)
                {
                case EnumGloabParas.EnumConnectionType.ExportMSSQL:
                    conn = new SqlConnection(sql);
                    break;

                case EnumGloabParas.EnumConnectionType.ExportMySql:
                    conn = new MySqlConnection(sql);
                    break;

                case EnumGloabParas.EnumConnectionType.ExportAccess:
                    conn = new OleDbConnection(sql);
                    break;

                default:
                    return(items);
                }
                conn.Open();
                if (connectionType == EnumGloabParas.EnumConnectionType.ExportMSSQL || connectionType == EnumGloabParas.EnumConnectionType.ExportMySql)
                {
                    tb = conn.GetSchema("Procedures");
                    //DataView dv = tb.DefaultView;
                    //dv.Sort = "TABLE_NAME Asc";
                    //DataTable dt2 = dv.ToTable();
                    foreach (DataRow r in tb.Rows)
                    {
                        switch (connectionType)
                        {
                        case EnumGloabParas.EnumConnectionType.ExportMSSQL:
                            items.Add(r[5].ToString());
                            break;

                        case EnumGloabParas.EnumConnectionType.ExportAccess:
                            items.Add(r[5].ToString());
                            break;
                        }
                    }
                }
                else if (connectionType == EnumGloabParas.EnumConnectionType.ExportAccess)
                {
                    string[] Restrictions = new string[4];
                    Restrictions[3] = "VIEW";
                    tb = conn.GetSchema("Tables", Restrictions);
                    foreach (DataRow r in tb.Rows)
                    {
                        items.Add(r[2].ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                WinFormLib.Core.MessageBoxHelper.ShowError(ex.Message);
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }

            return(items);
        }
        public static List <string> GetTables(EnumGloabParas.EnumConnectionType connectionType, string sql)
        {
            List <string> items = new List <string>();
            DbConnection  conn  = null;
            DataTable     tb    = null;

            try
            {
                switch (connectionType)
                {
                case EnumGloabParas.EnumConnectionType.ExportMSSQL:
                    conn = new SqlConnection(sql);
                    break;

                case EnumGloabParas.EnumConnectionType.ExportMySql:
                    conn = new MySqlConnection(sql);
                    break;

                case EnumGloabParas.EnumConnectionType.ExportAccess:
                    conn = new OleDbConnection(sql);
                    break;

                default:
                    return(items);
                }
                conn.Open();
                tb = conn.GetSchema("Tables");
                DataView dv = tb.DefaultView;
                dv.Sort = "TABLE_NAME Asc";
                DataTable dt2 = dv.ToTable();
                foreach (DataRow r in dt2.Rows)
                {
                    if (connectionType == EnumGloabParas.EnumConnectionType.ExportAccess)
                    {
                        if (r[3].ToString() != "TABLE")
                        {
                            continue;
                        }
                    }
                    if (connectionType == EnumGloabParas.EnumConnectionType.ExportMSSQL)
                    {
                        if (r[3].ToString() != "BASE TABLE")
                        {
                            continue;
                        }
                    }
                    items.Add(r[2].ToString());
                }
            }
            catch (Exception ex)
            {
                WinFormLib.Core.MessageBoxHelper.ShowError(ex.Message);
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }

            return(items);
        }