請參照
http://examples.codecharge.com/ExampleP ... eckbox.php
checkbox 的做法
employees_record_BeforeShow
global $employees_record;
$ArrayProject = array();
$ProjectConnection = null;
//Populate the multi-select project CheckBox list
if($employees_record->EditMode) {
//Create a new database connection object
$ProjectConnection = New clsDBIntranetDB();
$ProjectConnection->query("SELECT project_id FROM projects_employees WHERE emp_id =".$ProjectConnection->TOSql(CCGetParam("emp_id", 0),ccsInteger));
while($ProjectConnection->next_record()) {
array_push($ArrayProject,$ProjectConnection->f("project_id"));
}
$employees_record->ProjectList->Multiple = true;
$employees_record->ProjectList->Value = $ArrayProject;
//Close and destroy the recordset
$ProjectConnection->close();
}
$ArrayProject = array();
$ProjectConnection = null;
//Populate the multi-select project CheckBox list
if($employees_record->EditMode) {
//Create a new database connection object
$ProjectConnection = New clsDBIntranetDB();
$ProjectConnection->query("SELECT project_id FROM projects_employees WHERE emp_id =".$ProjectConnection->TOSql(CCGetParam("emp_id", 0),ccsInteger));
while($ProjectConnection->next_record()) {
array_push($ArrayProject,$ProjectConnection->f("project_id"));
}
$employees_record->ProjectList->Multiple = true;
$employees_record->ProjectList->Value = $ArrayProject;
//Close and destroy the recordset
$ProjectConnection->close();
}
employees_record_AfterInsert
ProjectEmployeesModify("Insert");
最後由 yehlu 於 2007-03-15 23:41:20 編輯,總共編輯了 1 次。
employees_record_AfterUpdate
ProjectEmployeesModify("Update");
最後由 yehlu 於 2007-03-15 23:41:05 編輯,總共編輯了 1 次。
employees_record_BeforeDelete
ProjectEmployeesModify("Delete");
function ProjectEmployeesModify
function ProjectEmployeesModify($Actions){
global $DBIntranetDB;
$EmpProjectConn = null;
$EmpID = 0;
$ProjectID = 0;
$ProjectList = array();
$GetLastInsKey = 0;
//Create a new database connection object
$EmpProjectConn = new clsDBIntranetDB();
//Retrieve the current project
$EmpID = CCGetFromGet("emp_id",0);
$ProjectList = CCGetFromPost("ProjectList",array());
if($Actions == "Insert"){
//Retrieve the last inserted key
//Use MS SQL method
//$GetLastInsKey = CCDLookup("@@IDENTITY","employees","",$DBIntranetDB);
//Use a method compatible with all databases (unsafe when multiple users insert records at the same time)
$GetLastInsKey = CCDLookup("max(emp_id)", "employees", "", $DBIntranetDB);
//Insert New links
reset($ProjectList);
while(list($key,$ProjectID) = each($ProjectList)){
$EmpProjectConn->query("INSERT INTO projects_employees(project_id, emp_id) VALUES (".$EmpProjectConn->ToSQL($ProjectID,ccsInteger).",".$EmpProjectConn->ToSQL($GetLastInsKey,ccsInteger).")");
}
}
if($EmpID >0){
if( ($Actions == "Delete") Or ($Actions == "Update")){
//Delete project employees links
$EmpProjectConn->query("DELETE FROM projects_employees WHERE emp_id=".$EmpProjectConn->ToSQL($EmpID,ccsInteger));
}
if($Actions == "Update"){
//Insert assigned employees
reset($ProjectList);
while(list($key,$ProjectID) = each($ProjectList)){
$EmpProjectConn->query("INSERT INTO projects_employees (project_id, emp_id) VALUES (".$EmpProjectConn->ToSQL($ProjectID,ccsInteger).",".$EmpProjectConn->ToSQL($EmpID,ccsInteger).")");
}
}
}
//Close and destroy the database connection object
$EmpProjectConn->close();
}
global $DBIntranetDB;
$EmpProjectConn = null;
$EmpID = 0;
$ProjectID = 0;
$ProjectList = array();
$GetLastInsKey = 0;
//Create a new database connection object
$EmpProjectConn = new clsDBIntranetDB();
//Retrieve the current project
$EmpID = CCGetFromGet("emp_id",0);
$ProjectList = CCGetFromPost("ProjectList",array());
if($Actions == "Insert"){
//Retrieve the last inserted key
//Use MS SQL method
//$GetLastInsKey = CCDLookup("@@IDENTITY","employees","",$DBIntranetDB);
//Use a method compatible with all databases (unsafe when multiple users insert records at the same time)
$GetLastInsKey = CCDLookup("max(emp_id)", "employees", "", $DBIntranetDB);
//Insert New links
reset($ProjectList);
while(list($key,$ProjectID) = each($ProjectList)){
$EmpProjectConn->query("INSERT INTO projects_employees(project_id, emp_id) VALUES (".$EmpProjectConn->ToSQL($ProjectID,ccsInteger).",".$EmpProjectConn->ToSQL($GetLastInsKey,ccsInteger).")");
}
}
if($EmpID >0){
if( ($Actions == "Delete") Or ($Actions == "Update")){
//Delete project employees links
$EmpProjectConn->query("DELETE FROM projects_employees WHERE emp_id=".$EmpProjectConn->ToSQL($EmpID,ccsInteger));
}
if($Actions == "Update"){
//Insert assigned employees
reset($ProjectList);
while(list($key,$ProjectID) = each($ProjectList)){
$EmpProjectConn->query("INSERT INTO projects_employees (project_id, emp_id) VALUES (".$EmpProjectConn->ToSQL($ProjectID,ccsInteger).",".$EmpProjectConn->ToSQL($EmpID,ccsInteger).")");
}
}
}
//Close and destroy the database connection object
$EmpProjectConn->close();
}
我的做法
new_prod_new_prod_a_BeforeShow
//設定為可多值,並將資料庫的值轉為陣列
$new_prod->new_prod_a->Multiple = true;
$new_prod_a = $new_prod->ds->new_prod_a->getValue();
$new_prod_a_v = explode(",", $new_prod_a);
$new_prod->new_prod_a->setValue($new_prod_a_v);
new_prod_ds_BeforeBuildInsert
new_prod_ds_BeforeBuildUpdate
//把填入的值轉回字串放入資料庫
$new_prod_a = $_POST["new_prod_a"];
foreach($new_prod_a as $key => $value){
$new_prod_a_v .= $value.",";
}
$new_prod_a_v = substr($new_prod_a_v,0,-1);
$new_prod->ds->new_prod_a->setValue($new_prod_a_v);
//設定為可多值,並將資料庫的值轉為陣列
$new_prod->new_prod_a->Multiple = true;
$new_prod_a = $new_prod->ds->new_prod_a->getValue();
$new_prod_a_v = explode(",", $new_prod_a);
$new_prod->new_prod_a->setValue($new_prod_a_v);
new_prod_ds_BeforeBuildInsert
new_prod_ds_BeforeBuildUpdate
//把填入的值轉回字串放入資料庫
$new_prod_a = $_POST["new_prod_a"];
foreach($new_prod_a as $key => $value){
$new_prod_a_v .= $value.",";
}
$new_prod_a_v = substr($new_prod_a_v,0,-1);
$new_prod->ds->new_prod_a->setValue($new_prod_a_v);