Exemple #1
0
 public void Add(Backend.Product p)
 {
     DB.Add(p);
     DAL.Product temp = Change.ProductBackendToDal(p);
     emartDataContext.Products.InsertOnSubmit(temp);
     emartDataContext.SubmitChanges();
 }
Exemple #2
0
        ///////////////////////////////////////////////// PRODUCT CONVERTION
        public static List <Backend.Product> ProductDalToBackendList(List <DAL.Product> SqlDB)
        {
            List <Backend.Product> list = new List <Backend.Product>();

            Backend.Product temp;
            foreach (DAL.Product d in SqlDB)
            {
                temp = new Backend.Product();
                temp.departmentID = d.departmentID;
                temp.inStock      = d.inStock;
                temp.inventoryID  = d.inventoryID;
                temp.isBestSeller = d.isBestSeller;
                temp.name         = d.name;
                temp.price        = d.price;
                temp.stockCount   = d.stockCount;
                var values = Enum.GetValues(typeof(Backend.Product.Type));
                foreach (Backend.Product.Type t in values)
                {
                    if (t.ToString().CompareTo(d.type) == 0)
                    {
                        temp.type = t;
                    }
                }

                list.Add(temp);
            }
            return(list);
        }
Exemple #3
0
        [Test] // #5
        public void e()
        {      //@ Add a product and check if he existing
            Backend.Product dp = new Backend.Product("Soldiers", Backend.Product.Type.toys, "4", "12341234", true, 200, 200.0);
            Product_Data    dt = new Product_Data();

            dt.Add(dp);
            Assert.IsTrue(dt.Contains(dp.inventoryID));
        }
Exemple #4
0
        [Test] // #3
        public void c()
        {      //@ Add a product and check if it existing
            Backend.Product dp = new Backend.Product("pentium", Backend.Product.Type.electronics, "1", "123123", true, 200, 200.0);
            Product_Data    dt = new Product_Data();

            dt.Add(dp);
            Assert.IsTrue(dt.Contains(dp.inventoryID));
        }
Exemple #5
0
        public void SQLEqualProduct()
        {
            clear();
            List <object> depList = new List <object>();

            depList.Add(new Backend.Department("Dep1", 1));
            sql.WriteToFile(depList, new Backend.Department());
            list.Add(a);
            sql.WriteToFile(list, a);
            Backend.Product prod = sql.ReadFromFile(Elements.Product).Cast <Backend.Product>().ToList().ElementAt(0);
            Assert.AreEqual(prod, a);
            clear();
        }
Exemple #6
0
        public Backend.Product getProductsInStockByID(string id)
        {
            List <Backend.Product> list = itsDAL.getAllProductsList();

            Backend.Product ans = new Backend.Product();
            foreach (Backend.Product p in list)
            {
                if (p.inventoryID == id)
                {
                    ans = p;
                }
            }
            return(ans);
        }
Exemple #7
0
        public static DAL.Product ProductBackendToDal(Backend.Product d)
        {
            DAL.Product temp = new DAL.Product();

            temp.departmentID = d.departmentID;
            temp.inStock      = d.inStock;
            temp.inventoryID  = d.inventoryID;
            temp.isBestSeller = d.isBestSeller;
            temp.name         = d.name;
            temp.price        = d.price;
            temp.stockCount   = d.stockCount;
            temp.type         = d.type.ToString();
            return(temp);
        }
Exemple #8
0
        //Converters


        //Product
        public Backend.Product ProductConverterToBackend(Product dataContextProduct)
        {
            Backend.Product currentProduct = new Backend.Product();
            currentProduct.Name       = dataContextProduct.Name;
            currentProduct.Type       = (PType)dataContextProduct.Type;
            currentProduct.ProductID  = dataContextProduct.ProductID;
            currentProduct.Location   = dataContextProduct.Location;
            currentProduct.InStock    = (PStatus)dataContextProduct.InStock;
            currentProduct.StockCount = dataContextProduct.StockCount;
            currentProduct.Price      = dataContextProduct.Price;
            currentProduct.TopSellerStatus.CurrentMonth = dataContextProduct.TopSeller.CurrentMonth;
            currentProduct.TopSellerStatus.IsTopSeller  = dataContextProduct.TopSeller.IsTopSeller;
            currentProduct.TopSellerStatus.SellCounter  = dataContextProduct.TopSeller.SellCounter;
            currentProduct.TopSellerStatus.ProductID    = dataContextProduct.TopSeller.ProductID;
            return(currentProduct);
        }
Exemple #9
0
        public void isTopSellerRestarted()
        {
            Backend.Product prod1 = new Backend.Product("Banana", PType.Electronics, 1, 21, 2);
            Backend.Product prod2 = new Backend.Product("avocado", PType.Food, 1, 21, 5);
            prod1.Buy();
            prod1.Buy();
            prod2.Buy();
            List <Backend.Product> Allprods = new List <Backend.Product>();

            Allprods.Add(prod1);
            Allprods.Add(prod2);
            TopSeller(Allprods, DateTime.Today.Month);
            Assert.IsTrue(prod1.IsTopSeller);
            Assert.IsFalse(prod2.IsTopSeller);
            TopSeller(Allprods, 1);
            Assert.IsFalse(prod1.IsTopSeller);
            Assert.IsFalse(prod2.IsTopSeller);
        }
Exemple #10
0
        public Product ProductConverterToContext(Backend.Product currentProduct)
        {
            TopSeller dataContextTopSeller = new TopSeller();
            Product   dataContextProduct   = new Product();

            dataContextProduct.Name           = currentProduct.Name;
            dataContextProduct.Type           = (int)currentProduct.Type;
            dataContextProduct.ProductID      = currentProduct.ProductID;
            dataContextProduct.Location       = currentProduct.Location;
            dataContextProduct.InStock        = (int)currentProduct.InStock;
            dataContextProduct.StockCount     = currentProduct.StockCount;
            dataContextProduct.Price          = currentProduct.Price;
            dataContextTopSeller.CurrentMonth = currentProduct.TopSellerStatus.CurrentMonth;
            dataContextTopSeller.IsTopSeller  = currentProduct.TopSellerStatus.IsTopSeller;
            dataContextTopSeller.SellCounter  = currentProduct.TopSellerStatus.SellCounter;
            dataContextTopSeller.ProductID    = currentProduct.TopSellerStatus.ProductID;
            dataContextProduct.TopSeller      = dataContextTopSeller;
            return(dataContextProduct);
        }
Exemple #11
0
        //adds new product to database
        public string Add(string name, string type, string departmentID, string stockCount, string price)
        {
            if (existByName(name))
            {
                itsDAL.Restock(this.getProductsInStockByName(name).name, stockCount);
                return("");
            }
            string id      = generateID();
            bool   inStock = false;

            if (int.Parse(stockCount) > 0)
            {
                inStock = true;
            }
            Backend.Product temp = new Backend.Product(name, (Backend.Product.Type)Enum.Parse(typeof(Backend.Product.Type), type), id, departmentID, inStock, int.Parse(stockCount), double.Parse(price));

            itsDAL.Add(temp);
            return(id);
        }
Exemple #12
0
        private void Search_Click(object sender, RoutedEventArgs e)
        {
            String search = searchtxt.Text;

            if (byNameradio.IsChecked == true)
            {
                if (MainWindow.isWord(search))
                {
                    Backend.Product p = BL_manager.BL_product.getProductsInStockByName(search);
                    if (p != null)
                    {
                        List <Backend.Product> list = new List <Backend.Product>();
                        list.Add(p);
                        searchResult.ItemsSource = list;
                        currList = list;
                    }
                    else
                    {
                        searchResult.ItemsSource = null;
                    }
                }
            }
            if (byIDradio.IsChecked == true)
            {
                if (MainWindow.isNumber(search))
                {
                    Backend.Product p = BL_manager.BL_product.getProductsInStockByID(search);
                    if (p != null)
                    {
                        List <Backend.Product> list = new List <Backend.Product>();
                        list.Add(p);
                        searchResult.ItemsSource = list;
                        currList = list;
                    }
                    else
                    {
                        searchResult.ItemsSource = null;
                    }
                }
            }
        }
Exemple #13
0
 public void Remove(string id)
 {
     Backend.Product temp = new Backend.Product();
     foreach (Backend.Product p in DB)
     {
         if (p.inventoryID == id)
         {
             temp = p;
         }
     }
     DB.Remove(temp);
     foreach (DAL.Product p in emartDataContext.Products)
     {
         if (p.inventoryID == id)
         {
             emartDataContext.Products.DeleteOnSubmit(p);
             emartDataContext.SubmitChanges();
             return;
         }
     }
 }