?? proactivitysrc.java.svn-base
字號:
package com.nsi.components.proactivity;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.nsi.components.src.NsiAbstractSrc;
import com.nsi.control.exceptions.NsiEventException;
import com.nsi.util.ValHelper;
/**
* @author Chris Ye, created on Oct 3, 2008
*
* ProActivitySrc
*/
public class ProActivitySrc extends NsiAbstractSrc
{
private static Log log = LogFactory.getLog(ProActivitySrc.class);
private ProActivityInfo info;
private String projectid;
/**
* constructor of ProActivitySrc
* @throws NsiEventException
*/
public ProActivitySrc()throws NsiEventException
{
super();
projectid = "";
info = new ProActivityInfo();
}
public ProActivityInfo getInfo()
{
return info;
}
public void setInfo(ProActivityInfo info)
{
this.info = info;
}
public String getProjectid()
{
return projectid;
}
public void setProjectid(String projectid)
{
this.projectid = projectid;
}
public void load() throws NsiEventException
{
selectProActivity();
}
public void store() throws NsiEventException
{
updateProActivity();
}
public boolean isProjectExists( String inprojectid ) throws NsiEventException
{
boolean flag = false;
String sSql = "select projectid from t_project where projectid =" + inprojectid;
try
{
getConnection();
List<Map<String,String>> result = sdrc.executeRetrieve(conn, sSql);
if(!result.isEmpty())
{
projectid = inprojectid;
flag = true;
}
}
catch(SQLException se)
{
log.error("isExists() -- caught SQLException : ", se);
throw new NsiEventException("isExists() -- caught SQLException : ", se);
}
catch(Exception ex)
{
log.error("projExists() -- caught Exception : ", ex);
throw new NsiEventException("projExists() -- caught Exception : ", ex);
}
finally
{
closeConnection();
}
return flag;
}
public boolean isExists() throws NsiEventException
{
boolean flag = false;
String sSql = "select projectid from t_project where projectid =" + projectid;
try
{
getConnection();
List<Map<String,String>> result = sdrc.executeRetrieve(conn, sSql);
if(!result.isEmpty()) flag = true;
}
catch(SQLException se)
{
log.error("isExists() -- caught SQLException : ", se);
throw new NsiEventException("isExists() -- caught SQLException : ", se);
}
catch(Exception ex)
{
log.error("projExists() -- caught Exception : ", ex);
throw new NsiEventException("projExists() -- caught Exception : ", ex);
}
finally
{
closeConnection();
}
return flag;
}
private void selectProActivity() throws NsiEventException
{
String sSql = "select a.projactid,a.projectid,a.activityid,a.bbillable,a.moduserid,a.bactive " +
"from t_proj_act a, ct_activity b " +
"where a.activityid = b.activityid and a.projectid=" + projectid + " " +
"order by b.activity";
try
{
getConnection();
List<Map<String,String>> result = sdrc.executeRetrieve(conn, sSql);
info.reset();
info.setProjectid(projectid);
if(!result.isEmpty())
{
int size = result.size();
for (int i = 0; i < size; i++)
{
Map<String,String> dtlresult = result.get(i);
ProActDetail actDetail = new ProActDetail();
actDetail.setProactid(ValHelper.getInstance().getValue(dtlresult, "projactid"));
modifyuser = ValHelper.getInstance().getValue(dtlresult, "moduserid");
actDetail.setProjectid(projectid);
actDetail.setActid(ValHelper.getInstance().getValue(dtlresult, "activityid"));
actDetail.setBillable(ValHelper.getInstance().getValue(dtlresult, "bbillable"));
actDetail.setActive(ValHelper.getInstance().getValue(dtlresult, "bactive"));
info.getDetaillist().add(actDetail);
}
}
}
catch(SQLException se)
{
log.error("selectProActivity() -- caught SQLException : ", se);
throw new NsiEventException("selectProActivity() -- caught SQLException : ", se);
}
catch(Exception ex)
{
log.error("selectProActivity() -- caught Exception : ", ex);
throw new NsiEventException("selectProActivity() -- caught Exception : ", ex);
}
finally
{
closeConnection();
}
}
private void updateProActivity() throws NsiEventException
{
List<ProActDetail> detailList=info.getDetaillist();
if(!detailList.isEmpty())
{
try
{
int size = detailList.size();
for (int i = 0; i < size; i++)
{
ProActDetail detail = detailList.get(i);
String sSql = "";
String projID = detail.getProjectid();
if(projectid.trim().equalsIgnoreCase(projID.trim()))
{
sSql = prepareSql(detail,projID);
}
if(!"".equalsIgnoreCase(sSql)) try
{
getConnection();
Statement stm = conn.createStatement();
int resultCount = sdrc.executeUpdate(stm, sSql);
if(resultCount != 1) throw new NsiEventException("ERROR update projectAct from t_pro_act!! resultCount = " + resultCount);
}
catch(SQLException se)
{
log.error("updateProActivity() -- caught SQLException : ", se);
throw new NsiEventException("updateProActivity() -- caught SQLException : ", se);
}
catch(Exception ex)
{
log.error("updateProActivity() -- caught Exception : ", ex);
throw new NsiEventException("updateProActivity() -- caught Exception : ", ex);
}
finally
{
closeConnection();
}
}
}
catch(Exception ex)
{
log.error("updateProActivity() -- caught Exception : ", ex);
throw new NsiEventException("updateProActivity() -- caught Exception : ", ex);
}
}
}
private String prepareSql(ProActDetail detail, String projID)
{
String sql="";
String proactid = detail.getProactid();
String actID = detail.getActid();
String active = detail.getActive();
String billable = detail.getBillable();
if( ValHelper.getInstance().isNotNullAndEmpty(proactid))
{
sql = "update t_proj_act set moduserid=" + modifyuser.trim() + ", " + "projectid=" + projID + ", " +
"activityid=" + actID + ", " + "bbillable='" + billable.trim()+ "', " + "bactive='" + active.trim() + "' " +
"where projactid=" + proactid + "";
}
else
{
if(( ValHelper.getInstance().isNotNullAndEmpty(actID)) &&( ValHelper.getInstance().isNotNullAndEmpty(active)) && ( ValHelper.getInstance().isNotNullAndEmpty(billable)))
{
sql = "insert into t_proj_act ( projactid,projectid,activityid,bactive,bbillable,moduserid ) " +
"values ( nextval('projactid_seq'), " + projID.trim() + "," + actID.trim() + "," + "'" + active.trim() + "'," +
"'" + billable.trim() + "', " + modifyuser.trim() + " )";
}
}
return sql;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -