public void ReturnItem(ItemForRent item, int quantity)
 {
     if (item is ItemForRent)
     {
         if (borrowings.ContainsKey(item) && borrowings[item] >= quantity)
         {
             borrowings[item] -= quantity;
             if (borrowings[item] == 0)
             {
                 borrowings.Remove(item);
             }
             //item.AddToStock(quantity);
         }
         else if (!borrowings.ContainsKey(item))
         {
             throw new LatitudeException("Item not in borrowings");
         }
         else
         {
             throw new LatitudeException("Quantity input exceeds actual borrowing quantity");
         }
     }
     else
     {
         throw new LatitudeException("Selected item is not for rent");
     }
 }
 internal void BorrowItem(ItemForRent item, int quantity)
 {
     if (borrowings.ContainsKey(item))
     {
         borrowings[item] += quantity;
     }
     else
     {
         borrowings.Add(item, quantity);
     }
 }
        public void InsertNewFine(Visitor v, ItemForRent item, int quantity)
        {
            string sql = $"insert into returned_item (ticketNr, sku, quantity, returnDate, paidFine) values ({v.TicketNr}, {item.Sku}, {quantity}, null, {item.CostPerUnit * quantity} )";

            try
            {
                myDataHelper.OpenConnection();
                myDataHelper.ExecuteQueries(sql);
            }
            catch
            {
                return;
            }
            finally
            {
                myDataHelper.CloseConnection();
            }
        }
        public void InsertNewReturn(Visitor v, ItemForRent item, int quantity)
        {
            string sql = $"start transaction; insert into returned_item (ticketNr, sku, quantity, returnDate) values ({v.TicketNr}, {item.Sku}, {quantity}, '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}'); ";

            sql += $"update item set quantity_in_stock = {item.QuantityInStock} where sku = {item.Sku}; commit;";
            try
            {
                myDataHelper.OpenConnection();
                myDataHelper.ExecuteQueries(sql);
            }
            catch
            {
                return;
            }
            finally
            {
                myDataHelper.CloseConnection();
            }
        }
 public double PayFine(ItemForRent item, int quantity)
 {
     if (item is ItemForRent)
     {
         if (borrowings.ContainsKey(item) && borrowings[item] >= quantity)
         {
             double amount = item.CostPerUnit * quantity;
             if (amount <= balance)
             {
                 balance          -= amount;
                 borrowings[item] -= quantity;
                 if (borrowings[item] == 0)
                 {
                     borrowings.Remove(item);
                 }
                 return(amount);
             }
             else
             {
                 throw new LatitudeException(string.Format("Balance is not enough. Fine (€{0:0.00}) has not been paid", amount));
             }
         }
         else if (!borrowings.ContainsKey(item))
         {
             throw new LatitudeException("Item not in borrowings");
         }
         else
         {
             throw new LatitudeException("Quantity input exceeds actual borrowing quantity");
         }
     }
     else
     {
         throw new LatitudeException("Selected item is not for rent");
     }
 }
        private List <EventItem> GetEventItems()
        {
            string           sql  = "SELECT * FROM item left join item_for_rent on item.sku = item_for_rent.sku left join item_for_sale on item.sku = item_for_sale.sku";
            List <EventItem> temp = new List <EventItem>();

            try
            {
                myDataHelper.OpenConnection();
                MySqlDataReader reader = myDataHelper.DataReader(sql);
                EventItem       item;
                while (reader.Read())
                {
                    if (reader["type"].ToString() == "for rent")
                    {
                        item = new ItemForRent(reader["name"].ToString(), Convert.ToInt32(reader["sku"]), reader["imgPath"].ToString(),
                                               Convert.ToDouble(reader["costPerUnit"]), Convert.ToInt32(reader["quantity_in_stock"]), Convert.ToInt32(reader["quantity_min"]),
                                               Convert.ToDouble(reader["rentingFee"]));
                    }
                    else
                    {
                        SaleType st;
                        if (reader["forSaleType"].ToString() == "drink")
                        {
                            st = SaleType.Drink;
                        }
                        else if (reader["forSaleType"].ToString() == "food")
                        {
                            st = SaleType.Food;
                        }
                        else
                        {
                            st = SaleType.Souvenir;
                        }

                        bool isSuitable;
                        if (Convert.ToInt32(reader["isSuitableForVM"]) == 1)
                        {
                            isSuitable = true;
                        }
                        else
                        {
                            isSuitable = false;
                        }

                        item = new ItemForSale(reader["name"].ToString(), Convert.ToInt32(reader["sku"]), reader["imgPath"].ToString(),
                                               Convert.ToDouble(reader["costPerUnit"]), Convert.ToInt32(reader["quantity_in_stock"]), Convert.ToInt32(reader["quantity_min"]),
                                               Convert.ToDouble(reader["sellingPrice"]), st, isSuitable);
                    }
                    temp.Add(item);
                }
                return(temp);
            }
            catch
            {
                return(null);
            }
            finally
            {
                myDataHelper.CloseConnection();
            }
        }