internal List <ApuestaDTO> RetrieveDTO() { MySqlConnection con = Connect(); MySqlCommand command = con.CreateCommand(); command.CommandText = "select * from apuesta"; try { con.Open(); MySqlDataReader res = command.ExecuteReader(); ApuestaDTO a = null; List <ApuestaDTO> listaApuestas = new List <ApuestaDTO>(); while (res.Read()) { Debug.WriteLine("Recuperado: " + res.GetDouble(1) + " " + res.GetDouble(2) + " " + res.GetDouble(3) + " " + res.GetString(4) + " " + res.GetString(6), res.GetString(7)); a = new ApuestaDTO(res.GetDouble(1), res.GetDouble(2), res.GetDouble(3), res.GetString(4), res.GetString(6), res.GetString(7)); listaApuestas.Add(a); } return(listaApuestas); } catch (MySqlException e) { Debug.WriteLine("Se ha producido un error de conexion"); return(null); } }
internal double RetrieveCuotas(ApuestaDTO apuesta) { MySqlConnection con = Connect(); MySqlCommand command = con.CreateCommand(); if (apuesta.TipoApuesta == "Over") { command.CommandText = " SELECT CuotaOver FROM Mercado WHERE ID = '" + apuesta.IDMercado + "';"; } else if (apuesta.TipoApuesta == "Under") { command.CommandText = " SELECT CuotaUnder FROM Mercado WHERE ID = '" + apuesta.IDMercado + "';"; } try { con.Open(); MySqlDataReader res = command.ExecuteReader(); double cuota = 0; if (res.Read()) { cuota = res.GetDouble(0); } return(cuota); } catch (MySqlException a) { Debug.WriteLine("Se ha producido un error de conexión"); return(0); } }
internal List <ApuestaDTO> RetrieveByUserEmail(string email) { MySqlConnection con = Connect(); MySqlCommand command = con.CreateCommand(); command.CommandText = "SELECT email, partido, tipo, tipoApuesta, cuota, importe FROM apuesta a JOIN usuario u JOIN mercado m WHERE email = '" + email + "' AND m.id = (SELECT mercado FROM apuesta JOIN usuario WHERE email = '" + email + "')"; try { con.Open(); MySqlDataReader res = command.ExecuteReader(); ApuestaDTO a = null; List <ApuestaDTO> apuestas = new List <ApuestaDTO>(); while (res.Read()) { a = new ApuestaDTO(res.GetString(0), res.GetInt32(1), res.GetInt32(2), res.GetDouble(3), res.GetInt32(4), res.GetDouble(5)); apuestas.Add(a); } con.Close(); return(apuestas); } catch (MySqlException e) { Debug.WriteLine("Error al conectar con la base de datos"); return(null); } }
internal ApuestaDTO Retrieve() { 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.GetDouble(1) + res.GetString(2) + res.GetDouble(3) + res.GetString(4) + res.GetInt16(5) + res.GetString(6)); a = new ApuestaDTO(res.GetDouble(1), res.GetString(2), res.GetDouble(3), res.GetString(4), res.GetInt16(5), res.GetString(6)); } con.Close(); return(a); } catch (MySqlException a) { Debug.WriteLine("Se ha producido un error de conexión"); return(null); } }
internal double Cuota(ApuestaDTO apuesta) { // MySqlConnection con = Connect(); // MySqlCommand command = con.CreateCommand(); // if (apuesta.Tipo_apuesta == "over") // { // command.CommandText = "SELECT cuota_over FROM mercado"; // } // else if (apuesta.Tipo_apuesta == "under") // { // command.CommandText = "SELECT cuota_under FROM mercado"; // } // try // { // con.Open(); // MySqlDataReader res = command.ExecuteReader(); // double cuota = 0; // if (res.Read()) // { // cuota = res.GetDouble(0); // } // con.Close(); // return cuota; //} // catch (MySqlException a) // { // Debug.WriteLine("Se ha producido un error de conexión"); // return 0; // } return(0); }
internal void Save(ApuestaDTO apuesta, double cuota) { MySqlConnection con = Connect(); MySqlCommand command = con.CreateCommand(); con.Open(); command.CommandText = "INSERT INTO apuesta(DineroApostado, TipoApuesta, Cuota, ID_Mercado, Email_Usuario) VALUES('" + apuesta.DineroApostado + "','" + apuesta.TipoApuesta + "','" + cuota.ToString(CultureInfo.CreateSpecificCulture("us-US")) + "','" + apuesta.IDMercado + "','" + apuesta.EmailUsuario + "');"; Debug.WriteLine("Comando: " + command.CommandText); command.ExecuteNonQuery(); con.Close(); }
internal void dineroUpdate(ApuestaDTO apuesta) { //MySqlConnection con = Connect(); //MySqlCommand command = con.CreateCommand(); //con.Open(); if (apuesta.Tipo_apuesta == "over") { // command.CommandText = "UPDATE mercado SET apostado_over = apostado_over + " + apuesta.Dinero_apostado + " WHERE id = " + apuesta.Id_mercado + ";"; } else if (apuesta.Tipo_apuesta == "under") { // command.CommandText = "UPDATE mercado SET apostado_under = apostado_under + " + apuesta.Dinero_apostado + " WHERE id = " + apuesta.Id_mercado + ";"; } //command.ExecuteNonQuery(); }
internal void UpdateDinero(ApuestaDTO apuesta) { MySqlConnection con = Connect(); MySqlCommand command = con.CreateCommand(); con.Open(); Debug.WriteLine("tipo: " + apuesta.TipoApuesta + apuesta.IDMercado); if (apuesta.TipoApuesta == "Over") { command.CommandText = "UPDATE Mercado SET DineroOver = DineroOver + " + apuesta.DineroApostado + " WHERE ID = " + apuesta.IDMercado + "; "; } else if (apuesta.TipoApuesta == "Under") { command.CommandText = "UPDATE Mercado SET DineroUnder = DineroUnder + " + apuesta.DineroApostado + " WHERE ID = " + apuesta.IDMercado + "; "; } command.ExecuteNonQuery(); }
internal void Save(ApuestaDTO apuesta, double tipo) { //MySqlConnection con = Connect(); // MySqlCommand command = con.CreateCommand(); //command.CommandText = "INSERT INTO Apuesta(cuota, tipo_apuesta, dinero_apostado, id_mercado, email_usuario) VALUES('" + tipo.ToString(CultureInfo.CreateSpecificCulture("us-US")) + "','" + apuesta.Tipo_apuesta + "','" + apuesta.Dinero_apostado + "','" + apuesta.Id_mercado + "','" + apuesta.Email_usuario + "');"; // Debug.WriteLine("comando " + command.CommandText); //try // { // con.Open(); // command.ExecuteNonQuery(); // con.Close(); // } // catch (MySqlException a) // { // Debug.WriteLine("Se ha producido un error de conexión"); //} }
internal List <ApuestaDTO> RetrieveDTO() { //MySqlConnection con = Connect(); //MySqlCommand command = con.CreateCommand(); //command.CommandText = "select * from apuestas"; //con.Open(); ///MySqlDataReader res = command.ExecuteReader(); ApuestaDTO a = null; List <ApuestaDTO> apuestas = new List <ApuestaDTO>(); /*while (res.Read()) * { * Debug.WriteLine("Recuperado: " + res.GetInt32(0) + " " + res.GetDouble(1) + " " + res.GetString(2) + " " + res.GetDouble(3) + " " + res.GetDouble(4) + " " + res.GetDateTime(5) + " " + res.GetInt32(6) + " " + res.GetString(7)); * a = new ApuestaDTO(res.GetString(7),res.GetDouble(1), res.GetDouble(3),res.GetString(2), res.GetDouble(4), res.GetDateTime(5)); * apuestas.Add(a); * }*/ //con.Close(); //return apuestas; return(null); }