/* * private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) * { * * cbAvailableSQLInstaces.Enabled = true; * string selected = (sender as ComboBox).Text; * cbAvailableSQLInstaces.Items.AddRange(NetWorks.GetSQLInstance(selected)); * cbAvailableSQLInstaces.SelectedIndex = 0; * } */ private void cbTablesList_SelectedIndexChanged(object sender, EventArgs e) { try { DataTable table = SQLWorks.ExecuteQuery(string.Format("SELECT * FROM {0}", SQlToHumanTranslater.TranslateToSQL(((ComboBox)sender).Text))); dgvTableView.DataSource = table; DataTableDecorator(); } catch (Exception ex) { DisplayStatus(ex.Message); } /* * SqlCommand cmd = new SqlCommand(command, connection); * * var result = cmd.BeginExecuteReader(); * while (!result.IsCompleted) * { * * * } * * using (SqlDataReader reader = cmd.EndExecuteReader(result)) * { * DataTable table = new DataTable(); * table.Load(reader); * dataGridView1.DataSource = table; * }*/ //} }
private void butGetAdress_Click(object sender, EventArgs e) { try { using (FWait wait = new FWait(() => { DataTable srvsNames = SQLWorks.ExecuteQuery("SELECT * FROM Users"); dgvTableView.Invoke(new Action(() => dgvTableView.DataSource = srvsNames)); })) wait.ShowDialog(this); } catch (Exception ex) { DisplayStatus(ex.Message); } #region //tbAdress.Text = NetWorks.ServersIp(tbPcName.Text); //SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance; //DataTable table = instance.GetDataSources(); //dataGridView1.DataSource = NetWorks.GetSQLServerNames(); //comboBox2.DataSource = table; // comboBox2.ValueMember = table.Columns[0].ColumnName; #endregion }
/// <summary> /// Генерируем текстовые поля ввода пользовательских данных с жирной кнопкой в конце /// </summary> private void CreateForm() { ColumnNames = SQLWorks.ExecuteQuery(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME != 'id' AND TABLE_NAME = '{0}'", tableName)). Rows.Cast <DataRow>().Select(row => row[0].ToString()).ToArray(); editableControlList = new List <Control>(); for (int i = 0; i < ColumnNames.Length; i++) { AddField(ColumnNames[i]); } Button insert = new Button() { Text = "Добавить", Location = LastConrolPosition, Size = new Size(this.Width - 10, 200), Font = new Font(Font.FontFamily, 30) }; insert.Click += new EventHandler(btnInsert_Click); Controls.Add(insert); display = new Label(); console = new StatusStrip() { Dock = DockStyle.Bottom, Size = new Size(this.Width, 20), }; console.Items.Add(new ToolStripControlHost(display)); Controls.Add(console); AutoSize = true; Size += new Size(0, 50);//потому что статусбар не влазиет( }
private FAddToTable(string tableName) { InitializeComponent(); TableName = tableName; Text = SQlToHumanTranslater.TranslateToHuman(tableName); StartPosition = FormStartPosition.CenterParent; table = SQLWorks.ExecuteQuery(string.Format("SELECT * FROM {0}", tableName)); lastConrolPosition = new Point(10, -20); CreateForm(); }
private FAddToTable(string tableName) { InitializeComponent(); TableName = tableName; Text = SQlToHumanTranslater.TranslateToHuman(tableName); StartPosition = FormStartPosition.CenterParent; table = SQLWorks.ExecuteQuery(string.Format("SELECT * FROM {0}", tableName)); lastConrolPosition = new Point(10, 10); ColumnNames = SQLWorks.ExecuteQuery(string.Format("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME != 'id' AND TABLE_NAME = '{0}'", tableName)). Rows.Cast <DataRow>().Select(row => row[0].ToString()).ToArray(); for (int i = 0; i < ColumnNames.Length; i++) { CreateForm(ColumnNames[i]); } Size = new Size(600, (Controls.Count * 50) + 200); }
List <Control> editableControlList;//список контролов на валидацию /// <summary> /// вставляет пару лэйбл - текстбокс аналогичный полю в БД /// </summary> /// <param name="name">Имя аналогичного столбца из БД</param> private void AddField(string name)//необходимо как то привести к паттерну стратегия { Label l = new Label() { Text = SQlToHumanTranslater.TranslateToHuman(name), Location = LastConrolPosition, Size = Size = new Size(500, 30) }; string type = SQLWorks.ExecuteQuery( string.Format("SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = '{0}' AND COLUMN_NAME = '{1}'", TableName, name)).Rows[0][0].ToString(); Control c; if (name.ToUpper().Contains("ID") || type == "bit") //для поля пол в таблице Юзерс { c = new ComboBox() //вместо текстбокса - комбобокс { AutoCompleteMode = AutoCompleteMode.Append, AutoCompleteSource = AutoCompleteSource.ListItems }; if (name.ToLower() == "isman")//плохо { ((ComboBox)c).Items.AddRange(new string[] { "муж", "жен" }); } else { ((ComboBox)c).Items.AddRange( SQLWorks.getRelatedTable(name).Rows.Cast <DataRow>().Select(r => r[1].ToString()).ToArray <string>() ); } } else { c = new TextBox(); } c.Name = name; c.Size = new Size(500, 30); c.Location = LastConrolPosition; c.Enabled = true; c.Font = new Font(Font.FontFamily, 15); editableControlList.Add(c); this.Controls.AddRange(new Control[] { l, c }); }
void CreateForm(string name) { Label l = new Label() { Text = SQlToHumanTranslater.TranslateToHuman(name), Location = LastConrolPosition, }; string type = SQLWorks.ExecuteQuery( string.Format("SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = '{0}' AND COLUMN_NAME = '{1}'", TableName, name)).Rows[0][0].ToString(); Control c; if (type != "bit") { c = new TextBox() { Size = new Size(500, 30), Location = LastConrolPosition, Enabled = true, //AutoSize = false, Font = new Font(Font.FontFamily, 15) }; } else { c = new ComboBox() { Size = new Size(500, 30), Location = LastConrolPosition, Enabled = true, Font = new Font(Font.FontFamily, 15) }; ((ComboBox)c).Items.AddRange((new string[] { "муж", "жен" })); } this.Controls.Add(l); this.Controls.Add(c); }
string[] AllColumnsOfTables() { DataTable table = SQLWorks.ExecuteQuery("SELECT DISTINCT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS where table_name <> 'sysdiagrams'"); return(table.Rows.Cast <DataRow>().Select(r => r[0].ToString()).ToArray()); }
string[] ColumnsOfTable(string tableName) { DataTable table = SQLWorks.ExecuteQuery("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS"); return(table.Rows.Cast <DataRow>().Select(r => r[0].ToString()).ToArray()); }