public SchemaTableDetail_HelperTable(Schema schema)
            : base(schema)
        {
            ID = StaticID;
            Name = "Конфигурация.Таблица.Деталь";

            SchemaTableColumn c;

            c = new SchemaTableColumn();
            c.Name = "ID";
            c.DataType = new GuidDataType() { Column = c };
            c.ColumnRoles.Add(RoleConst.Таблица_Ключ);
            c.IsNotNullable = true;
            c.Table = this;
            Columns.Add(c);

            c = new SchemaTableColumn();
            c.Name = "Имя";
            c.DataType = new StringDataType() { Column = c, MaxSize = 128 };
            c.IsNotNullable = false;
            c.Table = this;
            Columns.Add(c);

            c = new SchemaTableColumn();
            c.Name = "Таблица";
            c.DataType = new ForeingKeyDataType() { Column = c, RefTableID = SchemaTable_HelperTable.StaticID };
            c.IsNotNullable = false;
            c.Table = this;
            Columns.Add(c);
        }
        //public override bool GetNeedSave()
        //{
        //    if (Column != null)
        //        return Column.GetNeedSave();
        //    else
        //        return false;
        //}
        public SchemaTableColumnAddDialogModel(Controller controller, BaseModel parentModel, SchemaTable table)
            : base(controller, parentModel)
        {
            EditedColumnDataTypes = new List<SqlDataType>();

            Column = new SchemaTableColumn();
            Column.Position = table.GetMaxColumnPosition() + 1;
            Column.Table = table;
            Column.DataType = new GuidDataType() { Column = Column };
            Column.Name = "";

            EditedObject = Column;
        }
Exemplo n.º 3
0
        public void ImportSchemaFromNativeDB(string tableName)
        {
            if (Columns.Count != 0)
                throw new Exception("Для импорта нужна пустая таблица.");

            TableRoles.Add(RoleConst.Таблица);

            using (var db = App.Schema.SqlDB.GetDbManager())
            {
                db.SetCommand(
            @"
            SELECT *,
            CASE
              WHEN (SELECT count(*) FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE K
            WHERE K.COLUMN_NAME=C.COLUMN_NAME AND
              K.TABLE_NAME=" + tableName.AsSQL() + @" AND
              SUBSTRING(K.CONSTRAINT_NAME,1,4)='PK__')=1 THEN 1
              ELSE 0
              END IsKey
            FROM INFORMATION_SCHEMA.COLUMNS C WHERE TABLE_NAME=" + tableName.AsSQL() + " order by ORDINAL_POSITION");

                var columns = db.ExecuteDataTable();

                foreach (DataRow row in columns.Rows)
                {
                    var c = new SchemaTableColumn();
                    c.Position = (int)row["ORDINAL_POSITION"];
                    c.Name = row["COLUMN_NAME"].ToString();
                    c.ColumnRoles.Add(RoleConst.Таблица_Колонка);
                    if ((int)row["IsKey"] == 1)
                        c.ColumnRoles.Add(RoleConst.Таблица_Ключ);
                    /*
                    bit
                    datetime
                    decimal
                    int
                    money
                    nvarchar
                    uniqueidentifier
                    varbinary
                     */
                    var dataType = row["DATA_TYPE"].ToString().ToLower();

                    if (dataType == "int")
                    {
                        c.DataType = new IntDataType() { Column = c };
                    }
                    else
                        if (dataType == "bit")
                    {
                        c.DataType = new BitDataType() { Column = c };
                    }
                    else
                            if (dataType == "datetime")
                    {
                        c.DataType = new DateTimeDataType() { Column = c };
                    }
                    else
                                if (dataType == "money")
                    {
                        c.DataType = new MoneyDataType() { Column = c };
                    }
                    else
                                    if (dataType == "uniqueidentifier")
                    {
                        c.DataType = new GuidDataType() { Column = c };
                    }
                    else
                                        if (dataType == "decimal")
                    {
                        c.DataType = new DecimalDataType() { Column = c, Scale = (int)row["NUMERIC_SCALE"], Precision = (byte)row["NUMERIC_PRECISION"] };
                    }
                    else
                                        if (dataType == "nvarchar" || dataType == "varchar" || dataType == "char" || dataType == "nchar")
                    {
                        c.DataType = new StringDataType() { MaxSize = (int)row["CHARACTER_MAXIMUM_LENGTH"] == -1 ? 0 : (int)row["CHARACTER_MAXIMUM_LENGTH"], Column = c };
                    }
                    else
                                            if (dataType == "binary" || dataType == "varbinary")
                    {
                        c.DataType = new StringDataType() { MaxSize = (int)row["CHARACTER_MAXIMUM_LENGTH"] == -1 ? 0 : (int)row["CHARACTER_MAXIMUM_LENGTH"], Column = c };
                    }
                    else
                        throw new Exception("Неизвестный тип данных " + dataType);

                    c.IsNotNullable = row["IS_NULLABLE"].ToString() == "NO";
                    c.Table = this;
                    Columns.Add(c);

                }
            }
        }
Exemplo n.º 4
0
        public SchemaTable GetProvodkasTable()
        {
            if (IsLogTable || IsProvodkasTable)
                throw new Exception("internal error 23A598AB");

            //if (!TableRoles.Contains(RoleConst.ВложеннаяТаблица))
            //    throw new Exception("internal error 86D606F2");

            if (provodkasTable == null)
            {
                provodkasTable = new SchemaTable();

                provodkasTable.ID = Guid.NewGuid();
                provodkasTable.IsProvodkasTable = true;
                provodkasTable.IsLogTable = false;
                provodkasTable.Name = provodkasPrefix + Name;

                var c = new SchemaTableColumn();
                c.Name = "tableRecordID";
                c.DataType = new GuidDataType() { Column = c };
                c.IsNotNullable = true;
                c.Table = provodkasTable;
                provodkasTable.Columns.Add(c);

                c = new SchemaTableColumn();
                c.Name = "provodkaRecordID";
                c.DataType = new GuidDataType() { Column = c };
                c.IsNotNullable = true;
                c.Table = provodkasTable;
                provodkasTable.Columns.Add(c);

                c = new SchemaTableColumn();
                c.Name = "registrID";
                c.DataType = new GuidDataType() { Column = c };
                c.IsNotNullable = true;
                c.Table = provodkasTable;
                provodkasTable.Columns.Add(c);
            }
            return provodkasTable;
        }
Exemplo n.º 5
0
 public SchemaTableColumn GetPrimaryKeyColumn()
 {
     if (cached_PrimaryKeyColumn == null)
     {
         foreach (var col in Columns)
         {
             if (col.ColumnRoles.Contains(RoleConst.Таблица_Ключ))
             {
                 cached_PrimaryKeyColumn = col;
                 break;
             }
         }
     }
     return cached_PrimaryKeyColumn;
 }
Exemplo n.º 6
0
        public SchemaTable GetLogTable()
        {
            if (IsLogTable || IsProvodkasTable)
                throw new Exception("internal error 98AB23A5");

            if (logTable == null)
            {
                logTable = App.Schema.GetObject<SchemaTable>(ID);

                logTable.ID = Guid.NewGuid();
                logTable.IsLogTable = true;
                logTable.Name = logPrefix + Name;

                var toDelete = new List<SchemaTableColumn>();
                foreach (var col in logTable.Columns)
                {
                    if (col.Name == "__lockuser__" || col.Name == "__locksession__" || col.Name == "__locktime__")
                        toDelete.Add(col);

                    if (col.Name == "__timestamp__")
                        col.DataType = new BinaryDataType() { MaxLength = 8 };

                }

                toDelete.ForEach(col => logTable.Columns.Remove(col));

                if (logTable.TableRoles.Contains(RoleConst.ВложеннаяТаблица))
                    if (GetColumnByName("__mastertimestamp__") == null)
                    {
                        var c = new SchemaTableColumn();
                        c.Position = Columns.Count;
                        c.Name = "__mastertimestamp__";
                        c.DataType = new BinaryDataType() { MaxLength = 8 };
                        c.IsNotNullable = false;
                        c.Table = logTable;
                        logTable.Columns.Add(c);
                    }

            }
            return logTable;
        }
Exemplo n.º 7
0
 public override void firePropertyChanged(string propertyName)
 {
     columnsByName.Clear();
     logTable = null;
     cached_PrimaryKeyColumn = null;
     base.firePropertyChanged(propertyName);
 }
Exemplo n.º 8
0
 public bool CanAcceptSqlValueFromColumn(SchemaTableColumn valueColumn)
 {
     return DataType.CanAcceptSqlValueFromDataType(valueColumn.DataType);
 }