Exemple #1
0
 public void changeTableState()
 {
     States expectedState = States.Closed;
     Table t = new Table { TableNumber = "02", StateId = 1 };
     t.Close();
     Assert.AreEqual(expectedState, (t as ITable).State);
 }
        public IList<ForeignKey> DetermineForeignKeyReferences(Table table)
        {
            var constraints = table.Columns.Where(x => x.IsForeignKey.Equals(true)).Select(x => x.ConstraintName).Distinct().ToList();
            var foreignKeys = new List<ForeignKey>();
            constraints.ForEach(c =>
                {
                    var fkColumns = table.Columns.Where(x => x.ConstraintName.Equals(c)).ToArray();
                    var fk = new ForeignKey
                        {
                            Name = fkColumns[0].Name,
                            References = GetForeignKeyReferenceTableName(table.Owner, table.Name, fkColumns[0].Name),
                            Columns = fkColumns
                        };
                    foreignKeys.Add(fk);
                });

            Table.SetUniqueNamesForForeignKeyProperties(foreignKeys);

            return foreignKeys;
        }
        public PrimaryKey DeterminePrimaryKeys(Table table)
        {
            IList<Column> primaryKeys = table.Columns.Where(x => x.IsPrimaryKey.Equals(true)).ToList();

            if (primaryKeys.Count() == 1)
            {
                var c = primaryKeys.First();
                var key = new PrimaryKey
                    {
                        Type = PrimaryKeyType.PrimaryKey,
                        Columns =
                            {
                                new Column
                                    {
                                        DataType = c.DataType,
                                        Name = c.Name
                                    }
                            }
                    };
                return key;
            }
            else
            {
                var key = new PrimaryKey
                    {
                        Type = PrimaryKeyType.CompositeKey
                    };
                foreach (var primaryKey in primaryKeys)
                {
                    key.Columns.Add(new Column
                        {
                            DataType = primaryKey.DataType,
                            Name = primaryKey.Name
                        });
                }
                return key;
            }
        }
Exemple #4
0
 public TableSale(Register register, UserAccount userAccount, Table table)
     : base(register, userAccount)
 {
     this.Table = table;
 }
Exemple #5
0
        public Table AddTable(string tableNumber)
        {
            foreach (var t in Tables)
            {
                if (t.TableNumber.Equals(tableNumber))
                {
                    throw new BusinessRuleException("Table number must be unique");
                }
            }

            var table = new Table(this, tableNumber);
            Tables.Add(table);
            return table;
        }
Exemple #6
0
 public Sale CreateTableSale(Guid registerId, UserAccount userAccount, Table table)
 {
     var register = FetchRegister(registerId);
     return register.CreateTableSale(userAccount, table);
 }
Exemple #7
0
 public Sale CreateTableSale(Guid areaId, Guid registerId, UserAccount userAccount, Table table)
 {
     var area = FetchArea(areaId);
     return area.CreateTableSale(registerId, userAccount, table);
 }
        private IList<HasMany> DetermineHasManyRelationships(Table table)
        {
            var hasManyRelationships = new List<HasMany>();
            var conn = new IngresConnection(_connectionString);
            conn.Open();
            using (conn)
            {
                using (var command = conn.CreateCommand())
                {
                    command.CommandText = String.Format("SELECT f.table_name " +
                                                        "FROM iiref_constraints rc " +
                                                        "INNER JOIN iikeys p " +
                                                        "ON p.schema_name = rc.unique_schema_name " +
                                                        "AND p.constraint_name = rc.unique_constraint_name " +
                                                        "INNER JOIN iiconstraints c " +
                                                        "ON c.schema_name = rc.ref_schema_name " +
                                                        "AND c.constraint_name = rc.ref_constraint_name " +
                                                        "INNER JOIN iikeys f " +
                                                        "ON f.constraint_name = rc.ref_constraint_name " +
                                                        "AND p.key_position = f.key_position " +
                                                        "WHERE p.schema_name = '{0}' " +
                                                        "AND p.table_name = '{1}'",
                                                        table.Owner,
                                                        table.Name);
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            hasManyRelationships.Add(new HasMany
                                {
                                    Reference = reader.GetString(0).TrimEnd(),
                                });
                        }
                    }

                    return hasManyRelationships;
                }
            }
        }
        public IList<Column> GetTableDetails(Table table, string owner)
        {
            table.Owner = owner;
            var columns = new List<Column>();
            var conn = new IngresConnection(_connectionString);
            conn.Open();
            try
            {
                using (conn)
                {
                    using (var tableDetailsCommand = conn.CreateCommand())
                    {
                        tableDetailsCommand.CommandText = string.Format("SELECT" +
                                                                        " column_name," +
                                                                        " column_datatype," +
                                                                        " column_nulls," +
                                                                        " column_length," +
                                                                        " column_scale " +
                                                                        "FROM iicolumns " +
                                                                        "WHERE table_owner = '{0}' " +
                                                                        "AND table_name = '{1}' " +
                                                                        "ORDER BY column_sequence",
                                                                        owner, table.Name);

                        using (var sqlDataReader = tableDetailsCommand.ExecuteReader(CommandBehavior.Default))
                        {
                            while (sqlDataReader.Read())
                            {
                                string columnName = sqlDataReader.GetString(0).TrimEnd();
                                string dataType = sqlDataReader.GetString(1).TrimEnd();
                                bool isNullable = sqlDataReader.GetString(2).Equals("Y", StringComparison.CurrentCultureIgnoreCase);
                                int characterMaxLenth = sqlDataReader.GetInt32(3);
                                int numericPrecision = sqlDataReader.GetInt32(3);
                                int numericScale = sqlDataReader.GetInt32(4);

                                var m = new DataTypeMapper();

                                columns.Add(new Column
                                    {
                                        Name = columnName,
                                        DataType = dataType,
                                        IsNullable = isNullable,
                                        IsPrimaryKey = IsPrimaryKey(owner, table.Name, columnName),
                                        IsForeignKey = IsForeignKey(owner, table.Name, columnName),
                                        MappedDataType = m.MapFromDBType(ServerType.Ingres, dataType, characterMaxLenth, numericPrecision, numericScale).ToString(),
                                        DataLength = characterMaxLenth,
                                        ConstraintName = GetConstraintName(owner, table.Name, columnName),
                                        DataPrecision = numericPrecision,
                                        DataScale = numericScale
                                    });

                                table.Columns = columns;
                            }
                            table.PrimaryKey = DeterminePrimaryKeys(table);
                            table.ForeignKeys = DetermineForeignKeyReferences(table);
                            table.HasManyRelationships = DetermineHasManyRelationships(table);
                        }
                    }
                }
            }
            finally
            {
                conn.Close();
            }

            return columns;
        }
Exemple #10
0
 public Sale CreateTableSale(UserAccount userAccount, Table table)
 {
     var sale = new TableSale(this, userAccount, table);
     Sales.Add(sale);
     return sale;
 }