| |
 |
Featured Demos - Aspose.iCalendar |
 |
Aspose.Network is a fully featured, and easy-to-use component
to read outlook msg files and convert from msg to eml, mht and pdf file formats.
You can create and edit tasks in the Tasks list. Each task has a name and a recurrence pattern.
Aspose.iCalendar calculates occurrence dates for your tasks and shows them in the Occurrences list.
You can also edit individual occurrences and this will add occurrence exceptions to the pattern.
Tasks
|
New Task
|
New Custom Task
|
| Task Name | Schedule | Starts | Ends | | | |
| Pay invoice | Last weekday every month | 2004/01/30 00:00:00 | Ends after 6 occurrences |
Edit
|
Edit Custom
| Delete |
| Go to gym | Mon, Wed, Fri every week | 2004/03/01 00:00:00 | 2004/03/31 00:00:00 |
Edit
|
Edit Custom
| Delete |
Total 19 occurrences generated for the above tasks.
| Occurrence Date | Day of Week | Task Name | | |
| 2004/01/30 00:00:00 | Friday | Pay invoice | Edit | Delete |
| 2004/02/27 00:00:00 | Friday | Pay invoice | Edit | Delete |
| 2004/03/01 00:00:00 | Monday | Go to gym | Edit | Delete |
| 2004/03/03 00:00:00 | Wednesday | Go to gym | Edit | Delete |
| 2004/03/05 00:00:00 | Friday | Go to gym | Edit | Delete |
| 2004/03/08 00:00:00 | Monday | Go to gym | Edit | Delete |
| 2004/03/10 00:00:00 | Wednesday | Go to gym | Edit | Delete |
| 2004/03/12 00:00:00 | Friday | Go to gym | Edit | Delete |
| 2004/03/15 00:00:00 | Monday | Go to gym | Edit | Delete |
| 2004/03/17 00:00:00 | Wednesday | Go to gym | Edit | Delete |
| 2004/03/19 00:00:00 | Friday | Go to gym | Edit | Delete |
| 2004/03/22 00:00:00 | Monday | Go to gym | Edit | Delete |
| 1 2 |
| ASP.NET |
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
|
<%@ page language="C#" masterpagefile="~/tpl/Demo.Master" autoeventwireup="true" inherits="NWOnline.icalendardemo, NWOnline" title="iCalendar Demo - Aspose.Network Demos" enableviewstatemac="False" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<p class="componentDescriptionTxt">
<b>Aspose.Network</b> is a fully featured, and easy-to-use component
to read outlook msg files and convert from msg to eml, mht and pdf file formats.
You can create and edit tasks in the Tasks list. Each task has a name and a recurrence pattern.
Aspose.iCalendar calculates occurrence dates for your tasks and shows them in the Occurrences list.
You can also edit individual occurrences and this will add occurrence exceptions to the pattern.
</p>
<p>
<br />
<asp:Label ID="licenseLabel" runat="server" Font-Bold="True" Font-Names="Verdana"
Font-Size="X-Small" Height="1px" Width="100%"></asp:Label></p>
<p>
<br />
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small"
Height="1px" Width="64px">Tasks</asp:Label>
|
<asp:LinkButton ID="newTaskBtn" runat="server" Font-Names="Verdana" Font-Size="X-Small"
OnClick="newTaskBtn_Click">New Task</asp:LinkButton>
|
<asp:LinkButton ID="newCustomTaskBtn" runat="server" Font-Names="Verdana" Font-Size="X-Small"
OnClick="newCustomTaskBtn_Click">New Custom Task</asp:LinkButton>
|
</p>
<p>
<asp:DataGrid ID="taskGrid" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" Font-Names="Verdana"
Font-Size="X-Small" GridLines="Vertical" Height="72px" Width="800px">
<SelectedItemStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<AlternatingItemStyle BackColor="Gainsboro" />
<ItemStyle BackColor="#EEEEEE" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<Columns>
<asp:BoundColumn DataField="TaskId" ReadOnly="True" Visible="False"></asp:BoundColumn>
<asp:BoundColumn DataField="IsCustom" ReadOnly="True" Visible="False"></asp:BoundColumn>
<asp:BoundColumn DataField="TaskName" HeaderText="Task Name">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
<FooterStyle Wrap="False" />
</asp:BoundColumn>
<asp:BoundColumn DataField="Schedule" HeaderText="Schedule" ReadOnly="True">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
<FooterStyle Wrap="False" />
</asp:BoundColumn>
<asp:BoundColumn DataField="Starts" HeaderText="Starts" ReadOnly="True">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
<FooterStyle Wrap="False" />
</asp:BoundColumn>
<asp:BoundColumn DataField="Ends" HeaderText="Ends" ReadOnly="True">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
<FooterStyle Wrap="False" />
</asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="Edit" Text="Edit"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Update" Text=""></asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="false" CommandName="Cancel" Text=""></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="editCustomBtn" runat="server" CausesValidation="false" CommandName="Edit"
Text="Edit Custom">Edit Custom</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="Update" Text=""></asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="false" CommandName="Cancel"
Text=""></asp:LinkButton>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn CommandName="Delete" Text="Delete">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
<FooterStyle Wrap="False" />
</asp:ButtonColumn>
</Columns>
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" Mode="NumericPages" />
</asp:DataGrid></p>
<p>
<br />
<asp:Label ID="occurrencesLabel" runat="server" Font-Bold="True" Font-Names="Verdana"
Font-Size="X-Small" Height="9px" Width="536px">Occurrences</asp:Label></p>
<p>
<asp:Label ID="validationLabel" runat="server" BackColor="Red" BorderColor="Transparent"
BorderStyle="None" BorderWidth="1px" EnableViewState="False" Font-Bold="True"
Font-Names="Verdana" Font-Size="X-Small" ForeColor="White" Height="24px" Visible="False"
Width="544px">Label</asp:Label></p>
<p>
<asp:DataGrid ID="occurrenceGrid" runat="server" AllowPaging="True" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="3" Font-Names="Verdana" Font-Size="XX-Small" Height="120px" PageSize="12"
Width="624px">
<SelectedItemStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<ItemStyle ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="White" ForeColor="#000066" />
<Columns>
<asp:BoundColumn DataField="TaskId" HeaderText="TaskId" ReadOnly="True" Visible="False">
<HeaderStyle Width="0%" />
</asp:BoundColumn>
<asp:BoundColumn DataField="OccurrenceDateTime" HeaderText="OldOccurrenceDate" ReadOnly="True"
Visible="False"></asp:BoundColumn>
<asp:BoundColumn DataField="OccurrenceDateTime" HeaderText="Occurrence Date">
<HeaderStyle Width="25%" />
</asp:BoundColumn>
<asp:BoundColumn DataField="DayOfWeek" HeaderText="Day of Week" ReadOnly="True">
<HeaderStyle Width="15%" />
</asp:BoundColumn>
<asp:BoundColumn DataField="TaskName" HeaderText="Task Name" ReadOnly="True">
<HeaderStyle Width="30%" />
</asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" CancelText="Cancel" EditText="Edit"
UpdateText="Update">
<HeaderStyle Width="15%" />
</asp:EditCommandColumn>
<asp:ButtonColumn CommandName="Delete" Text="Delete">
<HeaderStyle Width="15%" />
</asp:ButtonColumn>
</Columns>
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" Mode="NumericPages" />
</asp:DataGrid></p>
</asp:Content>
|
| C# |
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
|
using System;
using System.Data;
using System.Web.UI.WebControls;
namespace NWOnline
{
public partial class icalendardemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (this.Session["model"] == null)
{
//Create new model and cache it in the session state.
this.model = new TasksModel();
this.model.CreateSampleTasks();
this.Session["model"] = this.model;
}
else
{
//Restore model from the cache
this.model = this.Session["model"] as TasksModel;
}
if (!this.IsPostBack)
{
BindGrids();
}
}
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.taskGrid.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.taskGrid_EditCommand);
this.taskGrid.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.taskGrid_DeleteCommand);
this.occurrenceGrid.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.occurrenceGrid_PageIndexChanged);
this.occurrenceGrid.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.occurrenceGrid_CancelCommand);
this.occurrenceGrid.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.occurrenceGrid_EditCommand);
this.occurrenceGrid.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.occurrenceGrid_UpdateCommand);
this.occurrenceGrid.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.occurrenceGrid_DeleteCommand);
}
/// <summary>
/// Called when a user clicked to delete a task.
/// </summary>
private void taskGrid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string taskId = e.Item.Cells[0].Text;
this.model.DeleteTask(taskId);
BindGrids();
}
private void taskGrid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string taskId = e.Item.Cells[0].Text;
bool isCustom = bool.Parse(e.Item.Cells[1].Text);
bool isForceCustom = (((LinkButton)e.CommandSource).Text == "Edit Custom");
if (isCustom || isForceCustom)
Server.Transfer(string.Format("EditCustomTaskForm.aspx?taskId={0}", taskId));
else
Server.Transfer(string.Format("EditTaskForm.aspx?taskId={0}", taskId));
}
protected void newTaskBtn_Click(object sender, EventArgs e)
{
Server.Transfer("EditTaskForm.aspx");
}
protected void newCustomTaskBtn_Click(object sender, EventArgs e)
{
Server.Transfer("EditCustomTaskForm.aspx");
}
/// <summary>
/// Called when the user clicks Edit occurrence command.
/// Switches occurrences grid into the editing mode.
/// </summary>
private void occurrenceGrid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.occurrenceGrid.EditItemIndex = e.Item.ItemIndex;
BindOccurrenceGrid();
}
/// <summary>
/// Saves changes made by the user in the occurrences grid into the model.
/// </summary>
private void occurrenceGrid_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string taskId = e.Item.Cells[0].Text;
DateTime oldOccurrence = DateTime.Parse(e.Item.Cells[1].Text);
TextBox dateEdit = (TextBox)e.Item.Cells[2].Controls[0];
DateTime newOccurrence;
if (!DemoUtil.TryParse(dateEdit.Text, out newOccurrence))
{
validationLabel.Text = "Please enter a valid date time.";
validationLabel.Visible = true;
return;
}
this.model.EditOccurrence(taskId, oldOccurrence, newOccurrence);
this.occurrenceGrid.EditItemIndex = -1;
BindOccurrenceGrid();
}
/// <summary>
/// Cancels occurrences grid editing mode.
/// </summary>
private void occurrenceGrid_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.occurrenceGrid.EditItemIndex = -1;
BindOccurrenceGrid();
}
/// <summary>
/// Called when a user clicked to delete (skip) an occurrence.
/// </summary>
private void occurrenceGrid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string taskId = e.Item.Cells[0].Text;
DateTime occurrence = DateTime.Parse(e.Item.Cells[1].Text);
this.model.DeleteOccurrence(taskId, occurrence);
this.occurrenceGrid.EditItemIndex = -1;
BindOccurrenceGrid();
}
private void occurrenceGrid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.occurrenceGrid.CurrentPageIndex = e.NewPageIndex;
BindOccurrenceGrid();
}
private void BindGrids()
{
BindTaskGrid();
BindOccurrenceGrid();
}
private void BindTaskGrid()
{
this.taskGrid.DataSource = this.model.GetTaskDataTable();
this.taskGrid.DataBind();
//Need to reset occurrences grid page index, otherwise web forms trip over.
this.occurrenceGrid.CurrentPageIndex = 0;
}
private void BindOccurrenceGrid()
{
DataView dataView = new DataView();
dataView.Table = this.model.GetOccurrenceDataTable();
dataView.Sort = "OccurrenceDateTime";
this.occurrenceGrid.DataSource = dataView;
this.occurrenceGrid.DataBind();
this.occurrencesLabel.Text = string.Format("Total {0} occurrences generated for the above tasks.", dataView.Count);
}
private TasksModel model;
}
}
|
| C# |
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
|
//////////////////////////////////////////////////////////////////////////
// Copyright 2002-2005 Aspose Pty Ltd. All Rights Reserved.
//
// This file is part of Aspose.iCalendar. The source code in this file
// is only intended as a supplement to the documentation, and is provided
// "as is", without warranty of any kind, either expressed or implied.
//////////////////////////////////////////////////////////////////////////
using System;
using Aspose.iCalendar;
namespace NWOnline
{
/// <summary>
/// Add/Edit Custom Task Form
/// </summary>
public partial class EditCustomTaskForm : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
this.model = this.Session["model"] as TasksModel;
validationLabel.Visible = false;
if (!this.IsPostBack)
{
//This is executed first time the page is loaded.
ViewState["referrer"] = Request.UrlReferrer;
//Save id of the task we are editing in the view state. It will be null for new task.
ViewState["taskId"] = Request.QueryString["taskId"];
Task task = GetTask();
if (task == null)
{
//Creating a new task.
formLabel.Text = "New Custom Task";
taskNameEdit.Text = "New Task";
iCalendarText.Text = "DTSTART:20040101\r\nRRULE:FREQ=DAILY;COUNT=10";
}
else
{
//Editing existing task.
formLabel.Text = "Edit Custom Task";
taskNameEdit.Text = task.Name;
iCalendarText.Text = task.Pattern.ToiCalendar();
}
this.examplesText.Text =
"Daily for 10 occurrences:\r\n" +
"DTSTART:20040902\r\n" +
"RRULE:FREQ=DAILY;COUNT=10\r\n" +
"\r\n" +
"Weekly on Tuesday and Thursday for 5 weeks:\r\n" +
"DTSTART;TZID=US-Eastern:20040902T090000\r\n" +
"RRULE:FREQ=WEEKLY;UNTIL=20041007T000000Z;WKST=SU;BYDAY=TU,TH\r\n" +
"\r\n" +
"Monthly on the 1st Friday for ten occurrences:\r\n" +
"DTSTART:20040903T090000\r\n" +
"RRULE:FREQ=MONTHLY;COUNT=10;BYDAY=1FR\r\n" +
"\r\n" +
"Monthly on the first and last day of the month for 10 occurrences:\r\n" +
"DTSTART:20040930T090000\r\n" +
"RRULE:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1\r\n";
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
/// <summary>
/// Looks up taskId value in the ViewState and returns a task object from the model for it.
/// Returns null if taskId is missing (creating new task).
/// </summary>
private Task GetTask()
{
if (ViewState["taskId"] == null)
return null;
return this.model.GetTask((string)ViewState["taskId"]);
}
protected void okBtn_Click(object sender, System.EventArgs e)
{
try
{
Task task = GetTask();
bool isNewTask = (task == null);
if (isNewTask)
task = new Task();
task.Name = this.taskNameEdit.Text;
task.Pattern = new RecurrencePattern(this.iCalendarText.Text);
//Test drive the pattern to make sure it is valid.
task.Pattern.GenerateOccurrences(DateTime.Now, DateTime.Now);
if (isNewTask)
model.AddTask(task);
Response.Redirect(ViewState["referrer"].ToString());
}
catch (Exception ex)
{
validationLabel.Text = ex.Message;
validationLabel.Visible = true;
}
}
protected void cancelBtn_Click(object sender, System.EventArgs e)
{
Response.Redirect(ViewState["referrer"].ToString());
}
private TasksModel model;
}
}
|
| C# |
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
|
//////////////////////////////////////////////////////////////////////////
// Copyright 2002-2005 Aspose Pty Ltd. All Rights Reserved.
//
// This file is part of Aspose.iCalendar. The source code in this file
// is only intended as a supplement to the documentation, and is provided
// "as is", without warranty of any kind, either expressed or implied.
//////////////////////////////////////////////////////////////////////////
using System;
using Aspose.iCalendar;
namespace NWOnline
{
/// <summary>
/// Add/Edit Task Form.
/// </summary>
public partial class EditTaskForm : System.Web.UI.Page
{
/// <summary>
/// Called when the page is loaded. When the page is loaded first time fills the controls with either
/// defaults for new task or with information from the existing task.
/// </summary>
protected void Page_Load(object sender, System.EventArgs e)
{
this.model = this.Session["model"] as TasksModel;
validationLabel.Visible = false;
if (!this.IsPostBack)
{
//This is executed first time the page is loaded.
ViewState["referrer"] = Request.UrlReferrer;
//Fill combo boxes with standard choices.
WebUtil.SetDataSource(monthlyDayCombo, EditTaskController.CreateDayList());
WebUtil.SetDataSource(monthlyDayOfWeekCombo, EditTaskController.CreateDayOfWeekList());
WebUtil.SetDataSource(monthlyNthOccurrenceCombo, EditTaskController.CreateNthOccurrenceList());
WebUtil.SetDataSource(monthlyDayOccurrenceCombo, EditTaskController.CreateWeekDayOccurrenceList());
WebUtil.SetDataSource(monthlyWeekDayTypeCombo, EditTaskController.CreateWeekDayTypeList());
WebUtil.SetDataSource(yearlyDayCombo, EditTaskController.CreateDayList());
WebUtil.SetDataSource(yearlyDayOfWeekCombo, EditTaskController.CreateDayOfWeekList());
WebUtil.SetDataSource(yearlyDayMonthCombo, EditTaskController.CreateMonthList());
WebUtil.SetDataSource(yearlyDayOfWeekMonthCombo, EditTaskController.CreateMonthList());
WebUtil.SetDataSource(yearlyNthOccurrenceCombo, EditTaskController.CreateNthOccurrenceList());
WebUtil.SetDataSource(yearlyDayOccurrenceCombo, EditTaskController.CreateWeekDayOccurrenceList());
WebUtil.SetDataSource(yearlyWeekDayTypeCombo, EditTaskController.CreateWeekDayTypeList());
WebUtil.SetDataSource(yearlyWeekDayMonthCombo, EditTaskController.CreateMonthList());
//Save id of the task we are editing in the view state. It will be null for new task.
ViewState["taskId"] = Request.QueryString["taskId"];
EditTaskController controller = new EditTaskController();
if (GetTask() == null)
{
//Creating a new task.
formLabel.Text = "New Task";
SetTaskData(controller.NewTask());
}
else
{
//Editing existing task.
formLabel.Text = "Edit Task";
SetTaskData(controller.LoadTask(GetTask()));
}
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
/// <summary>
/// Loads task data into controls on the form from the data row.
/// </summary>
private void SetTaskData(EditTaskFormData.TaskRow taskData)
{
this.taskNameEdit.Text = taskData.Name;
this.startDate.Text = taskData.StartDate;
this.startTime.Text = taskData.StartTime;
WebUtil.SelectItem(this.endRadio, taskData.EndChoice.ToString());
this.endMaxOccurrencesEdit.Text = taskData.Count;
this.endDate.Text = taskData.EndDate;
WebUtil.SelectItem(this.recurrenceRadio, taskData.RecurrenceChoice.ToString());
WebUtil.SelectItem(this.dailyRadio, taskData.DailyChoice.ToString());
this.dailyEveryNthDayEdit.Text = taskData.DailyEveryNthDay;
this.weeklyEveryNthWeekEdit.Text = taskData.WeeklyEveryNthWeek;
this.weekDaysBtns.Items[0].Selected = taskData.Sunday;
this.weekDaysBtns.Items[1].Selected = taskData.Monday;
this.weekDaysBtns.Items[2].Selected = taskData.Tuesday;
this.weekDaysBtns.Items[3].Selected = taskData.Wednesday;
this.weekDaysBtns.Items[4].Selected = taskData.Thursday;
this.weekDaysBtns.Items[5].Selected = taskData.Friday;
this.weekDaysBtns.Items[6].Selected = taskData.Saturday;
WebUtil.SelectItem(this.monthlyRadio, taskData.MonthlyChoice.ToString());
this.monthlyEveryNthMonthEdit.Text = taskData.MonthlyEveryNthMonth;
WebUtil.SelectItem(this.monthlyDayCombo, taskData.MonthlyDay.ToString());
WebUtil.SelectItem(this.monthlyNthOccurrenceCombo, taskData.MonthlyNthOccurrence.ToString());
WebUtil.SelectItem(this.monthlyDayOfWeekCombo, taskData.MonthlyDayOfWeek.ToString());
WebUtil.SelectItem(this.monthlyDayOccurrenceCombo, taskData.MonthlyDayOccurrence.ToString());
WebUtil.SelectItem(this.monthlyWeekDayTypeCombo, taskData.MonthlyWeekDayType.ToString());
WebUtil.SelectItem(this.yearlyRadio, taskData.YearlyChoice.ToString());
this.yearlyEveryNthYearEdit.Text = taskData.YearlyEveryNthYear;
WebUtil.SelectItem(this.yearlyDayMonthCombo, taskData.YearlyDayMonth.ToString());
WebUtil.SelectItem(this.yearlyDayCombo, taskData.YearlyDay.ToString());
WebUtil.SelectItem(this.yearlyNthOccurrenceCombo, taskData.YearlyNthOccurrence.ToString());
WebUtil.SelectItem(this.yearlyDayOfWeekCombo, taskData.YearlyDayOfWeek.ToString());
WebUtil.SelectItem(this.yearlyDayOfWeekMonthCombo, taskData.YearlyDayOfWeekMonth.ToString());
WebUtil.SelectItem(this.yearlyDayOccurrenceCombo, taskData.YearlyDayOccurrence.ToString());
WebUtil.SelectItem(this.yearlyWeekDayTypeCombo, taskData.YearlyWeekDayType.ToString());
WebUtil.SelectItem(this.yearlyWeekDayMonthCombo, taskData.YearlyWeekDayMonth.ToString());
UpdateiCalendar();
UpdateControls();
}
/// <summary>
/// Saves data from form controls into the data row.
/// </summary>
private EditTaskFormData.TaskRow GetTaskData()
{
EditTaskFormData dataSet = new EditTaskFormData();
EditTaskFormData.TaskRow taskData = dataSet.Task.NewTaskRow();
taskData.Name = this.taskNameEdit.Text;
taskData.StartDate = this.startDate.Text;
taskData.StartTime = this.startTime.Text;
taskData.EndChoice = int.Parse(this.endRadio.SelectedItem.Value);
taskData.Count = this.endMaxOccurrencesEdit.Text;
taskData.EndDate = this.endDate.Text;
taskData.RecurrenceChoice = int.Parse(this.recurrenceRadio.SelectedItem.Value);
taskData.DailyChoice = int.Parse(this.dailyRadio.SelectedItem.Value);
taskData.DailyEveryNthDay = this.dailyEveryNthDayEdit.Text;
taskData.WeeklyEveryNthWeek = this.weeklyEveryNthWeekEdit.Text;
taskData.Sunday = this.weekDaysBtns.Items[0].Selected;
taskData.Monday = this.weekDaysBtns.Items[1].Selected;
taskData.Tuesday = this.weekDaysBtns.Items[2].Selected;
taskData.Wednesday = this.weekDaysBtns.Items[3].Selected;
taskData.Thursday = this.weekDaysBtns.Items[4].Selected;
taskData.Friday = this.weekDaysBtns.Items[5].Selected;
taskData.Saturday = this.weekDaysBtns.Items[6].Selected;
taskData.MonthlyChoice = int.Parse(this.monthlyRadio.SelectedItem.Value);
taskData.MonthlyEveryNthMonth = this.monthlyEveryNthMonthEdit.Text;
taskData.MonthlyDay = int.Parse(this.monthlyDayCombo.SelectedItem.Value);
taskData.MonthlyNthOccurrence = int.Parse(this.monthlyNthOccurrenceCombo.SelectedItem.Value);
taskData.MonthlyDayOfWeek = int.Parse(this.monthlyDayOfWeekCombo.SelectedItem.Value);
taskData.MonthlyDayOccurrence = int.Parse(this.monthlyDayOccurrenceCombo.SelectedItem.Value);
taskData.MonthlyWeekDayType = int.Parse(this.monthlyWeekDayTypeCombo.SelectedItem.Value);
taskData.YearlyChoice = int.Parse(this.yearlyRadio.SelectedItem.Value);
taskData.YearlyEveryNthYear = this.yearlyEveryNthYearEdit.Text;
taskData.YearlyDayMonth = int.Parse(this.yearlyDayMonthCombo.SelectedItem.Value);
taskData.YearlyDay = int.Parse(this.yearlyDayCombo.SelectedItem.Value);
taskData.YearlyNthOccurrence = int.Parse(this.yearlyNthOccurrenceCombo.SelectedItem.Value);
taskData.YearlyDayOfWeek = int.Parse(this.yearlyDayOfWeekCombo.SelectedItem.Value);
taskData.YearlyDayOfWeekMonth = int.Parse(this.yearlyDayOfWeekMonthCombo.SelectedItem.Value);
taskData.YearlyDayOccurrence = int.Parse(this.yearlyDayOccurrenceCombo.SelectedItem.Value);
taskData.YearlyWeekDayType = int.Parse(this.yearlyWeekDayTypeCombo.SelectedItem.Value);
taskData.YearlyWeekDayMonth = int.Parse(this.yearlyWeekDayMonthCombo.SelectedItem.Value);
return taskData;
}
/// <summary>
/// Called when the user clicks okay. Performs validation and saves the data either into a new
/// task or into task we are editing.
/// </summary>
protected void okBtn_Click(object sender, System.EventArgs e)
{
try
{
Task task = GetTask();
bool isNewTask = (task == null);
if (isNewTask)
task = new Task();
EditTaskController controller = new EditTaskController();
controller.Save(GetTaskData(), task);
if (isNewTask)
this.model.AddTask(task);
Response.Redirect(ViewState["referrer"].ToString());
}
catch (ValidateException ex)
{
validationLabel.Text = ex.Message;
validationLabel.Visible = true;
}
}
protected void cancelBtn_Click(object sender, System.EventArgs e)
{
Response.Redirect(ViewState["referrer"].ToString());
}
/// <summary>
/// Looks up taskId value in the ViewState and returns a task object from the model for it.
/// Returns null if taskId is missing (creating new task).
/// </summary>
private Task GetTask()
{
if (ViewState["taskId"] == null)
return null;
return this.model.GetTask((string)ViewState["taskId"]);
}
protected void recurrenceRadio_SelectedIndexChanged(object sender, System.EventArgs e)
{
UpdateControls();
}
/// <summary>
/// Enables/diables controls according to the radio selections.
/// </summary>
private void UpdateControls()
{
RecurrenceChoice recurrenceChoice = (RecurrenceChoice)int.Parse(recurrenceRadio.SelectedItem.Value);
dailyPanel.Visible = (recurrenceChoice == RecurrenceChoice.Daily);
weeklyPanel.Visible = (recurrenceChoice == RecurrenceChoice.Weekly);
monthlyPanel.Visible = (recurrenceChoice == RecurrenceChoice.Monthly);
yearlyPanel.Visible = (recurrenceChoice == RecurrenceChoice.Yearly);
DailyChoice dailyChoice = (DailyChoice)int.Parse(this.dailyRadio.SelectedItem.Value);
dailyEveryNthDayEdit.Enabled = (dailyChoice == DailyChoice.EveryNthDay);
MonthlyChoice monthlyChoice = (MonthlyChoice)int.Parse(this.monthlyRadio.SelectedItem.Value);
monthlyDayCombo.Enabled = (monthlyChoice == MonthlyChoice.Day);
monthlyNthOccurrenceCombo.Enabled = monthlyDayOfWeekCombo.Enabled = (monthlyChoice == MonthlyChoice.DayOfWeek);
monthlyDayOccurrenceCombo.Enabled = monthlyWeekDayTypeCombo.Enabled = (monthlyChoice == MonthlyChoice.WeekDay);
YearlyChoice yearlyChoice = (YearlyChoice)int.Parse(this.yearlyRadio.SelectedItem.Value);
yearlyDayCombo.Enabled = yearlyDayMonthCombo.Enabled = (yearlyChoice == YearlyChoice.Day);
yearlyNthOccurrenceCombo.Enabled = yearlyDayOfWeekCombo.Enabled = yearlyDayOfWeekMonthCombo.Enabled = (yearlyChoice == YearlyChoice.DayOfWeek);
yearlyDayOccurrenceCombo.Enabled = yearlyWeekDayTypeCombo.Enabled = yearlyWeekDayMonthCombo.Enabled = (yearlyChoice == YearlyChoice.WeekDay);
EndType endType = (EndType)int.Parse(this.endRadio.SelectedItem.Value);
endMaxOccurrencesEdit.Enabled = (endType == EndType.Count);
endDate.Enabled = (endType == EndType.Until);
}
protected void refreshBtn_Click(object sender, System.EventArgs e)
{
UpdateiCalendar();
}
private void UpdateiCalendar()
{
try
{
Task dummyTask = new Task();
EditTaskController controller = new EditTaskController();
controller.Save(GetTaskData(), dummyTask);
iCalendarText.Text = dummyTask.Pattern.ToiCalendar();
}
catch (Exception ex)
{
this.iCalendarText.Text = ex.Message;
}
}
private TasksModel model;
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Label Label15;
protected System.Web.UI.HtmlControls.HtmlForm Form2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Panel Panel2;
protected System.Web.UI.WebControls.Label Label17;
}
}
|
|
|
|