using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Windows.Forms;

namespace AdvertsingProfitControl
{
    class WriteToDatabase
    {

        public void InsertIntoActualSales(string[] parameters, string conn)
        {
            using (OleDbConnection connection = new OleDbConnection(conn))
            {
                string sqlInsert = "INSERT INTO ActualSales(AcSold, AcSalePrice, AcTotalSales, AcCost, AcProfitReturn, AcTotalProfitReturn, FK_AdItemID, FK_DateID) VALUES (@sold, @salesPrice, @totalSales, @cost, @profitReturn, @toalProfitReturn, @adItemID, @dateID)";
                OleDbCommand command = new OleDbCommand(sqlInsert, connection);
                command.Parameters.AddWithValue("@sold", parameters[0]);
                command.Parameters.AddWithValue("@salesPrice", parameters[1]);
                command.Parameters.AddWithValue("@totalSales", parameters[2]);
                command.Parameters.AddWithValue("@cost", parameters[3]);
                command.Parameters.AddWithValue("@profitReturn", parameters[4]);
                command.Parameters.AddWithValue("@totalProfitReturn", parameters[5]);
                command.Parameters.AddWithValue("@adItemID", parameters[6]);
                command.Parameters.AddWithValue("@dateID", parameters[7]);
                try
                {
                    connection.Open();
                    command.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Error Writing to Database");
                }
            }
        }

        public void InsertIntoAdItems(string[] parameters, string conn)
        {

        }

        public void InsertIntoComment(string[] parameters, string conn)
        {

        }

        public void InsertIntoInventory(string[] parameters, string conn)
        {
            using (OleDbConnection connection = new OleDbConnection(conn))
            {
                string sql = "INSERT INTO Inventory(InvBeginingInventory, InvRecieved, InvTotal, InvEnding, Fk_AditemID, Fk_DateID) VALUES (@begining, @recieved, @total, @ending, @adItem, @dateID)";
                OleDbCommand command = new OleDbCommand(sql, connection);
                command.Parameters.AddWithValue("@begining", parameters[0]);
                command.Parameters.AddWithValue("@recieved", parameters[1]);
                command.Parameters.AddWithValue("@total", parameters[2]);
                command.Parameters.AddWithValue("@ending", parameters[3]);
                command.Parameters.AddWithValue("@adItem", parameters[4]);
                command.Parameters.AddWithValue("@dateID", parameters[5]);
                try
                {
                    connection.Open();
                    command.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Error Writing to Database");
                }
            }           
        }

        public void InsertIntoInvoice(string[] parameters, string conn)
        {

        }

        public void InsertIntoProjectedSales(string[] parameters, string conn)
        {

        }

        public void InsertIntoSupplier(string[] parameters, string conn)
        {

        }

        public void InsertIntoWeekEndingDate(string[] parameters, string conn)
        {

        }

        public void InsertIntoWeeklySales(string[] parameters, string conn)
        {

        }
    }
}
