Message |
Update of /usr/cvsroot/org/paneris/ftc/controller In directory rama.paneris.org:/tmp/cvs-serv19332 Modified Files: Form.java Log Message: Merge in branch Index: Form.java =================================================================== RCS file: /usr/cvsroot/org/paneris/ftc/controller/Form.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Form.java 15 Apr 2003 18:06:20 -0000 1.9 +++ Form.java 14 Jan 2006 20:10:21 -0000 1.10 @@ -81,11 +81,20 @@ public String getCheckbox(String description, String price, String ukDelivery, String overseasDelivery, String euDelivery, String paradoxCode) { - int id = getProductId(description); + Product p = null; + String pc = null; + if (paradoxCode == null || paradoxCode.equals("")) { + p = getProduct(description); + pc = p.getParadoxcode(); + } else { + p = getProduct(description,paradoxCode); + pc = paradoxCode; + } + int id = p.troid().intValue(); String returnValue = "<input type=checkbox name='product_" + id + "'>"; returnValue += addHidden(id, description, price, ukDelivery, overseasDelivery, euDelivery, - paradoxCode); + pc); return returnValue; } @@ -113,7 +122,16 @@ public String getDropdown(String description, String price, String options, String ukDelivery, String overseasDelivery, String euDelivery, String paradoxCode) { - int id = getProductId(description); + Product p = null; + String pc = null; + if (paradoxCode == null || paradoxCode.equals("")) { + p = getProduct(description); + pc = p.getParadoxcode(); + } else { + p = getProduct(description,paradoxCode); + pc = paradoxCode; + } + int id = p.troid().intValue(); String returnValue = "<select name='product_" + id + "'>\n"; returnValue += "<option value=''>-</option>\n"; CSVStringEnumeration enum = new CSVStringEnumeration(); @@ -125,7 +143,7 @@ returnValue += "</select>\n"; returnValue += addHidden(id, description, price, ukDelivery, overseasDelivery, euDelivery, - paradoxCode); + pc); return returnValue; } @@ -141,21 +159,36 @@ public String getInput(String description, String price, String displayValue) { return getInput(description,price,displayValue, null,null,null,null); } + // Note EU delivery defaults to overseas public String getInput(String description, String price, String displayValue, String ukDelivery, String overseasDelivery) { return getInput(description,price, displayValue, ukDelivery,overseasDelivery,overseasDelivery,null); } public String getInput(String description, String price, String displayValue, + String ukDelivery, String overseasDelivery, String euDelivery) { + return getInput(description,price, displayValue, + ukDelivery,overseasDelivery,euDelivery,null); + } + public String getInput(String description, String price, String displayValue, String ukDelivery, String overseasDelivery, String euDelivery, String paradoxCode) { - int id = getProductId(description); + Product p = null; + String pc = null; + if (paradoxCode == null || paradoxCode.equals("")) { + p = getProduct(description); + pc = p.getParadoxcode(); + } else { + p = getProduct(description,paradoxCode); + pc = paradoxCode; + } + int id = p.troid().intValue(); String returnValue = "<input type=\"text\" name='product_" + id + "'"; if (displayValue != null) returnValue += " value='"+ displayValue + "'"; returnValue += ">\n"; returnValue += addHidden(id, description, price, ukDelivery, overseasDelivery, euDelivery, - paradoxCode); + pc); return returnValue; } @@ -231,16 +264,25 @@ paradoxcodesEnum.reset(paradoxCodes); while (optionsEnum.hasMoreElements()) { String opt = (String)optionsEnum.nextElement(); - String pc = (String)paradoxcodesEnum.nextElement(); - String newDesc = description + " (" + pc + ")"; - int id = getProductId(newDesc); + String pcIn = (String)paradoxcodesEnum.nextElement(); + String newDesc = description + " (" + pcIn + ")"; + Product p = null; + String pcOut = null; + if (pcIn == null || pcIn.equals("")) { + p = getProduct(description); + pcOut = p.getParadoxcode(); + } else { + p = getProduct(description,pcIn); + pcOut = pcIn; + } + int id = p.troid().intValue(); select += "<option value='" + id + "'>" + opt + "</option>\n"; selectName += "_" + id; hidden += addHidden2(id, newDesc, price, - ukDelivery, overseasDelivery, euDelivery, pc); + ukDelivery, overseasDelivery, euDelivery, pcOut); } select = "<select name='" + selectName + "'>\n" + "<option value=''>-</option>\n" + @@ -275,7 +317,7 @@ /** * Get or create a product from its description */ - private int getProductId(String description) { + private Product getProduct(String description) { ProductTable table = db.getProductTable(); Product product = (Product)table.getDescriptionColumn(). firstWhereEq(description); @@ -284,7 +326,27 @@ product.setDescription(description); table.create(product); } - return product.getTroid().intValue(); + return product; + } + + /** + * Get or create a product from its description + */ + private Product getProduct(String description, String paradoxcode) { + ProductTable table = db.getProductTable(); + Product product = (Product)table.getDescriptionColumn(). + firstWhereEq(description); + if (product == null) { + product = (Product)table.newPersistent(); + product.setDescription(description); + product.setParadoxcode(paradoxcode); + + table.create(product); + } else + if (product.getParadoxcode()== null) + product.setParadoxcode(paradoxcode); + + return product; } }
|