📄 sdadataset.java
字号:
Row row = null; RecNo = 0; row = (Row) Rows.elementAt(RecNo); doDataChangeScroll(row); refreshDataControl(); return row; } else { return null; } } public Row Prior() { return internalPrior(); } private Row internalPrior() { if (Rows.size() > 0) { if (RecNo > 0) { Row row = null; RecNo--; refreshDataControl(); row = (Row) Rows.elementAt(RecNo); doDataChangeScroll(row); return row; } else { return null; } } else { return null; } } public Row Next() { return internalNext(); } private Row internalNext() { if (Rows.size() > 0) { if (RecNo < Rows.size() - 1) { Row row = null; RecNo++; refreshDataControl(); row = (Row) Rows.elementAt(RecNo); doDataChangeScroll(row); return row; } else { return null; } } else { return null; } } public Row Last() { return internalLast(); } private Row internalLast() { if (Rows.size() > 0) { RecNo = Rows.size() - 1; refreshDataControl(); Row row = null; row = (Row) Rows.elementAt(RecNo); doDataChangeScroll(row); return row; } else { return null; } } public boolean isEof() { return RecNo == Rows.size() - 1; } //删除 public boolean deleteRow() { return internalDeleteRow(); } private boolean internalDeleteRow() { if (allRows.size() > 0) { Row row = (Row) Rows.elementAt(RecNo); Rows.removeElementAt(RecNo); if (RecNo > Rows.size() - 1) { RecNo--; refreshDataControl(); doDataChangeScroll(RecNo); } allRows.removeElement(row); row = null; return true; } else { return false; } } //判断是否有自动序号字段,有就自动写入序号 private void setAutoID() { if (!autoID) { return; } Field fd = null; Row row = null; for (int i = 0; i < Rows.size(); i++) { row = (Row) Rows.elementAt(i); for (int j = 0; j < Fields.size(); j++) { fd = (Field) Fields.elementAt(j); if (fd.FiledType == FieldAudoID) { row.valueList.setElementAt(String.valueOf(i + 1), j); } } } } //增加 public void addRow(Row row) { internalAddRow(row); } private void internalAddRow(Row row) { if (isCanAddRow()) { if (!allRows.contains(row)) { allRows.addElement(row); if (row.visible) { Rows.addElement(row); //计算 try { calField(row); } catch (Exception e) { } //计算自动ID setAutoID(); refreshDataControl(); } } } else { System.out.println("Can not add row."); } } public void addRow(String[] stringArray) { internalAddRow(stringArray); } private void internalAddRow(String[] stringArray) { if (isCanAddRow()) { Row row = new Row(); for (int i = 0; i < stringArray.length; i++) { row.setValueByFieldIndex(i, stringArray[i]); } addRow(row); } else { System.out.println("Can not add row."); } } public void deleteRow(Row row) { internalDeleteRow(row); } private void internalDeleteRow(Row row) { if (Rows.contains(row)) { Rows.removeElement(row); allRows.removeElement(row); if (RecNo > Rows.size() - 1) { RecNo--; refreshDataControl(); Row srow = null; srow = getRow(RecNo); doDataChangeScroll(srow); } row = null; //ID setAutoID(); } } public void deleteRow(int recNo) { internalDeleteRow(recNo); } private void internalDeleteRow(int recNo) { if ((recNo > -1) && (recNo < Rows.size())) { Row row = (Row) Rows.elementAt(recNo); Rows.removeElementAt(recNo); allRows.removeElement(row); row = null; if (RecNo > Rows.size() - 1) { RecNo--; refreshDataControl(); Row srow = null; srow = getRow(RecNo); doDataChangeScroll(srow); } //ID setAutoID(); } } public Row getRow() { return internalGetRow(); } private Row internalGetRow() { if (RecNo > -1) { return (Row) Rows.elementAt(RecNo); } else { return null; } } public Row getRow(int recNo) { return internalGetRow(recNo); } private Row internalGetRow(int recNo) { if (Rows.size() > 0) { if ((recNo > -1) && (recNo < Rows.size())) { return (Row) Rows.elementAt(recNo); } else { return null; } } else { return null; } } public Row getRow(String fieldName, String fieldValue) { return internalGetRow(fieldName, fieldValue); } private Row internalGetRow(String fieldName, String fieldValue) { if (!Fields.contains(fieldName)) { return null; } else { int index = getFieldIndex(fieldName); Row result = null; if (index > -1) { for (int i = 0; i < Rows.size(); i++) { Row row = (Row) Rows.elementAt(i); if ((row.valueList.elementAt(index)).equals(fieldValue)) { result = row; break; } } } return result; } } private Row getDeltaRow(String fieldName, String fieldValue) { if (!deltaFields.contains(fieldName)) { return null; } else { int index = getFieldIndex(fieldName); Row result = null; if (index > -1) { for (int i = 0; i < deltaRows.size(); i++) { Row row = (Row) deltaRows.elementAt(i); if ((row.valueList.elementAt(index)).equals(fieldValue)) { result = row; break; } } } return result; } } //处理计算字段 private void calField(Row row) throws Exception { Field fd; for (int i = 0; i < Fields.size(); i++) { fd = (Field) Fields.elementAt(i); if (fd.CalField) { exp.setExpression(fd.CalExpression); Enumeration vars = exp.VarsList.keys(); while (vars.hasMoreElements()) { String fieldName = (String) vars.nextElement(); exp.setParamValue(fieldName, row.getValueByFieldName(fieldName)); } //计算 try { double value = exp.calculate(); row.setValueByFieldIndex(i, String.valueOf(value)); } catch (Exception e) { throw new Exception(e.getMessage()); } } } } //对内容排序(暂时实现单字段排序,排序的时候要判断字段类型) public void sortDataSet(String fieldName, int sortType) { internalSortDataSet(fieldName, sortType); doDataChangeScroll(RecNo); } private void internalSortDataSet(String fieldName, int sortType) { //新列 Vector tempRows = new Vector(); Enumeration list = Rows.elements(); while (list.hasMoreElements()) { tempRows.addElement(list.nextElement()); } Rows.removeAllElements(); //行 Row currRow = null; //列 int fieldType = getField(fieldName).FiledType; int fieldID = getFieldIndex(fieldName); //两个比较值 String tmpVal = null; String currVal = null; Row tmpRow = null; while (!tempRows.isEmpty()) { tmpRow = (Row) tempRows.elementAt(0); tmpVal = tmpRow.getValueByFieldIndex(fieldID); for (int i = 1; i < tempRows.size(); i++) { currRow = (Row) tempRows.elementAt(i); currVal = currRow.getValueByFieldIndex(fieldID); if ((currVal == null) || (currVal.equals(""))) { continue; } if ((tmpVal == null) || (tmpVal.equals(""))) { tmpRow = currRow; tmpVal = currVal; continue; } switch (fieldType) { case FieldDouble: case FieldByte: case FieldFloat: case FieldInteger: case FieldLong: case FieldShort: { if (Double.parseDouble(currVal) > Double.parseDouble(tmpVal)) { tmpRow = currRow; tmpVal = currVal; continue; } } case FieldString: case FieldBoolean: { //比较 if (currVal.compareTo(tmpVal) > 0) { tmpRow = currRow; tmpVal = currVal; continue; } } } } tempRows.removeElement(tmpRow); if (Rows.isEmpty() || (sortType == sortDesc)) { Rows.addElement(tmpRow); } else if (sortType == sortAsc) { Rows.insertElementAt(tmpRow, 0); } } //自动ID setAutoID(); //刷新 refreshDataControl(); } //数据集合的装载 public void fillDataSet(byte[] dataBuffer) { internalFillDataSet(dataBuffer); } private void internalFillDataSet(byte[] dataBuffer) { internalClearFields(); ByteArrayInputStream bis = new ByteArrayInputStream(dataBuffer); DataInputStream dis = new DataInputStream(bis); try { //字段区 int FieldsLen = dis.readInt(); byte[] fieldbyte = new byte[FieldsLen]; dis.read(fieldbyte); ByteArrayInputStream fieldbis = new ByteArrayInputStream(fieldbyte); DataInputStream fielddis = new DataInputStream(fieldbis); while (fielddis.available() > 0) { //读长度 int fieldLen = fielddis.readByte(); byte[] fb = new byte[fieldLen]; if (fieldLen > 0) { fielddis.read(fb); Fields.addElement(new String(fb, "UTF-8")); } } fieldbis.close(); fielddis.close(); //内容区 int valuesLen = 0; while (dis.available() > 0) { valuesLen = dis.readInt(); byte[] valuebyte = new byte[valuesLen]; dis.read(valuebyte); ByteArrayInputStream valuebis = new ByteArrayInputStream(valuebyte); DataInputStream valuedis = new DataInputStream(valuebis); Vector valueVector = new Vector(); while (valuedis.available() > 0) { //读长度 int valueLen = valuedis.readInt(); byte[] fb = new byte[valueLen]; if (valueLen > 0) { valuedis.read(fb); String fv = new String(fb, "UTF-8"); valueVector.addElement(fv); } else { valueVector.addElement(""); } } //加到列表 Rows.addElement(valueVector); //关闭 valuebis.close(); valuedis.close(); } if (Rows.size() > 0) { RecNo = 0; refreshDataControl(); doDataChangeScroll(RecNo); } } catch (Exception e) { } finally { try { bis.close(); dis.close(); } catch (Exception e) { } } //ID setAutoID(); } //内容滚动事件 public void setOnDataScrollChange(DataScrollChangeEvent onDataScrollChange) { this.onDataScrollChange = onDataScrollChange; } //过滤 public void setOnDataFilter(DataFilterEvent onDataFilter) { this.onDataFilter = onDataFilter; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -