Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
Prado::using('Example.Person');
4
 
5
class crud2 extends TPage
6
{
7
	private function sqlmap()
8
	{
9
		return $this->Application->Modules['person-sample']->Client;
10
	}
11
 
12
	private function loadData()
13
	{
14
		$this->personList->DataSource =  $this->sqlmap()->queryForList('SelectAll');
15
		$this->personList->dataBind();
16
	}
17
 
18
	public function onLoad($param)
19
	{
20
		if(!$this->IsPostBack)
21
			$this->loadData();
22
	}
23
 
24
	protected function editPerson($sender,$param)
25
	{
26
		$this->personList->EditItemIndex=$param->Item->ItemIndex;
27
		$this->loadData();
28
	}
29
 
30
	protected function deletePerson($sender, $param)
31
	{
32
		$id = $this->getKey($sender, $param);
33
 
34
		$this->sqlmap()->update("Delete", $id);
35
		$this->loadData();
36
	}
37
 
38
	protected function updatePerson($sender, $param)
39
	{
40
		$person = new Person();
41
		$person->FirstName = $this->getText($param, 0);
42
		$person->LastName = $this->getText($param, 1);
43
		$person->HeightInMeters = $this->getText($param, 2);
44
		$person->WeightInKilograms = $this->getText($param, 3);
45
		$person->ID = $this->getKey($sender, $param);
46
 
47
		$this->sqlmap()->update("Update", $person);
48
		$this->refreshList($sender, $param);
49
	}
50
 
51
	protected function addNewPerson($sender, $param)
52
	{
53
		$person = new Person;
54
		$person->FirstName = "-- New Person --";
55
		$this->sqlmap()->insert("Insert", $person);
56
 
57
		$this->loadData();;
58
	}
59
 
60
	protected function refreshList($sender, $param)
61
	{
62
		$this->personList->EditItemIndex=-1;
63
		$this->loadData();
64
	}
65
 
66
	private function getText($param, $index)
67
	{
68
		$item = $param->Item;
69
		return $item->Cells[$index]->Controls[0]->Text;
70
	}
71
 
72
	private function getKey($sender, $param)
73
	{
74
		return $sender->DataKeys[$param->Item->DataSourceIndex];
75
	}
76
}
77
 
78
?>