Esempio n. 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool AddRecord(HK_AccountHoldInfo model, ReckoningTransaction tm)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into HK_AccountHold (");
            strSql.Append("AvailableAmount,FreezeAmount,UserAccountDistributeLogo,");
            strSql.Append(" CostPrice,Code,BreakevenPrice,CurrencyTypeId,HoldAveragePrice)");
            strSql.Append(" values (");
            strSql.Append("@AvailableAmount,@FreezeAmount,@UserAccountDistributeLogo,");
            strSql.Append(" @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);
        }
Esempio n. 2
0
        /// <summary>
        /// 得到一个对象实体
        /// <param name="strHoldAccount"></param>
        /// <param name="iCurrType"></param>
        /// <param name="strCode"></param>
        /// </summary>
        public HK_AccountHoldInfo GetHKAccountHoldInfo(string strHoldAccount, string strCode, int iCurrType)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select AccountHoldLogoId,UserAccountDistributeLogo,CurrencyTypeId,Code,AvailableAmount,FreezeAmount,CostPrice,BreakevenPrice,HoldAveragePrice from HK_AccountHold ");

            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);
            HK_AccountHoldInfo model = null;

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return(model);
        }
Esempio n. 3
0
        /// <summary>
        /// 增加一条数据
        /// <param name="model"></param>
        /// </summary>
        public int Add(HK_AccountHoldInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into HK_AccountHold(");
            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);
        }
Esempio n. 4
0
        /// <summary>
        /// 更新一条数据
        /// <param name="model"></param>
        /// </summary>
        public void Update(HK_AccountHoldInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update HK_AccountHold 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);
        }
Esempio n. 5
0
        /// <summary>
        /// 带事物更新数据
        /// </summary>
        /// <param name="model">实体</param>
        /// <param name="db">Database</param>
        /// <param name="transaction">DbTransaction</param>
        public bool UpdateRecord(HK_AccountHoldInfo model, Database db, DbTransaction transaction)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update HK_AccountHold 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);
            }
        }
Esempio n. 6
0
        private bool HodingCheck(HK_AccountHoldInfo hold, HK_AccountHoldInfo_Delta change)
        {
            string strMessage = "";
            bool   result     = false;

            if (Request.BuySell == Types.TransactionDirection.Buying)
            {
                strMessage = "GT-2419:[港股委托持久化]买持仓检查,超过持仓限制";
                int     position     = 0;
                decimal freezeAmount = 0;

                position     = Convert.ToInt32(hold.AvailableAmount);
                freezeAmount = hold.FreezeAmount;

                if (ValidateCenter.ValidateHKMinVolumeOfBusiness(Request, position, ref strMessage))
                {
                    //获取持仓限制
                    Decimal pLimit = MCService.GetPositionLimit(Request.Code, Types.BreedClassTypeEnum.HKStock).PositionValue;
                    //可用持仓+冻结量+委托量<持仓限制
                    result = pLimit >= position + freezeAmount + Convert.ToDecimal(Request.OrderAmount);
                }
            }
            else
            {
                strMessage = "GT-2420:[港股委托持久化]卖持仓检查,无持仓";

                if (hold != null)
                {
                    strMessage = "GT-2421:[港股委托持久化]卖持仓检查,无足够可用持仓";
                    int position = Convert.ToInt32(hold.AvailableAmount);
                    //持仓帐户是否存在判断
                    if (ValidateCenter.ValidateHKMinVolumeOfBusiness(Request, position, ref strMessage))
                    {
                        //已经统一使用撮合单位了
                        decimal orderAmount = Convert.ToDecimal(Request.OrderAmount); // *unitMultiple;
                        //可用持仓>=委托量
                        result = hold.AvailableAmount >= orderAmount;
                    }
                }
            }

            if (result)
            {
                strMessage = "";
            }
            else
            {
                holdMessage = strMessage;
            }

            return(result);
        }
Esempio n. 7
0
        /// <summary>
        /// 对象实体绑定数据
        /// <param name="dataReader"></param>
        /// </summary>
        public HK_AccountHoldInfo ReaderBind(IDataReader dataReader)
        {
            HK_AccountHoldInfo model = new HK_AccountHoldInfo();
            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);
        }
Esempio n. 8
0
        /// <summary>
        /// 得到一个对象实体
        /// <param name="AccountHoldLogoID"></param>
        /// </summary>
        public HK_AccountHoldInfo GetModel(int AccountHoldLogoID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select AccountHoldLogoId,UserAccountDistributeLogo,CurrencyTypeId,Code,AvailableAmount,FreezeAmount,CostPrice,BreakevenPrice,HoldAveragePrice from HK_AccountHold ");

            strSql.Append(" where AccountHoldLogoId=@AccountHoldLogoId ");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "AccountHoldLogoId", DbType.Int32, AccountHoldLogoID);
            HK_AccountHoldInfo model = null;

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return(model);
        }