示例#1
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
 }
示例#2
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;
                }
            }
        }
示例#3
0
        public void ProductsDbGetProductsReturnsListProductAndInt()
        {
            //Assign
            var productsDb = new ProductsDB();

            //Act + Assert
            Assert.IsTrue(productsDb.GetProducts() is List <(Product, int)>);
        }
示例#4
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();
 }
示例#5
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);
     }
 }
示例#6
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;
            }
        }
示例#7
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");
     }
 }
示例#8
0
 public void OnGet()
 {
     Products = ProductsDB.GetProducts(Products, _configuration);
 }
示例#9
0
 // btn SAVE: save edit (update) or save add (create)
 private void threeBtnSave_Click(object sender, EventArgs e)
 {
     if (threeTab.SelectedIndex == 1) // EDIT MODE
     {
         // get current displaying product obj
         var currentProd = ProductsDB.GetProducts().
                           SingleOrDefault(p => p.ProductId == Convert.ToInt32(threeTxtEditProdId.Text));
         // initiate new product obj
         Products newProd;
         // validate: product name is empty or duplicated
         if (Validator.TBIsEmpty(threeTxtEditProdName, "Product Name") ||
             FindDuplicatedProductName(threeTxtEditProdName.Text))
         {
             // empty or same, do not perform update
             threeTxtEditProdName.Text = currentProd.ProdName;
             threeTxtEditProdName.SelectAll();
             return;
         }
         else
         {
             // name is valid, create new Product obj
             newProd = new Products {
                 ProdName = threeTxtEditProdName.Text
             }
         };
         // try to perform update
         try
         {
             Console.WriteLine("Old prod name is: " + currentProd.ProdName);
             var rowsAffected = ProductsDB.UpdateProduct(currentProd, newProd);
             MessageBox.Show($"{rowsAffected} record was updated.", "Congratulations");
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
     else if (threeTab.SelectedIndex == 2) // ADD MODE
     {
         // validate input, check if empty or have duplicated name
         if (!Validator.TBIsEmpty(threeTxtAddProdName, "Product Name") &&
             !FindDuplicatedProductName(threeTxtAddProdName.Text))
         {
             // validation passed, create new product using user input
             var newProd = new Products {
                 ProdName = threeTxtAddProdName.Text
             };
             // try to insert into DB
             try
             {
                 var id = ProductsDB.AddProduct(newProd);
                 MessageBox.Show($"New product {newProd.ProdName} is added, product id is: {id}.", "Congratulations");
                 threeTxtAddProdName.Clear();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }
     }
 }