Esempio n. 1
0
        //Create a method that creates one Stock (checks unique name**) given one StockDay item
        //Returns the unique ID of the stock in the DB
        private static int InputDay(StockDay dayIn)
        {
            SQLMethods connection = new SQLMethods();
            int        SymbolId   = -1;

            try
            {
                SymbolId = connection.GetSymbolId(dayIn.Symbol);
                if (SymbolId == 0)
                {
                    connection.CreateStock(dayIn.Symbol);
                    SymbolId = connection.GetSymbolId(dayIn.Symbol);
                }

                connection.CreateDay(SymbolId, dayIn);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }



            return(SymbolId);
        }
Esempio n. 2
0
        //Creates a new stock day in the DB
        public void CreateDay(int stockId, StockDay dayIn)
        {
            conn.Open();
            try
            {
                using (SqlCommand command = new SqlCommand(
                           "INSERT INTO Day (stockid, dayopen, dayclose, dayhigh, daylow, date, volume) VALUES(@StockId, @DayOpen, @DayClose, " +
                           "@DayHigh, @DayLow, @Date, @Volume)", conn))
                {
                    command.Parameters.Add(new SqlParameter("StockId", stockId));
                    command.Parameters.Add(new SqlParameter("DayOpen", dayIn.Open));
                    command.Parameters.Add(new SqlParameter("DayClose", dayIn.Close));
                    command.Parameters.Add(new SqlParameter("DayHigh", dayIn.High));
                    command.Parameters.Add(new SqlParameter("DayLow", dayIn.Low));
                    command.Parameters.Add(new SqlParameter("Date", dayIn.Date));
                    command.Parameters.Add(new SqlParameter("Volume", dayIn.Volume));
                    command.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }



            conn.Close();
        }