Exemple #1
0
        public IActionResult OnPost()
        {
            NewProduct.Description = ProductDescription;
            NewProduct.Id          = OldProduct.Id;
            int click = Int32.Parse(Request.Form["click"]);

            if (click == 1)
            {
                ProductsDB.UpdateProduct(NewProduct, _configuration);
                string currentShoppingCart = Request.Cookies["ShoppingCart"];
                if (currentShoppingCart != null && currentShoppingCart != "")
                {
                    string newShoppingCart = ProductsCookies.UpdateProduct(currentShoppingCart, NewProduct);
                    var    cookieOptions   = new CookieOptions {
                        Expires = DateTime.Now.AddDays(1)
                    };
                    Response.Cookies.Append("ShoppingCart", newShoppingCart, cookieOptions);
                }
                return(RedirectToPage("/Index"));
            }
            else
            {
                return(RedirectToPage("/Index"));
            }
        }
Exemple #2
0
        /// <summary>
        /// Add button adds new products to the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// @Author - Rohit
        private void btnAddProducts_Click(object sender, EventArgs e)
        {
            products = ProductsDB.GetAllProducts();

            if (products.FindIndex(prod => prod.ProductName == txtProductName.Text) >= 0)
            {
                MessageBox.Show("That product is already added.");
            }
            else
            {
                try
                {
                    ComProductId.Enabled = false;                                               // disables the product id textbox (not required while adding products)
                    string ProdName = txtProductName.Text;
                    if (ProdName == "")                                                         // null value validation on product name
                    {
                        MessageBox.Show("Null and Dublicate values are not allowed.", "Error"); // message box pop uo
                    }
                    else // if product name is not null add the new product using Add product method
                    {
                        ProductsDB.AddProducts(ProdName);
                        ShowProductsInProductsTab();                                      // Updates data grid view
                        LoadComboBox();                                                   // updates combo box to view the added product immediately
                        MessageBox.Show("New product succesfully added.", "Add Product"); // message box pop up
                        clear();                                                          // clears the fields after adding new product
                    }
                    ComProductId.Enabled = true;                                          // After the product is added, enable the product id textbox
                }
                catch (FormatException)                                                   // catches any format issues and null value exceptions
                {
                    MessageBox.Show("Null values are not allowed, Type correct information.", "Null Value / Incorrect Format");
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Modify the current selected product in the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// @Author - Rohit
        private void btnModifyProducts_Click(object sender, EventArgs e)
        {
            products = ProductsDB.GetAllProducts();

            if (products.FindIndex(prod => prod.ProductName == txtProductName.Text) >= 0)
            {
                MessageBox.Show("That product is already added.");
            }
            else
            {
                try
                {
                    int    ProdID   = Convert.ToInt32(ComProductId.SelectedItem);
                    string ProdName = txtProductName.Text;
                    if (string.IsNullOrEmpty(ProdName) || ComProductId.SelectedItem == null) // validation for null product name
                    {
                        MessageBox.Show("Please enter product name and select product ID.", "Incorrect Value");
                    }
                    else // if the product name is not null then use the modify method form database access class to modify the product
                    {
                        ProductsDB.ModifyProducts(ProdName, ProdID);
                        MessageBox.Show("Product name updated successfully", "Update"); // message pop up
                        clear();                                                        // clears the fields after modifying
                        ShowProductsInProductsTab();                                    // updates the datagridview after modifying the products
                    }
                }
                catch (FormatException)                                                     // catches any format issues and null value exceptions
                {
                    MessageBox.Show("Null values are not allowed", "Null Value Exception"); // message pop up
                }
            }
        }
Exemple #4
0
 // Tab Two Changed (by using ALL, EDIT, ADD btn): change UI appearance accordingly
 private void twoTab_SelectedIndexChanged(object sender, EventArgs e)
 {
     twoBtnViewAll.BackColor = Color.DarkCyan;;
     twoBtnEdit.BackColor    = Color.DarkCyan;
     twoBtnAdd.BackColor     = Color.DarkCyan;
     twoBtnSave.Visible      = true;
     if (twoTab.SelectedIndex == 0)
     {
         twoBtnSave.Visible = false;
         // 'ALL' tab, load all Product Supplier data and fill DataSource
         _psList = Products_suppliersDB.GetAllProductSupplierWithNames().OrderBy(ps => ps.ProdName).ToList();
         // use List to make a SortableBindingList
         var _sortableList = new SortableBindingList <ProductSupplierWithName>(_psList);
         productSupplierWithNameBindingSource.DataSource = _sortableList;
         // databinding for combo boxes
         suppliersBindingSource.DataSource = SuppliersDB.GetSuppliers().OrderBy(s => s.SupName);
         productsBindingSource.DataSource  = ProductsDB.GetProducts();
     }
     else if (twoTab.SelectedIndex == 2)
     {
         // 'ADD' tab
         // select nothing when load
         twoCmbAddProdName.SelectedIndex = -1;
         twoCmbAddSuppName.SelectedIndex = -1;
     }
     // 'EDIT' tab
 }
Exemple #5
0
        private void loadList()
        {
            if (comboBoxSupplier.SelectedValue != null)
            {
                int supID = Convert.ToInt32(comboBoxSupplier.SelectedValue);
                selectedSupplierID = supID;
                try
                {
                    // run the slq query method (included in ProductSupplier table)
                    list = ProductsDB.GetProducts(supID);

                    // run the toher sql query method (the not in)
                    notInList = ProductsDB.GetProdNotInList(supID);

                    // Display info
                    lstProducts.DataSource    = list;
                    lstProducts.DisplayMember = "ProdName";
                    lstProducts.ValueMember   = "ProductId";

                    listProducts.DataSource    = notInList;
                    listProducts.DisplayMember = "ProdName";
                    listProducts.ValueMember   = "ProductId";
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
            }
        }
Exemple #6
0
        //delete product button
        private void btnProdDelete_Click(object sender, EventArgs e)
        {
            string res = ProductsDB.DeleteProduct((int)LBProducts.SelectedValue);

            if (res != null)
            {
                if (res == "SUCCESS")
                {
                    KeyValuePair <string, int> vv = new KeyValuePair <string, int>("", -99);
                    foreach (KeyValuePair <string, int> v in ProductsDB.Products)
                    {
                        if (v.Value == (int)LBProducts.SelectedValue)
                        {
                            vv = v;
                        }
                    }

                    if (vv.Value != -99)
                    {
                        ProductsDB.Products.Remove(vv);
                    }
                    MessageBox.Show("Delete successful.", "Success");
                }
                else
                {
                    MessageBox.Show("Did not delete: " + res, "Error");
                }
            }
        }
Exemple #7
0
 /// <summary>
 /// Update All List of Infos
 /// </summary>
 private void UpdateAllInfos()
 {
     AllPackages       = PackagesDB.GetPackages();
     AllProducts       = ProductsDB.GetProducts();
     AllSuppliers      = SuppliersDB.GetSuppliers();
     ProSupLinkages    = ProSupDB.GetProSups();
     PacProSupLinkages = PacProSupDB.GetPacProSup();
 }
Exemple #8
0
        public void ProductsDbGetProductsReturnsListProductAndInt()
        {
            //Assign
            var productsDb = new ProductsDB();

            //Act + Assert
            Assert.IsTrue(productsDb.GetProducts() is List <(Product, int)>);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ProductsDB productsDB = db.Products.Find(id);

            db.Products.Remove(productsDB);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #10
0
        public void ProductsDbAddProductReturnsTrue()
        {
            //Assign
            var productsDb = new ProductsDB();
            var product    = new Product();

            //Act + Assert
            Assert.IsTrue(productsDb.AddProduct(product));
        }
Exemple #11
0
        public void ProductsDbGetProductReturnsProductAndInt()
        {
            //Assign
            var productsDb = new ProductsDB();
            var product    = new Product();

            productsDb.AddProduct(product);
            //Act + Assert
            Assert.AreEqual(productsDb.GetProduct(product.Name).Item1, product);
        }
Exemple #12
0
        public void ProductsDbChangeProductInfoReturnsTrue()
        {
            //Assign
            var productsDb = new ProductsDB();
            var product    = new Product();

            productsDb.AddProduct(product);
            //Act + Assert
            Assert.IsTrue(productsDb.ChangeProductInfo(product.Id, new Product(), 0));
        }
 public ActionResult Edit([Bind(Include = "id,price,model_name,product_name,size,counting_unit")] ProductsDB productsDB)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productsDB).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(productsDB));
 }
        public ActionResult Create([Bind(Include = "id,price,model_name,product_name,size,counting_unit")] ProductsDB productsDB)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(productsDB);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(productsDB));
        }
Exemple #15
0
 public IActionResult OnPost()
 {
     if (!ModelState.IsValid)
     {
         return(Page());
     }
     else
     {
         ProductsDB.AddProduct(NewProduct, _configuration);
         return(RedirectToPage("/Index"));
     }
 }
Exemple #16
0
 // Convenient Method: find if there is a duplicated product name in DB, return bool
 private bool FindDuplicatedProductName(string productName)
 {
     if (ProductsDB.GetProducts().Find(p => p.ProdName == productName) == null)
     {
         return(false);
     }
     else
     {
         MessageBox.Show("The product you input already exists.", "Duplicated Name");
         return(true);
     }
 }
Exemple #17
0
        //Method for OK button to add new product to list and database
        private void btnOK_Click(object sender, EventArgs e)
        {
            string name = txtProdName.Text.ToString();                                //get text from textbox
            int    i    = ProductsDB.AddNewProduct(name.ToUpper());                   //change input to uppercase

            KeyValuePair <string, int> val = new KeyValuePair <string, int>(name, i); //create key value pair for databse

            ProductsDB.Products.Add(val);                                             //add new value pair to database

            MessageBox.Show("Created new product.", "Success");                       //popup confirmation
            this.Close();
        }
Exemple #18
0
        /// <summary>
        /// Once the products tab is selected, populate the combo box and datagrid view
        /// </summary>
        /// @Author - Rohit
        private void LoadComboBox()
        {
            ComProductId.Items.Clear();                                 // clear the grid view
            List <Products> dispProducts = ProductsDB.GetAllProducts(); // get products from database

            ViewProducts.DataSource = dispProducts;                     // display them

            // loop through products and add ids to drop down
            foreach (Products prod in dispProducts)
            {
                ComProductId.Items.Add(prod.ProductID.ToString());
            }
        }
        // GET: Products/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductsDB productsDB = db.Products.Find(id);

            if (productsDB == null)
            {
                return(HttpNotFound());
            }
            return(View(productsDB));
        }
Exemple #20
0
        // ----- 3RD NAV BTN: Products -----

        // Tab Three Changed (by using ALL, EDIT, ADD btn): change UI appearance accordingly
        private void threeTab_SelectedIndexChanged(object sender, EventArgs e)
        {
            threeBtnSave.Visible   = true;
            threeBtnAll.BackColor  = Color.DarkCyan;
            threeBtnEdit.BackColor = Color.DarkCyan;
            threeBtnAdd.BackColor  = Color.DarkCyan;
            if (threeTab.SelectedIndex == 0)
            {
                // view ALL mode: hide save button
                threeBtnSave.Visible = false;
                // bind data to grid view
                var productsList      = ProductsDB.GetProducts();
                var _sortableProducts = new SortableBindingList <Products>(productsList);
                productsBindingSource.DataSource = _sortableProducts;
            }
        }
Exemple #21
0
        public IActionResult OnPost()
        {
            int click = Int32.Parse(Request.Form["click"]);

            if (click == 1)
            {
                Product = ProductsDB.GetProduct(Product.Id, _configuration);
                string currentShoppingCart = Request.Cookies["ShoppingCart"];
                string newShoppingCart     = ShoppingCartCookie.AddProduct(Product, currentShoppingCart);
                var    cookieOptions       = new CookieOptions {
                    Expires = DateTime.Now.AddDays(1)
                };
                Response.Cookies.Append("ShoppingCart", newShoppingCart, cookieOptions);
            }
            return(RedirectToPage("/Index"));
        }
Exemple #22
0
        protected override void SetUp()
        {
            mProps    = new ProductsProps();
            mOldProps = new ProductsProps();

            if (this.mConnectionString == "")
            {
                mdbReadable  = new ProductsDB();
                mdbWriteable = new ProductsDB();
            }

            else
            {
                mdbReadable  = new ProductsDB(this.mConnectionString);
                mdbWriteable = new ProductsDB(this.mConnectionString);
            }
        }
Exemple #23
0
 /// <summary>
 /// Once product id is selected form drop down, product name is retrieved from the database
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 /// @Author - Rohit
 private void ComProductId_SelectedValueChanged(object sender, EventArgs e)
 {
     try
     {
         int      ProductID = Convert.ToInt32(ComProductId.SelectedItem);
         Products myProduct = ProductsDB.GetProducts(ProductID);
         txtProductName.Text = myProduct.ProductName;
     }
     catch (FormatException) // format exception to only accept an positive integer
     {
         MessageBox.Show("Select or type valid Product ID", "Incorrect Input");
     }
     catch (NullReferenceException) // exception handled for null values
     {
         MessageBox.Show("Product Id does not exist.", "Incorrect Input");
     }
 }
Exemple #24
0
        // Load data for main form (first tab - Packages).
        private void loadMainFormData()
        {
            try
            {
                // access packages from db in thread (ASYNCHRONOUS) - Probably uneccessary

                /*Thread pkgWork = new Thread(() =>
                 * Thread pkgWork = new Thread(() =>
                 * {
                 *  packages = PackageDB.GetPackages();
                 * });
                 *
                 * // access all products from db in thread
                 * Thread prodWork = new Thread(() =>
                 * {
                 *  products = ProductsDB.GetAllProducts();
                 * });
                 *
                 * pkgWork.Start();
                 * prodWork.Start();
                 *
                 * pkgWork.Join();
                 * prodWork.Join();*/
                packages = PackageDB.GetPackages();
                products = ProductsDB.GetAllProducts();

                // access products and suppliers associated with current package
                PackageDB.GetPackageProducts(packages[pkgPos].PackageId, out pkgProducts, out pkgProdSupps);

                ShowPackages();
                ShowAllProducts();
                ShowPkgProducts(pkgProducts, pkgProdSupps);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while loading data.\n\n" + ex.Message,
                                ex.GetType().ToString());
            }
        }
Exemple #25
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                if (Validator.IsPresentCombo(productIdComboBox, "ID") && Validator.IsPresent(prodNameTextBox, "New Product Name") && Validator.IsCorrectLength(prodNameTextBox, "Name", 20) && Validator.IsNameValid(prodNameTextBox, "Name"))
                {
                    Products findOldProduct = FindOldProduct(productIdComboBox);


                    if (findOldProduct != null)
                    {
                        Products newProduct = productUpdate(prodNameTextBox, CreateObject(findOldProduct));


                        bool Success = ProductsDB.UpdateProduct(findOldProduct, newProduct);

                        if (Success)
                        {
                            MessageBox.Show("Product is updated :)");
                        }
                        UpdateAllInfos();
                        productsDataGridView.DataSource = AllProducts;
                    }
                    else
                    {
                        MessageBox.Show("Cant find Product ID");
                    }
                }
                else
                {
                    MessageBox.Show("Please re-enter. ");
                }
            }
            //catch the other error and show the ex error message from db class
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
Exemple #26
0
        private void btnProAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (Validator.IsPresent(txtNewProductName, "New Product Name") && Validator.IsCorrectLength(txtNewProductName, "Name", 20) && Validator.IsNameValid(txtNewProductName, "Name"))
                {
                    Products newProduct = productUpdate1(txtNewProductName);


                    newProduct.ProductId = ProductsDB.AddProduct(newProduct);


                    MessageBox.Show("Product is updated :)");
                    UpdateAllInfos();
                    productsDataGridView.DataSource = AllProducts;
                }
            }
            //catch the other error and show the ex error message from db class
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
Exemple #27
0
        public bool Consume(string username, string product, int quantity)
        {
            IProductsDB      productsDB      = new ProductsDB();
            IProductsManager productsManager = new ProductsManager(productsDB);

            decimal price = productsManager.GetProductPrice(product) * quantity;

            Account account = GetAccountByUsername(username);

            if (account.Amount - price < 0)
            {
                return(false);
            }
            account.Amount -= price;

            var nbRowsAffected = AccountDb.UpdateAccount(account);

            if (nbRowsAffected == 0)
            {
                return(false);
            }

            return(true);
        }
Exemple #28
0
 public void OnGet(int id)
 {
     Product = ProductsDB.GetProduct(id, _configuration);
 }
 public HttpResponseMessage Delete(int id)
 {
     ProductsDB.TblProducts.Remove(ProductsDB.TblProducts.FirstOrDefault(x => x.ProductId == id));
     return(ToJson(ProductsDB.SaveChanges()));
 }
 public HttpResponseMessage Put(int id, [FromBody] TblProduct value)
 {
     ProductsDB.Entry(value).State = EntityState.Modified;
     return(ToJson(ProductsDB.SaveChanges()));
 }