/// <summary> /// 連線按鈕事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Connect_Click(object sender, EventArgs e) { txtConnError.Text = ""; //LEVEL 1 CHECK SELECT if (DbSelect.SelectedItem == null || String.IsNullOrEmpty(DbSelect.SelectedItem.ToString())) { MessageBox.Show("您尚未選擇資料庫型態", "Error"); } else { param.DBType = DbSelect.SelectedItem.ToString(); //LEVEL 2 CHECK DB TEST if (String.IsNullOrEmpty(ConnStr.Text)) { MessageBox.Show("您沒有輸入資料庫連線字串", "Error"); } else { param.ConnectionString = ConnStr.Text; //Using DI INJECT INTO Dao.Dao testconn = new Dao.Dao(); Type type = Type.GetType("ModelHalper.Dao.Dao" + param.DBType); testconn.SQL = (IDao)Activator.CreateInstance(type); //IF CONNECTION ERROR if (!testconn.TestSql(param)) { txtConnError.Text = "您的連線字串有誤"; } else { Connect.Enabled = false; DbSelect.Enabled = false; ConnStr.Enabled = false; ConnName.Enabled = false; SettingSelect.Enabled = false; SaveConn.Enabled = false; DisConnect.Enabled = true; tablesearch.Enabled = true; CrtClass.Enabled = true; OutClass.Enabled = true; txtConnError.Text = "連線成功"; var tables = testconn.GetTable(param); foreach (TableModel table in tables) { TableSelect.Items.Add(table.Owner + "-" + table.Table_Name); } } } } }
/// <summary> /// 搜尋表單按鈕事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tablesearch_Click(object sender, EventArgs e) { //clear all TableSelect.Items.Clear(); param.Table_Name = TableName.Text; param.Owner = Owner.Text; Dao.Dao testconn = new Dao.Dao(); Type type = Type.GetType("ModelHelper.Dao.Dao" + param.DBType); testconn.SQL = (IDao)Activator.CreateInstance(type); var tables = testconn.GetTable(param); foreach (TableModel table in tables) { TableSelect.Items.Add(table.Owner + "-" + table.Table_Name); } }