require "csv"
require "sqlite3"

@@updateMenu = Shoes.app do
  begin
      # button("Update Menu Items") do
    db = SQLite3::Database.open("Database/CSDB.db")
    db.execute("DELETE FROM foodCosts")
#    file = CSV.open("CSV/foodCosts.csv","r")
    file = CSV.open("CSV/CSV-Menu.csv","r")
    # file = CSV.open("../documents/Pizzeria/Pizzeria Numbers/StartupCosts/CSV-Menu.csv","r")
    header = file.shift
    file.each do |e|
      # (item TEXT,salesPrice FLOAT,foodCost FLOAT,category TEXT)
      # for foodCosts.csv
#      db.execute("INSERT INTO foodCosts VALUES ('#{e[0]}', #{e[1]}, #{e[2]}, '#{e[3]}')")
      # for CSV-Menu.csv
      db.execute("INSERT INTO foodCosts VALUES ('#{e[0]}', #{e[1]}, #{e[2]}, '#{e[4]}')")
    end
    db.close
    # Shoes.p db.closed?
  # end
  title "Thank You"
  timer(1) do
    @@updateMenu.close
  end
  

  rescue Exception => e
    puts e
  end
end  
  
