第 1 頁 (共 1 頁)
checkbox 的做法
發表於 : 2007-03-15 23:29:16
由 yehlu
employees_record_BeforeShow
發表於 : 2007-03-15 23:38:44
由 yehlu
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();
}
employees_record_AfterInsert
發表於 : 2007-03-15 23:39:39
由 yehlu
ProjectEmployeesModify("Insert");
employees_record_AfterUpdate
發表於 : 2007-03-15 23:40:18
由 yehlu
ProjectEmployeesModify("Update");
employees_record_BeforeDelete
發表於 : 2007-03-15 23:40:52
由 yehlu
ProjectEmployeesModify("Delete");
function ProjectEmployeesModify
發表於 : 2007-03-15 23:50:46
由 yehlu
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();
}
我的做法
發表於 : 2007-03-16 10:09:11
由 yehlu
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);