use of br.senac.tads3.pi03b.gruposete.models.Hotel in project Loja_Agencia_De_Viagens by ArtCouSan.
the class AlteraHotelServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int id = Integer.parseInt(request.getParameter("id"));
HotelDAO dao = new HotelDAO();
String action = request.getParameter("action");
if ("edit".equalsIgnoreCase(action)) {
try {
Hotel hoteis = dao.getHotelById(id);
request.setAttribute("hoteis", hoteis);
} catch (SQLException | ClassNotFoundException ex) {
Logger.getLogger(AlteraHotelServlet.class.getName()).log(Level.SEVERE, null, ex);
}
RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/Editar/EditarHotel.jsp");
dispatcher.forward(request, response);
}
}
use of br.senac.tads3.pi03b.gruposete.models.Hotel in project Loja_Agencia_De_Viagens by ArtCouSan.
the class AlteraHotelServlet method doPost.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
boolean erro = false;
String nome_hotel = request.getParameter("nome_hotel");
if (nome_hotel == null || nome_hotel.length() < 1) {
erro = true;
request.setAttribute("erroNome_hotel", true);
}
String data_entrada = request.getParameter("data_entrada");
if (data_entrada == null || !" / / ".equals(data_entrada)) {
erro = true;
request.setAttribute("erroData_entrada", true);
}
String data_saida = request.getParameter("data_saida");
if (data_saida == null || !" / / ".equals(data_saida)) {
erro = true;
request.setAttribute("erroData_saida", true);
}
int quantidade_quartos = Integer.parseInt(request.getParameter("quantidade_quartos"));
if (quantidade_quartos < 1) {
erro = true;
request.setAttribute("erroQuantidade_quartos", true);
}
int quantidade_hospedes = Integer.parseInt(request.getParameter("quantidade_hospedes"));
if (quantidade_hospedes < 1) {
erro = true;
request.setAttribute("erroQuantidade_hospedes", true);
}
float preco = Float.parseFloat(request.getParameter("preco"));
if (preco < 0) {
erro = true;
request.setAttribute("erroPreco", true);
}
int id = Integer.parseInt(request.getParameter("identificacao"));
if (!erro) {
Hotel hotel = new Hotel(nome_hotel, data_entrada, data_saida, quantidade_quartos, quantidade_hospedes, preco, true);
hotel.setId_hotel(id);
try {
HotelDAO dao = new HotelDAO();
dao.alterar(hotel);
HttpSession sessao = request.getSession();
sessao.setAttribute("editarHotel", hotel);
response.sendRedirect("index.jsp");
} catch (Exception ex) {
}
} else {
RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/Editar/EditarHotel.jsp");
dispatcher.forward(request, response);
}
}
use of br.senac.tads3.pi03b.gruposete.models.Hotel in project Loja_Agencia_De_Viagens by ArtCouSan.
the class HotelDAO method getHotelById.
public Hotel getHotelById(int id) throws SQLException, ClassNotFoundException {
Hotel hotel = new Hotel();
connection = DbUtil.getConnection();
String query = "SELECT * FROM Hotel WHERE id_hotel = ?";
try {
preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, id);
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
hotel.setId_hotel(resultSet.getInt("id_hotel"));
hotel.setNome(resultSet.getString("nome_hotel"));
hotel.setData_entrada(resultSet.getString("data_entrada"));
hotel.setData_saida(resultSet.getString("data_saida"));
hotel.setQuantidade_quartos(resultSet.getInt("quantidade_quartos"));
hotel.setQuantidade_hospedes(resultSet.getInt("quantidade_hospedes"));
hotel.setPreco(resultSet.getFloat("preco"));
}
} catch (SQLException e) {
}
preparedStatement.close();
connection.close();
return hotel;
}
use of br.senac.tads3.pi03b.gruposete.models.Hotel in project Loja_Agencia_De_Viagens by ArtCouSan.
the class VendaDAO method procurarHotel.
public ArrayList<Hotel> procurarHotel(String busca) throws SQLException, ClassNotFoundException {
// Conecta.
connection = DbUtil.getConnection();
ArrayList<Hotel> listaResultado = new ArrayList<>();
// Comando SQL.
String slq = "SELECT * FROM hotel WHERE ativo = true" + " AND (nome_hotel LIKE ?" + " OR data_entrada LIKE ?" + " OR data_saida LIKE ?" + " OR preco LIKE ?" + " OR quantidade_quartos LIKE ?" + " OR quantidade_hospedes LIKE ?) LIMIT 5";
PreparedStatement stmt = connection.prepareStatement(slq);
// Insercoes.
stmt.setString(1, busca);
stmt.setString(2, busca);
stmt.setString(3, busca);
stmt.setString(4, busca);
stmt.setString(5, busca);
stmt.setString(6, busca);
// Executa e recebe resultado.
ResultSet result = stmt.executeQuery();
// Declara variaveis.
int id_hotel;
String nome;
String data_entrada;
String data_saida;
int quantidade_quartos;
int quantidade_hospedes;
float preco;
// Loop com resultados.
while (result.next()) {
// Prenche.
id_hotel = (result.getInt("id_hotel"));
nome = (result.getString("nome_hotel"));
data_entrada = (result.getString("data_entrada"));
data_saida = (result.getString("data_saida"));
preco = (result.getFloat("preco"));
quantidade_quartos = (result.getInt("quantidade_quartos"));
quantidade_hospedes = (result.getInt("quantidade_hospedes"));
Hotel hotel = new Hotel(nome, data_entrada, data_saida, quantidade_quartos, quantidade_hospedes, preco, true);
hotel.setId_hotel(id_hotel);
listaResultado.add(hotel);
}
// Fecha conexao.
connection.close();
// Retorna lista.
return listaResultado;
}
use of br.senac.tads3.pi03b.gruposete.models.Hotel in project Loja_Agencia_De_Viagens by ArtCouSan.
the class VendaServlet method doGet.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, FileNotFoundException {
String cpf = request.getParameter("cpf");
ClienteDAO clienteData = new ClienteDAO();
Cliente cliente = null;
try {
cliente = clienteData.getClienteByCPF(cpf);
} catch (SQLException | ClassNotFoundException ex) {
Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
}
double totalP = Double.parseDouble(request.getParameter("totalP"));
Venda venda = new Venda(cliente.getId_cliente(), 2, totalP);
VendaDAO vendaData = new VendaDAO();
try {
vendaData.inserir(venda);
} catch (SQLException | ClassNotFoundException ex) {
Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
}
int idLista = 0;
try {
idLista = vendaData.maiorIdVenda();
} catch (SQLException | ClassNotFoundException ex) {
Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
}
String idsVoos = request.getParameter("idsVoos");
String idsHoteis = request.getParameter("idsHoteis");
String precosVoos = request.getParameter("precosVoos");
String precosHoteis = request.getParameter("precosHoteis");
String quantidadeVoos = request.getParameter("quantidadeVoos");
String quantidadeHoteis = request.getParameter("quantidadeHoteis");
String[] idsV = idsVoos.split(",");
String[] precosV = precosVoos.split(",");
String[] quantidadesV = quantidadeVoos.split(",");
String[] idsH = idsHoteis.split(",");
String[] precosH = precosHoteis.split(",");
String[] quantidadesH = quantidadeHoteis.split(",");
for (int i = 0; i < idsV.length; i++) {
try {
VooDAO voo = new VooDAO();
int idV = Integer.parseInt(idsV[i]);
Voo vooEncontrado = voo.getVooById(idV);
int qtd_encontradaV = vooEncontrado.getQuantidade_passagens();
int quantidadeV = Integer.parseInt(quantidadesV[i]);
float precoV = Float.parseFloat(precosV[i]);
int novaQtdVoo = qtd_encontradaV - quantidadeV;
vendaData.inserirLista(idV, quantidadeV, precoV, idLista, "V");
vendaData.removerEstoqueVoo(idV, novaQtdVoo);
} catch (SQLException | ClassNotFoundException ex) {
Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
for (int i = 0; i < idsH.length; i++) {
try {
HotelDAO hotel = new HotelDAO();
int idH = Integer.parseInt(idsH[i]);
Hotel hotelEncontrado = hotel.getHotelById(idH);
int qtd_encontradaH = hotelEncontrado.getQuantidade_quartos();
int quantidadeH = Integer.parseInt(quantidadesH[i]);
float precoH = Float.parseFloat(precosH[i]);
int novaQtdHotel = qtd_encontradaH - quantidadeH;
vendaData.inserirLista(idH, quantidadeH, precoH, idLista, "H");
vendaData.removerEstoqueHotel(idH, novaQtdHotel);
} catch (SQLException | ClassNotFoundException ex) {
Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
dispatcher.forward(request, response);
}
Aggregations