📄 datamanager.java
字号:
/** * <p>Title: CowriePixie</p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: xidian</p> * @author yangyong * @version 1.0 */import java.io.ByteArrayInputStream;import java.io.DataInputStream;import java.util.Date;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.DateField;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.rms.RecordEnumeration;import javax.microedition.rms.RecordStore;/* * 创建日期 2005-9-23 * * TODO 要更改此生成的文件的模板,请转至 * 窗口 - 首选项 - Java - 代码样式 - 代码模板 *//** * @author Administrator * * TODO 要更改此生成的类型注释的模板,请转至 * 窗口 - 首选项 - Java - 代码样式 - 代码模板 */public class DataManager extends Form implements CommandListener, ItemStateListener { private ChoiceGroup cg; private Command ok; private Command back; private Command cancel; private Command okdel; private DateField sdf; private DateField edf; private String cgstr[] = { "全部删除", "按日期删除" }; private Display dis; private boolean datesel; private long slong; private long elong; private long datelong; byte field[]; public DataManager(Display display) { super("数据维护"); datesel = false; field = new byte[48]; dis = display; cg = new ChoiceGroup("费用清单维护 :", ChoiceGroup.EXCLUSIVE , cgstr, null); append(cg); sdf = new DateField("起始日期 :", DateField.DATE); edf = new DateField("终止日期 :", DateField.DATE); ok = new Command("删除", Command.OK, 2); addCommand(ok); back = new Command("返回", Command.BACK, 2); addCommand(back); setCommandListener(this); setItemStateListener(this); cancel = new Command("取消", Command.CANCEL, 2); okdel = new Command("确定", Command.OK, 2); } public void commandAction(Command c, Displayable d) { if(c == cancel) dis.setCurrent(this); if(c == okdel) ConfDelete(); if(c == back) { Main_Form mainform = new Main_Form(dis); dis.setCurrent(mainform); return; } if(c == ok) ConfDelete(); } void ConfDelete() { dis.setCurrent(this); DeleteFeeDetail(); Alert alert = new Alert("提示", " 数据删除完毕", Financing.alert, AlertType.ALARM); alert.setTimeout(500); dis.setCurrent(alert); } void DeleteFeeDetail() { String filename = "fee_detail"; if(!datesel) { try { RecordStore.deleteRecordStore(filename); } catch(Exception ex) { return; } return; } RecordStore feedetaildb; try { feedetaildb = RecordStore.openRecordStore(filename, true); } catch(Exception ex) { return; } try { RecordEnumeration re = feedetaildb.enumerateRecords(null, null, false); do { if(!re.hasNextElement()) break; int id = re.nextRecordId(); field = feedetaildb.getRecord(id); if(Decode()) try { feedetaildb.deleteRecord(id); } catch(Exception exception1) { } } while(true); feedetaildb.closeRecordStore(); } catch(Exception exception) { } } public boolean Decode() { try { int tempint = 0; String temp = new String(); ByteArrayInputStream bis = new ByteArrayInputStream(field); DataInputStream dis = new DataInputStream(bis); datelong = dis.readLong(); temp = dis.readUTF(); temp = dis.readUTF(); tempint = dis.readInt(); temp = dis.readUTF(); dis.close(); bis.close(); } catch(Exception exception) { } return datelong >= slong && datelong <= elong; } public void itemStateChanged(Item item) { if(item == cg) if(cg.getSelectedIndex() == 0) { delete(1); delete(1); datesel = false; } else { datesel = true; Date date = new Date(); insert(1, sdf); sdf.setDate(date); insert(2, edf); edf.setDate(date); slong = sdf.getDate().getTime(); elong = edf.getDate().getTime(); } if(item == sdf) slong = sdf.getDate().getTime(); if(item == edf) elong = edf.getDate().getTime(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -