Exemplo n.º 1
0
 private void btnRemoveProductFromShop_Click(object sender, EventArgs e)
 {
     if (lbProducts.SelectedIndex != -1 && lbShops.SelectedIndex != -1)
     {
         using (DBHelper helper = new DBHelper())
         {
             MySqlCommand command = new MySqlCommand("DELETE FROM ml_shop_product WHERE shop_id = @shop_id AND product_id = @product_id", helper.GetConnection());
             command.Parameters.AddWithValue("@shop_id", lbShops.SelectedValue);
             command.Parameters.AddWithValue("@product_id", lbProducts.SelectedValue);
             helper.Open();
             if (command.ExecuteNonQuery() == 1)
             {
                 DirectMessage.ShowInfo("Product removed successfully.");
             }
             else
             {
                 DirectMessage.ShowError("Something went wrong.");
             }
         }
     }
     else
     {
         DirectMessage.ShowError("You have to select a product and a shop from which to remove it.");
     }
 }
Exemplo n.º 2
0
 private void btnAddProduct_Click(object sender, EventArgs e)
 {
     if (tbxName.Text != "")
     {
         using (DBHelper helper = new DBHelper())
         {
             try
             {
                 MySqlCommand command = new MySqlCommand("INSERT INTO ml_product (name, description) VALUES (@name, @description);", helper.GetConnection());
                 command.Parameters.AddWithValue("@name", tbxName.Text);
                 command.Parameters.AddWithValue("@type", rtbxDescription.Text);
                 helper.Open();
                 if (command.ExecuteNonQuery() == 1)
                 {
                     DirectMessage.ShowInfo("Product added successfully.");
                     UpdateShops();
                 }
                 else
                 {
                     DirectMessage.ShowError("Something went wrong.");
                 }
             }
             catch (MySqlException)
             {
                 DirectMessage.ShowError("There was problem executing the operation.");
             }
         }
     }
     else
     {
         DirectMessage.ShowError("You have to fill in a name.");
     }
 }
Exemplo n.º 3
0
 private void btnAddProductToShop_Click(object sender, EventArgs e)
 {
     if (lbProducts.SelectedIndex != -1 && lbShops.SelectedIndex != -1)
     {
         if (lblTag.Text != "-")
         {
             try
             {
                 int quantity = Convert.ToInt32(tbxQuantity.Text);
                 try
                 {
                     decimal price = Convert.ToDecimal(tbxPrice.Text);
                     using (DBHelper helper = new DBHelper())
                     {
                         try
                         {
                             MySqlCommand command = new MySqlCommand("INSERT INTO ml_shop_product (shop_id, product_id, RFID_code, quantity, price) VALUES (@shop_id, @product_id, @rfid_code, @quantity, @price);", helper.GetConnection());
                             command.Parameters.AddWithValue("@shop_id", lbShops.SelectedValue);
                             command.Parameters.AddWithValue("@product_id", lbProducts.SelectedValue);
                             command.Parameters.AddWithValue("@rfid_code", lblTag.Text);
                             command.Parameters.AddWithValue("@quantity", quantity);
                             command.Parameters.AddWithValue("@price", price);
                             helper.Open();
                             if (command.ExecuteNonQuery() == 1)
                             {
                                 DirectMessage.ShowInfo("Product added successfully.");
                             }
                             else
                             {
                                 DirectMessage.ShowError("Something went wrong.");
                             }
                         }
                         catch (MySqlException)
                         {
                             DirectMessage.ShowError("There was problem executing the operation.");
                         }
                     }
                 }
                 catch (FormatException)
                 {
                     DirectMessage.ShowError("Invalid price format.");
                 }
             }
             catch (FormatException)
             {
                 DirectMessage.ShowError("Invalid quantity format.");
             }
         }
         else
         {
             DirectMessage.ShowError("You have to read an RFID code.");
         }
     }
     else
     {
         DirectMessage.ShowError("You have to select a product and a shop to which to add it.");
     }
 }