⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdadataset.java

📁 很好的UI界面源码..还有自己的输入法,可以更换风格.可以学习和使用
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package cn.sda.ui;import cn.sda.enterprise.*;import cn.sda.event.DataFilterEvent;import cn.sda.event.DataScrollChangeEvent;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.io.DataInputStream;import java.io.DataOutputStream;import java.util.Enumeration;import java.util.Vector;import javax.microedition.rms.RecordEnumeration;import javax.microedition.rms.RecordStore;/** * * @author Administrator *///数据集合类public class SDADataSet {    //rms    private DataSetRMS dataRms = null;    //字段类型    public static final byte FieldBoolean = 0;    public static final byte FieldByte = 1;    public static final byte FieldShort = 2;    public static final byte FieldInteger = 3;    public static final byte FieldLong = 4;    public static final byte FieldFloat = 5;    public static final byte FieldDouble = 6;    public static final byte FieldString = 7;    public static final byte FieldAudoID = 8;    //排序方式    public static final int sortDesc = 0;    public static final int sortAsc = 1;    //字段集合    private Vector Fields = null;    //可见值集合    private Vector Rows = null;    //所有值集合    private Vector allRows = null;    //delta记录    private Vector deltaFields = null;    private Vector deltaRows = null;    //Key    private String keyName = "";    //数据集合指针位置    public int RecNo = -1;    //表达式计算器    private SDAExpression exp;    //记录merge    private boolean recChangeLog = false;    //是否打开自动ID计算    private boolean autoID = false;    //需要刷新的表格列表    private Vector dataControlList = null;    //滚动事件    private DataScrollChangeEvent onDataScrollChange = null;    //数据执行过滤的事件    private DataFilterEvent onDataFilter = null;    //对链接组件通知变动    private boolean enableControls = true;    //字段描述    public class Field {        //字段名        private String FiledName = "";        //字段类型        private byte FiledType = FieldString;        //是否为计算字段        private boolean CalField = false;        //计算字段表达式        private String CalExpression = "";        public Field() {        }        public Field(String fieldName) {            this.FiledName = fieldName;        }        public Field(String fieldName, byte fieldType) {            this.FiledName = fieldName;            if ((fieldType > -1) && (fieldType < 8)) {                this.FiledType = fieldType;            }        }        public Field(String fieldName, byte fieldType, boolean isCalField, String CalExpression) {            this.FiledName = fieldName;            if ((fieldType > -1) && (fieldType < 8)) {                this.FiledType = fieldType;            }            this.CalField = isCalField;            this.CalExpression = CalExpression;        }        public String getCalExpression() {            return CalExpression;        }        public void setCalExpression(String CalExpression) {            if (isCanEditFields()) {                this.CalExpression = CalExpression;            } else {                System.out.println("Can not change Expression.");            }        }        public String getFiledName() {            return FiledName;        }        public void setFiledName(String FiledName) {            this.FiledName = FiledName;        }        public int getFiledType() {            return FiledType;        }        public void setFiledType(byte FiledType) {            if (isCanEditFields()) {                this.FiledType = FiledType;            } else {                System.out.println("Can not change FiledType.");            }        }        public boolean isCalFiled() {            return CalField;        }        public void setCalFiled(boolean isCalFiled) {            if (isCanEditFields()) {                this.CalField = isCalFiled;            } else {                System.out.println("Can not change CalField.");            }        }    }    //列构造方法    public Field newField() {        return new Field();    }    public Field newField(String fieldName) {        return new Field(fieldName);    }    public Field newField(String fieldName, byte fieldType) {        return new Field(fieldName, fieldType);    }    public Field newField(String fieldName, byte fieldType, boolean isCalField, String CalExpression) {        return new Field(fieldName, fieldType, isCalField, CalExpression);    }    //行数据    public class Row {        private Vector valueList;        private boolean visible = true;  //是否可见(过滤的时候需要)        private void internalRow() {            valueList = new Vector();            //增加空值            for (int i = 0; i < Fields.size(); i++) {                valueList.addElement(null);            }        }        public Row() {            internalRow();        }        public boolean isVisible() {            return visible;        }        public void setVisible(boolean visible) {            this.visible = visible;            //设置是否在Rows            if (!visible) {                if (isInRows()) {                    Rows.removeElement(this);                    setAutoID();                    refreshDataControl();                }            } else {                if (!isInRows()) {                    Rows.addElement(this);                    setAutoID();                    refreshDataControl();                }            }        }        //获取指定字段值        public String getValueByFieldName(String fieldName) {            return internalGetValueByFieldName(fieldName);        }        private String internalGetValueByFieldName(String fieldName) {            Field fd;            String result = null;            for (int i = 0; i < Fields.size(); i++) {                fd = (Field) Fields.elementAt(i);                if (fd.FiledName.equals(fieldName)) {                    result = (String) valueList.elementAt(i);                    break;                }            }            return result;        }        public String getValueByFieldIndex(int fieldIndex) {            return internalGetValueByFieldIndex(fieldIndex);        }        private String internalGetValueByFieldIndex(int fieldIndex) {            if ((fieldIndex > -1) && (fieldIndex < valueList.size())) {                //得到字段以后就从当前的行中获取值                return (String) valueList.elementAt(fieldIndex);            } else {                return null;            }        }        public Object getObjectByFieldIndex(int fieldIndex) {            return internalGetObjectByFieldIndex(fieldIndex);        }        private Object internalGetObjectByFieldIndex(int fieldIndex) {            if ((fieldIndex > -1) && (fieldIndex < valueList.size())) {                //得到字段以后就从当前的行中获取值                return valueList.elementAt(fieldIndex);            } else {                return null;            }        }        public void setValueByFieldName(String fieldName, String fieldValue) {            internalSetValueByFieldName(fieldName, fieldValue);        }        private void internalSetValueByFieldName(String fieldName, String fieldValue) {            Field fd;            for (int i = 0; i < Fields.size(); i++) {                fd = (Field) Fields.elementAt(i);                if ((fd.FiledName.equals(fieldName)) && (fd.FiledType != SDADataSet.FieldAudoID)) {                    valueList.setElementAt(fieldValue, i);                    //计算                    try {                        calField(this);                    } catch (Exception e) {                    }                    if (isInRows()) {                        refreshDataControl();                    }                    break;                }            }        }        public void setValueByFieldIndex(int fieldIndex, String fieldValue) {            internalSetValueByFieldIndex(fieldIndex, fieldValue);        }        private void internalSetValueByFieldIndex(int fieldIndex, String fieldValue) {            if ((fieldIndex > -1) && (fieldIndex < valueList.size())) {                Field fd = null;                fd = (Field) Fields.elementAt(fieldIndex);                if (fd.FiledType != SDADataSet.FieldAudoID) {                    valueList.setElementAt(fieldValue, fieldIndex);                    //计算                    try {                        calField(this);                    } catch (Exception e) {                    }                    if (isInRows()) {                        refreshDataControl();                    }                }            }        }        //判断是否在Rows中        private boolean isInRows() {            return Rows.indexOf(this) > -1;        }    }    //RMS操作类    private class DataSetRMS {        public DataSetRMS() {        }        public RecordStore OpenRS(String tableName) {            RecordStore rs = null;            if (tableName.length() > 32) {                return null;            }            try {                rs = RecordStore.openRecordStore(tableName, true);                return rs;            } catch (Exception e) {                return null;            }        }        //写入数据库        public void WriteDataSet(String tableName) {            //写入(先删除)            deleteTable(tableName);            //打开空的            RecordStore rs = OpenRS(tableName);            ByteArrayOutputStream bos = null;            DataOutputStream dos = null;            Field fd = null;            Row row = null;            byte[] SendByte = null;            //创建            bos = new ByteArrayOutputStream();            dos = new DataOutputStream(bos);            try {                //写入字段数                dos.writeShort((short) Fields.size());                //写入字段                for (int i = 0; i < Fields.size(); i++) {                    fd = (Field) Fields.elementAt(i);                    //字段名                    dos.writeUTF(fd.FiledName);                    //类型                    dos.writeByte(fd.FiledType);                    //是否计算字段                    dos.writeBoolean(fd.CalField);                    //表达式                    dos.writeUTF(fd.CalExpression);                }                SendByte = bos.toByteArray();                rs.addRecord(SendByte, 0, SendByte.length);                bos.close();                dos.close();                //写入具体内容                for (int i = 0; i < allRows.size(); i++) {                    bos = null;                    dos = null;                    bos = new ByteArrayOutputStream();                    dos = new DataOutputStream(bos);                    row = (Row) allRows.elementAt(i);                    dos.writeBoolean(row.visible);                    for (int j = 0; j < Fields.size(); j++) {                        dos.writeUTF(row.getValueByFieldIndex(j));                    }                    //写入                    SendByte = bos.toByteArray();                    rs.addRecord(SendByte, 0, SendByte.length);                    bos.close();                    dos.close();                    bos = null;                    dos = null;                }                rs.closeRecordStore();            } catch (Exception e) {            }        }        public void deleteTable(String tableName) {            try {                RecordStore.deleteRecordStore(tableName);            } catch (Exception e) {            }        }        //装载        public void loadTable(String tableName) {            //清空当前记录            internalClearFields();            //id数组            int[] arrayID = null;            //读新记录            RecordStore rs = OpenRS(tableName);            try {                if (rs.getNumRecords() == 0) {                    rs.closeRecordStore();                    return;                }            } catch (Exception e) {            }            ByteArrayInputStream bis = null;            DataInputStream dis = null;            byte[] recByte = null;            try {                RecordEnumeration rem = rs.enumerateRecords(null, null, false);                //记录的顺序要重新排布                arrayID = new int[rem.numRecords()];                int index = 0;                while (rem.hasNextElement()) {                    arrayID[index] = rem.nextRecordId();                    index++;                }                boolean asc = arrayID[0] < arrayID[arrayID.length - 1] ? true : false;                //读字段                 recByte = rs.getRecord(arrayID[asc?0:arrayID.length-1]);                bis = new ByteArrayInputStream(recByte);                dis = new DataInputStream(bis);                //字段数目                short fieldNum = dis.readShort();                for (int i = 0; i < fieldNum; i++) {                    Field fd = new Field();                    fd.FiledName = dis.readUTF();                    fd.FiledType = dis.readByte();                    fd.CalField = dis.readBoolean();                    fd.CalExpression = dis.readUTF();                    Fields.addElement(fd);                }                bis.close();                dis.close();                bis = null;                dis = null;                //读具体内容                for (int i = 1;                        i < arrayID.length;                        i++) {                    recByte = rs.getRecord(arrayID[asc?i:arrayID.length-i-1]);                    bis = new ByteArrayInputStream(recByte);                    dis = new DataInputStream(bis);                    Row row = new Row();                    row.visible = dis.readBoolean();                    for (int j = 0; j < Fields.size(); j++) {                        String ok=dis.readUTF();                        row.setValueByFieldIndex(j, ok);                    }                    allRows.addElement(row);                    if(row.visible)Rows.addElement(row);                    dis.close();                    bis.close();                    bis = null;                    dis = null;                }                

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -