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
|
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
Namespace Aspose.Tasks.Demos._9
Partial Public Class CreateCalExceptions
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If (Not IsPostBack) Then
popLists(Me.Monf, 12)
popLists(Me.Mont, 12)
popLists(Me.lstDayf, 31)
popLists(Me.lstDayt, 31)
Me.lstDayt.Text = "10"
End If
If IsPostBack Then
If GetPostBackControl(Me) <> "btn_Cal" Then
Dim strPrev As String = Me.lstDayf.Text
Dim cntPrev As Integer = Integer.Parse(strPrev)
setDays(Me.lstDayf,Integer.Parse(Me.Monf.Text))
If cntPrev > Me.lstDayf.Items.Count Then
Me.lstDayf.Text = "1"
Else
Me.lstDayf.Text = strPrev
End If
strPrev = Me.lstDayt.Text
cntPrev = Integer.Parse(strPrev)
setDays(Me.lstDayt, Integer.Parse(Me.Mont.Text))
If cntPrev > Me.lstDayt.Items.Count Then
Me.lstDayt.Text = "1"
Else
Me.lstDayt.Text = strPrev
End If
End If
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, ByVal intMax As Integer)
For i As Integer = 1 To intMax
lst.Items.Add(i.ToString())
Next i
End Sub
Private Sub setDays(ByVal lst As DropDownList, ByVal intMon As Integer)
lst.Items.Clear()
If intMon = 1 OrElse intMon = 3 OrElse intMon = 5 OrElse intMon = 7 OrElse intMon = 8 OrElse intMon = 10 OrElse intMon = 12 Then
popLists(lst, 31)
End If
If intMon = 4 OrElse intMon = 6 OrElse intMon = 9 OrElse intMon = 11 Then
popLists(lst, 30)
End If
If intMon = 2 Then
popLists(lst, 29)
End If
End Sub
Private Sub ValidateData()
Dim dtF As New DateTime(2000,Integer.Parse(Me.Monf.Text),Integer.Parse(Me.lstDayf.Text))
Dim dtT As New DateTime(2000, Integer.Parse(Me.Mont.Text), Integer.Parse(Me.lstDayt.Text))
If dtF > dtT Then
Me.lstDayf.Text = "1"
Me.lstDayt.Text = "10"
Me.Monf.Text = "1"
Me.Mont.Text = "1"
End If
End Sub
Protected Sub btn_Cal_Click(ByVal sender As Object, ByVal e As EventArgs)
ValidateData()
'create a prject instance
Dim prj As New Project()
'Define Calendar
Dim cal As New Aspose.Tasks.Calendar()
cal.Uid = 1
cal.Name = "Calendar1"
'Define week days exception
Dim except As New CalendarException()
except.EnteredByOccurrences = False
except.FromDate = New DateTime(2000, Integer.Parse(Me.Monf.Text), Integer.Parse(Me.lstDayf.Text), 0, 0, 0)
except.ToDate = New DateTime(2009, Integer.Parse(Me.Mont.Text), Integer.Parse(Me.lstDayt.Text), 23, 59, 0)
Dim al As New ArrayList()
If Me.RBDaily.Checked Then
except.Type = CalendarExceptionType.Daily
Else
except.Type = CalendarExceptionType.Weekly
If Me.chkMon.Checked Then
al.Add(DayType.Monday)
End If
If Me.chkTue.Checked Then
al.Add(DayType.Tuesday)
End If
If Me.chkWed.Checked Then
al.Add(DayType.Wednesday)
End If
If Me.chkThu.Checked Then
al.Add(DayType.Thursday)
End If
If Me.chkFri.Checked Then
al.Add(DayType.Friday)
End If
except.DaysOfWeek = al
End If
except.DayWorking = False
cal.Exceptions.Add(except)
prj.Calendars.Add(cal)
prj.CalcCalendarUids()
'create a project writer instance
Dim prjWriter As New ProjectWriter()
Me.Response.ContentType = "application/vnd.ms-project"
Me.Response.AppendHeader("Content-Disposition", "attachment; filename=calExcept.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
|