Exemplo n.º 1
0
        public ActionResult EditProduct(ProductVM model, HttpPostedFileBase file)
        {
            //int id = model.ProId;
            //using (Liquor_ShopEntities _dbContext = new Liquor_ShopEntities())
            //{
            //    model.Categories = new SelectList(_dbContext.Product_Categories.ToList(), "CatgId", "CategoryName");
            //}
            //model.Images = Directory.EnumerateFiles(Server.MapPath("~/Content/Images")).Select(i => Path.GetFileName(i));
            bool isSave = false;
            Liquor_ShopEntities _dbContext = new Liquor_ShopEntities();

            ProductDTO   productdto = Mapper.Map <ProductVM, ProductDTO>(model);
            Product_Name prod       = Mapper.Map <ProductDTO, Product_Name>(productdto);

            isSave = productservice.EditProductPost(prod);

            if (isSave == true)
            {
                TempData["Message"] = "You have edited the product";
            }

            if (file != null)
            {
                int          id    = prod.ProId;
                Product_Name pro   = _dbContext.Product_Name.Find(id);
                string       path  = Server.MapPath("/Images/" + model.ImageName);
                FileInfo     filez = new FileInfo(path);
                filez.Delete();
                AddImage(pro, file);
                _dbContext.SaveChanges();
            }
            return(RedirectToAction("EditProduct"));
        }
Exemplo n.º 2
0
        public MainPage Add(String product, String unitptice, String quantityperunit,
                            String unitsinsrock, String unitsonorder, String reorderlevel)
        {
            loginField.SendKeys("user");
            passwordField.SendKeys("user");
            passwordField.Submit();

            All_Products.Click();
            Create_new.Click();
            Product_Name.SendKeys(product);
            Product_Name.Click();

            Category_Id.Click();
            Category_Id.FindElement(By.XPath("//option[. = 'Beverages']")).Click();
            Supplier_Id.Click();
            Supplier_Id.FindElement(By.XPath("//option[. = 'Tokyo Traders']")).Click();

            Unit_Price.SendKeys(unitptice);
            Unit_Price.Click();
            QuantityPer_Unit.SendKeys(quantityperunit);
            QuantityPer_Unit.Click();
            UnitsIn_Stock.SendKeys(unitsinsrock);
            Unit_Price.Click();
            UnitsOn_Order.SendKeys(unitsonorder);
            UnitsOn_Order.Click();
            Reorder_Level.SendKeys(reorderlevel);
            Reorder_Level.Click();
            Button_OK.Click();

            return(new MainPage(driver));
        }
Exemplo n.º 3
0
 public Product_Name EditProduct(int id)
 {
     using (Liquor_ShopEntities _dbContext = new Liquor_ShopEntities())
     {
         Product_Name product = _dbContext.Product_Name.Find(id);
         return(product);
     }
 }
Exemplo n.º 4
0
 //Api Service for adding new product
 public bool AddProduct(Product_Name product, HttpPostedFileBase file)
 {
     using (Liquor_ShopEntities _dbContext = new Liquor_ShopEntities())
     {
         if (_dbContext.Product_Name.Any(p => p.ProductName == product.ProductName))
         {
             return(false);
         }
         product.Slug = product.ProductName.Replace(" ", "-").ToLower();
         _dbContext.Product_Name.Add(product);
         _dbContext.SaveChanges();
     }
     return(true);
 }
Exemplo n.º 5
0
        public ActionResult AddProduct(ProductVM model, HttpPostedFileBase file)
        {
            Liquor_ShopEntities _dbContext = new Liquor_ShopEntities();
            ProductDTO          dto        = Mapper.Map <ProductVM, ProductDTO>(model);
            Product_Name        prod       = Mapper.Map <ProductDTO, Product_Name>(dto);
            var isSave = productservice.AddProduct(prod, file);

            if (isSave == true)
            {
                int          id  = prod.ProId;
                Product_Name pro = _dbContext.Product_Name.Find(id);
                AddImage(pro, file);
                _dbContext.SaveChanges();
                ViewBag.Message = "Success";
            }
            return(RedirectToAction("Products"));
        }
Exemplo n.º 6
0
        public bool EditProductPost(Product_Name prod)
        {
            int id = prod.ProId;

            using (Liquor_ShopEntities _dbContext = new Liquor_ShopEntities())
            {
                Product_Name product = _dbContext.Product_Name.Find(id);
                product.ProductName = prod.ProductName;
                product.Description = prod.Description;
                product.Price       = prod.Price;
                product.Size        = prod.Size;
                product.Slug        = prod.ProductName.Replace(" ", "-").ToLower();
                product.SKU         = prod.SKU;
                product.CatFKId     = prod.CatFKId;
                product.ImageName   = prod.ImageName;

                _dbContext.SaveChanges();
            }
            return(true);
        }
 private void clear_Click(object sender, EventArgs e)
 {
     Cust_search.Clear();
     CustName.Clear();
     PhoneNumber.Clear();
     Cust_address.Clear();
     custEmail.Clear();
     Product_search.Clear();
     Product_Name.Clear();
     ProductID.Clear();
     Total_Amt.Text = "0";
     SubTotal.Clear();
     Discount.Text = "0";
     GST.Clear();
     PaidAmount.Clear();
     ReturnAmount.Clear();
     Quantity.Text            = "0";
     Amount.Text              = "0";
     AddedProducts.DataSource = null;
 }
Exemplo n.º 8
0
        public void AddImage(Product_Name prd, HttpPostedFileBase file)
        {
            string imagename   = Path.GetFileNameWithoutExtension(file.FileName);
            string extension   = Path.GetExtension(file.FileName);
            var    originalDir = new DirectoryInfo(String.Format("{0}Images", Server.MapPath(@"\")));
            var    pathstring  = Path.Combine(originalDir.ToString(), prd.ProductName);

            imagename = imagename + prd.ProId.ToString() + extension;


            if (!Directory.Exists(pathstring))
            {
                Directory.CreateDirectory(pathstring);
            }


            //string path = Path.Combine(Server.MapPath("~/Content/Images/"), imagename);
            var path = string.Format("{0}\\{1}", pathstring, imagename);

            prd.ImageName = imagename;
            file.SaveAs(path);
        }
Exemplo n.º 9
0
        public MainPage Exist()
        {
            loginField.SendKeys("user");
            passwordField.SendKeys("user");
            passwordField.Submit();

            All_Products.Click();
            Element.Click();

            Assert.AreEqual(Product_Name.GetAttribute("value"), "test");
            Assert.AreEqual(Category_Id.FindElement(By.CssSelector("#CategoryId > option:nth-child(2)")).GetAttribute("text"), "Beverages");
            Assert.AreEqual(Supplier_Id.FindElement(By.CssSelector("#SupplierId > option:nth-child(5)")).GetAttribute("text"), "Tokyo Traders");
            Assert.AreEqual(Unit_Price.GetAttribute("value"), "80,0000");
            Assert.AreEqual(QuantityPer_Unit.GetAttribute("value"), "30 in");
            Assert.AreEqual(UnitsIn_Stock.GetAttribute("value"), "40");
            Assert.AreEqual(UnitsOn_Order.GetAttribute("value"), "40");
            Assert.AreEqual(Reorder_Level.GetAttribute("value"), "5");

            Button_OK.Click();

            return(new MainPage(driver));
        }
        private void Save_Click(object sender, EventArgs e)
        {
            //Create the orders
            try
            {
                Connect connectObj = new Connect();
                con = connectObj.connect();
                SqlCommand cmd = new SqlCommand("Insert into MYORDER (ORD_ID,CID,DATE,AMOUNT) values(@oid,@cid,@date,@amount);", con);

                cmd.Parameters.AddWithValue("@oid", OrderID.Text);
                //cmd.Parameters.AddWithValue("@pid", textBox8.Text);
                cmd.Parameters.AddWithValue("@cid", cid);
                cmd.Parameters.AddWithValue("@date", date.Text);
                cmd.Parameters.AddWithValue("@amount", Total_Amt.Text);

                int i = cmd.ExecuteNonQuery();
                //If count is equal to 1, than show frmMain form
                if (i != 0)
                {
                    MessageBox.Show("Order Insertion Successful!", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Order Insertion Failed", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }
            //Insert into orderDetails
            try
            {
                int j;

                Connect connectObj = new Connect();
                con = connectObj.connect();


                for (int i = 0; i < transactionDT.Rows.Count; i++)
                {
                    SqlCommand cmd = new SqlCommand("Insert into ORDER_DETAILS (ord_id,pid,quantity) values(@oid,@pid,@quantity);", con);

                    cmd.Parameters.AddWithValue("@oid", OrderID.Text);
                    cmd.Parameters.AddWithValue("@pid", transactionDT.Rows[i]["Product ID"].ToString());
                    cmd.Parameters.AddWithValue("@quantity", transactionDT.Rows[i]["Quantity"].ToString());


                    j = cmd.ExecuteNonQuery();
                }
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }
            //Update stock table after creating order
            try
            {
                int     j;
                Connect connectObj = new Connect();
                con = connectObj.connect();

                for (int i = 0; i < transactionDT.Rows.Count; i++)
                {
                    SqlCommand cmd = new SqlCommand("UPDATE STOCK SET QUANTITY = QUANTITY - @quantity WHERE PID = @pid", con);

                    cmd.Parameters.AddWithValue("@pid", transactionDT.Rows[i]["Product ID"].ToString());
                    cmd.Parameters.AddWithValue("@quantity", transactionDT.Rows[i]["Quantity"].ToString());


                    j = cmd.ExecuteNonQuery();
                }
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }

            //Clear all the fields.
            Cust_search.Clear();
            CustName.Clear();
            PhoneNumber.Clear();
            Cust_address.Clear();
            custEmail.Clear();
            Product_search.Clear();
            Product_Name.Clear();
            ProductID.Clear();
            Total_Amt.Text = "0";
            SubTotal.Clear();
            Discount.Text = "0";
            GST.Clear();
            PaidAmount.Clear();
            ReturnAmount.Clear();
            Quantity.Text            = "0";
            Amount.Text              = "0";
            AddedProducts.DataSource = null;
        }
        private void Add_Click(object sender, EventArgs e)
        {
            String PNAME = Product_Name.Text;
            String PID   = ProductID.Text;

            if (Quantity.Text == "" || Product_Name.Text == "" || ProductID.Text == "")
            {
                MessageBox.Show("Enter the Quantity!!", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            try
            {
                Connect connectObj = new Connect();
                con = connectObj.connect();
                SqlCommand cmd = new SqlCommand("Select * from STOCK where PID =@pid and QUANTITY >= @quantity", con);

                cmd.Parameters.AddWithValue("@pid", ProductID.Text);
                cmd.Parameters.AddWithValue("@quantity", Quantity.Text);
                SqlDataAdapter adapt = new SqlDataAdapter(cmd);
                DataSet        ds    = new DataSet();
                adapt.Fill(ds);
                con.Close();
                int count = ds.Tables[0].Rows.Count;
                //If count is equal to 1, than show frmMain form
                if (count != 1)
                {
                    MessageBox.Show("Check stock!!!!", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }
            decimal quantity = decimal.Parse(Quantity.Text);
            decimal amount   = decimal.Parse(Amount.Text);
            decimal total    = amount * quantity;
            decimal subtotal = decimal.Parse(SubTotal.Text);


            subtotal += total;

            if (PNAME == "")
            {
                MessageBox.Show("select a product and try again", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                transactionDT.Rows.Add(PNAME, PID, quantity, amount, total);
                AddedProducts.DataSource = transactionDT;
                SubTotal.Text            = subtotal.ToString();

                if (ProductID.Text == "" || OrderID.Text == "")
                {
                    MessageBox.Show("Please provide all the details", "Captions", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }


                Product_Name.Clear();
                ProductID.Clear();
                Quantity.Text = "0";
                Amount.Text   = "0";
            }
        }
Exemplo n.º 12
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            int     IntTest;
            Double  DoubleTest;
            Boolean Fail = true;

            while (Fail)
            {
                _Product.Product_Name = Product_Name.Text;

                if (Int32.TryParse(Product_ID.Text, out IntTest))
                {
                    _Product.ProductId = Int32.Parse(Product_ID.Text);
                }
                else
                {
                    MessageBox.Show("Not an acceptible ID");
                    Fail = false;
                    break;
                }



                if (Int32.TryParse(Product_Stock.Text, out IntTest))
                {
                    _Product.Stock_Level = Int32.Parse(Product_Stock.Text);
                }
                else
                {
                    MessageBox.Show("Not an acceptible stock level");
                    Fail = false;
                    break;
                }

                if (Double.TryParse(Product_Price.Text, out DoubleTest))
                {
                    _Product.Price = Double.Parse(Product_Price.Text);
                }
                else
                {
                    MessageBox.Show("Not an acceptible price");
                    Fail = false;
                    break;
                }

                _PHPRepo.EditProductRecord(_Product);

                Product_ID.Clear();
                Product_Name.Clear();
                Product_Stock.Clear();
                Product_Price.Clear();

                Product_Name.Enabled  = false;
                Product_Stock.Enabled = false;
                Product_Price.Enabled = false;

                StockList.Items.Clear();
                List <Product> _NewList = _PHPRepo.GetProducts();
                foreach (Product p in _NewList)
                {
                    string[] row          = { p.ProductId.ToString(), p.Product_Name.ToString(), p.Price.ToString(), p.Stock_Level.ToString() };
                    var      listViewItem = new ListViewItem(row);
                    StockList.Items.Add(listViewItem);
                }
                ;

                Fail = false;
                break;
            }
        }