/// <summary> /// 更新资金表记录 /// </summary> /// <param name="cash">分红信息</param> /// <param name="accountTable">要更新的资金表实体</param> /// <param name="intNum">分红金额</param> private static void SetAccountTable(XH_AccountHoldTableInfo accountTable, int intNum) { //if (accountTable.AvailableAmount < 0.00m) // accountTable.AvailableAmount = 0; //原有的量 decimal availableAmount = accountTable.AvailableAmount; //if (accountTable.CostPrice < 0.00m) // accountTable.CostPrice = 0; //原来的成本价 decimal costPrice = accountTable.CostPrice; //持仓均价=(持仓均价*持仓量+买入成交量*买入价)/(持仓量+买入成交量) decimal holdPrice = accountTable.HoldAveragePrice; accountTable.HoldAveragePrice = (decimal)(holdPrice * availableAmount + intNum * 0) / (availableAmount + intNum); decimal newCostprice = availableAmount * costPrice / (availableAmount + intNum); //新的量 accountTable.AvailableAmount = availableAmount + intNum; //新的成本价 accountTable.CostPrice = newCostprice; decimal newBreakevenPrice = MCService.GetHoldPrice(accountTable.Code, accountTable.CostPrice, accountTable.AvailableAmount); //新的保本价 accountTable.BreakevenPrice = newBreakevenPrice; }
/// <summary> /// 增加一条数据 /// </summary> public int Add(XH_AccountHoldTableInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into XH_AccountHoldTable("); strSql.Append("UserAccountDistributeLogo,CurrencyTypeId,Code,AvailableAmount,FreezeAmount,CostPrice,BreakevenPrice,HoldAveragePrice)"); strSql.Append(" values ("); strSql.Append("@UserAccountDistributeLogo,@CurrencyTypeId,@Code,@AvailableAmount,@FreezeAmount,@CostPrice,@BreakevenPrice,@HoldAveragePrice)"); strSql.Append(";select @@IDENTITY"); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "UserAccountDistributeLogo", DbType.AnsiString, model.UserAccountDistributeLogo); db.AddInParameter(dbCommand, "CurrencyTypeId", DbType.Int32, model.CurrencyTypeId); db.AddInParameter(dbCommand, "Code", DbType.AnsiString, model.Code); db.AddInParameter(dbCommand, "AvailableAmount", DbType.Decimal, model.AvailableAmount); db.AddInParameter(dbCommand, "FreezeAmount", DbType.Decimal, model.FreezeAmount); db.AddInParameter(dbCommand, "CostPrice", DbType.Decimal, model.CostPrice); db.AddInParameter(dbCommand, "BreakevenPrice", DbType.Decimal, model.BreakevenPrice); db.AddInParameter(dbCommand, "HoldAveragePrice", DbType.Decimal, model.HoldAveragePrice); int result; object obj = db.ExecuteScalar(dbCommand); if (!int.TryParse(obj.ToString(), out result)) { return(0); } return(result); }
/// <summary> /// 带事物更新数据 /// </summary> /// <param name="model">实体</param> /// <param name="db">Database</param> /// <param name="transaction">DbTransaction</param> public bool UpdateRecord(XH_AccountHoldTableInfo model, Database db, DbTransaction transaction) { StringBuilder strSql = new StringBuilder(); strSql.Append("update XH_AccountHoldTable set "); strSql.Append("AvailableAmount=@AvailableAmount,"); strSql.Append("FreezeAmount=@FreezeAmount,"); strSql.Append("UserAccountDistributeLogo=@UserAccountDistributeLogo,"); strSql.Append("CostPrice=@CostPrice,"); strSql.Append("Code=@Code,"); strSql.Append("BreakevenPrice=@BreakevenPrice,"); strSql.Append("CurrencyTypeId=@CurrencyTypeId,"); strSql.Append("HoldAveragePrice=@HoldAveragePrice"); strSql.Append(" where AccountHoldLogoId=@AccountHoldLogoId "); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "AccountHoldLogoId", DbType.Int32, model.AccountHoldLogoId); db.AddInParameter(dbCommand, "AvailableAmount", DbType.Decimal, model.AvailableAmount); db.AddInParameter(dbCommand, "FreezeAmount", DbType.Decimal, model.FreezeAmount); db.AddInParameter(dbCommand, "UserAccountDistributeLogo", DbType.AnsiString, model.UserAccountDistributeLogo); db.AddInParameter(dbCommand, "CostPrice", DbType.Decimal, model.CostPrice); db.AddInParameter(dbCommand, "Code", DbType.AnsiString, model.Code); db.AddInParameter(dbCommand, "BreakevenPrice", DbType.Decimal, model.BreakevenPrice); db.AddInParameter(dbCommand, "CurrencyTypeId", DbType.Int32, model.CurrencyTypeId); db.AddInParameter(dbCommand, "HoldAveragePrice", DbType.Decimal, model.HoldAveragePrice); try { db.ExecuteNonQuery(dbCommand, transaction); return(true); } catch { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public XH_AccountHoldTableInfo GetXhAccountHoldTableWithNoLock(string strHoldAccount, string strCode, int iCurrType) { StringBuilder strSql = new StringBuilder(); //strSql.Append( // "select AccountHoldLogoId,AvailableAmount,FreezeAmount,UserAccountDistributeLogo,CostPrice,Code,BreakevenPrice,CurrencyTypeId from XH_AccountHoldTable WITH (NOLOCK)"); strSql.Append("select AccountHoldLogoId,UserAccountDistributeLogo,CurrencyTypeId,Code,AvailableAmount,FreezeAmount,CostPrice,BreakevenPrice,HoldAveragePrice from XH_AccountHoldTable WITH (NOLOCK)"); strSql.Append( " where CurrencyTypeId=@CurrencyTypeId AND UserAccountDistributeLogo=@UserAccountDistributeLogo AND Code=@Code"); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "CurrencyTypeId", DbType.Int32, iCurrType); db.AddInParameter(dbCommand, "UserAccountDistributeLogo", DbType.String, strHoldAccount); db.AddInParameter(dbCommand, "Code", DbType.String, strCode); XH_AccountHoldTableInfo model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public void Update(XH_AccountHoldTableInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update XH_AccountHoldTable set "); strSql.Append("UserAccountDistributeLogo=@UserAccountDistributeLogo,"); strSql.Append("CurrencyTypeId=@CurrencyTypeId,"); strSql.Append("Code=@Code,"); strSql.Append("AvailableAmount=@AvailableAmount,"); strSql.Append("FreezeAmount=@FreezeAmount,"); strSql.Append("CostPrice=@CostPrice,"); strSql.Append("BreakevenPrice=@BreakevenPrice,"); strSql.Append("HoldAveragePrice=@HoldAveragePrice"); strSql.Append(" where AccountHoldLogoId=@AccountHoldLogoId "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "AccountHoldLogoId", DbType.Int32, model.AccountHoldLogoId); db.AddInParameter(dbCommand, "UserAccountDistributeLogo", DbType.AnsiString, model.UserAccountDistributeLogo); db.AddInParameter(dbCommand, "CurrencyTypeId", DbType.Int32, model.CurrencyTypeId); db.AddInParameter(dbCommand, "Code", DbType.AnsiString, model.Code); db.AddInParameter(dbCommand, "AvailableAmount", DbType.Decimal, model.AvailableAmount); db.AddInParameter(dbCommand, "FreezeAmount", DbType.Decimal, model.FreezeAmount); db.AddInParameter(dbCommand, "CostPrice", DbType.Decimal, model.CostPrice); db.AddInParameter(dbCommand, "BreakevenPrice", DbType.Decimal, model.BreakevenPrice); db.AddInParameter(dbCommand, "HoldAveragePrice", DbType.Decimal, model.HoldAveragePrice); db.ExecuteNonQuery(dbCommand); }
/// <summary> /// 增加一条数据 /// </summary> public bool AddRecord(XH_AccountHoldTableInfo model, ReckoningTransaction tm) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into XH_AccountHoldTable("); strSql.Append( "AvailableAmount,FreezeAmount,UserAccountDistributeLogo,CostPrice,Code,BreakevenPrice,CurrencyTypeId,HoldAveragePrice)"); strSql.Append(" values ("); strSql.Append( "@AvailableAmount,@FreezeAmount,@UserAccountDistributeLogo,@CostPrice,@Code,@BreakevenPrice,@CurrencyTypeId,@HoldAveragePrice)"); strSql.Append(";select @@IDENTITY"); Database db = tm.Database; DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "AvailableAmount", DbType.Decimal, model.AvailableAmount); db.AddInParameter(dbCommand, "FreezeAmount", DbType.Decimal, model.FreezeAmount); db.AddInParameter(dbCommand, "UserAccountDistributeLogo", DbType.AnsiString, model.UserAccountDistributeLogo); db.AddInParameter(dbCommand, "CostPrice", DbType.Decimal, model.CostPrice); db.AddInParameter(dbCommand, "Code", DbType.AnsiString, model.Code); db.AddInParameter(dbCommand, "BreakevenPrice", DbType.Decimal, model.BreakevenPrice); db.AddInParameter(dbCommand, "CurrencyTypeId", DbType.Int32, model.CurrencyTypeId); db.AddInParameter(dbCommand, "HoldAveragePrice", DbType.Decimal, model.HoldAveragePrice); int result; object obj = db.ExecuteScalar(dbCommand, tm.Transaction); if (!int.TryParse(obj.ToString(), out result)) { return(false); } model.AccountHoldLogoId = result; return(true); }
private bool HodingCheck(XH_AccountHoldTableInfo hold, XH_AccountHoldTableInfo_Delta change) { string strMessage = ""; bool result = false; if (Request.BuySell == GTA.VTS.Common.CommonObject.Types.TransactionDirection.Buying) { strMessage = "GT-2219:[现货委托持久化]买持仓检查,超过持仓限制"; int position = 0; decimal freezeAmount = 0; position = Convert.ToInt32(hold.AvailableAmount); freezeAmount = hold.FreezeAmount; if (ValidateCenter.ValidateStockMinVolumeOfBusiness(Request, position, ref strMessage)) { //获取持仓限制 Decimal pLimit = MCService.GetPositionLimit(Request.Code).PositionValue; //可用持仓+冻结量+委托量<持仓限制 result = pLimit >= position + freezeAmount + Convert.ToDecimal(Request.OrderAmount); } } else { strMessage = "GT-2220:[现货委托持久化]卖持仓检查,无持仓"; if (hold != null) { strMessage = "GT-2221:[现货委托持久化]卖持仓检查,无足够可用持仓"; int position = Convert.ToInt32(hold.AvailableAmount); //持仓帐户是否存在判断 if (ValidateCenter.ValidateStockMinVolumeOfBusiness(Request, position, ref strMessage)) { //已经统一使用撮合单位了 decimal orderAmount = Convert.ToDecimal(Request.OrderAmount); // *unitMultiple; //可用持仓>=委托量 result = hold.AvailableAmount >= orderAmount; } } } if (result) { strMessage = ""; } else { holdMessage = strMessage; } return(result); }
private static bool func2(XH_AccountHoldTableInfo hold, XH_AccountHoldTableInfo_Delta change) { if (hold.AvailableAmount <= 0) { return(false); } if (hold.AvailableAmount + change.AvailableAmountDelta < 0) { return(false); } return(true); }
/// <summary> /// 对象实体绑定数据 /// </summary> public XH_AccountHoldTableInfo ReaderBind(IDataReader dataReader) { XH_AccountHoldTableInfo model = new XH_AccountHoldTableInfo(); object ojb; ojb = dataReader["AccountHoldLogoId"]; if (ojb != null && ojb != DBNull.Value) { model.AccountHoldLogoId = (int)ojb; } model.UserAccountDistributeLogo = dataReader["UserAccountDistributeLogo"].ToString(); ojb = dataReader["CurrencyTypeId"]; if (ojb != null && ojb != DBNull.Value) { model.CurrencyTypeId = (int)ojb; } model.Code = dataReader["Code"].ToString(); ojb = dataReader["AvailableAmount"]; if (ojb != null && ojb != DBNull.Value) { model.AvailableAmount = (decimal)ojb; } ojb = dataReader["FreezeAmount"]; if (ojb != null && ojb != DBNull.Value) { model.FreezeAmount = (decimal)ojb; } ojb = dataReader["CostPrice"]; if (ojb != null && ojb != DBNull.Value) { model.CostPrice = (decimal)ojb; } ojb = dataReader["BreakevenPrice"]; if (ojb != null && ojb != DBNull.Value) { model.BreakevenPrice = (decimal)ojb; } ojb = dataReader["HoldAveragePrice"]; if (ojb != null && ojb != DBNull.Value) { model.HoldAveragePrice = (decimal)ojb; } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public XH_AccountHoldTableInfo GetModel(int AccountHoldLogoId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select AccountHoldLogoId,UserAccountDistributeLogo,CurrencyTypeId,Code,AvailableAmount,FreezeAmount,CostPrice,BreakevenPrice,HoldAveragePrice from XH_AccountHoldTable "); strSql.Append(" where AccountHoldLogoId=@AccountHoldLogoId "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "AccountHoldLogoId", DbType.Int32, AccountHoldLogoId); XH_AccountHoldTableInfo model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
/// <summary> /// 更新过户记录 /// </summary> /// <param name="tm">TransactionManager</param> /// <param name="cash">分红信息</param> /// <param name="tables">登记列表</param> private static bool UpdateStockCut(ReckoningTransaction tm, List <XH_MelonCutRegisterTableInfo> tables) { #region old code 李健华 2010-06-11 改为因为在每天开市时处理那么生成为当日委托我成交 //List<XH_AccountHoldTableInfo> accountHoldList = new List<XH_AccountHoldTableInfo>(); //List<XH_HistoryTradeTableInfo> historyTradeList = new List<XH_HistoryTradeTableInfo>(); ////add 2010-1-15 因为数据库表有的成交记录是根据委托编号有外键关系,所以这里要生成委托记录 //List<XH_HistoryEntrustTableInfo> historyEntrustList = new List<XH_HistoryEntrustTableInfo>(); ////======== //foreach (XH_MelonCutRegisterTableInfo registerTable in tables) //{ // //更新持仓表 // List<XH_AccountHoldTableInfo> accountHoldTables = GetAccountHoldList( // registerTable.UserAccountDistributeLogo, // registerTable.TradeCurrencyType, registerTable.Code); // if (Utils.IsNullOrEmpty(accountHoldTables)) // continue; // //过户的量 // decimal num = registerTable.RegisterAmount; // //四舍五入 // num = Math.Round(num); // int intNum = decimal.ToInt32(num); // XH_AccountHoldTableInfo accountTable = accountHoldTables[0]; // SetAccountTable(accountTable, intNum); // accountHoldList.Add(accountTable); // //更新委托记录表 // XH_HistoryEntrustTableInfo historyEntrustTable = GetHistoryEntrustTable(registerTable, intNum); // historyEntrustList.Add(historyEntrustTable); // //更新历史成交表 // XH_HistoryTradeTableInfo historyTradeTable = GetHistoryTradeTable(registerTable, intNum); // historyTradeTable.EntrustNumber = historyEntrustTable.EntrustNumber; // historyTradeTable.CapitalAccount = historyEntrustTable.CapitalAccount; // historyTradeList.Add(historyTradeTable); // string format = "MelonCutService.UpdateStockCut进行股票分红[商品代码={0},持仓帐号={1},分红金额={2}]"; // string desc = string.Format(format, registerTable.Code, registerTable.UserAccountDistributeLogo, num); // LogHelper.WriteDebug(desc); //} //XH_AccountHoldTableDal xh_AccountHoldTableDal = new XH_AccountHoldTableDal(); //if (accountHoldList.Count > 0) //{ // foreach (var holdTableInfo in accountHoldList) // { // xh_AccountHoldTableDal.Update(holdTableInfo, tm.Database, tm.Transaction); // } //} ////先添加委托记录 //XH_HistoryEntrustTableDal xh_HistoryEntrustTableDal = new XH_HistoryEntrustTableDal(); //if (historyEntrustList.Count > 0) //{ // foreach (XH_HistoryEntrustTableInfo item in historyEntrustList) // { // xh_HistoryEntrustTableDal.Add(item, tm.Database, tm.Transaction); // } //} ////添加成交记录 ////DataRepository.XhAccountHoldTableProvider.Update(tm, accountHoldList); ////DataRepository.XhHistoryTradeTableProvider.BulkInsert(historyTradeList); //XH_HistoryTradeTableDal xh_HistoryTradeTableDal = new XH_HistoryTradeTableDal(); //if (historyTradeList.Count > 0) //{ // foreach (XH_HistoryTradeTableInfo historyTradeTable in historyTradeList) // { // //DataRepository.XhHistoryTradeTableProvider.Insert(tm, historyTradeTable); // xh_HistoryTradeTableDal.Add(historyTradeTable, tm.Database, tm.Transaction); // } //} ////删除对应的登记记录 ////DataRepository.XhMelonCutRegisterTableProvider.Delete(tm, tables); //XH_MelonCutRegisterTableDal xh_MelonCutRegisterTableDal = new XH_MelonCutRegisterTableDal(); //if (tables.Count > 0) //{ // foreach (var data in tables) // { // xh_MelonCutRegisterTableDal.Delete(data, tm.Database, tm.Transaction); // } //} #endregion #region new code 李健华 2010-06-11 改为因为在每天开市时处理那么生成为当日委托我成交 bool issuc = true; try { List <XH_AccountHoldTableInfo> accountHoldList = new List <XH_AccountHoldTableInfo>(); List <XH_TodayTradeTableInfo> todayTradeList = new List <XH_TodayTradeTableInfo>(); //add 2010-1-15 因为数据库表有的成交记录是根据委托编号有外键关系,所以这里要生成委托记录 List <XH_TodayEntrustTableInfo> todayEntrustList = new List <XH_TodayEntrustTableInfo>(); UA_UserAccountAllocationTableDal dal = new UA_UserAccountAllocationTableDal(); //======== foreach (XH_MelonCutRegisterTableInfo registerTable in tables) { //更新持仓表 List <XH_AccountHoldTableInfo> accountHoldTables = GetAccountHoldList(registerTable.UserAccountDistributeLogo, registerTable.TradeCurrencyType, registerTable.Code); if (Utils.IsNullOrEmpty(accountHoldTables)) { continue; } //过户的量 decimal num = registerTable.RegisterAmount; //四舍五入 num = Math.Round(num); int intNum = decimal.ToInt32(num); XH_AccountHoldTableInfo accountTable = accountHoldTables[0]; SetAccountTable(accountTable, intNum); accountHoldList.Add(accountTable); //更新委托记录表 XH_TodayEntrustTableInfo todayEntrustTable = GetHistoryEntrustTable(registerTable, intNum); todayEntrustList.Add(todayEntrustTable); //更新历史成交表 XH_TodayTradeTableInfo todayTradeTable = GetTodayTradeTable(registerTable, intNum); todayTradeTable.EntrustNumber = todayEntrustTable.EntrustNumber; todayTradeTable.CapitalAccount = todayEntrustTable.CapitalAccount; todayTradeList.Add(todayTradeTable); UA_UserAccountAllocationTableInfo userModel = dal.GetModel(registerTable.UserAccountDistributeLogo); #region 回推相关成交记录信息 ReckonEndObject <XH_TodayEntrustTableInfo, XH_TodayTradeTableInfo> reckonEndObject = new ReckonEndObject <XH_TodayEntrustTableInfo, XH_TodayTradeTableInfo>(); reckonEndObject.IsSuccess = true; reckonEndObject.EntrustTable = todayEntrustTable; List <XH_TodayTradeTableInfo> tradeModels = new List <XH_TodayTradeTableInfo>(); tradeModels.Add(todayTradeTable); reckonEndObject.TradeTableList = tradeModels; if (userModel != null) { reckonEndObject.TradeID = userModel.UserID; } reckonEndObject.Message = "分红委托成交"; CounterOrderService.Instance.AcceptStockDealOrder(reckonEndObject); #endregion string format = "MelonCutService.UpdateStockCut进行股票分红[商品代码={0},持仓帐号={1},分红金额={2}]"; string desc = string.Format(format, registerTable.Code, registerTable.UserAccountDistributeLogo, num); LogHelper.WriteDebug(desc); } XH_AccountHoldTableDal xh_AccountHoldTableDal = new XH_AccountHoldTableDal(); if (accountHoldList.Count > 0) { foreach (var holdTableInfo in accountHoldList) { xh_AccountHoldTableDal.Update(holdTableInfo, tm.Database, tm.Transaction); } } //先添加委托记录 XH_TodayEntrustTableDal xh_HistoryEntrustTableDal = new XH_TodayEntrustTableDal(); if (todayEntrustList.Count > 0) { foreach (XH_TodayEntrustTableInfo item in todayEntrustList) { xh_HistoryEntrustTableDal.Add(item, tm.Database, tm.Transaction); } } //添加成交记录 //DataRepository.XhAccountHoldTableProvider.Update(tm, accountHoldList); //DataRepository.XhHistoryTradeTableProvider.BulkInsert(historyTradeList); XH_TodayTradeTableDal xh_todayTradeTableDal = new XH_TodayTradeTableDal(); if (todayTradeList.Count > 0) { foreach (XH_TodayTradeTableInfo todayTradeTable in todayTradeList) { //DataRepository.XhHistoryTradeTableProvider.Insert(tm, historyTradeTable); xh_todayTradeTableDal.Add(todayTradeTable, tm); } } //删除对应的登记记录 //DataRepository.XhMelonCutRegisterTableProvider.Delete(tm, tables); XH_MelonCutRegisterTableDal xh_MelonCutRegisterTableDal = new XH_MelonCutRegisterTableDal(); if (tables.Count > 0) { foreach (var data in tables) { xh_MelonCutRegisterTableDal.Delete(data, tm.Database, tm.Transaction); } } } catch (Exception ex) { LogHelper.WriteError("过户分红异常" + ex.Message, ex); issuc = false; } return(issuc); #endregion }