示例#1
0
        /// <summary>
        /// 带事务的Update
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="trans">The trans.</param>
        /// <returns></returns>
        /// <remarks>2016/1/28 16:27:35</remarks>
        public bool Update(LeagueExchangerecordEntity entity, DbTransaction trans = null)
        {
            var       database       = new SqlDatabase(this.ConnectionString);
            DbCommand commandWrapper = database.GetStoredProcCommand("dbo.P_LeagueExchangerecord_Update");

            database.AddInParameter(commandWrapper, "@Idx", DbType.Int32, entity.Idx);
            database.AddInParameter(commandWrapper, "@ManagerId", DbType.Guid, entity.ManagerId);
            database.AddInParameter(commandWrapper, "@ItemCode", DbType.Int32, entity.ItemCode);
            database.AddInParameter(commandWrapper, "@CostScore", DbType.Int32, entity.CostScore);
            database.AddInParameter(commandWrapper, "@RowTime", DbType.DateTime, entity.RowTime);


            int results = 0;

            if (trans != null)
            {
                results = database.ExecuteNonQuery(commandWrapper, trans);
            }
            else
            {
                results = database.ExecuteNonQuery(commandWrapper);
            }

            entity.Idx = (System.Int32)database.GetParameterValue(commandWrapper, "@Idx");

            return(Convert.ToBoolean(results));
        }
示例#2
0
        /// <summary>
        /// 将IDataReader的当前记录读取到LeagueExchangerecordEntity 对象
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public LeagueExchangerecordEntity LoadSingleRow(IDataReader reader)
        {
            var obj = new LeagueExchangerecordEntity();

            obj.Idx       = (System.Int32)reader["Idx"];
            obj.ManagerId = (System.Guid)reader["ManagerId"];
            obj.ItemCode  = (System.Int32)reader["ItemCode"];
            obj.CostScore = (System.Int32)reader["CostScore"];
            obj.RowTime   = (System.DateTime)reader["RowTime"];

            return(obj);
        }
示例#3
0
        /// <summary>
        /// GetById
        /// </summary>
        /// <param name="idx">idx</param>
        /// <returns>LeagueExchangerecordEntity</returns>
        /// <remarks>2016/1/28 16:27:35</remarks>
        public LeagueExchangerecordEntity GetById(System.Int32 idx)
        {
            var database = new SqlDatabase(this.ConnectionString);

            DbCommand commandWrapper = database.GetStoredProcCommand("P_LeagueExchangerecord_GetById");

            database.AddInParameter(commandWrapper, "@Idx", DbType.Int32, idx);


            LeagueExchangerecordEntity obj = null;

            using (IDataReader reader = database.ExecuteReader(commandWrapper))
            {
                if (reader.Read())
                {
                    obj = LoadSingleRow(reader);
                }
            }
            return(obj);
        }
        public static bool Update(LeagueExchangerecordEntity leagueExchangerecordEntity, DbTransaction trans = null, string zoneId = "")
        {
            var provider = new LeagueExchangerecordProvider(zoneId);

            return(provider.Update(leagueExchangerecordEntity, trans));
        }
示例#5
0
 MessageCode Tran_SaveExchange(DbTransaction transaction, LaegueManagerinfoEntity leagueManager, ItemPackageFrame package, LeagueExchangerecordEntity leagueExchangerecord)
 {
     if (!LaegueManagerinfoMgr.Update(leagueManager, transaction))
     {
         return(MessageCode.NbUpdateFail);
     }
     if (!package.Save(transaction))
     {
         return(MessageCode.NbUpdateFail);
     }
     if (!LeagueExchangerecordMgr.Insert(leagueExchangerecord, transaction))
     {
         return(MessageCode.NbUpdateFail);
     }
     return(MessageCode.Success);
 }
示例#6
0
        MessageCode SaveExchange(LaegueManagerinfoEntity leagueManager, ItemPackageFrame package, LeagueExchangerecordEntity leagueExchangerecord)
        {
            if (leagueManager == null || package == null || leagueExchangerecord == null)
            {
                return(MessageCode.NbUpdateFail);
            }
            try
            {
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
                {
                    transactionManager.BeginTransaction();
                    var messageCode = Tran_SaveExchange(transactionManager.TransactionObject, leagueManager, package, leagueExchangerecord);

                    if (messageCode == ShareUtil.SuccessCode)
                    {
                        transactionManager.Commit();
                    }
                    else
                    {
                        transactionManager.Rollback();
                    }
                    return(messageCode);
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("SaveExchange", ex);
                return(MessageCode.Exception);
            }
        }
示例#7
0
        public LeagueExchangeResponse Exchange(Guid managerId, string exchangeKey)
        {
            var manager = LaegueManagerinfoMgr.GetById(managerId);

            if (manager == null || string.IsNullOrEmpty(manager.ExchangeIds) ||
                !manager.ExchangeIds.Contains(exchangeKey))
            {
                return(ResponseHelper.InvalidParameter <LeagueExchangeResponse>());
            }
            var exchangeCache = CacheFactory.LeagueCache.GetExchangeEntity(exchangeKey);

            if (exchangeCache == null)
            {
                return(ResponseHelper.InvalidParameter <LeagueExchangeResponse>());
            }

            if (manager.ExchangedIds.Contains(exchangeKey))
            {
                return(ResponseHelper.Create <LeagueExchangeResponse>(MessageCode.LeagueExchangeTimesOver));
            }

            if (manager.SumScore < exchangeCache.CostScore)
            {
                return(ResponseHelper.Create <LeagueExchangeResponse>(MessageCode.LeagueExchangeHonorShortage));
            }
            var package = ItemCore.Instance.GetPackage(managerId, EnumTransactionType.LeagueExchange);

            var itemcode           = exchangeCache.ItemCode;
            var exchanagerItemCode = Convert.ToInt32(exchangeKey.Split(',')[1]);

            if (exchangeCache.ItemCode != exchanagerItemCode)
            {
                itemcode = exchanagerItemCode;
            }

            var itemInfo = CacheFactory.ItemsdicCache.GetItem(itemcode);
            var code     = MessageCode.Success;

            if (itemInfo.ItemType == (int)EnumItemType.Equipment)
            {
                var allEquipmentProperties = CacheFactory.LeagueCache.AnalysisProperties(manager.EquipmentProperties);
                var property = GetEquipmentProperty(manager.EquipmentItems, allEquipmentProperties, itemcode);
                code = package.AddEquipment(itemcode, true, false, property);
            }
            else
            {
                code = package.AddItem(itemcode, true, false);
            }
            if (code != MessageCode.Success)
            {
                return(ResponseHelper.Create <LeagueExchangeResponse>(code));
            }
            manager.SumScore     = manager.SumScore - exchangeCache.CostScore;
            manager.UpdateTime   = DateTime.Now;
            manager.ExchangedIds = manager.ExchangedIds + "|" + exchangeKey;

            var record = new LeagueExchangerecordEntity()
            {
                CostScore = exchangeCache.CostScore,
                ItemCode  = itemcode,
                ManagerId = managerId,
                RowTime   = DateTime.Now
            };

            code = SaveExchange(manager, package, record);
            if (code != MessageCode.Success)
            {
                return(ResponseHelper.Create <LeagueExchangeResponse>(code));
            }
            else
            {
                package.Shadow.Save();
                var response = ResponseHelper.CreateSuccess <LeagueExchangeResponse>();
                response.Data = new LeagueExchangeEntity {
                    CurScore = manager.SumScore, ItemCode = itemcode
                };
                return(response);
            }
        }