-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPlanner.mxml
123 lines (104 loc) · 3.91 KB
/
Planner.mxml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?xml version="1.0" encoding="utf-8"?>
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%" title="Планировщик" creationComplete="titlewindow1_creationCompleteHandler(event)"
close="closeBtn_clickHandler(event)">
<s:layout>
<s:VerticalLayout horizontalAlign="center" padding="10"/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.events.CloseEvent;
import mx.events.FlexEvent;
import mx.events.ItemClickEvent;
import mx.events.ResizeEvent;
import mx.managers.PopUpManager;
import mx.utils.UIDUtil;
import spark.components.Alert;
import spark.components.WindowedApplication;
private var selectStmt:SQLStatement;
protected function closeBtn_clickHandler(event:CloseEvent):void
{
PopUpManager.removePopUp(this);
}
protected function titlewindow1_creationCompleteHandler(event:FlexEvent):void
{
this.width = this.parent.width;
this.height = this.parent.height;
this.closeButton.visible = true;
list.addEventListener(ItemClickEvent.ITEM_CLICK, lst_itemClickHandler);
}
protected function lst_itemClickHandler(evt:ItemClickEvent):void {
if (evt.label == 'change') {
saveBtn.label = "Сохранить";
saveBtn.setStyle("icon", "images/dark-red-circle.png");
return;
}
if (evt.label == 'delete') {
deleteRow (evt.item);
}
}
private function deleteRow(item:Object):void
{
selectStmt = new SQLStatement();
selectStmt.sqlConnection = Copypaste.loadData.conn;
selectStmt.text = "DELETE FROM planner WHERE `uid` = '" + item.uid + "'";
selectStmt.execute();
Copypaste.planner.removeItem(item);
}
protected function addBtn_clickHandler(event:MouseEvent):void
{
var obj:PlanData = new PlanData();
obj.uid = UIDUtil.createUID();
obj.hour = 15;
obj.min = 30;
Copypaste.planner.addItem(obj);
saveBtn.label = "Сохранить";
saveBtn.setStyle("icon", "images/dark-red-circle.png");
}
protected function saveBtn_clickHandler(event:MouseEvent):void
{
selectStmt = new SQLStatement();
selectStmt.sqlConnection = Copypaste.loadData.conn;
var sql:String = "DELETE FROM planner";
selectStmt.text = sql;
selectStmt.addEventListener(SQLEvent.RESULT, selectRes);
selectStmt.addEventListener(SQLErrorEvent.ERROR, selectError);
selectStmt.execute();
}
protected function selectRes(event:SQLEvent):void
{
selectStmt.removeEventListener(SQLEvent.RESULT, selectRes);
selectStmt.removeEventListener(SQLErrorEvent.ERROR, selectError);
for (var i:int = Copypaste.planner.length-1; i >= 0; i--)
{
var item:PlanData = Copypaste.planner.getItemAt(i) as PlanData;
selectStmt = new SQLStatement();
selectStmt.sqlConnection = Copypaste.loadData.conn;
var sql:String = "";
sql += "INSERT INTO planner (uid, hour, min) VALUES ('" + item.uid + "', '";
sql += item.hour+ "', '";
sql += item.min + "')";
trace (sql);
selectStmt.text = sql;
selectStmt.execute();
}
saveBtn.label = "Сохранить";
saveBtn.setStyle("icon", "images/dark-green-circle.png");
}
protected function selectError(event:SQLErrorEvent):void
{
trace ('5 error ' + event.text);
}
]]>
</fx:Script>
<s:List id="list" width="100%" height="100%" dataProvider="{Copypaste.planner}" itemRenderer="timeIR">
<s:layout>
<s:TileLayout orientation="columns" verticalAlign="top" padding="5"/>
</s:layout>
</s:List>
<s:HGroup horizontalAlign="center">
<s:Button id="addNew" label="Добавить ресурс" click="addBtn_clickHandler(event)" icon="images/add.png"/>
<s:Button id="saveBtn" label="Сохранить" click="saveBtn_clickHandler(event)" icon="images/dark-green-circle.png"/>
</s:HGroup>
</s:TitleWindow>