DataManagerBase.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. namespace Easychart.Finance.DataProvider
  2. {
  3. using Easychart.Finance;
  4. using System;
  5. using System.Data;
  6. using System.Globalization;
  7. using System.IO;
  8. using System.Web.UI.WebControls;
  9. public class DataManagerBase : IDataManager, IDisposable
  10. {
  11. private bool changed;
  12. private bool downloadRealTimeQuote;
  13. private DateTime endTime;
  14. private int futureBars;
  15. private ExchangeIntraday intradayInfo;
  16. private bool isFix;
  17. private DateTime startTime;
  18. private DateTime virtualEndTime;
  19. private bool virtualFetch;
  20. private DateTime virtualStartTime;
  21. protected BoundColumn CreateBoundColumn(string HeaderText, string DataField, string SortExpression, string DataFormatString)
  22. {
  23. BoundColumn column = new BoundColumn();
  24. column.DataField = DataField;
  25. column.SortExpression = SortExpression;
  26. column.HeaderText = HeaderText;
  27. column.DataFormatString = DataFormatString;
  28. return column;
  29. }
  30. protected HyperLinkColumn CreateHyperLinkColumn(string Text, string DataNavigateUrlField, string DataNavigateUrlFormatString)
  31. {
  32. HyperLinkColumn column = new HyperLinkColumn();
  33. column.Text = Text;
  34. column.DataNavigateUrlField = DataNavigateUrlField;
  35. column.DataNavigateUrlFormatString = DataNavigateUrlFormatString;
  36. return column;
  37. }
  38. public int DeleteSymbols(string Symbols)
  39. {
  40. return this.DeleteSymbols(Symbols.Split(new char[] { ',', ';' }));
  41. }
  42. public int DeleteSymbols(string[] Symbols)
  43. {
  44. return this.DeleteSymbols("", Symbols, false, true, true);
  45. }
  46. public virtual int DeleteSymbols(string Exchange, string[] Symbols, bool Remain, bool DeleteRealtime, bool DeleteHistorical)
  47. {
  48. return 0;
  49. }
  50. public virtual IDataProvider GetData(string Code, int Count)
  51. {
  52. return null;
  53. }
  54. public DataTable GetStockList()
  55. {
  56. return this.GetStockList(null, null, null);
  57. }
  58. public DataTable GetStockList(string Exchange, string ConditionId, string Key)
  59. {
  60. return this.GetStockList(Exchange, ConditionId, Key, "", 0, 0x7fffffff);
  61. }
  62. public virtual DataTable GetStockList(string Exchange, string ConditionId, string Key, string Sort, int StartRecords, int MaxRecords)
  63. {
  64. return null;
  65. }
  66. public DataTable GetSymbolList()
  67. {
  68. return this.GetSymbolList(null, null, null);
  69. }
  70. public DataTable GetSymbolList(string Exchange, string ConditionId, string Key)
  71. {
  72. return this.GetSymbolList(Exchange, ConditionId, Key, "", 0, 0x7fffffff);
  73. }
  74. public virtual DataTable GetSymbolList(string Exchange, string ConditionId, string Key, string Sort, int StartRecords, int MaxRecords)
  75. {
  76. return null;
  77. }
  78. public string[] GetSymbolStrings()
  79. {
  80. return this.GetSymbolStrings(null, null, null);
  81. }
  82. public string[] GetSymbolStrings(string Exchange, string ConditionId, string Key)
  83. {
  84. DataTable table = this.GetSymbolList(Exchange, ConditionId, Key);
  85. string[] strArray = new string[table.Rows.Count];
  86. for (int i = 0; i < strArray.Length; i++)
  87. {
  88. strArray[i] = table.Rows[i][0].ToString();
  89. }
  90. return strArray;
  91. }
  92. public DataTable RecordRange(DataTable dt, int StartRecords, int MaxRecords)
  93. {
  94. for (int i = 0; i < StartRecords; i++)
  95. {
  96. dt.Rows.RemoveAt(0);
  97. }
  98. while (dt.Rows.Count > MaxRecords)
  99. {
  100. dt.Rows.RemoveAt(dt.Rows.Count - 1);
  101. }
  102. return dt;
  103. }
  104. public void SaveData(string Symbol, IDataProvider idp, bool Intraday)
  105. {
  106. this.SaveData(Symbol, idp, null, DateTime.MinValue, DateTime.MaxValue, Intraday);
  107. }
  108. public virtual void SaveData(string Symbol, IDataProvider idp, Stream OutStream, DateTime Start, DateTime End, bool Intraday)
  109. {
  110. }
  111. public virtual void SaveSymbolList(string[] ss, out int succ, out int failed)
  112. {
  113. succ = 0;
  114. failed = ss.Length;
  115. }
  116. public virtual void SetStrings(CommonDataProvider cdp, string Code)
  117. {
  118. cdp.SetStringData("Code", Code);
  119. }
  120. public virtual int SymbolCount(string Exchange, string ConditionId, string Key)
  121. {
  122. return -1;
  123. }
  124. public static DateTime ToDate(object o)
  125. {
  126. if (o == DBNull.Value)
  127. {
  128. return DateTime.Today;
  129. }
  130. return (DateTime)o;
  131. }
  132. public static DateTime ToDateDef(string Format, string s, DateTime Def)
  133. {
  134. try
  135. {
  136. return DateTime.ParseExact(s, Format, DateTimeFormatInfo.InvariantInfo);
  137. }
  138. catch
  139. {
  140. return Def;
  141. }
  142. }
  143. public static double ToDecimalDouble(object o)
  144. {
  145. if (o == DBNull.Value)
  146. {
  147. return double.NaN;
  148. }
  149. return (double)((decimal)o);
  150. }
  151. public static double ToDouble(object o)
  152. {
  153. if (o == DBNull.Value)
  154. {
  155. return double.NaN;
  156. }
  157. return (double)o;
  158. }
  159. public static int ToInt(object o)
  160. {
  161. if (o == DBNull.Value)
  162. {
  163. return 0;
  164. }
  165. return (int)o;
  166. }
  167. public static long ToInt64(object o)
  168. {
  169. if (o == DBNull.Value)
  170. {
  171. return 0L;
  172. }
  173. return (long)o;
  174. }
  175. public static float ToSingle(object o)
  176. {
  177. if (o == DBNull.Value)
  178. {
  179. return float.NaN;
  180. }
  181. return (float)o;
  182. }
  183. public virtual CommonDataProvider UpdateEod(string Symbol, CommonDataProvider cdpDelta)
  184. {
  185. CommonDataProvider idp = (CommonDataProvider)this[Symbol];
  186. idp.Merge(cdpDelta);
  187. this.SaveData(Symbol, idp, false);
  188. return idp;
  189. }
  190. public bool Changed
  191. {
  192. get
  193. {
  194. return this.changed;
  195. }
  196. set
  197. {
  198. this.changed = value;
  199. }
  200. }
  201. public bool DownloadRealTimeQuote
  202. {
  203. get
  204. {
  205. return this.downloadRealTimeQuote;
  206. }
  207. set
  208. {
  209. this.downloadRealTimeQuote = value;
  210. this.changed = true;
  211. }
  212. }
  213. public DateTime EndTime
  214. {
  215. get
  216. {
  217. return this.endTime;
  218. }
  219. set
  220. {
  221. this.endTime = value;
  222. this.changed = true;
  223. }
  224. }
  225. public virtual DataTable Exchanges
  226. {
  227. get
  228. {
  229. return null;
  230. }
  231. }
  232. public int FutureBars
  233. {
  234. get
  235. {
  236. return this.futureBars;
  237. }
  238. set
  239. {
  240. this.futureBars = value;
  241. this.changed = true;
  242. }
  243. }
  244. public ExchangeIntraday IntradayInfo
  245. {
  246. get
  247. {
  248. return this.intradayInfo;
  249. }
  250. set
  251. {
  252. this.intradayInfo = value;
  253. this.changed = true;
  254. }
  255. }
  256. public bool IsFix
  257. {
  258. get
  259. {
  260. return this.isFix;
  261. }
  262. set
  263. {
  264. this.isFix = value;
  265. this.changed = true;
  266. }
  267. }
  268. public virtual IDataProvider this[string Code]
  269. {
  270. get
  271. {
  272. return this[Code, DataPacket.MaxValue];
  273. }
  274. }
  275. public virtual IDataProvider this[string Code, int Count]
  276. {
  277. get
  278. {
  279. IDataProvider data = this.GetData(Code, Count);
  280. if (data is CommonDataProvider)
  281. {
  282. (data as CommonDataProvider).FutureBars = this.futureBars;
  283. }
  284. return data;
  285. }
  286. }
  287. public DateTime StartTime
  288. {
  289. get
  290. {
  291. return this.startTime;
  292. }
  293. set
  294. {
  295. this.startTime = value;
  296. this.changed = true;
  297. }
  298. }
  299. public virtual DataGridColumn[] StockListColumns
  300. {
  301. get
  302. {
  303. return null;
  304. }
  305. }
  306. public DateTime VirtualEndTime
  307. {
  308. get
  309. {
  310. return this.virtualEndTime;
  311. }
  312. set
  313. {
  314. this.virtualEndTime = value;
  315. }
  316. }
  317. public bool VirtualFetch
  318. {
  319. get
  320. {
  321. return this.virtualFetch;
  322. }
  323. set
  324. {
  325. this.virtualFetch = value;
  326. }
  327. }
  328. public DateTime VirtualStartTime
  329. {
  330. get
  331. {
  332. return this.virtualStartTime;
  333. }
  334. set
  335. {
  336. this.virtualStartTime = value;
  337. }
  338. }
  339. /// <summary>
  340. /// 执行与释放或重置非托管资源相关的应用程序定义的任务。
  341. /// </summary>
  342. public void Dispose()
  343. {
  344. if (intradayInfo != null) intradayInfo.Dispose();
  345. intradayInfo = null;
  346. }
  347. }
  348. }