2018-06-03 22:26:41 +08:00

117 lines
2.9 KiB
Java

package com.tenwa.flow.comm.handler;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import jbo.app.VOUCHER_CONNECTION;
import com.amarsoft.are.jbo.BizObject;
import com.amarsoft.are.jbo.BizObjectManager;
import com.amarsoft.are.jbo.JBOFactory;
import com.amarsoft.are.jbo.JBOTransaction;
import com.amarsoft.awe.dw.handler.impl.CommonHandler;
import com.amarsoft.awe.util.Transaction;
public class VocherHandler extends CommonHandler {
PreparedStatement stmt = null;
String sql = null;
Connection conn = null;
ResultSet rs = null;
UUID uuid = null;
Transaction Sqlca =null;
@Override
protected void afterInsert(JBOTransaction tx, BizObject bo) throws Exception {
String AuxiliaryId=bo.getAttribute("AuxiliaryId").toString();
String id=bo.getAttribute("id").toString();
String []aux=AuxiliaryId.split(",");
BizObjectManager bm=JBOFactory.getFactory().getManager(VOUCHER_CONNECTION.CLASS_NAME);
if(AuxiliaryId.length()>0){
for(int i=0;i<aux.length;i++){
BizObject conn=bm.newObject();
conn.setAttributeValue("connection_status", "0");
conn.setAttributeValue("CONFIG_ID",id);
conn.setAttributeValue("ASSTACTTYPE", aux[i]);
bm.saveObject(conn);
}
}
// 连接数据库,并插入数据
try{
Sqlca = Transaction.createTransaction(tx);
Connection conn =tx.getConnection(Sqlca);
uuid = UUID.randomUUID();
String uid = uuid.toString().replace("-", "");
// 获取页面上的值
String name=bo.getAttribute("SUBJECTS_NAME").toString();
// 插入数据
String sql = "insert into t_fk(id,name) values(?,?)";
stmt = conn.prepareStatement(sql);
stmt.setString(1, uid);
stmt.setString(2,name);
stmt.executeUpdate();
conn.commit();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
}
}
if (stmt != null) {
try {
stmt.close();
} catch (Exception e2) {
}
}
if (conn != null) {
try {
Sqlca.disConnect();
Sqlca=null;
conn.close();
} catch (Exception e2) {
}
}
}
}
@Override
protected void beforeUpdate(JBOTransaction tx, BizObject bo)
throws Exception {
String AuxiliaryId=bo.getAttribute("AuxiliaryId").toString();
String id=bo.getAttribute("id").toString();
String []aux=AuxiliaryId.split(",");
BizObjectManager bm=JBOFactory.getFactory().getManager(VOUCHER_CONNECTION.CLASS_NAME);
bm.createQuery("delete from O where CONFIG_ID=:id").setParameter("id", id).executeUpdate();
if(AuxiliaryId.length()>0)
{
for(int i=0;i<aux.length;i++)
{
BizObject conn=bm.newObject();
conn.setAttributeValue("connection_status", "0");
conn.setAttributeValue("CONFIG_ID",id);
conn.setAttributeValue("ASSTACTTYPE", aux[i]);
bm.saveObject(conn);
}
}
}
}