/*
* Created on 2004-7-2 by Jem.Lee
* TestFormData.java is a part of com.test
* ALL RIGHTS RESERVED.
* COPYRIGHT (C) 2004. Jem
*/
package com.test;
import cn.bs.common.transdata.TransFormData;
import cn.bs.common.transdata.TransFormTable;
/**
* <PRE>
* History
* 2004-7-2 22:46:54 created by Jem.Lee
*
* 目的
* 测试H-DTO模式
* </PRE>
*/
public class TestFormData {
public static void main(String[] args) throws Exception {
//申明TransFormData对象
TransFormData sesData = new TransFormData();
//向TransFormData对象(sesData)放置数据
sesData.putFieldValueO("Test1","Test1Value");
sesData.putFieldValueO("Test2","Test2Value");
sesData.putFieldValueO("Test3","Test3Value");
sesData.putFieldValueO("Test4","Test4Value");
//从TransFormData对象(sesData)取得数据
System.out.println(sesData.getFieldValue("Test1"));
System.out.println(sesData.getFieldValue("Test2"));
System.out.println(sesData.getFieldValue("Test3"));
System.out.println(sesData.getFieldValue("Test4"));
//向TransFormData增加一张表
TransFormTable table = sesData.addTable("MyTable");
for(int i = 0; i < 10; i ++){ //10 rows
//向表增加一条记录
TransFormData data = table.add(); //5 counlums
//往记录里面添加Field,并设值
data.putFieldValueO("tableCoun1","01");
data.putFieldValueO("tableCoun2","02");
data.putFieldValueO("tableCoun3","03");
data.putFieldValueO("tableCoun4","04");
data.putFieldValueO("tableCoun5","05");
}
System.out.println("-------------------table1----------------------");
for(int i = 0; i < 10; i ++){
//从表中获得一条记录
TransFormData rec = table.get(i);
//获得记录的每个field的值
System.out.print(rec.getFieldFromName("tableCoun1").getValue());
System.out.print("|");
System.out.print(rec.getFieldFromName("tableCoun2").getValue());
System.out.print("|");
System.out.print(rec.getFieldFromName("tableCoun3").getValue());
System.out.print("|");
System.out.print(rec.getFieldFromName("tableCoun4").getValue());
System.out.print("|");
System.out.print(rec.getFieldFromName("tableCoun5").getValue());
System.out.println("|");
}
TransFormTable table2 = null;
int tableSize = 0;
//向TransFormData对象增加一个表,
//并判断该表是否存在,如果存在,则获取该表的对象,否则创建表
try{
table2 = sesData.addTable("MyTable");
}catch(Exception ex){
table2 = sesData.getTable("MyTable");
tableSize = table2.size();
}
for(int i = 0; i < tableSize; i ++){ //5 rows
TransFormData data = null;
//向表中增加记录,并判断该记录是否存在,
//如果存在,则获取该记录的对象,否则创建记录
try{
data = table2.add(); //5 counlums
}catch(Exception ex){
data = table2.get(i);
}
data.putFieldValueO("table2Coun1","01");
data.putFieldValueO("table2Coun2","02");
data.putFieldValueO("table2Coun3","03");
data.putFieldValueO("table2Coun4","04");
data.putFieldValueO("table2Coun5","05");
}
System.out.println("----------------table2---------------------");
for(int i = 10; i < 20; i ++){
TransFormData rec = table2.get(i);
System.out.print(rec.getFieldFromName("table2Coun1").getValue());
System.out.print("|");
System.out.print(rec.getFieldFromName("table2Coun2").getValue());
System.out.print("|");
System.out.print(rec.getFieldFromName("table2Coun3").getValue());
System.out.print("|");
System.out.print(rec.getFieldFromName("table2Coun4").getValue());
System.out.print("|");
System.out.print(rec.getFieldFromName("table2Coun5").getValue());
System.out.println("|");
}
}
}
|