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
|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace Aspose.Tasks.Demos._9
{
public partial class CreateCalExceptions : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
popLists(this.Monf, 12);
popLists(this.Mont, 12);
popLists(this.lstDayf, 31);
popLists(this.lstDayt, 31);
this.lstDayt.Text = "10";
}
if (IsPostBack)
{
if(GetPostBackControl(this) != "btn_Cal")
{
string strPrev = this.lstDayf.Text;
int cntPrev = int.Parse(strPrev);
setDays(this.lstDayf,int.Parse(this.Monf.Text));
if (cntPrev > this.lstDayf.Items.Count)
this.lstDayf.Text = "1";
else
this.lstDayf.Text = strPrev;
strPrev = this.lstDayt.Text;
cntPrev = int.Parse(strPrev);
setDays(this.lstDayt, int.Parse(this.Mont.Text));
if (cntPrev > this.lstDayt.Items.Count)
this.lstDayt.Text = "1";
else
this.lstDayt.Text = strPrev;
}
}
}
public static string GetPostBackControl(Page page)
{
Control control = null;
string ctrlname = page.Request.Params.Get("__EVENTTARGET");
if (ctrlname != null && ctrlname != string.Empty)
{
control = page.FindControl(ctrlname);
}
else
{
foreach (string ctl in page.Request.Form)
{
Control c = page.FindControl(ctl);
if (c is System.Web.UI.WebControls.Button)
{
control = c;
break;
}
}
}
return control.ID;
}
private void popLists(DropDownList lst ,int intMax)
{
for (int i = 1; i <= intMax; i++)
lst.Items.Add(i.ToString());
}
private void setDays(DropDownList lst,int intMon)
{
lst.Items.Clear();
if (intMon == 1 || intMon == 3 || intMon == 5 || intMon == 7 || intMon == 8 || intMon == 10 || intMon == 12)
popLists(lst, 31);
if (intMon == 4 || intMon == 6 || intMon == 9 || intMon == 11)
popLists(lst, 30);
if (intMon == 2)
popLists(lst, 29);
}
private void ValidateData()
{
DateTime dtF = new DateTime(2000,int.Parse(this.Monf.Text),int.Parse(this.lstDayf.Text));
DateTime dtT = new DateTime(2000, int.Parse(this.Mont.Text), int.Parse(this.lstDayt.Text));
if (dtF > dtT)
{
this.lstDayf.Text = "1";
this.lstDayt.Text = "10";
this.Monf.Text = "1";
this.Mont.Text = "1";
}
}
protected void btn_Cal_Click(object sender, EventArgs e)
{
ValidateData();
//create a prject instance
Project prj = new Project();
//Define Calendar
Aspose.Tasks.Calendar cal = new Aspose.Tasks.Calendar();
cal.Uid = 1;
cal.Name = "Calendar1";
//Define week days exception
CalendarException except = new CalendarException();
except.EnteredByOccurrences = false;
except.FromDate = new DateTime(2000, int.Parse(this.Monf.Text), int.Parse(this.lstDayf.Text), 0, 0, 0);
except.ToDate = new DateTime(2009, int.Parse(this.Mont.Text ), int.Parse(this.lstDayt.Text), 23, 59, 0);
ArrayList al = new ArrayList();
if (this.RBDaily.Checked)
except.Type = CalendarExceptionType.Daily;
else
{
except.Type = CalendarExceptionType.Weekly;
if (this.chkMon.Checked)
al.Add(DayType.Monday);
if (this.chkTue.Checked)
al.Add(DayType.Tuesday);
if (this.chkWed.Checked)
al.Add(DayType.Wednesday);
if (this.chkThu.Checked)
al.Add(DayType.Thursday);
if (this.chkFri.Checked)
al.Add(DayType.Friday);
except.DaysOfWeek = al;
}
except.DayWorking = false;
cal.Exceptions.Add(except);
prj.Calendars.Add(cal);
prj.CalcCalendarUids();
//create a project writer instance
ProjectWriter prjWriter = new ProjectWriter();
this.Response.ContentType = "application/vnd.ms-project";
this.Response.AppendHeader("Content-Disposition", "attachment; filename=calExcept.xml");
this.Response.Flush();
System.IO.Stream st = this.Response.OutputStream;
prjWriter.Write(prj, st, TasksDataFormat.XML);
this.Response.End();
}
}
}
|