Example #1
0
        public List <Prod> fillByBrand(String bName)
        {
            List <Prod> list = new List <Prod>();

            var prod = (from u in db.Products
                        where u.inStock.Equals(1) && u.Brand.Equals(bName)
                        select u);

            foreach (var f in prod)
            {
                var r = new Prod
                {
                    ID          = f.ID,
                    sNumber     = f.Serial_Number,
                    prodType    = f.ProdType,
                    prodName    = f.ProdName,
                    special     = Convert.ToInt32(f.Special),
                    Price       = Convert.ToDouble(f.Price),
                    brand       = f.Brand,
                    description = f.Description,
                    Qty         = Convert.ToInt32(f.Quantity),
                    Image       = f.Image
                };

                list.Add(r);
            }
            return(list);
        }
Example #2
0
        //Getting all products from database
        public List <Prod> prodList()
        {
            List <Prod> pr = new List <Prod>();

            dynamic products = (from s in db.Products
                                select s);


            foreach (Product f in products)
            {
                var r = new Prod
                {
                    ID          = f.ID,
                    sNumber     = f.Serial_Number,
                    prodType    = f.ProdType,
                    prodName    = f.ProdName,
                    special     = Convert.ToInt32(f.Special),
                    Price       = Convert.ToDouble(f.Price),
                    brand       = f.Brand,
                    description = f.Description,
                    Qty         = Convert.ToInt32(f.Quantity),
                    Image       = f.Image,
                    inStock     = Convert.ToInt32(f.inStock)
                };

                pr.Add(r);
            }

            return(pr);
        }
Example #3
0
        //Method for Add new Product To DataBase
        public bool appendNewProduct(Prod p)
        {
            var newProduct = new Product
            {
                Serial_Number = p.sNumber,
                ProdType      = p.prodType,
                ProdName      = p.prodName,
                Price         = Convert.ToDouble(p.Price),
                Special       = p.special,
                Description   = p.description,
                Quantity      = p.Qty,
                Brand         = p.brand,
                Image         = p.Image,
                inStock       = 1
            };

            db.Products.InsertOnSubmit(newProduct);

            try
            {
                db.SubmitChanges();
                pStakerSetup(newProduct.ID, newProduct.Quantity);
                return(true);
            }
            catch (Exception ex)
            {
                ex.GetBaseException();
                return(false);
            }
        }
Example #4
0
        //Edit Exsiting Product
        public bool modifyProd(Prod product, int ID)
        {
            var item = (from i in db.Products
                        where i.ID.Equals(ID)
                        select i).FirstOrDefault();

            item.Serial_Number = product.sNumber;
            item.ProdType      = product.prodType;
            item.ProdName      = product.prodName;
            item.Price         = Convert.ToDouble(product.Price);
            item.Special       = Convert.ToInt32(product.special);
            item.Quantity      = Convert.ToInt32(product.Qty);
            item.Brand         = product.brand;
            item.Image         = product.Image;

            try
            {
                db.SubmitChanges();
                return(true);
            }
            //Error Handling
            catch (IndexOutOfRangeException ex)
            {
                ex.GetBaseException();
                return(false);
            }
        }
Example #5
0
        //Getting product from table
        public Prod GetProd(int ID)
        {
            var FoundProduct = (from p in db.Products
                                where p.ID.Equals(ID)
                                select p).FirstOrDefault();

            Prod pr = new Prod
            {
                ID          = FoundProduct.ID,
                sNumber     = FoundProduct.Serial_Number,
                prodType    = FoundProduct.ProdType,
                prodName    = FoundProduct.ProdName,
                special     = Convert.ToInt32(FoundProduct.Special),
                Qty         = Convert.ToInt32(FoundProduct.Quantity),
                Price       = Convert.ToDouble(FoundProduct.Price),
                brand       = FoundProduct.Brand,
                Image       = FoundProduct.Image,
                inStock     = Convert.ToInt32(FoundProduct.inStock),
                description = FoundProduct.Description
            };

            return(pr);
        }
Example #6
0
        public List <Prod> fillByPrice(int n)
        {
            List <Prod> p = new List <Prod>();

            if (n == 1)
            {
                var prod = (from u in db.Products
                            where u.inStock.Equals(1) && (u.Price > 0 && u.Price <= 50)
                            select u);

                foreach (var f in prod)
                {
                    var r = new Prod
                    {
                        ID          = f.ID,
                        sNumber     = f.Serial_Number,
                        prodType    = f.ProdType,
                        prodName    = f.ProdName,
                        special     = Convert.ToInt16(f.Special),
                        Price       = Convert.ToDouble(f.Price),
                        brand       = f.Brand,
                        description = f.Description,
                        Qty         = Convert.ToInt16(f.Quantity),
                        Image       = f.Image
                    };

                    p.Add(r);
                }
            }
            else if (n == 2)
            {
                var prod = (from u in db.Products
                            where u.inStock.Equals(1) && (u.Price >= 50 && u.Price <= 100)
                            select u);

                foreach (var f in prod)
                {
                    var r = new Prod
                    {
                        ID          = f.ID,
                        sNumber     = f.Serial_Number,
                        prodType    = f.ProdType,
                        prodName    = f.ProdName,
                        special     = Convert.ToInt16(f.Special),
                        Price       = Convert.ToDouble(f.Price),
                        brand       = f.Brand,
                        description = f.Description,
                        Qty         = Convert.ToInt16(f.Quantity),
                        Image       = f.Image
                    };

                    p.Add(r);
                }
            }
            else if (n == 3)
            {
                var prod = (from u in db.Products
                            where u.inStock.Equals(1) && (u.Price >= 100 && u.Price <= 200)
                            select u);

                foreach (var f in prod)
                {
                    var r = new Prod
                    {
                        ID          = f.ID,
                        sNumber     = f.Serial_Number,
                        prodType    = f.ProdType,
                        prodName    = f.ProdName,
                        special     = Convert.ToInt16(f.Special),
                        Price       = Convert.ToDouble(f.Price),
                        brand       = f.Brand,
                        description = f.Description,
                        Qty         = Convert.ToInt16(f.Quantity),
                        Image       = f.Image
                    };

                    p.Add(r);
                }
            }

            return(p);
        }
Example #7
0
        public List <Prod> fillByDescOrder(int A)
        {
            List <Prod> p = new List <Prod>();

            if (A == 1)
            {
                var prod = (from u in db.Products
                            orderby u.ProdName ascending
                            select u);

                foreach (var f in prod)
                {
                    var r = new Prod
                    {
                        ID          = f.ID,
                        sNumber     = f.Serial_Number,
                        prodType    = f.ProdType,
                        prodName    = f.ProdName,
                        special     = Convert.ToInt16(f.Special),
                        Price       = Convert.ToDouble(f.Price),
                        brand       = f.Brand,
                        description = f.Description,
                        Qty         = Convert.ToInt16(f.Quantity),
                        Image       = f.Image
                    };

                    p.Add(r);
                }
            }
            else if (A == 2)
            {
                var prod = (from u in db.Products
                            orderby u.ProdName descending
                            select u);

                foreach (var f in prod)
                {
                    var r = new Prod
                    {
                        ID          = f.ID,
                        sNumber     = f.Serial_Number,
                        prodType    = f.ProdType,
                        prodName    = f.ProdName,
                        special     = Convert.ToInt16(f.Special),
                        Price       = Convert.ToDouble(f.Price),
                        brand       = f.Brand,
                        description = f.Description,
                        Qty         = Convert.ToInt16(f.Quantity),
                        Image       = f.Image
                    };

                    p.Add(r);
                }
            }
            else if (A == 20)
            {
                var prod = (from u in db.Products
                            where u.Special.Equals(1)
                            select u);

                foreach (var f in prod)
                {
                    var r = new Prod
                    {
                        ID          = f.ID,
                        sNumber     = f.Serial_Number,
                        prodType    = f.ProdType,
                        prodName    = f.ProdName,
                        special     = Convert.ToInt16(f.Special),
                        Price       = Convert.ToDouble(f.Price),
                        brand       = f.Brand,
                        description = f.Description,
                        Qty         = Convert.ToInt16(f.Quantity),
                        Image       = f.Image
                    };

                    p.Add(r);
                }
            }

            return(p);
        }