Exemple #1
0
        /// <summary>
        /// This function adds an entry to the stock price table. It records
        /// the stock ID (retrieved from symbol table) and the latest
        ///  sale price associated with that stock.
        /// </summary>
        /// <param name="stockID">database ID of the stock to be added</param>
        /// <param name="lastPrice">Decimal of the most recent sale price of that stock</param>
        /// <returns></returns>
        public bool addStockQuote(int stockID, decimal lastPrice)
        {
            bool quote_added = false;

            using (var db = new stock_advisorDataContext(Program.ConnectionString))
            {
                DateTime current = DateTime.Now;
                //create user_info object w/params
                var newEntry = new STOCK_PRICE()
                {
                    Stock_id = stockID,
                    Price    = lastPrice,
                    Date     = current
                };

                db.STOCK_PRICEs.InsertOnSubmit(newEntry);

                try
                {
                    db.SubmitChanges(); //execute insert
                    //verify that was successfully inserted
                    var added = db.STOCK_PRICEs.SingleOrDefault(a => a.Stock_id == stockID && a.Date == current);
                    if (added != null)
                    {
                        quote_added = true;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception caught during stock quote creation/insert:\n");
                    Console.WriteLine(e.Message);
                }
            }
            return(quote_added);
        }
Exemple #2
0
        /// <summary>
        /// This function gets the last row in the stock prices table (most recent entry)
        /// and returns the date & time associated with that entry.
        /// </summary>
        /// <returns>DateTime object containing date and time of last entry in stock price</returns>
        public DateTime getLastStockUpdateTime()
        {
            DateTime last_insert = new DateTime(2004, 11, 23);  //if no records are found, return arbitrarily distant date to force an update.

            using (var db = new stock_advisorDataContext(Program.ConnectionString))
            {
                STOCK_PRICE last_stock = db.STOCK_PRICEs.OrderByDescending(a => a.id).FirstOrDefault();

                if (last_stock != null)
                {
                    last_insert = last_stock.Date;
                }
            }
            return(last_insert);
        }
 partial void DeleteSTOCK_PRICE(STOCK_PRICE instance);
 partial void UpdateSTOCK_PRICE(STOCK_PRICE instance);
 partial void InsertSTOCK_PRICE(STOCK_PRICE instance);
 private void detach_STOCK_PRICEs(STOCK_PRICE entity)
 {
     this.SendPropertyChanging();
     entity.STOCK = null;
 }
 private void attach_STOCK_PRICEs(STOCK_PRICE entity)
 {
     this.SendPropertyChanging();
     entity.STOCK = this;
 }