Example #1
0
        public static bool Update(Raw_Stock stockItem)
        {
            //check the customer input data
            try
            {
                string insertQuery =
                    "UPDATE raw_stock SET stock_name=@stock_name, stock_category=@stock_category, " +
                    "stock_qty=@stock_qty, stock_reorder_level=@stock_reorder_level, " +
                    "stock_price=@stock_price, sup_id=@sup_id WHERE stock_id=@stock_id";
                SqlCommand insertCommand = new SqlCommand(insertQuery, Database.GetConnection());
                insertCommand.Parameters.AddWithValue("@stock_name", stockItem.Name);
                insertCommand.Parameters.AddWithValue("@stock_category", stockItem.Category);
                insertCommand.Parameters.AddWithValue("@stock_qty", stockItem.Quantity);
                insertCommand.Parameters.AddWithValue("@stock_reorder_level", stockItem.ReorderLevel);
                insertCommand.Parameters.AddWithValue("@stock_price", stockItem.Price);
                insertCommand.Parameters.AddWithValue("@sup_id", stockItem.Supplier.ID);
                insertCommand.Parameters.AddWithValue("@stock_id", stockItem.ID);

                insertCommand.ExecuteNonQuery();
                insertCommand.Dispose();
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: {0}", ex.Message);
            }
            return(false);
        }
Example #2
0
 /// <summary>
 /// Returns a FoodMenu from the DB with a particular id
 /// </summary>
 /// <param name="id"></param>
 /// <returns>FoodMenu or null if no such menu is found</returns>
 ///
 public static bool Add(Raw_Stock meat, Raw_Stock veg_1, Raw_Stock veg_2, Raw_Stock drink, decimal price)
 {
     try
     {
         if (meat != null && veg_1 != null && veg_2 != null && drink != null && price > 0.00m)
         {
             string insertQuery =
                 "INSERT INTO menus (menu_meat_id, menu_veg_1_id, menu_veg_2_id, " +
                 "menu_drink_id, menu_price) " +
                 "VALUES (@menu_meat_id, @menu_veg_1_id, @menu_veg_2_id, @menu_drink_id, " +
                 "@menu_price)";
             SqlCommand insertCommand = new SqlCommand(insertQuery, Database.GetConnection());
             insertCommand.Parameters.AddWithValue("@menu_meat_id", meat.ID);
             insertCommand.Parameters.AddWithValue("@menu_veg_1_id", veg_1.ID);
             insertCommand.Parameters.AddWithValue("@menu_veg_2_id", veg_2.ID);
             insertCommand.Parameters.AddWithValue("@menu_drink_id", drink.ID);
             insertCommand.Parameters.AddWithValue("@menu_price", price);
             insertCommand.ExecuteNonQuery();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("ERROR: {0}", ex.Message);
         //null is returned when information isn't found or if it cannot be processed
         return(false);
     }
 }
Example #3
0
 private bool ValidateFields(Raw_Stock stockItem)
 {
     //checks each feild in the class to see wether they are null / empty
     foreach (PropertyInfo pi in stockItem.GetType().GetProperties())
     {
         if (pi.PropertyType == typeof(string))
         {
             string value = (string)pi.GetValue(stockItem);
             if (string.IsNullOrEmpty(value))
             {
                 return(false);
             }
         }
     }
     //validation passed
     return(true);
 }