- /*
- * Copyright 1999,2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- package peaklau.eaglefund;
-
-
-
- import javax.microedition.lcdui.Alert;
- import javax.microedition.lcdui.AlertType;
- import javax.microedition.lcdui.Command;
- import javax.microedition.lcdui.CommandListener;
- import javax.microedition.lcdui.Displayable;
- import javax.microedition.lcdui.Form;
- import javax.microedition.lcdui.TextField;
-
-
- /**
- * User Interface for adding funds.<br>
- *
- * <br>
- * @author peaklau <br>
- * email:<A HREF="mailto:peaklau@hotmail.com">peaklau@hotmail.com</A> <br>
- * <a href="http://www.peaklau.com/fund/english/">HomePage</a>
- * @version $Revision: 1.1 $ $Date: 2007/05/09 16:07:03 $
- */
-
- public class FundAddScreen extends Form implements CommandListener {
- private Command back=new Command("返回",Command.BACK,1);
- private Command add=new Command("确认添加",Command.OK,1);
- private Alert alert=null;
-
- private INavigator navigator=null;
-
- private TextField code=null;
- private TextField quantity=null;
-
- public FundAddScreen(INavigator navigator){
- super("添加基金");
- this.navigator=navigator;
- code=new TextField("基金代码:","",6,TextField.NUMERIC);
- quantity=new TextField("份额(格式123.12):","",9,TextField.ANY);
-
- this.append(code);
- this.append(quantity);
-
- addCommand(add);
- addCommand(back);
- setCommandListener(this);
- alert=new Alert("提示信息");
- }
-
- public void commandAction(Command command, Displayable displayable) {
- if(command == back){
- if(navigator!=null){
- navigator.getDisplay().setCurrent(navigator.getDisplayable("mainScreen"));
- }
- }else if(command == add){
- String ccode="000000";
- if(code.getString().length()!=0){
- ccode=code.getString();
- }
- String squantity=quantity.getString();
- boolean error=false;
- for(int i=0;i<squantity.length();i++){
- char c=squantity.charAt(i);
- if(((c>='0')&&(c<='9'))||(c=='.')){
- }else{
- error=true;
- }
- }
- if(error){
- alert.setString("数量格式错误");
- alert.setType(AlertType.ERROR);
- navigator.getDisplay().setCurrent(alert,this);
- return;
- }
- int qquantity=0;
- int index=squantity.indexOf(".");
- if(index>=0){
- qquantity+=100*Integer.parseInt(squantity.substring(0,index));
- if(index+1<squantity.length()){
- qquantity+=10*Integer.parseInt(squantity.substring(index+1,index+2));
- }
- if(index+2<squantity.length()){
- qquantity+=Integer.parseInt(squantity.substring(index+2,index+3));
- }
- }else{
- if(squantity.length()==0){
- qquantity=0;
- }else{
- int tmp=Integer.parseInt(squantity);
- if(tmp>20000000){
- alert.setString("数量太大");
- alert.setType(AlertType.ERROR);
- navigator.getDisplay().setCurrent(alert,this);
- return;
- }
- qquantity=100*Integer.parseInt(squantity);
- }
- }
- if(Integer.parseInt(ccode)==0){
- alert.setString("基金代码有误!");
- alert.setType(AlertType.ERROR);
- navigator.getDisplay().setCurrent(alert,this);
- }
- if(DataCenter.addFund(ccode,null,qquantity)){
- alert.setString("添加成功!");
- alert.setType(AlertType.INFO);
- navigator.getDisplay().setCurrent(alert,navigator.getDisplayable("valueScreen"));
- navigator.getCanvas("valueScreen").refresh();
- }else{
- alert.setString("该基金已经存在了!");
- alert.setType(AlertType.ERROR);
- navigator.getDisplay().setCurrent(alert,this);
- }
- //System.out.println(code.getString()+" "+quantity.getString());
- }
- }
-
- }