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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Aspose.Tasks
Imports System.IO
Namespace Aspose.Tasks.Demos._9
Partial Public Class CreateCalendar
Inherits System.Web.UI.Page
Private pgTable As Table
'bool isTbl;
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
pgTable = getTable(Me)
If (Not IsPostBack) Then
Try
popLists(Me.DayType1)
popLists(Me.DayType2)
popLists(Me.DayType3)
popLists(Me.DayType4)
popLists(Me.DayType5)
popLists(Me.DayType6)
popLists(Me.DayType7)
' * ***/
'getTable1(this);
Catch
Session("tmp")="Error"
End Try
End If
If IsPostBack Then
Select Case GetPostBackControl(Me)
Case "DayType1"
setDefaults(Me.DayType1)
Case "DayType2"
setDefaults(Me.DayType2)
Case "DayType3"
setDefaults(Me.DayType3)
Case "DayType4"
setDefaults(Me.DayType4)
Case "DayType5"
setDefaults(Me.DayType5)
Case "DayType6"
setDefaults(Me.DayType6)
Case "DayType7"
setDefaults(Me.DayType7)
End Select
End If
End Sub
Public Shared Function GetPostBackControl(ByVal page As Page) As String
Dim control As Control = Nothing
Dim ctrlname As String = page.Request.Params.Get("__EVENTTARGET")
If ctrlname IsNot Nothing AndAlso ctrlname <> String.Empty Then
control = page.FindControl(ctrlname)
Else
For Each ctl As String In page.Request.Form
Dim c As Control = page.FindControl(ctl)
If TypeOf c Is System.Web.UI.WebControls.Button Then
control = c
Exit For
End If
Next ctl
End If
Return control.ID
End Function
Private Sub popLists(ByVal lst As DropDownList)
Dim idx As Integer = Integer.Parse(lst.ID.Substring(lst.ID.Length - 1))
Dim strHrPatt() As String = { "DayHour" & idx.ToString() & "1f", "DayHour" & idx.ToString() & "2f", "DayHour" & idx.ToString() & "1t", "DayHour" & idx.ToString() & "2t" }
Dim strMinPatt() As String = { "DayMin" & idx.ToString() & "1f", "DayMin" & idx.ToString() & "2f", "DayMin" & idx.ToString() & "1t", "DayMin" & idx.ToString() & "2t" }
Dim tRow As TableRow = pgTable.Rows(idx)
For i As Integer = 2 To 3
For Each ctl As Control In tRow.Cells(i).Controls
If TypeOf ctl Is DropDownList Then
Dim ddl As DropDownList = CType(ctl, DropDownList)
ddl.Items.Clear()
For j As Integer = 0 To 3
If ddl.ID = strHrPatt(j) Then
For k As Integer = 0 To 23
ddl.Items.Add(k.ToString().PadLeft(2, "0"c))
Next k
Else
If ddl.ID = strMinPatt(j) Then
For l As Integer = 0 To 55 Step 5
ddl.Items.Add(l.ToString().PadLeft(2, "0"c))
Next l
End If
End If
Next j
ddl.Text = "09"
End If
Next ctl
Next i
setDefaults(lst)
End Sub
Private Sub setDefaults(ByVal lst As DropDownList)
Dim myTbl As Table = pgTable
Dim idx As Integer = Integer.Parse(lst.ID.Substring(lst.ID.Length - 1))
Dim strHrPatt() As String = { "DayHour" & idx.ToString() & "1f", "DayHour" & idx.ToString() & "2f", "DayHour" & idx.ToString() & "1t", "DayHour" & idx.ToString() & "2t" }
Dim tRow As TableRow = myTbl.Rows(idx)
For i As Integer = 2 To 3
For Each ctl As Control In tRow.Cells(i).Controls
If TypeOf ctl Is DropDownList Then
Dim ddl As DropDownList = CType(ctl, DropDownList)
If lst.Text = "Holiday" Then
ddl.Text = "00"
Else
For j As Integer = 0 To 3
If ddl.ID = strHrPatt(j) Then
Select Case ddl.ID.Substring(ddl.ID.Length - 2)
Case "1f"
ddl.Text = "09"
Case "2f"
ddl.Text = "14"
Case "1t"
ddl.Text = "13"
Case "2t"
ddl.Text = "18"
End Select
End If
Next j
End If
End If
Next ctl
Next i
End Sub
Private Function getTable(ByVal obj As Page) As Table
For Each webCtl As Control In obj.Form.Controls
For Each ctl As Control In webCtl.Controls
If TypeOf ctl Is Table Then
Return CType(ctl, Table)
End If
Next ctl
Next webCtl
Dim tmp As New Table()
Return tmp
End Function
Private Function getTable1(ByVal obj As Page) As Table
For Each webCtl As Control In obj.Form.Controls
For Each ctl As Control In webCtl.Controls
For Each ctl1 As Control In ctl.Controls
For Each ctl2 As Control In ctl1.Controls
For Each ctl3 As Control In ctl2.Controls
For Each ctl4 As Control In ctl3.Controls
For Each ctl5 As Control In ctl4.Controls
For Each ctl6 As Control In ctl5.Controls
For Each ctl7 As Control In ctl6.Controls
If TypeOf ctl7 Is Table Then
Return CType(ctl7, Table)
End If
Next ctl7
Next ctl6
Next ctl5
Next ctl4
Next ctl3
Next ctl2
Next ctl1
Next ctl
Next webCtl
Dim tmp As New Table()
Return tmp
End Function
Private Sub chkVals(ByVal txtHr1f As DropDownList, ByVal txtMin1f As DropDownList, ByVal txtHr2f As DropDownList, ByVal txtMin2f As DropDownList, ByVal txtHr1t As DropDownList, ByVal txtMin1t As DropDownList, ByVal txtHr2t As DropDownList, ByVal txtMin2t As DropDownList)
Dim dtFrom1 As DateTime = DateTime.Parse(txtHr1f.Text & ":" & txtMin1f.Text)
Dim dtFrom2 As DateTime = DateTime.Parse(txtHr2f.Text & ":" & txtMin2f.Text)
Dim dtTo1 As DateTime = DateTime.Parse(txtHr1t.Text & ":" & txtMin1t.Text)
Dim dtTo2 As DateTime = DateTime.Parse(txtHr2t.Text & ":" & txtMin2t.Text)
If dtFrom1 >= dtTo1 OrElse dtFrom2 >= dtTo2 OrElse dtTo1 >= dtFrom2 OrElse dtFrom2 >= dtTo2 Then
Select Case txtHr1f.ID.Substring(txtHr1f.ID.Length-3)
Case "11f"
setDefaults(Me.DayType1)
Case "21f"
setDefaults(Me.DayType2)
Case "31f"
setDefaults(Me.DayType3)
Case "41f"
setDefaults(Me.DayType4)
Case "51f"
setDefaults(Me.DayType5)
Case "61f"
setDefaults(Me.DayType6)
Case "71f"
setDefaults(Me.DayType7)
End Select
End If
End Sub
Private Sub ValidateData()
chkVals(Me.DayHour11f, Me.DayMin11f, Me.DayHour12f, Me.DayMin12f, Me.DayHour11t, Me.DayMin11t, Me.DayHour12t, Me.DayMin12t)
chkVals(Me.DayHour21f, Me.DayMin21f, Me.DayHour22f, Me.DayMin22f, Me.DayHour21t, Me.DayMin21t, Me.DayHour22t, Me.DayMin22t)
chkVals(Me.DayHour31f, Me.DayMin31f, Me.DayHour32f, Me.DayMin32f, Me.DayHour31t, Me.DayMin31t, Me.DayHour32t, Me.DayMin22t)
chkVals(Me.DayHour41f, Me.DayMin41f, Me.DayHour42f, Me.DayMin42f, Me.DayHour41t, Me.DayMin41t, Me.DayHour42t, Me.DayMin22t)
chkVals(Me.DayHour51f, Me.DayMin51f, Me.DayHour52f, Me.DayMin52f, Me.DayHour51t, Me.DayMin51t, Me.DayHour52t, Me.DayMin22t)
chkVals(Me.DayHour61f, Me.DayMin61f, Me.DayHour62f, Me.DayMin62f, Me.DayHour61t, Me.DayMin61t, Me.DayHour62t, Me.DayMin22t)
chkVals(Me.DayHour71f, Me.DayMin71f, Me.DayHour72f, Me.DayMin72f, Me.DayHour71t, Me.DayMin71t, Me.DayHour72t, Me.DayMin22t)
End Sub
Private Sub createWeekDays(ByVal lst As DropDownList, ByVal cal As Calendar)
Dim idx As Integer = Integer.Parse(lst.ID.Substring(lst.ID.Length - 1))
Dim ddls(7) As DropDownList
Dim cnt As Integer = 0
Dim tRow As TableRow = pgTable.Rows(idx)
For i As Integer = 2 To 3
For Each ctl As Control In tRow.Cells(i).Controls
If TypeOf ctl Is DropDownList Then
Dim ddl As DropDownList = CType(ctl, DropDownList)
ddls(cnt) = ddl
cnt = cnt + 1
End If
Next ctl
Next i
Dim myWeekDay As New WeekDay()
Select Case idx
Case 1
myWeekDay = New WeekDay(DayType.Monday)
Case 2
myWeekDay = New WeekDay(DayType.Tuesday)
Case 3
myWeekDay = New WeekDay(DayType.Wednesday)
Case 4
myWeekDay = New WeekDay(DayType.Thursday)
Case 5
myWeekDay = New WeekDay(DayType.Friday)
Case 6
myWeekDay = New WeekDay(DayType.Saturday)
Case 7
myWeekDay = New WeekDay(DayType.Sunday)
End Select
Dim wt1 As New WorkingTime()
Dim wt2 As New WorkingTime()
If lst.Text = "Working" Then
wt1.FromTime = New DateTime(1, 1, 1, Integer.Parse(ddls(0).Text), Integer.Parse(ddls(1).Text), 0, 0)
wt1.ToTime = New DateTime(1, 1, 1, Integer.Parse(ddls(2).Text), Integer.Parse(ddls(3).Text), 0, 0)
wt2.FromTime = New DateTime(1, 1, 1, Integer.Parse(ddls(4).Text), Integer.Parse(ddls(5).Text), 0, 0)
wt2.ToTime = New DateTime(1, 1, 1, Integer.Parse(ddls(6).Text), Integer.Parse(ddls(7).Text), 0, 0)
myWeekDay.WorkingTimes.Add(wt1)
myWeekDay.WorkingTimes.Add(wt2)
myWeekDay.DayWorking = True
cal.Days.Add(myWeekDay)
Else
cal.Days.Add(myWeekDay)
End If
End Sub
Protected Sub btn_Cal_Click(ByVal sender As Object, ByVal e As EventArgs)
ValidateData()
Dim prj As New Project()
Dim cal As New Aspose.Tasks.Calendar()
cal.Uid = 1
cal.Name = "Calendar1"
prj.Calendars.Add(cal)
createWeekDays(Me.DayType1, cal)
createWeekDays(Me.DayType2, cal)
createWeekDays(Me.DayType3, cal)
createWeekDays(Me.DayType4, cal)
createWeekDays(Me.DayType5, cal)
createWeekDays(Me.DayType6, cal)
createWeekDays(Me.DayType7, cal)
prj.CalcCalendarUids()
Dim prjWriter As New ProjectWriter()
Me.Response.ContentType = "application/vnd.ms-project"
Me.Response.AppendHeader("Content-Disposition", "attachment; filename=projCal.xml")
Me.Response.Flush()
Dim st As System.IO.Stream = Me.Response.OutputStream
prjWriter.Write(prj, st, TasksDataFormat.XML)
Me.Response.End()
End Sub
End Class
End Namespace
|