Example #1
0
        public Table GetTable(string tablename)
        {
            Table table = null;
            List<ColumnStructure> information = new List<ColumnStructure>();

            using (MySqlTransaction transaction = Connection.Instance.BeginTransaction()) {

                //Structure
                string query = "DESC " + tablename;
                MySqlCommand command = Connection.Instance.GetCommand(query, transaction);

                using (MySqlDataReader reader = command.ExecuteReader()) {
                    while (reader.Read()) {
                        ColumnStructure cs = new ColumnStructure();

                        cs.ColumnName = DbUtils.GetString(reader["Field"]);
                        cs.DataType = DbUtils.GetString(reader["Type"]);
                        cs.KeyType = DbUtils.GetString(reader["Key"]);
                        cs.IsNullable = DbUtils.GetString(reader["Null"]);
                        cs.Extra = DbUtils.GetString(reader["Extra"]);

                        information.Add(cs);
                    }
                }

                //Data
                table = new Table(tablename, information);

                query = "SELECT * from " + tablename;
                MySqlCommand commandData = Connection.Instance.GetCommand(query, transaction);

                using(MySqlDataReader reader = commandData.ExecuteReader()) {
                    while(reader.Read()) {
                        DataRow row = new DataRow();
                        row.ColumnStructure = information;
                        for (int i = 0; i < reader.FieldCount; i++) {
                            row.Attributes.Add(new Flag(reader.GetName(i), reader[i].ToString(),  reader.GetDataTypeName(i)));
                        }
                        table.DataRows.Add(row);
                    }
                }

                transaction.Commit();
            }

            return table;
        }
Example #2
0
        private ComboBox GetValueComboBox(ColumnStructure cs)
        {
            ComboBox combobox = new ComboBox();
            combobox.BeginUpdate();

            combobox.DropDownStyle = ComboBoxStyle.DropDownList;
            combobox.Width = this.pnlValues.Width - 3;
            combobox.Font = new Font("Microsoft Sans Serif", 10);

            Table table = this.dbInformation.GetTableOfForeignKey(this.table.TableName, cs.ColumnName);

            if (table != null) {
                if(cs.IsNullable.ToLower() == "yes") {
                    combobox.Items.Add("");
                }

                foreach (DTO.DataRow row in table.DataRows) {
                    string item = string.Empty;
                    foreach (Flag flag in row.Attributes) {
                        item += flag.Value + "; ";
                    }
                    combobox.Items.Add(item);
                }
            }

            if(combobox.Items.Count > 0) {
                combobox.SelectedIndex = 0;
            }

            combobox.EndUpdate();

            return combobox;
        }