public List <Product> SearchByWord(string word) { KeyWord = word; foreach (var tree in Trees) { if (tree.NumberOfNodes() == 0) { AddItemsToTheTree(TradeMarkTree); } } Products.Clear(); foreach (var tree in Trees) { if (tree is StringBST) { StringBST tempTree = (StringBST)tree; tempTree.InOrder(); foreach (var product in tempTree.GetProducts()) { if (product.ProductDescription.ToLower().Contains(KeyWord.ToLower()) || product.Name.ToLower().Contains(KeyWord.ToLower()) || product.Model.ToLower().Contains(KeyWord.ToLower()) || product.TradeMark.ToLower().Contains(KeyWord.ToLower())) { if (!Products.Contains(product)) { Products.Add(product); } } } break; } if (tree is IntBST) { IntBST tempTree = (IntBST)tree; tempTree.InOrder(); foreach (var product in tempTree.GetProducts()) { if (product.ProductDescription.ToLower().Contains(KeyWord.ToLower()) || product.Name.ToLower().Contains(KeyWord.ToLower()) || product.Model.ToLower().Contains(KeyWord.ToLower()) || product.TradeMark.ToLower().Contains(KeyWord.ToLower())) { if (!Products.Contains(product)) { Products.Add(product); } } } break; } } return(Products); }
private void TestForm_Load(object sender, EventArgs e) { IntBST priceTree = new IntBST(); StringBST tradeMarkTree = new StringBST("TradeMark"); Product[] fakeProducts = new Product[10]; for (int i = 0; i < fakeProducts.Length / 2; i++) { fakeProducts[i] = new Product { Name = "Product " + i, ProductDescription = "This is the " + i + ". test product", SalePrice = i + 1, Model = "X1", Cost = i, TradeMark = "TheJengo", }; priceTree.Add(fakeProducts[i]); tradeMarkTree.Add(fakeProducts[i]); } for (int i = fakeProducts.Length / 2; i < fakeProducts.Length; i++) { fakeProducts[i] = new Product { Name = "Product " + i, ProductDescription = "This is the " + i + ". test product", SalePrice = i + 1, Model = "X" + i, Cost = i, TradeMark = "TheTudorst", }; priceTree.Add(fakeProducts[i]); tradeMarkTree.Add(fakeProducts[i]); } priceTree.InOrder(); tradeMarkTree.InOrder(); lvwProduct.Items.Clear(); Filter f1 = new Filter("Computer"); List <string> label = f1.GetStringLabels("Model"); foreach (var Product in f1.SearchByWord("Lenovo")) { var listViewItem = new ListViewItem(Product.TradeMark); listViewItem.SubItems.Add(Product.Model); listViewItem.SubItems.Add(Product.Name); listViewItem.SubItems.Add(Product.ProductDescription); listViewItem.SubItems.Add(Product.SalePrice + " TL"); lvwProduct.Items.Add(listViewItem); } /* * HashMapChain _HMP = new HashMapChain(10); * foreach (var Product in tradeMarkTree.GetProducts()) * { * var listViewItem = new ListViewItem(Product.TradeMark); * listViewItem.SubItems.Add(Product.Model); * listViewItem.SubItems.Add(Product.Name); * listViewItem.SubItems.Add(Product.ProductDescription); * listViewItem.SubItems.Add(Product.SalePrice + " TL"); * listView1.Items.Add(listViewItem); * } * List<Product> ps = tradeMarkTree.Search("TheJengo").Products; * foreach (var item in ps) * { * _HMP.AddItem(item.Model, item); * } */ }
public List <string> GetStringLabels(string type) { List <string> Labels = new List <string>(); if (type == "Categories" && new CategoryDataAccess().GetList() != null) { foreach (var category in new CategoryDataAccess().GetList()) { Labels.Add(category.Name); } return(Labels); } foreach (var tree in Trees) { if (tree is StringBST) { StringBST tempTree = (StringBST)tree; if (tempTree.NumberOfNodes() == 0) { AddItemsToTheTree(tempTree); } if (String.Compare(tempTree.GetTreeType(), type, true) == 0) { if (type == "TradeMark") { tempTree.InOrder(); foreach (var product in tempTree.GetProducts()) { if (!Labels.Exists(t => t.CompareTo(product.TradeMark) == 0)) { Labels.Add(product.TradeMark); } } break; } if (type == "Name") { tempTree.InOrder(); foreach (var product in tempTree.GetProducts()) { if (!Labels.Exists(t => t.CompareTo(product.Name) == 0)) { Labels.Add(product.Name); } } break; } } if (type == "Model" && tree == TradeMarkTree) { StringBST tempTradeMarkTree = (StringBST)tree; if (tree.NumberOfNodes() == 0) { AddItemsToTheTree(tree); } tree.InOrder(); foreach (var product in tempTree.Search(TradeMark).Products) { if (!Labels.Exists(t => t.CompareTo(product.Model) == 0)) { Labels.Add(product.Model); } } break; } } } return(Labels); }