/// <summary> /// 创建一个今日成交记录 /// </summary> /// <param name="registerTable">登记表实体</param> /// <param name="intNum">分红过户量</param>里 /// <returns>今日成交实体</returns> private static XH_TodayTradeTableInfo GetTodayTradeTable(XH_MelonCutRegisterTableInfo registerTable, int intNum) { XH_TodayTradeTableInfo todayTradeTable = new XH_TodayTradeTableInfo(); todayTradeTable.TradeNumber = Guid.NewGuid().ToString(); todayTradeTable.BuySellTypeId = (int)GTA.VTS.Common.CommonObject.Types.TransactionDirection.Buying; todayTradeTable.StockAccount = registerTable.UserAccountDistributeLogo; todayTradeTable.TradeTypeId = (int)Types.DealRptType.DRTTransfer; todayTradeTable.CurrencyTypeId = registerTable.TradeCurrencyType; todayTradeTable.TradeUnitId = MCService.GetPriceUnit(registerTable.Code); todayTradeTable.TradeAmount = intNum; todayTradeTable.TradeTime = DateTime.Now; CM_BourseType bourseType = MCService.CommonPara.GetBourseTypeByCommodityCode(registerTable.Code); if (bourseType != null) { } CM_Commodity commodity = MCService.CommonPara.GetCommodityByCommodityCode(registerTable.Code); todayTradeTable.SpotCode = registerTable.Code; if (commodity != null) { } CM_BreedClass breedClass = MCService.CommonPara.GetBreedClassByCommodityCode(registerTable.Code); if (breedClass != null) { } return(todayTradeTable); }
/// <summary> /// 进行股票分红登记 /// </summary> /// <param name="list">分红信息列表</param> private static bool RegisterStockList(IList <CM_StockMelonStock> list) { try { //选出今日需要登记的股票分红信息 var q = from c in list where CheckRegDate(c.StockRightRegisterDate) && c.StockRightLogoutDatumDate.HasValue && c.SentStockRatio.HasValue select c; //处理每一个股票的分红 foreach (CM_StockMelonStock cash in q) { //获取所有有此股票的持仓记录 List <XH_AccountHoldTableInfo> holdTables = GetAccountHoldListByCode(cash.CommodityCode); if (Utils.IsNullOrEmpty(holdTables)) { continue; } List <XH_MelonCutRegisterTableInfo> tables = new List <XH_MelonCutRegisterTableInfo>(); foreach (XH_AccountHoldTableInfo holdTable in holdTables) { XH_MelonCutRegisterTableInfo table = new XH_MelonCutRegisterTableInfo(); table.RegisterDate = cash.StockRightRegisterDate.Value; table.CutDate = cash.StockRightLogoutDatumDate.Value; table.Code = cash.CommodityCode; //====update 李健华 2010-01-15 这里是股票分红 //table.CutType = (int) Types.MeloncutType.Cash; table.CutType = (int)Types.MeloncutType.Stock; //========== table.UserAccountDistributeLogo = holdTable.UserAccountDistributeLogo; table.TradeCurrencyType = holdTable.CurrencyTypeId; //目前这个没有什么用,因为数据库已经把该字段设置为外键不能为null,所以这里直接以持仓的交易货币类型来代替如果日后有用再修改 table.CurrencyTypeId = holdTable.CurrencyTypeId; table.RegisterAmount = holdTable.AvailableAmount * ((decimal)cash.SentStockRatio.Value); tables.Add(table); } //记录到登记表中 SaveRegisterTables(tables); string format = "MelonCutService.RegisterStockList进行股票分红登记[商品代码={0},登记的持有者总数={1}]"; string desc = string.Format(format, cash.CommodityCode, holdTables.Count); LogHelper.WriteDebug(desc); } } catch (Exception ex) { LogHelper.WriteError("股票分红登记异常" + ex.Message, ex); return(false); } return(true); }
/// <summary> /// 创建一个今日委托记录 /// </summary> /// <param name="registerTable">登记表实体</param> /// <param name="intNum">分红过户量</param>里 /// <returns>今日委托实体</returns> private static XH_TodayEntrustTableInfo GetHistoryEntrustTable(XH_MelonCutRegisterTableInfo registerTable, int intNum) { XH_TodayEntrustTableInfo todayEntrustTable = new XH_TodayEntrustTableInfo(); todayEntrustTable.EntrustNumber = XHCommonLogic.BuildXHOrderNo(); todayEntrustTable.CurrencyTypeId = registerTable.TradeCurrencyType; todayEntrustTable.TradeUnitId = MCService.GetPriceUnit(registerTable.Code); todayEntrustTable.EntrustAmount = intNum; todayEntrustTable.EntrustPrice = 0; todayEntrustTable.EntrustTime = DateTime.Now; todayEntrustTable.OfferTime = DateTime.Now; todayEntrustTable.BuySellTypeId = (int)GTA.VTS.Common.CommonObject.Types.TransactionDirection.Buying; todayEntrustTable.OrderStatusId = (int)Types.OrderStateType.DOSDealed; todayEntrustTable.StockAccount = registerTable.UserAccountDistributeLogo;//持仓账号,在分红记录中都是持仓账号 //====通过持仓账号查询相关联的资金账号 UA_UserAccountAllocationTableDal dal = new UA_UserAccountAllocationTableDal(); UA_UserAccountAllocationTableInfo uaUser = dal.GetUserHoldAccountByUserCapitalAccount(registerTable.UserAccountDistributeLogo); todayEntrustTable.CapitalAccount = uaUser.UserAccountDistributeLogo; //===== todayEntrustTable.PortfolioLogo = ""; todayEntrustTable.SpotCode = registerTable.Code; todayEntrustTable.TradeAmount = intNum; todayEntrustTable.TradeAveragePrice = 0; todayEntrustTable.CancelAmount = 0; todayEntrustTable.IsMarketValue = false; todayEntrustTable.OrderMessage = "股票分红生成委托记录"; todayEntrustTable.McOrderId = Guid.NewGuid().ToString(); return(todayEntrustTable); }
/// <summary> /// 更新一条数据 /// </summary> public void Update(XH_MelonCutRegisterTableInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update XH_MelonCutRegisterTable set "); strSql.Append("RegisterDate=@RegisterDate,"); strSql.Append("CutDate=@CutDate,"); strSql.Append("UserAccountDistributeLogo=@UserAccountDistributeLogo,"); strSql.Append("TradeCurrencyType=@TradeCurrencyType,"); strSql.Append("Code=@Code,"); strSql.Append("RegisterAmount=@RegisterAmount,"); strSql.Append("CutType=@CutType,"); strSql.Append("CurrencyTypeId=@CurrencyTypeId"); strSql.Append(" where MelonCutRegisterID=@MelonCutRegisterID "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "MelonCutRegisterID", DbType.Int32, model.MelonCutRegisterID); db.AddInParameter(dbCommand, "RegisterDate", DbType.DateTime, model.RegisterDate); db.AddInParameter(dbCommand, "CutDate", DbType.DateTime, model.CutDate); db.AddInParameter(dbCommand, "UserAccountDistributeLogo", DbType.AnsiString, model.UserAccountDistributeLogo); db.AddInParameter(dbCommand, "TradeCurrencyType", DbType.Int32, model.TradeCurrencyType); db.AddInParameter(dbCommand, "Code", DbType.AnsiString, model.Code); db.AddInParameter(dbCommand, "RegisterAmount", DbType.Decimal, model.RegisterAmount); db.AddInParameter(dbCommand, "CutType", DbType.Int32, model.CutType); db.AddInParameter(dbCommand, "CurrencyTypeId", DbType.Int32, model.CurrencyTypeId); db.ExecuteNonQuery(dbCommand); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(XH_MelonCutRegisterTableInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into XH_MelonCutRegisterTable("); strSql.Append( "RegisterDate,CutDate,UserAccountDistributeLogo,TradeCurrencyType,Code,RegisterAmount,CutType,CurrencyTypeId)"); strSql.Append(" values ("); strSql.Append( "@RegisterDate,@CutDate,@UserAccountDistributeLogo,@TradeCurrencyType,@Code,@RegisterAmount,@CutType,@CurrencyTypeId)"); strSql.Append(";select @@IDENTITY"); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "RegisterDate", DbType.DateTime, model.RegisterDate); db.AddInParameter(dbCommand, "CutDate", DbType.DateTime, model.CutDate); db.AddInParameter(dbCommand, "UserAccountDistributeLogo", DbType.AnsiString, model.UserAccountDistributeLogo); db.AddInParameter(dbCommand, "TradeCurrencyType", DbType.Int32, model.TradeCurrencyType); db.AddInParameter(dbCommand, "Code", DbType.AnsiString, model.Code); db.AddInParameter(dbCommand, "RegisterAmount", DbType.Decimal, model.RegisterAmount); db.AddInParameter(dbCommand, "CutType", DbType.Int32, model.CutType); db.AddInParameter(dbCommand, "CurrencyTypeId", DbType.Int32, model.CurrencyTypeId); 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 void Delete(XH_MelonCutRegisterTableInfo model, Database db, DbTransaction transaction) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from XH_MelonCutRegisterTable "); strSql.Append(" where MelonCutRegisterID=@MelonCutRegisterID "); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "MelonCutRegisterID", DbType.Int32, model.MelonCutRegisterID); db.ExecuteNonQuery(dbCommand, transaction); }
/// <summary> /// 创建资金流水表的记录 /// </summary> /// <param name="registerTable">登记表实体</param> /// <param name="capitalAccount">资金账号</param> /// <param name="num">分红金额</param> /// <returns>资金流水表实体</returns> private static UA_CapitalFlowTableInfo GetFlowTable(XH_MelonCutRegisterTableInfo registerTable, string capitalAccount, decimal num) { UA_CapitalFlowTableInfo flowTable = new UA_CapitalFlowTableInfo(); flowTable.TradeCurrencyType = registerTable.TradeCurrencyType; flowTable.FromCapitalAccount = string.Empty; //因为数据库不能为null所以这里以空的字符串填充 //flowTable.ToCapitalAccount = registerTable.UserAccountDistributeLogo; flowTable.ToCapitalAccount = capitalAccount; flowTable.TransferAmount = num; flowTable.TransferTime = DateTime.Now; flowTable.TransferTypeLogo = (int)Types.TransferType.DividendTransfer; return(flowTable); }
/// <summary> /// 对象实体绑定数据 /// </summary> public XH_MelonCutRegisterTableInfo ReaderBind(IDataReader dataReader) { XH_MelonCutRegisterTableInfo model = new XH_MelonCutRegisterTableInfo(); object ojb; ojb = dataReader["MelonCutRegisterID"]; if (ojb != null && ojb != DBNull.Value) { model.MelonCutRegisterID = (int)ojb; } ojb = dataReader["RegisterDate"]; if (ojb != null && ojb != DBNull.Value) { model.RegisterDate = (DateTime)ojb; } ojb = dataReader["CutDate"]; if (ojb != null && ojb != DBNull.Value) { model.CutDate = (DateTime)ojb; } model.UserAccountDistributeLogo = dataReader["UserAccountDistributeLogo"].ToString(); ojb = dataReader["TradeCurrencyType"]; if (ojb != null && ojb != DBNull.Value) { model.TradeCurrencyType = (int)ojb; } model.Code = dataReader["Code"].ToString(); ojb = dataReader["RegisterAmount"]; if (ojb != null && ojb != DBNull.Value) { model.RegisterAmount = (decimal)ojb; } ojb = dataReader["CutType"]; if (ojb != null && ojb != DBNull.Value) { model.CutType = (int)ojb; } ojb = dataReader["CurrencyTypeId"]; if (ojb != null && ojb != DBNull.Value) { model.CurrencyTypeId = (int)ojb; } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public XH_MelonCutRegisterTableInfo GetModel(int MelonCutRegisterID) { StringBuilder strSql = new StringBuilder(); strSql.Append( "select MelonCutRegisterID,RegisterDate,CutDate,UserAccountDistributeLogo,TradeCurrencyType,Code,RegisterAmount,CutType,CurrencyTypeId from XH_MelonCutRegisterTable "); strSql.Append(" where MelonCutRegisterID=@MelonCutRegisterID "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "MelonCutRegisterID", DbType.Int32, MelonCutRegisterID); XH_MelonCutRegisterTableInfo model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }