///<summary> /// Обновление информации в выпадающем списке ///</summary> private void UpdateItems() { comboBoxReason.Items.Clear(); comboBoxReason.Items.Add("N/A"); if (_typeItemsCollection != null) { foreach (IDictionaryItem dic in _typeItemsCollection.GetValidEntries().OfType <IDictionaryItem>().OrderBy(i => i.ToString())) { comboBoxReason.Items.Add(dic); } if (_lastSelectedItemId > 0) { comboBoxReason.SelectedItem = _typeItemsCollection.GetItemById(_lastSelectedItemId); } } if (_selectedItem != null) { comboBoxReason.SelectedItem = _selectedItem; } else { comboBoxReason.Text = defaultText; } }
/* * Глобальные коллекции */ #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); } } }
/// <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); } } }
///<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; }