Esempio n. 1
0
        public ProductWCF[] searchProduct(string searchTerm)
        {
            List <Product> searchResults = new List <Product>();

            Product idSearchResult = null;

            try
            {
                idSearchResult = ProductDAO.getSearchProductbyid(searchTerm);
            }
            catch (InvalidOperationException ex)
            {
            }

            List <Product> nameSearchResults     = ProductDAO.getSearchProductbyname(searchTerm);
            List <Product> categorySearchResults = ProductDAO.getSearchProductbyCategory(searchTerm);

            if (idSearchResult != null)
            {
                searchResults.Add(idSearchResult);
            }

            foreach (Product p in nameSearchResults)
            {
                //searchResults.Add(p);

                if (searchResults.Count > 0)
                {
                    bool isrepeat = false;

                    foreach (Product p1 in searchResults)
                    {
                        if (p.ItemNumber.Equals(p1.ItemNumber))
                        {
                            isrepeat = true;
                        }
                    }

                    if (!isrepeat)
                    {
                        searchResults.Add(p);
                    }
                }
                else
                {
                    searchResults.Add(p);
                }
            }

            foreach (Product p in categorySearchResults)
            {
                if (searchResults.Count > 0)
                {
                    bool isrepeat = false;
                    foreach (Product p1 in searchResults)
                    {
                        if (!p.ItemNumber.Equals(p1.ItemNumber))
                        {
                            isrepeat = true;
                        }
                    }

                    if (!isrepeat)
                    {
                        searchResults.Add(p);
                    }
                }
                else
                {
                    searchResults.Add(p);
                }
            }



            List <ProductWCF> searchResultWCF = new List <ProductWCF>();

            foreach (Product p in searchResults)
            {
                Console.WriteLine(p.ItemNumber);
                Console.WriteLine(p.Description);
                Console.WriteLine("------");

                ProductWCF pwcf = new ProductWCF();
                pwcf.ItemNumber             = p.ItemNumber;
                pwcf.Description            = p.Description;
                pwcf.Category               = p.Category;
                pwcf.ReorderLevel           = p.ReorderLevel != null ? (int)p.ReorderLevel : 0;
                pwcf.ReorderQuantity        = p.ReorderQuantity != null ? (int)p.ReorderQuantity : 0;
                pwcf.UnitofMeasure          = p.UnitOfMeasure;
                pwcf.Bin                    = p.Bin != null ? (int)p.Bin : 0;
                pwcf.Supplier1ID            = p.Supplier1ID;
                pwcf.Supplier2ID            = p.Supplier2ID;
                pwcf.Supplier3ID            = p.Supplier3ID;
                pwcf.AdjustmentVoucherPrice = p.AdjustmentVoucherPrice != null ? (double)p.AdjustmentVoucherPrice : 0.0;
                pwcf.Stock                  = p.Stock.TotalInventoryBalance != null ? (int)p.Stock.TotalInventoryBalance : 0;

                pwcf.ConsolidatedListID     = 0;
                pwcf.ActualQuantityAccepted = 0;
                pwcf.QuantityRequested      = 0;

                searchResultWCF.Add(pwcf);
            }

            return(searchResultWCF.ToArray <ProductWCF>());
        }