1. /*
  2. * Copyright 1999,2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package peaklau.eaglefund;
  17. import javax.microedition.lcdui.Alert;
  18. import javax.microedition.lcdui.AlertType;
  19. import javax.microedition.lcdui.Command;
  20. import javax.microedition.lcdui.CommandListener;
  21. import javax.microedition.lcdui.Displayable;
  22. import javax.microedition.lcdui.Form;
  23. import javax.microedition.lcdui.StringItem;
  24. import javax.microedition.lcdui.TextField;
  25. /**
  26. * User Interface for modifying one fund quota.<br>
  27. *
  28. *
  29. * @author peaklau <br>
  30. * email:<A HREF="mailto:peaklau@hotmail.com">peaklau@hotmail.com</A> <br>
  31. * <a href="http://www.peaklau.com/fund/english/">HomePage</a>
  32. * @version $Revision: 1.1 $ $Date: 2007/05/09 16:07:04 $
  33. */
  34. public class FundDoModifyScreen extends Form implements CommandListener {
  35. private Command back=new Command("返回",Command.BACK,1);
  36. private Command add=new Command("确认修改",Command.OK,1);
  37. private Alert alert=null;
  38. private INavigator navigator=null;
  39. private String codeID=null;
  40. private StringItem code=null;
  41. private TextField quantity=null;
  42. public FundDoModifyScreen(String codeID,INavigator navigator){
  43. super("修改基金");
  44. this.navigator=navigator;
  45. this.codeID=codeID;
  46. code=new StringItem("基金代码:",codeID);
  47. quantity=new TextField("份额(格式123.12):","",9,TextField.ANY);
  48. this.append(code);
  49. this.append(quantity);
  50. addCommand(add);
  51. addCommand(back);
  52. setCommandListener(this);
  53. alert=new Alert("提示信息");
  54. }
  55. public void commandAction(Command command, Displayable displayable) {
  56. if(command == back){
  57. if(navigator!=null){
  58. navigator.getDisplay().setCurrent(navigator.getDisplayable("fundModifyScreen"));
  59. }
  60. }else if(command == add){
  61. String squantity=quantity.getString();
  62. boolean error=false;
  63. for(int i=0;i<squantity.length();i++){
  64. char c=squantity.charAt(i);
  65. if(((c>='0')&&(c<='9'))||(c=='.')){
  66. }else{
  67. error=true;
  68. }
  69. }
  70. if(error){
  71. alert.setString("数量格式错误");
  72. alert.setType(AlertType.ERROR);
  73. navigator.getDisplay().setCurrent(alert,this);
  74. return;
  75. }
  76. int qquantity=0;
  77. int index=squantity.indexOf(".");
  78. if(index>=0){
  79. qquantity+=100*Integer.parseInt(squantity.substring(0,index));
  80. if(index+1<squantity.length()){
  81. qquantity+=10*Integer.parseInt(squantity.substring(index+1,index+2));
  82. }
  83. if(index+2<squantity.length()){
  84. qquantity+=Integer.parseInt(squantity.substring(index+2,index+3));
  85. }
  86. }else{
  87. if(squantity.length()==0){
  88. qquantity=0;
  89. }else{
  90. int tmp=Integer.parseInt(squantity);
  91. if(tmp>20000000){
  92. alert.setString("数量太大");
  93. alert.setType(AlertType.ERROR);
  94. navigator.getDisplay().setCurrent(alert,this);
  95. return;
  96. }
  97. qquantity=100*Integer.parseInt(squantity);
  98. }
  99. }
  100. String ccode=codeID;
  101. index=codeID.indexOf("(");
  102. if(index>0){
  103. ccode=codeID.substring(index+1,ccode.length()-1);
  104. }
  105. DataCenter.updateRecordQantity(ccode,qquantity);
  106. alert.setString("修改成功!");
  107. alert.setType(AlertType.INFO);
  108. navigator.getDisplay().setCurrent(alert,navigator.getDisplayable("valueScreen"));
  109. navigator.getCanvas("valueScreen").refresh();
  110. }
  111. }
  112. }