Пример #1
0
        public override Stock GetStock(int stockId)
        {
            Stock stock = null;

              using (OdbcCommand command = new OdbcCommand())
              {
            command.Connection = connection;
            command.CommandText = string.Format("SELECT ticker, price FROM get_stock({0});", stockId);

            using (OdbcDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult))
            {
              if (reader.HasRows)
              {
            stock = new Stock();
            stock.Id = stockId;
            stock.Ticker = reader.GetString(0);
            stock.LastPrice = reader.GetDecimal(1);
              }

              reader.Close();
            }
              }

              return stock;
        }
        //~PostgresqlDataProvider()
        //{
        //  if (connection.State != ConnectionState.Closed)
        //    connection.Close();
        //}
        public override Stock GetStock(int stockId)
        {
            string query = "SELECT id, ticker, price FROM stocks WHERE id = " + stockId;
              OdbcCommand command = new OdbcCommand(query, connection);
              OdbcDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult);

              if (!reader.HasRows)
              {
            reader.Close();
            return null;
              }

              Stock stock = new Stock();
              stock.Id = reader.GetInt32(0);
              stock.Ticker = reader.GetString(1);
              stock.LastPrice = reader.GetDecimal(2);

              reader.Close();
              return stock;
        }
        public override Stock[] SelectStocks()
        {
            IList<Stock> stocks = new List<Stock>();

              string query = "SELECT id, ticker, price FROM stocks";
              OdbcCommand command = new OdbcCommand(query, connection);
              OdbcDataReader reader = command.ExecuteReader();

              while (reader.Read())
              {
            Stock stock = new Stock();
            stock.Id = reader.GetInt32(0);
            stock.Ticker = reader.GetString(1);
            stock.LastPrice = reader.GetDecimal(2);
            stocks.Add(stock);
              }

              reader.Close();
              return stocks.ToArray();
        }
Пример #4
0
        public override Stock[] SelectStocks()
        {
            XDocument document = XDocument.Load(FileName);
              XElement stocksElement = document.Root.Element(StocksElementName);
              IList<Stock> stockList = new List<Stock>();

              foreach (XElement stockElement in stocksElement.Elements())
              {
            Stock stock = new Stock();
            stock.Id = int.Parse(stockElement.Element("id").Value);
            //stock.TickSize = decimal.Parse(stockElement.Element("tickSize").Value, new CultureInfo("en-US"));
            stock.LastPrice = decimal.Parse(stockElement.Element("price").Value, new CultureInfo("en-US"));
            stockList.Add(stock);
              }

              return stockList.ToArray();
        }
Пример #5
0
        public override Stock[] SelectStocks()
        {
            IList<Stock> stocks = new List<Stock>();

              using (OdbcCommand command = new OdbcCommand())
              {
            command.Connection = connection;
            command.CommandText = "SELECT id, ticker, price FROM stocks;"; // nebo: FROM get_stocks();

            using (OdbcDataReader reader = command.ExecuteReader())
            {
              while (reader.Read())
              {
            Stock stock = new Stock();
            stock.Id = reader.GetInt32(0);
            stock.Ticker = reader.GetString(1);
            stock.LastPrice = reader.GetDecimal(2);
            stocks.Add(stock);
              }

              reader.Close();
            }
              }

              return stocks.ToArray();
        }