private void ProductCategoryComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ProductsGridView.Rows.Clear();

            if (ProductCategoryComboBox.SelectedIndex == 0)
            {
                FoodRepository _DataAccess = new FoodRepository();

                foreach (Food ProductDetail in _DataAccess.RetreiveAllProducts())
                {
                    ProductsGridView.Rows.Add(ProductDetail.FId, ProductDetail.FName, ProductDetail.FPrice, ProductDetail.FCategory, ProductDetail.FDescription, ProductDetail.FPicture);
                }
            }
            else if (ProductCategoryComboBox.SelectedIndex > 0)
            {
                string CategoryName = ProductCategoryComboBox.SelectedItem.ToString();

                FoodRepository _DataAccess = new FoodRepository();

                int CategoryID = _DataAccess.ReturnCategoryID(CategoryName);

                foreach (Food ProductDetail in _DataAccess.RetreiveProductsFromCategory(CategoryID))
                {
                    ProductsGridView.Rows.Add(ProductDetail.FId, ProductDetail.FName, ProductDetail.FPrice, CategoryName, ProductDetail.FDescription, ProductDetail.FPicture);
                }
            }
        }
        private void UpdateProductButton_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are You Sure You Want to Update this Product?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                FoodRepository _DataAccess = new FoodRepository();

                int ProductID = Convert.ToInt32(ProductIDBox.Text);

                string ProductName = ProductNameBox.Text;

                decimal ProductPrice = Convert.ToDecimal(ProductPriceBox.Text);

                string ProductCategory = ProductCategoryComboBox.Text;

                int ProductCategoryID = _DataAccess.ReturnCategoryID(ProductCategory);

                string ProductDescription = ProductDescriptionRBox.Text;

                /*initializing memory stream class for creating a stream of binary numbers*/
                MemoryStream ms = new MemoryStream();

                /*saving the image in raw format from picture box*/
                ProductPictureBox.Image.Save(ms, ProductPictureBox.Image.RawFormat);

                /*Array of Binary numbers that have been converted*/
                byte[] MyProductPicture = ms.GetBuffer();

                /*closing the memory stream*/
                ms.Close();

                if (_DataAccess.UpdateProduct(ProductID, ProductName, ProductPrice, ProductCategoryID, ProductDescription, MyProductPicture))
                {
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Product Not Updated", "Error", MessageBoxButtons.OK);
                }
            }
        }
Ejemplo n.º 3
0
        private void AddProductButton_Click(object sender, EventArgs e)
        {
            FoodRepository _DataAccess = new FoodRepository();

            /*THIS IS THE MAIN CODE FOR HASHING*/

            /*initializing memory stream class for creating a stream of binary numbers*/
            MemoryStream ms = new MemoryStream();

            /*saving the image in raw format from picture box*/
            ProductPictureBox.Image.Save(ms, ProductPictureBox.Image.RawFormat);

            /*Array of Binary numbers that have been converted*/
            byte[] ProductPicture = ms.GetBuffer();

            /*closing the memory stream*/
            ms.Close();

            /*HASHING END HERE*/


            if (_DataAccess.AddNewProductToDatabase(ProductNameBox.Text, Convert.ToDecimal(ProductPriceBox.Text), _DataAccess.ReturnCategoryID(ProductCategoryComboBox.SelectedItem.ToString()), ProductDescriptionRBox.Text, ProductPicture))
            {
                MessageBox.Show("Product Added");
            }
            else
            {
                MessageBox.Show("Product Not Added");
            }
        }