📄 main.aspx.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;
using System.Data.SqlClient;
public partial class Main : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["uname"] != null)
{
this.btngowork.Attributes.Add("onclick", "return confirm('确定要上班吗?')");
this.btnoffwork.Attributes.Add("onclick", "return confirm('确定要下班吗?')");
if (!IsPostBack)
{
SetWork sw = new SetWork();
SqlDataReader dr = sw.sel_worktime();
if (dr.Read())
{
string onworktime = dr["ondutytime"].ToString();
string offworktime = dr["offdutytime"].ToString();
string startdate = dr["onStateTime"].ToString();
string enddate = dr["onEndTime"].ToString();
lab_on.Text = onworktime;
lab_off.Text = offworktime;
lab_startdate.Text = startdate;
lab_enddate.Text = enddate;
if (Convert.ToDateTime(lab_startdate.Text) < DateTime.Now && Convert.ToDateTime(lab_enddate.Text) > DateTime.Now)
{
if (DateTime.Now > Convert.ToDateTime("06:00") && DateTime.Now < Convert.ToDateTime("12:00"))
{
this.btnoffwork.Enabled = false;
if (DateTime.Now > Convert.ToDateTime(this.lab_on.Text))
{
string latertime = Convert.ToString(DateTime.Now - Convert.ToDateTime(this.lab_on.Text));
// Response.Write("<script>alert('如果是上班,你已迟到了"+latertime+"小时')</script>");
labmessage.Text = "如果是上班,你已迟到了<b>" + latertime + "</b>小时";
}
}
else
{
this.btngowork.Enabled = false;
if (Convert.ToDateTime(this.lab_off.Text) > DateTime.Now)
{
string leavetime = Convert.ToString(Convert.ToDateTime(this.lab_off.Text) - DateTime.Now);
// Response.Write("<script>alert('如果是下班,你将早退" + leavetime + "小时')</script>");
labmessage.Text = "如果是下班,你将早退<b>" + leavetime + "</b>小时";
}
}
}
else
{
this.btngowork.Enabled = false;
this.btnoffwork.Enabled = false;
Response.Write("<script>alert('上班日期过期,请管理员重新设置!')</script>");
}
band();
}
}
staff s = new staff();
SqlDataReader dr_Attendance = s.SelectTotle(Session["uname"].ToString(), DateTime.Now.Month.ToString());
if (dr_Attendance.Read())
{
string later = dr_Attendance["later"].ToString();
string early = dr_Attendance["early"].ToString();
int nowork = Convert.ToInt32(dr_Attendance["nowork1"]) + Convert.ToInt32(dr_Attendance["nowork2"]);
lablater.Text = "<Font color=red>迟到:</font>" + later + "次";
labearly.Text = "<Font color=red>早退:</font>" + early + "次";
labnowork.Text = "<Font color=red>旷工:</font>" + nowork + "次";
}
}
else
{
Response.Redirect("login.aspx");
}
}
protected void btngowork_Click(object sender, EventArgs e)
{
int ondutystatus;
if (DateTime.Now > Convert.ToDateTime(this.lab_on.Text))
{
ondutystatus = 0;
}
else
{
ondutystatus = 1;
}
ArrayList onwork = new ArrayList();
onwork.Add(Session["uname"].ToString());
onwork.Add(ondutystatus);
onwork.Add(DateTime.Now.ToShortTimeString());
onwork.Add(DateTime.Now.ToShortDateString());
onwork.Add(this.tmessage.Text.ToString());
SetWork sw = new SetWork();
if (sw.sel_YesOrNoWork(Convert.ToInt32(Session["uname"]), DateTime.Now.ToShortDateString()) != 1)
{
sw.onwork(onwork);
band();
}
else
{
Response.Write("<script>alert('重复上班!')</script>");
}
}
protected void btnoffwork_Click(object sender, EventArgs e)
{
SetWork sw = new SetWork();
SqlDataReader dr = sw.checkoffwork(Convert.ToInt32(Session["uname"]), DateTime.Now.ToShortDateString());
if (dr.Read())
{
if (dr["offdutyStatus"].ToString() == "" && dr["offdudydate"].ToString() == "")
{
if (sw.sel_YesOrNoWork(Convert.ToInt32(Session["uname"]), DateTime.Now.ToShortDateString()) == 1)
{
int leaver;
if (Convert.ToDateTime(this.lab_off.Text) > DateTime.Now)
{
leaver = 0;
}
else
{
leaver = 1;
}
ArrayList offwork = new ArrayList();
offwork.Add(Convert.ToInt32(Session["uname"]));
offwork.Add(leaver);
offwork.Add(DateTime.Now.ToShortTimeString());
offwork.Add(DateTime.Now.ToShortDateString());
offwork.Add(this.tmessage.Text.ToString());
sw.offwork(offwork);
band();
}
}
else
{
Response.Write("<script>alert('重复下班!')</script>");
}
}
else
{
int leaver_insert;
if (DateTime.Now > Convert.ToDateTime(this.lab_off.Text))
{
leaver_insert = 1;
}
else
{
leaver_insert = 0;
}
ArrayList arr_offwork_insert = new ArrayList();
arr_offwork_insert.Add(Convert.ToInt32(Session["uname"]));
arr_offwork_insert.Add(leaver_insert);
arr_offwork_insert.Add(DateTime.Now.ToShortTimeString());
arr_offwork_insert.Add(DateTime.Now.ToShortDateString());
arr_offwork_insert.Add(this.tmessage.Text.ToString());
sw.offwork_insert(arr_offwork_insert);
band();
}
}
private void band()
{
string NowMonth = DateTime.Now.Month.ToString();
staff s = new staff();
this.gridattendance.DataSource = s.SelectAttendance(Session["uname"].ToString(), NowMonth);
this.gridattendance.DataBind();
}
protected void gridattendance_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标经过时,行背景色变
// e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ECF3E1'");
//鼠标移出时,行背景色变
// e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
DataRowView dv = (DataRowView)e.Row.DataItem;
if (Convert.ToString(dv["ondutyStatus"]) == "1")
{
((Label)e.Row.FindControl("labstatus1")).Text = "正常上班";
}
else if (Convert.ToString(dv["ondutyStatus"]) == "0")
{
((Label)e.Row.FindControl("labstatus1")).Text = "迟到";
((Label)e.Row.FindControl("labstatus1")).ForeColor = System.Drawing.Color.Red;
}
else if (Convert.ToString(dv["ondutyStatus"]) == "")
{
((Label)e.Row.FindControl("labstatus1")).Text = "旷工";
((Label)e.Row.FindControl("labstatus1")).ForeColor = System.Drawing.Color.Red;
}
if (Convert.ToString(dv["offdutyStatus"]) == "1")
{
((Label)e.Row.FindControl("labstatus2")).Text = "正常下班";
}
else if ((Convert.ToString(dv["offdutyStatus"]) == "0"))
{
((Label)e.Row.FindControl("labstatus2")).Text = "早退";
((Label)e.Row.FindControl("labstatus2")).ForeColor = System.Drawing.Color.Red;
}
else if ((Convert.ToString(dv["offdutyStatus"]) == ""))
{
((Label)e.Row.FindControl("labstatus2")).Text = "旷工";
((Label)e.Row.FindControl("labstatus2")).ForeColor = System.Drawing.Color.Red;
}
}
}
protected void gridattendance_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.gridattendance.PageIndex = e.NewPageIndex;
band();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -