Exemplo n.º 1
0
        protected void gvBetLog_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "ReturnBet")
            {
                var bet = new Bet(Convert.ToInt32(e.CommandArgument.ToString()));

                try
                {
                    if (bet.UserID == userid)
                    {
                        Bet.ReturnBet(bet.ID);
                        ClientScript.RegisterClientScriptBlock(typeof (string), "success",
                            "alert('投注退还成功');window.location.href=window.location.href", true);
                    }
                    else
                        throw new Exception("非本人投注项");
                }
                catch
                {
                    ClientScript.RegisterClientScriptBlock(typeof (string), "failed", "alert('投注退还失败');", true);
                }

                BindData();
            }
        }
Exemplo n.º 2
0
        protected void btnMatchResult_Click(object sender, EventArgs e)
        {
            try
            {
                var guid = CasinoItem.GetCasinoItemGuidByMatch(CurrentMatch, CasinoType.MatchResult);

                if (guid.HasValue)
                {
                    if (CasinoItem.GetCasinoItem(guid.Value).CloseTime < DateTime.Now)
                    {
                        throw new Exception("已超出投注截止时间");
                    }

                    if (Bet.GetUserCasinoItemAllBet(userid, guid.Value).Count > 0)
                    {
                        throw new Exception("已经投过此注,不能重复猜比分");
                    }

                    var bet = new Bet
                    {
                        BetAmount = null,
                        BetRate = null,
                        CasinoItemGuid = guid.Value,
                        UserID = userid,
                        UserName = username
                    };

                    var matchResult = new MatchResultBetDetail
                    {
                        Home = Convert.ToInt16(tbHome.Text),
                        Away = Convert.ToInt16(tbAway.Text)
                    };

                    bet.Insert(matchResult);

                    ClientScript.RegisterClientScriptBlock(typeof(string), "succeed",
                        "alert('投注成功'); window.location.href = window.location.href;", true);
                }
            }
            catch (Exception ex)
            {
                ClientScript.RegisterClientScriptBlock(typeof(string), "failed", $"alert('{ex.Message}')", true);
            }
        }
Exemplo n.º 3
0
        protected void gvBet_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "ReturnBet")
            {
                var bet = new Bet(Convert.ToInt32(e.CommandArgument.ToString()));

                try
                {
                    Bet.ReturnBet(bet.ID);
                    ClientScript.RegisterClientScriptBlock(typeof (string), "success",
                        "alert('投注退还成功');window.location.href=window.location.href", true);
                }
                catch (Exception ex)
                {
                    ClientScript.RegisterClientScriptBlock(typeof (string), "failed", $"alert('{ex.Message}');", true);
                }

                BindData();
            }
        }
Exemplo n.º 4
0
        //public static void CleanNoCasinoItemBet()
        //{
        //    using (var conn = SQLConn.GetConnection())
        //    {
        //        conn.Open();
        //        var trans = conn.BeginTransaction();
        //        try
        //        {
        //            DataAccess.Bet.CleanBet(trans);
        //            DataAccess.BetDetail.CleanBetDetail(trans);
        //            trans.Commit();
        //        }
        //        catch
        //        {
        //            trans.Rollback();
        //        }
        //        //conn.Close();
        //    }
        //}
        public static void ReturnBet(int key)
        {
            using (var conn = SQLConn.GetConnection())
            {
                conn.Open();
                var trans = conn.BeginTransaction();
                try
                {
                    var bet = new Bet(key);

                    if (bet.BetAmount.HasValue && bet.BetAmount >= 0f)
                    {
                        var betAmount = Convert.ToSingle(bet.BetAmount);

                        var banker = new Banker(CasinoItem.GetCasinoItem(bet.CasinoItemGuid).BankerID);
                        var gambler = new Gambler(bet.UserID, trans);

                        gambler.Cash += betAmount;
                        gambler.TotalBet -= betAmount;
                        banker.Cash -= betAmount;

                        gambler.Update(trans);
                        banker.Update(trans);
                    }
                    else if (!bet.BetAmount.HasValue && !bet.Earning.HasValue && bet.EarningDesc == "RP+1")
                    {
                        Users.UpdateUserExtCredits(bet.UserID, 4, -1);
                    }

                    DataAccess.Bet.DeleteBetById(key, trans);
                    DataAccess.BetDetail.CleanBetDetail(trans);
                    trans.Commit();
                }
                catch
                {
                    trans.Rollback();
                }
            }
        }
Exemplo n.º 5
0
        public void CalcBonus()
        {
            if (string.IsNullOrEmpty(ResultHome.ToString()) || string.IsNullOrEmpty(ResultAway.ToString()))
            {
                throw new Exception("You can not calc bonus without a match result");
            }

            using (var conn = SQLConn.GetConnection())
            {
                conn.Open();
                var trans = conn.BeginTransaction();

                try
                {
                    var itemGuid = DataAccess.CasinoItem.GetCasinoItemGuidByMatch(MatchGuid,
                                                                                  (int)CasinoType.SingleChoice, trans);

                    if (itemGuid.HasValue)
                    {
                        //single choice bonus
                        var item   = CasinoItem.GetCasinoItem(itemGuid.Value);
                        var banker = new Banker(item.BankerID);

                        var totalEarning = 0f;

                        var betList = Bet.GetBetByCasinoItemGuid(itemGuid.Value, trans);

                        foreach (var bet in betList)
                        {
                            var dt = DataAccess.BetDetail.GetBetDetailByBetId(bet.ID);

                            if (dt != null)
                            {
                                var gambler = new Gambler(bet.UserID, trans);

                                if (bet.IsWin == null)
                                {
                                    var isWin = false;

                                    var dr = dt.Rows[0];

                                    if (dr["DetailName"].ToString() == MatchChoiceOption.HomeWinValue &&
                                        ResultHome > ResultAway)
                                    {
                                        isWin = true;
                                    }
                                    else if (dr["DetailName"].ToString() == MatchChoiceOption.DrawValue &&
                                             ResultHome == ResultAway)
                                    {
                                        isWin = true;
                                    }
                                    else if (dr["DetailName"].ToString() == MatchChoiceOption.AwayWinValue &&
                                             ResultHome < ResultAway)
                                    {
                                        isWin = true;
                                    }

                                    bet.IsWin = isWin;

                                    if (bet.BetAmount.HasValue)
                                    {
                                        totalEarning += bet.BetAmount.Value;

                                        if (isWin)
                                        {
                                            bet.Earning = bet.BetAmount * bet.BetRate;

                                            if (bet.Earning != null)
                                            {
                                                bet.EarningDesc = $"{bet.Earning.Value:N2}";

                                                totalEarning -= bet.Earning.Value;

                                                //add gambler cash

                                                gambler.Cash += bet.Earning.Value;
                                                gambler.Win++;

                                                banker.Cash -= bet.Earning.Value;
                                            }
                                        }
                                        else
                                        {
                                            gambler.Lose++;

                                            bet.Earning     = 0;
                                            bet.EarningDesc = string.Empty;
                                        }
                                    }
                                }

                                bet.Update(trans);
                                gambler.Update(trans);
                            }
                        }

                        banker.Update(trans);

                        item.Earning = totalEarning;
                        item.Save(trans);
                    }

                    itemGuid = DataAccess.CasinoItem.GetCasinoItemGuidByMatch(MatchGuid, (int)CasinoType.MatchResult,
                                                                              trans);

                    if (itemGuid.HasValue)
                    {
                        //match result bonus
                        var betList = Bet.GetBetByCasinoItemGuid(itemGuid.Value, trans);

                        var item = CasinoItem.GetCasinoItem(itemGuid.Value);
                        item.Earning = 0;
                        item.Save(trans);

                        foreach (var bet in betList)
                        {
                            var gambler = new Gambler(bet.UserID, trans);

                            var dt = DataAccess.BetDetail.GetBetDetailByBetId(bet.ID);

                            var betDetail = new MatchResultBetDetail(dt);

                            if (bet.IsWin == null)
                            {
                                if (betDetail.Home == ResultHome && betDetail.Away == ResultAway)
                                {
                                    //win
                                    bet.IsWin       = true;
                                    bet.Earning     = 0;
                                    bet.EarningDesc = "RP+1";

                                    gambler.Win++;

                                    //update user rp

                                    Users.UpdateUserExtCredits(bet.UserID, 4, 1);
                                }
                                else
                                {
                                    //lose
                                    bet.IsWin       = false;
                                    bet.Earning     = 0;
                                    bet.EarningDesc = string.Empty;

                                    gambler.Lose++;
                                }
                            }

                            bet.Update(trans);
                            gambler.Update(trans);
                        }
                    }

                    trans.Commit();
                }
                catch
                {
                    trans.Rollback();
                }
            }
        }
Exemplo n.º 6
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in gvMatch.Rows)
            {
                var tbHomeScore = row.FindControl("tbHomeScore") as TextBox;
                var tbAwayScore = row.FindControl("tbAwayScore") as TextBox;

                if (tbHomeScore != null && tbAwayScore != null && gvMatch.DataKeys[row.RowIndex] != null)
                {
                    var matchGuid = (Guid)gvMatch.DataKeys[row.RowIndex].Value;

                    var guid = CasinoItem.GetCasinoItemGuidByMatch(matchGuid, CasinoType.MatchResult);

                    if (guid.HasValue)
                    {
                        var item = CasinoItem.GetCasinoItem(guid.Value);

                        if (item?.ItemGuid != null)
                        {
                            short homeScore, awayScore;

                            if (short.TryParse(tbHomeScore.Text, out homeScore) && short.TryParse(tbAwayScore.Text, out awayScore))
                            {
                                //save
                                if (CasinoItem.GetCasinoItem(guid.Value).CloseTime < DateTime.Now)
                                {
                                    continue;
                                }

                                if (homeScore < 0 || awayScore < 0)
                                {
                                    continue;
                                }

                                var bets = Bet.GetUserCasinoItemAllBet(userid, item.ItemGuid.Value);

                                if (bets.Count > 0)
                                {
                                    //already bet
                                    continue;
                                }

                                try
                                {
                                    var bet = new Bet
                                    {
                                        BetAmount = null,
                                        BetRate = null,
                                        CasinoItemGuid = guid.Value,
                                        UserID = userid,
                                        UserName = username
                                    };

                                    if (bet.BetCheck())
                                    {
                                        var matchResult = new MatchResultBetDetail
                                        {
                                            Home = homeScore,
                                            Away = awayScore
                                        };

                                        bet.Insert(matchResult);
                                    }
                                }
                                catch
                                {
                                    ClientScript.RegisterClientScriptBlock(typeof(string), "failed",
                                        "alert('投注失败'); window.location.href = window.location.href;", true);
                                }
                            }
                        }
                    }
                }
            }

            ClientScript.RegisterClientScriptBlock(typeof(string), "failed",
                "alert('您的投注单已提交'); window.location.href = window.location.href;", true);
        }
Exemplo n.º 7
0
        protected void btnSingleChoice_Click(object sender, EventArgs e)
        {
            try
            {
                var guid = CasinoItem.GetCasinoItemGuidByMatch(CurrentMatch, CasinoType.SingleChoice);

                if (guid.HasValue)
                {
                    if (CasinoItem.GetCasinoItem(guid.Value).CloseTime < DateTime.Now)
                    {
                        throw new Exception("已超出投注截止时间");
                    }

                    //Gambler in Lower could not bet above the SingleBetLimit of DefaultLeague (Contest)
                    var m = new Match(CurrentMatch);

                    if (m.LeagueGuid.Equals(ConfigGlobal.DefaultLeagueID))
                    {
                        if (Gambler.GetGamblerTotalBetByUserId(userid, m.LeagueGuid) < ConfigGlobal.TotalBetStandard)
                        {
                            var alreadyMatchBet = Bet.GetUserMatchTotalBet(userid, CurrentMatch);
                            float currentMatchBet;

                            if (!string.IsNullOrEmpty(tbBet.Text.Trim()) &&
                                float.TryParse(tbBet.Text.Trim(), out currentMatchBet))
                            {
                                if (ConfigGlobal.SingleBetLimit > 0 && alreadyMatchBet + currentMatchBet > ConfigGlobal.SingleBetLimit)
                                {
                                    throw new Exception(
                                        $"下半赛区博彩玩家单场投注不能超过{ConfigGlobal.SingleBetLimit.ToString("f2")}博彩币");
                                }
                            }
                        }
                    }

                    //get selected option
                    var item = (SingleChoice)CasinoItem.GetCasinoItem(guid.Value);
                    var seletedOption = item.Options.Find(option => option.OptionValue == rblSingleChoice.SelectedValue);

                    var bet = new Bet
                    {
                        BetAmount = Convert.ToSingle(tbBet.Text.Trim()),
                        BetRate = seletedOption.OptionRate,
                        CasinoItemGuid = guid.Value,
                        UserID = userid,
                        UserName = username
                    };

                    bet.Insert(seletedOption.OptionValue);

                    ClientScript.RegisterClientScriptBlock(typeof(string), "succeed",
                        "alert('投注成功'); window.location.href = window.location.href;", true);
                }
            }
            catch (Exception ex)
            {
                ClientScript.RegisterClientScriptBlock(typeof(string), "failed", $"alert('{ex.Message}')", true);
            }
        }