namespace Easychart.Finance.DataProvider { using Easychart.Finance; using System; using System.Data; using System.Globalization; using System.IO; using System.Web.UI.WebControls; public class DataManagerBase : IDataManager, IDisposable { private bool changed; private bool downloadRealTimeQuote; private DateTime endTime; private int futureBars; private ExchangeIntraday intradayInfo; private bool isFix; private DateTime startTime; private DateTime virtualEndTime; private bool virtualFetch; private DateTime virtualStartTime; protected BoundColumn CreateBoundColumn(string HeaderText, string DataField, string SortExpression, string DataFormatString) { BoundColumn column = new BoundColumn(); column.DataField = DataField; column.SortExpression = SortExpression; column.HeaderText = HeaderText; column.DataFormatString = DataFormatString; return column; } protected HyperLinkColumn CreateHyperLinkColumn(string Text, string DataNavigateUrlField, string DataNavigateUrlFormatString) { HyperLinkColumn column = new HyperLinkColumn(); column.Text = Text; column.DataNavigateUrlField = DataNavigateUrlField; column.DataNavigateUrlFormatString = DataNavigateUrlFormatString; return column; } public int DeleteSymbols(string Symbols) { return this.DeleteSymbols(Symbols.Split(new char[] { ',', ';' })); } public int DeleteSymbols(string[] Symbols) { return this.DeleteSymbols("", Symbols, false, true, true); } public virtual int DeleteSymbols(string Exchange, string[] Symbols, bool Remain, bool DeleteRealtime, bool DeleteHistorical) { return 0; } public virtual IDataProvider GetData(string Code, int Count) { return null; } public DataTable GetStockList() { return this.GetStockList(null, null, null); } public DataTable GetStockList(string Exchange, string ConditionId, string Key) { return this.GetStockList(Exchange, ConditionId, Key, "", 0, 0x7fffffff); } public virtual DataTable GetStockList(string Exchange, string ConditionId, string Key, string Sort, int StartRecords, int MaxRecords) { return null; } public DataTable GetSymbolList() { return this.GetSymbolList(null, null, null); } public DataTable GetSymbolList(string Exchange, string ConditionId, string Key) { return this.GetSymbolList(Exchange, ConditionId, Key, "", 0, 0x7fffffff); } public virtual DataTable GetSymbolList(string Exchange, string ConditionId, string Key, string Sort, int StartRecords, int MaxRecords) { return null; } public string[] GetSymbolStrings() { return this.GetSymbolStrings(null, null, null); } public string[] GetSymbolStrings(string Exchange, string ConditionId, string Key) { DataTable table = this.GetSymbolList(Exchange, ConditionId, Key); string[] strArray = new string[table.Rows.Count]; for (int i = 0; i < strArray.Length; i++) { strArray[i] = table.Rows[i][0].ToString(); } return strArray; } public DataTable RecordRange(DataTable dt, int StartRecords, int MaxRecords) { for (int i = 0; i < StartRecords; i++) { dt.Rows.RemoveAt(0); } while (dt.Rows.Count > MaxRecords) { dt.Rows.RemoveAt(dt.Rows.Count - 1); } return dt; } public void SaveData(string Symbol, IDataProvider idp, bool Intraday) { this.SaveData(Symbol, idp, null, DateTime.MinValue, DateTime.MaxValue, Intraday); } public virtual void SaveData(string Symbol, IDataProvider idp, Stream OutStream, DateTime Start, DateTime End, bool Intraday) { } public virtual void SaveSymbolList(string[] ss, out int succ, out int failed) { succ = 0; failed = ss.Length; } public virtual void SetStrings(CommonDataProvider cdp, string Code) { cdp.SetStringData("Code", Code); } public virtual int SymbolCount(string Exchange, string ConditionId, string Key) { return -1; } public static DateTime ToDate(object o) { if (o == DBNull.Value) { return DateTime.Today; } return (DateTime)o; } public static DateTime ToDateDef(string Format, string s, DateTime Def) { try { return DateTime.ParseExact(s, Format, DateTimeFormatInfo.InvariantInfo); } catch { return Def; } } public static double ToDecimalDouble(object o) { if (o == DBNull.Value) { return double.NaN; } return (double)((decimal)o); } public static double ToDouble(object o) { if (o == DBNull.Value) { return double.NaN; } return (double)o; } public static int ToInt(object o) { if (o == DBNull.Value) { return 0; } return (int)o; } public static long ToInt64(object o) { if (o == DBNull.Value) { return 0L; } return (long)o; } public static float ToSingle(object o) { if (o == DBNull.Value) { return float.NaN; } return (float)o; } public virtual CommonDataProvider UpdateEod(string Symbol, CommonDataProvider cdpDelta) { CommonDataProvider idp = (CommonDataProvider)this[Symbol]; idp.Merge(cdpDelta); this.SaveData(Symbol, idp, false); return idp; } public bool Changed { get { return this.changed; } set { this.changed = value; } } public bool DownloadRealTimeQuote { get { return this.downloadRealTimeQuote; } set { this.downloadRealTimeQuote = value; this.changed = true; } } public DateTime EndTime { get { return this.endTime; } set { this.endTime = value; this.changed = true; } } public virtual DataTable Exchanges { get { return null; } } public int FutureBars { get { return this.futureBars; } set { this.futureBars = value; this.changed = true; } } public ExchangeIntraday IntradayInfo { get { return this.intradayInfo; } set { this.intradayInfo = value; this.changed = true; } } public bool IsFix { get { return this.isFix; } set { this.isFix = value; this.changed = true; } } public virtual IDataProvider this[string Code] { get { return this[Code, DataPacket.MaxValue]; } } public virtual IDataProvider this[string Code, int Count] { get { IDataProvider data = this.GetData(Code, Count); if (data is CommonDataProvider) { (data as CommonDataProvider).FutureBars = this.futureBars; } return data; } } public DateTime StartTime { get { return this.startTime; } set { this.startTime = value; this.changed = true; } } public virtual DataGridColumn[] StockListColumns { get { return null; } } public DateTime VirtualEndTime { get { return this.virtualEndTime; } set { this.virtualEndTime = value; } } public bool VirtualFetch { get { return this.virtualFetch; } set { this.virtualFetch = value; } } public DateTime VirtualStartTime { get { return this.virtualStartTime; } set { this.virtualStartTime = value; } } /// /// 执行与释放或重置非托管资源相关的应用程序定义的任务。 /// public void Dispose() { if (intradayInfo != null) intradayInfo.Dispose(); intradayInfo = null; } } }