/// <summary> /// 增加一条数据 /// </summary> public void Add(QH_TodayTradeTableInfo model, ReckoningTransaction tm) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into QH_TodayTradeTable("); strSql.Append("TradeNumber,EntrustNumber,PortfolioLogo,TradePrice,EntrustPrice,TradeAmount,TradeProceduresFee,Margin,ContractCode,TradeAccount,CapitalAccount,BuySellTypeId,OpenCloseTypeId,TradeUnitId,TradeTypeId,CurrencyTypeId,TradeTime,MarketProfitLoss)"); strSql.Append(" values ("); strSql.Append("@TradeNumber,@EntrustNumber,@PortfolioLogo,@TradePrice,@EntrustPrice,@TradeAmount,@TradeProceduresFee,@Margin,@ContractCode,@TradeAccount,@CapitalAccount,@BuySellTypeId,@OpenCloseTypeId,@TradeUnitId,@TradeTypeId,@CurrencyTypeId,@TradeTime,@MarketProfitLoss)"); Database db = tm.Database; DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "TradeNumber", DbType.AnsiString, model.TradeNumber); db.AddInParameter(dbCommand, "EntrustNumber", DbType.AnsiString, model.EntrustNumber); db.AddInParameter(dbCommand, "PortfolioLogo", DbType.AnsiString, model.PortfolioLogo); db.AddInParameter(dbCommand, "TradePrice", DbType.Decimal, model.TradePrice); db.AddInParameter(dbCommand, "EntrustPrice", DbType.Decimal, model.EntrustPrice); db.AddInParameter(dbCommand, "TradeAmount", DbType.Int32, model.TradeAmount); db.AddInParameter(dbCommand, "TradeProceduresFee", DbType.Decimal, model.TradeProceduresFee); db.AddInParameter(dbCommand, "Margin", DbType.Decimal, model.Margin); db.AddInParameter(dbCommand, "ContractCode", DbType.AnsiString, model.ContractCode); db.AddInParameter(dbCommand, "TradeAccount", DbType.AnsiString, model.TradeAccount); db.AddInParameter(dbCommand, "CapitalAccount", DbType.AnsiString, model.CapitalAccount); db.AddInParameter(dbCommand, "BuySellTypeId", DbType.Int32, model.BuySellTypeId); db.AddInParameter(dbCommand, "OpenCloseTypeId", DbType.Int32, model.OpenCloseTypeId); db.AddInParameter(dbCommand, "TradeUnitId", DbType.Int32, model.TradeUnitId); db.AddInParameter(dbCommand, "TradeTypeId", DbType.Int32, model.TradeTypeId); db.AddInParameter(dbCommand, "CurrencyTypeId", DbType.Int32, model.CurrencyTypeId); db.AddInParameter(dbCommand, "TradeTime", DbType.DateTime, model.TradeTime); db.AddInParameter(dbCommand, "MarketProfitLoss", DbType.Decimal, model.MarketProfitLoss); db.ExecuteNonQuery(dbCommand, tm.Transaction); }
/// <summary> /// 更新一条数据 /// </summary> public void Update(QH_TodayTradeTableInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update QH_TodayTradeTable set "); strSql.Append("EntrustNumber=@EntrustNumber,"); strSql.Append("PortfolioLogo=@PortfolioLogo,"); strSql.Append("TradePrice=@TradePrice,"); strSql.Append("EntrustPrice=@EntrustPrice,"); strSql.Append("TradeAmount=@TradeAmount,"); strSql.Append("TradeProceduresFee=@TradeProceduresFee,"); strSql.Append("Margin=@Margin,"); strSql.Append("ContractCode=@ContractCode,"); strSql.Append("TradeAccount=@TradeAccount,"); strSql.Append("CapitalAccount=@CapitalAccount,"); strSql.Append("BuySellTypeId=@BuySellTypeId,"); strSql.Append("OpenCloseTypeId=@OpenCloseTypeId,"); strSql.Append("TradeUnitId=@TradeUnitId,"); strSql.Append("TradeTypeId=@TradeTypeId,"); strSql.Append("CurrencyTypeId=@CurrencyTypeId,"); strSql.Append("TradeTime=@TradeTime,"); strSql.Append("MarketProfitLoss=@MarketProfitLoss"); strSql.Append(" where TradeNumber=@TradeNumber "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "TradeNumber", DbType.AnsiString, model.TradeNumber); db.AddInParameter(dbCommand, "EntrustNumber", DbType.AnsiString, model.EntrustNumber); db.AddInParameter(dbCommand, "PortfolioLogo", DbType.AnsiString, model.PortfolioLogo); db.AddInParameter(dbCommand, "TradePrice", DbType.Decimal, model.TradePrice); db.AddInParameter(dbCommand, "EntrustPrice", DbType.Decimal, model.EntrustPrice); db.AddInParameter(dbCommand, "TradeAmount", DbType.Int32, model.TradeAmount); db.AddInParameter(dbCommand, "TradeProceduresFee", DbType.Decimal, model.TradeProceduresFee); db.AddInParameter(dbCommand, "Margin", DbType.Decimal, model.Margin); db.AddInParameter(dbCommand, "ContractCode", DbType.AnsiString, model.ContractCode); db.AddInParameter(dbCommand, "TradeAccount", DbType.AnsiString, model.TradeAccount); db.AddInParameter(dbCommand, "CapitalAccount", DbType.AnsiString, model.CapitalAccount); db.AddInParameter(dbCommand, "BuySellTypeId", DbType.Int32, model.BuySellTypeId); db.AddInParameter(dbCommand, "OpenCloseTypeId", DbType.Int32, model.OpenCloseTypeId); db.AddInParameter(dbCommand, "TradeUnitId", DbType.Int32, model.TradeUnitId); db.AddInParameter(dbCommand, "TradeTypeId", DbType.Int32, model.TradeTypeId); db.AddInParameter(dbCommand, "CurrencyTypeId", DbType.Int32, model.CurrencyTypeId); db.AddInParameter(dbCommand, "TradeTime", DbType.DateTime, model.TradeTime); db.AddInParameter(dbCommand, "MarketProfitLoss", DbType.Decimal, model.MarketProfitLoss); db.ExecuteNonQuery(dbCommand); }
/// <summary> /// 得到一个对象实体 /// </summary> public QH_TodayTradeTableInfo GetModel(string TradeNumber) { StringBuilder strSql = new StringBuilder(); strSql.Append("select TradeNumber,EntrustNumber,PortfolioLogo,TradePrice,EntrustPrice,TradeAmount,TradeProceduresFee,Margin,ContractCode,TradeAccount,CapitalAccount,BuySellTypeId,OpenCloseTypeId,TradeUnitId,TradeTypeId,CurrencyTypeId,TradeTime,MarketProfitLoss from QH_TodayTradeTable "); strSql.Append(" where TradeNumber=@TradeNumber "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "TradeNumber", DbType.AnsiString, TradeNumber); QH_TodayTradeTableInfo model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
///// <summary> ///// 获得数据列表 ///// </summary> //public List<QH_TodayTradeTableInfo> GetPushList(string channelID) //{ // string where = string.Format("SELECT X.* FROM QH_TodayTradeTable X ,QH_PushBackOrderTable Y WHERE X.TradeNumber = Y.TradeNumber and y.ChannelID = '{0}'", channelID); // List<QH_TodayTradeTableInfo> list = new List<QH_TodayTradeTableInfo>(); // Database db = DatabaseFactory.CreateDatabase(); // using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, where.ToString())) // { // while (dataReader.Read()) // { // list.Add(ReaderBind(dataReader)); // } // } // return list; //} /// <summary> /// 对象实体绑定数据 /// </summary> public QH_TodayTradeTableInfo ReaderBind(IDataReader dataReader) { QH_TodayTradeTableInfo model = new QH_TodayTradeTableInfo(); object ojb; model.TradeNumber = dataReader["TradeNumber"].ToString(); model.EntrustNumber = dataReader["EntrustNumber"].ToString(); model.PortfolioLogo = dataReader["PortfolioLogo"].ToString(); ojb = dataReader["TradePrice"]; if (ojb != null && ojb != DBNull.Value) { model.TradePrice = (decimal)ojb; } ojb = dataReader["EntrustPrice"]; if (ojb != null && ojb != DBNull.Value) { model.EntrustPrice = (decimal)ojb; } ojb = dataReader["TradeAmount"]; if (ojb != null && ojb != DBNull.Value) { model.TradeAmount = (int)ojb; } ojb = dataReader["TradeProceduresFee"]; if (ojb != null && ojb != DBNull.Value) { model.TradeProceduresFee = (decimal)ojb; } ojb = dataReader["Margin"]; if (ojb != null && ojb != DBNull.Value) { model.Margin = (decimal)ojb; } model.ContractCode = dataReader["ContractCode"].ToString(); model.TradeAccount = dataReader["TradeAccount"].ToString(); model.CapitalAccount = dataReader["CapitalAccount"].ToString(); ojb = dataReader["BuySellTypeId"]; if (ojb != null && ojb != DBNull.Value) { model.BuySellTypeId = (int)ojb; } ojb = dataReader["OpenCloseTypeId"]; if (ojb != null && ojb != DBNull.Value) { model.OpenCloseTypeId = (int)ojb; } ojb = dataReader["TradeUnitId"]; if (ojb != null && ojb != DBNull.Value) { model.TradeUnitId = (int)ojb; } ojb = dataReader["TradeTypeId"]; if (ojb != null && ojb != DBNull.Value) { model.TradeTypeId = (int)ojb; } ojb = dataReader["CurrencyTypeId"]; if (ojb != null && ojb != DBNull.Value) { model.CurrencyTypeId = (int)ojb; } ojb = dataReader["TradeTime"]; if (ojb != null && ojb != DBNull.Value) { model.TradeTime = (DateTime)ojb; } ojb = dataReader["MarketProfitLoss"]; if (ojb != null && ojb != DBNull.Value) { model.MarketProfitLoss = (decimal)ojb; } return(model); }
/// <summary> /// 构建期货撤单回报 /// </summary> /// <param name="tet"></param> /// <param name="rde"></param> /// <param name="tm"></param> /// <param name="isInternalCancelOrder"></param> /// <returns></returns> public static QH_TodayTradeTableInfo BuildQHCancelRpt(QH_TodayEntrustTableInfo tet, CancelOrderEntity rde, ReckoningTransaction tm, bool isInternalCancelOrder) { string result = string.Empty; //当为价格错误的撤单时,直接作为废单,不记录到数据库中。 if (rde.OrderVolume == -1) { return(null); } //成交回报实体 var qhDealrpt = new QH_TodayTradeTableInfo(); qhDealrpt.TradeNumber = rde.Id; //不再自己构建id,使用撤单回报的id,一一对应 //成交时间 qhDealrpt.TradeTime = DateTime.Now; //成交价 qhDealrpt.TradePrice = 0; //成交量 qhDealrpt.TradeAmount = Convert.ToInt32(rde.OrderVolume); //股东代码 qhDealrpt.TradeAccount = tet.TradeAccount; //资金帐户 qhDealrpt.CapitalAccount = tet.CapitalAccount; //成交回报类型 if (isInternalCancelOrder) { qhDealrpt.TradeTypeId = (int)Types.DealRptType.DRTInternalCanceled; } else { qhDealrpt.TradeTypeId = (int)Types.DealRptType.DRTCanceled; } //现货名称 qhDealrpt.ContractCode = tet.ContractCode; //交易手续费 qhDealrpt.TradeProceduresFee = 0; //保证金 qhDealrpt.Margin = 0; //委托价格 qhDealrpt.EntrustPrice = tet.EntrustPrice; //委托单号 qhDealrpt.EntrustNumber = tet.EntrustNumber; //投组标识 qhDealrpt.PortfolioLogo = tet.PortfolioLogo; //货币类型 qhDealrpt.CurrencyTypeId = tet.CurrencyTypeId; //开平方向 qhDealrpt.OpenCloseTypeId = tet.OpenCloseTypeId; //买卖方向 qhDealrpt.BuySellTypeId = tet.BuySellTypeId; //成交单位 qhDealrpt.TradeUnitId = tet.TradeUnitId; //2009-12-03 add 李健华 qhDealrpt.MarketProfitLoss = 0; //========== QH_TodayTradeTableDal qh_TodayTradeTableDal = new QH_TodayTradeTableDal(); // var provider = new SqlQhTodayTradeTableProvider(TransactionFactory.RC_ConnectionString, true, string.Empty); //provider.Insert(tm, qhDealrpt); qh_TodayTradeTableDal.Add(qhDealrpt, tm); return(qhDealrpt); }
/// <summary> /// 构建股指期货成交回报 /// </summary> /// <param name="tet"></param> /// <param name="sdbe"></param> /// <param name="qhcr"></param> /// <param name="dMargin"></param> /// <param name="tm"></param> /// <param name="marketProfitLoss"></param> /// <param name="dealRptType">成交类型</param> /// <returns></returns> public static QH_TodayTradeTableInfo BuildGZQHDealRpt(QH_TodayEntrustTableInfo tet, FutureDealBackEntity sdbe, QHCostResult qhcr, decimal dMargin, decimal marketProfitLoss, ReckoningTransaction tm, Types.DealRptType dealRptType) { string result = string.Empty; //成交回报实体 var qhDealrpt = new QH_TodayTradeTableInfo(); //xhDealrpt.TradeNumber = this.BuildXHDealOrderNo(); qhDealrpt.TradeNumber = sdbe.Id; //不再自己构建id,使用成交回报的id,一一对应 //成交时间 qhDealrpt.TradeTime = sdbe.DealTime; //成交价 qhDealrpt.TradePrice = sdbe.DealPrice; //成交量 qhDealrpt.TradeAmount = Convert.ToInt32(sdbe.DealAmount); //成交单位 qhDealrpt.TradeUnitId = tet.TradeUnitId; //股东代码 qhDealrpt.TradeAccount = tet.TradeAccount; //资金帐户 qhDealrpt.CapitalAccount = tet.CapitalAccount; //成交回报类型 // qhDealrpt.TradeTypeId = (int)Types.DealRptType.DRTDealed; qhDealrpt.TradeTypeId = (int)dealRptType; //现货名称 qhDealrpt.ContractCode = tet.ContractCode; //现货代码 //qhDealrpt = tet.ContractName; //交易手续费 qhDealrpt.TradeProceduresFee = qhcr.Cosing; //保证金 //qhDealrpt.Margin = 0; // dMargin; //update date 2009-12-03 不管开平仓都记录保证金 //if (tet.OpenCloseTypeId == (int) Types.FutureOpenCloseType.OpenPosition) qhDealrpt.Margin = dMargin; //============= //委托价格 qhDealrpt.EntrustPrice = tet.EntrustPrice; //委托单号 qhDealrpt.EntrustNumber = tet.EntrustNumber; //投组标识 qhDealrpt.PortfolioLogo = tet.PortfolioLogo; //货币类型 qhDealrpt.CurrencyTypeId = tet.CurrencyTypeId; qhDealrpt.BuySellTypeId = tet.BuySellTypeId; qhDealrpt.OpenCloseTypeId = tet.OpenCloseTypeId; //add 李健华 增加每笔盯市盈亏 qhDealrpt.MarketProfitLoss = marketProfitLoss; //========== QH_TodayTradeTableDal qhTodayTradeTableDal = new QH_TodayTradeTableDal(); if (qhTodayTradeTableDal.Exists(qhDealrpt.TradeNumber)) { string format = "BuildGZQHDealRpt数据库已经存在TradeNumber={0}"; string desc = string.Format(format, qhDealrpt.TradeNumber); LogHelper.WriteDebug(desc); return(null); } try { qhTodayTradeTableDal.Add(qhDealrpt, tm); } catch (Exception ex) { LogHelper.WriteError(ex.Message, ex); qhDealrpt = null; } return(qhDealrpt); }