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); }