Esempio n. 1
0
        public List <CancelRedoItem> GetCancelRedoBySubmitId(Model.Database.EntrustCommand cmdItem)
        {
            var entrustSecuItems = _entrustSecurityBLL.GetCancelRedoBySubmitId(cmdItem.SubmitId);
            var cancelItemList   = new List <CancelRedoItem>();

            if (entrustSecuItems == null)
            {
                return(cancelItemList);
            }

            var tradeCommand = _tradeCommandBLL.GetTradeCommand(cmdItem.CommandId);

            if (tradeCommand == null)
            {
                return(cancelItemList);
            }

            foreach (var p in entrustSecuItems)
            {
                var cancelRedoItem = Convert(p, tradeCommand);

                cancelItemList.Add(cancelRedoItem);
            }

            return(cancelItemList);
        }
Esempio n. 2
0
        public BLLResponse SubmitOne(Model.Database.EntrustCommand cmdItem, List <CancelRedoItem> cancelItems, CallerCallback callback)
        {
            //TODO: adjust the EntrustAmount
            List <EntrustSecurity> entrustItems = new List <EntrustSecurity>();
            DateTime now = DateTime.Now;

            //merge the same security in with the same commandId
            var uniqueSecuCodes = cancelItems.Select(p => p.SecuCode).Distinct().ToList();

            foreach (var secuCode in uniqueSecuCodes)
            {
                EntrustSecurity item = new EntrustSecurity
                {
                    CommandId   = cmdItem.CommandId,
                    SecuCode    = secuCode,
                    EntrustDate = now,
                };

                var originSecuItems = cancelItems.Where(p => p.SecuCode.Equals(secuCode)).ToList();
                if (originSecuItems != null && originSecuItems.Count > 0)
                {
                    item.SecuType         = originSecuItems[0].SecuType;
                    item.EntrustPrice     = originSecuItems[0].EntrustPrice;
                    item.EntrustDirection = originSecuItems[0].EDirection;
                    item.EntrustPriceType = originSecuItems[0].EEntrustPriceType;
                    item.PriceType        = originSecuItems[0].EPriceSetting;

                    item.EntrustAmount = originSecuItems.Sum(o => o.LeftAmount);

                    entrustItems.Add(item);
                }
            }

            return(SubmitSync(cmdItem, entrustItems, callback));
        }
Esempio n. 3
0
        public List <CancelRedoItem> GetEntrustedSecuItems(Model.Database.EntrustCommand cmdItem)
        {
            var entrustSecuItems = _entrustSecurityBLL.GetCancelBySumbitId(cmdItem.SubmitId);
            var cancelItemList   = new List <CancelRedoItem>();

            if (entrustSecuItems == null)
            {
                return(cancelItemList);
            }

            var tradeCommand = _tradeCommandBLL.GetTradeCommand(cmdItem.CommandId);

            if (tradeCommand == null)
            {
                return(cancelItemList);
            }

            DateTime now = DateTime.Now;

            foreach (var p in entrustSecuItems)
            {
                //Only can cancel the entrusted security in the same entrusted day.
                if (p.ModifiedDate != null && p.ModifiedDate.Date.Equals(now.Date))
                {
                    var cancelRedoItem = Convert(p, tradeCommand);
                    cancelItemList.Add(cancelRedoItem);
                }
            }

            return(cancelItemList);
        }
Esempio n. 4
0
        private int SumbitToDB(Model.Database.EntrustCommand cmdItem, List <EntrustSecurity> entrustItems)
        {
            int userId = LoginManager.Instance.GetUserId();

            cmdItem.SubmitPerson = userId;

            return(_entrustCombineBLL.Submit(cmdItem, entrustItems));
        }
        public BLLResponse WithdrawBasket(Model.Database.EntrustCommand cmdItem)
        {
            UFXBasketWithdrawRequest request = new UFXBasketWithdrawRequest
            {
                BatchNo = cmdItem.BatchNo,
            };

            var responseItems = _withdrawSyncBLL.WithdrawBasket(request);

            return(GetResponse(cmdItem.SubmitId, cmdItem.CommandId, responseItems));
        }
Esempio n. 6
0
        public BLLResponse SubmitAsync(Model.Database.EntrustCommand cmdItem, List <EntrustSecurity> entrustItems, CallerCallback callback, EventWaitHandle waitHandle)
        {
            int ret = LocalSubmit(cmdItem, entrustItems);

            if (ret <= 0)
            {
                return(new BLLResponse(ConnectionCode.DBInsertFail, "Fail to submit into database"));
            }

            return(_ufxBasketEntrustBLL.SubmitAsync(cmdItem, entrustItems, callback, waitHandle));
        }
Esempio n. 7
0
        public BLLResponse Withdraw(Model.Database.EntrustCommand cmdItem, CallerCallback callerCallback)
        {
            BLLResponse bllResponse = new BLLResponse();

            UFXBasketWithdrawRequest request = new UFXBasketWithdrawRequest
            {
                BatchNo = cmdItem.BatchNo,
            };

            Callbacker callbacker = new Callbacker
            {
                Token = new CallerToken
                {
                    SubmitId  = cmdItem.SubmitId,
                    CommandId = cmdItem.CommandId,
                    WaitEvent = new AutoResetEvent(false),
                    Caller    = callerCallback,
                },

                DataHandler = WithdrawDataHandler,
            };

            var result = _securityBLL.WithdrawBasket(request, callbacker);

            if (result == Model.ConnectionCode.Success)
            {
                if (callbacker.Token.WaitEvent.WaitOne(_timeOut))
                {
                    var errorResponse = callbacker.Token.ErrorResponse as UFXErrorResponse;
                    if (errorResponse != null && T2ErrorHandler.Success(errorResponse.ErrorCode))
                    {
                        bllResponse.Code    = Model.ConnectionCode.Success;
                        bllResponse.Message = "Success Withdraw";
                    }
                    else
                    {
                        bllResponse.Code    = Model.ConnectionCode.FailWithdraw;
                        bllResponse.Message = errorResponse.ErrorMessage;
                    }
                }
                else
                {
                    bllResponse.Code    = Model.ConnectionCode.FailTimeoutWithdraw;
                    bllResponse.Message = "Fail to submit the basket withdraw to UFX!";
                }
            }
            else
            {
                bllResponse.Code    = Model.ConnectionCode.FailSubmit;
                bllResponse.Message = "Fail to submit the basket withdraw to UFX!";
            }

            return(bllResponse);
        }
Esempio n. 8
0
        private int LocalSubmit(Model.Database.EntrustCommand cmdItem, List <EntrustSecurity> entrustItems)
        {
            int ret = SumbitToDB(cmdItem, entrustItems);

            if (ret > 0)
            {
                entrustItems.Where(p => p.CommandId == cmdItem.CommandId)
                .ToList()
                .ForEach(o => o.SubmitId = cmdItem.SubmitId);
            }

            return(ret);
        }
Esempio n. 9
0
        private Model.Database.EntrustCommand MergeEntrustCommandItem(List <Model.Database.EntrustCommand> oldCmdItems)
        {
            Debug.Assert(oldCmdItems.Select(p => p.CommandId).Distinct().Count() == 1, "撤销的委托指令不是同一指令号");
            var commandId = oldCmdItems.Select(p => p.CommandId).Distinct().Single();
            var copies    = oldCmdItems.Where(p => p.CommandId == commandId).Select(o => o.Copies).Sum();
            var cmdItem   = new Model.Database.EntrustCommand
            {
                CommandId = commandId,
                Copies    = copies,
            };

            return(cmdItem);
        }
Esempio n. 10
0
        //public List<EntrustCommandItem> Get()
        //{
        //    var dbCommand = _dbHelper.GetStoredProcCommand(SP_Get);

        //    List<EntrustCommandItem> items = new List<EntrustCommandItem>();
        //    var reader = _dbHelper.ExecuteReader(dbCommand);
        //    if (reader.HasRows)
        //    {
        //        while (reader.Read())
        //        {
        //            EntrustCommandItem item = new EntrustCommandItem();
        //            item.SubmitId = (int)reader["SubmitId"];
        //            item.CommandId = (int)reader["CommandId"];
        //            item.Copies = (int)reader["Copies"];
        //            if (reader["EntrustNo"] != null && reader["EntrustNo"] != DBNull.Value)
        //            {
        //                item.EntrustNo = (int)reader["EntrustNo"];
        //            }

        //            if (reader["BatchNo"] != null && reader["BatchNo"] != DBNull.Value)
        //            {
        //                item.BatchNo = (int)reader["BatchNo"];
        //            }
        //            item.EntrustStatus = (EntrustStatus)(int)reader["EntrustStatus"];
        //            item.DealStatus = (DealStatus)(int)reader["DealStatus"];

        //            if (reader["CreatedDate"] != null && reader["CreatedDate"] != DBNull.Value)
        //            {
        //                item.CreatedDate = (DateTime)reader["CreatedDate"];
        //            }

        //            if (reader["ModifiedDate"] != null && reader["ModifiedDate"] != DBNull.Value)
        //            {
        //                item.ModifiedDate = (DateTime)reader["ModifiedDate"];
        //            }

        //            if (reader["EntrustFailCode"] != null && reader["EntrustFailCode"] != DBNull.Value)
        //            { 
        //                item.EntrustFailCode = (int)reader["EntrustFailCode"];
        //            }

        //            if (reader["EntrustFailCause"] != null && reader["EntrustFailCause"] != DBNull.Value)
        //            {
        //                item.EntrustFailCause = (string)reader["EntrustFailCause"];
        //            }

        //            items.Add(item);
        //        }
        //    }
        //    reader.Close();
        //    _dbHelper.Close(dbCommand.Connection);

        //    return items;
        //}

        //public List<EntrustCommandItem> GetByCommandId(int commandId)
        //{
        //    var dbCommand = _dbHelper.GetStoredProcCommand(SP_GetByCommandId);
        //    _dbHelper.AddInParameter(dbCommand, "@CommandId", System.Data.DbType.Int32, commandId);

        //    List<EntrustCommandItem> items = new List<EntrustCommandItem>();
        //    var reader = _dbHelper.ExecuteReader(dbCommand);
        //    if (reader.HasRows)
        //    {
        //        while (reader.Read())
        //        {
        //            EntrustCommandItem item = new EntrustCommandItem();
        //            item.SubmitId = (int)reader["SubmitId"];
        //            item.CommandId = (int)reader["CommandId"];
        //            item.Copies = (int)reader["Copies"];
        //            if (reader["EntrustNo"] != null && reader["EntrustNo"] != DBNull.Value)
        //            {
        //                item.EntrustNo = (int)reader["EntrustNo"];
        //            }

        //            if (reader["BatchNo"] != null && reader["BatchNo"] != DBNull.Value)
        //            {
        //                item.BatchNo = (int)reader["BatchNo"];
        //            }
        //            item.EntrustStatus = (EntrustStatus)(int)reader["EntrustStatus"];
        //            item.DealStatus = (DealStatus)(int)reader["DealStatus"];

        //            if (reader["CreatedDate"] != null && reader["CreatedDate"] != DBNull.Value)
        //            {
        //                item.CreatedDate = (DateTime)reader["CreatedDate"];
        //            }

        //            if (reader["ModifiedDate"] != null && reader["ModifiedDate"] != DBNull.Value)
        //            {
        //                item.ModifiedDate = (DateTime)reader["ModifiedDate"];
        //            }

        //            if (reader["EntrustFailCode"] != null && reader["EntrustFailCode"] != DBNull.Value)
        //            {
        //                item.EntrustFailCode = (int)reader["EntrustFailCode"];
        //            }

        //            if (reader["EntrustFailCause"] != null && reader["EntrustFailCause"] != DBNull.Value)
        //            {
        //                item.EntrustFailCause = (string)reader["EntrustFailCause"];
        //            }

        //            items.Add(item);
        //        }
        //    }
        //    reader.Close();
        //    _dbHelper.Close(dbCommand.Connection);

        //    return items;
        //}

        public Model.Database.EntrustCommand GetBySubmitId(int submitId)
        {
            var dbCommand = _dbHelper.GetStoredProcCommand(SP_GetBySubmitId);
            _dbHelper.AddInParameter(dbCommand, "@SubmitId", System.Data.DbType.Int32, submitId);

            var item = new Model.Database.EntrustCommand();
            var reader = _dbHelper.ExecuteReader(dbCommand);
            if (reader.HasRows && reader.Read())
            {
                item = ParseDataSingle(reader);
            }
            reader.Close();
            _dbHelper.Close(dbCommand);

            return item;
        }
Esempio n. 11
0
        private Model.Database.EntrustCommand ParseDataSingle(DbDataReader reader)
        {
            var item = new Model.Database.EntrustCommand();
            item.SubmitId = (int)reader["SubmitId"];
            item.CommandId = (int)reader["CommandId"];
            item.Copies = (int)reader["Copies"];
            if (reader["EntrustNo"] != null && reader["EntrustNo"] != DBNull.Value)
            {
                item.EntrustNo = (int)reader["EntrustNo"];
            }

            if (reader["BatchNo"] != null && reader["BatchNo"] != DBNull.Value)
            {
                item.BatchNo = (int)reader["BatchNo"];
            }
            item.EntrustStatus = (EntrustStatus)(int)reader["EntrustStatus"];
            item.DealStatus = (DealStatus)(int)reader["DealStatus"];
            item.SubmitPerson = (int)reader["SubmitPerson"];

            if (reader["CreatedDate"] != null && reader["CreatedDate"] != DBNull.Value)
            {
                item.CreatedDate = (DateTime)reader["CreatedDate"];
            }

            if (reader["ModifiedDate"] != null && reader["ModifiedDate"] != DBNull.Value)
            {
                item.ModifiedDate = (DateTime)reader["ModifiedDate"];
            }

            if (reader["EntrustFailCode"] != null && reader["EntrustFailCode"] != DBNull.Value)
            {
                item.EntrustFailCode = (int)reader["EntrustFailCode"];
            }

            if (reader["EntrustFailCause"] != null && reader["EntrustFailCause"] != DBNull.Value)
            {
                item.EntrustFailCause = (string)reader["EntrustFailCause"];
            }

            return item;
        }
        public BLLResponse Submit(Model.Database.EntrustCommand cmdItem, List <EntrustSecurity> entrustItems, CallerCallback callerCallback)
        {
            var cmdEntrustItems = entrustItems.Where(p => p.CommandId == cmdItem.CommandId && p.SubmitId == cmdItem.SubmitId).ToList();

            if (cmdEntrustItems == null || cmdEntrustItems.Count == 0)
            {
                return(new BLLResponse(ConnectionCode.EmptyEntrustItem, "Empty EntrustCommandItem or EntrustSecurityItem."));
            }

            UpdateUFXSetting();
            var tradeCommandItem = _tradeCommandBLL.GetTradeCommand(cmdItem.CommandId);
            var portfolio        = LoginManager.Instance.GetPortfolio(tradeCommandItem.PortfolioCode);
            //var stockholder = LoginManager.Instance.GetHolder(tradeCommandItem.

            var ufxRequests = new List <UFXBasketEntrustRequest>();
            var futuItem    = cmdEntrustItems.Find(p => p.SecuType == Model.SecurityInfo.SecurityType.Futures);

            foreach (var secuItem in cmdEntrustItems)
            {
                UFXBasketEntrustRequest request = new UFXBasketEntrustRequest
                {
                    StockCode             = secuItem.SecuCode,
                    EntrustPrice          = secuItem.EntrustPrice,
                    EntrustAmount         = secuItem.EntrustAmount,
                    PriceType             = EntrustRequestHelper.GetEntrustPriceType(secuItem.EntrustPriceType),
                    ExtSystemId           = secuItem.RequestId,
                    ThirdReff             = EntrustRequestHelper.GenerateThirdReff(secuItem.CommandId, secuItem.SubmitId, secuItem.RequestId),
                    LimitEntrustRatio     = _limitEntrustRatio,
                    FutuLimitEntrustRatio = _futuLimitEntrustRatio,
                    OptLimitEntrustRatio  = _optLimitEntrustRatio,
                };

                if (secuItem.SecuType == Model.SecurityInfo.SecurityType.Stock)
                {
                    request.EntrustDirection = EntrustRequestHelper.GetEntrustDirection(secuItem.EntrustDirection);
                    request.FuturesDirection = string.Empty;
                }
                else if (secuItem.SecuType == Model.SecurityInfo.SecurityType.Futures)
                {
                    request.EntrustDirection = EntrustRequestHelper.GetEntrustDirection(secuItem.EntrustDirection);
                    request.FuturesDirection = EntrustRequestHelper.GetFuturesDirection(secuItem.EntrustDirection);
                }

                var secuInfo = SecurityInfoManager.Instance.Get(secuItem.SecuCode, secuItem.SecuType);
                if (secuInfo != null)
                {
                    request.MarketNo = EntrustRequestHelper.GetMarketNo(secuInfo.ExchangeCode);
                }

                if (tradeCommandItem != null)
                {
                    request.AccountCode = tradeCommandItem.AccountCode;
                    request.CombiNo     = tradeCommandItem.PortfolioCode;
                }

                ufxRequests.Add(request);
            }

            Callbacker callbacker = new Callbacker
            {
                Token = new CallerToken
                {
                    SubmitId  = cmdItem.SubmitId,
                    CommandId = cmdItem.CommandId,
                    Caller    = callerCallback,
                    WaitEvent = new AutoResetEvent(false),
                },

                DataHandler = EntrustDataHandler,
            };

            var result = _securityBLL.EntrustBasket(ufxRequests, callbacker);

            BLLResponse bllResponse = new BLLResponse();

            if (result == Model.ConnectionCode.Success)
            {
                if (callbacker.Token.WaitEvent.WaitOne(_timeOut))
                {
                    var errorResponse = callbacker.Token.ErrorResponse as UFXErrorResponse;
                    if (errorResponse != null && T2ErrorHandler.Success(errorResponse.ErrorCode))
                    {
                        bllResponse.Code    = ConnectionCode.Success;
                        bllResponse.Message = "Success Entrust";
                    }
                    else
                    {
                        bllResponse.Code    = ConnectionCode.FailEntrust;
                        bllResponse.Message = "Fail Entrust: " + errorResponse.ErrorCode + " " + errorResponse.ErrorMessage + " " + errorResponse.MessageDetail;
                    }
                }
                else
                {
                    bllResponse.Code    = ConnectionCode.FailTimeoutEntrust;
                    bllResponse.Message = "Timeout to entrust.";
                }
            }
            else
            {
                bllResponse.Code    = result;
                bllResponse.Message = "Fail to submit in ufx.";
            }

            return(bllResponse);
        }
        //TODO: async to sumbit the command, it can emit the latency.
        public BLLResponse SubmitAsync(Model.Database.EntrustCommand cmdItem, List <EntrustSecurity> entrustItems, CallerCallback callerCallback, EventWaitHandle waitHandle)
        {
            var cmdEntrustItems = entrustItems.Where(p => p.CommandId == cmdItem.CommandId && p.SubmitId == cmdItem.SubmitId).ToList();

            if (cmdEntrustItems == null || cmdEntrustItems.Count == 0)
            {
                return(new BLLResponse(ConnectionCode.EmptyEntrustItem, "Empty EntrustCommandItem or EntrustSecurityItem."));
            }

            UpdateUFXSetting();
            var tradeCommandItem = _tradeCommandBLL.GetTradeCommand(cmdItem.CommandId);
            var portfolio        = LoginManager.Instance.GetPortfolio(tradeCommandItem.PortfolioCode);
            //var stockholder = LoginManager.Instance.GetHolder(tradeCommandItem.

            var ufxRequests = new List <UFXBasketEntrustRequest>();
            var futuItem    = cmdEntrustItems.Find(p => p.SecuType == Model.SecurityInfo.SecurityType.Futures);

            foreach (var secuItem in cmdEntrustItems)
            {
                UFXBasketEntrustRequest request = new UFXBasketEntrustRequest
                {
                    StockCode             = secuItem.SecuCode,
                    EntrustPrice          = secuItem.EntrustPrice,
                    EntrustAmount         = secuItem.EntrustAmount,
                    PriceType             = EntrustRequestHelper.GetEntrustPriceType(secuItem.EntrustPriceType),
                    ExtSystemId           = secuItem.RequestId,
                    ThirdReff             = EntrustRequestHelper.GenerateThirdReff(secuItem.CommandId, secuItem.SubmitId, secuItem.RequestId),
                    LimitEntrustRatio     = _limitEntrustRatio,
                    FutuLimitEntrustRatio = _futuLimitEntrustRatio,
                    OptLimitEntrustRatio  = _optLimitEntrustRatio,
                };

                if (secuItem.SecuType == Model.SecurityInfo.SecurityType.Stock)
                {
                    request.EntrustDirection = EntrustRequestHelper.GetEntrustDirection(secuItem.EntrustDirection);
                    request.FuturesDirection = string.Empty;
                }
                else if (secuItem.SecuType == Model.SecurityInfo.SecurityType.Futures)
                {
                    request.EntrustDirection = EntrustRequestHelper.GetEntrustDirection(secuItem.EntrustDirection);
                    request.FuturesDirection = EntrustRequestHelper.GetFuturesDirection(secuItem.EntrustDirection);
                }

                var secuInfo = SecurityInfoManager.Instance.Get(secuItem.SecuCode, secuItem.SecuType);
                if (secuInfo != null)
                {
                    request.MarketNo = EntrustRequestHelper.GetMarketNo(secuInfo.ExchangeCode);
                }

                if (tradeCommandItem != null)
                {
                    request.AccountCode = tradeCommandItem.AccountCode;
                    request.CombiNo     = tradeCommandItem.PortfolioCode;
                }

                ufxRequests.Add(request);
            }

            Callbacker callbacker = new Callbacker
            {
                Token = new CallerToken
                {
                    SubmitId  = cmdItem.SubmitId,
                    CommandId = cmdItem.CommandId,
                    Caller    = callerCallback,
                    WaitEvent = waitHandle,
                },

                DataHandler = EntrustDataHandler,
            };

            var result = _securityBLL.EntrustBasket(ufxRequests, callbacker);

            return(new BLLResponse(result, "Finish to entrust."));
        }
Esempio n. 14
0
 public int Submit(Model.Database.EntrustCommand cmdItem, List <EntrustSecurity> entrustItems)
 {
     return(_entrustdao.Submit(cmdItem, entrustItems));
 }
Esempio n. 15
0
        public int Submit(Model.Database.EntrustCommand cmdItem, List <EntrustSecurity> entrustItems)
        {
            var dbCommand = _dbHelper.GetCommand();

            _dbHelper.Open(dbCommand);

            //use transaction to execute
            DbTransaction transaction = dbCommand.Connection.BeginTransaction();

            dbCommand.Transaction = transaction;
            dbCommand.CommandType = System.Data.CommandType.StoredProcedure;
            int ret = -1;

            try
            {
                //delete all old one
                dbCommand.CommandText = SP_CreateEntrustCommand;
                _dbHelper.AddInParameter(dbCommand, "@CommandId", System.Data.DbType.Int32, cmdItem.CommandId);
                _dbHelper.AddInParameter(dbCommand, "@Copies", System.Data.DbType.Int32, cmdItem.Copies);
                _dbHelper.AddInParameter(dbCommand, "@SubmitPerson", System.Data.DbType.Int32, cmdItem.SubmitPerson);
                _dbHelper.AddInParameter(dbCommand, "@CreatedDate", System.Data.DbType.DateTime, DateTime.Now);

                _dbHelper.AddReturnParameter(dbCommand, "@return", System.Data.DbType.Int32);

                ret = dbCommand.ExecuteNonQuery();

                if (ret >= 0)
                {
                    int submitId = -1;
                    if (ret > 0)
                    {
                        submitId         = (int)dbCommand.Parameters["@return"].Value;
                        cmdItem.SubmitId = submitId;
                    }

                    foreach (var entrustItem in entrustItems)
                    {
                        dbCommand.Parameters.Clear();
                        dbCommand.CommandText = SP_CreateEntrustSecurity;

                        _dbHelper.AddInParameter(dbCommand, "@SubmitId", System.Data.DbType.Int32, submitId);
                        _dbHelper.AddInParameter(dbCommand, "@CommandId", System.Data.DbType.Int32, entrustItem.CommandId);
                        _dbHelper.AddInParameter(dbCommand, "@SecuCode", System.Data.DbType.String, entrustItem.SecuCode);
                        _dbHelper.AddInParameter(dbCommand, "@SecuType", System.Data.DbType.Int32, entrustItem.SecuType);
                        _dbHelper.AddInParameter(dbCommand, "@EntrustAmount", System.Data.DbType.Int32, entrustItem.EntrustAmount);
                        _dbHelper.AddInParameter(dbCommand, "@EntrustPrice", System.Data.DbType.Decimal, entrustItem.EntrustPrice);
                        _dbHelper.AddInParameter(dbCommand, "@EntrustDirection", System.Data.DbType.Int32, (int)entrustItem.EntrustDirection);
                        _dbHelper.AddInParameter(dbCommand, "@EntrustStatus", System.Data.DbType.Int32, (int)entrustItem.EntrustStatus);
                        _dbHelper.AddInParameter(dbCommand, "@EntrustPriceType", System.Data.DbType.Int32, (int)entrustItem.EntrustPriceType);
                        _dbHelper.AddInParameter(dbCommand, "@PriceType", System.Data.DbType.Int32, (int)entrustItem.PriceType);
                        _dbHelper.AddInParameter(dbCommand, "@EntrustDate", System.Data.DbType.DateTime, entrustItem.EntrustDate);
                        _dbHelper.AddInParameter(dbCommand, "@CreatedDate", System.Data.DbType.DateTime, DateTime.Now);

                        _dbHelper.AddReturnParameter(dbCommand, "@return", System.Data.DbType.Int32);

                        ret = dbCommand.ExecuteNonQuery();
                        if (ret > 0)
                        {
                            int requetId = (int)dbCommand.Parameters["@return"].Value;
                            entrustItem.RequestId = requetId;
                        }
                    }
                }

                transaction.Commit();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                //TODO: add log
                logger.Error(ex);
                ret = -1;
                throw;
            }
            finally
            {
                _dbHelper.Close(dbCommand);
                transaction.Dispose();
            }

            return(ret);
        }
Esempio n. 16
0
        public int Create(Model.Database.EntrustCommand cmdItem, List <EntrustSecurity> entrustItems)
        {
            var dbCommand = _dbHelper.GetCommand();

            _dbHelper.Open(dbCommand);

            //use transaction to execute
            DbTransaction transaction = dbCommand.Connection.BeginTransaction();

            dbCommand.Transaction = transaction;
            dbCommand.CommandType = System.Data.CommandType.StoredProcedure;
            int ret = -1;

            try
            {
                //delete all old one
                dbCommand.CommandText = SP_CreateArchiveEntrustCommand;
                _dbHelper.AddInParameter(dbCommand, "@SubmitId", System.Data.DbType.Int32, cmdItem.SubmitId);
                _dbHelper.AddInParameter(dbCommand, "@CommandId", System.Data.DbType.Int32, cmdItem.CommandId);
                _dbHelper.AddInParameter(dbCommand, "@Copies", System.Data.DbType.Int32, cmdItem.Copies);
                _dbHelper.AddInParameter(dbCommand, "@EntrustNo", System.Data.DbType.Int32, cmdItem.EntrustNo);
                _dbHelper.AddInParameter(dbCommand, "@BatchNo", System.Data.DbType.Int32, cmdItem.BatchNo);
                _dbHelper.AddInParameter(dbCommand, "@EntrustStatus", System.Data.DbType.Int32, (int)cmdItem.EntrustStatus);
                _dbHelper.AddInParameter(dbCommand, "@DealStatus", System.Data.DbType.Int32, (int)cmdItem.DealStatus);
                _dbHelper.AddInParameter(dbCommand, "@SubmitPerson", System.Data.DbType.Int32, cmdItem.SubmitPerson);
                _dbHelper.AddInParameter(dbCommand, "@ArchiveDate", System.Data.DbType.DateTime, DateTime.Now);
                _dbHelper.AddInParameter(dbCommand, "@CreatedDate", System.Data.DbType.DateTime, cmdItem.CreatedDate);
                _dbHelper.AddInParameter(dbCommand, "@ModifiedDate", System.Data.DbType.DateTime, cmdItem.ModifiedDate);
                _dbHelper.AddInParameter(dbCommand, "@EntrustFailCode", System.Data.DbType.Int32, cmdItem.EntrustFailCode);
                _dbHelper.AddInParameter(dbCommand, "@EntrustFailCause", System.Data.DbType.String, cmdItem.EntrustFailCause);

                _dbHelper.AddReturnParameter(dbCommand, "@return", System.Data.DbType.Int32);

                ret = dbCommand.ExecuteNonQuery();

                if (ret >= 0)
                {
                    int archiveId = -1;
                    if (ret > 0)
                    {
                        archiveId = (int)dbCommand.Parameters["@return"].Value;
                    }

                    foreach (var entrustItem in entrustItems)
                    {
                        dbCommand.Parameters.Clear();
                        dbCommand.CommandText = SP_CreateArchiveEntrustSecurity;

                        _dbHelper.AddInParameter(dbCommand, "@ArchiveId", System.Data.DbType.Int32, archiveId);
                        _dbHelper.AddInParameter(dbCommand, "@RequestId", System.Data.DbType.Int32, entrustItem.RequestId);
                        _dbHelper.AddInParameter(dbCommand, "@SubmitId", System.Data.DbType.Int32, entrustItem.SubmitId);
                        _dbHelper.AddInParameter(dbCommand, "@CommandId", System.Data.DbType.Int32, entrustItem.CommandId);
                        _dbHelper.AddInParameter(dbCommand, "@SecuCode", System.Data.DbType.String, entrustItem.SecuCode);
                        _dbHelper.AddInParameter(dbCommand, "@SecuType", System.Data.DbType.Int32, (int)entrustItem.SecuType);
                        _dbHelper.AddInParameter(dbCommand, "@EntrustAmount", System.Data.DbType.Int32, entrustItem.EntrustAmount);
                        _dbHelper.AddInParameter(dbCommand, "@EntrustPrice", System.Data.DbType.Decimal, entrustItem.EntrustPrice);
                        _dbHelper.AddInParameter(dbCommand, "@EntrustDirection", System.Data.DbType.Int32, (int)entrustItem.EntrustDirection);
                        _dbHelper.AddInParameter(dbCommand, "@EntrustStatus", System.Data.DbType.Int32, (int)entrustItem.EntrustStatus);
                        _dbHelper.AddInParameter(dbCommand, "@EntrustPriceType", System.Data.DbType.Int32, (int)entrustItem.EntrustPriceType);
                        _dbHelper.AddInParameter(dbCommand, "@PriceType", System.Data.DbType.Int32, (int)entrustItem.PriceType);
                        _dbHelper.AddInParameter(dbCommand, "@EntrustNo", System.Data.DbType.Int32, entrustItem.EntrustNo);
                        _dbHelper.AddInParameter(dbCommand, "@BatchNo", System.Data.DbType.Int32, entrustItem.BatchNo);
                        _dbHelper.AddInParameter(dbCommand, "@DealStatus", System.Data.DbType.Int32, (int)entrustItem.DealStatus);
                        _dbHelper.AddInParameter(dbCommand, "@TotalDealAmount", System.Data.DbType.Int32, entrustItem.TotalDealAmount);
                        _dbHelper.AddInParameter(dbCommand, "@TotalDealBalance", System.Data.DbType.Decimal, entrustItem.TotalDealBalance);
                        _dbHelper.AddInParameter(dbCommand, "@TotalDealFee", System.Data.DbType.Decimal, entrustItem.TotalDealFee);
                        _dbHelper.AddInParameter(dbCommand, "@DealTimes", System.Data.DbType.Int32, entrustItem.DealTimes);
                        _dbHelper.AddInParameter(dbCommand, "@EntrustDate", System.Data.DbType.DateTime, entrustItem.EntrustDate);
                        _dbHelper.AddInParameter(dbCommand, "@CreatedDate", System.Data.DbType.DateTime, entrustItem.CreatedDate);
                        _dbHelper.AddInParameter(dbCommand, "@ModifiedDate", System.Data.DbType.DateTime, entrustItem.ModifiedDate);
                        _dbHelper.AddInParameter(dbCommand, "@EntrustFailCode", System.Data.DbType.Int32, entrustItem.EntrustFailCode);
                        _dbHelper.AddInParameter(dbCommand, "@EntrustFailCause", System.Data.DbType.String, entrustItem.EntrustFailCause);

                        ret = dbCommand.ExecuteNonQuery();
                        if (ret < 0)
                        {
                            string msg = string.Format("Fail to insert: ArchiveId: {0}, SubmitId: {1}, RequestId: {2}, SecuCode: {3}",
                                                       archiveId, entrustItem.SubmitId, entrustItem.RequestId, entrustItem.SecuCode);
                            logger.Error(msg);
                        }
                    }
                }

                transaction.Commit();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                //TODO: add log
                logger.Error(ex);
                ret = -1;
                throw;
            }
            finally
            {
                _dbHelper.Close(dbCommand);
                transaction.Dispose();
            }

            return(ret);
        }
Esempio n. 17
0
 public int Create(Model.Database.EntrustCommand entrustCommand, List <EntrustSecurity> securities)
 {
     return(_archiveentrustdao.Create(entrustCommand, securities));
 }