public int getTicketCountEvent(Event _event) { int count = 0; eventDAO = EventDAOMySQL.getInstance(); int id = eventDAO.getId(_event); String sql = "SELECT id FROM ticket WHERE event_id=" + id; try { conn.Open(); MySqlCommand cmd = new MySqlCommand(sql, conn); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { id = (int)reader["id"]; count++; } } catch (MySqlException e) { Console.WriteLine(e.Message); } finally { conn.Close(); } return count; }
public bool checkTicket(Ticket ticket) { bool ok = true; eventDAO = EventDAOMySQL.getInstance(); int id = eventDAO.getId(ticket._event); String sql = "SELECT id FROM ticket WHERE event_id=" + id + " AND number=" + ticket.number + " AND row=" + ticket.row; try { conn.Open(); MySqlCommand cmd = new MySqlCommand(sql, conn); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { id = (int)reader["id"]; ok = false; } } catch (MySqlException e) { Console.WriteLine(e.Message); } finally { conn.Close(); } return ok; }
public List<Ticket> getTicketsOfEvent(Event _event) { List<Ticket> tickets = new List<Ticket>(); eventDAO = EventDAOMySQL.getInstance(); int id = eventDAO.getId(_event); String sql = "SELECT * FROM ticket WHERE event_id=" + id; try { conn.Open(); MySqlCommand cmd = new MySqlCommand(sql, conn); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Ticket ticket = new Ticket(_event, (int)reader["number"], (int)reader["row"]); tickets.Add(ticket); } } catch (MySqlException e) { Console.WriteLine(e.Message); } finally { conn.Close(); } return tickets; }
public void addTicket(Ticket ticket) { EventDAOMySQL eventDAO = EventDAOMySQL.getInstance(); int eventId = eventDAO.getId(ticket._event); String sql = "INSERT INTO ticket(`row`,`number`,`event_id`) VALUES(" + ticket.row + "," + ticket.number + "," + eventId + ");"; conn.Open(); MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.ExecuteNonQuery(); }