📄 default.aspx.cs
字号:
{
DataGrid1.CurrentPageIndex = DataGrid1.PageCount - 1;
DataGrid1.DataBind();
}
else
{
DataGrid1.CurrentPageIndex = PreviousPageIndex;
DataGrid1.DataBind();
}
}
/// <summary>
/// This event gets fired when a user selects a new task list. We load in the new task list.
/// </summary>
private void cboTaskLists_SelectedIndexChanged(object sender, System.EventArgs e)
{
// Load the task list that corresponds to this task list name
if (cboTaskLists.SelectedItem.Value != String.Empty)
{
Session["TaskListID"] = Convert.ToInt32(cboTaskLists.SelectedItem.Value);
ShowTaskList(Convert.ToInt32(cboTaskLists.SelectedItem.Value));
}
}
/// <summary>
/// Destroys our authentication session, removes the Session variables and
/// redirects the user to the login page.
/// </summary>
private void lnkLogOff_Click(object sender, System.EventArgs e)
{
Session.Abandon();
Response.Cookies.Clear();
System.Web.Security.FormsAuthentication.SignOut();
Response.Redirect("login.aspx");
}
/// <summary>
/// Redirects the user to the "Create a new Task" page
/// </summary>
private void lnkAdd_Click(object sender, System.EventArgs e)
{
Response.Redirect("Task.aspx");
}
/// <summary>
/// This event gets fired when a user clicks the "View" button on the task list display
/// </summary>
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// The "View/Edit" link
DataGrid1.EditItemIndex = e.Item.ItemIndex;
ShowTaskList(Convert.ToInt32(cboTaskLists.SelectedItem.Value));
}
/// <summary>
/// This event gets fired when the user clicks the "Hide" button when viewing a task
/// </summary>
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();
ShowTaskList(Convert.ToInt32(cboTaskLists.SelectedItem.Value));
}
/// <summary>
/// Rebinds the grid and redisplays the tasks. If two users are working on the same exact task list
/// from different PCs, they can click the "Refresh" link to see the changes/updates the other user has made.
/// </summary>
private void lnkRefresh_Click(object sender, System.EventArgs e)
{
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();
ShowTaskList(Convert.ToInt32(cboTaskLists.SelectedItem.Value));
}
/// <summary>
/// This is a generic event handler that gets fired when any of the Grid's constituent controls fire an event.
/// We can keep track of what is firing by the CommandName property. For instance, the "Save" link has a
/// CommandName of "SaveTask".
/// </summary>
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
TextBox txtSubject, txtBody;
DropDownList cboStatus;
DropDownList cboCategory;
DropDownList cboMoveTo;
int TaskListID = 0;
int TaskID = 0;
if (e.CommandName == "SaveTask")
{
TaskID = Convert.ToInt32(e.Item.Cells[1].Text);
TaskListID = Convert.ToInt32(cboTaskLists.SelectedItem.Value);
txtSubject = (TextBox)e.Item.FindControl("txtTaskSubject");
txtBody = (TextBox)e.Item.FindControl("txtTaskBody");
cboStatus = (DropDownList)e.Item.FindControl("cboTaskStatus");
cboCategory = (DropDownList)e.Item.FindControl("cboTaskCategory");
cboMoveTo = (DropDownList)e.Item.FindControl("cboMoveTo");
TaskListItem ti = tl.GetTaskListItem(CurrentUser, TaskID, Convert.ToInt32(cboTaskLists.SelectedItem.Value));
ti.TaskListID = Convert.ToInt32(cboMoveTo.SelectedItem.Value);
ti.Body = Server.HtmlEncode(txtBody.Text);
ti.StatusValue = Convert.ToInt32(cboStatus.SelectedItem.Value);
ti.CategoryID = Convert.ToInt32(cboCategory.SelectedItem.Value);
ti.StatusName = cboStatus.SelectedItem.Text;
ti.Subject = Server.HtmlEncode(txtSubject.Text);
ti.ModifiedDate = DateTime.Now;
tl.Modify(CurrentUser, ti, TaskListID);
DataGrid1.EditItemIndex = -1;
this.ShowTaskList(TaskListID);
}
else if (e.CommandName == "CancelTask")
{
TaskListID = Convert.ToInt32(cboTaskLists.SelectedItem.Value);
DataGrid1.EditItemIndex = -1;
this.ShowTaskList(TaskListID);
}
else if (e.CommandName == "DeleteTask")
{
TaskID = Convert.ToInt32(e.Item.Cells[1].Text);
TaskListID = Convert.ToInt32(cboTaskLists.SelectedItem.Value);
tl.Delete(CurrentUser, TaskListID, TaskID);
DataGrid1.EditItemIndex = -1;
this.ShowTaskList(TaskListID);
}
}
/// <summary>
/// This event gets fired when the grid is building. Also, when the user clicks the "View" button,
/// it gets fired again as all the new data loads. This is where we can populate the Status List dropdown list,
/// as well as the TaskSummary usercontrol object (called SummaryHeader here)
/// </summary>
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DropDownList StatusList = (DropDownList)e.Item.FindControl("cboTaskStatus");
DropDownList CategoryList = (DropDownList)e.Item.FindControl("cboTaskCategory");
DropDownList MoveToList = (DropDownList)e.Item.FindControl("cboMoveTo");
TaskSummary SummaryHeader = (TaskSummary)e.Item.FindControl("TaskSummary");
DataRowView dr = (DataRowView)e.Item.DataItem;
if (StatusList != null)
{
this.LoadStatusList(StatusList);
if (StatusList.Items.FindByText(dr["Status"].ToString()) != null)
StatusList.Items.FindByText(dr["Status"].ToString()).Selected = true;
}
if (CategoryList != null)
{
this.LoadCategoryList(CategoryList);
if (CategoryList.Items.FindByValue(dr["CategoryID"].ToString()) != null)
CategoryList.Items.FindByValue(dr["CategoryID"].ToString()).Selected = true;
}
if (MoveToList != null)
{
this.LoadTaskListDropDown(MoveToList);
if (MoveToList.Items.FindByValue(dr["TaskListID"].ToString()) != null)
MoveToList.Items.FindByValue(dr["TaskListID"].ToString()).Selected = true;
}
if (SummaryHeader != null)
{
SummaryHeader.Subject = dr["Subject"].ToString();
SummaryHeader.Status = dr["Status"].ToString();
SummaryHeader.CreatedOn = (DateTime)dr["CreatedDate"];
SummaryHeader.LastModified = (DateTime)dr["LastModifiedDate"];
SummaryHeader.LastModifiedBy = dr["LastModifiedBy"].ToString();
SummaryHeader.CategoryIconUrl = dr["IconUrl"].ToString();
}
}
/// <summary>
/// This event gets fired whenever a user changes a page. We just have to set the CurrentPageIndex to
/// whatever argument was passed in, then rebind the grid.
/// </summary>
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
this.ShowTaskList(Convert.ToInt32(cboTaskLists.SelectedItem.Value));
}
private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void lnkManageTaskLists_Click(object sender, System.EventArgs e)
{
Response.Redirect("ManageTaskList.aspx");
}
private void lnkManageUsers_Click(object sender, System.EventArgs e)
{
Response.Redirect("ManageUsers.aspx");
}
private void lnkMyPreferences_Click(object sender, System.EventArgs e)
{
Response.Redirect("Preferences.aspx");
}
private void lnkManageApplication_Click(object sender, System.EventArgs e)
{
Response.Redirect("ManageApplication.aspx");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -