示例#1
0
        private void SetTableFilter()
        {
            if (txtFilter.Text.Equals("Filter..."))
            {
                return;
            }

            filteredTablesList.Clear();
            TablesListBox.DataSource = null;
            if (rdoContains.Checked)
            {
                var filterQuery = from t in tablesList
                                  where t.Contains(txtFilter.Text.Trim())
                                  select t;
                filteredTablesList.AddRange(filterQuery.ToList <string>());
            }
            else
            {
                var filterQuery = from t in tablesList
                                  where t.StartsWith(txtFilter.Text.Trim())
                                  select t;
                filteredTablesList.AddRange(filterQuery.ToList <string>());
            }
            TablesListBox.DataSource = filteredTablesList;
            TablesListBox.Refresh();
            RefreshColumnList();
        }
示例#2
0
        /*private void button1_Click(object sender, EventArgs e)
         * {
         *  Table t = new Table("dbo.Customers", 0, Global.databases[4]);
         *  t.TryRead(new SqlConnection(Database.BuildConnectionString(Global.databases[4].dbParams)));
         * }*/

        private void TablesListBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            int index = TablesListBox.IndexFromPoint(e.Location);

            if (index != ListBox.NoMatches)
            {
                GlobalContext.currentTable = GlobalContext.currentDb.Tables[index];
                dataGridView1.DataSource   = GlobalContext.currentDb.Tables[index].ToDataTable();

                /*MessageBox.Show(Global.databases[Global.currentDb].tables[index].Rows[0].Values[1].ToString());
                 * //int rowCount = Global.databases[Global.currentDb].tables[index].columns[0].vales
                 * var columnNames = Global.databases[Global.currentDb].tables[index].columns.Select(x => x.name);
                 * List<List<object>> vals = new List<List<object>>();
                 * foreach (public TableColumn column in Global.databases[Global.currentDb].tables[index].Cols)
                 * {
                 *  table.Columns.Add()
                 * }*/
                //var cols = Global.databases[Global.currentDb].tables[index].columns;
                //var colsNumber = cols.Count;
                //foreach (Column col in cols)
                //{
                //    col.GetType();
                //    table.Columns.Add(col.name);
                //}
                //for(int i = 0; i < Global.databases[Global.currentDb].tables[index].recordNumber; i++)
                //{

                //    var row = table.Rows.Add();
                //    for (var j = 0; j < colsNumber; j++)
                //    {
                //        var c = cols[j];
                //        switch (c.dataType.ToString())
                //        {
                //            case "integer":
                //                row[cols[j].name] = (cols[j] as Column<int>).values[i];
                //                break;
                //            case "varchar":
                //                row[cols[j].name] = (cols[j] as Column<string>).values[i];
                //                break;
                //            case "nvarchar":
                //                row[cols[j].name] = (cols[j] as Column<string>).values[i];
                //                break;
                //            case "char":
                //                row[cols[j].name] = (cols[j] as Column<char>).values[i];
                //                break;
                //            case "nchar":
                //                row[cols[j].name] = (cols[j] as Column<char>).values[i];
                //                break;
                //            case "float":
                //            case "real":
                //                row[cols[j].name] = (cols[j] as Column<double>).values[i];
                //                break;
                //            default: throw new Exception("Cannot parse type: " + c.dataType.ToString());
                //        }
                //    }
                //}
                //dataGridView1.DataSource = table;
            }
        }
示例#3
0
 private void deleteTableToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show($"Delete table {TablesListBox.SelectedItem} ?", "Are you sure?", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         Global.currentDb.DropTable(TablesListBox.SelectedItem.ToString());
         TablesListBox.Refresh();
         Global.currentTable = null;
     }
 }
        /// <summary>
        /// Resets the form elements/selected items
        /// </summary>
        private void ResetForm()
        {
            TablesListBox.ClearSelected();
            TablesListBox.SelectedItem = null;

            CustomersListBox.ClearSelected();
            CustomersListBox.SelectedItem = null;

            CompaniesListBox.ClearSelected();
            CompaniesListBox.SelectedItem = null;
        }
示例#5
0
 /// <summary>
 /// Selects all tables in the database schema for searching
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnSelectAllTables_Click(object sender, EventArgs e)
 {
     TablesListBox.SuspendLayout();
     ColumnsListBox.SuspendLayout();
     for (int i = 0; i < TablesListBox.Items.Count; i++)
     {
         TablesListBox.SetSelected(i, true);
     }
     TablesListBox.TopIndex = 0;
     RefreshColumnList();
     TablesListBox.ResumeLayout();
     ColumnsListBox.ResumeLayout();
 }
示例#6
0
 private void deleteTableToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show($"Delete table {TablesListBox.SelectedItem} ?", "Are you sure?", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         try
         {
             GlobalContext.currentDb.DropTable(TablesListBox.SelectedItem.ToString());
             TablesListBox.Refresh();
             GlobalContext.currentTable = null;
         }
         catch (Exception exc)
         {
             MessageBox.Show(exc.Message, "Failed to drop table", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
示例#7
0
        //private void LoadConnections()
        //{
        //	string[] lines = File.ReadAllLines("Connections.txt");
        //	cboConnString.Items.AddRange(lines);
        //	cboConnString.Refresh();
        //}

        /// <summary>
        /// Open the database, loads the schema into the dataset
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <exception>Throws SqlException or a general Exception</exception>
        private void btnOpenDatabase_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cboConnString.Text))
            {
                MessageBox.Show("Enter or select an existing connection string before clicking \"Open\"!", "Open Database Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            // Collapse the columns list box
            splitContainer3.SuspendLayout();
            splitContainer3.Panel2Collapsed = true;
            btnShowColumns.Text             = ">";
            splitContainer3.ResumeLayout();

            tablesList.Clear();
            TablesListBox.DataSource = null;
            TablesListBox.Refresh();

            ssStatus.Items[0].Text = "";
            txtResults.Text        = "Opening Database - for Clarity and other very large schemas, this may take some time. Be patient." +
                                     "\r\nFor example, Clarity takes over 30 seconds to load";
            txtResults.Refresh();

            DateTime start = DateTime.Now;

            string connString = cboConnString.Text.Trim();

            dbUtils.OpenDatabase(connString, ssStatus);
            foreach (DataRow row in dbUtils.SchemaDataSet.Tables["Tables"].Rows)
            {
                tablesList.Add(row["TABLE_NAME"].ToString());
            }
            TablesListBox.DataSource = tablesList;
            TablesListBox.Refresh();
            TimeSpan elapsed = DateTime.Now - start;

            SetStatus(String.Format("Database Loaded: {0} in {1:D2} hours, {2:D2} minutes, {3:D2} seconds and {4:D2} milliseconds",
                                    dbUtils.CurrentDatabase, elapsed.Hours,
                                    elapsed.Minutes, elapsed.Seconds, elapsed.Milliseconds));
            btnSearch.Enabled          = true;
            btnSelectAllTables.Enabled = true;
        }
 /// <summary>
 /// Resets the form elements/selected items and clears the selected table
 /// </summary>
 private void ResetForm()
 {
     TablesListBox.ClearSelected();
     TablesListBox.SelectedItem = null;
     TableNameTextBox.Text      = "";
 }