| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393 |
- 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;
- }
- }
- /// <summary>
- /// 执行与释放或重置非托管资源相关的应用程序定义的任务。
- /// </summary>
- public void Dispose()
- {
- if (intradayInfo != null) intradayInfo.Dispose();
- intradayInfo = null;
- }
- }
- }
|