Beispiel #1
0
        internal MercadoDTO RetrieveMercado(ApuestaDTO apuesta)
        {
            MySqlConnection con     = connect();
            MySqlCommand    command = con.CreateCommand();

            if (apuesta.TipoApuesta == "Over")
            {
                command.CommandText = "SELECT CuotaOver FROM Mercado WHERE id = " + apuesta.Mercado_id;
            }
            else if (apuesta.TipoApuesta == "Under")
            {
                command.CommandText = "SELECT CuotaUnder FROM MercadoWHERE id = " + apuesta.Mercado_id;;
            }

            try
            {
                con.Open();
                MySqlDataReader res = command.ExecuteReader();
                MercadoDTO      m   = null;

                if (res.Read())
                {
                    m = new MercadoDTO(res.GetDouble(1), res.GetDouble(2), res.GetDouble(3), res.GetDouble(4), res.GetDouble(5), res.GetInt32(6));
                }
                con.Close();
                return(m);
            }
            catch (MySqlException a)
            {
                Debug.WriteLine("Se ha producido un error de conexión.");
                return(null);
            }
        }
Beispiel #2
0
        internal ApuestaDTO RetrieveDTO()
        {
            MySqlConnection con     = connect();
            MySqlCommand    command = con.CreateCommand();

            command.CommandText = "select * from Apuesta";
            try
            {
                con.Open();
                MySqlDataReader res = command.ExecuteReader();

                ApuestaDTO a = null;
                if (res.Read())



                {
                    Debug.WriteLine("Recuperado:  " + res.GetDateTime(1) + " " + res.GetInt32(2) + " " + res.GetString(3) + " " + res.GetInt32(4) + " " + res.GetDouble(5));
                    a = new ApuestaDTO(res.GetDateTime(1), res.GetInt32(2), res.GetString(3), res.GetInt32(4), res.GetDouble(5));
                }

                con.Close();
                return(a);
            }
            catch (MySqlException a) {
                Debug.WriteLine("Se ha producido un error de conexion");
                return(null);
            }
        }
Beispiel #3
0
        internal List <ApuestaDTO> RetrieveDTO()
        {
            MySqlConnection con     = Connect();
            MySqlCommand    command = con.CreateCommand();

            command.CommandText = "select * from Apuestas";
            try
            {
                con.Open();
                MySqlDataReader   res      = command.ExecuteReader();
                ApuestaDTO        a        = null;
                List <ApuestaDTO> apuestas = new List <ApuestaDTO>();
                while (res.Read())
                {
                    Debug.WriteLine("recuperamosdto: " + res.GetInt32(0) + " " + res.GetString(1)
                                    + " " + res.GetInt32(2) + " " + res.GetString(3) + " " +
                                    res.GetFloat(4) + " " + res.GetInt32(5) + " " + res.GetDateTime(6));
                    a = new ApuestaDTO(res.GetString(1), res.GetInt32(2), res.GetString(3), res.GetFloat(4), res.GetInt32(5));
                    apuestas.Add(a);
                }
                con.Close();
                return(apuestas);
            }
            catch (MySqlException e)
            {
                Debug.WriteLine("se ha producido un error de conexión");
                return(null);
            }
        }
        internal void Calculos(ApuestaDTO Apuesta, Mercado Dinero)
        {
            MySqlConnection con              = conect();
            MySqlCommand    command          = con.CreateCommand();
            double          probabilidadOver = Dinero.DineroOver / (Dinero.DineroOver + Dinero.DineroUnder);
            double          cuotaOver        = 0;
            double          over             = 0.95;

            if (probabilidadOver != 0)
            {
                cuotaOver = 1 / probabilidadOver * 0.95;
                over      = Math.Round((double)Convert.ToDouble(cuotaOver), 2);
            }

            double probabilidadUnder = Dinero.DineroUnder / (Dinero.DineroOver + Dinero.DineroUnder);
            double cuotaUnder        = 0;
            double under             = 0.95;

            if (probabilidadUnder != 0)
            {
                cuotaUnder = 1 / probabilidadUnder * 0.95;
                under      = Math.Round((double)Convert.ToDouble(cuotaUnder), 2);
            }



            Debug.WriteLine("under: " + cuotaUnder + "dineroOver: " + Dinero.DineroOver + "dineroUnder: " + Dinero.DineroUnder + "probabilidad: " + probabilidadUnder);
            Debug.WriteLine("under: " + under);
            con.Open();

            command.CommandText = "UPDATE Mercado SET CuotaUnder=" + under.ToString(CultureInfo.CreateSpecificCulture("us-US")) + ", CuotaOver =" + over.ToString(CultureInfo.CreateSpecificCulture("us-US")) + " WHERE ID= " + Dinero.Id + ";";
            Debug.WriteLine("Comando: " + command.CommandText);



            command.ExecuteNonQuery();
        }
        internal MercadoDTO RetrieveMercado(ApuestaDTO apuesta)
        {
            MySqlConnection con     = conect();
            MySqlCommand    command = con.CreateCommand();


            con.Open();



            if (apuesta.TipoApuesta == "Over")
            {
                command.CommandText = "UPDATE Mercado Set DineroOver = DineroOver + " + apuesta.DineroApostado + " WHERE ID= " + apuesta.Mercado_id;;
            }
            else if (apuesta.TipoApuesta == "Under")
            {
                command.CommandText = "UPDATE Mercado Set DineroUnder = DineroUnder + " + apuesta.DineroApostado + " WHERE ID= " + apuesta.Mercado_id;
            }
            try
            {
                con.Open();
                MySqlDataReader res = command.ExecuteReader();
                MercadoDTO      m   = null;

                if (res.Read())
                {
                    m = new MercadoDTO(res.GetInt32(1), res.GetInt32(2), res.GetInt32(3), res.GetDouble(4), res.GetDouble(5), res.GetInt32(6));
                }
                return(m);
            }
            catch (MySqlException a)
            {
                Debug.WriteLine("Se ha producido un error de conexión");
                return(null);
            }
        }