/// <summary>
        /// 带事务的Update
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="trans">The trans.</param>
        /// <returns></returns>
        /// <remarks>2016/6/7 18:38:46</remarks>
        public bool Update(GambleTitleEntity entity, DbTransaction trans = null)
        {
            var       database       = new SqlDatabase(this.ConnectionString);
            DbCommand commandWrapper = database.GetStoredProcCommand("dbo.P_GambleTitle_Update");

            database.AddInParameter(commandWrapper, "@Idx", DbType.Guid, entity.Idx);
            database.AddInParameter(commandWrapper, "@Title", DbType.String, entity.Title);
            database.AddInParameter(commandWrapper, "@IsOfficial", DbType.Int32, entity.IsOfficial);
            database.AddInParameter(commandWrapper, "@ResultFlagId", DbType.Guid, entity.ResultFlagId);
            database.AddInParameter(commandWrapper, "@StartTime", DbType.DateTime, entity.StartTime);
            database.AddInParameter(commandWrapper, "@StopTime", DbType.DateTime, entity.StopTime);
            database.AddInParameter(commandWrapper, "@OpenTime", DbType.DateTime, entity.OpenTime);
            database.AddInParameter(commandWrapper, "@CurrentCount", DbType.Int32, entity.CurrentCount);
            database.AddInParameter(commandWrapper, "@Status", DbType.Int32, entity.Status);
            database.AddInParameter(commandWrapper, "@RowTime", DbType.DateTime, entity.RowTime);
            database.AddInParameter(commandWrapper, "@RowVersion", DbType.Binary, entity.RowVersion);


            int results = 0;

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

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

            return(Convert.ToBoolean(results));
        }
示例#2
0
        void BindOptions()
        {
            if (ddltNeedOpenGambleTitle.Items.Count == 0)
            {
                return;
            }
            GambleTitleEntity title = GambleTitleMgr.GetById(new Guid(ddltNeedOpenGambleTitle.SelectedValue), ZoneId);

            List <GambleOptionEntity> list = GambleOptionMgr.GetByTitleId(new Guid(ddltNeedOpenGambleTitle.SelectedValue), ZoneId);

            rblOptions.DataSource     = list;
            rblOptions.DataTextField  = "OptionContent";
            rblOptions.DataValueField = "Idx";
            rblOptions.DataBind();

            if (title.ResultFlagId != Guid.Empty)
            {
                for (int i = 0, count = rblOptions.Items.Count; i < count; i++)
                {
                    if (new Guid(rblOptions.Items[i].Value) == title.ResultFlagId)
                    {
                        rblOptions.Items[i].Selected = true;
                        return;
                    }
                }
            }
        }
        /// <summary>
        /// 将IDataReader的当前记录读取到GambleTitleEntity 对象
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public GambleTitleEntity LoadSingleRow(IDataReader reader)
        {
            var obj = new GambleTitleEntity();

            obj.Idx          = (System.Guid)reader["Idx"];
            obj.Title        = (System.String)reader["Title"];
            obj.IsOfficial   = (System.Int32)reader["IsOfficial"];
            obj.ResultFlagId = (System.Guid)reader["ResultFlagId"];
            obj.StartTime    = (System.DateTime)reader["StartTime"];
            obj.StopTime     = (System.DateTime)reader["StopTime"];
            obj.OpenTime     = (System.DateTime)reader["OpenTime"];
            obj.CurrentCount = (System.Int32)reader["CurrentCount"];
            obj.Status       = (System.Int32)reader["Status"];
            obj.RowTime      = (System.DateTime)reader["RowTime"];
            obj.RowVersion   = (System.Byte[])reader["RowVersion"];

            return(obj);
        }
        /// <summary>
        /// GetByOptionRateId
        /// </summary>
        /// <param name="optionRateId">optionRateId</param>
        /// <returns>GambleTitleEntity</returns>
        /// <remarks>2016/6/7 18:38:46</remarks>
        public GambleTitleEntity GetByOptionRateId(System.Int32 optionRateId)
        {
            var database = new SqlDatabase(this.ConnectionString);

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

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


            GambleTitleEntity obj = null;

            using (IDataReader reader = database.ExecuteReader(commandWrapper))
            {
                if (reader.Read())
                {
                    obj = LoadSingleRow(reader);
                }
            }
            return(obj);
        }
        /// <summary>
        /// GetByIdAndStatus
        /// </summary>
        /// <param name="idx">idx</param>
        /// <param name="status">status</param>
        /// <returns>GambleTitleEntity</returns>
        /// <remarks>2016/6/7 18:38:46</remarks>
        public GambleTitleEntity GetByIdAndStatus(System.Guid idx, System.Int32 status)
        {
            var database = new SqlDatabase(this.ConnectionString);

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

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


            GambleTitleEntity obj = null;

            using (IDataReader reader = database.ExecuteReader(commandWrapper))
            {
                if (reader.Read())
                {
                    obj = LoadSingleRow(reader);
                }
            }
            return(obj);
        }
示例#6
0
        public static bool Update(GambleTitleEntity gambleTitleEntity, DbTransaction trans = null, string zoneId = "")
        {
            var provider = new GambleTitleProvider(zoneId);

            return(provider.Update(gambleTitleEntity, trans));
        }
示例#7
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                if (ddltNeedOpenGambleTitle.Items.Count == 0)
                {
                    return;
                }

                if (rblOptions.SelectedIndex < 0)
                {
                    ShowMessage("您需要选择一个正确选项");
                    return;
                }
                System.Text.StringBuilder msg = new System.Text.StringBuilder();
                if (chkAll.Checked)
                {
                    for (int i = 0, count = SZone.Items.Count; i < count; i++)
                    {
                        try
                        {
                            GambleTitleEntity title = GambleTitleMgr.GetById(new Guid(ddltNeedOpenGambleTitle.SelectedValue), SZone.Items[i].Value);
                            if (title == null)
                            {
                                msg.Append(SZone.Items[i].Text + "|");
                                continue;
                            }

                            title.ResultFlagId = new Guid(rblOptions.SelectedValue);
                            if (!GambleTitleMgr.Update(title, null, SZone.Items[i].Value))
                            {
                                msg.Append(SZone.Items[i].Text + "|");
                            }
                        }
                        catch (Exception ex)
                        {
                            msg.Append(SZone.Items[i].Text + ";错误信息" + ex.Message + "|");
                        }
                    }
                }
                else
                {
                    GambleTitleEntity title = GambleTitleMgr.GetById(new Guid(ddltNeedOpenGambleTitle.SelectedValue), ZoneId);
                    if (title == null)
                    {
                        ShowMessage("竞猜主题为空,不能公布任何选项!");
                        return;
                    }
                    //System.Text.StringBuilder msg = new System.Text.StringBuilder();
                    title.ResultFlagId = new Guid(rblOptions.SelectedValue);
                    if (!GambleTitleMgr.Update(title, null, ZoneId))
                    {
                        msg.Append(SZone.SelectedItem.Text + "|");
                    }
                }
                if (msg.Length > 0)
                {
                    ShowMessage(msg.ToString() + "发布正确选项失败!");
                }
                else
                {
                    ShowMessage("成功发布正确选项!");
                }
            }
            catch (Exception ex)
            {
                ShowMessage(ex.Message);
            }
        }
示例#8
0
        /// <summary>
        /// 坐庄
        /// </summary>
        /// <param name="managerId">庄家ID</param>
        /// <param name="rateStr">赔率字符串(以‘|’分割)</param>
        /// <param name="gambleTitleId">竞猜的主题ID</param>
        /// <param name="hostMoney">奖池的奖金</param>
        public AuctionBuyResponse ToBeHost(Guid managerId, string rateStr, Guid gambleTitleId, int hostMoney, string zoneId = "")
        {
            AuctionBuyResponse mc = new AuctionBuyResponse();

            //如果赔率是空  默认   2|2|2
            if (string.IsNullOrEmpty(rateStr))
            {
                rateStr = "2|2|2";
            }
            try
            {
                #region 各种验证
                //奖池不得低于5000点券
                if (hostMoney < CacheFactory.AppsettingCache.GetAppSettingToInt(EnumAppsetting.MinGamblePoolMoney))
                {
                    mc.Code = (int)MessageCode.GambleNotEnoughMoney;
                    return(mc);
                }
                //是否存在该题目
                GambleTitleEntity gte = GambleTitleMgr.GetById(gambleTitleId, zoneId);
                if (gte == null)
                {
                    mc.Code = (int)MessageCode.GambleTitleNoExist;
                    return(mc);
                }
                //该题目是否允许玩家坐庄
                if (managerId != LeagueConst.GambleNpcId)
                {
                    if (gte.IsOfficial == 1)
                    {
                        mc.Code = (int)MessageCode.ThisGambleTitleIsOfficial;
                        return(mc);
                    }
                }

                //最多三个庄家,检查有没有超过3家
                if (gte.CurrentCount >= 3)
                {
                    mc.Code = (int)MessageCode.GambleHostsIsFull;
                    return(mc);
                }
                //竞猜还没有开始
                if (gte.StartTime > DateTime.Now)
                {
                    mc.Code = (int)MessageCode.GambleNotStart;
                    return(mc);
                }

                if (gte.StopTime < DateTime.Now)
                {
                    mc.Code = (int)MessageCode.GambleNotStart;
                    return(mc);
                }



                //验证赔率和玩家资金

                string[] rateArr = rateStr.Split('|');
                List <GambleOptionEntity> optionList = GambleOptionMgr.GetByTitleId(gambleTitleId, zoneId);
                if (optionList == null || optionList.Count == 0 || optionList.Count != rateArr.Length)
                {
                    mc.Code = (int)MessageCode.GambleParamError;
                    return(mc);
                }
                decimal[] rateArrM = new decimal[rateArr.Length];
                for (int i = 0, count = optionList.Count; i < count; i++)
                {
                    rateArrM[i] = decimal.Round(Convert.ToDecimal(rateArr[i]), 2);
                }

                #endregion

                //支付奖金

                string           billingId = "Gamble" + ShareUtil.GenerateComb();
                GambleHostEntity ghe       = new GambleHostEntity();
                ghe.ManagerId = managerId;
                if (managerId == LeagueConst.GambleNpcId)
                {
                    ghe.ManagerName = "Official_Manager";
                }
                else
                {
                    ghe.ManagerName = ManagerCore.Instance.GetManager(managerId).Name;
                }
                ghe.TitleId    = gambleTitleId;
                ghe.Status     = 0;
                ghe.RowTime    = DateTime.Now;
                ghe.TotalMoney = hostMoney;
                ghe.HostMoney  = hostMoney;
                string conn = ConnectionFactory.Instance.GetConnectionString(zoneId, EnumDbType.Main);
                using (var transactionManager = new TransactionManager(conn))
                {
                    transactionManager.BeginTransaction();
                    if (managerId != LeagueConst.GambleNpcId)
                    {
                        MessageCode code = PayCore.Instance.GambleTrueMatch(managerId, hostMoney, billingId, transactionManager.TransactionObject);
                        if (code != MessageCode.Success)
                        {
                            transactionManager.Rollback();
                            mc.Code = (int)code;
                            return(mc);
                        }
                    }
                    bool addResult = GambleTitleMgr.AddCount(gambleTitleId, transactionManager.TransactionObject, zoneId);
                    if (!addResult)
                    {
                        transactionManager.Rollback();
                        mc.Code = (int)MessageCode.GambleHostsIsFull;
                        return(mc);
                    }
                    int idxx = 0;
                    if (!GambleHostMgr.InsertOnce(managerId, ghe.ManagerName, ghe.TitleId, ghe.HostMoney, ghe.TotalMoney, ghe.RowTime, ref idxx, transactionManager.TransactionObject))
                    {
                        transactionManager.Rollback();
                        mc.Code = (int)MessageCode.GambleOnlyOnce;
                        return(mc);
                    }
                    ghe.Idx = idxx;
                    GambleHostoptionrateEntity ghoe = new GambleHostoptionrateEntity();
                    ghoe.HostId  = ghe.Idx;
                    ghoe.Status  = 0;
                    ghoe.RowTime = DateTime.Now;
                    for (int i = 0, count = optionList.Count; i < count; i++)
                    {
                        ghoe.OptionId = optionList[i].Idx;
                        ghoe.WinRate  = rateArrM[i];
                        if (!GambleHostoptionrateMgr.Insert(ghoe, transactionManager.TransactionObject, zoneId))
                        {
                            transactionManager.Rollback();
                            mc.Code = (int)MessageCode.GambleHostRateInsertError;
                            return(mc);
                        }
                    }
                    transactionManager.Commit();
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("Gamble.ToBeHost", ex);
                mc.Code = (int)MessageCode.Exception;
                return(mc);
            }
            mc.Data = new AuctionBuyEntity();
            if (managerId != LeagueConst.GambleNpcId)
            {
                mc.Data.ManagerPoint = PayCore.Instance.GetPoint(managerId);
            }
            mc.Code = (int)MessageCode.Success;
            return(mc);
        }
示例#9
0
        /// <summary>
        /// 玩家参与竞猜
        /// </summary>
        /// <param name="managerId">经理ID</param>
        /// <param name="gambleMoney">下注金额</param>
        /// <param name="optionRateId">庄家的哪个选项的竞猜</param>
        /// <returns>是否参与成功</returns>
        public AuctionBuyResponse AttendGamble(Guid managerId, int gambleMoney, int optionRateId)
        {
            #region 各种验证

            NbManagerEntity manager = ManagerCore.Instance.GetManager(managerId);

            AuctionBuyResponse mc = new AuctionBuyResponse();
            if (gambleMoney < 1)
            {
                mc.Code = (int)MessageCode.GambleTooPoor;
                return(mc);
            }
            if (manager == null)
            {
                mc.Code = (int)MessageCode.LoginNoUser;
                return(mc);
            }
            //是否存在该题目
            GambleTitleEntity gte = GambleTitleMgr.GetByOptionRateId(optionRateId);
            if (gte == null)
            {
                mc.Code = (int)MessageCode.GambleTitleNoExist;
                return(mc);
            }

            //竞猜还没有开始
            if (gte.StartTime > DateTime.Now)
            {
                mc.Code = (int)MessageCode.GambleNotStart;
                return(mc);
            }

            if (gte.StopTime < DateTime.Now)
            {
                mc.Code = (int)MessageCode.GambleNotStart;
                return(mc);
            }

            //检查奖金是否够支付
            GambleHostoptionrateEntity ore = GambleHostoptionrateMgr.GetById(optionRateId);
            if (ore == null || ore.Idx == 0)
            {
                mc.Code = (int)MessageCode.Exception;
                return(mc);
            }
            GambleHostEntity he = GambleHostMgr.GetById(ore.HostId);
            if (he == null || he.Idx == 0)
            {
                mc.Code = (int)MessageCode.Exception;
                return(mc);
            }
            decimal needMoney = (decimal)(ore.GambleMoney + gambleMoney) * ore.WinRate;
            if (needMoney > he.TotalMoney)
            {
                mc.Code = (int)MessageCode.GambleNeedMoreTotalMoney;
                return(mc);
            }

            //不能竞猜自己发起的主题
            if (managerId == he.ManagerId)
            {
                mc.Code = (int)MessageCode.GambleCannotGambleSelf;
                return(mc);
            }
            //压住金额20钻石:任意等级       100钻石:需VIP3        300钻石:需VIP5
            mc.Code = (int)MessageCode.NbFunctionNotOpen;
            switch (manager.Level)
            {
            case 0:
            case 1:
            case 2:
                if (gambleMoney != 20)
                {
                    return(mc);
                }
                break;

            case 3:
            case 4:
                if (gambleMoney != 20 || gambleMoney != 100)
                {
                    return(mc);
                }
                break;

            default:
                if (gambleMoney != 20 || gambleMoney != 100 || gambleMoney != 300)
                {
                    return(mc);
                }
                break;
            }
            //支付金额
            string billingId = "Gamble_" + ShareUtil.GenerateComb().ToString();

            GambleDetailEntity de = new GambleDetailEntity();
            de.ManagerId    = managerId;
            de.ManagerName  = manager.Name;
            de.GambleMoney  = gambleMoney;
            de.HostOptionId = ore.Idx;
            de.ResultMoney  = 0;
            de.Status       = 0;
            de.RowTime      = DateTime.Now;
            try
            {
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
                {
                    transactionManager.BeginTransaction();
                    ore.GambleMoney       += gambleMoney;
                    ore.AttendPeopleCount += 1;
                    he.TotalMoney         += gambleMoney;
                    he.AttendPeopleCount  += 1;
                    if (!GambleHostMgr.Update(he, transactionManager.TransactionObject))
                    {
                        transactionManager.Rollback();
                        mc.Code = (int)MessageCode.GambleTooManyPeopleIsGambling;
                        return(mc);
                    }
                    if (!GambleHostoptionrateMgr.Update(ore, transactionManager.TransactionObject))
                    {
                        transactionManager.Rollback();
                        mc.Code = (int)MessageCode.GambleTooManyPeopleIsGambling;
                        return(mc);
                    }
                    if (!GambleDetailMgr.Insert(de, transactionManager.TransactionObject))
                    {
                        transactionManager.Rollback();
                        mc.Code = (int)MessageCode.GambleTooManyPeopleIsGambling;
                        return(mc);
                    }
                    MessageCode code = PayCore.Instance.GambleTrueMatch(managerId, gambleMoney, billingId, transactionManager.TransactionObject);
                    if (code != MessageCode.Success)
                    {
                        transactionManager.Rollback();
                        mc.Code = (int)MessageCode.GamblePayError;
                        return(mc);
                    }
                    transactionManager.Commit();
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("Gamble.AttendGamble", ex);
                mc.Code = (int)MessageCode.Exception;
            }
            #endregion
            mc.Data = new AuctionBuyEntity();
            mc.Data.ManagerPoint = PayCore.Instance.GetPoint(managerId);
            return(mc);
        }
示例#10
0
        /// <summary>
        /// 增加奖池奖金
        /// </summary>
        /// <param name="managerId">经理ID</param>
        /// <param name="gambleTitleId">竞猜主题ID</param>
        /// <param name="addMoney">需要增加的金额</param>
        /// <returns>是否增加奖金成功</returns>
        public AuctionBuyResponse AddMoney(Guid managerId, Guid gambleTitleId, int addMoney)
        {
            #region 各种验证
            AuctionBuyResponse mc = new AuctionBuyResponse();
            GambleHostEntity   he = GambleHostMgr.GetByManagerIdAndTitleId(managerId, gambleTitleId);
            if (he == null)
            {
                mc.Code = (int)MessageCode.GambleTitleNoExist;
                return(mc);
            }
            //是否存在该题目
            GambleTitleEntity gte = GambleTitleMgr.GetById(he.TitleId);

            if (gte == null)
            {
                mc.Code = (int)MessageCode.GambleTitleNoExist;
                return(mc);
            }
            //该题目是否允许玩家坐庄
            if (gte.IsOfficial == 1)
            {
                mc.Code = (int)MessageCode.ThisGambleTitleIsOfficial;
                return(mc);
            }

            //竞猜还没有开始
            if (gte.StartTime > DateTime.Now)
            {
                mc.Code = (int)MessageCode.GambleNotStart;
                return(mc);
            }

            if (gte.StopTime < DateTime.Now)
            {
                mc.Code = (int)MessageCode.GambleNotStart;
                return(mc);
            }

            //GambleHostEntity he = GambleHostMgr.GetByManagerIdAndTitleId(managerId, gambleTitleId);
            if (he == null || he.Idx == 0)
            {
                mc.Code = (int)MessageCode.GambleUareNotHost;
                return(mc);
            }


            #endregion

            //支付奖金
            string billingId = "Gamble_" + ShareUtil.GenerateComb().ToString();
            try
            {
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
                {
                    transactionManager.BeginTransaction();
                    MessageCode code = PayCore.Instance.GambleTrueMatch(managerId, addMoney, billingId, transactionManager.TransactionObject);
                    if (code != MessageCode.Success)
                    {
                        transactionManager.Rollback();
                        mc.Code = (int)MessageCode.GamblePayError;
                        return(mc);
                    }
                    he.TotalMoney += addMoney;
                    he.HostMoney  += addMoney;
                    bool updateResult = GambleHostMgr.Update(he, transactionManager.TransactionObject);
                    if (!updateResult)
                    {
                        transactionManager.Rollback();
                        mc.Code = (int)MessageCode.GambleAddMoneyError;
                        return(mc);
                    }
                    transactionManager.Commit();
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("Gamble.AddMoney", ex);
                mc.Code = (int)MessageCode.Exception;
            }
            mc.Data = new AuctionBuyEntity();
            mc.Data.ManagerPoint = PayCore.Instance.GetPoint(managerId);
            return(mc);
        }