protected void Server_ValidatePass(object source, ServerValidateEventArgs args) { // --- regras if (oldpass.Text.StartsWith(" ")) { args.IsValid = false; } if (oldpass.Text.Trim().Length == 0) { args.IsValid = false; } Common.Data.UserTO userTO = (Common.Data.UserTO)Session["user"]; Common.Data.UserTO userTO2 = Common.Data.User.GetUserByLoginPass(userTO.nick, Request["oldpass"], true); if (userTO2 == null) { args.IsValid = false; } // --- feedback if (!args.IsValid) { lbl_OldPass.Text = "(Inválida)"; } }
private void ProcessBuy() { if (Page.IsPostBack && Request.Url.Host == Request.UrlReferrer.Host && Request.HttpMethod == "POST") { Common.Data.UserTO userTO = (Common.Data.UserTO)Session["user"]; float credits = float.Parse(Page.Request["buyvalue"]); int bank = int.Parse(Page.Request["bank"]); CheckPendingRequests(); CreditBuyRequestTO to = new CreditBuyRequestTO(); to.id = 0; to.request_date = DateTime.Now; to.credits = credits + Common.Data.CreditBuyRequest.CentsFromBank(bank); while (Common.Data.CreditBuyRequest.ValueExistsFromBank(bank, to.credits)) { to.credits += 0.01f; } to.user_id = userTO.id; to.bank_id = bank; to.confirmation_date = null; to.cancellation_date = null; to.adm_user_id = null; Common.Data.CreditBuyRequest.Insert(to); Response.Redirect("BuyRequestConfirmation.aspx"); } }
protected void ProcessRegister() { if (Page.IsPostBack && Request.Url.Host == Request.UrlReferrer.Host && Request.HttpMethod == "POST") { // // altera usuário // Common.Data.UserTO userTO = (Common.Data.UserTO)Session["user"]; // verifica se a senha antiga bate... Common.Data.UserTO userTO2 = Common.Data.User.GetUserByLoginPass(userTO.nick, Request["oldpass"], true); if (userTO2 == null) { // senha inválida... Response.Redirect("Default.aspx"); } string[] genders = { "M", "F" }; // muda a senha... if (Page.Request["pass1"] != null && Page.Request["pass1"].Length > 0) { userTO.password = Page.Request["pass1"]; Common.Data.User.UpdatePassword(userTO); } if (Page.Request["avatar"] != null) { userTO.avatar_url = (string)Page.Request["avatar"]; } else { userTO.avatar_url = ""; } userTO.birthday = DateTime.Parse(Page.Request["birthday"]); userTO.gender = genders[int.Parse(Page.Request["gender"]) - 1]; userTO.newsletters = (Page.Request["newsletters"] != null && Page.Request["newsletters"].ToLower() == "on"); // tenta atualizar //try { Common.Data.User.Update(userTO); Session["user"] = userTO; } //catch //{ // // erro // Response.Redirect("RegisterError.aspx"); //} Response.Redirect("MyAccount.aspx"); } }
/// <summary> /// Verifica as requisições em aberto, se existir alguma, redireciona para página de erro /// </summary> private void CheckPendingRequests() { Common.Data.UserTO userTO = (Common.Data.UserTO)Session["user"]; List <Common.Data.CreditBuyRequestTO> requests = Common.Data.CreditBuyRequest.GetBuyRequestListByUserId(userTO.id, true); if (requests.Count > 0) { // já existe requisição em aberto... Response.Redirect("BuyRequestExists.aspx"); } }
private void ProcessCancel() { if (Page.IsPostBack && Request.Url.Host == Request.UrlReferrer.Host && Request.HttpMethod == "POST") { Common.Data.UserTO userTO = (Common.Data.UserTO)Session["user"]; List <Common.Data.CreditBuyRequestTO> requests = Common.Data.CreditBuyRequest.GetBuyRequestListByUserId(userTO.id, true); if (requests != null && requests.Count > 0) { Common.Data.CreditBuyRequest.Cancel(requests[0].id); Response.Redirect("BuyRequest.aspx"); } } }
public BingoNextInfoTO NextInfo(string session) { WebLoggedUser webUser = Global.GetRegisteredBySession(session); if (webUser == null) { return(null); } Common.Data.UserTO userTO = Global.GetUserTOBySession(session); BingoNextInfoTO to = new BingoNextInfoTO(); List <ResultsBingoTO> nextGames = new List <ResultsBingoTO>(); nextGames = ResultsBingo.GetNextResults(false, true); to.id = nextGames[0].id; to.ticketValue = nextGames[0].ticket_value; BetInfoTO betInfo = ReservedTicketsBingo.GetBetInfo(to.id); to.totalPlayers = betInfo.total_players; to.totalTickets = betInfo.total_tickets; to.turn_type = nextGames[0].turn_type; to.gamePattern = Global.patterns[nextGames[0].pattern_idx].lines.ToArray(); to.user_credits = userTO.credits; to.user_bonus = userTO.bonus; to.user_prize = userTO.prize; BetInfoTO bet = ReservedTicketsBingo.GetBetInfo(nextGames[0].id); to.prize = bet.total_bet * (cfg.bingo_percent_prize / 100.0f); List <ReservedTicketsBingoTO> user_reservedListTO = ReservedTicketsBingo.GetTicketsList(nextGames[0].id, userTO.id, true); if (user_reservedListTO != null && user_reservedListTO.Count > 0) { to.user_ticketsCount = user_reservedListTO[0].tickets; } else { to.user_ticketsCount = 0; } return(to); }
protected void Page_Load(object sender, EventArgs e) { Common.Data.UserTO userTO = (Common.Data.UserTO)Session["user"]; if (Session["validated"] == null || (bool)Session["validated"] == false || userTO == null || userTO.access_level != Common.Data.Access_Level.Admin) { Response.Redirect("Default.aspx"); } cfg = Common.Data.MiscConfigurations.GetConfigurations(); if (Page.IsPostBack) { this.Validate(); } else { Populate(); } }
private void Populate() { Common.Data.UserTO userTO = (Common.Data.UserTO)Session["user"]; List <Common.Data.CreditBuyRequestTO> requests = Common.Data.CreditBuyRequest.GetBuyRequestListByUserId(userTO.id, true); if (requests != null && requests.Count > 0) { numero.Text = requests[0].id.ToString(); creditos.Text = Common.Util.Misc.FormatReal((float)(int)requests[0].credits); data.Text = requests[0].request_date.ToString("dd/MM/yyyy"); banco.Text = requests[0].extras.bank_name; agencia.Text = requests[0].extras.bank_agency; conta.Text = requests[0].extras.bank_account; titular.Text = requests[0].extras.bank_titular; valor.Text = Common.Util.Misc.FormatReal(requests[0].credits); } else { Response.Redirect("BuyRequest.aspx"); } }
protected void Populate() { Common.Data.UserTO userTO = (Common.Data.UserTO)Session["user"]; /* * DirectoryInfo info = new DirectoryInfo(Server.MapPath("~/img/avatars/70x70")); * FileInfo[] files = info.GetFiles("*.png"); * * images.InnerHtml = ""; * foreach (FileInfo f in files) * { * string src = f.Name; * images.InnerHtml += "<a href='javascript:SelectImage(\"" + src + "\")'><img src='" + "img/avatars/70x70/" + src + "' border='0' vspace='2' hspace='2' runat='server'></a>"; * } * avatar.Text = userTO.avatar_url; */ name.Text = userTO.name; nick.Text = userTO.nick; email.Text = userTO.email; birthday.Text = userTO.birthday.ToString("dd/MM/yyyy"); gender.SelectedIndex = (userTO.gender == "M" ? 1 : 2); newsletters.Checked = userTO.newsletters; }
/// <summary> /// Usuário entrou no bingo ou pediu atualização das informações /// </summary> public BingoInfoTO EnterAndGetInformation(string session) { DateTime currentTime = DateTime.Now; // atualiza o timeout timeoutDate = currentTime.AddMinutes(70); WebLoggedUser webUser = Global.GetRegisteredBySession(session); if (webUser == null) { return(null); } Common.Data.UserTO userTO = Global.GetUserTOBySession(session); if (webUser.bingo == null) { Global.EnterBingo(session, this); Global.ChatAddLine(null, "<b>" + userTO.nick + "</b> entrou."); } BingoInfoTO info = new BingoInfoTO(); info.currentGame = currentGame; info.currentGameTotals = currentGameTotals; info.currentGamePattern = Global.patterns[currentGamePatternIdx].lines.ToArray(); // determina as datas dos próximos jogos info.nextGames = ResultsBingo.GetNextResults(false, true); info.nextGamesTotals.Clear(); foreach (ResultsBingoTO res in info.nextGames) { info.nextGamesTotals.Add(ReservedTicketsBingo.GetBetInfo(res.id)); } // várias informações da rodada info.timeToNext = SecondsToDate(info.nextGames[0].date); DateTime serverNow = currentTime; info.serverTime = (UInt32)serverNow.TimeOfDay.TotalSeconds; info.turn_prize = currentGameTotals.total_bet * (cfg.bingo_percent_prize / 100.0f); info.turn_accum = cfg.bingo_accum; info.user_id = userTO.id; info.user_access_level = (short)userTO.access_level; info.user_nick = userTO.nick; info.user_credits = userTO.credits; info.user_bonus = userTO.bonus; info.user_prize = userTO.prize; // localiza as cartelas do jogador nessa rodada int idx = FindBingoTurnPlayerIdx(userTO.id); if (currentGame.turn_type == BingoGameType.none || idx == -1) { info.user_tickets = null; } else { info.user_tickets = currentPlayers[idx].tickets; } // determina quantas cartelas o jogador tem em cada uma das próximas rodadas for (int i = 0; i < info.nextGames.Count; i++) { List <ReservedTicketsBingoTO> user_reservedListTO = ReservedTicketsBingo.GetTicketsList(info.nextGames[i].id, userTO.id, true); if (user_reservedListTO != null && user_reservedListTO.Count > 0) { info.user_nextTicketsCount.Add(user_reservedListTO[0].tickets); } else { info.user_nextTicketsCount.Add(0); } } // retorna as bolas da rodada e o índice da última bola já sorteada info.serverBalls = serverBalls; info.currentBallIdx = currentBallIdx; GC.Collect(); return(info); }
/// <summary> /// Limpa os dados do jogo corrente /// </summary> private void ClearCurrentGame() { // ### DEBUG ### Common.Data.Log.Insert(Common.Data.Log_Type.Debug, "Finalizado: " + currentGame.id); // ### DEBUG ### // calcula o prêmio (divide pelo número de vencedores) float prize = currentGameTotals.total_bet * (cfg.bingo_percent_prize / 100.0f); if (currentGame.turn_type == BingoGameType.mega) { // se a bola vencedora for até a TOP_BOLAª, dá o acumulado também // nota: aqui a bola 1 é o índice 0 if (currentGame.winner_num_balls < TOP_BOLA) { // ### DEBUG ### Common.Data.Log.Insert(Common.Data.Log_Type.Debug, "Pago acumulado Nº " + currentGame.id + ": " + Common.Util.Misc.FormatReal(cfg.bingo_accum)); // ### DEBUG ### prize += cfg.bingo_accum; cfg.bingo_accum = cfg.bingo_initial_accum; Common.Data.MiscConfigurations.Update(cfg); } } // atualiza o prêmio do jogo que será gravado no banco currentGame.total_bet = currentGameTotals.total_bet; currentGame.total_prize = prize; // distribui o prêmio entre os vencedores float distr_prize = prize / currentGame.extras.winner_users_ids.Count; for (int i = 0; i < currentGame.extras.winner_users_ids.Count; i++) { currentGame.extras.winner_users_prizes[i] = distr_prize; Common.Data.UserTO userTO = Common.Data.User.GetUserById(currentGame.extras.winner_users_ids[i]); userTO.prize += distr_prize; Common.Data.User.Update(userTO); // insere no log o registro de pagamento do usuário Common.Data.LogTO log = new Common.Data.LogTO(); log.user_id = currentGame.extras.winner_users_ids[i]; log.log_type = Common.Data.Log_Type.BingoPrize; log.description = "Prêmio bingo rodada Nº " + currentGame.id; log.value = distr_prize; Common.Data.Log.Insert(log); } // confirma a rodada currentGame.confirmation_date = DateTime.Now; if (currentGame.winner_num_balls > 0) { ResultsBingo.Confirm(currentGame); } else { // exceção: não tem ganhador! // essa rodada não ocorreu de verdade, então cancela e devolve as apostas ResultsBingo.Cancel(currentGame.id); } currentGame.turn_type = BingoGameType.none; currentGame.id = 0; currentGame.ticket_value = 0; currentGame.winner_num_balls = 0; currentGameTotals.total_bet = 0; currentGameTotals.total_players = 0; currentGameTotals.total_tickets = 0; }