Esempio n. 1
0
 private void addItemButton_Click(object sender, EventArgs e)
 {
    
         aProductInfo = new Product(productIdTextBox.Text, Convert.ToInt16(quantityTextBox.Text));
         MessageBox.Show(aShop.AddProduct(aProductInfo));
         ShowItemInListView();    
  }
Esempio n. 2
0
        private void sellItemButton_Click(object sender, EventArgs e)
        {
            aProduct = new Product(sellProductIdTextBox.Text, Convert.ToInt16(sellQuantityTextBox.Text));
            string msg = shop.SellProduct(aProduct);

            ShowProductsOnListView();

            MessageBox.Show(msg);
        }
Esempio n. 3
0
 private void UpdateQuantity(Product aNewProduct)
 {
     foreach (Product aProduct in productList)
     {
         if (aProduct.ProductId == aNewProduct.ProductId)
         {
             aProduct.Quantity += aNewProduct.Quantity;
         }
     }
 }
Esempio n. 4
0
 public string SaveProduct(Product aProduct)
 {
     SqlConnection conn = new SqlConnection(connectionString);
     conn.Open();
     string query = "INSERT INTO t_Product(Quantity, ProductID) VALUES (" + aProduct.Quantity + ",'" +
                    aProduct.ProductId + "')";
     sqlCommand = new SqlCommand(query, conn);
     sqlCommand.ExecuteNonQuery();
     conn.Close();
     return "Product has been saved";
 }
Esempio n. 5
0
 public string SellProduct(Product aSellProduct)
 {
     foreach (Product aProduct in productList)
     {
         if (aProduct.ProductId == aSellProduct.ProductId)
         {
             aProduct.Quantity -= aSellProduct.Quantity;
             return "Product Sold!";
         }
     }
     return "The product does not exists!";
 }
Esempio n. 6
0
 private string UpdateProductQuantity(Product aProduct)
 {
     string connectionString =
         @"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\FTFL-ITS-2014000122\SuperShopWithAddAndSellApp\SuperShopWithAddAndSellApp\SuperShop.mdf";
     SqlConnection conn = new SqlConnection(connectionString);
     conn.Open();
     string query = "UPDATE Product_table SET Quantity = Quantity + " + aProduct.Quantity + " WHERE ProductID = '" + aProduct.ProductId + "'"; 
     SqlCommand insert = new SqlCommand(query, conn);
     insert.ExecuteNonQuery();
     conn.Close();
     return "Product has been saved.";            
 }
Esempio n. 7
0
 private void addItemButton_Click(object sender, EventArgs e)
 {
     string id = productIdTextBox.Text;
     int quantity = Convert.ToInt16(quantityTextBox.Text);
     aProduct = new Product(id, quantity);
     string mes = shop.AddProduct(aProduct);
     MessageBox.Show(mes);
       string msg = aDatabase.AddProductInDatabase(id, quantity);
      MessageBox.Show(msg);
     
     ShowProductsOnListView();
 }
Esempio n. 8
0
 public string AddProduct(Product aNewProduct)
 {
    if(HasThisID(aNewProduct.ProductId))
     {
         UpdateQuantity(aNewProduct);
         return "product updated";
     }
    else
    {
        productList.Add(aNewProduct);
        return "product added";
    }
 }
Esempio n. 9
0
 public string SellProduct(Product aSellProduct)
 {
     if (HasThisIdInSell(aSellProduct.ProductId))
     {
        return SellQuantity(aSellProduct);
        // return "product updated";
     }
     else
     {
       //  productList.Add(aNewProduct);
         return "product is not found";
     }
 }
Esempio n. 10
0
 private string AddProduct(Product aProduct)
 {
     string connectionString =
         @"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\FTFL-ITS-2014000122\SuperShopWithAddAndSellApp\SuperShopWithAddAndSellApp\SuperShop.mdf";
     SqlConnection conn = new SqlConnection(connectionString);
     conn.Open();
     string query = "INSERT INTO Product_table(Quantity, ProductID) VALUES (" + aProduct.Quantity + ",'" +
                    aProduct.ProductId + "')";
     SqlCommand insert = new SqlCommand(query, conn);
     insert.ExecuteNonQuery();
     conn.Close();
     return "Product has been saved.";
 }
Esempio n. 11
0
        public string SellProduct(Product aNewProduct)
        {
            foreach (Product aProduct in productList)
            {
                if (aProduct.ProductId == aNewProduct.ProductId)
                {
                    aProduct.Quantity -= aNewProduct.Quantity;
                    return "product Updated";
                }

            }
            //productList.Add(aNewProduct);
            return "succefully selled";
        }
Esempio n. 12
0
        public string AddProduct(Product aNewProduct)
        {
            foreach (Product aProduct in productList)
            {
                if (aProduct.ProductId == aNewProduct.ProductId)
                {
                    aProduct.Quantity += aNewProduct.Quantity;
                    return "product Updated";
                }

            }
            productList.Add(aNewProduct);
            return "succefully added";
        }
Esempio n. 13
0
        private void addProductButton_Click(object sender, EventArgs e)
        {
            int qty = Convert.ToInt16(quantityTextBox.Text);
            Product aProduct = new Product(productIdTextBox.Text, qty);

            if (HasThisId(aProduct.ProductId))
            {
                MessageBox.Show(UpdateProductQuantity(aProduct));
            }
            else
            {
                MessageBox.Show(AddProduct(aProduct));
            }
            ShowItemInListView();
        }
Esempio n. 14
0
        private void addItemButton_Click(object sender, EventArgs e)
        {
            string id = productIdTextBox.Text;
            int qty = Convert.ToInt16(quantityTextBox.Text);
             Product aProduct = new Product(productIdTextBox.Text, qty);

             if (aDatabase.HasThisId(id))
             {
                 MessageBox.Show(aDatabase.UpdateProductInDatabase(id,qty));
             }
             else
             {
                 MessageBox.Show(aDatabase.AddProductInDatabase(id,qty));
             }


             addItemdataGridView.DataSource = null;
             addItemdataGridView.DataSource = aDatabase.fillDataTable("Product"); // table name
           // ShowProductsOnListView();
        }
Esempio n. 15
0
        private void sellItemButton_Click(object sender, EventArgs e)
        {
            aDatabase = new Database();

            string id = sellProductIdTextBox.Text;
            int quantity = Convert.ToInt16(sellQuantityTextBox.Text);
            aProduct = new Product(id, quantity);
            
            if (aDatabase.HasThisId(id))
            {
                MessageBox.Show(aDatabase.SellProductInDatabase(id, quantity));
            }
            else
            {
                MessageBox.Show("Product not fornd");
            }

            sellItemdataGridView.DataSource = null;
            sellItemdataGridView.DataSource = aDatabase.fillDataTable("Product"); // table name
        }
Esempio n. 16
0
        public List<Product> GetAllProduct()
        {
            SqlConnection conn = new SqlConnection(connectionString);
            conn.Open();
            string query = "SELECT ProductId, Quantity FROM t_Product";
            SqlCommand insert = new SqlCommand(query, conn);
            SqlDataReader productReader = insert.ExecuteReader();

            List<Product> productList = new List<Product>();

            while (productReader.Read())
            {
                Product aProduct = new Product();
                aProduct.ProductId = productReader["productId"].ToString();
                aProduct.Quantity = Convert.ToInt16(productReader["Quantity"]);
                productList.Add(aProduct);

            }
            conn.Close();
            return productList;
        }
Esempio n. 17
0
        public string SellProduct(Product aNewProduct)
        {
            foreach (Product aProduct in productList)
            {
                if (aProduct.ProductId == aNewProduct.ProductId)
                {
                    bool isSuccess = aProduct.DeductQuantity(aNewProduct.Quantity);
                    if (!isSuccess)
                    {
                        return "Insuficient quantity";
                    }

                    return "Sell success";
                }
            }
            return "success";

            //public List<Product> GetProductList()
            //{
            //    return productList;
            //}
        }
Esempio n. 18
0
 private void sellItemButton_Click(object sender, EventArgs e)
 {
     aProductInfo = new Product(sellProductIdTextBox.Text, Convert.ToInt16(sellQuantityTextBox.Text));
     MessageBox.Show(aShop.SellProduct(aProductInfo));
     SellItemInListView();
 }
Esempio n. 19
0
 private string AddProduct(Product aProduct)
 {
     aDatabaseGateway.SaveProduct(aProduct);
     return "Product has been saved.";
 }
Esempio n. 20
0
 private void sellProductButton_Click(object sender, EventArgs e)
 {
     aproductInfo = new Product(productIdTextBox.Text, Convert.ToInt16(quantityTextBox.Text));
     MessageBox.Show(ashop.SellProduct(aproductInfo));
     ShowSellItemListView();
 }
Esempio n. 21
0
 private string SellQuantity(Product aSellProduct)
 {
     foreach (Product aProduct in productList)
     {
         if (aProduct.ProductId == aSellProduct.ProductId)
         {
             if (aProduct.Quantity >= aSellProduct.Quantity && aProduct.Quantity != 0)
             {
                 aProduct.Quantity -= aSellProduct.Quantity;
                 return "product has been selled";
             }
             else
             {
                 return "sorry, sell quqntity is not sufficient";
             }
         }
     }
     return null;
 }
Esempio n. 22
0
 private string UpdateProductQuantity(Product aProduct)
 {
     return aDatabaseGateway.IncreaseProductQuantity(aProduct);
 }
Esempio n. 23
0
 public string IncreaseProductQuantity(Product aProduct)
 {
     SqlConnection conn = new SqlConnection(connectionString);
     conn.Open();
     string query = "UPDATE t_Product SET Quantity = Quantity + " + aProduct.Quantity + " WHERE ProductID = '" + aProduct.ProductId + "'";
     SqlCommand insert = new SqlCommand(query, conn);
     insert.ExecuteNonQuery();
     conn.Close();
     return "Product quantity has been increased";            
 }