private UIElement createNode(CategoryTreeNode category) { if (category.Icon != null) { var panel = new StackPanel { Margin = new Thickness(5, 0, 5, 0) }; //panel.SetValue(TiltEffectCustom.IsTiltEnabledProperty, true); panel.SetValue(RotateEffect.IsEnabledProperty, true); panel.Children.Add(new Image { Source = new BitmapImage(category.Icon), Height = 60, Width = 60, Margin = new Thickness(5, 20, 5, 5), HorizontalAlignment = System.Windows.HorizontalAlignment.Center }); panel.Children.Add(new TextBlock { TextWrapping = TextWrapping.Wrap, Text = category.Name, MaxWidth = 100, VerticalAlignment = System.Windows.VerticalAlignment.Center, HorizontalAlignment = System.Windows.HorizontalAlignment.Center, FontSize = 16, Foreground = (Brush)App.Current.Resources["AppForegroundBrush"] }); return(panel); } else { var border = new Border { Child = new TextBlock { Text = category.Name, TextWrapping = System.Windows.TextWrapping.Wrap, FontSize = 20, Margin = new Thickness(7), Foreground = (Brush)App.Current.Resources["AppForegroundBrush"], VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }, MinWidth = 80, MaxWidth = 120, MinHeight = 60, Margin = new Thickness(5), BorderBrush = (Brush)App.Current.Resources["AppBorderBrush"], BorderThickness = new Thickness(2), Background = (Brush)App.Current.Resources["AppBackgroundBrush"], VerticalAlignment = System.Windows.VerticalAlignment.Stretch }; border.SetValue(RotateEffect.IsEnabledProperty, true); return(border); } }
private ICategoryTreeService CreateFakeCategoryNameService() { var fakeRoot = new CategoryTreeNode(null, 0, null); var fakeCat0 = new CategoryTreeNode("Sport", 0, fakeRoot); var fakeCat1 = new CategoryTreeNode("Sport subcategory 0", 1, fakeCat0); var fakeCat2 = new CategoryTreeNode("Sport subcategory 1", 2, fakeCat1); var fakeCategoryNameService = new Mock <ICategoryTreeService>(); fakeCategoryNameService.Setup(f => f.GetCategoriesTree()).Returns(fakeRoot); return(fakeCategoryNameService.Object); }
//private void linkedTreeView_AfterSelect(object sender, TreeViewEventArgs e) //{ // var selected = (ModelTreeNode)e.Node; // var enable = false; // //if(selected != null) // //{ // // enable = selected.Parent == null;//only allow adding categories on top level nodes // //} // //else // //{ // // enable = true;//nothing selected, we should be able to add a category // //} // toolStripButtonAddCategory.Enabled = enable; //} private void toolStripButtonAddCategory_Click(object sender, EventArgs args) { var selectedNode = treeViewItems.SelectedNode as ModelTreeNode; var categoryModel = new CategoryModel(); var categoryNode = new CategoryTreeNode <TModel, TNode>(categoryModel, ""); if (selectedNode != null && selectedNode.Parent == null) { selectedNode.AddSibling(categoryNode); //top most item, add as sibling } else { treeViewItems.Nodes.Add(categoryNode); //not top most item, so add new category to end of top most items list. } }
public CategoryTreeNode AsTree() { // This is the root node, all assemblies are direct children of this node CategoryTreeNode root = new CategoryTreeNode { Name = "Root" }; // Add all descriptors as children of the root node (we need the ToList() in order to have // a new pointer to list and not operate on the same one Descriptors uses, since we will be removing items) root.Descriptors = Descriptors.Values.ToList(); // Push leaves down PushLeaves(root, 0); return(root); }
private void PushLeaves(CategoryTreeNode node, int level) { // Check all descriptors of the node for (int i = 0; i < node.Descriptors.Count; i++) { var d = node.Descriptors[i]; var split = d.Category.Path.Split('.'); // Example: RuriLib.Blocks.Http // If a descriptor's category has a namespace which (split) is longer than the current tree level if (split.Length > level) { var subCat = split[level]; // Example: level 0 => RuriLib, level 1 => Http // Try to get an existing subcategory node var subCatNode = node.SubCategories.FirstOrDefault(s => s.Name == subCat); // Create the subcategory node if it doesn't exist if (subCatNode == null) { subCatNode = new CategoryTreeNode { Parent = node, Name = subCat }; node.SubCategories.Add(subCatNode); } subCatNode.Descriptors.Add(d); node.Descriptors.RemoveAt(i); i--; } } // Order them alphabetically node.SubCategories = node.SubCategories.OrderBy(s => s.Name).ToList(); node.Descriptors = node.Descriptors.OrderBy(d => d.Name).ToList(); // Push leaves of subcategories recursively for (int i = 0; i < node.SubCategories.Count; i++) { var s = node.SubCategories[i]; PushLeaves(s, level + 1); } }
private CategoryTreeNode ReadCategory(XmlReader xmlReader, ref int i) { var categoryName = xmlReader.GetAttribute("name"); var categoryId = int.Parse(xmlReader.GetAttribute("id")); var catNode = new CategoryTreeNode(categoryName, categoryId, _root); xmlReader.ReadToDescendant("sub-category"); do { categoryName = xmlReader.GetAttribute("name"); categoryId = int.Parse(xmlReader.GetAttribute("id")); var subCat = new CategoryTreeNode(categoryName, categoryId, catNode); xmlReader.ReadToDescendant("sub-sub-category"); do { categoryName = xmlReader.GetAttribute("name"); categoryId = int.Parse(xmlReader.GetAttribute("id")); new CategoryTreeNode(categoryName, categoryId, subCat); } while (xmlReader.ReadToNextSibling("sub-sub-category")); } while (xmlReader.ReadToNextSibling("sub-category")); return(catNode); }
public ActionResult Category(String name, string filterText = "", string sortOrder = "", int page = 1, int pageSize = 36) { var model = new CategoryViewModel(); try { model.FilterText = filterText.Trim(); model.SortOrder = sortOrder; using (var db = new DBContext()) { // Get category id var categoryId = ParseId(name); // Get category info var category = db.Categories.Where(r => r.CategoryId == categoryId).FirstOrDefault(); if (category != null) { // Set meta data ViewBag.MetaDescription = "Memory Audio - " + category.CategoryName; ViewBag.MetaKeywords = category.CategoryName + ",memory-audio,audiophile,sound,hifi,stereo,hi-end,hd,ultra-hd,dts,dts-hd"; // Query products var query = from p in db.Products join c in db.Categories on p.CategoryId equals c.CategoryId into pc join b in db.Brands on p.BrandId equals b.BrandId into pb from j1 in pc.DefaultIfEmpty() from j2 in pb.DefaultIfEmpty() where p.Display > 1 select new ProductInfo { ProductId = p.ProductId, ProductName = p.ProductName, CategoryId = p.CategoryId, CategoryName = j1.CategoryName, BrandId = p.BrandId, BrandName = j2.BrandName, Specification = p.Specification, TotalInStock = p.TotalInStock, Price = p.Price, Discount = p.Discount, Image1 = p.Image1, Image2 = p.Image2, Image3 = p.Image3, Image4 = p.Image4, Image5 = p.Image5, Image6 = p.Image6, CreationDate = p.CreationDate, Display = p.Display, SortIdx = p.SortIdx }; // Get category nodes include its children and parent var categoryNode = new CategoryTreeNode(); categoryNode.CategoryId = category.CategoryId; categoryNode.CategoryName = category.CategoryName; categoryNode.Description = category.Description; categoryNode.Level = 0; categoryNode.Parent = null; categoryNode.Nodes = new List <CategoryTreeNode>(); CategoryTree.AppendChildNodes(categoryNode); CategoryTree.AppendParentNodes(categoryNode); // Filter products by category which included its children var childNodes = categoryNode.GetChildNodes(); var childCategoryIds = new List <int>(); foreach (var node in childNodes) { childCategoryIds.Add(node.CategoryId); } if (childCategoryIds.Count > 0) { query = query.Where(r => childCategoryIds.Contains(r.CategoryId ?? 0)); } if (!string.IsNullOrWhiteSpace(filterText)) { query = query.Where(r => r.ProductName.Contains(filterText) || r.CategoryName.Contains(filterText)); } // Get parent nodes var parentNodes = categoryNode.GetParentNodes(); foreach (var parentNode in parentNodes) { var parentCategory = db.Categories.Where(r => r.CategoryId == parentNode.CategoryId).FirstOrDefault(); if (parentCategory != null && parentCategory.CategoryId != category.CategoryId) { model.ParentCategories.Add(parentCategory); } } // Sorting switch (sortOrder) { case "price": query = query.OrderBy(p => p.Price); break; case "price_desc": query = query.OrderByDescending(p => p.Price); break; case "name": query = query.OrderBy(p => p.ProductName); break; case "name_desc": query = query.OrderByDescending(p => p.ProductName); break; default: query = query.OrderByDescending(p => p.SortIdx); break; } var products = query.ToList(); var pageCount = (products.Count / pageSize) + (products.Count % pageSize > 0 ? 1 : 0); if (page > pageCount) { page = pageCount; } model.Products = query.ToPagedList <ProductInfo>(page == 0 ? 1 : page, pageSize); } else { throw new Exception("Category not found!"); } model.Category = category; model.PageIndex = model.Products.PageNumber; model.PageSize = model.Products.PageSize; return(View(model)); } } catch (Exception ex) { // Write event logs EventLogs.Write("HomeController - Category: " + ex.ToString(), EventLogEntryType.Error); // Redirect to error page return(RedirectToAction("Index", "Error")); } }
public ActionResult Product(string name) { var model = new ProductViewModel(); try { using (var db = new DBContext()) { // Get ProductId var productId = ParseId(name); // Get product info var productInfo = (from p in db.Products join c in db.Categories on p.CategoryId equals c.CategoryId into pc join b in db.Brands on p.BrandId equals b.BrandId into pb from j1 in pc.DefaultIfEmpty() from j2 in pb.DefaultIfEmpty() where p.ProductId == productId && p.Display > 1 select new ProductInfo { ProductId = p.ProductId, ProductName = p.ProductName, CategoryId = p.CategoryId, CategoryName = j1.CategoryName, BrandId = p.BrandId, BrandName = j2.BrandName, Specification = p.Specification, TotalInStock = p.TotalInStock, Price = p.Price, Discount = p.Discount, MSRP = p.MSRP, Image1 = p.Image1, Image2 = p.Image2, Image3 = p.Image3, Image4 = p.Image4, Image5 = p.Image5, Image6 = p.Image6, CreationDate = p.CreationDate, Display = p.Display, SortIdx = p.SortIdx }).FirstOrDefault(); // Product existed? if (productInfo == null) { return(RedirectToAction("Index", "Error", new { @message = "Product not found!" })); } // Get related products var relatedProducts = from p in db.Products join c in db.Categories on p.CategoryId equals c.CategoryId into pc join b in db.Brands on p.BrandId equals b.BrandId into pb from j1 in pc.DefaultIfEmpty() from j2 in pb.DefaultIfEmpty() where p.Display > 1 && p.ProductId != productInfo.ProductId && p.CategoryId == productInfo.CategoryId orderby p.Display descending, p.SortIdx ascending select new ProductInfo { ProductId = p.ProductId, ProductName = p.ProductName, CategoryId = p.CategoryId, CategoryName = j1.CategoryName, BrandId = p.BrandId, BrandName = j2.BrandName, Specification = p.Specification, TotalInStock = p.TotalInStock, Price = p.Price, Discount = p.Discount, Image1 = p.Image1, Image2 = p.Image2, Image3 = p.Image3, Image4 = p.Image4, Image5 = p.Image5, Image6 = p.Image6, CreationDate = p.CreationDate, Display = p.Display, SortIdx = p.SortIdx }; // Get category info and its parent var category = db.Categories.Where(r => r.CategoryId == productInfo.CategoryId).FirstOrDefault(); if (category != null) { var categoryNode = new CategoryTreeNode(); categoryNode.CategoryId = category.CategoryId; categoryNode.CategoryName = category.CategoryName; categoryNode.Description = category.Description; categoryNode.Level = 0; categoryNode.Parent = null; categoryNode.Nodes = new List <CategoryTreeNode>(); CategoryTree.AppendParentNodes(categoryNode); var parentNodes = categoryNode.GetParentNodes(); foreach (var parentNode in parentNodes) { var parentCategory = db.Categories.Where(r => r.CategoryId == parentNode.CategoryId).FirstOrDefault(); if (parentCategory != null && parentCategory.CategoryId != category.CategoryId) { model.ParentCategories.Add(parentCategory); } } model.Category = category; } model.Product = productInfo; model.RelatedProducts = relatedProducts.Take(AppSettings.PAGE_SIZE).ToList(); // Set meta data ViewBag.MetaDescription = "Memory Audio - " + productInfo.ProductName; ViewBag.MetaKeywords = productInfo.CategoryName + "," + productInfo.ProductName + "," + productInfo.BrandName + ",memory audio,audiophile,sound,hifi,stereo,hi-end,hd,ultra-hd,dts,dts-hd"; return(View(model)); } } catch (Exception ex) { // Write event logs EventLogs.Write("HomeController - Products: " + ex.ToString(), EventLogEntryType.Error); // Redirect to error page return(RedirectToAction("Index", "Error")); } }
public CategoryTree(CategoryTreeNode root) => Root = root;