📄 setup_form.java
字号:
/** * <p>Title: CowriePixie</p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: xidian</p> * @author yangyong * @version 1.0 */import javax.microedition.lcdui.Alert;import javax.microedition.lcdui.AlertType;import javax.microedition.lcdui.ChoiceGroup;import javax.microedition.lcdui.Command;import javax.microedition.lcdui.CommandListener;import javax.microedition.lcdui.Display;import javax.microedition.lcdui.Displayable;import javax.microedition.lcdui.Form;import javax.microedition.lcdui.Item;import javax.microedition.lcdui.ItemStateListener;import javax.microedition.lcdui.TextField;import javax.microedition.rms.RecordStore;/* * 创建日期 2005-9-23 * * TODO 要更改此生成的文件的模板,请转至 * 窗口 - 首选项 - Java - 代码样式 - 代码模板 *//** * @author Administrator * * TODO 要更改此生成的类型注释的模板,请转至 * 窗口 - 首选项 - Java - 代码样式 - 代码模板 */public class Setup_Form extends Form implements CommandListener, ItemStateListener { protected RecordStore feetypedb; protected RecordStore subfeetypedb; private ChoiceGroup choice; private Command add; private Command back; private Display dis; private ChoiceGroup itemlist; private ChoiceGroup subitemlist; private TextField itemadd; private String stringElements[] = { "增加费用类别", "增加费用明细" }; private boolean subitemsel; private String code; private String subcode; private String itemname; private String maxcode; private String maxsubcode; public Setup_Form(Display display) { super("系统设置"); subitemsel = false; dis = display; code = new String(); subcode = new String(); itemname = new String(); choice = new ChoiceGroup("选择增加类别 :",ChoiceGroup.EXCLUSIVE , stringElements, null); append(choice); itemlist = new ChoiceGroup("费用类别 :", ChoiceGroup.EXCLUSIVE ); for(int i = 0; i < Financing.feenamevector.size(); i++) { Fee_Type feetype = (Fee_Type)Financing.feenamevector.elementAt(i); itemlist.append(feetype.name, null); } append(itemlist); subitemlist = new ChoiceGroup("费用明细 :", ChoiceGroup.EXCLUSIVE ); itemadd = new TextField("新增费用类别 :", null, 10, TextField.ANY);//新增费用类别名最多为10位 append(itemadd); back = new Command("返回",Command.BACK,2); addCommand(back); add = new Command("新增",Command.OK, 2); addCommand(add); setCommandListener(this); setItemStateListener(this); } public void commandAction(Command c, Displayable d) { if(c == back) { Main_Form mainform = new Main_Form(dis); dis.setCurrent(mainform); return; } if(c == add) Add(); } public void Add() { if(itemname.length() == 0) { try { Alert alert = new Alert("告警", " 请输入名称", Financing.alert, AlertType.ALARM); alert.setTimeout(500); dis.setCurrent(alert); } catch(Exception exception) { } } else { WriteData(); Alert alert = new Alert("提示", " 增加完毕", Financing.alert, AlertType.ALARM); alert.setTimeout(500); dis.setCurrent(alert); itemadd.setString(""); itemname = ""; } } public void WriteData() { GetMaxCode(); if(subitemsel) { String filename = "sub_fee_type"; try { subfeetypedb = RecordStore.openRecordStore(filename, true); } catch(Exception ex) { return; } Sub_Fee_Type temp = new Sub_Fee_Type(code, maxsubcode, itemname); byte field[] = temp.encode(); try { subfeetypedb.addRecord(field, 0, field.length); } catch(Exception exception) { } try { subfeetypedb.closeRecordStore(); } catch(Exception exception1) { } subitemlist.append(itemname, null); } else { String filename = "fee_type"; try { feetypedb = RecordStore.openRecordStore(filename, true); } catch(Exception ex) { return; } Fee_Type temp = new Fee_Type(maxcode, itemname); byte field[] = temp.encode(); try { feetypedb.addRecord(field, 0, field.length); } catch(Exception exception2) { } try { feetypedb.closeRecordStore(); } catch(Exception exception3) { } itemlist.append(itemname, null); } } void GetMaxCode() { maxsubcode = ""; maxcode = ""; int temp = -1; for(int i = 0; i < Financing.feenamevector.size(); i++) { Fee_Type feetype = (Fee_Type)Financing.feenamevector.elementAt(i); if(Integer.parseInt(feetype.code) > temp) temp = Integer.parseInt(feetype.code); } if(temp + 1 < 10) { maxcode = String.valueOf(String.valueOf(maxcode)).concat("0"); maxcode = String.valueOf(maxcode) + String.valueOf(Integer.toString(temp + 1)); } else { maxcode = Integer.toString(temp + 1); } temp = -1; if(subitemsel) { for(int h = 0; h < Financing.subfeenamevector.size(); h++) { Sub_Fee_Type subfeetype = (Sub_Fee_Type)Financing.subfeenamevector.elementAt(h); if(code.equals(subfeetype.code) && Integer.parseInt(subfeetype.subcode) > temp) temp = Integer.parseInt(subfeetype.subcode); } if(temp + 1 < 10) { maxsubcode = String.valueOf(String.valueOf(maxsubcode)).concat("0"); maxsubcode = String.valueOf(maxsubcode) + String.valueOf(Integer.toString(temp + 1)); } else { maxsubcode = Integer.toString(temp + 1); } } } public void itemStateChanged(Item item) { if(item == choice) if(choice.getSelectedIndex() == 0) { itemlist.setLabel("费用类别 :"); itemadd.setLabel("新增费用类别 :"); delete(2); subitemsel = false; } else { subitemsel = true; insert(2, subitemlist); GetItemCode(); itemlist.setLabel("费用类别 :"); itemadd.setLabel("新增费用明细 :"); } if(item == itemlist && subitemsel) GetItemCode(); if(item == itemadd) itemname = itemadd.getString(); } public void GetSubItemCode() { String subfeename = new String(); subfeename = subitemlist.getString(subitemlist.getSelectedIndex()); int h = 0; do { if(h >= Financing.subfeenamevector.size()) break; Sub_Fee_Type subfeetype = (Sub_Fee_Type)Financing.subfeenamevector.elementAt(h); if(code.equals(subfeetype.code) && subfeename.equals(subfeetype.name)) { subcode = subfeetype.subcode; break; } h++; } while(true); } public void GetItemCode() { String feename = new String(); feename = itemlist.getString(itemlist.getSelectedIndex()); int i = 0; do { if(i >= Financing.feenamevector.size()) break; Fee_Type feetype = (Fee_Type)Financing.feenamevector.elementAt(i); if(feename.equals(feetype.name)) { code = feetype.code; break; } i++; } while(true); int m = subitemlist.size(); for(int j = 0; j < m; i++) subitemlist.delete(0); int count = 0; for(int h = 0; h < Financing.subfeenamevector.size(); h++) { Sub_Fee_Type subfeetype = (Sub_Fee_Type)Financing.subfeenamevector.elementAt(h); if(code.equals(subfeetype.code)) { subitemlist.insert(count, subfeetype.name, null); count++; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -