DataManagerBase.cs 9.7 KB

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