<?php 
class CActionConfigProject extends CActionBase
{
	function doAction()
	{
		$ret = 0;
		$job = $_POST["job"];
		switch($job)
		{
			case "add":
				$ret = $this->Add();
			break;
			case "mod":
				$ret = $this->Mod();
			break;
			case "del":
				$ret = $this->Del();
			break;
		}
		
		return $ret;
	}	
	
	function Add()
	{
		$project_name	 = $_POST["project_name"];
		$project_code	 = $_POST["project_code"];
		$project_desc	 = $_POST["project_desc"];
		$project_state = $_POST["project_state"];
		
		$nCount = $this->db->GetCount('tb_project', 'project_name', $project_name);
		if($nCount > 0) return 2; //用户名称相同
		
		$project_id = $this->db->GetMaxField('tb_project', 'project_id')+1;
		$sql = "insert into tb_project (project_id, project_name, project_code, project_status, project_desc, create_time) values (";
		$sql = $sql . $project_id . ",";
		$sql = $sql . "'".$project_name."',";
		$sql = $sql . "'".$project_code."',";
		$sql = $sql . $project_state.",";
		$sql = $sql . "'".$project_desc."',";
		$sql = $sql . "now())";
		
		$this->db->ExeSql($sql);
		return 0;
	}
	
	function Mod()
	{
		$project_id	 = $_POST["project_id"];
		$project_name	 = $_POST["project_name"];
		$project_code	 = $_POST["project_code"];
		$project_desc	 = $_POST["project_desc"];
		$project_state = $_POST["project_state"];
		
		//$nCount = $this->db->GetCount('tb_project', 'project_name', $project_name);
		//if($nCount > 0) return 2; //用户名称相同
		
		$sql = "update tb_project set ";
		$sql = $sql . "project_name ='".$project_name."',";
		$sql = $sql . "project_code ='".$project_code."',";
		$sql = $sql . "project_desc ='".$project_desc."',";
		$sql = $sql . "project_status =".$project_state;		
		$sql = $sql . " where project_id=".$project_id;
		$this->db->ExeSql($sql);
		return 0;
	}
	
	function Del()
	{
		$project_id = $_POST["project_id"];
		$sql = "delete from tb_project where project_id=".$project_id;
		$this->db->ExeSql($sql);
		return 0;
	}
	
};
?>
