예제 #1
0
        internal List <mercado> Retrieve()
        {
            //Devuelve todos los registros
            MySqlConnection con     = Connect();
            MySqlCommand    command = con.CreateCommand();

            command.CommandText = "Select(A.Cuota,A.Tipo_apuesta,A.Dinero_apostado,U.Email,M.tipo_mercado) from mercado M INNER JOIN usuario U INNER JOIN apuestas A ON A.ID_MERCADO = M.id AND A.ID_USUARIOS = U.ID; from mercado";
            con.Open();
            MySqlDataReader res = command.ExecuteReader();

            mercado        m        = null;
            List <mercado> mercados = new List <mercado>();

            //Cada vez que ecuentra un objeto lo añade al list
            //List<mercado> mercados = new List<mercado>();

            ////Devolver objeto mercado. Se devolvera un registro
            while (res.Read())
            {
                m = new mercado(res.GetString(0), res.GetDecimal(1), res.GetDecimal(2), res.GetInt32(3), res.GetFloat(4), res.GetFloat(5), res.GetInt32(6));
                mercados.Add(m);
            }

            con.Close();
            return(mercados);
        }
예제 #2
0
        internal void Save(apuestas a)
        {
            MySqlConnection con     = Connect();
            MySqlCommand    command = con.CreateCommand();

            command.CommandText = "INSERT INTO apuestas(Id,Tipo_apuesta,Cuota,Dinero_apostado,ID_MERCADO,ID_USUARIOS) values ('" + a.Id + "','" + a.Tipo_apuesta + "','" + a.Cuota + "','" + a.Dinero_apostado + "','" + a.ID_MERCADO + "','" + a.ID_USUARIOS + "');";
            Debug.WriteLine("comando" + command.CommandText);

            //Mercado asociado a la apuesta
            command.CommandText = "Select(A.Cuota,A.Tipo_apuesta,A.Dinero_apostado,U.Email,M.tipo_mercado) from mercado M INNER JOIN usuario U INNER JOIN apuestas A ON A.ID_MERCADO = M.id AND A.ID_USUARIOS = U.ID from mercado where id=" + a.ID_MERCADO;
            con.Open();
            MySqlDataReader res = command.ExecuteReader();

            mercado m = null;

            //Cada vez que ecuentra un objeto lo añade al list
            //List<mercado> mercados = new List<mercado>();

            ////Devolver objeto mercado. Se devolvera un registro
            if (res.Read())
            {
                m = new mercado(res.GetString(0), res.GetDecimal(1), res.GetDecimal(2), res.GetInt32(3), res.GetFloat(4), res.GetFloat(5), res.GetInt32(6));
            }

            con.Close();

            double Cuota_over;
            double Cuota_under;
            double prob_over;
            double prob_under;

            prob_over  = m.Dinero_over / (m.Dinero_over + m.Dinero_under);
            prob_under = m.Dinero_under / (m.Dinero_over + m.Dinero_under);

            Cuota_over  = 1 / prob_over * 0.95;
            Cuota_under = 1 / prob_under * 0.95;

            if (a.Tipo_apuesta == "over")
            {
                command.CommandText = "UPDATE mercado set Dinero_over = Dinero_over" + a.Dinero_apostado + "WHERE id =" + a.ID_MERCADO + ";";
                Debug.WriteLine("comando" + command.CommandText);
            }
            else if (a.Tipo_apuesta == "under")
            {
                command.CommandText = "UPDATE mercado set Dinero_under = Dinero_under" + a.Dinero_apostado + "WHERE id =" + a.ID_MERCADO + ";";
                Debug.WriteLine("comando" + command.CommandText);
            }

            try
            {
                con.Open();
                command.ExecuteNonQuery();
                con.Close();
            }
            catch (MySqlException e)
            {
                Debug.WriteLine("Se ha producido un error de conexión");
            }
        }
예제 #3
0
        internal void Save(apuestas a)
        {
            MySqlConnection con     = Connect();
            MySqlCommand    command = con.CreateCommand();

            command.CommandText = "INSERT INTO apuestas(Id,Tipo_apuesta,Cuota,Dinero_apostado,ID_MERCADO,ID_USUARIOS) values ('" + a.Id + "','" + a.Tipo_apuesta + "','" + a.Cuota + "','" + a.Dinero_apostado + "','" + a.ID_MERCADO + "','" + a.ID_USUARIOS + "');";
            Debug.WriteLine("comando" + command.CommandText);

            mercado m = new mercado();//modificar aquiS


            double Cuota_over;
            double Cuota_under;
            double prob_over;
            double prob_under;

            prob_over  = m.Dinero_over / (m.Dinero_over + m.Dinero_under);
            prob_under = m.Dinero_under / (m.Dinero_over + m.Dinero_under);

            Cuota_over  = 1 / prob_over * 0.95;
            Cuota_under = 1 / prob_under * 0.95;

            if (a.Tipo_apuesta == "over")
            {
                command.CommandText = "UPDATE mercado set Dinero_over = Dinero_over" + a.Dinero_apostado + "WHERE id =" + a.ID_MERCADO + ";";
                Debug.WriteLine("comando" + command.CommandText);
            }
            else if (a.Tipo_apuesta == "under")
            {
                command.CommandText = "UPDATE mercado set Dinero_under = Dinero_under" + a.Dinero_apostado + "WHERE id =" + a.ID_MERCADO + ";";
                Debug.WriteLine("comando" + command.CommandText);
            }

            try
            {
                con.Open();
                command.ExecuteNonQuery();
                con.Close();
            }
            catch (MySqlException e)
            {
                Debug.WriteLine("Se ha producido un error de conexión");
            }
        }