TrendMissDataManage.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.Common;
  5. using System.Data.SqlClient;
  6. using System.Text;
  7. using CB.Common;
  8. using CB.Data;
  9. using CB.Entity;
  10. using CB.Interface.Infrastructure;
  11. namespace CB.Data.SqlServer
  12. {
  13. public class TrendMissDataManage : Repository<TrendMissDataInfo>, ITrendMissDataService
  14. {
  15. public TrendMissDataManage(string interfaceId)
  16. : base(interfaceId)
  17. {
  18. }
  19. public override bool Save(TrendMissDataInfo entity)
  20. {
  21. throw new NotImplementedException();
  22. }
  23. public override bool Update(TrendMissDataInfo entity)
  24. {
  25. throw new NotImplementedException();
  26. }
  27. public override bool Delete(int id)
  28. {
  29. throw new NotImplementedException();
  30. }
  31. public override TrendMissDataInfo Get<TKey>(TKey key)
  32. {
  33. throw new NotImplementedException();
  34. }
  35. public override IList<TrendMissDataInfo> ToList()
  36. {
  37. IList<TrendMissDataInfo> list = new List<TrendMissDataInfo>();
  38. StringBuilder strSql = new StringBuilder();
  39. strSql.Append("select Id, ChartId, Term, ItemValue, ItemSelect, OrderBy, RecordCount, Times, TimesTheory, Cycle, MaxMiss, AvgMiss, LastMiss, LocalMiss, LastMaxMiss, ContinuousTimes, ContinuousLocalTimes, ContinuousMaxTimes, ContinuousLocalMiss, ContinuousMaxMiss, ContinuousLocalProbability, ContinuousProbability, Probability, AppearingProbability, InvestmentValue, CoveringProbability ");
  40. strSql.Append(" from DT_TrendMissData ORDER BY [Term] ASC");
  41. using (DataTable dt = DbHelper.ExecuteDatatable(InterfaceId, strSql.ToString()))
  42. {
  43. if (null != dt && 0 < dt.Rows.Count)
  44. {
  45. foreach (DataRow dr in dt.Rows)
  46. {
  47. list.Add(LoadEntity(dr));
  48. }
  49. }
  50. dt.Dispose();
  51. }
  52. return list;
  53. }
  54. public override IList<TrendMissDataInfo> ToList(TrendMissDataInfo entity)
  55. {
  56. throw new NotImplementedException();
  57. }
  58. public override IList<TrendMissDataInfo> ToPaging(TrendMissDataInfo entity, int pageSize, int pageIndex, out int recordCount)
  59. {
  60. throw new NotImplementedException();
  61. }
  62. public bool BatchSave(IList<TrendMissDataInfo> list)
  63. {
  64. if (null == list || 0 >= list.Count)
  65. return false;
  66. using (DbConnection conn = DbHelper.Factory(InterfaceId).CreateConnection())
  67. {
  68. conn.ConnectionString = DbHelper.ConnectionString(InterfaceId);
  69. conn.Open();
  70. DbDataAdapter adapter = DbHelper.Factory(InterfaceId).CreateDataAdapter();
  71. adapter.SelectCommand = DbHelper.Factory(InterfaceId).CreateCommand();
  72. adapter.SelectCommand.CommandText = @"SELECT TOP 0 [ChartId],[Term],[ItemValue],[ItemSelect],[OrderBy],[RecordCount],[Times],[TimesTheory],
  73. [Cycle],[MaxMiss],[AvgMiss],[LastMiss],[LocalMiss],[LastMaxMiss],[ContinuousTimes],[ContinuousLocalTimes],[ContinuousMaxTimes],
  74. [ContinuousLocalMiss],[ContinuousMaxMiss],[ContinuousLocalProbability],[ContinuousProbability],[Probability],[AppearingProbability],
  75. [InvestmentValue],[CoveringProbability] FROM [DT_TrendMissData]";
  76. adapter.SelectCommand.CommandType = CommandType.Text;
  77. adapter.SelectCommand.Connection = conn;
  78. adapter.InsertCommand = DbHelper.Factory(InterfaceId).CreateCommand();
  79. adapter.InsertCommand.CommandText = "usp_TrendMissData_save";
  80. adapter.InsertCommand.CommandType = CommandType.StoredProcedure;
  81. adapter.InsertCommand.Connection = conn;
  82. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ChartId", (DbType)SqlDbType.Int, 4, "ChartId"));
  83. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@Term", (DbType)SqlDbType.Int, 4, "Term"));
  84. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ItemValue", (DbType)SqlDbType.NChar, 40, "ItemValue"));
  85. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ItemSelect", (DbType)SqlDbType.Bit, 1, "ItemSelect"));
  86. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@OrderBy", (DbType)SqlDbType.Int, 4, "OrderBy"));
  87. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@RecordCount", (DbType)SqlDbType.Int, 4, "RecordCount"));
  88. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@Times", (DbType)SqlDbType.Int, 4, "Times"));
  89. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@TimesTheory", (DbType)SqlDbType.Int, 4, "TimesTheory"));
  90. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@Cycle", (DbType)SqlDbType.Float, 8, "Cycle"));
  91. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@MaxMiss", (DbType)SqlDbType.Int, 4, "MaxMiss"));
  92. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@AvgMiss", (DbType)SqlDbType.Float, 8, "AvgMiss"));
  93. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@LastMiss", (DbType)SqlDbType.Int, 4, "LastMiss"));
  94. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@LocalMiss", (DbType)SqlDbType.Int, 4, "LocalMiss"));
  95. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@LastMaxMiss", (DbType)SqlDbType.Int, 4, "LastMaxMiss"));
  96. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ContinuousTimes", (DbType)SqlDbType.Int, 4, "ContinuousTimes"));
  97. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ContinuousLocalTimes", (DbType)SqlDbType.Int, 4, "ContinuousLocalTimes"));
  98. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ContinuousMaxTimes", (DbType)SqlDbType.Int, 4, "ContinuousMaxTimes"));
  99. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ContinuousLocalMiss", (DbType)SqlDbType.Int, 4, "ContinuousLocalMiss"));
  100. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ContinuousMaxMiss", (DbType)SqlDbType.Int, 4, "ContinuousMaxMiss"));
  101. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ContinuousLocalProbability", (DbType)SqlDbType.Float, 8, "ContinuousLocalProbability"));
  102. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ContinuousProbability", (DbType)SqlDbType.Float, 8, "ContinuousProbability"));
  103. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@Probability", (DbType)SqlDbType.Float, 8, "Probability"));
  104. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@AppearingProbability", (DbType)SqlDbType.Float, 8, "AppearingProbability"));
  105. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@InvestmentValue", (DbType)SqlDbType.Float, 8, "InvestmentValue"));
  106. adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@CoveringProbability", (DbType)SqlDbType.Float, 8, "CoveringProbability"));
  107. adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
  108. adapter.UpdateBatchSize = 0;
  109. DataSet ds = new DataSet();
  110. adapter.Fill(ds);
  111. for (int i = list.Count - 1; i >= 0; i--)
  112. {
  113. object[] row =
  114. {
  115. list[i].ChartId, list[i].Term, list[i].ItemValue, list[i].ItemSelect, list[i].OrderBy, list[i].RecordCount, list[i].Times,list[i].TimesTheory,
  116. list[i].Cycle,list[i].MaxMiss,list[i].AvgMiss,list[i].LastMiss,list[i].LocalMiss,list[i].LastMaxMiss,list[i].ContinuousTimes,list[i].ContinuousLocalTimes,
  117. list[i].ContinuousMaxTimes,list[i].ContinuousLocalMiss,list[i].ContinuousMaxMiss,list[i].ContinuousLocalProbability,list[i].ContinuousProbability,
  118. list[i].Probability,list[i].AppearingProbability,list[i].InvestmentValue,list[i].CoveringProbability
  119. };
  120. ds.Tables[0].Rows.Add(row);
  121. }
  122. adapter.Update(ds.Tables[0]);
  123. ds.Tables[0].Clear();
  124. adapter.Dispose();
  125. ds.Dispose();
  126. conn.Close();
  127. }
  128. return true;
  129. }
  130. public IList<TrendMissDataInfo> GetMissDataList(int charid, long term)
  131. {
  132. IList<TrendMissDataInfo> list = new List<TrendMissDataInfo>();
  133. DbParameter[] para =
  134. {
  135. DbHelper.MakeInParam(InterfaceId,"@statement",(DbType)SqlDbType.NVarChar,500,"SELECT Id, ChartId, Term, ItemValue, ItemSelect, OrderBy, RecordCount, Times, TimesTheory, Cycle, MaxMiss, AvgMiss, LastMiss, LocalMiss, LastMaxMiss, ContinuousTimes, ContinuousLocalTimes, ContinuousMaxTimes, ContinuousLocalMiss, ContinuousMaxMiss, ContinuousLocalProbability, ContinuousProbability, Probability, AppearingProbability, InvestmentValue, CoveringProbability FROM DT_TrendMissData WHERE [ChartId]=@charid And [Term]=@qi ORDER BY [OrderBy] ASC"),
  136. DbHelper.MakeInParam(InterfaceId,"@params",(DbType)SqlDbType.NVarChar,30,"@charid int,@qi int"),
  137. DbHelper.MakeInParam(InterfaceId,"@charid",(DbType)SqlDbType.Int,4,charid),
  138. DbHelper.MakeInParam(InterfaceId,"@qi",(DbType)SqlDbType.Int,4,term)
  139. };
  140. using (IDataReader reader = DbHelper.ExecuteReader(InterfaceId, CommandType.StoredProcedure, "dbo.sp_executesql", para))
  141. {
  142. while (reader.Read())
  143. {
  144. list.Add(LoadEntity(reader));
  145. }
  146. reader.Close();
  147. }
  148. return list;
  149. }
  150. protected override TrendMissDataInfo LoadEntity(DataRow dr)
  151. {
  152. return null;
  153. }
  154. protected override TrendMissDataInfo LoadEntity(IDataReader reader)
  155. {
  156. return new TrendMissDataInfo
  157. {
  158. Id = TypeConverter.ObjectToInt(reader["Id"]),
  159. ChartId = TypeConverter.ObjectToInt(reader["ChartId"]),
  160. Term = TypeConverter.ObjectToInt(reader["Term"]),
  161. ItemValue = reader["ItemValue"].ToString().Trim(),
  162. ItemSelect = TypeConverter.ObjectToBool(reader["ItemSelect"], false),
  163. OrderBy = TypeConverter.ObjectToInt(reader["OrderBy"]),
  164. RecordCount = TypeConverter.ObjectToInt(reader["RecordCount"]),
  165. Times = TypeConverter.ObjectToInt(reader["Times"]),
  166. TimesTheory = TypeConverter.ObjectToInt(reader["TimesTheory"]),
  167. Cycle = TypeConverter.StrToDouble(reader["Cycle"].ToString(), 0),
  168. MaxMiss = TypeConverter.ObjectToInt(reader["MaxMiss"]),
  169. AvgMiss = TypeConverter.StrToDouble(reader["AvgMiss"].ToString(), 0),
  170. LastMiss = TypeConverter.ObjectToInt(reader["LastMiss"]),
  171. LocalMiss = TypeConverter.ObjectToInt(reader["LocalMiss"]),
  172. LastMaxMiss = TypeConverter.ObjectToInt(reader["LastMaxMiss"]),
  173. ContinuousTimes = TypeConverter.ObjectToInt(reader["ContinuousTimes"]),
  174. ContinuousLocalTimes = TypeConverter.ObjectToInt(reader["ContinuousLocalTimes"]),
  175. ContinuousMaxTimes = TypeConverter.ObjectToInt(reader["ContinuousMaxTimes"]),
  176. ContinuousLocalMiss = TypeConverter.ObjectToInt(reader["ContinuousLocalMiss"]),
  177. ContinuousMaxMiss = TypeConverter.ObjectToInt(reader["ContinuousMaxMiss"]),
  178. ContinuousLocalProbability = TypeConverter.StrToDouble(reader["ContinuousLocalProbability"].ToString(), 0),
  179. ContinuousProbability = TypeConverter.StrToDouble(reader["ContinuousProbability"].ToString(), 0),
  180. Probability = TypeConverter.StrToDouble(reader["Probability"].ToString(), 0),
  181. AppearingProbability = TypeConverter.StrToDouble(reader["AppearingProbability"].ToString(), 0),
  182. InvestmentValue = TypeConverter.StrToDouble(reader["InvestmentValue"].ToString(), 0),
  183. CoveringProbability = TypeConverter.StrToDouble(reader["CoveringProbability"].ToString(), 0)
  184. };
  185. }
  186. }
  187. }