📄 adminfour.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.Data.OleDb;
namespace KaoQin
{
/// <summary>
/// adminFour 的摘要说明。
/// </summary>
public class adminFour : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddId;
protected System.Web.UI.WebControls.Label Label1;
protected System.Data.DataSet ds;
protected System.Web.UI.WebControls.DataGrid data;
protected System.Web.UI.WebControls.Button btnQuery;
protected System.Web.UI.WebControls.Label info;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.DropDownList ddYear;
protected System.Web.UI.WebControls.DropDownList ddMon;
protected System.Web.UI.WebControls.Label labCd;
protected System.Web.UI.WebControls.Label labZt;
protected System.Web.UI.WebControls.Label labBj;
protected System.Web.UI.WebControls.Label labSj;
protected System.Web.UI.WebControls.Label labKg;
protected System.Data.OleDb.OleDbDataReader reader;
protected System.Data.OleDb.OleDbConnection con;
protected System.Data.OleDb.OleDbCommand com;
protected System.Data.OleDb.OleDbDataAdapter da;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(System.Convert.ToString(Session["admin"]).Equals(""))
{
Response.Redirect("admin.aspx");
}
else
{
string strcon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("message.mdb")+";User Id=admin;Password=;";
con=new OleDbConnection(strcon);
ds=new DataSet();
string sql1="select id from usermessage";
if(!IsPostBack)
{
con.Open();
com=new OleDbCommand(sql1,con);
reader=com.ExecuteReader();
while(reader.Read())
{
ddId.Items.Add(reader.GetString(0));
}
reader.Close();
com.Dispose();
con.Close();
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnQuery.Click += new System.EventHandler(this.btnQuery_Click);
this.data.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.data_PageIndexChanged);
this.data.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.data_DeleteCommand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnQuery_Click(object sender, System.EventArgs e)
{
string strId,strYear,strMon,strSql;
strId=ddId.SelectedItem.Text.Trim().ToString();
strYear=ddYear.SelectedItem.Text.Trim().ToString();
strMon=ddMon.SelectedItem.Text.Trim().ToString();
if(strId.Equals(""))
{
info.Text="请选择员工编号!";
}
else
{
if(strYear.Equals(""))
{
info.Text="请选择查询年份!";
}
else
{
if(strMon.Equals(""))
{
info.Text="请选择查询月份!";
}
else
{
string strCd,strZt,strSj,strBj,strKg;
int cdCount=0,ztCount=0,sjCount=0,bjCount=0,kgCount=0;
strCd="select id from kaoqin where id='"+strId+"' and cd='迟到' and year='"+strYear+"' and mon='"+strMon+"'";
strZt="select id from kaoqin where id='"+strId+"' and zt='早退' and year='"+strYear+"' and mon='"+strMon+"'";
strSj="select id from kaoqin where id='"+strId+"' and sj='事假' and year='"+strYear+"' and mon='"+strMon+"'";
strBj="select id from kaoqin where id='"+strId+"' and bj='病假' and year='"+strYear+"' and mon='"+strMon+"'";
strKg="select id from kaoqin where id='"+strId+"' and kg='旷工' and year='"+strYear+"' and mon='"+strMon+"'";
con.Open();
com=new OleDbCommand(strCd,con);
reader=com.ExecuteReader();
while(reader.Read())
{
cdCount++;
}
labCd.Text="迟到:"+cdCount.ToString()+"次";
reader.Close();
com.Dispose();
con.Close();
con.Open();
com=new OleDbCommand(strZt,con);
reader=com.ExecuteReader();
while(reader.Read())
{
ztCount++;
}
labZt.Text="早退:"+ztCount.ToString()+"次";
reader.Close();
com.Dispose();
con.Close();
con.Open();
com=new OleDbCommand(strSj,con);
reader=com.ExecuteReader();
while(reader.Read())
{
sjCount++;
}
labSj.Text="事假:"+sjCount.ToString()+"次";
reader.Close();
com.Dispose();
con.Close();
con.Open();
com=new OleDbCommand(strBj,con);
reader=com.ExecuteReader();
while(reader.Read())
{
bjCount++;
}
labBj.Text="病假:"+bjCount.ToString()+"次";
reader.Close();
com.Dispose();
con.Close();
con.Open();
com=new OleDbCommand(strKg,con);
reader=com.ExecuteReader();
while(reader.Read())
{
kgCount++;
}
labKg.Text="旷工:"+kgCount.ToString()+"次";
reader.Close();
com.Dispose();
con.Close();
strSql="select * from kaoqin where id='"+strId+"' and year='"+strYear+"' and mon='"+strMon+"'";
con.Open();
da=new OleDbDataAdapter(strSql,con);
da.Fill(ds,"kaoqin");
data.DataSource=ds.Tables["kaoqin"].DefaultView;
data.DataBind();
con.Close();
}
}
}
}
private void data_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
data.CurrentPageIndex=e.NewPageIndex;
data.DataSource=ds.Tables["kaoqin"].DefaultView;
data.DataBind();
}
private void data_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string strId,strYear,strMon,strSql;
strId=ddId.SelectedItem.Text.Trim().ToString();
strYear=ddYear.SelectedItem.Text.Trim().ToString();
strMon=ddMon.SelectedItem.Text.Trim().ToString();
string kqdate=(string)data.DataKeys[(int)e.Item.ItemIndex];
string strDelSql="delete from kaoqin where id='"+strId+"' and kqdate='"+kqdate+"'";
con.Open();
com=new System.Data.OleDb.OleDbCommand(strDelSql,con);
com.ExecuteNonQuery();
com.Dispose();
con.Close();
string strCd,strZt,strSj,strBj,strKg;
int cdCount=0,ztCount=0,sjCount=0,bjCount=0,kgCount=0;
strCd="select id from kaoqin where id='"+strId+"' and cd='迟到' and year='"+strYear+"' and mon='"+strMon+"'";
strZt="select id from kaoqin where id='"+strId+"' and zt='早退' and year='"+strYear+"' and mon='"+strMon+"'";
strSj="select id from kaoqin where id='"+strId+"' and sj='事假' and year='"+strYear+"' and mon='"+strMon+"'";
strBj="select id from kaoqin where id='"+strId+"' and bj='病假' and year='"+strYear+"' and mon='"+strMon+"'";
strKg="select id from kaoqin where id='"+strId+"' and kg='旷工' and year='"+strYear+"' and mon='"+strMon+"'";
con.Open();
com=new OleDbCommand(strCd,con);
reader=com.ExecuteReader();
while(reader.Read())
{
cdCount++;
}
labCd.Text="迟到:"+cdCount.ToString()+"次";
reader.Close();
com.Dispose();
con.Close();
con.Open();
com=new OleDbCommand(strZt,con);
reader=com.ExecuteReader();
while(reader.Read())
{
ztCount++;
}
labZt.Text="早退:"+ztCount.ToString()+"次";
reader.Close();
com.Dispose();
con.Close();
con.Open();
com=new OleDbCommand(strSj,con);
reader=com.ExecuteReader();
while(reader.Read())
{
sjCount++;
}
labSj.Text="事假:"+sjCount.ToString()+"次";
reader.Close();
com.Dispose();
con.Close();
con.Open();
com=new OleDbCommand(strBj,con);
reader=com.ExecuteReader();
while(reader.Read())
{
bjCount++;
}
labBj.Text="病假:"+bjCount.ToString()+"次";
reader.Close();
com.Dispose();
con.Close();
con.Open();
com=new OleDbCommand(strKg,con);
reader=com.ExecuteReader();
while(reader.Read())
{
kgCount++;
}
labKg.Text="旷工:"+kgCount.ToString()+"次";
reader.Close();
com.Dispose();
con.Close();
strSql="select * from kaoqin where id='"+strId+"' and year='"+strYear+"' and mon='"+strMon+"'";
con.Open();
da=new OleDbDataAdapter(strSql,con);
da.Fill(ds,"kaoqin");
data.DataSource=ds.Tables["kaoqin"].DefaultView;
data.DataBind();
con.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -