| 1 19 package org.openbravo.erpCommon.info; 20 21 import org.openbravo.base.secureApp.*; 22 import org.openbravo.xmlEngine.XmlDocument; 23 import org.openbravo.erpCommon.utility.Utility; 24 import org.openbravo.erpCommon.utility.ComboTableData; 25 import java.io.*; 26 import javax.servlet.*; 27 import javax.servlet.http.*; 28 29 30 public class ProductMultiple extends HttpSecureAppServlet { 31 32 33 public void init (ServletConfig config) { 34 super.init(config); 35 boolHist = false; 36 } 37 38 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 39 VariablesSecureApp vars = new VariablesSecureApp(request); 40 41 if (vars.commandIn("DEFAULT")) { 42 String strWindowId = vars.getStringParameter("WindowID"); 43 String strNameValue = vars.getRequestGlobalVariable("inpNameValue", "ProductMultiple.name"); 44 String strProductCategory = vars.getRequestGlobalVariable("inpProductCategory", "ProductMultiple.productCategory"); 45 if (!strNameValue.equals("")) vars.setSessionValue("ProductMultiple.name", strNameValue + "%"); 46 printPageFS(response, vars); 47 } else if (vars.commandIn("FRAME1")) { 48 String strKeyValue = vars.getGlobalVariable("inpKey", "ProductMultiple.key", ""); 49 String strNameValue = vars.getGlobalVariable("inpName", "ProductMultiple.name", ""); 50 printPageFrame1(response, vars, strKeyValue, strNameValue); 51 } else if (vars.commandIn("FRAME2")) { 52 String strKey = vars.getGlobalVariable("inpKey", "ProductMultiple.key", ""); 53 String strName = vars.getGlobalVariable("inpName", "ProductMultiple.name", ""); 54 String strProductCategory = vars.getRequestGlobalVariable("inpProductCategory", "ProductMultiple.productCategory"); 55 printPageFrame2(response, vars, strKey, strName, strProductCategory); 56 } else if (vars.commandIn("FIND")) { 57 String strKey = vars.getRequestGlobalVariable("inpKey", "ProductMultiple.key"); 58 String strName = vars.getRequestGlobalVariable("inpName", "ProductMultiple.name"); 59 String strProductCategory = vars.getRequestGlobalVariable("inpProductCategory", "ProductMultiple.productCategory"); 60 vars.setSessionValue("ProductMultiple.initRecordNumber", "0"); 61 62 printPageFrame2(response, vars, strKey, strName, strProductCategory); 63 } else if (vars.commandIn("FRAME3")) { 64 printPageFrame3(response, vars); 65 } else if (vars.commandIn("PREVIOUS")) { 66 String strInitRecord = vars.getSessionValue("ProductMultiple.initRecordNumber"); 67 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "ProductMultiple"); 68 int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange); 69 if (strInitRecord.equals("") || strInitRecord.equals("0")) vars.setSessionValue("ProductMultiple.initRecordNumber", "0"); 70 else { 71 int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 72 initRecord -= intRecordRange; 73 strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord)); 74 vars.setSessionValue("BusinessPartner.initRecordNumber", strInitRecord); 75 } 76 77 response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2"); 78 } else if (vars.commandIn("NEXT")) { 79 String strInitRecord = vars.getSessionValue("ProductMultiple.initRecordNumber"); 80 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "ProductMultiple"); 81 int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange); 82 int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 83 if (initRecord==0) initRecord=1; 84 initRecord += intRecordRange; 85 strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord)); 86 vars.setSessionValue("ProductMultiple.initRecordNumber", strInitRecord); 87 88 response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2"); 89 } else pageError(response); 90 } 91 92 void printPageFS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 93 if (log4j.isDebugEnabled()) log4j.debug("Output: Multiple products seeker Frame Set"); 94 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ProductMultiple_FS").createXmlDocument(); 95 96 response.setContentType("text/html; charset=UTF-8"); 97 PrintWriter out = response.getWriter(); 98 out.println(xmlDocument.print()); 99 out.close(); 100 } 101 102 103 void printPageFrame1(HttpServletResponse response, VariablesSecureApp vars, String strKeyValue, String strNameValue) throws IOException, ServletException { 104 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 1 of the multiple products seeker"); 105 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ProductMultiple_F1").createXmlDocument(); 106 if (strKeyValue.equals("") && strNameValue.equals("")) { 107 xmlDocument.setParameter("key", "%"); 108 } else { 109 xmlDocument.setParameter("key", strKeyValue); 110 } 111 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 112 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 113 xmlDocument.setParameter("name", strNameValue); 114 try { 115 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "M_Product_Category_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ProductMultiple"), Utility.getContext(this, vars, "#User_Client", "ProductMultiple"), 0); 116 Utility.fillSQLParameters(this, vars, null, comboTableData, "ProductMultiple", ""); 117 xmlDocument.setData("reportM_Product_Category_ID","liststructure", comboTableData.select(false)); 118 comboTableData = null; 119 } catch (Exception ex) { 120 throw new ServletException(ex); 121 } 122 123 response.setContentType("text/html; charset=UTF-8"); 124 PrintWriter out = response.getWriter(); 125 out.println(xmlDocument.print()); 126 out.close(); 127 } 128 129 void printPageFrame2(HttpServletResponse response, VariablesSecureApp vars, String strKey, String strName, String strProductCategory) throws IOException, ServletException { 130 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 2 of the multuple images seeker"); 131 XmlDocument xmlDocument; 132 133 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "ProductMultiple"); 134 int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange)); 135 String strInitRecord = vars.getSessionValue("ProductMultiple.initRecordNumber"); 136 int initRecordNumber = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 137 138 if (strKey.equals("") && strName.equals("") && strProductCategory.equals("")) { 139 String [] discard = {"sectionDetail", "hasPrevious", "hasNext"}; 140 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ProductMultiple_F2", discard).createXmlDocument(); 141 xmlDocument.setData("structure1", BusinessPartnerData.set()); 142 } else { 143 String [] discard = {"withoutPrevious", "withoutNext"}; 144 ProductMultipleData[] data = ProductMultipleData.select(this, strKey, strName, strProductCategory, Utility.getContext(this, vars, "#User_Client", "ProductMultiple"), Utility.getContext(this, vars, "#User_Org", "ProductMultiple"), initRecordNumber, intRecordRange); 145 if (data==null || data.length==0 || initRecordNumber<=1) discard[0] = new String ("hasPrevious"); 146 if (data==null || data.length==0 || data.length<intRecordRange) discard[1] = new String ("hasNext"); 147 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ProductMultiple_F2", discard).createXmlDocument(); 148 xmlDocument.setData("structure1", data); 149 } 150 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 151 response.setContentType("text/html; charset=UTF-8"); 152 PrintWriter out = response.getWriter(); 153 out.println(xmlDocument.print()); 154 out.close(); 155 } 156 157 void printPageFrame3(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 158 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 3 of the multiple products seeker"); 159 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ProductMultiple_F3").createXmlDocument(); 160 161 response.setContentType("text/html; charset=UTF-8"); 162 PrintWriter out = response.getWriter(); 163 out.println(xmlDocument.print()); 164 out.close(); 165 } 166 167 public String getServletInfo() { 168 return "Servlet that presents the multiple products seeker"; 169 } } 171 | Popular Tags |