<%-- Document : exec_agregar_nota_ticket Created on : 25/11/2011, 02:48:46 PM Author : psoto --%> <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%@page import = "conexion.*" import = "java.sql.*" import = "own.codec.*" import = "general.Config" import = "general.Permisos" import = "java.util.Date" import = "java.text.SimpleDateFormat" %> Actualizando el sistema... <% /************************** Guarda los cambios hechos a los datos del usuario en la base de datos **************************************/ out.println(""); String nompag[] = request.getRequestURI().split("/"); Date hoy = new Date(); SimpleDateFormat formato = new SimpleDateFormat("yyyyMMdd"); String fecha_hoy = formato.format(hoy); %> <% Connection lcnt_con = null; ResultSet lrs_res = null; Statement lst_stm = null; String ls_query = new String(""); String emergent_error = new String(""); boolean lb_connection = false; String debug = new String("si"); String id_tickets = new String("si"); int consecutivo = 0; // Conexión a la base de datos try { if (!Config.getParametro("debug").equals("si")) { debug = "no"; } ConexionEquipos c = new ConexionEquipos(); lcnt_con = c.getConnection(); lst_stm = lcnt_con.createStatement(); lb_connection = true; } catch (Exception e) { emergent_error = "Error al conectarse a la base de datos "; if (debug.equals("si")) { emergent_error += e; } lb_connection = false; } //********* Validación fundamental para evitar ejecución de código sin privilegios suficientes **********// try { if (!Permisos.PermisoModulo(nompag[nompag.length - 1].toString(), Integer.parseInt(session.getAttribute("id_user").toString()))) { if (lb_connection) { lst_stm.close(); lcnt_con.close(); } emergent_error += " Privilegios insuficientes. "; lb_connection = false; } } catch (Exception e) { emergent_error += " Privilegios insuficientes. "; if (debug.equals("si")) { emergent_error += "Trace: " + e.toString(); } lb_connection = false; } //*******************************************************************************************************// if (lb_connection) { try { id_tickets = new codec().codec(request.getParameter("id_tickets"), 0); lst_stm.executeUpdate("START TRANSACTION;"); ls_query = " Select consecutivo FROM rel_notas_tickets WHERE id_tickets= " + id_tickets; lrs_res = lst_stm.executeQuery(ls_query); while (lrs_res.next()) { consecutivo = lrs_res.getInt("consecutivo"); } consecutivo = consecutivo + 1; ls_query = "INSERT INTO rel_notas_tickets (id_tickets,consecutivo,asunto,descripcion,fecha_creacion) " + " VALUES ( " + " " + id_tickets + ", " + " " + consecutivo + ", " + " '" + request.getParameter("asunto") + "', " + " '" + request.getParameter("descripcion") + "' , " + " NoW() " + " );"; lst_stm.executeUpdate(ls_query); //Registrar en la bitácora try { String mensaje_log = new String(""); mensaje_log = "Usuario -" + session.getAttribute("username").toString() + "- generó el la Nota - " + consecutivo + " - del Ticket -"+id_tickets+"-;"; Config.GuardarLog(Integer.parseInt(session.getAttribute("id_user").toString()), mensaje_log, 3); } catch (Exception e) { } session.setAttribute("mensaje_pendiente", "La Nota - " + consecutivo + " - fue registrada."); lst_stm.executeUpdate("COMMIT;"); %> <% } catch (Exception e) { emergent_error = "Error al actualizar la base de datos "; lst_stm.executeUpdate("ROLLBACK;"); if (debug.equals("si")) { emergent_error += e + " Query actual: " + ls_query; } %>
<%=emergent_error%>
<% } finally { lst_stm.close(); lcnt_con.close(); } } else { %>
<%=emergent_error%>
<% } %>