[Quantproject-developers] QuantProject/b2_DataAccess/Tables FinancialValues.cs, NONE, 1.1
Brought to you by:
glauco_1
|
From: Marco M. <mi...@us...> - 2010-11-20 19:01:08
|
Update of /cvsroot/quantproject/QuantProject/b2_DataAccess/Tables In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv28321 Added Files: FinancialValues.cs Log Message: Added FinancialValues class, for accessing the FinancialValues table in DB --- NEW FILE: FinancialValues.cs --- /* QuantProject - Quantitative Finance Library FinancialValues.cs Copyright (C) 2010 Marco Milletti This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Data; using QuantProject.DataAccess; namespace QuantProject.DataAccess.Tables { /// <summary> /// Class to access the financialValues table /// </summary> public class FinancialValues { private DataTable financialValues; /// <summary> /// Gets the ticker whose financials are contained into the FinancialValues object /// </summary> /// <returns></returns> public string Ticker { get{ return ((string)this.financialValues.Rows[ 0 ][ "fvTiTicker" ]); } } public FinancialValues( string ticker, int periodLengthInMonths) { this.financialValues = FinancialValues.GetTickerFinancialValues( ticker, periodLengthInMonths ); } /// <summary> /// It provides addition of the given financial values into table "financial values" /// </summary> public static void Add( string ticker, int financialDataCode, int sourceCode, DateTime endingPeriodDate, int periodLengthInMonths, double financialValue, DateTime downloadDate) { try { SqlExecutor.ExecuteNonQuery("INSERT INTO financialValues(fvTiTicker, fvFdId, fvFsId, " + "fvEndingPeriodDate, fvPeriodLengthInMonths, " + "fvValue, fvDownloadDate) " + "VALUES('" + ticker + "', " + financialDataCode + ", " + sourceCode + ", " + SQLBuilder.GetDateConstant(endingPeriodDate) + ", " + periodLengthInMonths + ", " + financialValue + ", " + SQLBuilder.GetDateConstant(downloadDate) + ")"); } catch(Exception ex) { string notUsed = ex.ToString(); } } /// <summary> /// returns the financial values DataTable for the given ticker /// </summary> public static DataTable GetTickerFinancialValues( string instrumentKey, int periodLengthInMonths ) { string sql = "select * from financialValues where fvTiTicker='" + instrumentKey + "' " + "and fvPeriodLengthInMonths= " + periodLengthInMonths + " order by fvEndingPeriodDate"; return SqlExecutor.GetDataTable( sql ); } #region SetDataTable for tickerList // private static string setDataTable_getTickerListWhereClause_getSingleTickerWhereClause( // string ticker ) // { // return "(" + FinancialValues.TickerFieldName + "='" + ticker + "')"; // } // private static string setDataTable_getTickerListWhereClause( ICollection tickerCollection ) // { // string returnValue = ""; // foreach (string ticker in tickerCollection) // if ( returnValue == "" ) // // this is the first ticker to handle // returnValue += setDataTable_getTickerListWhereClause_getSingleTickerWhereClause( ticker ); // else // // this is not the first ticker to handle // returnValue += " or " + // setDataTable_getTickerListWhereClause_getSingleTickerWhereClause( ticker ); // return "( " + returnValue + " )"; // } // /// <summary> // /// Builds a Quotes data table containing a row for each ticker in the // /// collection, with the quotes for the given DateTime // /// </summary> // /// <param name="tickerCollection">Tickers whose quotes are to be fetched</param> // /// <param name="dateTime">Date for the quotes to be fetched</param> // /// <param name="dataTable">Output parameter</param> // public static void SetDataTable( ICollection tickerCollection , DateTime dateTime , DataTable dataTable) // { // string sql; // sql = "select * from quotes " + // "where " + setDataTable_getTickerListWhereClause( tickerCollection ) + // " and " + FinancialValues.Date + "=" + SQLBuilder.GetDateConstant( dateTime ) + " " + // "order by " + FinancialValues.TickerFieldName; // // SqlExecutor.SetDataTable( sql , dataTable ); // } #endregion } } |