Exemplo n.º 1
0
 /// <summary>
 /// Получает текущее связанное значение
 /// </summary>
 /// <param name="attribute"></param>
 /// <returns></returns>
 public PgAtM.PgAttributeVariantM GetRefValue(PgAtM.PgAttributeM attribute)
 {
     if (attribute == null)
     {
         return(null);
     }
     if ((attribute.Field as PgM.PgFieldM).RefType == AbsM.ERefType.None)
     {
         return(null);
     }
     if (attribute.Variants == null)
     {
         return(null);
     }
     if (attribute.Value == null)
     {
         return(null);
     }
     foreach (var item in attribute.Variants)
     {
         // Ищим подходящий элемент для текущей записи
         if (item.CheckValue(attribute.Value))
         {
             return(item);
         }
     }
     return(null);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Используется для работы с историей
        /// </summary>
        /// <param name="table">Таблица для которой загружается история</param>
        /// <param name="idObject">Идентификатор объекта для которой загружается история</param>
        /// <param name="loadFromHistory">Использовать для загрузки атрибутов таблицу истории</param>
        /// <param name="idHistoryTable">Идентификатор таблицы истории из которой загружаются атрибуты</param>
        /// <param name="idHistoryObject">Идентификатор объекта в таблице истории</param>
        /// <param name="isReadOnly">Открываются ли атрибуты только для чтения</param>
        /// <param name="IsDebug">Запускается ли работа с атрибутами в режиме отладки</param>
        public PgAttributesListVM(PgM.PgTableBaseM table, object idObject, bool loadFromHistory, int?idHistoryTable = null, int?idHistoryObject = null, bool isReadOnly = false, bool IsDebug = false, bool loadStyle = true)
        {
            LoadStyle = loadStyle;
            if (loadFromHistory)
            {
                LoadFromHistory = loadFromHistory;
                IdHistoryTable  = (int)idHistoryTable;
                IdHistoryObject = (int)idHistoryObject;
            }
            _isDebug = IsDebug;
            _connect = ((PgVM.PgDataRepositoryVM)table.Source).Connect;
            if (isReadOnly || table.IsReadOnly || !table.CanWrite)
            {
                _isReadOnly = true;
            }
            _table = table;
            if (!String.IsNullOrEmpty(_table.GeomField))
            {
                _geomAttribute = new PgAtM.PgAttributeM(this, (PgM.PgFieldM)_table.Fields.First(p => p.Name == _table.GeomField));
            }

            _pkAttribute = new PgAtM.PgAttributeM(this, (PgM.PgFieldM)_table.PrimaryKeyField, idObject);
            if (idObject == null)
            {
                _isNew = true;
            }

            _attributes = new ObservableCollection <PgAtM.PgAttributeM>();
        }
Exemplo n.º 3
0
        public PgAttributeVariantM(PgAttributeM source, string text, PgStyleObjectM style, object id)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            _id     = id;
            _source = source;
            _text   = text;
            PgAttributesListVM attrList = this.Source.Source as PgAttributesListVM;

            if (style != null && attrList.LoadStyle)
            {
                switch (((PgM.PgTableBaseM)source.Field.Table).GeomType)
                {
                case AbsM.EGeomType.Point:
                    _preview = GetPreviewStylePoint(style);
                    break;

                case AbsM.EGeomType.Line:
                    _preview = GetPreviewStyleLine(style);
                    break;

                case AbsM.EGeomType.Polygon:
                    _preview = GetPreviewStylePoligon(style);
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 4
0
        internal static object GetValue(PgAttributeM item)
        {
            switch (item.Field.Type)
            {
            case AbsM.EFieldType.Integer:
            {
                return(ExtraFunctions.Converts.To <int?>(item.Value));
            }

            case AbsM.EFieldType.Text:
            {
                return(ExtraFunctions.Converts.To <string>(item.Value));
            }

            case AbsM.EFieldType.Date:
            case AbsM.EFieldType.DateTime:
            {
                return(ExtraFunctions.Converts.To <DateTime?>(item.Value));
            }

            case AbsM.EFieldType.Real:
            {
                return(ExtraFunctions.Converts.To <double?>(item.Value));
            }

            default:
            {
                return(null);
            }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Загрузка связанных таблиц
        /// </summary>
        private void LoadRelatedTables(object idObject)
        {
            if (idObject != null && (_table.Type == AbsM.ETableType.Data || _table.Type == AbsM.ETableType.MapLayer))
            {
                RelatedTables.Clear();
                using (SqlWork sqlWork = new SqlWork(Connect))
                {
                    // Запрос для получения идентификаторов связанных таблиц
                    sqlWork.sql = String.Format(@"SELECT tfi.id_table, tfi.name_db, tfi.ref_field
                                    FROM sys_scheme.table_field_info tfi 
                                    INNER JOIN sys_scheme.table_info ti ON tfi.id_table = ti.id
                                    INNER JOIN sys_scheme.table_type_table ttt ON ttt.id = ti.type
                                    WHERE tfi.ref_table = {0} AND (ttt.id = 1 OR ttt.id = 4)", _table.Id);
                    sqlWork.ExecuteReader();
                    while (sqlWork.CanRead())
                    {
                        int    idTable    = sqlWork.GetInt32("id_table");
                        string colName    = sqlWork.GetString("name_db");
                        int    refFieldId = sqlWork.GetInt32("ref_field");

                        PgM.PgFieldM field = _table.Fields.FirstOrDefault(f => f.Id == refFieldId) as PgM.PgFieldM;

                        if (field != null && field.Table != null && field.Table.Id is int &&
                            classesOfMetods.getRefTableRight(_table.Id, (int)field.Table.Id))
                        {
                            PgAtM.PgAttributeM attr        = _attributesListVM.Attributes.FirstOrDefault(a => a.Field == field);
                            String             filterValue = null;
                            if (attr.Value != null)
                            {
                                filterValue = attr.Value.ToString();
                            }

                            PgM.PgTableBaseM pgTable = _table.Source.Tables.FirstOrDefault(p => (int)p.Id == idTable) as PgM.PgTableBaseM;
                            if (pgTable != null)
                            {
                                FilterRelationModel filterRM = new FilterRelationModel()
                                {
                                    Type    = TypeRelation.ELEMENT,
                                    Element = new FilterElementModel()
                                    {
                                        Column = colName,
                                        Type   = TypeOperation.Equal,
                                        Value  = filterValue
                                    }
                                };
                                RelatedTables.Add(new PgTV.PgTableViewVM(pgTable, filterRM));
                            }
                        }
                    }
                    sqlWork.Close();
                }
            }
            OnPropertyChanged("HasRelatedTables");
        }
Exemplo n.º 6
0
 public PgAttributeIntervalM(PgAttributeM source, string text, PgStyleObjectM style, object id, double min, double max)
     : base(source, text, style, id)
 {
     if (min != null)
     {
         _min = min;
     }
     if (max != null)
     {
         _max = max;
     }
 }
Exemplo n.º 7
0
 void ClearValueInField(object param = null)
 {
     if (CanClearValueInField(param))
     {
         PgAtM.PgAttributeM attr = null;
         if (param is CommandEventParameter)
         {
             CommandEventParameter commEvtParam = param as CommandEventParameter;
             attr = commEvtParam.CommandParameter as PgAtM.PgAttributeM;
         }
         else if (param is PgAtM.PgAttributeM)
         {
             attr = param as PgAtM.PgAttributeM;
         }
         attr.Value = null;
     }
 }
Exemplo n.º 8
0
 bool CanClearValueInField(object param = null)
 {
     if (_isReadOnly == true)
     {
         return(false);
     }
     PgAtM.PgAttributeM attr = null;
     if (param is CommandEventParameter)
     {
         CommandEventParameter commEvtParam = param as CommandEventParameter;
         attr = commEvtParam.CommandParameter as PgAtM.PgAttributeM;
     }
     else if (param is PgAtM.PgAttributeM)
     {
         attr = param as PgAtM.PgAttributeM;
     }
     return(attr != null && attr.Value != null);
 }
Exemplo n.º 9
0
        /// <summary>
        /// Работы с атрибутами объекта
        /// </summary>
        /// <param name="table">Ссылка на таблицу</param>
        /// <param name="idObject">Идентификатор объекта с атрибутами.
        /// Если он null создается новый</param>
        /// <exception cref="ArgumentNullException"/>
        public PgAttributesListVM(PgAtVM.PgAttributesVM attributeVM, object idObject, bool loadStyle = true)
        {
            LoadStyle    = loadStyle;
            _attributeVM = attributeVM;

            _isDebug    = attributeVM.IsDebug;
            _connect    = attributeVM.Connect;
            _isReadOnly = attributeVM.IsReadOnly;
            _table      = attributeVM.Table;
            if (!String.IsNullOrEmpty(_table.GeomField))
            {
                _geomAttribute = new PgAtM.PgAttributeM(this, (PgM.PgFieldM)_table.Fields.First(p => p.Name == _table.GeomField));
            }

            _pkAttribute = new PgAtM.PgAttributeM(this, (PgM.PgFieldM)_table.PrimaryKeyField, idObject);
            if (idObject == null)
            {
                _isNew = true;
            }

            _attributes = new ObservableCollection <PgAtM.PgAttributeM>();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Загрузка атрибутов из таблицы истории
        /// </summary>
        /// <param name="idHistoryTable"></param>
        /// <param name="idHistoryObject"></param>
        public void LoadAttributesFromHistoryTable(int idHistoryTable, int idHistoryObject)
        {
            var addAttributes = new List <PgAtM.PgAttributeM>();

            foreach (PgM.PgFieldM item in _table.Fields)
            {
                if (item.Type != AbsM.EFieldType.Geometry &&
                    PkAttribute.Field != item &&
                    item.IsVisible)
                {
                    var attribute = FindAttribute(item);
                    if (attribute == null)
                    {
                        attribute = new PgAtM.PgAttributeM(this, item);
                    }
                    addAttributes.Add(attribute);
                }
            }
            ExtraFunctions.Sorts.SortList(Attributes, addAttributes);

            // Список полей основной таблицы
            List <String> columnsInTablelist = new List <string>();
            // Список полей таблицы истории, которые также существуют в основной таблице
            List <String> columnsInHistoryTablelist = new List <string>();

            foreach (PgM.PgFieldM field in _table.Fields)
            {
                columnsInTablelist.Add(field.Name);
            }

            //Получаем список полей в таблице истории, которые также существуют в основной таблице
            using (SqlWork sqlWork = new SqlWork(_connect))
            {
                String sql = String.Format(@"
                    SELECT isc.column_name
                    FROM sys_scheme.table_history_info thi
                    INNER JOIN sys_scheme.table_info ti
                    ON thi.id_table = ti.id
                    INNER JOIN information_schema.columns isc
                    ON isc.table_name = thi.history_table_name AND isc.table_schema = ti.scheme_name
                    WHERE thi.id_history_table = {0} AND  isc.column_name in ('{1}')",
                                           idHistoryTable,
                                           String.Join("', '", columnsInTablelist.ToArray()));

                sqlWork.sql = sql;
                sqlWork.ExecuteReader();
                while (sqlWork.CanRead())
                {
                    columnsInHistoryTablelist.Add(sqlWork.GetString(0));
                }
                sqlWork.Close();
            }

            // Получаем название таблицы истории
            String historyTableName;

            using (SqlWork sqlWork = new SqlWork(_connect))
            {
                sqlWork.sql      = String.Format(@"SELECT thi.history_table_name
                                                            FROM sys_scheme.table_info ti 
                                                            INNER JOIN sys_scheme.table_history_info thi ON ti.id = thi.id_table
                                                            WHERE thi.id_history_table = {0}", idHistoryTable);
                historyTableName = sqlWork.ExecuteScalar().ToString();
            }

            //Получаем значения "После изменения"
            using (SqlWork sqlWork = new SqlWork(_connect))
            {
                String fieldsListForSql = String.Join(", ", columnsInHistoryTablelist.ToArray());
                if (!String.IsNullOrEmpty(_table.GeomField))
                {
                    fieldsListForSql = fieldsListForSql.Replace(
                        _table.GeomField,
                        String.Format(@"st_ASTEXT(st_TRANSFORM(""{0}"", {1})) AS ""{0}""", _table.GeomField, Program.srid));
                }

                sqlWork.sql = String.Format("SELECT {0}, type_operation FROM {1}.{2} WHERE id_history = {3}",
                                            fieldsListForSql,
                                            _table.SchemeName,
                                            historyTableName,
                                            idHistoryObject);
                sqlWork.ExecuteReader();
                if (sqlWork.CanRead())
                {
                    PgHistM.PgHistoryTypeOperation TypeOperation = sqlWork.GetValue <PgHistM.PgHistoryTypeOperation>("type_operation");

                    if (TypeOperation == PgHistM.PgHistoryTypeOperation.Delete)
                    {
                        foreach (PgAtM.PgAttributeM attr in Attributes)
                        {
                            PgAtM.PgAttributeM.SetValue(attr, null);
                        }
                    }
                    else
                    {
                        foreach (PgAtM.PgAttributeM attr in Attributes)
                        {
                            if (columnsInHistoryTablelist.Contains(attr.Field.Name))
                            {
                                PgAtM.PgAttributeM.SetValue(attr, sqlWork.GetValue <object>(attr.Field.Name));
                            }
                        }
                        object value = sqlWork.GetValue <object>(PkAttribute.Field.Name);
                        if (value != null)
                        {
                            PgAtM.PgAttributeM.SetValue(PkAttribute, value);
                        }
                        if (!String.IsNullOrEmpty(_table.GeomField))
                        {
                            object geomvalue = sqlWork.GetValue <object>(GeomAttribute.Field.Name);
                            if (geomvalue != null)
                            {
                                PgAtM.PgAttributeM.SetValue(GeomAttribute, geomvalue);
                            }
                        }
                    }
                }
            }
            GetAttributesVariants(Attributes);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Загружает или обнавляет список атрибутов со связанными справочниками
        /// </summary>
        public void Reload(object param = null)
        {
            if (LoadFromHistory)
            {
                LoadAttributesFromHistoryTable(IdHistoryTable, IdHistoryObject);
            }
            else
            {
                var addAttributes = new List <PgAtM.PgAttributeM>();
                foreach (PgM.PgFieldM item in _table.Fields)
                {
                    if (item.Type != AbsM.EFieldType.Geometry &&
                        PkAttribute.Field != item &&
                        item.IsVisible)
                    {
                        var attribute = FindAttribute(item);
                        if (attribute == null)
                        {
                            attribute = new PgAtM.PgAttributeM(this, item);
                        }
                        addAttributes.Add(attribute);
                    }
                }
                ExtraFunctions.Sorts.SortList(Attributes, addAttributes);

                if (!IsNew) // Если это не новый объект загружаем данные атрибутов из базы
                {
                    string mainSql     = GetSQLQuery(_table, string.Format(@"""{0}"" = :{0}", PkAttribute.Field.Name));
                    var    arrayParams = new IParams[]
                    {
                        new Interfaces.Params(@":" + PkAttribute.Field.Name, PkAttribute.Value, (PkAttribute.Field as PgM.PgFieldM).DbType),
                        new Interfaces.Params(@":srid", Program.srid, System.Data.DbType.Int32)
                    };

                    using (var sqlCmd = new SqlWork(_connect, _isDebug))
                    {
                        sqlCmd.sql = mainSql;
                        if (sqlCmd.ExecuteReader(arrayParams) && sqlCmd.CanRead())
                        {
                            foreach (var item in Attributes)
                            {
                                PgAtM.PgAttributeM.SetValue(item, sqlCmd.GetValue <object>(item.Field.Name));
                            }
                            object pkvalue = sqlCmd.GetValue <object>(PkAttribute.Field.Name);
                            if (pkvalue != null)
                            {
                                PgAtM.PgAttributeM.SetValue(PkAttribute, pkvalue);
                            }

                            if (!String.IsNullOrEmpty(_table.GeomField))
                            {
                                object geomvalue = sqlCmd.GetValue <object>(GeomAttribute.Field.Name);
                                if (geomvalue != null)
                                {
                                    PgAtM.PgAttributeM.SetValue(GeomAttribute, geomvalue);
                                }
                            }
                        }
                    }
                }
                var atributes = Attributes;
                GetAttributesVariants(atributes);
            }
        }
Exemplo n.º 12
0
 public PgAttributeReferenceM(PgAttributeM source, string text, PgStyleObjectM style, object id)
     : base(source, text, style, id)
 {
 }
Exemplo n.º 13
0
 /// <summary>
 /// Принудительно заполняет поле значением
 /// </summary>
 /// <param name="item">Атрибут</param>
 /// <param name="value">Новое значение</param>
 internal static void SetValue(PgAttributeM item, object value)
 {
     item.OnPropertyChanged(ref item._value, value, () => item.Value);
 }