KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
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
34 public class EditCCPMeasureValues extends HttpSecureAppServlet {
35   static final BigDecimal JavaDoc ZERO = new BigDecimal JavaDoc(0.0);
36   
37
38   public void init (ServletConfig config) {
39     super.init(config);
40     boolHist = false;
41   }
42
43   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
44     VariablesSecureApp vars = new VariablesSecureApp(request);
45     if (vars.commandIn("DEFAULT")) {
46       String JavaDoc strKey = vars.getRequestGlobalVariable("inpmaMeasureShiftId", "EditCCPMeasureValues|inpmaMeasureShiftId");
47       String JavaDoc strWindowId = vars.getGlobalVariable("inpwindowId", "EditCCPMeasureValues|windowId", "");
48       String JavaDoc strTabName = vars.getGlobalVariable("inpTabId", "EditCCPMeasureValues|adTabId", "");
49       String JavaDoc strMeasureDate = vars.getRequestGlobalVariable("inpmeasuredate", "EditCCPMeasureValues|inpmeasuredate");
50       String JavaDoc strProduct = vars.getRequestGlobalVariable("inpproduct", "EditCCPMeasureValues|inpproduct");
51       String JavaDoc strShift = vars.getRequestGlobalVariable("inpshift", "EditCCPMeasureValues|inpshift");
52
53       vars.setSessionValue("EditCCPMeasureValues|adProcessId", "800062");
54
55       printPage_FS(response, vars);
56     } else if (vars.commandIn("FRAME2")) {
57       printPage_F2(response, vars);
58     } else if (vars.commandIn("FRAME1")) {
59       String JavaDoc strWindowId = vars.getGlobalVariable("inpWindowId", "EditCCPMeasureValues|windowId");
60       String JavaDoc strKey = vars.getGlobalVariable("inpmaMeasureShiftId", "EditCCPMeasureValues|inpmaMeasureShiftId");
61       String JavaDoc strTabId = vars.getGlobalVariable("inpTabId", "EditCCPMeasureValues|adTabId");
62       String JavaDoc strProcessId = vars.getGlobalVariable("inpadProcessId", "EditCCPMeasureValues|adProcessId");
63       String JavaDoc strMeasureDate = vars.getGlobalVariable("inpmeasuredate", "EditCCPMeasureValues|inpmeasuredate", "");
64       String JavaDoc strProduct = vars.getGlobalVariable("inpproduct", "EditCCPMeasureValues|inpproduct", "");
65       String JavaDoc strShift = vars.getGlobalVariable("inpshift", "EditCCPMeasureValues|inpshift", "");
66       vars.removeSessionValue("EditCCPMeasureValues|windowId");
67       vars.removeSessionValue("EditCCPMeasureValues|adTabId");
68       vars.removeSessionValue("EditCCPMeasureValues|adProcessId");
69
70       printPageDataSheet(response, vars, strKey, strWindowId, strTabId, strProcessId, strMeasureDate, strProduct, strShift);
71     } else if (vars.commandIn("SAVE")) {
72       String JavaDoc strKey = vars.getStringParameter("inpmaMeasureShiftId");
73       String JavaDoc strWindowId = vars.getStringParameter("inpWindowId");
74       String JavaDoc strTabId = vars.getStringParameter("inpTabId");
75       updateValues(response, request, vars, strKey, strWindowId, strTabId);
76     } else pageErrorPopUp(response);
77   }
78
79
80   void printPage_FS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
81     if (log4j.isDebugEnabled()) log4j.debug("Output: FrameSet");
82     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/EditCCPMeasureValues_FS").createXmlDocument();
83     response.setContentType("text/html; charset=UTF-8");
84     PrintWriter out = response.getWriter();
85     out.println(xmlDocument.print());
86     out.close();
87     if (log4j.isDebugEnabled()) log4j.debug("Output: FrameSet - out");
88   }
89
90   void printPage_F2(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
91     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame2");
92     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/EditCCPMeasureValues_F2").createXmlDocument();
93     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
94     response.setContentType("text/html; charset=UTF-8");
95     PrintWriter out = response.getWriter();
96     out.println(xmlDocument.print());
97     out.close();
98     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame2 - Out");
99   }
100
101   void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strWindowId, String JavaDoc strTabId, String JavaDoc strProcessId, String JavaDoc strMeasureDate, String JavaDoc strProduct, String JavaDoc strShift) throws IOException, ServletException {
102     if (log4j.isDebugEnabled()) log4j.debug("Output: values ");
103     String JavaDoc[] discard = {""};
104     EditCCPMeasureValuesData[] data = null;
105     data = EditCCPMeasureValuesData.select(this, strKey);
106
107     String JavaDoc shift = "";
108
109     if (vars.getLanguage().equals("en_US")) shift = EditCCPMeasureValuesData.selectShift(this, strShift);
110     else shift = EditCCPMeasureValuesData.selectShiftTrl(this, strShift, vars.getLanguage());
111     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/EditCCPMeasureValues_F1", discard).createXmlDocument();
112     
113     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
114     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
115     xmlDocument.setParameter("key", strKey);
116     xmlDocument.setParameter("windowId", strWindowId);
117     xmlDocument.setParameter("tabId", strTabId);
118
119     xmlDocument.setParameter("measureDate", strMeasureDate);
120     xmlDocument.setParameter("shift", shift);
121     if (strProduct == null) strProduct = "";
122     xmlDocument.setParameter("product", strProduct);
123
124     if (log4j.isDebugEnabled()) log4j.debug("Param: " + vars.getLanguage() + " " + strReplaceWith + " " + strKey + " " + strWindowId + " " + strTabId + " " + strMeasureDate + " shift: " + shift + " " + strShift + " " + strProduct);
125     EditCCPMeasureValuesHoursData[][] dataHours = new EditCCPMeasureValuesHoursData[data.length][10];
126     EditCCPMeasureValuesValuesData[][] dataValues = new EditCCPMeasureValuesValuesData[data.length][];
127
128     for (int i=0; i<data.length; i++){
129       dataHours[i] = EditCCPMeasureValuesHoursData.select(this, data[i].groupid);
130       if (dataHours[i] == null || dataHours[i].length == 0) dataHours[i] = new EditCCPMeasureValuesHoursData[0];
131       
132       dataValues[i] = EditCCPMeasureValuesValuesData.select(this, data[i].groupid);
133       if (dataValues[i] == null || dataValues[i].length == 0) dataValues[i] = new EditCCPMeasureValuesValuesData[0];
134     }
135
136     OBError myMessage = vars.getMessage("EditCCPMeasureValues");
137     vars.removeMessage("EditCCPMeasureValues");
138     if (myMessage!=null) {
139       xmlDocument.setParameter("messageType", myMessage.getType());
140       xmlDocument.setParameter("messageTitle", myMessage.getTitle());
141       xmlDocument.setParameter("messageMessage", myMessage.getMessage());
142     }
143     xmlDocument.setData("structure1", data);
144     xmlDocument.setDataArray("reportHours", "structureHours",dataHours);
145     xmlDocument.setDataArray("reportValues", "structureValues",dataValues);
146     response.setContentType("text/html; charset=UTF-8");
147     PrintWriter out = response.getWriter();
148     out.println(xmlDocument.print());
149     out.close();
150     if (log4j.isDebugEnabled()) log4j.debug("Output: values - out");
151   }
152
153   void updateValues(HttpServletResponse response, HttpServletRequest request, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strWindowId, String JavaDoc strTabId) throws IOException, ServletException {
154     String JavaDoc strMessage="";
155     if (log4j.isDebugEnabled()) log4j.debug("Update: values");
156
157     String JavaDoc[] strValueId = request.getParameterValues("strKey");
158     String JavaDoc[] strGroupId = request.getParameterValues("strGroup");
159     OBError myError = null;
160     int total = 0;
161     Boolean JavaDoc error = false;
162
163     if (log4j.isDebugEnabled()) log4j.debug("Update: values after strValueID");
164     if (strValueId != null && strValueId.length > 0) {
165       Connection JavaDoc conn = null;
166       try {
167         conn = this.getTransactionConnection();
168         for (int i=0; i<strValueId.length; i++) {
169           String JavaDoc numeric = "";
170           String JavaDoc text = "";
171           String JavaDoc check = "N";
172           if (log4j.isDebugEnabled()) log4j.debug("*****strValueId[i]=" + strValueId[i]);
173           if (!strValueId[i].equals("0")) {
174             String JavaDoc type = EditCCPMeasureValuesData.selectType(this, strValueId[i]);
175             if (type.equals("N")) numeric = vars.getStringParameter("strValue"+strValueId[i]);
176             else if (type.equals("T")) text = vars.getStringParameter("strValue"+strValueId[i]);
177             else check = vars.getStringParameter("strValue"+strValueId[i]);
178             if (log4j.isDebugEnabled()) log4j.debug("Values to update: " + strValueId[i] + ", " + numeric + ", " + text + ", " + check);
179             total = EditCCPMeasureValuesData.update(conn, this, numeric, text, check.equals("Y")?"Y":"N", strValueId[i]);
180             if (total == 0) error =true;
181           }
182         }
183         for (int i=0; i<strGroupId.length; i++) {
184           if (log4j.isDebugEnabled()) log4j.debug("*****strGroupId[i]=" + strGroupId[i]);
185           if (!strGroupId[i].equals("0")) {
186             String JavaDoc secProduct = vars. getStringParameter("strProduct"+strGroupId[i]);
187             if (log4j.isDebugEnabled()) log4j.debug("Values to update: " + strGroupId[i] + ", " + secProduct);
188             total = EditCCPMeasureValuesData.updateSecProduct(conn, this, secProduct, strGroupId[i]);
189             if (total == 0) error = true;
190           }
191         }
192         releaseCommitConnection(conn);
193       } catch (Exception JavaDoc e) {
194         myError = Utility.translateError(this, vars, vars.getLanguage(), e.getMessage());
195         try {
196           releaseRollbackConnection(conn);
197         } catch (Exception JavaDoc ignored) {}
198         e.printStackTrace();
199         log4j.warn("Rollback in transaction");
200         if (!myError.isConnectionAvailable()) {
201           bdErrorConnection(response);
202           return;
203         }
204       }
205     }
206     if (error){
207       myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=DBExecuteError");
208     } else if (myError == null) {
209       myError = new OBError();
210       myError.setType("Info");
211       myError.setMessage(Utility.messageBD(this, "Success", vars.getLanguage()));
212       myError.setTitle("");
213     }
214     vars.setMessage(strTabId, myError);
215     ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTabId);
216     String JavaDoc strWindowPath="", strTabName="";
217     if (tab!=null && tab.length!=0) {
218       strTabName = FormatUtilities.replace(tab[0].name);
219       strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html";
220     } else strWindowPath = strDefaultServlet;
221     if (!strMessage.equals("")) vars.setSessionValue(strWindowId + "|" + strTabName + ".message", strMessage);
222     printPageClosePopUp(response, vars, strWindowPath);
223   }
224
225
226   public String JavaDoc getServletInfo() {
227     return "Servlet that presents the button of Create From Multiple";
228   } // end of getServletInfo() method
229
}
230
Popular Tags