Ejemplo n.º 1
0
        /// <summary>
        /// realiza el jugego por un jugador
        /// </summary>
        /// <param name="dropJugador">lista del jugador</param>
        /// <param name="dropColor">lista del color</param>
        /// <param name="txtCantidadJugadorApuesta">cantidad</param>
        /// <param name="ColorRuleta">Color ramdom</param>
        /// <param name="stGanancia">donde quedara guardada la salida</param>
        /// <param name="stlblDineroActual">donde quedaará guardado el dinero acual</param>
        private void Jugar(DropDownList dropJugador, DropDownList dropColor, TextBox txtCantidadJugadorApuesta,
                           Color ColorRuleta, out string stGanancia, out string stlblDineroActual)
        {
            casinoEntities casino    = new casinoEntities();
            var            idJugador = int.Parse(dropJugador.SelectedValue);
            var            Jugador   = casino.jugadores.SingleOrDefault(j => j.id == idJugador);

            decimal recuperado = CantidadRecuperadXColor(ColorRuleta);

            var cantidadApuesta = int.Parse(txtCantidadJugadorApuesta.Text);
            var ganancia        = recuperado * cantidadApuesta;
            var mensajeGanancia = "";

            if (dropColor.SelectedItem.Text == ColorRuleta.ToString())
            {
                Jugador.cantidad = Jugador.cantidad + ganancia;
                mensajeGanancia  = $"{recuperado} veces lo apostado: ${Math.Round(ganancia, 1)}";
            }
            else
            {
                Jugador.cantidad = Jugador.cantidad - cantidadApuesta;
                mensajeGanancia  = "$0";
            }

            casino.SaveChanges();
            stGanancia        = mensajeGanancia;
            stlblDineroActual = $"${Math.Round(Jugador.cantidad, 1)}";
        }
Ejemplo n.º 2
0
        private void CargarGrid()
        {
            casinoEntities casino        = new casinoEntities();
            var            listJugadores = (from jugador in casino.jugadores
                                            select jugador).ToList();

            gvjugadores.DataSource = listJugadores;
            gvjugadores.DataBind();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// /verifica si la transaccion fu exitoisa
 /// </summary>
 /// <param name="casino">entidad a guardar</param>
 public void VerificaTran(casinoEntities casino)
 {
     if (casino.SaveChanges() > 0)
     {
         ShowMensajes("Cambios guardados exitosamente");
     }
     else
     {
         ShowMensajes("No se pudo intente de nuevo");
     }
     Limpiar();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// válida la cantidad de dinero a apostar
        /// </summary>
        /// <param name="cantidadApuesta">cantidad a apostar</param>
        /// <param name="idJugador"> id del jugador</param>
        private bool ValidaCantidad(TextBox txtCantidad, int idJugador)
        {
            if (idJugador == 0)
            {
                return(ResultadoValidaCantidad(txtCantidad, "Debe seleccionar un jugador"));
            }

            var cantidadApuesta = string.IsNullOrEmpty(txtCantidad.Text) ? 0 : decimal.Parse(txtCantidad.Text);

            if (cantidadApuesta < 1)
            {
                return(ResultadoValidaCantidad(txtCantidad, "Debe ingresar una cantidad a apostar"));
            }
            else
            {
                casinoEntities casino = new casinoEntities();

                var Cantidad = (from jugador in casino.jugadores
                                where jugador.id == idJugador
                                select jugador.cantidad).First();

                decimal ValorMinimo, ValorMaximo = 0;
                ValorMinimo = (Cantidad * 8) / 100;
                ValorMaximo = (Cantidad * 15) / 100;

                if (Cantidad <= 1000)
                {
                    ValorMaximo = ValorMinimo = Cantidad;
                }

                if (Cantidad == 0)
                {
                    FinalizarJuego();
                    return(ResultadoValidaCantidad(txtCantidad, "No tiene dinero para jugar"));
                }
                else if (cantidadApuesta < ValorMinimo || cantidadApuesta > ValorMaximo)
                {
                    if (Cantidad <= 1000)
                    {
                        return(ResultadoValidaCantidad(txtCantidad, $"El valor debe ser entre ${Math.Round(Cantidad, 1)} "));
                    }
                    else
                    {
                        return(ResultadoValidaCantidad(txtCantidad, $"El valor debe estar entre ${Math.Round(ValorMinimo, 1)} (8%)" +
                                                       $" y ${Math.Round(ValorMaximo, 1)} (15%)"));
                    }
                }
                else
                {
                    return(true);
                }
            }
        }
Ejemplo n.º 5
0
        protected void btnGuardar_Click(object sender, EventArgs e)
        {
            casinoEntities casino = new casinoEntities();

            try
            {
                if (txtJugador.Text != "")
                {
                    switch (hdfModificando.Value)
                    {
                    case nameof(opera.modifica):
                        var Id      = int.Parse(hdfID.Value);
                        var Jugador = casino.jugadores.SingleOrDefault(j => j.id == Id);
                        if (Jugador.nombre != txtJugador.Text)
                        {
                            Jugador.nombre   = txtJugador.Text;
                            Jugador.cantidad = txtJugador0.Text == "" ? 0 : int.Parse(txtJugador0.Text);
                        }
                        else
                        {
                            ShowMensajes("Modifique un nuevo nombre del jugador");
                            return;
                        }

                        break;

                    default:
                        casino.jugadores.Add(new jugadores {
                            nombre = txtJugador.Text, cantidad = 10000
                        });
                        break;
                    }

                    VerificaTran(casino);
                }
                else
                {
                    ShowMensajes("Escriba el nombre del jugador");
                    txtJugador.Focus();
                }
            }
            catch (Exception)
            {
                ShowMensajes("Error al guardar intente de nuevo");
            }
        }
Ejemplo n.º 6
0
        private void CargasListas()
        {
            casinoEntities casino = new casinoEntities();

            #region colores

            List <ValorColor> lstColores = new List <ValorColor>();
            lstColores.Add(new ValorColor {
                nombre = "Seleccione", id = 0
            });
            lstColores.AddRange(from color in casino.ValorColor
                                select color);

            ddlColor3.DataValueField = ddlColor2.DataValueField = ddlColor1.DataValueField = "id";
            ddlColor3.DataTextField  = ddlColor2.DataTextField = ddlColor1.DataTextField = "nombre";
            ddlColor3.DataSource     = ddlColor2.DataSource = ddlColor1.DataSource = lstColores;
            ddlColor1.DataBind();
            ddlColor2.DataBind();
            ddlColor3.DataBind();
            #endregion
            #region jugadores

            List <jugadores> jugadorSeleccione = new List <jugadores>();
            jugadorSeleccione.Add(new jugadores {
                nombre = "Seleccione", cantidad = 0, id = 0
            });
            List <jugadores> listJugadores = new List <jugadores>();
            listJugadores.AddRange(jugadorSeleccione);
            listJugadores.AddRange(from jugador in casino.jugadores
                                   select jugador);

            ddlJugador3.DataValueField = ddlJugador2.DataValueField = ddlJugador1.DataValueField = "Id";
            ddlJugador3.DataTextField  = ddlJugador2.DataTextField = ddlJugador1.DataTextField = "Nombre";
            ddlJugador3.DataSource     = ddlJugador2.DataSource = ddlJugador1.DataSource = listJugadores;
            ddlJugador1.DataBind();
            ddlJugador2.DataBind();
            ddlJugador3.DataBind();
            #endregion
        }
Ejemplo n.º 7
0
        protected void gvjugadores_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            txtJugador.Text = "";
            int         index = Convert.ToInt32(e.CommandArgument);
            GridViewRow row   = gvjugadores.Rows[index];

            hdfID.Value = gvjugadores.DataKeys[index].Values["id"].ToString();
            var            Id      = int.Parse(hdfID.Value);
            casinoEntities casino  = new casinoEntities();
            var            Jugador = casino.jugadores.SingleOrDefault(j => j.id == Id);

            if (e.CommandName == "Modificar")
            {
                txtJugador.Text      = Jugador.nombre;
                txtJugador0.Text     = Math.Round(Jugador.cantidad).ToString();
                hdfModificando.Value = nameof(opera.modifica);
            }
            else if (e.CommandName == "Eliminar")
            {
                casino.jugadores.Remove(Jugador);
                VerificaTran(casino);
            }
        }