Example #1
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            CodeTableDefinition codeTableDialog = new CodeTableDefinition();
            DialogResult        result          = codeTableDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                DataTable bindingTable   = GetProject().CodeData.GetCodeTableNamesForProject(GetProject());
                DataView  dataView       = bindingTable.DefaultView;
                string    display        = String.Empty;
                string    kindOfDatabase = GetProject().CodeData.IdentifyDatabase();

                //TODO: Will need to rework this section not to be dependant on strings and develop a
                // more OO solution
                switch (kindOfDatabase)
                {
                case "ACCESS":
                    display = ColumnNames.NAME;
                    break;

                case "SQLSERVER":
                    display = ColumnNames.SCHEMA_TABLE_NAME;
                    break;

                case "MYSQL":
                    display = ColumnNames.SCHEMA_TABLE_NAME;
                    break;

                default:
                    display = ColumnNames.SCHEMA_TABLE_NAME;
                    break;
                }
                dataView.Sort = display;

                // Check if this table already exists. If so, increment a suffix counter.
                tableName = Util.Squeeze(codeTableDialog.CodeTableName);
                string newTableName = tableName;
                int    count        = 0;
                while (dataView.Find(newTableName) != -1)
                {
                    count++;
                    newTableName = tableName + count;
                }
                tableName  = newTableName;
                columnName = Util.Squeeze(codeTableDialog.CodeTableRootName);
                if (!Util.IsFirstCharacterALetter(columnName))
                {
                    columnName = "col" + columnName;
                }
                DataTable table = new DataTable(tableName);
                table.Columns.Add(columnName);
                dgCodeTable.PreferredColumnWidth = Convert.ToInt32(dgCodeTable.Width * .87);
                dgCodeTable.DataSource           = table;
                codeTableDialog.Close();
            }
        }
        private void btnCreate_Click(object sender, EventArgs e)
        {
            CodeTableDefinition codeTableDialog = new CodeTableDefinition();
            DialogResult result = codeTableDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                DataTable bindingTable = GetProject().CodeData.GetCodeTableNamesForProject(GetProject());
                DataView dataView = bindingTable.DefaultView;
                string display = String.Empty;
                string kindOfDatabase = GetProject().CodeData.IdentifyDatabase();

                //TODO: Will need to rework this section not to be dependant on strings and develop a
                // more OO solution
                switch (kindOfDatabase)
                {
                    case "ACCESS":
                        display = ColumnNames.NAME;
                        break;
                    case "SQLSERVER":
                        display = ColumnNames.SCHEMA_TABLE_NAME;
                        break;
                    case "MYSQL":
                        display = ColumnNames.SCHEMA_TABLE_NAME;
                        break;
                    default:
                        display = ColumnNames.SCHEMA_TABLE_NAME;
                        break;
                }
                dataView.Sort = display;

                // Check if this table already exists. If so, increment a suffix counter.
                tableName = Util.Squeeze(codeTableDialog.CodeTableName);
                string newTableName = tableName;
                int count = 0;
                while (dataView.Find(newTableName)!=-1)
                {
                    count++;
                    newTableName = tableName + count;
                }
                tableName = newTableName;
                columnName = Util.Squeeze(codeTableDialog.CodeTableRootName);
                if(!Util.IsFirstCharacterALetter(columnName)) columnName = "col" + columnName;
                DataTable table = new DataTable(tableName);
                table.Columns.Add(columnName);
                dgCodeTable.PreferredColumnWidth = Convert.ToInt32(dgCodeTable.Width * .87);
                dgCodeTable.DataSource = table;
                codeTableDialog.Close();
            }
        }