From: Anneli <an...@us...> - 2005-01-18 15:32:25
|
Update of /cvsroot/redpos/RedPOS/src/org/redpos/client/ui/plugin/function In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30990/src/org/redpos/client/ui/plugin/function Modified Files: TotalDiscountAmount.java FindProduct.java RowDiscountAmount.java Pay.java TotalDiscountPercent.java RowDiscountPercent.java EditReceiptRow.java Log Message: Better handling of NumberFormatException Index: FindProduct.java =================================================================== RCS file: /cvsroot/redpos/RedPOS/src/org/redpos/client/ui/plugin/function/FindProduct.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FindProduct.java 10 Jan 2005 15:23:42 -0000 1.3 --- FindProduct.java 18 Jan 2005 15:31:56 -0000 1.4 *************** *** 236,256 **** if(input != null && input.length() > 0) { ! Double dAmount = Double.valueOf(input); ! if(dAmount.doubleValue() >= 10000) { // send message to ui String message = language.getString( "ui.main.message.editreceiptrow4.text", ! "You have to enter a valid price"); sendUIMessage(message); - userInput.setFocus(); return; } - - Amount amount = new Amount(dAmount.doubleValue()); - - addProductToReceipt(selectedProduct, amount); } else --- 236,270 ---- if(input != null && input.length() > 0) { ! Double dAmount; ! try ! { ! dAmount = Double.valueOf(input); ! ! if(dAmount.doubleValue() >= 10000) ! { ! // send message to ui ! String message = language.getString( ! "ui.main.message.editreceiptrow4.text", ! "You have to enter a valid price"); ! sendUIMessage(message); ! userInput.setFocus(); ! return; ! } ! ! Amount amount = new Amount(dAmount.doubleValue()); ! ! addProductToReceipt(selectedProduct, amount); ! } ! catch (NumberFormatException e) { // send message to ui String message = language.getString( "ui.main.message.editreceiptrow4.text", ! "You have to enter a valid price"); sendUIMessage(message); userInput.setFocus(); return; } } else Index: TotalDiscountAmount.java =================================================================== RCS file: /cvsroot/redpos/RedPOS/src/org/redpos/client/ui/plugin/function/TotalDiscountAmount.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TotalDiscountAmount.java 3 Jan 2005 12:15:34 -0000 1.2 --- TotalDiscountAmount.java 18 Jan 2005 15:31:56 -0000 1.3 *************** *** 142,148 **** if (in.length() != 0) { ! // convert to amount ! Amount amount = new Amount(Double.valueOf(in).doubleValue()); // calls POS engine method and add the discount boolean ok = addTotalDiscount(amount); --- 142,163 ---- if (in.length() != 0) { ! Amount amount; ! try ! { ! // convert to amount ! amount = new Amount(Double.valueOf(in).doubleValue()); ! } ! catch (NumberFormatException e) ! { ! String message = ""; ! message = getLanguageString("ui.main.message.totaldiscountamount4.text", ! "You have to enter a valid value"); + sendUIMessage(message); + input.setFocus(); + return; + } + + // calls POS engine method and add the discount boolean ok = addTotalDiscount(amount); Index: Pay.java =================================================================== RCS file: /cvsroot/redpos/RedPOS/src/org/redpos/client/ui/plugin/function/Pay.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Pay.java 17 Jan 2005 10:23:21 -0000 1.4 --- Pay.java 18 Jan 2005 15:31:57 -0000 1.5 *************** *** 339,343 **** inputMessage, inputLabelText, true, getLanguage(), this); userInput.setFocus(); ! } } else --- 339,343 ---- inputMessage, inputLabelText, true, getLanguage(), this); userInput.setFocus(); ! } } else *************** *** 365,386 **** // get input from user String input = userInput.getInput(); Amount amount; ! if(input == null || input.length() == 0) { ! amount = getAmountToPay(); ! payChange = new Amount(0); } ! else { ! Double dAmount = Double.valueOf(input); ! amount = new Amount(dAmount.doubleValue()); ! payChange = new Amount(dAmount.doubleValue()); ! } ! ! getLog().info( ! "handlePaymentSelected: entered amount = " + amount.toString()); ! // add the payment using the POS Engine service ! addPayment(payment, amount); // see if there is more to pay, if so re-invoke payment selection --- 365,400 ---- // get input from user String input = userInput.getInput(); + Amount amount; ! try { ! if(input == null || input.length() == 0) ! { ! amount = getAmountToPay(); ! payChange = new Amount(0); ! } ! else ! { ! Double dAmount = Double.valueOf(input); ! amount = new Amount(dAmount.doubleValue()); ! payChange = new Amount(dAmount.doubleValue()); ! } ! ! getLog().info( ! "handlePaymentSelected: entered amount = " + amount.toString()); ! ! // add the payment using the POS Engine service ! addPayment(payment, amount); } ! catch (NumberFormatException e) { ! String message = ""; ! message = getLanguageString("ui.main.message.pay7.text", ! "Couldn't add payment"); ! this.sendUIMessage(message); ! userInput.setFocus(); ! return; ! } // see if there is more to pay, if so re-invoke payment selection Index: EditReceiptRow.java =================================================================== RCS file: /cvsroot/redpos/RedPOS/src/org/redpos/client/ui/plugin/function/EditReceiptRow.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** EditReceiptRow.java 23 Nov 2004 16:02:27 -0000 1.1 --- EditReceiptRow.java 18 Jan 2005 15:31:57 -0000 1.2 *************** *** 142,160 **** quantityString = quantityString.replace(',', '.'); priceString = priceString.replace(',', '.'); ! // update receipt row object with new info ! // ! Double quantity = Double.valueOf(quantityString); ! if(quantity.doubleValue() >= 1000) { ! // send message to ui ! String message = getLanguageString( ! "ui.main.message.editreceiptrow3.text", ! "You have to enter a valid quantity"); ! sendUIMessage(message); ui.setFocusInQuantity(); return; } if(receiptRow.getQuantity() < 0 && quantity.doubleValue() > 0) --- 142,176 ---- quantityString = quantityString.replace(',', '.'); priceString = priceString.replace(',', '.'); + + Double quantity; ! try { ! // update receipt row object with new info ! // ! quantity = Double.valueOf(quantityString); ! if(quantity.doubleValue() >= 1000) ! { ! // send message to ui ! String message = getLanguageString( ! "ui.main.message.editreceiptrow3.text", ! "You have to enter a valid quantity"); ! sendUIMessage(message); + ui.setFocusInQuantity(); + return; + } + } + catch (NumberFormatException e) + { + String message = ""; + message = getLanguageString("ui.main.message.editreceiptrow3.text", + "You have to enter a valid quantity"); + + sendUIMessage(message); ui.setFocusInQuantity(); return; } + if(receiptRow.getQuantity() < 0 && quantity.doubleValue() > 0) *************** *** 163,180 **** receiptRow.setQuantity(quantity.doubleValue()); ! Double price = Double.valueOf(priceString); ! if(price.doubleValue() >= 10000) { ! // send message to ui ! String message = getLanguageString( ! "ui.main.message.editreceiptrow4.text", ! "You have to enter a valid price"); ! sendUIMessage(message); ui.setFocusInPrice(); return; } ! // if price has changed, update tax amount if(price.doubleValue() != receiptRow.getAmount().doubleValue()) --- 179,212 ---- receiptRow.setQuantity(quantity.doubleValue()); ! Double price; ! ! try ! { ! price = Double.valueOf(priceString); ! ! if(price.doubleValue() >= 10000) ! { ! // send message to ui ! String message = getLanguageString( ! "ui.main.message.editreceiptrow4.text", ! "You have to enter a valid price"); ! sendUIMessage(message); ! ! ui.setFocusInPrice(); ! return; ! } ! } ! catch (NumberFormatException e) { ! String message = ""; ! message = getLanguageString("ui.main.message.editreceiptrow4.text", ! "You have to enter a valid price"); + sendUIMessage(message); ui.setFocusInPrice(); return; } ! // if price has changed, update tax amount if(price.doubleValue() != receiptRow.getAmount().doubleValue()) *************** *** 186,190 **** receiptRow.setTaxAmount(taxAmount); } ! // call update receipt row in receipt service // --- 218,222 ---- receiptRow.setTaxAmount(taxAmount); } ! // call update receipt row in receipt service // Index: RowDiscountAmount.java =================================================================== RCS file: /cvsroot/redpos/RedPOS/src/org/redpos/client/ui/plugin/function/RowDiscountAmount.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RowDiscountAmount.java 3 Jan 2005 12:15:34 -0000 1.2 --- RowDiscountAmount.java 18 Jan 2005 15:31:56 -0000 1.3 *************** *** 123,129 **** if (in.length() != 0) { ! // convert to amount ! Amount amount = new Amount(Double.valueOf(in).doubleValue()); // calls POS engine method and add the discount boolean ok = addRowDiscount(amount); --- 123,144 ---- if (in.length() != 0) { ! Amount amount; ! try ! { ! // convert to amount ! amount = new Amount(Double.valueOf(in).doubleValue()); + } + catch (NumberFormatException e) + { + String message = ""; + message = getLanguageString("ui.main.message.rowdiscountamount5.text", + "You have to enter a valid value"); + + sendUIMessage(message); + input.setFocus(); + return; + } + // calls POS engine method and add the discount boolean ok = addRowDiscount(amount); Index: RowDiscountPercent.java =================================================================== RCS file: /cvsroot/redpos/RedPOS/src/org/redpos/client/ui/plugin/function/RowDiscountPercent.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RowDiscountPercent.java 3 Jan 2005 12:15:34 -0000 1.2 --- RowDiscountPercent.java 18 Jan 2005 15:31:57 -0000 1.3 *************** *** 123,130 **** if (in.length() != 0) { ! // convert to percent ! double percent = Double.valueOf(in).doubleValue(); ! percent = percent / 100; // calls POS engine method and add the discount boolean ok = addRowDiscount(new Double(percent)); --- 123,144 ---- if (in.length() != 0) { ! double percent; ! try ! { ! // convert to percent ! percent = Double.valueOf(in).doubleValue(); ! percent = percent / 100; ! } ! catch (NumberFormatException e) ! { ! String message = ""; ! message = getLanguageString("ui.main.message.rowdiscountamount5.text", ! "You have to enter a valid value"); + sendUIMessage(message); + input.setFocus(); + return; + } + // calls POS engine method and add the discount boolean ok = addRowDiscount(new Double(percent)); Index: TotalDiscountPercent.java =================================================================== RCS file: /cvsroot/redpos/RedPOS/src/org/redpos/client/ui/plugin/function/TotalDiscountPercent.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TotalDiscountPercent.java 3 Jan 2005 12:15:34 -0000 1.2 --- TotalDiscountPercent.java 18 Jan 2005 15:31:57 -0000 1.3 *************** *** 141,148 **** if (in.length() != 0) { ! // convert to double ! double percent = Double.valueOf(in).doubleValue(); ! percent = percent / 100; // calls POS engine method and add the discount boolean ok = addTotalDiscount(new Double(percent)); --- 141,162 ---- if (in.length() != 0) { ! double percent; ! try ! { ! // convert to percent ! percent = Double.valueOf(in).doubleValue(); ! percent = percent / 100; ! } ! catch (NumberFormatException e) ! { ! String message = ""; ! message = getLanguageString("ui.main.message.totaldiscountpercent4.text", ! "You have to enter a valid value"); + sendUIMessage(message); + input.setFocus(); + return; + } + // calls POS engine method and add the discount boolean ok = addTotalDiscount(new Double(percent)); |