1 19 package org.openbravo.erpCommon.ad_actionButton; 20 21 import org.openbravo.erpCommon.utility.Utility; 22 import org.openbravo.utils.FormatUtilities; 23 import org.openbravo.base.secureApp.*; 24 import org.openbravo.xmlEngine.XmlDocument; 25 import java.io.*; 26 import javax.servlet.*; 27 import javax.servlet.http.*; 28 import java.math.BigDecimal ; 29 30 import java.sql.Connection ; 32 33 import org.openbravo.erpCommon.utility.ComboTableData; 34 35 public class UpdateMaintenanceScheduled extends HttpSecureAppServlet { 36 static final BigDecimal ZERO = new BigDecimal (0.0); 37 38 39 public void init (ServletConfig config) { 40 super.init(config); 41 boolHist = false; 42 } 43 44 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 45 VariablesSecureApp vars = new VariablesSecureApp(request); 46 if (vars.commandIn("DEFAULT")) { 47 String strKey = vars.getRequestGlobalVariable("inpmaMaintPartId", "UpdateMaintenanceScheduled|inpmaMaintPartId"); 48 String strWindowId = vars.getGlobalVariable("inpwindowId", "UpdateMaintenanceScheduled|windowId", ""); 49 String strTabName = vars.getGlobalVariable("inpTabId", "UpdateMaintenanceScheduled|adTabId", ""); 50 String strPartDate = vars.getRequestGlobalVariable("inppartdate", "UpdateMaintenanceScheduled|inppartdate"); 51 52 vars.setSessionValue("UpdateMaintenanceScheduled|adProcessId", "800062"); 53 54 printPage_FS(response, vars); 55 } else if (vars.commandIn("FRAME2")) { 56 printPage_F2(response, vars); 57 } else if (vars.commandIn("FRAME1")) { 58 String strWindowId = vars.getGlobalVariable("inpWindowId", "UpdateMaintenanceScheduled|windowId"); 59 String strKey = vars.getGlobalVariable("inpmaMaintPartId", "UpdateMaintenanceScheduled|inpmaMaintPartId"); 60 String strTabId = vars.getGlobalVariable("inpTabId", "UpdateMaintenanceScheduled|adTabId"); 61 String strProcessId = vars.getGlobalVariable("inpadProcessId", "UpdateMaintenanceScheduled|adProcessId"); 62 String strPartDate = vars.getRequestGlobalVariable("inppartdate", "UpdateMaintenanceScheduled|inppartdate"); 63 vars.removeSessionValue("UpdateMaintenanceScheduled|windowId"); 64 vars.removeSessionValue("UpdateMaintenanceScheduled|adTabId"); 65 69 printPageDataSheet(response, vars, strKey, strWindowId, strTabId, strProcessId, strPartDate, strPartDate, null); 70 } else if (vars.commandIn("FIND")) { 71 String strWindowId = vars.getGlobalVariable("inpWindowId", "UpdateMaintenanceScheduled|windowId"); 72 String strKey = vars.getGlobalVariable("inpmaMaintPartId", "UpdateMaintenanceScheduled|inpmaMaintPartId"); 73 String strTabId = vars.getGlobalVariable("inpTabId", "UpdateMaintenanceScheduled|adTabId"); 74 String strProcessId = vars.getGlobalVariable("inpadProcessId", "UpdateMaintenanceScheduled|adProcessId"); 75 String strPartDateFrom = vars.getRequestGlobalVariable("inpPartDateFrom", "UpdateMaintenanceScheduled|inpPartDateFrom"); 76 String strPartDateTo = vars.getRequestGlobalVariable("inpPartDateTo", "UpdateMaintenanceScheduled|inpPartDateTo"); 77 String strMaintType = vars.getRequestGlobalVariable("inpMaintType", "UpdateMaintenanceScheduled|inpMaintType"); 78 79 80 printPageDataSheet(response, vars, strKey, strWindowId, strTabId, strProcessId, strPartDateFrom, strPartDateTo, strMaintType); 81 } else if (vars.commandIn("SAVE")) { 82 String strKey = vars.getStringParameter("inpmaMaintPartId"); 83 String strWindowId = vars.getStringParameter("inpWindowId"); 84 String strTabId = vars.getStringParameter("inpTabId"); 85 String strMessage = updateValues(request, vars, strKey); 86 ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTabId); 87 String strWindowPath="", strTabName=""; 88 if (tab!=null && tab.length!=0) { 89 strTabName = FormatUtilities.replace(tab[0].name); 90 strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html"; 91 } else strWindowPath = strDefaultServlet; 92 if (!strMessage.equals("")) vars.setSessionValue(strWindowId + "|" + strTabName + ".message", strMessage); 93 printPageClosePopUp(response, vars, strWindowPath); 94 } else pageErrorPopUp(response); 95 } 96 97 98 void printPage_FS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 99 if (log4j.isDebugEnabled()) log4j.debug("Output: FrameSet"); 100 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/UpdateMaintenanceScheduled_FS").createXmlDocument(); 101 response.setContentType("text/html; charset=UTF-8"); 102 PrintWriter out = response.getWriter(); 103 out.println(xmlDocument.print()); 104 out.close(); 105 if (log4j.isDebugEnabled()) log4j.debug("Output: FrameSet - out"); 106 } 107 108 void printPage_F2(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 109 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame2"); 110 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/UpdateMaintenanceScheduled_F2").createXmlDocument(); 111 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 112 response.setContentType("text/html; charset=UTF-8"); 113 PrintWriter out = response.getWriter(); 114 out.println(xmlDocument.print()); 115 out.close(); 116 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame2 - Out"); 117 } 118 119 void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strKey, String strWindowId, String strTabId, String strProcessId, String strPartDateFrom, String strPartDateTo, String strMaintType) throws IOException, ServletException { 120 if (log4j.isDebugEnabled()) log4j.debug("Output: values "); 121 String [] discard = {""}; 122 UpdateMaintenanceScheduledData[] data = null; 123 if (strMaintType == null) strMaintType = ""; 124 if (strPartDateTo == null) strPartDateTo = ""; 125 data = UpdateMaintenanceScheduledData.select(this, vars.getLanguage(), strPartDateFrom, strPartDateTo, strMaintType); 126 127 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/UpdateMaintenanceScheduled_F1", discard).createXmlDocument(); 128 129 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 130 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 131 xmlDocument.setParameter("key", strKey); 132 xmlDocument.setParameter("windowId", strWindowId); 133 xmlDocument.setParameter("tabId", strTabId); 134 135 xmlDocument.setParameter("partDateFrom", strPartDateFrom); 136 xmlDocument.setParameter("partDateTo", strPartDateTo); 137 xmlDocument.setParameter("maintType", strMaintType); 138 139 try { 140 ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "", "Maintenance type", "", Utility.getContext(this, vars, "#User_Org", "UpdateMaintenanceScheduled"), Utility.getContext(this, vars, "#User_Client", "UpdateMaintenanceScheduled"), 0); 141 Utility.fillSQLParameters(this, vars, null, comboTableData, "UpdateMaintenanceScheduled", strMaintType); 142 xmlDocument.setData("reportMaintType","liststructure", comboTableData.select(false)); 143 comboTableData = null; 144 } catch (Exception ex) { 145 throw new ServletException(ex); 146 } 147 148 xmlDocument.setData("structure1", data); 149 response.setContentType("text/html; charset=UTF-8"); 150 PrintWriter out = response.getWriter(); 151 out.println(xmlDocument.print()); 152 out.close(); 153 if (log4j.isDebugEnabled()) log4j.debug("Output: values - out"); 154 } 155 156 String updateValues(HttpServletRequest request, VariablesSecureApp vars, String strKey) throws IOException, ServletException { 157 if (log4j.isDebugEnabled()) log4j.debug("Update: values"); 158 159 String [] strValueId = request.getParameterValues("strMaintScheduled"); 160 if (log4j.isDebugEnabled()) log4j.debug("Update: values after strValueID"); 161 if (strValueId == null || strValueId.length == 0) return ""; 162 Connection conn = null; 163 try { 164 conn = this.getTransactionConnection(); 165 for (int i=0; i<strValueId.length; i++) { 166 if (log4j.isDebugEnabled()) log4j.debug("*****strValueId[i]=" + strValueId[i]); 167 String done = vars.getStringParameter("strDone"+strValueId[i]); 168 if (done == null) done = ""; 169 String result = vars.getStringParameter("strResult"+strValueId[i]); 170 if (result == null) result = ""; 171 String usedtime = vars.getStringParameter("strUsedTime"+strValueId[i]); 172 String observation = vars.getStringParameter("strObservation"+strValueId[i]); 173 if (done.equals("Y")) { 174 if (log4j.isDebugEnabled()) log4j.debug("Values to update: " + strValueId[i] + ", " + result + ", " + usedtime + ", " + observation); 175 UpdateMaintenanceScheduledData.update(conn, this, result.equals("Y")?"Y":"N", usedtime, observation, vars.getUser(), strKey, strValueId[i]); 176 } 177 } 178 releaseCommitConnection(conn); 179 } catch (Exception e) { 180 try { 181 releaseRollbackConnection(conn); 182 } catch (Exception ignored) {} 183 e.printStackTrace(); 184 log4j.warn("Rollback in transaction"); 185 return Utility.messageBD(this, "ProcessRunError", vars.getLanguage()); 186 } return Utility.messageBD(this, "Success", vars.getLanguage()); 188 } 189 190 191 public String getServletInfo() { 192 return "Servlet that presents the Create From Multiple button"; 193 } } 195 | Popular Tags |