cyderick
Posts: 3
|
Posted: 06/28/2013, 3:36 AM |
|
hi, my problem is my checkbox list only save the last key of my selection, but im following the example pack of codecharge guide to do this, the result is the example pack in codecharge does not working. But the example given from internet (http://examples.codecharge.com/) is working!
this is the class for insert, update, and delete, this is copy from example pack of codecharge
class ProjectEmployeesModifyCheckboxList {
final public void process(Page page, String mode) {
String[] projectList = page.getHttpPostParameters().getParameterValues("ProjectList");
long empId = 0;
try {
empId = Long.parseLong(DBTools.toSql(page.getHttpGetParameter("emp_id"),JDBCConnection.INTEGER, "CC5Ajax"));
System.out.println("empId:"+empId);
} catch (Exception e_ignore) {}
if ( "Insert".equals(mode) ) { /
/Retrieve the last inserted key
//Use MS SQL method (disabled below)
//String lastInsKey = DBTools.convertToString(
// DBTools.dLookUp("@@IDENTITY", "employees", "", "IntranetDB"));
//Use method compatible with all databases (unsafe when multiple users
//insert records at the same time)
String lastInsKey = Utils.convertToString( DBTools.dLookUp("max(emp_id)", "employees", "", "CC5Ajax"));
//Insert New links
if (projectList != null) {
JDBCConnection conn = JDBCConnectionFactory.getJDBCConnection("CC5Ajax");
for(int i=0; i< projectList.length; i++) {
String projectId = conn.toSql(projectList, JDBCConnection.INTEGER);
System.out.println(">>>"+projectId);
conn.executeUpdate("INSERT INTO projects_employees (project_id, emp_id) VALUES (" + projectId + "," + lastInsKey + ")");
}
conn.closeConnection();
}
} else if (empId > 0) {
JDBCConnection conn = JDBCConnectionFactory.getJDBCConnection("CC5Ajax");
if ("Delete".equals(mode) || "Update".equals(mode)) {
//Delete project employees links
conn.executeUpdate("DELETE FROM projects_employees WHERE emp_id=" + empId);
}
if ("Update".equals(mode)) {
//Insert assigned employees
for(int i=0; i<projectList.length; i++) {
String projectId = conn.toSql(projectList, JDBCConnection.INTEGER);
conn.executeUpdate("INSERT INTO projects_employees (project_id, emp_id) VALUES (" + projectId + "," + empId + ")");
}
} conn.closeConnection(); }
}
}
String[] projectList = page.getHttpPostParameters().getParameterValues("ProjectList");
_________________
hi |