private DataGridViewColumn getDataGridViewColumn(DataChooser chooser)
        {
            string col = chooser.Column;

            if (chooser.IsSQL())
            {
                if (string.IsNullOrWhiteSpace(chooser.Sql))
                {
                    throw new Exception("Data Chooser config for colum " + chooser.Column + " is set as SQL but the SQL is kept as blank");
                }
                List <List <object> > result = controller.ExecuteSelectSQL(chooser.Sql, false);
                List <string>         values = new List <string>();
                foreach (List <object> row in result)
                {
                    values.Add(row[0].ToString());
                }
                return(getDataGridViewComboBoxColumn(chooser.Column, values));
            }
            else if (chooser.IsChooser())
            {
                DataGridViewTextBoxColumn column = getDataGridViewTextBoxColumn(chooser.Column, false);
                return(column);
            }
            else if (chooser.IsTable())
            {
                if (string.IsNullOrWhiteSpace(chooser.SourceColumn))
                {
                    throw new Exception("Data Chooser config for colum " + chooser.Column + " is set as Table but the SourceColumn is kept as blank");
                }
                if (string.IsNullOrWhiteSpace(chooser.SourceTable))
                {
                    throw new Exception("Data Chooser config for colum " + chooser.Column + " is set as Table but the SourceTable is kept as blank");
                }
                string sql = "SELECT DISTINCT(" + chooser.SourceColumn + ") FROM " + chooser.SourceTable;

                List <List <object> > result = controller.ExecuteSelectSQL(sql, false);
                List <string>         values = new List <string>();
                foreach (List <object> row in result)
                {
                    values.Add(row[0].ToString());
                }
                return(getDataGridViewComboBoxColumn(chooser.Column, values));
            }
            else
            {
                throw new Exception("Data Chooser config for colum " + chooser.Column + " is set with a invalid Source " + chooser.ChooserType);
            }
        }
        private void executeButton_Click(object sender, EventArgs e)
        {
            try
            {
                string sql = sqlTextBox.SelectedText;
                if (string.IsNullOrWhiteSpace(sql))
                {
                    sql = sqlTextBox.Text;
                }
                if (string.IsNullOrWhiteSpace(sql))
                {
                    MessageBox.Show("SQL is blank", "SQL is blank", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (sql.ToUpper().StartsWith("SELECT"))
                {
                    view = controller.ExecuteSelectSQL(tableName, sql);
                    dataGridView1.Columns.Clear();
                    dataGridView1.Rows.Clear();
                    foreach (string col in view.Columns.Keys)
                    {
                        DataChooser dataChooser = null;
                        foreach (DataChooser chooser in view.DataChoosers)
                        {
                            if (col.Equals(chooser.Column))
                            {
                                dataChooser = chooser;
                            }
                        }

                        DataGridViewColumn gridColumn = null;
                        if (dataChooser == null)
                        {
                            if (view.Columns[col] == typeof(DateTime))
                            {
                                gridColumn = getDataGridViewTextBoxColumn(col, true);
                            }
                            else
                            {
                                gridColumn = getDataGridViewTextBoxColumn(col, false);
                            }
                        }
                        else
                        {
                            gridColumn = getDataGridViewColumn(dataChooser);
                        }
                        dataGridView1.Columns.Add(gridColumn);

                        if (DBBrowserConstant.DBBROWSER_ACTION.Equals(col))
                        {
                            gridColumn.Visible = false;
                        }
                    }
                    foreach (List <object> row in view.Data)
                    {
                        dataGridView1.Rows.Add(row.ToArray());
                    }
                }
                else
                {
                    string[] sqlArray = controller.ExecuteSQL(view, sql);
                    foreach (string sqlStr in sqlArray)
                    {
                        foreach (DataGridViewRow row in operationGridView.Rows)
                        {
                            object sqlObj = row.Cells[Operation.Index].Value;
                            if (sqlObj != null && sqlStr.Equals(sqlObj.ToString()))
                            {
                                row.Cells[Executed.Index].Value = true;
                            }
                        }
                    }
                }
                MessageBox.Show("Sql execution successful", "Sql execution successful", MessageBoxButtons.OK, MessageBoxIcon.Information);

                //this.splitContainer4.SplitterDistance = this.splitContainer4.Height * 40 / 100;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while Executing sql\r\n" + ex.Message, "Error while Executing sql", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }