checkbox 的做法

CodeCharge Studio 2.x, 3.x, 4.x, 5.x
回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

checkbox 的做法

文章 yehlu »

yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

employees_record_BeforeShow

文章 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();

}
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

employees_record_AfterInsert

文章 yehlu »

ProjectEmployeesModify("Insert");
最後由 yehlu 於 2007-03-15 23:41:20 編輯,總共編輯了 1 次。
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

employees_record_AfterUpdate

文章 yehlu »

ProjectEmployeesModify("Update");
最後由 yehlu 於 2007-03-15 23:41:05 編輯,總共編輯了 1 次。
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

employees_record_BeforeDelete

文章 yehlu »

ProjectEmployeesModify("Delete");
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

function ProjectEmployeesModify

文章 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();
}
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

我的做法

文章 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);
回覆文章

回到「CodeCharge Studio」