Esempio n. 1
0
        /*internal List<Apuesta> RetrieveApuestas1(String email)
         * {
         *  CultureInfo culInfo = new System.Globalization.CultureInfo("es-ES");
         *  culInfo.NumberFormat.NumberDecimalSeparator = ".";
         *  culInfo.NumberFormat.CurrencyDecimalSeparator = ".";
         *  culInfo.NumberFormat.PercentDecimalSeparator = ".";
         *  culInfo.NumberFormat.CurrencyDecimalSeparator = ".";
         *  System.Threading.Thread.CurrentThread.CurrentCulture = culInfo;
         *
         *  MySqlConnection con = Connect();
         *  MySqlCommand command = con.CreateCommand();
         *  command.CommandText = "select id_usuario from usuarios where email='"+email+"'";
         *  Debug.WriteLine("COMMAND " + command.CommandText);
         *
         *  try
         *  {
         *      Debug.WriteLine("Entro por aqui");
         *      con.Open();
         *      command.ExecuteNonQuery();
         *      con.Close();
         *  }
         *  catch (MySqlException e)
         *  {
         *      Debug.WriteLine("Se ha producido un error de conexión "+e.Message);
         *      con.Close();
         *  }
         *
         *  con.Open();
         *  MySqlDataReader reader = command.ExecuteReader();
         *
         *  reader.Read();
         *
         *  int userid = reader.GetInt32(0);
         *
         *  Debug.WriteLine("Obtento " + userid);
         *
         *  reader.Close();
         *  con.Close();
         *
         *
         *  con.Open();
         *  MySqlConnection con = Connect();
         *  MySqlCommand command = con.CreateCommand();
         *  command.CommandText = "select m.eventos_id_evento, m.over_under, a.tipo_apuesta, a.cuota, a.dinero_apostado from mercados m, apuestas a" +
         *      " where a.mercados_id_mercado=m.id_mercado and a.usuarios_id_usuarios=" + userid;
         *
         *  con.Close();
         *  try
         *  {
         *      con.Open();
         *      MySqlDataReader res = command.ExecuteReader();
         *
         *      Apuesta m = null;
         *      List<Apuesta> datos = new List<Apuesta>();
         *
         *      while (res.Read())
         *      {
         *          Debug.WriteLine("Id evento:  " + res.GetInt32(0) + " tipo mercado " + res.GetDouble(1) + " tipo apuesta : " + res.GetInt32(2)
         + " cuota : " + res.GetDouble(3) + " cinero postado : " + res.GetDouble(4));
         +
         +          m = new Apuesta(res.GetInt32(0), res.GetDouble(1), res.GetInt32(2), res.GetDouble(3), res.GetDouble(4));
         +          datos.Add(m);
         +      }
         +      con.Close();
         +      return datos;
         +  }
         +  catch (MySqlException e)
         +  {
         +      Debug.WriteLine("Error de conexión");
         +      return null;
         +  }
         +
         +
         + }*/

        internal List <Apuesta> RetrieveApuestas2(int id_mercado)
        {
            CultureInfo culInfo = new System.Globalization.CultureInfo("es-ES");

            culInfo.NumberFormat.NumberDecimalSeparator          = ".";
            culInfo.NumberFormat.CurrencyDecimalSeparator        = ".";
            culInfo.NumberFormat.PercentDecimalSeparator         = ".";
            culInfo.NumberFormat.CurrencyDecimalSeparator        = ".";
            System.Threading.Thread.CurrentThread.CurrentCulture = culInfo;

            MySqlConnection con     = Connect();
            MySqlCommand    command = con.CreateCommand();

            command.CommandText = "SELECT u.email, m.over_under, a.tipo_apuesta, a.cuota, a.dinero_apostado FROM usuarios u, mercados m, " +
                                  "apuestas a WHERE m.id_mercado= " + id_mercado + "AND a.mercados_id_mercado= " + id_mercado + " AND u.id_usuario= a.usuarios_id_usuarios;";


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

                Apuesta        m     = null;
                List <Apuesta> datos = new List <Apuesta>();

                while (res.Read())
                {
                    Debug.WriteLine("Email de usuario:  " + res.GetString(0) + " tipo de mercado:  " + res.GetDouble(1) + " tipo de apuesta: " + res.GetInt32(2)
                                    + " cuota:  " + res.GetDouble(3) + " dinero apostado:  " + res.GetDouble(4));

                    m = new Apuesta(res.GetString(0), res.GetDouble(1), res.GetInt32(2), res.GetDouble(3), res.GetDouble(4));
                    datos.Add(m);
                }
                con.Close();
                return(datos);
            }
            catch (MySqlException e)
            {
                Debug.WriteLine("Error de conexión");
                return(null);
            }
        }
 public Apuesta2 ToID(Apuesta a)
 {
     return(new Apuesta2(a.ApuestaID));
 }
 public ApuestaDTO ToDTO(Apuesta a)
 {
     return(new ApuestaDTO(a.ApuestaID, a.EventoID, a.UsuarioID, a.Tipo_apuesta, a.Cuota, a.Dinero_apostado, a.Mercado));
 }
 public Usuario2 ToExamen2(Apuesta a)
 {
     return(new Usuario2(a.Usuario.Nombre));
 }
 public ApuestaExamen ToExamen(Apuesta a)
 {
     return(new ApuestaExamen(a.Dinero_apostado, a.Tipo_apuesta, a.Cuota));
 }
        internal void insertarApuesta(Apuesta a)
        {
            CultureInfo culInfo = new System.Globalization.CultureInfo("es-ES");

            culInfo.NumberFormat.NumberDecimalSeparator = ".";

            culInfo.NumberFormat.CurrencyDecimalSeparator        = ".";
            culInfo.NumberFormat.PercentDecimalSeparator         = ".";
            culInfo.NumberFormat.CurrencyDecimalSeparator        = ".";
            System.Threading.Thread.CurrentThread.CurrentCulture = culInfo;


            Debug.WriteLine("apuesta vale " + a);

            MySqlConnection con     = Connect();
            MySqlCommand    command = con.CreateCommand();

            command.CommandText = "insert into apuesta(id_apuesta,email_fk,id_mercado_fk, tipo_apuesta, cuota, dinero_apostado) values ('" + a.IdApuesta + "','" + a.EmailFk + "' ,'" + a.IdMercado + "' ,'" + a.TipoApuesta + "' ,'" + a.DineroApostado + "');";
            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");
                con.Close();
            }


            con.Open();

            command.CommandText = "select dinero_apostado_over from mercado where id_mercado=" + a.IdMercado + "; ";

            Debug.WriteLine("COMMAND " + command.CommandText);

            MySqlDataReader reader = command.ExecuteReader();

            reader.Read();


            double dineroOver = reader.GetDouble(0);

            reader.Close();

            con.Close();



            con.Open();

            command.CommandText = "select dinero_apostado_under from mercado where id_mercado=" + a.IdMercado + "; ";

            reader = command.ExecuteReader();

            reader.Read();

            double dineroUnder = reader.GetDouble(0);

            reader.Close();

            con.Close();

            if (a.TipoApuesta == 1)
            {
                dineroOver = dineroOver + a.DineroApostado;
            }
            else
            {
                dineroUnder = dineroUnder + a.DineroApostado;
            }

            Debug.WriteLine(dineroOver);
            Debug.WriteLine(dineroUnder);

            double po = dineroOver / (dineroOver + dineroUnder);

            double pu = dineroUnder / (dineroUnder + dineroOver);

            Debug.WriteLine(po);
            Debug.WriteLine(pu);

            double co = Convert.ToDouble((1 / po) * 0.95);

            double cu = Convert.ToDouble((1 / pu) * 0.95);



            if (a.TipoApuesta == 1)
            {
                command.CommandText = "update mercado set CUOTA_OVER = '" + co + "',CUOTA_UNDER = '" + cu + "',  DINERO_APOSTADO_OVER = '" + dineroOver + "' where ID_MERCADO =" + a.IdMercado + ";";

                try

                {
                    con.Open();

                    command.ExecuteNonQuery();
                }

                catch (MySqlException e)

                {
                    Console.WriteLine("Error " + e);
                }

                con.Close();
            }
            else
            {
                command.CommandText = "update mercado set CUOTA_UNDER = '" + cu + "', CUOTA_OVER = '" + co + "',  DINERO_APOSTADO_UNDER = '" + dineroUnder + "' where ID_MERCADO =" + a.IdMercado + "; ";

                try

                {
                    con.Open();

                    command.ExecuteNonQuery();
                }

                catch (MySqlException e)

                {
                    Console.WriteLine("Error " + e);
                }

                con.Close();
            }
        }