KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_actionButton > UpdateMaintenanceScheduled


1 /*
2  *************************************************************************
3  * The contents of this file are subject to the Openbravo Public License
4  * Version 1.0 (the "License"), being the Mozilla Public License
5  * Version 1.1 with a permitted attribution clause; you may not use this
6  * file except in compliance with the License. You may obtain a copy of
7  * the License at http://www.openbravo.com/legal/license.html
8  * Software distributed under the License is distributed on an "AS IS"
9  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10  * License for the specific language governing rights and limitations
11  * under the License.
12  * The Original Code is Openbravo ERP.
13  * The Initial Developer of the Original Code is Openbravo SL
14  * All portions are Copyright (C) 2001-2006 Openbravo SL
15  * All Rights Reserved.
16  * Contributor(s): ______________________________________.
17  ************************************************************************
18 */

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 JavaDoc;
29
30 // imports for transactions
31
import java.sql.Connection JavaDoc;
32
33 import org.openbravo.erpCommon.utility.ComboTableData;
34
35 public class UpdateMaintenanceScheduled extends HttpSecureAppServlet {
36   static final BigDecimal JavaDoc ZERO = new BigDecimal JavaDoc(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 JavaDoc strKey = vars.getRequestGlobalVariable("inpmaMaintPartId", "UpdateMaintenanceScheduled|inpmaMaintPartId");
48       String JavaDoc strWindowId = vars.getGlobalVariable("inpwindowId", "UpdateMaintenanceScheduled|windowId", "");
49       String JavaDoc strTabName = vars.getGlobalVariable("inpTabId", "UpdateMaintenanceScheduled|adTabId", "");
50       String JavaDoc 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 JavaDoc strWindowId = vars.getGlobalVariable("inpWindowId", "UpdateMaintenanceScheduled|windowId");
59       String JavaDoc strKey = vars.getGlobalVariable("inpmaMaintPartId", "UpdateMaintenanceScheduled|inpmaMaintPartId");
60       String JavaDoc strTabId = vars.getGlobalVariable("inpTabId", "UpdateMaintenanceScheduled|adTabId");
61       String JavaDoc strProcessId = vars.getGlobalVariable("inpadProcessId", "UpdateMaintenanceScheduled|adProcessId");
62       String JavaDoc strPartDate = vars.getRequestGlobalVariable("inppartdate", "UpdateMaintenanceScheduled|inppartdate");
63       vars.removeSessionValue("UpdateMaintenanceScheduled|windowId");
64       vars.removeSessionValue("UpdateMaintenanceScheduled|adTabId");
65       //vars.removeSessionValue("UpdateMaintenanceScheduled|adProcessId");
66
//vars.removeSessionValue("UpdateMaintenanceScheduled|inpmaMaintScheduledId");
67
//vars.removeSessionValue("UpdateMaintenanceScheduled|inppartdate");
68

69       printPageDataSheet(response, vars, strKey, strWindowId, strTabId, strProcessId, strPartDate, strPartDate, null);
70     } else if (vars.commandIn("FIND")) {
71       String JavaDoc strWindowId = vars.getGlobalVariable("inpWindowId", "UpdateMaintenanceScheduled|windowId");
72       String JavaDoc strKey = vars.getGlobalVariable("inpmaMaintPartId", "UpdateMaintenanceScheduled|inpmaMaintPartId");
73       String JavaDoc strTabId = vars.getGlobalVariable("inpTabId", "UpdateMaintenanceScheduled|adTabId");
74       String JavaDoc strProcessId = vars.getGlobalVariable("inpadProcessId", "UpdateMaintenanceScheduled|adProcessId");
75       String JavaDoc strPartDateFrom = vars.getRequestGlobalVariable("inpPartDateFrom", "UpdateMaintenanceScheduled|inpPartDateFrom");
76       String JavaDoc strPartDateTo = vars.getRequestGlobalVariable("inpPartDateTo", "UpdateMaintenanceScheduled|inpPartDateTo");
77       String JavaDoc 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 JavaDoc strKey = vars.getStringParameter("inpmaMaintPartId");
83       String JavaDoc strWindowId = vars.getStringParameter("inpWindowId");
84       String JavaDoc strTabId = vars.getStringParameter("inpTabId");
85       String JavaDoc strMessage = updateValues(request, vars, strKey);
86       ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTabId);
87       String JavaDoc 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 JavaDoc strKey, String JavaDoc strWindowId, String JavaDoc strTabId, String JavaDoc strProcessId, String JavaDoc strPartDateFrom, String JavaDoc strPartDateTo, String JavaDoc strMaintType) throws IOException, ServletException {
120     if (log4j.isDebugEnabled()) log4j.debug("Output: values ");
121     String JavaDoc[] 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 JavaDoc 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 JavaDoc updateValues(HttpServletRequest request, VariablesSecureApp vars, String JavaDoc strKey) throws IOException, ServletException {
157     if (log4j.isDebugEnabled()) log4j.debug("Update: values");
158
159     String JavaDoc[] strValueId = request.getParameterValues("strMaintScheduled");
160     if (log4j.isDebugEnabled()) log4j.debug("Update: values after strValueID");
161     if (strValueId == null || strValueId.length == 0) return "";
162     Connection JavaDoc 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 JavaDoc done = vars.getStringParameter("strDone"+strValueId[i]);
168         if (done == null) done = "";
169         String JavaDoc result = vars.getStringParameter("strResult"+strValueId[i]);
170         if (result == null) result = "";
171         String JavaDoc usedtime = vars.getStringParameter("strUsedTime"+strValueId[i]);
172         String JavaDoc 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 JavaDoc e) {
180       try {
181         releaseRollbackConnection(conn);
182       } catch (Exception JavaDoc ignored) {}
183       e.printStackTrace();
184       log4j.warn("Rollback in transaction");
185       return Utility.messageBD(this, "ProcessRunError", vars.getLanguage());
186     }//*/
187
return Utility.messageBD(this, "Success", vars.getLanguage());
188   }
189
190
191   public String JavaDoc getServletInfo() {
192     return "Servlet that presents the Create From Multiple button";
193   } // end of getServletInfo() method
194
}
195
Popular Tags