Exemplo n.º 1
0
        /// <summary>
        ///     Creates a new database table within the domain.
        /// </summary>
        public DomainTable CreateTable()
        {
            DomainTable table = new DomainTable(this);

            _tables.Add(table);
            return(table);
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Deserialises the version history from the specified xml element.
 /// </summary>
 internal static void Deserialise(DomainTable table, XmlNode parentNode)
 {
     foreach (XmlNode xmlNode in parentNode.SelectNodes("column"))
     {
         DomainTableColumn result = table.CreateColumn();
         result.Deserialise(xmlNode);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 ///     Deserialises the version history from the specified xml element.
 /// </summary>
 internal static void Deserialise(DomainTable table, XmlNode parentNode)
 {
     foreach (XmlNode xmlNode in parentNode.SelectNodes("index"))
     {
         DomainTableIndex result = table.CreateIndex();
         result.Deserialise(xmlNode);
         DomainTableIndexColumn.Deserialise(result, xmlNode);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 ///     Deserialises the version history from the specified xml element.
 /// </summary>
 internal static void Deserialise(Domain domain, XmlNode parentNode)
 {
     foreach (XmlNode xmlNode in parentNode.SelectNodes("table"))
     {
         DomainTable result = domain.CreateTable();
         result.Deserialise(xmlNode);
         DomainTableColumn.Deserialise(result, xmlNode);
         DomainTableIndex.Deserialise(result, xmlNode);
         DomainTableConstraint.Deserialise(result, xmlNode);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        ///     Imports the specified database table into the current domain.
        /// </summary>
        /// <param name="tableName">
        ///     The name of the table to be imported.
        /// </param>
        public override DomainTable ImportTable(String tableName)
        {
            // Import the table information
            DomainTable table = this.Execute(record => this.ParseTable(this.Domain, record), @"
              select objects.name 
              from sys.schemas
              join sys.objects on objects.schema_id = schemas.schema_id
              where schemas.name = 'dbo' and objects.type = 'u' and objects.name = @param1", tableName).FirstOrDefault();

            return(table);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Parses a data record into a <see cref="DatabaseTableColumn" /> instance.
        /// </summary>
        private DomainTableColumn ParseColumn(DomainTable table, IDataRecord record)
        {
            DomainTableColumn column = table.CreateColumn();

            column.ColumnOrdinal      = record["column_index"].ConvertTo <Int32>();
            column.ColumnName         = record["column_name"].ConvertTo <String>();
            column.ColumnType         = record["column_type"].ConvertTo <DomainDataType>();
            column.ColumnLength       = record["column_length"].ConvertTo <Int32>();
            column.ColumnScale        = record["column_scale"].ConvertTo <Int32>();
            column.ColumnNullable     = record["column_nullable"].ConvertTo <Boolean>();
            column.ColumnDefaultValue = record["column_default"].ConvertTo <String>();
            return(column);
        }
Exemplo n.º 7
0
        private void TableDropdown_Leave(Object sender, EventArgs eventArguments)
        {
            DomainTable bestMatch = (this.TableDropdown.DataSource as DomainTable[]).FirstOrDefault(t => String.Equals(t.TableName, this.TableDropdown.Text, StringComparison.OrdinalIgnoreCase));

            for (Int32 i = this.TableDropdown.Text.Length; i > 0 && bestMatch == null; i--)
            {
                bestMatch = (this.TableDropdown.DataSource as DomainTable[]).Where(t => t.TableName.StartsWith(this.TableDropdown.Text.Substring(0, i), StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
            }
            if (bestMatch != null)
            {
                this.TableDropdown.SelectedItem = bestMatch;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///     Parses a data record into a <see cref="DatabaseConstraint" /> instance.
        /// </summary>
        private DomainTableConstraint ParseConstraint(DomainTable table, IDataRecord record)
        {
            DomainTableConstraint constraint = table.CreateConstraint();

            constraint.ConstraintName  = record["key_name"].ConvertTo <String>();
            constraint.ReferencedTable = table.Domain.Tables.FirstOrDefault(t => t.TableName == record["key_object"].ConvertTo <String>());

            // Import the column information
            this.Execute(rec2 => this.ParseConstraintColumn(constraint, rec2), @"
              select column_name = columns.name, column_reference = referenced_column.name
              from sys.schemas
              join sys.objects on objects.schema_id = schemas.schema_id 
              join sys.columns on columns.object_id = objects.object_id 
              join sys.foreign_keys on foreign_keys.parent_object_id = objects.object_id
              join sys.foreign_key_columns on foreign_key_columns.constraint_object_id = foreign_keys.object_id and foreign_key_columns.parent_object_id = foreign_keys.parent_object_id and foreign_key_columns.parent_column_id = columns.column_id
              join sys.columns as referenced_column on referenced_column.object_id = foreign_key_columns.referenced_object_id and referenced_column.column_id = foreign_key_columns.referenced_column_id
              where schemas.name = 'dbo' and objects.type = 'u' and objects.name = @param1 and foreign_keys.object_id = @param2", table.TableName, record["key_id"]).ToArray();
            return(constraint);
        }
Exemplo n.º 9
0
        /// <summary>
        ///     Parses a data record into a <see cref="DatabaseIndex" /> instance.
        /// </summary>
        private DomainTableIndex ParseIndex(DomainTable table, IDataRecord record)
        {
            DomainTableIndex index = table.CreateIndex();

            index.IndexName     = record["index_name"].ConvertTo <String>();
            index.IndexIsUnique = record["index_unique"].ConvertTo <Boolean>();

            // Import the column information
            this.Execute(rec2 => this.ParseIndexColumn(index, rec2), @"
              select columns.name
              from sys.schemas
              join sys.objects on objects.schema_id = schemas.schema_id 
              join sys.columns on columns.object_id = objects.object_id 
              join sys.indexes on indexes.object_id = objects.object_id
              join sys.index_columns on index_columns.object_id = objects.object_id and index_columns.index_id = indexes.index_id and index_columns.column_id = columns.column_id
              where schemas.name = 'dbo' and objects.type = 'u' and objects.name = @param1 and indexes.index_id = @param2
              order by indexes.type, indexes.index_id", table.TableName, record["index_id"]).ToArray();

            return(index);
        }
Exemplo n.º 10
0
        private void TableDropdown_SelectedIndexChanged(object sender, EventArgs e)
        {
            DomainTable selectedValue = this.TableDropdown.SelectedValue as DomainTable;
            List <KeyValuePair <DomainTableColumn, String> > columns = null;

            if (selectedValue != null)
            {
                if (String.IsNullOrEmpty(this.NameTextbox.Text) || (this.NameTextbox.Tag is Boolean && ((Boolean)this.NameTextbox.Tag)))
                {
                    this.NameTextbox.Text = selectedValue.TableName.ToPascal();
                }

                columns = selectedValue.TableColumns.ToDictionary(c => c, c => c.ColumnName).ToList();
                columns.Insert(0, new KeyValuePair <DomainTableColumn, String>(null, EntityEditor.NONE));
            }

            this.FilterDropdown.DisplayMember = "Value";
            this.FilterDropdown.ValueMember   = "Key";
            this.FilterDropdown.DataSource    = columns;
            this.FilterDropdown.Enabled       = columns != null;
            this.FilterDropdown.SelectedItem  = columns == null ? null : (Object)columns.FirstOrDefault(kvp => kvp.Key == this.DomainEntity.FilterColumn);
        }
Exemplo n.º 11
0
        /// <summary>
        ///     Parses a data record into a <see cref="DatabaseTable" /> instance.
        /// </summary>
        private DomainTable ParseTable(Domain domain, IDataRecord record)
        {
            DomainTable table = domain.CreateTable();

            table.TableName = record["name"].ConvertTo <String>();

            // Import the column information
            this.Execute(rec2 => this.ParseColumn(table, rec2), @"
              select column_index = columns.column_id, column_name = columns.name, column_type = case types.name when 'bigint' then 'Int64' when 'binary' then 'Binary' when 'bit' then 'Boolean' when 'char' then 'Char' when 'date' then 'DateTime' when 'datetime' then 'DateTime' when 'decimal' then 'Decimal' when 'float' then 'Double' when 'int' then 'Int32' when 'money' then 'Decimal' when 'nchar' then 'NChar' when 'nvarchar' then 'NVarchar' when 'smallint' then 'Int16' when 'tinyint' then 'Byte' when 'real' then 'Single' when 'uniqueidentifier' then 'Guid' when 'varbinary' then 'Binary' when 'varchar' then 'Varchar' else types.name end, column_length = case when types.name in ('nchar', 'nvarchar') then columns.max_length / 2 when types.name in ('char', 'varchar') then columns.max_length else columns.precision end, column_scale = columns.scale, column_nullable = case when columns.is_nullable = 0 then 'False' else 'True' end, column_default = case when len(default_constraints.definition) < 4 then substring(default_constraints.definition, 2, len(default_constraints.definition) - 2) when isnumeric(substring(default_constraints.definition, 3, len(default_constraints.definition) - 4)) = 0 then substring(default_constraints.definition, 2, len(default_constraints.definition) - 2) else substring(default_constraints.definition, 3, len(default_constraints.definition) - 4) end
              from sys.schemas
              join sys.objects on objects.schema_id = schemas.schema_id 
              join sys.columns on columns.object_id = objects.object_id
              join sys.types on types.user_type_id = columns.user_type_id
              left join sys.default_constraints on default_constraints.parent_object_id = columns.object_id and default_constraints.parent_column_id = columns.column_id
              where schemas.name = 'dbo' and objects.type = 'u' and objects.name = @param1
			  order by columns.column_id"            , table.TableName).ToArray();

            // Import the index information
            this.Execute(rec2 => this.ParseIndex(table, rec2), @"
              select index_id = indexes.index_id, index_name = indexes.name, index_unique = indexes.is_unique
              from sys.schemas
              join sys.objects on objects.schema_id = schemas.schema_id 
              join sys.indexes on indexes.object_id = objects.object_id
              where schemas.name = 'dbo' and objects.type = 'u' and objects.name = @param1
              order by indexes.type, indexes.index_id", table.TableName).ToArray();

            // Import the constraint information
            this.Execute(rec2 => this.ParseConstraint(table, rec2), @"
              select key_id = foreign_keys.object_id, key_name = foreign_keys.name, key_object = referenced_object.name
              from sys.schemas
              join sys.objects on objects.schema_id = schemas.schema_id 
              join sys.foreign_keys on foreign_keys.parent_object_id = objects.object_id
              join sys.objects as referenced_object on referenced_object.object_id = foreign_keys.referenced_object_id
              where schemas.name = 'dbo' and objects.type = 'u' and objects.name = @param1
              order by foreign_keys.key_index_id", table.TableName).ToArray();

            return(table);
        }
Exemplo n.º 12
0
        /// <summary>
        ///     Loads the domain from the specified document.
        /// </summary>
        public static Domain Load(String filePath)
        {
            Domain domain = new Domain();

            if (File.Exists(filePath))
            {
                XmlDocument document = new XmlDocument();
                document.Load(filePath);
                domain._version = new Version(document.DocumentElement.Attributes["version"].Value);

                domain.Deserialise(document.DocumentElement);
                DomainTable.Deserialise(domain, document.DocumentElement);
                DomainContainer.Deserialise(domain, document.DocumentElement);
                DomainContainer.DeserialiseExtenders(domain, document.DocumentElement);
                DomainDataSource.Deserialise(domain, document.DocumentElement);
            }
            else
            {
                domain.ChangeVersion(7, 0, 0, 0, 0);
                domain.DomainName = "Consensus";
            }
            return(domain);
        }
Exemplo n.º 13
0
 /// <summary>
 ///     Initialises a new <see cref="DomainTableColumn" /> instance.
 /// </summary>
 public DomainTableColumn(DomainTable table) : base(table.Version)
 {
     _table = table;
 }
Exemplo n.º 14
0
 /// <summary>
 ///     Initialises a new <see cref="TableEditor" /> instance.
 /// </summary>
 public TableEditor(DomainTable domainTable)
 {
     this.InitializeComponent();
     this.DomainTable = domainTable;
 }
Exemplo n.º 15
0
        private void NameTextbox_TextChanged(object sender, EventArgs e)
        {
            DomainTable selectedValue = this.TableDropdown.SelectedValue as DomainTable;

            this.NameTextbox.Tag = selectedValue == null || String.IsNullOrEmpty(this.NameTextbox.Text) || String.Equals(selectedValue.TableName.ToPascal(), this.NameTextbox.Text);
        }
Exemplo n.º 16
0
 /// <summary>
 ///     Initialises a new <see cref="DomainTableColumn" /> instance.
 /// </summary>
 public DomainTableIndex(DomainTable table) : base(table.Version)
 {
     _table        = table;
     _indexColumns = new List <DomainTableIndexColumn>();
 }
Exemplo n.º 17
0
 /// <summary>
 ///     Initialises a new <see cref="DomainTableConstraint" /> instance.
 /// </summary>
 public DomainTableConstraint(DomainTable table) : base(table.Version)
 {
     _table             = table;
     _constraintColumns = new List <DomainTableConstraintColumn>();
 }