`/**
- 查询数据
**/
function query(){
//异常处理
function handleException(exception){
//错误信息
handleErrorMsg(MESSAGE_NAME, "QUERY_EXCEPTION", [exception.getMessage()], null,null, HANDLER_OPTION_DEFAULT, null)
//打印 StackOverflowError
logError(MODULE_MM, exception)
//日志记录到数据库
logErrorToDB(MODULE_MM, exception.getMessage(), getDBTime(), FORM_NAME, "Function:query")
}
catch(Exception, handleException)
//查询条件
name = editQuery.getText().trim()
//获取filter对象
filter = createATRowFilter(TABLE_TEST_HXF)
//查询Filter
if(!isEmptyStr(name)){
filter.forColumnNameContaining(TABLE_TEST_HXF_NAME,name.trim())
}
//排序
// ATCOLUMN = class com.datasweep.plantops.common.constants.filtering.IATRowFilterAttributes::ATCOLUMN
ASCENDING = class com.datasweep.plantops.common.constants.filtering.IFilterSortOrders::ASCENDING
filter.addOrderATColumnBy(TABLE_TEST_HXF_NAME,ASCENDING)
//sql查询
sql = "SELECT '',name_s,age_s,gender_s,to_char(birthday_t,'YYYY-MM-DD') FROM AT_00_TQ_TESTHXFSUB aui WHERE 1=1"
list = querySql(sql) //执行sqls
gridUserInfo.clearGrid() //清空grid
gridUserInfo.setNumberOfRows(0) //行从0开始
addVectorToGrid(list, gridUserInfo) //将集合添加到grid
setGridSeq(gridUserInfo) //设置序号
gridUserInfo.resizeColumnsToFit()//图表自适应
}
/**
-
删除数据
**/
function del(){
selectRow = gridUserInfo.getSelectedRow() //拿到选中行数据
if(selectRow ==0){ //如果没选中则提示
handleErrorMsg(MESSAGE_NAME, "SELECT_DEL_ROW", null, null,null, HANDLER_OPTION_DEFAULT, null)
return
} else{ //选中后点删除 弹出确认窗口
if(handleQuestionMsg(TRX_MSG,"IS_DELETE",null,null,HANDLER_OPTION_DEFAULT,null) == HANDLER_RESULT_YES){
//确认删除后
atHandler = createATHandler(TABLE_TEST_HXF) //创建数据库Handler对象
atRowFilter = createATRowFilter(TABLE_TEST_HXF) //创建数据库Filter对象name = gridUserInfo.getCellText(selectedRow,1) //从选中行中获取用于查询的值
atRowFilter.forColumnNameEqualTo(TABLE_TEST_HXF_NAME,name) //设置查询条件
atRowVector = atHandler.getATRowsByFilter(atRowFilter,false) //查询
//如果有查到数据,则执行删除
if(atRowVector.size() >0){
atRow = atRowVector.elementAt(0)atRow.delete() //逻辑 response = atHandler.save() //入库
if(response.isError()){
handleErrorMsg(MESSAGE_NAME,"DELETE_FILE",null,null,HANDLER_OPTION_DEFAULT,null)
return
}
handleInfoMsg(MESSAGE_NAME,"DELETE_SUCCESSFULLY",null,null,HANDLER_OPTION_DEFAULT,null)
gridUserInfo.deleteGridRow(selectedRow) //删除主界面grid的数据
gridResie(gridUserInfo) //刷新grid
}
}
}
}
/** -
编辑
**/
function edit(){selectRow = gridUserInfo.getSelectedRow() //选中的行号 行号从0开始
if(selectRow ==-1){
dialogError("请选择需要修改的行!")
return
}
//获取编辑框中的输入值
name = gridUserInfo.getCellText(selectRow,1)
age = gridUserInfo.getCellText(selectRow,2)
birthday = gridUserInfo.getCellValue(selectRow,4)
gender = gridUserInfo.getCellText(selectRow,3)form = getForm(FORM_NAME_ADD) //获取form
if(form != null){
//setFormProperty主界面向子界面传值
setFormProperty(form,"name",name)
setFormProperty(form,"age",age)
setFormProperty(form,"birthday",birthday)
setFormProperty(form,"gender",gender)
setFormProperty(form,"isEdit",true)
showAsDialog(form) //弹窗atRowResult = getFormProperty(form,"SAVE_RESULT") //获取保存结果
if(atRowResult != null){
showSaveResult(atRowResult,gridUserInfo.getNumberOfRows())
}
setFormProperty(form,"SAVE_RESULT",null)
query() //查询刷新数据
}
}
/**
- 新增数据
**/
function add(){
//获取新增form
form = getForm(FORM_NAME_ADD)
//新增Form为空时
if(form != null){
//弹窗
showAsDialog(form)
//获取返回值
atRowResult = getFormProperty(form,"SAVE_RESULT")
if(atRowResult != null){
showSaveResult(atRowResult,gridUserInfo.getNumberOfRows())
}
setFormProperty(form,"SAVE_RESULT",null)
query()//查询刷新数据
}
}
/**
- 新增数据之保存或编辑 -add弹窗
**/
function add(){
//异常信息
function handleException(exception){
//错误消息
handleErrorMsg(MESSAGE_NAME, "ADD_EXCEPTION", [exception.getMessage()], null,null, HANDLER_OPTION_DEFAULT, null)
//打印 StackOverflowError
logError(MODULE_MM, exception)
//日志记录到数据库
logErrorToDB(MODULE_MM, exception.getMessage(), getDBTime(), FORM_NAME, "Function:add")
}
catch(Exception, handleException)
name = editName.getText().trim()
age = editAge.getText().trim()
birthday = dateTimePickerBirthday.getValue()
if(radioButton1.getChecked()){
gender = radioButton1.getText().trim()
} else{
gender = radioButton2.getText().trim()
}
//创建查询filter
atRowFilter = createATRowFilter(TABLE_TEST_HXF)
//查询 注意查询的字段必须为唯一
atRowFilter.forColumnNameEqualTo(TABLE_TEST_HXF_NAME,name)
atRowVector = atRowFilter.exec()
atHandler = createATHandler(TABLE_TEST_HXF)
atRow = atHandler.createATRow()
//判断新增的数据是否存在,存在则更新,不存在则插入
if(atRowVector.size() >0){
atRow = atRowVector[0] //如果存在数据则将查询出的结果赋值给atRow,此时atRow中会有库中此条数据的唯一标识
}
//将数据存入atRow
atRow.setValue(TABLE_TEST_HXF_NAME,name)
atRow.setValue(TABLE_TEST_HXF_AGE,age)
atRow.setValue(TABLE_TEST_HXF_BIRTHDAY,birthday)
atRow.setValue(TABLE_TEST_HXF_GENDER,gender)
response = atRow.save(null,null,null)
if(response.isError()){
handleErrorMsg(MESSAGE_NAME,"SAVE_FILE",null,null,HANDLER_OPTION_DEFAULT,null)
return
}
handleInfoMsg(MESSAGE_NAME,"SAVE_SUCCESSFULLY",null,null,HANDLER_OPTION_DEFAULT,null)
setProperty("SAVE_RESULT",atRow) //操作结果传递
closeDialog(0) //关闭界面
}
/**
- 编辑页面初始化函数
**/
function setPageControlValue(){
name = getFormProperty("name")
age = getFormProperty("age")
gender = getFormProperty("gender")
birthday = getFormProperty("birthday")
isEdit = getFormProperty("isEdit")
println(isEdit)
if(isEdit != null && isEdit){
editName.setText(name)
editAge.setText(age)
if("男".equals(gender)){
radioButton1.setChecked(true)
}
if("女".equals(gender)){
radioButton2.setChecked(true)
}
dateTimePickerBirthday.setValue(StringToDate(birthday,1))
}
}`