/// <summary>
        /// 增加一条数据
        /// <param name="model"></param>
        /// </summary>
        public int Add(HK_CapitalAccountInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into HK_CapitalAccount(");
            strSql.Append("UserAccountDistributeLogo,TradeCurrencyType,AvailableCapital,BalanceOfTheDay,TodayOutInCapital,FreezeCapitalTotal,CapitalBalance,HasDoneProfitLossTotal)");

            strSql.Append(" values (");
            strSql.Append("@UserAccountDistributeLogo,@TradeCurrencyType,@AvailableCapital,@BalanceOfTheDay,@TodayOutInCapital,@FreezeCapitalTotal,@CapitalBalance,@HasDoneProfitLossTotal)");
            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, "TradeCurrencyType", DbType.Int32, model.TradeCurrencyType);
            db.AddInParameter(dbCommand, "AvailableCapital", DbType.Decimal, model.AvailableCapital);
            db.AddInParameter(dbCommand, "BalanceOfTheDay", DbType.Decimal, model.BalanceOfTheDay);
            db.AddInParameter(dbCommand, "TodayOutInCapital", DbType.Decimal, model.TodayOutInCapital);
            db.AddInParameter(dbCommand, "FreezeCapitalTotal", DbType.Decimal, model.FreezeCapitalTotal);
            db.AddInParameter(dbCommand, "CapitalBalance", DbType.Decimal, model.CapitalBalance);
            db.AddInParameter(dbCommand, "HasDoneProfitLossTotal", DbType.Decimal, model.HasDoneProfitLossTotal);
            int    result;
            object obj = db.ExecuteScalar(dbCommand);

            if (!int.TryParse(obj.ToString(), out result))
            {
                return(0);
            }
            return(result);
        }
        /// <summary>
        /// 初始化港股资金账户
        /// </summary>
        /// <param name="account">账户实体对象</param>
        /// <param name="outMessage"></param>
        /// <param name="db"></param>
        /// <param name="tm">开启事务对象,如果为null不开启事务</param>
        public void InitializationHKCapitalAccount(AccountEntity account, out string outMessage, Database db, DbTransaction tm)
        {
            outMessage = string.Empty;
            if (account == null)
            {
                outMessage = "现货资金账户对象为空!";
                return;
            }

            HK_CapitalAccountDal  dal   = new HK_CapitalAccountDal();
            HK_CapitalAccountInfo model = new HK_CapitalAccountInfo();

            model.AvailableCapital          = 0;
            model.BalanceOfTheDay           = 0;
            model.FreezeCapitalTotal        = 0;
            model.TodayOutInCapital         = 0;
            model.UserAccountDistributeLogo = account.Account;
            model.CapitalBalance            = 0;
            model.TradeCurrencyType         = (int)GTA.VTS.Common.CommonObject.Types.CurrencyType.RMB;
            dal.Add(model, db, tm);
            model.TradeCurrencyType = (int)GTA.VTS.Common.CommonObject.Types.CurrencyType.HK;
            dal.Add(model, db, tm);
            model.TradeCurrencyType = (int)GTA.VTS.Common.CommonObject.Types.CurrencyType.US;
            dal.Add(model, db, tm);
        }
        /// <summary>
        /// 开启事务更新数据
        /// Create BY:李健华
        /// Create date:2009-07-16
        /// </summary>
        /// <param name="model">要更新的实体</param>
        /// <param name="db"></param>
        /// <param name="trm">如果为null不开启事务</param>
        public void Update(HK_CapitalAccountInfo model, Database db, DbTransaction trm)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update HK_CapitalAccount set ");
            strSql.Append("UserAccountDistributeLogo=@UserAccountDistributeLogo,");
            strSql.Append("TradeCurrencyType=@TradeCurrencyType,");
            strSql.Append("AvailableCapital=@AvailableCapital,");
            strSql.Append("BalanceOfTheDay=@BalanceOfTheDay,");
            strSql.Append("TodayOutInCapital=@TodayOutInCapital,");
            strSql.Append("FreezeCapitalTotal=@FreezeCapitalTotal,");
            //strSql.Append("CapitalBalance=@CapitalBalance,");
            strSql.Append("HasDoneProfitLossTotal=@HasDoneProfitLossTotal");
            strSql.Append(" where CapitalAccountLogo=@CapitalAccountLogo ");
            //Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "CapitalAccountLogo", DbType.Int32, model.CapitalAccountLogo);
            db.AddInParameter(dbCommand, "UserAccountDistributeLogo", DbType.AnsiString, model.UserAccountDistributeLogo);
            db.AddInParameter(dbCommand, "TradeCurrencyType", DbType.Int32, model.TradeCurrencyType);
            db.AddInParameter(dbCommand, "AvailableCapital", DbType.Decimal, model.AvailableCapital);
            db.AddInParameter(dbCommand, "BalanceOfTheDay", DbType.Decimal, model.BalanceOfTheDay);
            db.AddInParameter(dbCommand, "TodayOutInCapital", DbType.Decimal, model.TodayOutInCapital);
            db.AddInParameter(dbCommand, "FreezeCapitalTotal", DbType.Decimal, model.FreezeCapitalTotal);
            // db.AddInParameter(dbCommand, "CapitalBalance", DbType.Decimal, model.CapitalBalance);
            db.AddInParameter(dbCommand, "HasDoneProfitLossTotal", DbType.Decimal, model.HasDoneProfitLossTotal);
            if (trm != null)
            {
                db.ExecuteNonQuery(dbCommand, trm);
            }
            else
            {
                db.ExecuteNonQuery(dbCommand);
            }
        }
 /// <summary>
 /// 构造函数重载
 /// </summary>
 /// <param name="gTCapitalObj">港股资金账号信息实体</param>
 /// <param name="dMarketValue">现所有持仓总市值</param>
 /// <param name="currencyName">当前交易货币类型</param>
 /// <param name="notDoneProfitLossTotal">未实现盈亏</param>
 public HKCapitalEntity(HK_CapitalAccountInfo gTCapitalObj, decimal dMarketValue, string currencyName, decimal notDoneProfitLossTotal)
 {
     GTCapitalObj           = gTCapitalObj;
     MarketValue            = dMarketValue;
     AssetAmount            = MarketValue + GTCapitalObj.CapitalBalance;
     NotDoneProfitLossTotal = notDoneProfitLossTotal;
     ProfitLossTotal        = gTCapitalObj.HasDoneProfitLossTotal + notDoneProfitLossTotal;
     CurrencyName           = currencyName;
 }
        /// <summary>
        /// 对象实体绑定数据
        /// <param name="dataReader"></param>
        /// </summary>
        public HK_CapitalAccountInfo ReaderBind(IDataReader dataReader)
        {
            HK_CapitalAccountInfo model = new HK_CapitalAccountInfo();
            object ojb;

            ojb = dataReader["CapitalAccountLogo"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CapitalAccountLogo = (int)ojb;
            }
            model.UserAccountDistributeLogo = dataReader["UserAccountDistributeLogo"].ToString();
            ojb = dataReader["TradeCurrencyType"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.TradeCurrencyType = (int)ojb;
            }
            ojb = dataReader["AvailableCapital"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AvailableCapital = (decimal)ojb;
            }
            ojb = dataReader["BalanceOfTheDay"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BalanceOfTheDay = (decimal)ojb;
            }
            ojb = dataReader["TodayOutInCapital"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.TodayOutInCapital = (decimal)ojb;
            }
            ojb = dataReader["FreezeCapitalTotal"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.FreezeCapitalTotal = (decimal)ojb;
            }
            ojb = dataReader["CapitalBalance"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CapitalBalance = (decimal)ojb;
            }
            ojb = dataReader["HasDoneProfitLossTotal"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.HasDoneProfitLossTotal = (decimal)ojb;
            }
            return(model);
        }
Ejemplo n.º 6
0
        private bool CapitalCheck(HK_CapitalAccountInfo capital, HK_CapitalAccount_DeltaInfo change)
        {
            //只有买时才检查
            if (Request.BuySell == Types.TransactionDirection.Buying)
            {
                if (capital.AvailableCapital <= 0)
                {
                    return(false);
                }

                return(capital.AvailableCapital + change.AvailableCapitalDelta >= 0);
            }

            //卖时只要成交额大于费用即可,前面已经检查过,此处不再检查
            return(true);
        }
        /// <summary>
        /// 得到一个对象实体
        /// <param name="CapitalAccountLogo"></param>
        /// </summary>
        public HK_CapitalAccountInfo GetModel(int CapitalAccountLogo)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select CapitalAccountLogo,UserAccountDistributeLogo,TradeCurrencyType,AvailableCapital,BalanceOfTheDay,TodayOutInCapital,FreezeCapitalTotal,CapitalBalance,HasDoneProfitLossTotal from HK_CapitalAccount ");
            strSql.Append(" where CapitalAccountLogo=@CapitalAccountLogo ");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "CapitalAccountLogo", DbType.Int32, CapitalAccountLogo);
            HK_CapitalAccountInfo model = null;

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return(model);
        }
        /// <summary>
        /// 更新一条数据
        /// Update BY:李健华
        /// Update date:2009-10-20
        /// Desc.:更改重载是否开启事务操作,本方法调用是否开启事务方法,此为默认不开启事务
        /// </summary>
        public void Update(HK_CapitalAccountInfo model)
        {
            Database db = DatabaseFactory.CreateDatabase();

            Update(model, db, null);
        }