private void add() { //Add row DTO.DataRow row = new DTO.DataRow(); row.ColumnStructure = this.table.ColumnStructure; foreach (Control ctrl in this.pnlValues.Controls) { ColumnStructure cs = (ColumnStructure)ctrl.Tag; if (ctrl is TextBox) { row.Attributes.Add(new Flag(cs.ColumnName, ctrl.Text, cs.DataType)); } else if(ctrl is ComboBox) { string value = string.Empty; if(!string.IsNullOrEmpty(ctrl.Text)) { value = ctrl.Text.Split(';')[0]; } row.Attributes.Add(new Flag(cs.ColumnName, value, cs.DataType)); } } this.table.DataRows.Add(row); //Clear fields if (this.ctrlToIncrement != null) { int id = 1; Int32.TryParse(this.ctrlToIncrement.Text, out id); this.clearFields(); this.ctrlToIncrement.Text = (id + 1).ToString(); } else { this.clearFields(); } //Generate query this.txtQuery.Text = InsertStatement.GetQuery(table); }
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; }
private void Add() { //Add row DTO.DataRow row = new DTO.DataRow(); row.ColumnStructure = this.table.ColumnStructure; foreach (Control ctrl in this.pnlValues.Controls) { ColumnStructure cs = (ColumnStructure)ctrl.Tag; if (ctrl is TextBox) { row.Attributes.Add(new Flag(cs.ColumnName, ctrl.Text, cs.DataType)); } else if (ctrl is ComboBox) { string value = string.Empty; if (!string.IsNullOrEmpty(ctrl.Text)) { value = ctrl.Text.Split(';')[0]; } row.Attributes.Add(new Flag(cs.ColumnName, value, cs.DataType)); } } this.table.DataRows.Add(row); //Clear fields if (this.ctrlToIncrement != null) { Int32.TryParse(this.ctrlToIncrement.Text, out int id); this.ClearFields(); this.ctrlToIncrement.Text = (id + 1).ToString(); } else { this.ClearFields(); } //Generate query this.txtQuery.Text = InsertStatement.GetQuery(table); }