/// <summary> /// 表改变 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TableSelectedIndexChanged(object sender, EventArgs e) { ServerNetInfo.DBItems db_info = this.GetSelectDB(); if (db_info == null) { return; } string table_name = GetSelectTable(); if (string.IsNullOrEmpty(table_name)) { return; } Dictionary <string, Type> list = DatabaseManager.Instance.GetFields((eDBType)db_info.id, table_name); if (list == null || list.Count == 0) { return; } //--列出字段 m_field_name.Items.Clear(); m_key_type.Items.Clear(); foreach (var obj in list) { m_field_name.Items.Add(obj.Key); m_key_type.Items.Add(obj.Key); } m_field_name.SelectedIndex = -1; m_key_type.SelectedIndex = -1; ClearFind(); }
private void OpenDB(ServerNetInfo.DBItems db_info) { string conn_str = "Database='" + db_info.name + "';Data Source='" + db_info.address + "';User Id='" + db_info.username + "';Password='******';charset='utf8';pooling=true"; Database db = new Database(); db.Open(conn_str, db_info.name); m_db_instance[db_info.id] = db; }
private ServerNetInfo.DBItems GetSelectDB() { int select_indx = m_db_list.SelectedIndex; if (select_indx < 0 || select_indx >= ServerConfig.info.db_list.Count) { return(null); } ServerNetInfo.DBItems db_info = ServerConfig.info.db_list[select_indx]; return(db_info); }
/// <summary> /// 数据库改变 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DBSelectedIndexChanged(object sender, EventArgs e) { ServerNetInfo.DBItems db_info = this.GetSelectDB(); if (db_info == null) { return; } System.Data.DataTable dt = DatabaseManager.Instance.GetTables((eDBType)db_info.id); if (dt == null) { return; } //--列出表名 m_table_name.Items.Clear(); for (int i = 0; i < dt.Rows.Count; i++) { m_table_name.Items.Add(dt.Rows[i][2].ToString()); } m_table_name.SelectedIndex = -1; m_field_name.SelectedIndex = -1; m_key_type.SelectedIndex = -1; ClearFind(); }
/// <summary> /// 判断有效性,收集输入信息 /// </summary> /// <returns></returns> private QueryInfo CheckValidAndCollect() { QueryInfo query_info = new QueryInfo(); ServerNetInfo.DBItems db_info = this.GetSelectDB(); if (db_info == null) { ShowErrorMsg("未选择数据库"); return(null); } query_info.db_type = (eDBType)(db_info.id); string table_name = GetSelectTable(); if (string.IsNullOrEmpty(table_name)) { ShowErrorMsg("未选择表"); return(null); } query_info.table_name = table_name; string field_name = GetSelectField(); if (string.IsNullOrEmpty(field_name)) { ShowErrorMsg("未选择字段"); return(null); } query_info.field_name = field_name; //bin类型 switch (m_bin_type.SelectedItem.ToString()) { case "binary": query_info.bin_type = MySql.Data.MySqlClient.MySqlDbType.Binary; break; case "varbinary": query_info.bin_type = MySql.Data.MySqlClient.MySqlDbType.VarBinary; break; case "bit": query_info.bin_type = MySql.Data.MySqlClient.MySqlDbType.Bit; break; case "tinyblob": query_info.bin_type = MySql.Data.MySqlClient.MySqlDbType.TinyBlob; break; case "blob": query_info.bin_type = MySql.Data.MySqlClient.MySqlDbType.Blob; break; case "mediumblob": query_info.bin_type = MySql.Data.MySqlClient.MySqlDbType.MediumBlob; break; case "longblob": query_info.bin_type = MySql.Data.MySqlClient.MySqlDbType.LongBlob; break; default: query_info.bin_type = MySql.Data.MySqlClient.MySqlDbType.Blob; break; } ///固定长度 query_info.fixed_length = 0; int index = m_field_config_list.SelectedIndex; if (index < 0 || index >= ServerConfig.info.field_list.Count) { ShowErrorMsg("未选中bin字段配置"); return(null); } query_info.fixed_length = ServerConfig.info.field_list[index].fixed_length; if (m_field_list.Items.Count <= 0) { ShowErrorMsg("未设置bin结构"); return(null); } if (string.IsNullOrEmpty(m_key_type.SelectedItem.ToString().Trim())) { ShowErrorMsg("未选择查询关键字"); return(null); } query_info.sql_key_name = m_key_type.SelectedItem.ToString(); string key = m_txt_key.Text.Trim(); if (string.IsNullOrEmpty(key)) { ShowErrorMsg("未输入关键字值"); return(null); } query_info.sql_key_value = key; if (m_sql_type.SelectedIndex < 0) { ShowErrorMsg("未选择关键字类型"); return(null); } query_info.sql_key_type = m_sql_type.SelectedIndex; if (query_info.sql_key_type != 0 && query_info.sql_key_type != 1) { ShowErrorMsg("选择的关键字类型不对"); return(null); } return(query_info); }