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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
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;
using Aspose.Tasks;
using System.IO;
namespace Aspose.Tasks.Demos._9
{
public partial class CreateCalendar : System.Web.UI.Page
{
Table pgTable;
//bool isTbl;
protected void Page_Load(object sender, EventArgs e)
{
pgTable = getTable(this);
if (!IsPostBack)
{
try
{
popLists(this.DayType1);
popLists(this.DayType2);
popLists(this.DayType3);
popLists(this.DayType4);
popLists(this.DayType5);
popLists(this.DayType6);
popLists(this.DayType7);
// * ***/
//getTable1(this);
}
catch {
Session["tmp"]="Error";
}
}
if (IsPostBack)
{
switch (GetPostBackControl(this))
{
case "DayType1":
setDefaults(this.DayType1);
break;
case "DayType2":
setDefaults(this.DayType2);
break;
case "DayType3":
setDefaults(this.DayType3);
break;
case "DayType4":
setDefaults(this.DayType4);
break;
case "DayType5":
setDefaults(this.DayType5);
break;
case "DayType6":
setDefaults(this.DayType6);
break;
case "DayType7":
setDefaults(this.DayType7);
break;
}
}
}
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 idx = int.Parse(lst.ID.Substring(lst.ID.Length - 1));
string[] strHrPatt = { "DayHour" + idx.ToString() + "1f", "DayHour" + idx.ToString() + "2f", "DayHour" + idx.ToString() + "1t", "DayHour" + idx.ToString() + "2t" };
string[] strMinPatt = { "DayMin" + idx.ToString() + "1f", "DayMin" + idx.ToString() + "2f", "DayMin" + idx.ToString() + "1t", "DayMin" + idx.ToString() + "2t" };
TableRow tRow = pgTable.Rows[idx];
for (int i = 2; i <= 3; i++)
{
foreach (Control ctl in tRow.Cells[i].Controls)
if (ctl is DropDownList)
{
DropDownList ddl = (DropDownList)ctl;
ddl.Items.Clear();
for (int j = 0; j < 4; j++)
if (ddl.ID == strHrPatt[j])
for (int k = 0; k < 24; k++)
ddl.Items.Add(k.ToString().PadLeft(2, '0'));
else
if (ddl.ID == strMinPatt[j])
for (int l = 0; l <= 55; l = l + 5)
ddl.Items.Add(l.ToString().PadLeft(2, '0'));
ddl.Text = "09";
}
}
setDefaults(lst);
}
private void setDefaults( DropDownList lst)
{
Table myTbl = pgTable;
int idx = int.Parse(lst.ID.Substring(lst.ID.Length - 1));
string[] strHrPatt = { "DayHour" + idx.ToString() + "1f", "DayHour" + idx.ToString() + "2f", "DayHour" + idx.ToString() + "1t", "DayHour" + idx.ToString() + "2t" };
TableRow tRow = myTbl.Rows[idx];
for (int i = 2; i <= 3; i++)
{
foreach (Control ctl in tRow.Cells[i].Controls)
if (ctl is DropDownList)
{
DropDownList ddl = (DropDownList)ctl;
if (lst.Text == "Holiday")
ddl.Text = "00";
else
for (int j = 0; j < 4; j++)
if (ddl.ID == strHrPatt[j])
{
switch (ddl.ID.Substring(ddl.ID.Length - 2))
{
case "1f":
ddl.Text = "09";
break;
case "2f":
ddl.Text = "14";
break;
case "1t":
ddl.Text = "13";
break;
case "2t":
ddl.Text = "18";
break;
}
}
}
}
}
private Table getTable(Page obj)
{
foreach (Control webCtl in obj.Form.Controls)
foreach (Control ctl in webCtl.Controls)
if (ctl is Table)
return (Table)ctl;
Table tmp = new Table();
return tmp;
}
private Table getTable1(Page obj)
{
foreach (Control webCtl in obj.Form.Controls)
foreach (Control ctl in webCtl.Controls)
foreach (Control ctl1 in ctl.Controls)
foreach (Control ctl2 in ctl1.Controls)
foreach (Control ctl3 in ctl2.Controls)
foreach (Control ctl4 in ctl3.Controls)
foreach (Control ctl5 in ctl4.Controls)
foreach (Control ctl6 in ctl5.Controls)
foreach (Control ctl7 in ctl6.Controls)
if (ctl7 is Table)
return (Table)ctl7;
Table tmp = new Table();
return tmp;
}
private void chkVals(DropDownList txtHr1f, DropDownList txtMin1f, DropDownList txtHr2f, DropDownList txtMin2f, DropDownList txtHr1t, DropDownList txtMin1t, DropDownList txtHr2t, DropDownList txtMin2t)
{
DateTime dtFrom1 = DateTime.Parse(txtHr1f.Text + ":" + txtMin1f.Text);
DateTime dtFrom2 = DateTime.Parse(txtHr2f.Text + ":" + txtMin2f.Text);
DateTime dtTo1 = DateTime.Parse(txtHr1t.Text + ":" + txtMin1t.Text);
DateTime dtTo2 = DateTime.Parse(txtHr2t.Text + ":" + txtMin2t.Text);
if (dtFrom1 >= dtTo1 || dtFrom2 >= dtTo2 || dtTo1 >= dtFrom2 || dtFrom2 >= dtTo2)
switch(txtHr1f.ID.Substring(txtHr1f.ID.Length-3))
{
case "11f":
setDefaults(this.DayType1);
break;
case "21f":
setDefaults(this.DayType2);
break;
case "31f":
setDefaults(this.DayType3);
break;
case "41f":
setDefaults(this.DayType4);
break;
case "51f":
setDefaults(this.DayType5);
break;
case "61f":
setDefaults(this.DayType6);
break;
case "71f":
setDefaults(this.DayType7);
break;
}
}
private void ValidateData()
{
chkVals(this.DayHour11f, this.DayMin11f, this.DayHour12f, this.DayMin12f, this.DayHour11t, this.DayMin11t, this.DayHour12t, this.DayMin12t);
chkVals(this.DayHour21f, this.DayMin21f, this.DayHour22f, this.DayMin22f, this.DayHour21t, this.DayMin21t, this.DayHour22t, this.DayMin22t);
chkVals(this.DayHour31f, this.DayMin31f, this.DayHour32f, this.DayMin32f, this.DayHour31t, this.DayMin31t, this.DayHour32t, this.DayMin22t);
chkVals(this.DayHour41f, this.DayMin41f, this.DayHour42f, this.DayMin42f, this.DayHour41t, this.DayMin41t, this.DayHour42t, this.DayMin22t);
chkVals(this.DayHour51f, this.DayMin51f, this.DayHour52f, this.DayMin52f, this.DayHour51t, this.DayMin51t, this.DayHour52t, this.DayMin22t);
chkVals(this.DayHour61f, this.DayMin61f, this.DayHour62f, this.DayMin62f, this.DayHour61t, this.DayMin61t, this.DayHour62t, this.DayMin22t);
chkVals(this.DayHour71f, this.DayMin71f, this.DayHour72f, this.DayMin72f, this.DayHour71t, this.DayMin71t, this.DayHour72t, this.DayMin22t);
}
private void createWeekDays(DropDownList lst,Calendar cal)
{
int idx = int.Parse(lst.ID.Substring(lst.ID.Length - 1));
DropDownList[] ddls=new DropDownList[8];
int cnt = 0;
TableRow tRow = pgTable.Rows[idx];
for (int i = 2; i <= 3; i++)
{
foreach (Control ctl in tRow.Cells[i].Controls)
if (ctl is DropDownList)
{
DropDownList ddl = (DropDownList)ctl;
ddls[cnt] = ddl;
cnt = cnt + 1;
}
}
WeekDay myWeekDay=new WeekDay();
switch (idx)
{
case 1:
myWeekDay = new WeekDay(DayType.Monday);
break;
case 2:
myWeekDay = new WeekDay(DayType.Tuesday);
break;
case 3:
myWeekDay = new WeekDay(DayType.Wednesday);
break;
case 4:
myWeekDay = new WeekDay(DayType.Thursday);
break;
case 5:
myWeekDay = new WeekDay(DayType.Friday);
break;
case 6:
myWeekDay = new WeekDay(DayType.Saturday);
break;
case 7:
myWeekDay = new WeekDay(DayType.Sunday);
break;
}
WorkingTime wt1 = new WorkingTime();
WorkingTime wt2 = new WorkingTime();
if (lst.Text == "Working")
{
wt1.FromTime = new DateTime(1, 1, 1, int.Parse(ddls[0].Text), int.Parse(ddls[1].Text), 0, 0);
wt1.ToTime = new DateTime(1, 1, 1, int.Parse(ddls[2].Text), int.Parse(ddls[3].Text), 0, 0);
wt2.FromTime = new DateTime(1, 1, 1, int.Parse(ddls[4].Text), int.Parse(ddls[5].Text), 0, 0);
wt2.ToTime = new DateTime(1, 1, 1, int.Parse(ddls[6].Text), int.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);
}
}
protected void btn_Cal_Click(object sender, EventArgs e)
{
ValidateData();
Project prj = new Project();
Aspose.Tasks.Calendar cal = new Aspose.Tasks.Calendar();
cal.Uid = 1;
cal.Name = "Calendar1";
prj.Calendars.Add(cal);
createWeekDays(this.DayType1, cal);
createWeekDays(this.DayType2, cal);
createWeekDays(this.DayType3, cal);
createWeekDays(this.DayType4, cal);
createWeekDays(this.DayType5, cal);
createWeekDays(this.DayType6, cal);
createWeekDays(this.DayType7, cal);
prj.CalcCalendarUids();
ProjectWriter prjWriter = new ProjectWriter();
this.Response.ContentType = "application/vnd.ms-project";
this.Response.AppendHeader("Content-Disposition", "attachment; filename=projCal.xml");
this.Response.Flush();
System.IO.Stream st = this.Response.OutputStream;
prjWriter.Write(prj, st, TasksDataFormat.XML);
this.Response.End();
}
}
}
|