📄 schmanage.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Data.SqlClient;
namespace OfficeOnline
{
/// <summary>
/// SchManage 的摘要说明。
/// </summary>
public class SchManage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.ImageButton ImageButton1;
protected System.Web.UI.WebControls.DropDownList dropDay;
protected System.Web.UI.WebControls.DropDownList dropMonth;
protected System.Web.UI.WebControls.RangeValidator RangeValidator_Year;
protected System.Web.UI.WebControls.ImageButton cmdQuery;
protected System.Web.UI.WebControls.DataGrid dgdsch;
protected System.Web.UI.WebControls.TextBox tbxEmpID;
protected System.Web.UI.WebControls.Label lblerr;
protected System.Web.UI.WebControls.TextBox tbxYear;
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
lblerr.Text="";
}
}
public void BindGrid()
{
//创建数据库连接和命令对象
SqlConnection objconn = new SqlConnection(ConfigurationSettings.AppSettings["connstr"]);
SqlCommand objcmd = new SqlCommand("SchManage",objconn);
//设定命令类型
objcmd.CommandType= CommandType.StoredProcedure ;
//添加参数
//日程类型
SqlParameter paramSchTypeID = new SqlParameter("@SchTypeID", SqlDbType.Int);
paramSchTypeID.Direction=ParameterDirection.Output;
objcmd.Parameters.Add(paramSchTypeID);
//打开数据库连接
objconn.Open();
SqlDataReader result = objcmd.ExecuteReader(CommandBehavior.CloseConnection);
dgdsch.DataSource=result;
dgdsch.DataBind();
}
public void DataGrid_Page(Object sender,DataGridPageChangedEventArgs E)
{
dgdsch.CurrentPageIndex =E.NewPageIndex ;
BindGrid();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
this.cmdQuery.Click += new System.Web.UI.ImageClickEventHandler(this.cmdQuery_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void cmdQuery_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(tbxYear.Text!="")
{
lblerr.Text="";
int year =Int32.Parse(tbxYear.Text);
int month=dropMonth.SelectedIndex+1;
int day=Int32.Parse(dropDay.SelectedItem.Text );
DateTime dateVar= new DateTime(year,month,day);
//创建数据库连接对象
SqlConnection objconn = new SqlConnection(ConfigurationSettings.AppSettings["connstr"]);
if(tbxEmpID.Text!="")
{
SqlCommand objcmd = new SqlCommand("SelSch",objconn);
//设定命令类型
objcmd.CommandType= CommandType.StoredProcedure ;
//添加参数
//员工编号
SqlParameter paramEmpID = new SqlParameter("@EmpID",SqlDbType.Int);
paramEmpID.Value=Convert.ToInt32(tbxEmpID.Text.ToString());
objcmd.Parameters.Add(paramEmpID);
//日程类型
SqlParameter paramSchTypeID = new SqlParameter("@SchTypeID", SqlDbType.Int);
paramSchTypeID.Direction=ParameterDirection.Output;
objcmd.Parameters.Add(paramSchTypeID);
//执行时间
SqlParameter paramDate=new SqlParameter("@Date",SqlDbType.DateTime);
paramDate.Value=dateVar.ToShortDateString();
objcmd.Parameters.Add(paramDate);
//打开数据库连接
objconn.Open();
SqlDataReader result = objcmd.ExecuteReader(CommandBehavior.CloseConnection);
dgdsch.DataSource=result;
dgdsch.DataBind();
}
else
{
SqlCommand objcmd = new SqlCommand("SchByDate",objconn);
//设定命令类型
objcmd.CommandType= CommandType.StoredProcedure ;
//添加参数
//日程类型
SqlParameter paramSchTypeID = new SqlParameter("@SchTypeID", SqlDbType.Int);
paramSchTypeID.Direction=ParameterDirection.Output;
objcmd.Parameters.Add(paramSchTypeID);
//执行时间
SqlParameter paramDate=new SqlParameter("@Date",SqlDbType.DateTime);
paramDate.Value=dateVar.ToShortDateString();
objcmd.Parameters.Add(paramDate);
//打开数据库连接
objconn.Open();
SqlDataReader result1 = objcmd.ExecuteReader(CommandBehavior.CloseConnection);
dgdsch.DataSource=result1;
dgdsch.DataBind();
}
}
else
{lblerr.Text="请输入查询年";}
}
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect("Default.aspx");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -