private void GetTargets(ITreeNode targetData, ref ShopCatNode targetShopCatNode, ref TreeNodes targetCollection) { if (targetData == null) { var shopRoot = treeShop.DataSource as TreeNodes; targetCollection = shopRoot; } else if (targetData is ShopCatNode) { targetShopCatNode = targetData as ShopCatNode; targetCollection = targetShopCatNode.Childs; } else if (targetData is ShopProdNode) { targetShopCatNode = (targetData as ShopProdNode).Parent as ShopCatNode; targetCollection = targetShopCatNode.Childs; } }
private void DropSupNode(SupNode supNode, ShopCatNode parentShopCatNode, TreeNodes targetCollection) { List<ShopCategory> newShopCategories = supNode.Base.CreateShopCategories(parentShopCatNode.Base); context.SaveChanges(); targetCollection.Clear(); foreach (var newShopCategory in newShopCategories) { var newShopCatNode = new ShopCatNode(newShopCategory, parentShopCatNode); targetCollection.Add(newShopCatNode); } }
//private void InternationalDropNodes(TreeListNode sourceNode, TreeListNode targetNode) //{ // try // { // var sourceData = GetData(sourceNode); // var targetData = GetData(targetNode); // ShopCatNode targetShopCatNode = null; // TreeNodes targetCollection = null; // GetTargets(targetData, ref targetShopCatNode, ref targetCollection); // if (sourceData is SupNode) // { // DropSupNode(sourceData as SupNode, targetShopCatNode, targetCollection); // } // else if (sourceData is SupCatNode) // { // DropSupCatNode(sourceData as SupCatNode, targetShopCatNode, targetCollection); // } // else if (sourceData is SupProdNode) // { // DropSupProdNode(sourceData as SupProdNode, targetShopCatNode, targetCollection); // } // treeShop.RefreshDataSource(); // } // catch (Exception ex) // { // throw; // } //} private void DropSupProdNode(SupProdNode supProdNode, ShopCatNode parentShopCatNode, TreeNodes targetCollection) { if (parentShopCatNode == null) return; var newShopProd = supProdNode.Base.CreateShopProduct(parentShopCatNode.Base); context.SaveChanges(); var newShopProdNode = new ShopProdNode(newShopProd, parentShopCatNode); targetCollection.Add(newShopProdNode); }
private void DropShopProdNode(ShopProdNode shopProdNode, ShopCatNode targetShopCatNode, TreeNodes targetCollection) { if (targetShopCatNode == null) return; shopProdNode.Base.Move(targetShopCatNode.Base); context.SaveChanges(); shopProdNode.Parent.Childs.Remove(shopProdNode); targetCollection.Add(shopProdNode); shopProdNode.Parent = targetShopCatNode; }
private void DropSupCatNode(ITreeNode sourceData, ShopCatNode parentShopCatNode, TreeNodes targetCollection) { var supCatNode = sourceData as SupCatNode; var parentShopCat = parentShopCatNode == null ? null : parentShopCatNode.Base; bool mergeCategories = false; if (parentShopCatNode != null) { mergeCategories = MessageBox.Show("Да - Слить, Нет - Добавить?", "Слияние", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes; } var newShopCategory = supCatNode.Base.CreateShopCategory(parentShopCat, mergeCategories); context.SaveChanges(); var newShopCatNode = new ShopCatNode(newShopCategory, parentShopCatNode); targetCollection.Add(newShopCatNode); }
private void DropShopCatNode(ShopCatNode sourceCatNode, ShopCatNode targetCatNode, TreeNodes targetCollection) { var sourceShopCat = sourceCatNode.Base; var targetShopCat = targetCatNode == null ? null : targetCatNode.Base; bool mergeCategories = false; if (targetCatNode != null) { mergeCategories = MessageBox.Show("Да - Слить, Нет - Добавить?", "Слияние", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes; } if (mergeCategories) sourceShopCat.Merge(targetShopCat); else sourceShopCat.Move(targetShopCat); context.SaveChanges(); var rootTreeNodes = treeShop.DataSource as TreeNodes; TreeNodes sourceContainer = sourceCatNode.Parent == null ? rootTreeNodes : sourceCatNode.Parent.Childs; sourceContainer.Remove(sourceCatNode); if (mergeCategories) return; targetCollection.Add(sourceCatNode); sourceCatNode.Parent = targetCatNode; }
private void CreateShopCatNode(TreeListNode parent) { ITreeNode data = GetData(parent); ShopCatNode parentShopCatNode = null; if (data is ShopProdNode) { parentShopCatNode = (data as ShopProdNode).Parent as ShopCatNode; } else { parentShopCatNode = data as ShopCatNode; } ShopCategory parentShopCat = parentShopCatNode.Base; var shopCategory = new ShopCategory(parentShopCat); shopCategory.Title = "Новая категория"; context.SaveChanges(); var shopCatNode = new ShopCatNode(shopCategory, parentShopCatNode); parentShopCatNode.Childs.Add(shopCatNode); parent.TreeList.RefreshDataSource(); foreach (TreeListNode treeListNode in parent.Nodes) { ShopCatNode neighbourCat = GetData(treeListNode) as ShopCatNode; if (neighbourCat == null) continue; if (neighbourCat.Base.Id != shopCategory.Id) continue; var treeList = treeListNode.TreeList; treeList.MakeNodeVisible(treeListNode); treeListNode.TreeList.FocusedNode = treeListNode; //treeListNode.TreeList.SetFocusedNode(treeListNode); treeListNode.TreeList.ShowEditor(); break; } }
private void BuildShopTree() { var shopCats = context.ShopCategorySet.Where(c => c.Parent == null).ToList(); var shopNodes = new TreeNodes(); foreach (var s in shopCats) { var supNode = new ShopCatNode(s, null); shopNodes.Add(supNode); } treeShop.DataSource = shopNodes; treeShop.Refresh(); if (treeSuppliers.Nodes.Count > 0) { treeSuppliers.Nodes[0].Expanded = true; } }
public ShopProdNode(ShopProduct @base, ShopCatNode shopCatNode) { Base = @base; Parent = shopCatNode; }
public ShopCatNode(ShopCategory @base, ShopCatNode parentShopCatNode) { Base = @base; Parent = parentShopCatNode; }