Ejemplo n.º 1
0
        ///<summary>
        /// ќбновл¤ет информацию, сожержащуюс¤ в списке
        ///</summary>
        public void UpdateInformation()
        {
            DrawItem += ATAChapterComboBox_DrawItem;
            if (_ataChapterCollection == null)
            {
                _ataChapterCollection = new AtaChapterCollection();
            }
            _ataChapterCollection.Clear();
            IDictionaryCollection atas = GlobalObjects.CasEnvironment.GetDictionary <AtaChapter>();

            foreach (AtaChapter ata in atas)
            {
                _ataChapterCollection.Add(ata);
            }
            _ataChapterDictionaries = new Dictionary <string, AtaChapter>();
            List <string> ataChapters = new List <string>();

            _ataChapterDictionaries.Clear();
            for (int i = 0; i < _ataChapterCollection.Count; i++)
            {
                ataChapters.Add(_ataChapterCollection[i].ShortName + " " + _ataChapterCollection[i].FullName);
                _ataChapterDictionaries.Add(ataChapters[i], _ataChapterCollection[i]);
            }

            ataChapters.Sort();

            Items.Clear();
            Items.AddRange(ataChapters.ToArray());
            Text          = defaultText;
            DropDownStyle = ComboBoxStyle.DropDown;
            DrawMode      = DrawMode.OwnerDrawFixed;
            LostFocus    += ATAChapterComboBoxLostFocus;
            GotFocus     += ATAChapterComboBoxGotFocus;
        }
Ejemplo n.º 2
0
        /*
         * Глобальные коллекции
         */

        #region public void Save(BaseSmartCoreObject saveObject)
        public void Save(BaseEntityObject saveObject)
        {
            if (saveObject == null)
            {
                return;
            }

            saveObject.CorrectorId = _casEnvironment.IdentityUser.ItemId;

            var type = AuditOperation.Created;

            if (saveObject.ItemId > 0)
            {
                type = AuditOperation.Changed;
            }

            CasEnvironment.Keeper.Save(saveObject);
            _auditRepository.WriteAsync(saveObject, type, _casEnvironment.IdentityUser);

            if (saveObject is AbstractDictionary)
            {
                IDictionaryCollection col = CasEnvironment.GetDictionary(saveObject.GetType());

                if (col == null)
                {
                    return;
                }
                AbstractDictionary dict = (AbstractDictionary)col.GetItemById(saveObject.ItemId);
                if (dict == null || saveObject.ItemId != dict.ItemId)
                {
                    col.Add(saveObject);
                }
                else
                {
                    dict.SetProperties((AbstractDictionary)saveObject);
                }
            }
            if (saveObject is Store)
            {
                Store o = CasEnvironment.Stores.GetItemById(saveObject.ItemId);
                if (o == null || saveObject.ItemId != o.ItemId)
                {
                    CasEnvironment.Stores.Add((Store)saveObject);
                }
            }
            if (saveObject is BaseComponent)
            {
                BaseComponent o = _componentCore.GetBaseComponentById(saveObject.ItemId);
                if (o == null || saveObject.ItemId != o.ItemId)
                {
                    CasEnvironment.BaseComponents.Add((BaseComponent)saveObject);
                }
            }
        }
Ejemplo n.º 3
0
        ///<summary>
        /// Обновление информации в выпадающем списке
        ///</summary>
        private void UpdateInformation()
        {
            if (_typeItemsCollection != null)
            {
                _typeItemsCollection.CollectionChanged -= DictionaryCollectionChanged;
            }

            if (_type.IsSubclassOf(typeof(AbstractDictionary)))
            {
                try
                {
                    if (GlobalObjects.CasEnvironment != null)
                    {
                        _typeItemsCollection = GlobalObjects.CasEnvironment.GetDictionary(_type);
                    }
                    else
                    {
                        _typeItemsCollection = GlobalObjects.CaaEnvironment.GetDictionary(_type);
                    }
                }
                catch (Exception)
                {
                    _typeItemsCollection = null;
                }
            }

            if (_type.IsSubclassOf(typeof(StaticDictionary)))
            {
                try
                {
                    PropertyInfo p = _type.GetProperty("Items");

                    ConstructorInfo  ci       = _type.GetConstructor(new Type[0]);
                    StaticDictionary instance = (StaticDictionary)ci.Invoke(null);
                    _typeItemsCollection = (IDictionaryCollection)p.GetValue(instance, null);
                }
                catch (Exception)
                {
                    _typeItemsCollection = null;
                }
            }

            UpdateItems();

            LostFocus += ComboBoxLostFocus;
            GotFocus  += ATAChapterComboBoxGotFocus;

            if (_typeItemsCollection != null)
            {
                _typeItemsCollection.CollectionChanged += DictionaryCollectionChanged;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Новый метод для сохранения объектов
        /// </summary>
        /// <param name="saveObject">Сохраняемый объект</param>
        /// <param name="saveChild">Сохранять дочерние объекты</param>
        /// <param name="saveForced">Сохранять свойтсва, помеченные как "принудительные"</param>
        public void SaveAll(BaseEntityObject saveObject, bool saveChild = false, bool saveForced = false)
        {
            if (saveObject == null)
            {
                return;
            }

            CasEnvironment.Keeper.SaveAll(saveObject, saveChild, saveForced);

            if (saveObject is AbstractDictionary)
            {
                IDictionaryCollection col = CasEnvironment.GetDictionary(saveObject.GetType());

                if (col == null)
                {
                    return;
                }
                AbstractDictionary dict = (AbstractDictionary)col.GetItemById(saveObject.ItemId);
                if (dict == null || saveObject.ItemId != dict.ItemId)
                {
                    col.Add(saveObject);
                }
                else
                {
                    dict.SetProperties((AbstractDictionary)saveObject);
                }
            }
            if (saveObject is Store)
            {
                Store o = CasEnvironment.Stores.GetItemById(saveObject.ItemId);
                if (o == null || saveObject.ItemId != o.ItemId)
                {
                    CasEnvironment.Stores.Add((Store)saveObject);
                }
            }
            if (saveObject is BaseComponent)
            {
                BaseComponent o = _componentCore.GetBaseComponentById(saveObject.ItemId);
                if (o == null || saveObject.ItemId != o.ItemId)
                {
                    CasEnvironment.BaseComponents.Add((BaseComponent)saveObject);
                }
            }
        }
Ejemplo n.º 5
0
        public IDictionaryCollection GetInstance()
        {
            if (_collectionType == null)
            {
                throw new Exception("_collectionType: не должен быть null");
            }

            Type @interface = _collectionType.GetInterface(typeof(IDictionaryCollection).Name);

            if (@interface == null)
            {
                throw new Exception("_collectionType: " + _collectionType + " не реализует интерфейс IDictionaryCollection");
            }

            //_collectionType.IsSubclassOf(typeof(CommonCollection<>)) почему то возвращает false

            Type t    = _collectionType;
            bool find = false;

            while (t != null)
            {
                if (t.Name == typeof(CommonCollection <>).Name)
                {
                    find = true;
                    break;
                }
                t = t.BaseType;
            }
            if (find == false)
            {
                throw new Exception("_collectionType: " + _collectionType + " не является наследником BaseItemsCollection<>");
            }

            ConstructorInfo ci = _collectionType.GetConstructor(new Type[0]);

            if (ci == null)
            {
                throw new Exception("Type: " + _collectionType + " не имеет открытого конструктора по умолчанию");
            }

            IDictionaryCollection collection = (IDictionaryCollection)ci.Invoke(null);

            return(collection);
        }
Ejemplo n.º 6
0
        ///<summary>
        /// Обновление информации в выпадающем списке
        ///</summary>
        private void UpdateInformation()
        {
            if (_typeItemsCollection != null)
            {
                _typeItemsCollection.CollectionChanged -= DictionaryCollectionChanged;
            }

            buttonEdit.Visible = !_type.IsSubclassOf(typeof(StaticDictionary));
            AdjustSizes();

            try
            {
                if (_type.IsSubclassOf(typeof(StaticDictionary)))
                {
                    //поиск своиства Items у типа StaticDictionary
                    PropertyInfo p = _type.GetProperty("Items");

                    ConstructorInfo  ci       = _type.GetConstructor(new Type[0]);
                    StaticDictionary instance = (StaticDictionary)ci.Invoke(null);

                    _typeItemsCollection = (IDictionaryCollection)p.GetValue(instance, null);
                }
                if (_type.IsSubclassOf(typeof(AbstractDictionary)))
                {
                    _typeItemsCollection = GlobalObjects.CasEnvironment.GetDictionary(_type);
                }
            }
            catch (Exception)
            {
                _typeItemsCollection = null;
            }

            UpdateItems();

            LostFocus += ComboBoxLostFocus;
            GotFocus  += ATAChapterComboBoxGotFocus;

            if (_typeItemsCollection != null)
            {
                _typeItemsCollection.CollectionChanged += DictionaryCollectionChanged;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Обновляет значения полей
        /// </summary>
        public override void FillControls()
        {
            BeginUpdate();

            if (_typeItemsCollection != null)
            {
                _typeItemsCollection.CollectionChanged -= DictionaryCollectionChanged;
            }

            checkedListBoxItems.Items.Clear();
            checkedListBoxItems.SelectedIndexChanged -= CheckedListBoxItemsSelectedIndexChanged;
            checkBoxSelectAll.CheckedChanged         -= CheckBoxSelectAllCheckedChanged;

            if (Filter != null)
            {
                Type filterType = Filter.GetType();
                if (filterType.IsGenericType)
                {
                    Type genericArgumentType = filterType.GetGenericArguments().FirstOrDefault();
                    if (genericArgumentType.IsSubclassOf(typeof(AbstractDictionary)))
                    {
                        try
                        {
                            if (GlobalObjects.CasEnvironment != null)
                            {
                                _typeItemsCollection = GlobalObjects.CasEnvironment.GetDictionary(genericArgumentType);
                            }
                            else
                            {
                                _typeItemsCollection = GlobalObjects.CaaEnvironment.GetDictionary(genericArgumentType);
                            }
                        }
                        catch (Exception)
                        {
                            _typeItemsCollection = null;
                        }
                    }
                    if (genericArgumentType.IsSubclassOf(typeof(StaticDictionary)))
                    {
                        try
                        {
                            PropertyInfo p = genericArgumentType.GetProperty("Items");

                            ConstructorInfo  ci       = genericArgumentType.GetConstructor(new Type[0]);
                            StaticDictionary instance = (StaticDictionary)ci.Invoke(null);
                            _typeItemsCollection = (IDictionaryCollection)p.GetValue(instance, null);
                        }
                        catch (Exception)
                        {
                            _typeItemsCollection = null;
                        }
                    }
                }

                if (_typeItemsCollection != null)
                {
                    //в CheckListBox добавляются только элементы используемые в фильтруемых
                    //объектах
                    if (_filterValues != null && _filterValues.Length > 0)
                    {
                        foreach (IDictionaryItem dic in _typeItemsCollection.OfType <IDictionaryItem>().Where(i => _filterValues.Contains(i)))
                        {
                            checkedListBoxItems.Items.Add(dic, Filter.Values.Contains(dic));
                        }

                        int countValidItems = Filter.GetValidValuesCount();
                        if (countValidItems == 0)
                        {
                            checkBoxSelectAll.CheckState = CheckState.Unchecked;
                        }
                        else if (countValidItems == _filterValues.Length)
                        {
                            checkBoxSelectAll.CheckState = CheckState.Checked;
                        }
                        else
                        {
                            checkBoxSelectAll.CheckState = CheckState.Indeterminate;
                        }
                    }
                }
            }

            checkedListBoxItems.SelectedIndexChanged += CheckedListBoxItemsSelectedIndexChanged;
            checkBoxSelectAll.CheckedChanged         += CheckBoxSelectAllCheckedChanged;

            if (_typeItemsCollection != null)
            {
                _typeItemsCollection.CollectionChanged += DictionaryCollectionChanged;
            }

            EndUpdate();
        }
Ejemplo n.º 8
0
 public void Add(Type t, IDictionaryCollection dictionary)
 {
     _dictionaries.Add(t, dictionary);
 }
Ejemplo n.º 9
0
        private void ComboBoxReasonTextUpdate(object sender, EventArgs e)
        {
            _filterString = treeCombobox.Text;

            if (string.IsNullOrEmpty(_filterString))
            {
                UpdateItems();
            }
            else
            {
                treeCombobox.Nodes.Clear();
                treeCombobox.Nodes.Add("N/A");

                if (_typeItemsCollection != null)
                {
                    try
                    {
                        if (_type.IsSubclassOf(typeof(StaticTreeDictionary)))
                        {
                            if (_rootNodesNames == null || _rootNodesNames.Length <= 0)
                            {
                                //поиск своиства Roots у типа StaticDictionary
                                PropertyInfo p = _type.GetProperty("Items");

                                ConstructorInfo  ci       = _type.GetConstructor(new Type[0]);
                                StaticDictionary instance = (StaticDictionary)ci.Invoke(null);

                                IDictionaryCollection items = (IDictionaryCollection)p.GetValue(instance, null);

                                foreach (IDictionaryTreeItem dic in items
                                         .OfType <IDictionaryTreeItem>()
                                         .Where(i => i.ToString().ToLowerInvariant().Contains(_filterString.ToLowerInvariant())))
                                {
                                    treeCombobox.Nodes.Add(new TreeNode {
                                        Text = dic.ToString(), Name = dic.ToString(), Tag = dic
                                    });
                                }

                                buttonEdit.Enabled = false;
                            }
                            else
                            {
                                ConstructorInfo ci       = _type.GetConstructor(new Type[0]);
                                object          instance = ci.Invoke(null);

                                foreach (string rootNodeName in _rootNodesNames)
                                {
                                    //поиск своиства Roots у типа StaticDictionary
                                    FieldInfo p = _type.GetField(rootNodeName);
                                    if (p == null)
                                    {
                                        continue;
                                    }
                                    StaticTreeDictionary currentRoot = p.GetValue(instance) as StaticTreeDictionary;
                                    StaticTreeDictionary currentNode = currentRoot;
                                    if (currentNode == null)
                                    {
                                        return;
                                    }
                                    while (currentNode != null)
                                    {
                                        if (currentNode.ToString().ToLowerInvariant().Contains(_filterString.ToLowerInvariant()))
                                        {
                                            TreeNode newNode = new TreeNode
                                            {
                                                Text = currentNode.ToString(),
                                                Name = currentNode.ToString(),
                                                Tag  = currentNode,
                                            };
                                            Nodes.Add(newNode);
                                        }
                                        if (currentNode.Children.Count > 0)
                                        {
                                            //Если у выбранного узла есть подузлы - осуществляется переход на первый подузел
                                            currentNode = currentNode.Children[0] as StaticTreeDictionary;
                                        }
                                        else
                                        {
                                            //У выбранного узла подузлов нет
                                            if (currentNode.Next != null)
                                            {
                                                //Если есть след. узел на этом уровне - переход на него
                                                currentNode = currentNode.Next;
                                            }
                                            else
                                            {
                                                //На данном уровне след. узла нет.
                                                StaticTreeDictionary parent = currentNode.Parent;
                                                while (parent != null && parent != currentRoot)
                                                {
                                                    //Переход вверх по дереву до тех пор, пока на уровне не появится след.узел
                                                    //переход на след. узел на верхнем уровне
                                                    if (parent.Next != null)
                                                    {
                                                        currentNode = parent.Next;
                                                        break;
                                                    }
                                                    parent = parent.Parent;
                                                }

                                                if (parent == null || parent == currentRoot)
                                                {
                                                    currentNode = null;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (_type.IsSubclassOf(typeof(AbstractDictionary)))
                        {
                            foreach (IDictionaryItem dic in _typeItemsCollection)
                            {
                                treeCombobox.Nodes.Add(new TreeNode {
                                    Text = dic.ToString(), Tag = dic
                                });
                            }
                        }
                    }
                    catch (Exception)
                    {
                        _typeItemsCollection = null;
                    }
                }
                treeCombobox.DropDownStyle  = ComboBoxStyle.DropDown;
                treeCombobox.SelectionStart = _filterString.Length;
            }
        }
Ejemplo n.º 10
0
        ///<summary>
        /// Обновление информации в выпадающем списке
        ///</summary>
        private void UpdateItems()
        {
            treeCombobox.Nodes.Clear();
            treeCombobox.Nodes.Add("N/A");
            if (_typeItemsCollection != null)
            {
                try
                {
                    if (_type.IsSubclassOf(typeof(StaticTreeDictionary)))
                    {
                        if (_rootNodesNames == null || _rootNodesNames.Length <= 0)
                        {
                            //поиск своиства Roots у типа StaticDictionary
                            PropertyInfo p = _type.GetProperty("Roots");

                            ConstructorInfo  ci       = _type.GetConstructor(new Type[0]);
                            StaticDictionary instance = (StaticDictionary)ci.Invoke(null);

                            IDictionaryCollection roots = (IDictionaryCollection)p.GetValue(instance, null);

                            StaticTreeDictionary currentNode = roots[0] as StaticTreeDictionary;
                            if (currentNode == null)
                            {
                                return;
                            }
                            TreeNode currentParent = null;
                            while (currentNode != null)
                            {
                                TreeNode newNode = new TreeNode {
                                    Text = currentNode.ToString(), Name = currentNode.ToString(),
                                };
                                //if (currentNode.Children.Count == 0)
                                newNode.Tag = currentNode;

                                if (currentParent == null)
                                {
                                    Nodes.Add(newNode);
                                }
                                else
                                {
                                    currentParent.Nodes.Add(newNode);
                                }

                                if (currentNode.Children.Count > 0)
                                {
                                    //Если у выбранного узла есть подузлы - осуществляется переход на первый подузел
                                    currentNode   = currentNode.Children[0] as StaticTreeDictionary;
                                    currentParent = newNode;
                                }
                                else
                                {
                                    //У выбранного узла подузлов нет
                                    if (currentNode.Next != null)
                                    {
                                        //Если есть след. узел на этом уровне - переход на него
                                        currentNode = currentNode.Next;
                                    }
                                    else
                                    {
                                        //На данном уровне след. узла нет.
                                        StaticTreeDictionary parent = currentNode.Parent;
                                        while (parent != null)
                                        {
                                            currentParent = currentParent != null ? currentParent.Parent : null;
                                            //Переход вверх по дереву до тех пор, пока на уровне не появится след.узел
                                            //переход на след. узел на верхнем уровне
                                            if (parent.Next != null)
                                            {
                                                currentNode = parent.Next;
                                                break;
                                            }
                                            parent = parent.Parent;
                                        }

                                        if (parent == null)
                                        {
                                            currentNode = null;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            ConstructorInfo ci       = _type.GetConstructor(new Type[0]);
                            object          instance = ci.Invoke(null);

                            foreach (string rootNodeName in _rootNodesNames)
                            {
                                //поиск своиства Roots у типа StaticDictionary
                                //PropertyInfo[] typeProperties = _type.GetField(BindingFlags.Public | BindingFlags.Static);
                                FieldInfo p = _type.GetField(rootNodeName);
                                //p = typeProperties.FirstOrDefault(prop => prop.Name == rootNodeName);
                                if (p == null)
                                {
                                    continue;
                                }
                                StaticTreeDictionary currentRoot = p.GetValue(instance) as StaticTreeDictionary;
                                StaticTreeDictionary currentNode = currentRoot;
                                if (currentNode == null)
                                {
                                    return;
                                }
                                TreeNode currentParent = null;
                                while (currentNode != null)
                                {
                                    TreeNode newNode = new TreeNode {
                                        Text = currentNode.ToString(), Name = currentNode.ToString(),
                                    };
                                    //if (currentNode.Children.Count == 0)
                                    newNode.Tag = currentNode;

                                    if (currentParent == null)
                                    {
                                        Nodes.Add(newNode);
                                    }
                                    else
                                    {
                                        currentParent.Nodes.Add(newNode);
                                    }

                                    if (currentNode.Children.Count > 0)
                                    {
                                        //Если у выбранного узла есть подузлы - осуществляется переход на первый подузел
                                        currentNode   = currentNode.Children[0] as StaticTreeDictionary;
                                        currentParent = newNode;
                                    }
                                    else
                                    {
                                        if (currentNode == currentRoot)
                                        {
                                            break;
                                        }
                                        //У выбранного узла подузлов нет
                                        if (currentNode.Next != null)
                                        {
                                            //Если есть след. узел на этом уровне - переход на него
                                            currentNode = currentNode.Next;
                                        }
                                        else
                                        {
                                            //На данном уровне след. узла нет.
                                            StaticTreeDictionary parent = currentNode.Parent;
                                            while (parent != null && parent != currentRoot)
                                            {
                                                currentParent = currentParent != null ? currentParent.Parent : null;
                                                //Переход вверх по дереву до тех пор, пока на уровне не появится след.узел
                                                //переход на след. узел на верхнем уровне
                                                if (parent.Next != null)
                                                {
                                                    currentNode = parent.Next;
                                                    break;
                                                }
                                                parent = parent.Parent;
                                            }

                                            if (parent == null || parent == currentRoot)
                                            {
                                                currentNode = null;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (_type.IsSubclassOf(typeof(AbstractDictionary)))
                    {
                        foreach (IDictionaryItem dic in _typeItemsCollection)
                        {
                            treeCombobox.Nodes.Add(new TreeNode {
                                Text = dic.ToString(), Tag = dic
                            });
                        }
                    }

                    if (_lastSelectedItemId > 0)
                    {
                        treeCombobox.SelectedItem = _typeItemsCollection.GetItemById(_lastSelectedItemId);
                    }
                }
                catch (Exception)
                {
                    _typeItemsCollection = null;
                }
            }

            if (_selectedItem != null)
            {
                treeCombobox.SelectedItem = _selectedItem;
            }
            else
            {
                treeCombobox.Text = defaultText;
            }
            treeCombobox.DropDownStyle = ComboBoxStyle.DropDown;
        }