123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.Common;
- using System.Data.SqlClient;
- using System.Text;
- using CB.Common;
- using CB.Data;
- using CB.Entity;
- using CB.Interface.Infrastructure;
- namespace CB.Data.SqlServer
- {
- public class TrendMissDataManage : Repository<TrendMissDataInfo>, ITrendMissDataService
- {
- public TrendMissDataManage(string interfaceId)
- : base(interfaceId)
- {
- }
- public override bool Save(TrendMissDataInfo entity)
- {
- throw new NotImplementedException();
- }
- public override bool Update(TrendMissDataInfo entity)
- {
- throw new NotImplementedException();
- }
- public override bool Delete(int id)
- {
- throw new NotImplementedException();
- }
- public override TrendMissDataInfo Get<TKey>(TKey key)
- {
- throw new NotImplementedException();
- }
- public override IList<TrendMissDataInfo> ToList()
- {
- IList<TrendMissDataInfo> list = new List<TrendMissDataInfo>();
- StringBuilder strSql = new StringBuilder();
- 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 ");
- strSql.Append(" from DT_TrendMissData ORDER BY [Term] ASC");
- using (DataTable dt = DbHelper.ExecuteDatatable(InterfaceId, strSql.ToString()))
- {
- if (null != dt && 0 < dt.Rows.Count)
- {
- foreach (DataRow dr in dt.Rows)
- {
- list.Add(LoadEntity(dr));
- }
- }
- dt.Dispose();
- }
- return list;
- }
- public override IList<TrendMissDataInfo> ToList(TrendMissDataInfo entity)
- {
- throw new NotImplementedException();
- }
- public override IList<TrendMissDataInfo> ToPaging(TrendMissDataInfo entity, int pageSize, int pageIndex, out int recordCount)
- {
- throw new NotImplementedException();
- }
- public bool BatchSave(IList<TrendMissDataInfo> list)
- {
- if (null == list || 0 >= list.Count)
- return false;
- using (DbConnection conn = DbHelper.Factory(InterfaceId).CreateConnection())
- {
- conn.ConnectionString = DbHelper.ConnectionString(InterfaceId);
- conn.Open();
- DbDataAdapter adapter = DbHelper.Factory(InterfaceId).CreateDataAdapter();
- adapter.SelectCommand = DbHelper.Factory(InterfaceId).CreateCommand();
- adapter.SelectCommand.CommandText = @"SELECT TOP 0 [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]";
- adapter.SelectCommand.CommandType = CommandType.Text;
- adapter.SelectCommand.Connection = conn;
- adapter.InsertCommand = DbHelper.Factory(InterfaceId).CreateCommand();
- adapter.InsertCommand.CommandText = "usp_TrendMissData_save";
- adapter.InsertCommand.CommandType = CommandType.StoredProcedure;
- adapter.InsertCommand.Connection = conn;
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ChartId", (DbType)SqlDbType.Int, 4, "ChartId"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@Term", (DbType)SqlDbType.Int, 4, "Term"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ItemValue", (DbType)SqlDbType.NChar, 40, "ItemValue"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ItemSelect", (DbType)SqlDbType.Bit, 1, "ItemSelect"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@OrderBy", (DbType)SqlDbType.Int, 4, "OrderBy"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@RecordCount", (DbType)SqlDbType.Int, 4, "RecordCount"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@Times", (DbType)SqlDbType.Int, 4, "Times"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@TimesTheory", (DbType)SqlDbType.Int, 4, "TimesTheory"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@Cycle", (DbType)SqlDbType.Float, 8, "Cycle"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@MaxMiss", (DbType)SqlDbType.Int, 4, "MaxMiss"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@AvgMiss", (DbType)SqlDbType.Float, 8, "AvgMiss"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@LastMiss", (DbType)SqlDbType.Int, 4, "LastMiss"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@LocalMiss", (DbType)SqlDbType.Int, 4, "LocalMiss"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@LastMaxMiss", (DbType)SqlDbType.Int, 4, "LastMaxMiss"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ContinuousTimes", (DbType)SqlDbType.Int, 4, "ContinuousTimes"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ContinuousLocalTimes", (DbType)SqlDbType.Int, 4, "ContinuousLocalTimes"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ContinuousMaxTimes", (DbType)SqlDbType.Int, 4, "ContinuousMaxTimes"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ContinuousLocalMiss", (DbType)SqlDbType.Int, 4, "ContinuousLocalMiss"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ContinuousMaxMiss", (DbType)SqlDbType.Int, 4, "ContinuousMaxMiss"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ContinuousLocalProbability", (DbType)SqlDbType.Float, 8, "ContinuousLocalProbability"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@ContinuousProbability", (DbType)SqlDbType.Float, 8, "ContinuousProbability"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@Probability", (DbType)SqlDbType.Float, 8, "Probability"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@AppearingProbability", (DbType)SqlDbType.Float, 8, "AppearingProbability"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@InvestmentValue", (DbType)SqlDbType.Float, 8, "InvestmentValue"));
- adapter.InsertCommand.Parameters.Add(DbHelper.MakeParamByColumn(InterfaceId, "@CoveringProbability", (DbType)SqlDbType.Float, 8, "CoveringProbability"));
- adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
- adapter.UpdateBatchSize = 0;
- DataSet ds = new DataSet();
- adapter.Fill(ds);
- for (int i = list.Count - 1; i >= 0; i--)
- {
- object[] row =
- {
- list[i].ChartId, list[i].Term, list[i].ItemValue, list[i].ItemSelect, list[i].OrderBy, list[i].RecordCount, list[i].Times,list[i].TimesTheory,
- list[i].Cycle,list[i].MaxMiss,list[i].AvgMiss,list[i].LastMiss,list[i].LocalMiss,list[i].LastMaxMiss,list[i].ContinuousTimes,list[i].ContinuousLocalTimes,
- list[i].ContinuousMaxTimes,list[i].ContinuousLocalMiss,list[i].ContinuousMaxMiss,list[i].ContinuousLocalProbability,list[i].ContinuousProbability,
- list[i].Probability,list[i].AppearingProbability,list[i].InvestmentValue,list[i].CoveringProbability
- };
- ds.Tables[0].Rows.Add(row);
- }
- adapter.Update(ds.Tables[0]);
- ds.Tables[0].Clear();
- adapter.Dispose();
- ds.Dispose();
- conn.Close();
- }
- return true;
- }
- public IList<TrendMissDataInfo> GetMissDataList(int charid, long term)
- {
- IList<TrendMissDataInfo> list = new List<TrendMissDataInfo>();
- DbParameter[] para =
- {
- 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"),
- DbHelper.MakeInParam(InterfaceId,"@params",(DbType)SqlDbType.NVarChar,30,"@charid int,@qi int"),
- DbHelper.MakeInParam(InterfaceId,"@charid",(DbType)SqlDbType.Int,4,charid),
- DbHelper.MakeInParam(InterfaceId,"@qi",(DbType)SqlDbType.Int,4,term)
- };
- using (IDataReader reader = DbHelper.ExecuteReader(InterfaceId, CommandType.StoredProcedure, "dbo.sp_executesql", para))
- {
- while (reader.Read())
- {
- list.Add(LoadEntity(reader));
- }
- reader.Close();
- }
- return list;
- }
- protected override TrendMissDataInfo LoadEntity(DataRow dr)
- {
- return null;
- }
- protected override TrendMissDataInfo LoadEntity(IDataReader reader)
- {
- return new TrendMissDataInfo
- {
- Id = TypeConverter.ObjectToInt(reader["Id"]),
- ChartId = TypeConverter.ObjectToInt(reader["ChartId"]),
- Term = TypeConverter.ObjectToInt(reader["Term"]),
- ItemValue = reader["ItemValue"].ToString().Trim(),
- ItemSelect = TypeConverter.ObjectToBool(reader["ItemSelect"], false),
- OrderBy = TypeConverter.ObjectToInt(reader["OrderBy"]),
- RecordCount = TypeConverter.ObjectToInt(reader["RecordCount"]),
- Times = TypeConverter.ObjectToInt(reader["Times"]),
- TimesTheory = TypeConverter.ObjectToInt(reader["TimesTheory"]),
- Cycle = TypeConverter.StrToDouble(reader["Cycle"].ToString(), 0),
- MaxMiss = TypeConverter.ObjectToInt(reader["MaxMiss"]),
- AvgMiss = TypeConverter.StrToDouble(reader["AvgMiss"].ToString(), 0),
- LastMiss = TypeConverter.ObjectToInt(reader["LastMiss"]),
- LocalMiss = TypeConverter.ObjectToInt(reader["LocalMiss"]),
- LastMaxMiss = TypeConverter.ObjectToInt(reader["LastMaxMiss"]),
- ContinuousTimes = TypeConverter.ObjectToInt(reader["ContinuousTimes"]),
- ContinuousLocalTimes = TypeConverter.ObjectToInt(reader["ContinuousLocalTimes"]),
- ContinuousMaxTimes = TypeConverter.ObjectToInt(reader["ContinuousMaxTimes"]),
- ContinuousLocalMiss = TypeConverter.ObjectToInt(reader["ContinuousLocalMiss"]),
- ContinuousMaxMiss = TypeConverter.ObjectToInt(reader["ContinuousMaxMiss"]),
- ContinuousLocalProbability = TypeConverter.StrToDouble(reader["ContinuousLocalProbability"].ToString(), 0),
- ContinuousProbability = TypeConverter.StrToDouble(reader["ContinuousProbability"].ToString(), 0),
- Probability = TypeConverter.StrToDouble(reader["Probability"].ToString(), 0),
- AppearingProbability = TypeConverter.StrToDouble(reader["AppearingProbability"].ToString(), 0),
- InvestmentValue = TypeConverter.StrToDouble(reader["InvestmentValue"].ToString(), 0),
- CoveringProbability = TypeConverter.StrToDouble(reader["CoveringProbability"].ToString(), 0)
- };
- }
- }
- }
|