?? taskmanage.ascx.cs
字號:
?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;
public partial class controls_TaskManage : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
//如果頁面是回發頁面
if(!Page.IsPostBack)
{
//根據傳遞過來的參數,判斷顯示的View
if (Request.QueryString["viewindex"] == "0")
{
//顯示登記頁面
MultiView1.ActiveViewIndex = 0;
}
else
{
//顯示查詢頁面
MultiView1.ActiveViewIndex = 1;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
//登記計劃任務
//初始化任務實體,并賦值
TaskEntity task = new TaskEntity();
task.Name = txtname.Text;
task.UserName = txtusername.Text;
task.BeginDate = Calendar1.SelectedDate;
task.EndDate = Calendar2.SelectedDate;
//初始化任務實體類,并調用添加方法
TaskDA myda = new TaskDA();
bool result=myda.InsertTask(task);
if (result)
Label1.Text = "登記成功";
}
protected void Button2_Click(object sender, EventArgs e)
{
//通過員工姓名進行查詢
//構造函數中第一個參數表示SQL語句中的參數名
//第二個參數表示控件的ID,第三個參數表示控件的取值屬性
ControlParameter cp = new ControlParameter("name", "txtname1", "Text");
//獲取Select語句,并添加條件
//因為Select語句中使用了多表查詢,所以字段前要注明表名
string str = SqlDataSource1.SelectCommand;
str += " where EmployeeInfo.employeename =@name";
//更新Select語句
SqlDataSource1.SelectCommand = str;
//添加參數-必須先清空參數
SqlDataSource1.SelectParameters.Clear();
SqlDataSource1.SelectParameters.Add(cp);
//重新綁定數據
GridView1.DataBind();
}
protected void Button3_Click(object sender, EventArgs e)
{
//通過日期區間進行查詢
//因為日期區間有兩個日期,所以設置兩個參數
ControlParameter cp = new ControlParameter("begindate", "txtbegindate1", "Text");
ControlParameter cp1 = new ControlParameter("enddate", "txtenddate1", "Text");
//獲取Select語句,并添加條件
//任務的日期在表中是以區間形式存取,此處查詢條件要注意
string str = SqlDataSource1.SelectCommand;
str += " where task.taskbegindate> @begindate and task.taskenddate< @enddate";
//更新Select語句
SqlDataSource1.SelectCommand = str;
//添加參數-必須先清空參數
SqlDataSource1.SelectParameters.Clear();
SqlDataSource1.SelectParameters.Add(cp);
SqlDataSource1.SelectParameters.Add(cp1);
//重新綁定數據
GridView1.DataBind();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -