/// <summary>
        /// 现货持仓冻结处理
        /// </summary>
        /// <param name="tm"></param>
        /// <returns></returns>
        private int PO_BuildHoldFreezeRecord(ReckoningTransaction tm)
        {
            LogHelper.WriteDebug("现货持仓冻结处理XHSellOrderLogicFlow.PO_ProcessXhHoldingAccountFreeze");

            var ahft = new XH_AcccountHoldFreezeTableInfo();

            //现货持仓帐户标识
            ahft.AccountHoldLogo = HoldingAccountId;
            //委托单号
            ahft.EntrustNumber = EntrustNumber;
            //冻结时间
            ahft.FreezeTime = DateTime.Now;
            //解冻时间
            ahft.ThawTime = DateTime.Now;
            //冻结数量
            //decimal unitMultiple = MCService.GetTradeUnitScale(stockorder.Code, stockorder.OrderUnitType);
            decimal orderAmount = Convert.ToDecimal(Request.OrderAmount); // *unitMultiple;

            ahft.PrepareFreezeAmount = Convert.ToInt32(orderAmount);
            //冻结类型
            ahft.FreezeTypeLogo = (int)Types.FreezeType.DelegateFreeze;

            //string format = "现货持仓冻结处理[委托单号={0},冻结总量={1},冻结时间={2},解冻时间={3},冻结类型={4},现货帐户持仓标识={5},]";
            //string desc = string.Format(format, ahft.EntrustNumber, ahft.PrepareFreezeAmount, ahft.FreezeTime,
            //                            ahft.ThawTime, ahft.FreezeTypeLogo, ahft.HoldFreezeLogoId);
            //LogHelper.WriteDebug(desc);

            XH_AcccountHoldFreezeTableDal dal = new XH_AcccountHoldFreezeTableDal();

            return(dal.Add(ahft, tm.Database, tm.Transaction));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 港股持仓冻结处理
        /// </summary>
        /// <param name="tm"></param>
        /// <returns></returns>
        private int PO_BuildHoldFreezeRecord(ReckoningTransaction tm)
        {
            LogHelper.WriteDebug("港股持仓冻结处理XHSellOrderLogicFlow.PO_ProcessXhHoldingAccountFreeze");

            HK_AcccountHoldFreezeInfo hahf = new HK_AcccountHoldFreezeInfo();

            hahf.AccountHoldLogo = HoldingAccountId; //港股持仓帐户标识
            hahf.EntrustNumber   = EntrustNumber;    //委托单号
            hahf.FreezeTime      = DateTime.Now;     //冻结时间
            hahf.ThawTime        = DateTime.Now;     //解冻时间

            //decimal unitMultiple = MCService.GetTradeUnitScale(stockorder.Code, stockorder.OrderUnitType);
            decimal orderAmount = Convert.ToDecimal(Request.OrderAmount);                    // *unitMultiple;

            hahf.PrepareFreezeAmount = Convert.ToInt32(orderAmount);                         //冻结数量
            hahf.FreezeTypeID        = (int)Entity.Contants.Types.FreezeType.DelegateFreeze; //冻结类型


            HK_AcccountHoldFreezeDal dal = new HK_AcccountHoldFreezeDal();

            try
            {
                return(dal.Add(hahf, tm.Database, tm.Transaction));
            }
            catch (Exception ex)
            {
                string txt = "AccountHoldLogo={0},EntrustNumber={1},FreezeTime={2},ThawTime={3},PrepareFreezeAmount={4},FreezeTypeID={5}";
                txt = string.Format(txt, hahf.AccountHoldLogo, hahf.EntrustNumber, hahf.FreezeTime, hahf.ThawTime, hahf.PrepareFreezeAmount, hahf.FreezeTypeID);
                LogHelper.WriteDebug("港股持仓冻结处理实体内容" + txt);
                throw ex;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(HK_CapitalAccountFreezeInfo model, ReckoningTransaction tm)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update HK_CapitalAccountFreeze set ");
            strSql.Append("FreezeTime=@FreezeTime,");
            strSql.Append("FreezeCapitalAmount=@FreezeCapitalAmount,");
            strSql.Append("ThawTime=@ThawTime,");
            strSql.Append("FreezeTypeLogo=@FreezeTypeLogo,");
            strSql.Append("EntrustNumber=@EntrustNumber,");
            strSql.Append("CapitalAccountLogo=@CapitalAccountLogo,");
            strSql.Append("OweCosting=@OweCosting,");
            strSql.Append("FreezeCost=@FreezeCost");
            strSql.Append(" where CapitalFreezeLogoId=@CapitalFreezeLogoId ");
            Database  db        = tm.Database;
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "FreezeTime", DbType.DateTime, model.FreezeTime);
            db.AddInParameter(dbCommand, "FreezeCapitalAmount", DbType.Decimal, model.FreezeCapitalAmount);
            db.AddInParameter(dbCommand, "CapitalFreezeLogoId", DbType.Int32, model.CapitalFreezeLogoId);
            db.AddInParameter(dbCommand, "ThawTime", DbType.DateTime, model.ThawTime);
            db.AddInParameter(dbCommand, "FreezeTypeLogo", DbType.Int32, model.FreezeTypeLogo);
            db.AddInParameter(dbCommand, "EntrustNumber", DbType.AnsiString, model.EntrustNumber);
            db.AddInParameter(dbCommand, "CapitalAccountLogo", DbType.Int32, model.CapitalAccountLogo);
            db.AddInParameter(dbCommand, "OweCosting", DbType.Decimal, model.OweCosting);
            db.AddInParameter(dbCommand, "FreezeCost", DbType.Decimal, model.FreezeCost);
            db.ExecuteNonQuery(dbCommand, tm.Transaction);
        }
Exemplo n.º 4
0
        ///// <summary>
        ///// 进行股票分红
        ///// </summary>
        ///// <param name="list">分红列表</param>
        //private static void CutStockList(IList<CM_StockMelonStock> list)
        //{
        //    //选出今日需要分红的股票分红信息
        //    var q = from c in list
        //            where
        //                CheckDate(c.StockRightLogoutDatumDate) && c.StockRightRegisterDate.HasValue &&
        //                c.SentStockRatio.HasValue
        //            select c;

        //    foreach (CM_StockMelonStock cash in q)
        //    {
        //        //update 李健华 2010-1-15 这里是股票分红 不是现金分红Types.MeloncutType.Cash);
        //        List<XH_MelonCutRegisterTableInfo> tables = GetMeloncutRegisterList(cash.CommodityCode,
        //                                                                            cash.StockRightRegisterDate.Value,
        //                                                                            cash.StockRightLogoutDatumDate.Value,
        //                                                                            Types.MeloncutType.Stock);
        //        //==============================

        //        ProcessStockCut(cash, tables);
        //    }
        //}

        /// <summary>
        /// 对某一个股票进行分红(过户)
        /// </summary>
        /// <param name="cash">分红信息</param>
        /// <param name="tables">登记列表</param>
        private static bool ProcessStockCut(List <XH_MelonCutRegisterTableInfo> tables)
        {
            bool isSuss = true;

            if (Utils.IsNullOrEmpty(tables))
            {
                return(isSuss);
            }

            //TransactionManager tm = TransactionFactory.GetTransactionManager();
            //tm.BeginTransaction();
            ReckoningTransaction reckoningTransaction = new ReckoningTransaction();
            Database             database             = DatabaseFactory.CreateDatabase();
            DbConnection         connection           = database.CreateConnection();

            try
            {
                connection.Open();
                reckoningTransaction.Database = database;
                DbTransaction transaction = connection.BeginTransaction();
                reckoningTransaction.Transaction = transaction;
                isSuss = UpdateStockCut(reckoningTransaction, tables);
                reckoningTransaction.Transaction.Commit();
            }
            catch (Exception ex)
            {
                LogHelper.WriteError("", ex);
                reckoningTransaction.Transaction.Rollback();
                isSuss = false;
            }
            return(isSuss);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 更新现货持仓
        /// </summary>
        /// <param name="cAvaliable"></param>
        /// <param name="cFreeeze"></param>
        /// <param name="transactionManager"></param>
        /// <param name="holdAccountId"></param>
        /// <returns></returns>
        public static bool UpdateXHHoldAccount(decimal cAvaliable, decimal cFreeeze,
                                               ReckoningTransaction transactionManager, int holdAccountId)
        {
            int results = 0;

            string strSql = string.Empty;

            //var database = new SqlDatabase(TransactionFactory.RC_ConnectionString);
            var database = DataManager.GetDatabase();

            strSql = "UPDATE [XH_AccountHoldTable] SET [AvailableAmount] = [AvailableAmount] + @AvailableHold"
                     + ",[FreezeAmount] = [FreezeAmount] + @FreezeHold"
                     + "WHERE [AccountHoldLogoId] = @holdAccountId";


            DbCommand commandWrapper = GetDBCommand(database, strSql);

            database.AddInParameter(commandWrapper, "@AvailableHold", DbType.Decimal, cAvaliable);
            database.AddInParameter(commandWrapper, "@holdAccountId", DbType.Int32, holdAccountId);
            database.AddInParameter(commandWrapper, "@FreezeHold", DbType.Decimal, cFreeeze);

            if (transactionManager != null)
            {
                results = DbHelperSQL.ExecuteCountSql(strSql, transactionManager);
            }
            else
            {
                results = DbHelperSQL.ExecuteCountSql(strSql);
            }

            return(Convert.ToBoolean(results));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 执行带事务sql语句
        /// </summary>
        /// <param name="strSql">sql语句</param>
        /// <param name="tm">事务对象</param>
        /// <returns></returns>
        public static bool XHCapitalAccountProcess(string strSql,
                                                   ReckoningTransaction tm)
        {
            bool result = false;

            try
            {
                if (tm != null)
                {
                    DbHelperSQL.ExecuteSql(strSql, tm);
                }
                else
                {
                    DbHelperSQL.ExecuteSql(strSql);
                }

                result = true;
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex.Message, ex);
            }

            return(result);
        }
Exemplo n.º 7
0
        //更新数据库中的分红日期
        public static void UpdateMelonCutDate()
        {
            ReckoningTransaction reckoningTransaction = new ReckoningTransaction();
            Database             database             = DatabaseFactory.CreateDatabase();
            DbConnection         connection           = database.CreateConnection();

            //TransactionManager tm = TransactionFactory.GetTransactionManager();
            //tm.BeginTransaction();

            try
            {
                connection.Open();
                reckoningTransaction.Database = database;
                DbTransaction transaction = connection.BeginTransaction();
                reckoningTransaction.Transaction = transaction;

                DoUpdate(MelonCutDate, reckoningTransaction);
                reckoningTransaction.Transaction.Commit();
            }
            catch (Exception ex)
            {
                LogHelper.WriteError("UpdateMelonCutDate", ex);
                reckoningTransaction.Transaction.Rollback();
            }
            finally
            {
                if (connection != null && connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 带事务更新
        /// </summary>
        /// <param name="baseTable"></param>
        /// <param name="db"></param>
        /// <param name="transaction"></param>
        public void PersistBase(QH_HoldAccountTableInfo baseTable, Database db, DbTransaction transaction)
        {
            QH_HoldAccountTableDal dal = new QH_HoldAccountTableDal();
            ReckoningTransaction   tm  = new ReckoningTransaction();

            tm.Database    = db;
            tm.Transaction = transaction;
            dal.Update(baseTable, tm);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 带事务更新
        /// </summary>
        /// <param name="delta"></param>
        /// <param name="db"></param>
        /// <param name="transaction"></param>
        public void PersistChangeWithTransaction(QH_HoldAccountTableInfo_Delta delta, Database db, DbTransaction transaction)
        {
            QH_HoldAccountTableDal dal = new QH_HoldAccountTableDal();
            ReckoningTransaction   tm  = new ReckoningTransaction();

            tm.Database    = db;
            tm.Transaction = transaction;

            dal.AddUpdate(delta, tm);
        }
        /// <summary>
        /// 依据港股委托单号获取委托单对象
        /// </summary>
        /// <param name="strEntrustId"></param>
        /// <param name="tm"></param>
        /// <returns></returns>
        public static HK_TodayEntrustInfo GetHKEntrustEntity(string strEntrustId, ReckoningTransaction tm)
        {
            HK_TodayEntrustInfo result = null;

            HK_TodayEntrustDal hkTodayEntrustDal = new HK_TodayEntrustDal();


            result = hkTodayEntrustDal.GetModel(strEntrustId);//TODO:trans

            return(result);
        }
        /// <summary>
        /// 执行存储过程
        /// </summary>
        /// <param name="capitalFreezeLogoId">资金冻结Id</param>
        /// <param name="reckoningTransaction">事务封装对象</param>
        public void Delete(int capitalFreezeLogoId, ReckoningTransaction reckoningTransaction)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("delete from HK_CapitalAccountFreeze ");
            strSql.Append(" where CapitalFreezeLogoId=@CapitalFreezeLogoId ");
            Database  db        = reckoningTransaction.Database;
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "CapitalFreezeLogoId", DbType.Int32, capitalFreezeLogoId);
            db.ExecuteNonQuery(dbCommand, reckoningTransaction.Transaction);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 更新委托表
        /// </summary>
        /// <param name="tet">委托表</param>
        /// <param name="rt">事务包装类</param>
        /// <returns>是否成功</returns>
        public static bool UpdateEntrustTable(QH_TodayEntrustTableInfo tet, ReckoningTransaction rt)
        {
            try
            {
                QH_TodayEntrustTableDal dal = new QH_TodayEntrustTableDal();
                dal.Update(tet, rt);
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex.Message, ex);
                return(false);
            }

            return(true);
        }
Exemplo n.º 13
0
 /// <summary>
 /// 增加期货成交资金流水记录
 /// </summary>
 /// <param name="tet"></param>
 /// <param name="rt"></param>
 /// <returns></returns>
 public static bool AddQH_CapitalFlow(QH_TradeCapitalFlowDetailInfo tet, ReckoningTransaction rt)
 {
     try
     {
         QH_TradeCapitalFlowDetailDal dal = new QH_TradeCapitalFlowDetailDal();
         tet.CreateDateTime = DateTime.Now;
         dal.Add(tet, rt);
     }
     catch (Exception ex)
     {
         LogHelper.WriteError(ex.Message, ex);
         return(false);
     }
     return(true);
 }
Exemplo n.º 14
0
        ///// <summary>
        ///// 进行现金分红
        ///// </summary>
        ///// <param name="list">分红列表</param>
        //private static bool CutCashList(IList<CM_StockMelonCash> list)
        //{
        //    //选出今日需要分红的股票分红信息
        //    var q = from c in list
        //            where
        //                CheckDate(c.StockRightLogoutDatumDate) && c.StockRightRegisterDate.HasValue &&
        //                c.RatioOfCashDividend.HasValue
        //            select c;

        //    foreach (CM_StockMelonCash cash in q)
        //    {
        //        List<XH_MelonCutRegisterTableInfo> tables = GetMeloncutRegisterList(cash.CommodityCode,
        //                                                                            cash.StockRightRegisterDate.Value,
        //                                                                            cash.StockRightLogoutDatumDate.Value,
        //                                                                            Types.MeloncutType.Cash);
        //        ProcessCashCut(cash, tables);
        //    }

        //    return true;
        //}

        /// <summary>
        /// 对某一个股票进行现金分红
        /// </summary>
        /// <param name="cash">分红信息</param>
        /// <param name="tables">登记列表</param>
        //private static void ProcessCashCut(CM_StockMelonCash cash, List<XH_MelonCutRegisterTableInfo> tables)
        private static bool ProcessCashCut(IList <XH_MelonCutRegisterTableInfo> tables)
        {
            bool isSuss = true;

            if (Utils.IsNullOrEmpty(tables))
            {
                return(isSuss);
            }

            //TransactionManager tm = TransactionFactory.GetTransactionManager();
            //tm.BeginTransaction();
            ReckoningTransaction reckoningTransaction = new ReckoningTransaction();
            Database             database             = DatabaseFactory.CreateDatabase();
            DbConnection         connection           = database.CreateConnection();
            List <XH_CapitalAccountTableInfo> list    = new List <XH_CapitalAccountTableInfo>();

            try
            {
                connection.Open();
                reckoningTransaction.Database = database;
                DbTransaction transaction = connection.BeginTransaction();
                reckoningTransaction.Transaction = transaction;

                isSuss = UpdateCashCut(reckoningTransaction, tables);
                reckoningTransaction.Transaction.Commit();
            }
            catch (Exception ex)
            {
                LogHelper.WriteError("", ex);
                reckoningTransaction.Transaction.Rollback();
                isSuss = false;
            }
            finally
            {
                //这里为了安全起见,自行执行一次关闭数据连接
                if (reckoningTransaction != null && reckoningTransaction.Transaction != null)
                {
                    reckoningTransaction.Transaction.Dispose();
                }
                if (connection != null && connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
            }

            return(isSuss);
        }
        public void DeleteEntityList(List <string> ids, ReckoningTransaction trans)
        {
            if (Utils.IsNullOrEmpty(ids))
            {
                return;
            }
            //陈武民修改 修改时间 2009年07月09日
            // TransactionManager tm = TransactionFactory.GetTransactionManager();
            //tm.BeginTransaction();

            try
            {
                // DataRepository.BdUnReckonedDealTableProvider.Delete(tm, id);
                // tm.Commit();
                BD_UnReckonedDealTableDal dal = new BD_UnReckonedDealTableDal();



                //lock (((ICollection) hasSendSet).SyncRoot)
                //    hasSendSet.Remove(id);

                hasSendSetLock.EnterWriteLock();
                try
                {
                    foreach (var id in ids)
                    {
                        dal.Delete(id, trans.Database, trans.Transaction);
                        hasSendSet.Remove(id);
                        LogHelper.WriteDebug("$-------$CrashManger.DeleteEntity成交回报删除成功!ID=" + id);
                    }
                }
                finally
                {
                    hasSendSetLock.ExitWriteLock();
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteError("$-------$CrashManager.SaveEntity成交回报删除失败!", ex);
                //tm.Rollback();
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// 删除持仓冻结记录
        /// </summary>
        /// <param name="persistCapitalFreezeId">冻结记录id</param>
        /// <param name="db">数据库对象</param>
        /// <param name="transaction">事务对象</param>
        /// <returns></returns>
        public static bool DeleteCapitalFreeze(int persistCapitalFreezeId, Database db, DbTransaction transaction)
        {
            if (persistCapitalFreezeId != -1)
            {
                try
                {
                    XH_CapitalAccountFreezeTableDal caDal = new XH_CapitalAccountFreezeTableDal();

                    ReckoningTransaction tm = new ReckoningTransaction();
                    tm.Database    = db;
                    tm.Transaction = transaction;
                    caDal.Delete(persistCapitalFreezeId, tm);
                }
                catch (Exception ex)
                {
                    LogHelper.WriteError(ex.Message, ex);
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 更新现货持仓
        /// </summary>
        /// <param name="scale"></param>
        /// <param name="others"></param>
        /// <param name="dealAmount"></param>
        /// <param name="strHoldAccount"></param>
        /// <param name="strCode"></param>
        /// <param name="iCurrType"></param>
        /// <param name="transactionManager"></param>
        /// <returns></returns>
        public static bool UpdateXHHoldAccount_Sell(decimal scale,
                                                    decimal others,
                                                    decimal dealAmount,
                                                    string strHoldAccount,
                                                    string strCode,
                                                    int iCurrType, ReckoningTransaction transactionManager)
        {
            int results = 0;

            var database = DataManager.GetDatabase();

            //卖出不需要计算保本价
            string strSql = "UPDATE [XH_AccountHoldTable]"
                            + " SET [FreezeAmount] = [FreezeAmount] + @dealAmount"
                            //+ ",[BreakevenPrice] = ([CostPrice] + @others)/(1 - @scale)"
                            +
                            "WHERE UserAccountDistributeLogo = @strHoldAccount AND Code = @strCode AND CurrencyTypeId=@iCurrType";

            DbCommand commandWrapper = GetDBCommand(database, strSql);

            //database.AddInParameter(commandWrapper, "@scale", DbType.Decimal, scale);
            //database.AddInParameter(commandWrapper, "@others", DbType.Decimal, others);
            database.AddInParameter(commandWrapper, "@dealAmount", DbType.Decimal, dealAmount);
            database.AddInParameter(commandWrapper, "@strHoldAccount", DbType.String, strHoldAccount);
            database.AddInParameter(commandWrapper, "@strCode", DbType.String, strCode);
            database.AddInParameter(commandWrapper, "@iCurrType", DbType.Int32, iCurrType);
            //database.AddOutParameter(commandWrapper, "@iHoldAccountId", DbType.Int32, 4);
            if (transactionManager != null)
            {
                results = DbHelperSQL.ExecuteCountSql(strSql, transactionManager);
            }
            else
            {
                results = DbHelperSQL.ExecuteCountSql(strSql);
            }

            return(Convert.ToBoolean(results));
        }
Exemplo n.º 18
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(QH_TradeCapitalFlowDetailInfo model, ReckoningTransaction tm)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into QH_TradeCapitalFlowDetail(");
            strSql.Append("TradeID,UserCapitalAccount,FlowTypes,Margin,TradeProceduresFee,ProfitLoss,OtherCose,CurrencyType,CreateDateTime)");

            strSql.Append(" values (");
            strSql.Append("@TradeID,@UserCapitalAccount,@FlowTypes,@Margin,@TradeProceduresFee,@ProfitLoss,@OtherCose,@CurrencyType,@CreateDateTime)");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "TradeID", DbType.String, model.TradeID);
            db.AddInParameter(dbCommand, "UserCapitalAccount", DbType.AnsiString, model.UserCapitalAccount);
            db.AddInParameter(dbCommand, "FlowTypes", DbType.Int32, model.FlowTypes);
            db.AddInParameter(dbCommand, "Margin", DbType.Decimal, model.Margin);
            db.AddInParameter(dbCommand, "TradeProceduresFee", DbType.Decimal, model.TradeProceduresFee);
            db.AddInParameter(dbCommand, "ProfitLoss", DbType.Decimal, model.ProfitLoss);
            db.AddInParameter(dbCommand, "OtherCose", DbType.Decimal, model.OtherCose);
            db.AddInParameter(dbCommand, "CurrencyType", DbType.Int32, model.CurrencyType);
            //db.AddInParameter(dbCommand, "FlowTotal", DbType.Decimal, model.FlowTotal);
            db.AddInParameter(dbCommand, "CreateDateTime", DbType.DateTime, model.CreateDateTime);
            db.ExecuteNonQuery(dbCommand, tm.Transaction);
        }
Exemplo n.º 19
0
        /// <summary>
        /// 更新当前日期到数据库状态表中
        /// </summary>
        /// <param name="name"></param>
        /// <param name="tm"></param>
        private static void DoUpdate(string name, ReckoningTransaction tm)
        {
            BD_StatusTableDal  dal         = new BD_StatusTableDal();
            BD_StatusTableInfo statusTable = dal.GetModel(name);

            if (statusTable != null)
            {
                if (tm == null)
                {
                    dal.Delete(name);
                }
                else
                {
                    dal.Delete(name, tm);
                }
            }


            statusTable       = new BD_StatusTableInfo();
            statusTable.name  = name;
            statusTable.value = DateTime.Now.ToString();

            if (tm != null)
            {
                dal.Add(statusTable, tm.Database, tm.Transaction);
            }
            else
            {
                dal.Add(statusTable);
            }

            string format = "更新系统状态表[Name={0},Date={1}]";
            string desc   = string.Format(format, name, statusTable.value);

            LogHelper.WriteInfo(desc);
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(HK_TodayTradeInfo model, ReckoningTransaction tm)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into HK_TodayTrade(");
            strSql.Append("TradeNumber,PortfolioLogo,EntrustNumber,TradePrice,TradeAmount,EntrustPrice,StampTax,Commission,TransferAccountFee,TradeProceduresFee,MonitoringFee,TradingSystemUseFee,TradeCapitalAmount,ClearingFee,HoldAccount,CapitalAccount,Code,TradeTypeId,TradeUnitId,BuySellTypeId,CurrencyTypeId,TradeTime)");

            strSql.Append(" values (");
            strSql.Append("@TradeNumber,@PortfolioLogo,@EntrustNumber,@TradePrice,@TradeAmount,@EntrustPrice,@StampTax,@Commission,@TransferAccountFee,@TradeProceduresFee,@MonitoringFee,@TradingSystemUseFee,@TradeCapitalAmount,@ClearingFee,@HoldAccount,@CapitalAccount,@Code,@TradeTypeId,@TradeUnitId,@BuySellTypeId,@CurrencyTypeId,@TradeTime)");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "TradeNumber", DbType.AnsiString, model.TradeNumber);
            db.AddInParameter(dbCommand, "PortfolioLogo", DbType.AnsiString, model.PortfolioLogo);
            db.AddInParameter(dbCommand, "EntrustNumber", DbType.AnsiString, model.EntrustNumber);
            db.AddInParameter(dbCommand, "TradePrice", DbType.Decimal, model.TradePrice);
            db.AddInParameter(dbCommand, "TradeAmount", DbType.Int32, model.TradeAmount);
            db.AddInParameter(dbCommand, "EntrustPrice", DbType.Decimal, model.EntrustPrice);
            db.AddInParameter(dbCommand, "StampTax", DbType.Decimal, model.StampTax);
            db.AddInParameter(dbCommand, "Commission", DbType.Decimal, model.Commission);
            db.AddInParameter(dbCommand, "TransferAccountFee", DbType.Decimal, model.TransferAccountFee);
            db.AddInParameter(dbCommand, "TradeProceduresFee", DbType.Decimal, model.TradeProceduresFee);
            db.AddInParameter(dbCommand, "MonitoringFee", DbType.Decimal, model.MonitoringFee);
            db.AddInParameter(dbCommand, "TradingSystemUseFee", DbType.Decimal, model.TradingSystemUseFee);
            db.AddInParameter(dbCommand, "TradeCapitalAmount", DbType.Decimal, model.TradeCapitalAmount);
            db.AddInParameter(dbCommand, "ClearingFee", DbType.Decimal, model.ClearingFee);
            db.AddInParameter(dbCommand, "HoldAccount", DbType.AnsiString, model.HoldAccount);
            db.AddInParameter(dbCommand, "CapitalAccount", DbType.AnsiString, model.CapitalAccount);
            db.AddInParameter(dbCommand, "Code", DbType.AnsiString, model.Code);
            db.AddInParameter(dbCommand, "TradeTypeId", DbType.Int32, model.TradeTypeId);
            db.AddInParameter(dbCommand, "TradeUnitId", DbType.Int32, model.TradeUnitId);
            db.AddInParameter(dbCommand, "BuySellTypeId", DbType.Int32, model.BuySellTypeId);
            db.AddInParameter(dbCommand, "CurrencyTypeId", DbType.Int32, model.CurrencyTypeId);
            db.AddInParameter(dbCommand, "TradeTime", DbType.DateTime, model.TradeTime);
            db.ExecuteNonQuery(dbCommand, tm.Transaction);
        }
Exemplo n.º 21
0
 /// <summary>
 /// 更新数据库中港股清算日期
 /// </summary>
 public static void UpdateHKReckoningDate(ReckoningTransaction tm)
 {
     DoUpdate(HKReckoningDate, tm);
 }
Exemplo n.º 22
0
 /// <summary>
 /// 更新数据库中现货清算日期
 /// </summary>
 public static void UpdateRegistMelonCutDate(ReckoningTransaction tm)
 {
     DoUpdate(RegistMelonCutDate, tm);
 }
        /// <summary>
        /// 依据期货委托单号获取委托单实体
        /// </summary>
        /// <param name="strEntrustId"></param>
        /// <param name="tm"></param>
        /// <returns></returns>
        public static QH_TodayEntrustTableInfo GetQHEntrustEntity(string strEntrustId, ReckoningTransaction tm)
        {
            QH_TodayEntrustTableInfo result = null;

            QH_TodayEntrustTableDal qhtodayEntrustTabledDal = new QH_TodayEntrustTableDal();

            result = qhtodayEntrustTabledDal.GetModel(strEntrustId);

            return(result);
        }
        /// <summary>
        /// 依据现货委托单号获取委托单对象
        /// </summary>
        /// <param name="strEntrustId"></param>
        /// <param name="tm"></param>
        /// <returns></returns>
        public static XH_TodayEntrustTableInfo GetXHEntrustEntity(string strEntrustId, ReckoningTransaction tm)
        {
            XH_TodayEntrustTableInfo result = null;

            XH_TodayEntrustTableDal xh_TodayEntrustTableDal = new XH_TodayEntrustTableDal();


            result = xh_TodayEntrustTableDal.GetModel(strEntrustId, tm);

            return(result);
        }
Exemplo n.º 25
0
        /// <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
        }
        private int PO_BuildCapitalFreezeRecord(decimal predealCapital, decimal predealCost, GTA.VTS.Common.CommonObject.Types.TransactionDirection buySellType, ReckoningTransaction tm)
        {
            var caft = new XH_CapitalAccountFreezeTableInfo();

            ;
            //委托单号
            caft.EntrustNumber = EntrustNumber;

            //卖不产生冻结金额,只有费用
            if (buySellType == GTA.VTS.Common.CommonObject.Types.TransactionDirection.Buying)
            {
                //冻结 预成交金额
                caft.FreezeCapitalAmount = predealCapital;
            }

            //冻结 预成交费用
            caft.FreezeCost = predealCost;
            //冻结时间
            caft.FreezeTime = DateTime.Now;
            //解冻时间
            caft.ThawTime = DateTime.Now;
            //冻结类型
            caft.FreezeTypeLogo = (int)Types.FreezeType.DelegateFreeze;

            caft.OweCosting = 0;

            caft.CapitalAccountLogo = CapitalAccountId;

            string format =
                "现货资金冻结处理XHBuyOrderLogicFlow.PO_BuildCapitalFreezeRecord[委托单号={0},冻结时间={1},解冻时间={2},冻结类型={3},预成交金额={4},预成交费用={5},资金账户ID={6}]";

            string desc = string.Format(format, caft.EntrustNumber, caft.FreezeTime, caft.ThawTime, caft.FreezeTypeLogo,
                                        caft.FreezeCapitalAmount, caft.FreezeCost, CapitalAccountId);

            LogHelper.WriteDebug(desc);

            XH_CapitalAccountFreezeTableDal dal = new XH_CapitalAccountFreezeTableDal();

            return(dal.Add(caft, tm.Database, tm.Transaction));
        }
Exemplo n.º 27
0
        /// <summary>
        /// 更新分红记录
        /// </summary>
        /// <param name="tm">TransactionManager</param>
        /// <param name="cash">分红信息</param>
        /// <param name="tables">登记列表</param>
        private static bool UpdateCashCut(ReckoningTransaction tm, IList <XH_MelonCutRegisterTableInfo> tables)
        {
            bool issuss = true;
            List <XH_CapitalAccountTableInfo> capitalList = new List <XH_CapitalAccountTableInfo>();
            List <UA_CapitalFlowTableInfo>    flowList    = new List <UA_CapitalFlowTableInfo>();

            XH_CapitalAccountTableDal dal = new XH_CapitalAccountTableDal();

            try
            {
                foreach (XH_MelonCutRegisterTableInfo registerTable in tables)
                {
                    //分红的现金额
                    decimal num = registerTable.RegisterAmount;

                    UA_UserAccountAllocationTableInfo capitalAccount = Utils.GetCapitalAccountByHoldAccount(registerTable.UserAccountDistributeLogo, registerTable.Code);

                    XH_CapitalAccountTableInfo accountTable = dal.GetXHCapitalAccount(capitalAccount.UserAccountDistributeLogo, registerTable.TradeCurrencyType);

                    if (accountTable == null)
                    {
                        continue;
                    }


                    accountTable.TodayOutInCapital += num;


                    accountTable.AvailableCapital += num;

                    capitalList.Add(accountTable);


                    //更新资金流水表
                    UA_CapitalFlowTableInfo flowTable = GetFlowTable(registerTable, capitalAccount.UserAccountDistributeLogo, num);
                    flowList.Add(flowTable);


                    string format = "MelonCutService.UpdateCashCut进行现金分红[商品代码={0},持仓帐号={1},分红金额={2}]";
                    string desc   = string.Format(format, registerTable.Code, registerTable.UserAccountDistributeLogo, num);
                    LogHelper.WriteDebug(desc);
                }

                XH_CapitalAccountTableDal xh_AccountTableDal = new XH_CapitalAccountTableDal();

                if (capitalList.Count > 0)
                {
                    foreach (var accountTableInfo in capitalList)
                    {
                        xh_AccountTableDal.Update(accountTableInfo, tm.Database, tm.Transaction);
                    }
                }
                if (flowList.Count > 0)
                {
                    UA_CapitalFlowTableDal flowTableDal = new UA_CapitalFlowTableDal();
                    foreach (var historyTradeTableInfo in flowList)
                    {
                        flowTableDal.Add(historyTradeTableInfo, tm.Database, tm.Transaction);
                    }
                }
                if (tables.Count > 0)
                {
                    XH_MelonCutRegisterTableDal melonCutRegisterTableDal = new XH_MelonCutRegisterTableDal();
                    foreach (var registerTableInfo in tables)
                    {
                        melonCutRegisterTableDal.Delete(registerTableInfo, tm.Database, tm.Transaction);
                    }
                }
            }
            catch (Exception ex)
            {
                issuss = false;
                LogHelper.WriteError("分红出现问题 ", ex);
            }
            return(issuss);
        }
Exemplo n.º 28
0
 /// <summary>
 /// 更新数据库中期货清算日期和移动历史数据日期
 /// </summary>
 /// <param name="tm">事务</param>
 /// <param name="value">日期</param>
 public static void UpdateFutureReckoningDate(string value, ReckoningTransaction tm)
 {
     DoUpdate(FutureReckoningDate, value, tm);
     DoUpdate(FutureHistoryDataProcessDate, value, tm);
 }
        /// <summary>
        /// 检验并持久化柜台委托单
        /// </summary>
        /// <param name="strMessage">错误消息</param>
        /// <param name="outEntity">柜台持久化后的对象</param>
        /// <returns>是否成功</returns>
        private bool PersistentOrder(ref XH_TodayEntrustTableInfo outEntity, ref string strMessage)
        {
            #region 初始化参数

            //取代码对应品种的交易币种
            if (!GetCurrencyType())
            {
                strMessage = "GT-2226:[现货委托持久化]无法获取交易币种";
                return(false);
            }

            if (CurrencyType == -1)
            {
                strMessage = "GT-2226:[现货委托持久化]无法获取交易币种";
                return(false);
            }

            //预成交金额
            decimal predealCapital = 0;
            //预成交费用
            decimal predealCost = 0;

            //预成交总金额(根据买卖的不同,不一定=predealCapital+predealCost)
            decimal preDealSum = 0;

            //资金及持仓帐户
            string strHoldingAccount;
            string strCapitalAccount;

            //依据交易员及委托信息取对应资金及持仓帐户
            if (!CheckAccount(out strCapitalAccount, out strHoldingAccount, out strMessage))
            {
                return(false);
            }

            GetAccountId(strCapitalAccount, strHoldingAccount);

            if (CapitalAccountId == -1)
            {
                strMessage = "GT-2227:[现货委托持久化]无法获取资金帐号ID";
                return(false);
            }

            #endregion

            #region 检查

            try
            {
                //计算预成交金额和预成交费用
                if (!this.PO_ComputePreCapital(ref strMessage, ref predealCapital, ref predealCost))
                {
                    PO_ValidateFailureProcess(ref strMessage);
                    return(false);
                }

                //四舍五入
                predealCapital = Utils.Round(predealCapital);
                predealCost    = Utils.Round(predealCost);

                //1.资金检查
                if (
                    !this.PO_CapitalValidate(predealCost, predealCapital, ref strMessage))
                {
                    PO_ValidateFailureProcess(ref strMessage);
                    return(false);
                }

                //2.持仓检查
                if (!PO_HoldValidate(ref strMessage))
                {
                    PO_ValidateFailureProcess(ref strMessage);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                strMessage = ex.Message;
                PO_ValidateFailureProcess(ref strMessage);
                return(false);
            }

            #endregion

            #region 创建委托(处理失败时要删除此条委托)

            try
            {
                EntrustNumber = XHCommonLogic.BuildXhOrder(ref outEntity, Request, HoldingAccount, CapitalAccount,
                                                           CurrencyType,
                                                           ref strMessage);
            }
            catch (Exception ex)
            {
                DeleteEntrust(EntrustNumber);
                LogHelper.WriteError(ex.Message, ex);
                strMessage = "GT-2225:[现货委托持久化]无法创建委托";
                LogHelper.WriteDebug(strMessage + ":" + outEntity);

                return(false);
            }

            #endregion

            #region Persist流程

            //persistent流程
            //1.资金处理,可用资金减去预成交总金额,总冻结资金加上预成交总金额
            //2.冻结资金处理,生成一条冻结记录
            //3.持仓处理:只有卖出时才会有持仓处理,可用持仓减少委托量,总冻结持仓增加委托量
            //4.持仓冻结处理:只有卖出时才会有持仓冻结处理,生成一条冻结记录

            //实际处理:
            //2.4放在一个事务中进行,当成功后再进行1.3的处理
            bool isSuccess = false;

            #region 资金预处理


            var caMemory = MemoryDataManager.XHCapitalMemoryList.GetByCapitalAccountLogo(CapitalAccountId);

            if (caMemory == null)
            {
                strMessage = "GT-2211:[现货委托持久化]资金帐户不存在:" + CapitalAccount;

                return(false);
            }

            if (Request.BuySell == GTA.VTS.Common.CommonObject.Types.TransactionDirection.Buying)
            {
                //预成交总金额 = 预成交金额 + 预成交费用
                preDealSum = predealCapital + predealCost;
            }
            else
            {
                //预成交总金额 = 预成交费用(卖不需要加金额)
                preDealSum = predealCost;
            }

            XH_CapitalAccountTable_DeltaInfo capitalDelta = new XH_CapitalAccountTable_DeltaInfo();
            capitalDelta.CapitalAccountLogo      = caMemory.Data.CapitalAccountLogo;
            capitalDelta.AvailableCapitalDelta   = -preDealSum;
            capitalDelta.FreezeCapitalTotalDelta = preDealSum;

            //return caMemory.AddDelta(-preDealCapitalAmount, preDealCapitalAmount, 0, 0);
            //return caMemory.AddDelta(capitalDelta);

            #endregion

            #region 持仓预处理(买入不处理)
            decimal                       orderAmount = Convert.ToDecimal(Request.OrderAmount);
            XHHoldMemoryTable             ahtMemory   = null;
            XH_AccountHoldTableInfo_Delta holdDelta   = null;
            if (Request.BuySell == GTA.VTS.Common.CommonObject.Types.TransactionDirection.Selling)
            {
                ahtMemory = MemoryDataManager.XHHoldMemoryList.GetByAccountHoldLogoId(HoldingAccountId);
                if (ahtMemory == null)
                {
                    ahtMemory = XHCommonLogic.GetHoldMemoryTable(HoldingAccount, Code, CurrencyType);
                }

                if (ahtMemory == null)
                {
                    strMessage = "GT-2212:[现货委托持久化]持仓帐户不存在:" + HoldingAccount;
                    return(false);
                }

                holdDelta = new XH_AccountHoldTableInfo_Delta();
                var holdData = ahtMemory.Data;
                holdDelta.AccountHoldLogoId    = holdData.AccountHoldLogoId;
                holdDelta.AvailableAmountDelta = -orderAmount;
                holdDelta.FreezeAmountDelta    = orderAmount;
                holdDelta.Data = holdData;
            }

            #endregion

            #region 数据库提交动作

            bool     isCapitalSuccess = false;
            bool     isHoldingSuccess = false;
            Database database         = DatabaseFactory.CreateDatabase();
            try
            {
                using (DbConnection connection = database.CreateConnection())
                {
                    connection.Open();
                    DbTransaction transaction = connection.BeginTransaction();
                    try
                    {
                        ReckoningTransaction tm = new ReckoningTransaction();
                        tm.Database    = database;
                        tm.Transaction = transaction;
                        //1.资金处理
                        //首先提交资金到数据库
                        isCapitalSuccess = caMemory.CheckAndAddDelta(CapitalCheck, capitalDelta, database, transaction);
                        if (!isCapitalSuccess)
                        {
                            strMessage = "GT-2218:[现货委托持久化]资金检查,无足够可用资金";
                            throw new CheckException("XHCapitalMemoryTable.CheckAddAddDelta失败");
                        }

                        //2.冻结资金处理,生成一条冻结记录
                        PO_BuildCapitalFreezeRecord(predealCapital, predealCost, Request.BuySell, tm);

                        //3.持仓冻结处理:只有卖出是才会有持仓处理
                        if (Request.BuySell ==
                            GTA.VTS.Common.CommonObject.Types.TransactionDirection.Selling)
                        {
                            //持仓冻结处理,生成一条冻结记录
                            PO_BuildHoldFreezeRecord(tm);
                        }

                        //4.持仓处理
                        if (Request.BuySell == GTA.VTS.Common.CommonObject.Types.TransactionDirection.Selling)
                        {
                            isHoldingSuccess = ahtMemory.CheckAndAddDelta(HodingCheck, holdDelta, tm.Database, tm.Transaction);
                            if (!isHoldingSuccess)
                            {
                                strMessage  = holdMessage;
                                holdMessage = "";
                                throw new CheckException("XHHoldingMemoryTable.CheckAddAddDelta失败");
                            }
                        }

                        transaction.Commit();
                        isSuccess = true;
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        LogHelper.WriteError(ex.Message, ex);
                        if (!(ex is CheckException))
                        {
                            strMessage = "GT-2213:[现货委托持久化]持久化失败,无法提交到数据库";
                        }
                        isSuccess = false;
                    }
                }
            }
            catch (Exception ex)
            {
                strMessage = "GT-2214:[现货委托持久化]持久化失败";
                LogHelper.WriteError(ex.Message, ex);
            }

            //事务失败
            if (!isSuccess)
            {
                DeleteEntrust(EntrustNumber);

                if (isCapitalSuccess)
                {
                    caMemory.RollBackMemory(capitalDelta);
                }

                if (Request.BuySell == GTA.VTS.Common.CommonObject.Types.TransactionDirection.Selling)
                {
                    if (isHoldingSuccess)
                    {
                        ahtMemory.RollBackMemory(holdDelta);
                    }
                }


                return(false);
            }

            //if(isSuccess)
            //{
            //    //当提交资金、持仓 到数据库成功后,同步到内存
            //    caMemory.AddDeltaToMemory(capitalDelta);
            //    if (Request.BuySell == CommonObject.Types.TransactionDirection.Selling)
            //    {
            //        ahtMemory.AddDeltaToMemory(holdDelta);
            //    }
            //}
            //else
            //{
            //    DeleteEntrust(EntrustNumber);
            //    return false;
            //}

            #endregion


            #endregion

            return(true);
        }
Exemplo n.º 30
0
 /// <summary>
 /// 更新数据库中期货清算日期
 /// </summary>
 public static void UpdateFutureReckoningDate(ReckoningTransaction tm)
 {
     DoUpdate(FutureReckoningDate, tm);
 }