internal void BuildSupliersTree() { var suppliers = context.SupplierSet.ToList(); // чтобы захешировать и работало быстрее var supplierCategories = context.SupplierCategorySet.ToList(); var supplierProducts = context.SupplierProductSet.ToList(); var supNodes = new TreeNodes(); foreach (var s in suppliers) { var supNode = new SupNode(s); supNodes.Add(supNode); } treeSuppliers.DataSource = supNodes; treeSuppliers.Refresh(); if (treeSuppliers.Nodes.Count > 0) { treeSuppliers.Nodes[0].Expanded = true; } }
private void treeSuppliers_DragDrop(object sender, DragEventArgs e) { Cursor = Cursors.WaitCursor; // для перенесенных ссылок из браузера string url = (string)e.Data.GetData(typeof(string)); var newProdSuplier = Scraper.Scrape(url); if (newProdSuplier != null) { var treeNodes = treeSuppliers.DataSource as TreeNodes; var node = treeNodes.Cast<SupNode>().FirstOrDefault(n => n.Base.Id == newProdSuplier.Id); if (node == null) { node = new SupNode(newProdSuplier); treeNodes.Add(node); } treeSuppliers.RefreshDataSource(); } Cursor = Cursors.Default; }
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); } }