📄 yymdb.java
字号:
else {
errorMessage = "(del_table)Can't find this table!";
}
}
catch (Exception e) {
errorMessage = "DelTable Error!\nMessage:" + e;
}
finally {
}
}
public void add_field(String tblname, String fldname) {
clsTable temp = null;
try {
if (existsTable(tblname) == true && !tblname.equals("")) {
for (int i = 0; i < table.size(); i++) {
temp = (clsTable) table.get(i);
if (existsField(tblname, fldname) == true
&& !fldname.equals("")) {
errorMessage = "Error Field Name!!!";
}
else {
if (!RowCountLargeThanOne(tblname)) {
if (temp.getName().equals(tblname)) {
temp.field.add(new clsField(fldname));
table.set(i, temp);
break;
}
}
else {
errorMessage =
"(AddField)About a has row table,you can not add a new field!";
}
}
}
}
else {
errorMessage = "(add_field)Can't find this table!";
}
}
catch (Exception e) {
errorMessage = "AddField Error!\nMessage:" + e;
}
finally {
}
}
public void del_field(String tblname, String fldname) {
try {
clsTable temptbl;
clsField tempfld;
if (existsTable(tblname) && existsField(tblname, fldname)) {
for (int k = 0; k < table.size(); k++) {
temptbl = (clsTable) table.get(k);
if (temptbl.getName().equals(tblname)) {
for (int i = 0; i < temptbl.field.size(); i++) {
tempfld = (clsField) temptbl.field.get(i);
if (tempfld.getName().equals(fldname)) {
tempfld.value.clear();
temptbl.field.set(i, tempfld);
temptbl.field.remove(i);
table.set(k, temptbl);
break;
}
}
}
}
}
else {
errorMessage = "(del_field)Can't find this table or field!";
}
}
catch (Exception e) {
errorMessage = "DelField Error!\nMessage:" + e;
}
finally {
}
}
public void add_row(String tblname, String value[]) {
clsField tempfld;
clsTable temptbl;
try {
for (int k = 0; k < table.size(); k++) {
temptbl = (clsTable) table.get(k);
if (temptbl.getName().equals(tblname)) {
if (value.length == temptbl.field.size()) {
for (int i = 0; i < temptbl.field.size(); i++) {
tempfld = (clsField) temptbl.field.get(i);
tempfld.value.add(value[i]);
temptbl.field.set(i, tempfld);
}
}
table.set(k, temptbl);
break;
}
}
}
catch (Exception e) {
errorMessage = "AddRow Error!\nMessage:" + e.getMessage();
}
}
public void del_row(String tblname, String whereField, String whereValue) {
clsField tempfld;
clsTable temptbl;
String out = new String();
try {
if (existsTable(tblname) == true
&& existsField(tblname, whereField) == true) {
int tempRowIndex;
for (int i = 0; i < table.size(); i++) {
temptbl = (clsTable) table.get(i);
if (temptbl.getName().equals(tblname)) {
for (int j = 0; j < temptbl.field.size(); j++) {
tempfld = (clsField) temptbl.field.get(j);
if (tempfld.getName().equals(whereField)) {
for (int m = 0; m < tempfld.value.size(); m++) {
String tempFieldValue = new String();
tempFieldValue = (String) tempfld.value
.get(m);
if (tempFieldValue.equals(whereValue)) {
tempRowIndex = m;
for (int k = 0; k < temptbl.field
.size(); k++) {
clsField tempdelrowfld;
tempdelrowfld = (clsField) temptbl.field
.get(k);
tempdelrowfld.value
.remove(tempRowIndex);
temptbl.field.set(k, tempdelrowfld);
}
table.set(i, temptbl);
break;
}
}
}
}
}
}
}
else {
errorMessage = "(del_row)Can't find this table or field!";
}
}
catch (Exception e) {
errorMessage = "DelRow Error!\nMessage:" + e;
}
finally {
}
}
public String return_all() {
String out = new String();
try {
out = out + "\n Database:" + name + " ";
out = out + "\n==========START==========";
for (int i = 0; i < table.size(); i++) {
clsTable temp = (clsTable) table.get(i);
clsField tempfld;
out = out + "\n Table:" + temp.getName();
if (temp.field.size() != 0) {
clsField tempfield = (clsField) temp.field.get(0);
for (int m = 0; m < tempfield.value.size(); m++) {
for (int j = 0; j < temp.field.size(); j++) {
tempfld = (clsField) temp.field.get(j);
out = out + "\n " + tempfld.getName() + ":";
out = out + (String) tempfld.value.get(m);
}
out = out + "\n------------------------------";
}
}
}
out = out + "\n===========END===========\n";
}
catch (Exception e) {
}
return out;
}
public void openDB(String filename) {
try {
table.clear();
setName("");
if (!filename.equals("") || !new File(filename).exists() == false) {
File f = new File(filename);
System.out.println("Loading Database.....");
SAXParserFactory saxpf = SAXParserFactory.newInstance();
SAXParser saxparser = saxpf.newSAXParser();
SaxParser parser1 = new SaxParser(false);
saxparser.parse(f, parser1);
SaxParser parser2 = new SaxParser(true);
saxparser.parse(f, parser2);
System.out.println("Finish Load Database!");
}
else {
errorMessage = "(OpenDB)File Name Error!";
}
}
catch (Exception e) {
errorMessage = "OpenDB Error!\nMessage:" + e + "";
}
finally {
}
}
public void saveDB(String filename) {
String headerString = "<?xml version=\"1.0\" encoding=\"gb2312\"?>\n";
String root = "<Database dbname=\"" + getName() + "\">\n";
String rootEnd = "</Database>\n";
String element;
String elementEnd;
try {
File file = new File(filename);
if (file.exists() == false) {
file.createNewFile();
}
FileWriter fwriter = new FileWriter(file);
fwriter.write(headerString);
fwriter.write(root);
clsTable temptbl;
clsField tempfld;
for (int i = 0; i < table.size(); i++) {
temptbl = retTableRef(i);
fwriter.write(" <Table tblname=\"" + temptbl.getName()
+ "\">\n");
if (temptbl.field.size() > 0
&& ( (clsField) temptbl.field.get(0)).value.size() > 0) {
for (int j = 0; j < temptbl.field.size(); j++) {
tempfld = retFieldRef(i, j);
fwriter.write(" <Field fldname=\"" + tempfld.getName()
+ "\">\n");
for (int k = 0; k < ( (clsField) temptbl.field.get(0)).value
.size(); k++) {
fwriter.write(" <Value " + "val=\"" +
(tempfld.value.get(k)).toString() + "\" />\n");
}
fwriter.write(" </Field>\n");
}
}
fwriter.write(" </Table>\n");
}
fwriter.write(rootEnd);
fwriter.close();
}
catch (Exception e) {
System.out.println("SaveDB Error!!!\nMessage:" + e);
}
finally {
}
}
public void setTableName(String oldtblname, String newtblname) {
try {
clsTable temptbl;
if (table.size() > 0 && existsTable(oldtblname)) {
for (int i = 0; i < table.size(); i++) {
temptbl = (clsTable) table.get(i);
if (temptbl.getName() == oldtblname) {
temptbl.setName(newtblname);
table.set(i, temptbl);
break;
}
}
}
else {
errorMessage =
"(setTableName)Can't find this table or haven't any table!";
}
}
catch (Exception e) {
errorMessage = "SetTableName Error!\nMessage:" + e;
}
finally {
}
}
public String getFieldName(String tblname, int fldIndex) {
String out = new String();
try {
clsField tempfld;
tempfld = retFieldRef(tblname, fldIndex);
out = tempfld.getName();
}
catch (Exception e) {
errorMessage = "GetFieldName Error!\nMessage:" + e;
}
finally {
}
return out;
}
public boolean RowCountLargeThanOne(String tblname) {
boolean out = false;
try {
clsTable temptbl;
clsField tempfld;
if (existsTable(tblname)) {
for (int i = 0; i < table.size(); i++) {
temptbl = (clsTable) table.get(i);
if (temptbl.getName().equals(tblname)
&& temptbl.field.size() > 0) {
for (int j = 0; j < temptbl.field.size(); j++) {
tempfld = (clsField) temptbl.field.get(i);
if (tempfld.value.size() == 0) {
out = false;
}
else {
out = true;
}
}
break;
}
else {
out = false;
}
}
}
else {
errorMessage = "(RowCountLargeThanOne)Can't find this table!";
}
}
catch (Exception e) {
errorMessage = "RowCount Error!\nMessage:" + e;
}
finally {
}
return out;
}
public boolean TableCountLargeThanOne() {
return (table.size() > 0);
}
public boolean FieldCountLargeThanOne(String tblname) {
boolean out = false;
try {
if (existsTable(tblname) == true) {
for (int i = 0; i < table.size(); i++) {
clsTable temptbl = (clsTable) table.get(i);
if (temptbl.field.size() > 0) {
out = true;
break;
}
}
}
else {
errorMessage = "(FieldCountLargeThanOne)Can't find this table!";
}
}
catch (Exception e) {
errorMessage = "FieldCount Error!\nMessage:" + e;
}
return out;
}
public int retTableIndex(String tblname) {
clsTable temptbl;
int out = -1;
try {
if (existsTable(tblname)) {
for (int i = 0; i < table.size(); i++) {
temptbl = (clsTable) table.get(i);
if (temptbl.getName().equals(tblname)) {
out = i;
break;
}
}
}
else {
errorMessage = "(retTableIndex)Can't find this table!";
}
}
catch (Exception e) {
errorMessage = "getTableIndex Error!\nMessage:" + e;
}
return out;
}
public int retFieldIndex(String tblname, String fldname) {
clsTable temptbl;
int out = -1;
try {
temptbl = retTableRef(tblname);
clsField tempfld;
if (existsTable(tblname) && existsField(tblname, fldname)) {
for (int i = 0; i < temptbl.field.size(); i++) {
tempfld = (clsField) temptbl.field.get(i);
if (tempfld.getName().equals(fldname)) {
out = i;
break;
}
}
}
else {
errorMessage = "(getFieldIndex)Can't find this table or field!";
}
}
catch (Exception e) {
errorMessage = "getFieldIndex Error!\nMessage:" + e;
}
return out;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessageEmpty() {
errorMessage = null;
errorMessage = new String();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -