//prida rezervaci knihy z pohledu klienta protected void Button12_Click(object sender, EventArgs e) { int clientId = (int)Session["clientId"]; DateTime reservation_appeal = Convert.ToDateTime(null); //prida zaznam do rezervace knihy DatabaseLibrary.Reservation res = new DatabaseLibrary.Reservation(); res.client_id = clientId; res.book_id = Convert.ToInt32(ddl_reser_copy.SelectedValue); long copy_count = new DatabaseLibrary.CopyTable().SelectCount(res.book_id); long reser_count = new DatabaseLibrary.ReservationTable().SelectCount(res.book_id); if (copy_count > reser_count) { reservation_appeal = DateTime.Now; } res.reservation_date = DateTime.Now; res.reservation_appeal = reservation_appeal; new DatabaseLibrary.ReservationTable().InsertReservation(res); Response.Redirect(Request.RawUrl); }
public void InsertReservation(Reservation res) { using (MySqlConnection conn = new MySqlConnection(connString)) { conn.Open(); MySqlCommand command = new MySqlCommand(INSERT_RESERVATION, conn); /* Add parameters into the command */ command.Parameters.AddWithValue("@copy_id", res.copy_id); command.Parameters.AddWithValue("@client_id", res.client_id); command.Parameters.AddWithValue("@reservation_appeal", res.reservation_appeal); command.Parameters.AddWithValue("@reservation_date", res.reservation_date); /* Executes the command */ command.ExecuteNonQuery(); } }
public List<Reservation> SelectAll() { List<Reservation> resList = new List<Reservation>(); using (MySqlConnection conn = new MySqlConnection(connString)) { conn.Open(); MySqlCommand command = new MySqlCommand(SELECT_ALL, conn); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Reservation res = new Reservation(); res.reservation_id = reader.GetInt32("reservation_id"); res.reservation_date = reader.GetDateTime("reservation_date"); res.reservation_appeal = reader.GetDateTime("reservation_appeal"); res.client_id = reader.GetInt32("client_id"); res.book_id = reader.GetInt32("book_id"); resList.Add(res); } } return resList; }
public void Update(Reservation res) { using (MySqlConnection conn = new MySqlConnection(connString)) { conn.Open(); MySqlCommand command = new MySqlCommand(UPDATE_RESERVATION, conn); command.Parameters.AddWithValue("@book_id", res.book_id); command.Parameters.AddWithValue("@client_id", res.client_id); command.Parameters.AddWithValue("@reservation_appeal", res.reservation_appeal); command.Parameters.AddWithValue("@reservation_date", res.reservation_date); /* Executes the command */ command.ExecuteNonQuery(); } }
public Reservation SelectOne(int reservationId) { Reservation res = new Reservation(); using (MySqlConnection conn = new MySqlConnection(connString)) { conn.Open(); MySqlCommand command = new MySqlCommand(SELECT_ONE, conn); command.Parameters.AddWithValue("@reservation_id", reservationId); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { res.reservation_id = reader.GetInt32(0); res.reservation_appeal = reader.GetDateTime(1); res.reservation_date = reader.GetDateTime(2); res.client_id = reader.GetInt32(3); res.book_id = reader.GetInt32(4); } reader.Close(); } return res; }
public List<Reservation> SelectAllByClient(int clientId) { List<Reservation> resList = new List<Reservation>(); using (MySqlConnection conn = new MySqlConnection(connString)) { conn.Open(); MySqlCommand command = new MySqlCommand(SELECT_ALL_BY_CLIENT, conn); command.Parameters.AddWithValue("@client_id", clientId); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Reservation res = new Reservation(); res.reservation_id = reader.GetInt32("reservation_id"); res.reservation_date = reader.GetDateTime("reservation_date"); res.reservation_appeal = reader.GetDateTime("reservation_appeal"); res.client_id = reader.GetInt32("client_id"); res.book_id = reader.GetInt32("book_id"); res.book_name = reader.GetString("book_name"); resList.Add(res); } } return resList; }