protected void btnSave_Click(object sender, EventArgs e) { string type = Request.QueryString["type"]; UserInfoModel user = new UserInfoModel { UserID = txtUserID.Value, UserName = txtName.Value, DeptID = Convert.ToInt32(ddlDept.SelectedValue), Cellphone = txtCellphone.Value, UserType = Convert.ToByte(ddlType.Value) }; UserInfoBLL bll = new UserInfoBLL(); try { if (type == "add") { bll.AppendUser(user); } else { if (txtPwd.Value != "") { user.Password = txtPwd.Value; } bll.EditUser(user); } ClientScript.RegisterStartupScript(this.GetType(), "optuser", "alert('保存成功!');parent.dialog.close();window.parent.location.reload();", true); } catch { ClientScript.RegisterStartupScript(this.GetType(), "optuser", "alert('保存失败!');", true); } }
protected override void Loading() { if (!IsPostBack) { BindDepartment(); string type = Request.QueryString["type"]; string userID = Request.QueryString["user"]; if (type == "edit") { UserInfoBLL bll = new UserInfoBLL(); UserInfoModel user = bll.GetUserById(userID); txtUserID.Disabled = true; txtUserID.Value = userID; txtName.Value = user.UserName; ddlDept.SelectedValue = (user.DeptID).ToString(); txtCellphone.Value = user.Cellphone; ddlType.Value = (user.UserType).ToString(); } else { editpwd.Visible = false; } } }
protected override void Loading() { if (!IsPostBack) { string userID = ((UserInfoModel)Session["user"]).UserID; UserInfoBLL bll = new UserInfoBLL(); UserInfoModel user = bll.GetUserById(userID); txtCellphone.Value = user.Cellphone; } }
protected void btnLogin_Click(object sender, EventArgs e) { string userID = txtUsername.Value.Trim(); string uPwd = txtPassword.Value; UserInfoBLL bll = new UserInfoBLL(); switch (bll.IsLoginIn(userID, uPwd)) { case LoginState.loginState_Success: // 判断用户登录类型 UserInfoModel user = bll.GetUserById(userID); Session["user"] = user; if (user.UserType.Equals(0)) Response.Redirect("Employee/MyAttendance.aspx"); else if (user.UserType.Equals(1)) Response.Redirect("Manager/AttendanceManage.aspx"); else Response.Redirect("Admin/AttendanceSetting.aspx"); break; case LoginState.loginState_NoFound: ClientScript.RegisterStartupScript(this.GetType(), "nofound", "alert('用户名不存在!');", true); break; case LoginState.loginState_PwdError: ClientScript.RegisterStartupScript(this.GetType(), "pwderror", "alert('用户密码错误!');", true); break; } }
public void ProcessRequest(HttpContext context) { if (context.Request.QueryString["type"] != null) { if (context.Request.QueryString["type"] == "bind") { #region 绑定用户列表 if (context.Request.QueryString["opera"] == "users") { Dictionary<string, string> userDic = new Dictionary<string, string>(); if (context.Request.QueryString["userID"] != null) { userDic["userID"] = context.Request.QueryString["userID"]; } if (context.Request.QueryString["userName"] != null) { userDic["userName"] = context.Request.QueryString["userName"]; } if (context.Request.QueryString["deptID"] != null) { userDic["deptID"] = context.Request.QueryString["deptID"]; } int pageCurrent = Convert.ToInt32(context.Request.QueryString["pageCurrent"]); string order = string.IsNullOrEmpty(context.Request.QueryString["orderField"]) ? "UserID" : context.Request.QueryString["orderField"]; int rowCount; UserInfoBLL bll = new UserInfoBLL(); DataTable dt = bll.GetUserList(userDic, pageCurrent, order, out rowCount); StringBuilder sb = new StringBuilder(); List<string> list = new List<string>(); list.Add("<tr><th scope='col'>序号</th><th scope='col'><input id='chkAll' type='checkbox' onclick='selectAll();' /></th><th scope='col'><a href='javascript:void(0);' onclick='order(\"UserID\");'>用户ID</a></th><th scope='col'><a href='javascript:void(0);' onclick='order(\"UserName\");'>用户姓名</a></th><th scope='col'><a href='javascript:void(0);' onclick='order(\"DeptID\");'>所属部门</a></th><th scope='col'> </th></tr>"); for (int i = 0; i < dt.Rows.Count; i++) { sb.Append("<tr>"); sb.AppendFormat("<td style='width: 10%;'><span>{0}</span></td>", dt.Rows[i][0]); sb.AppendFormat("<td style='width: 10%;'><input type='checkbox' value='{0}' /></td>", dt.Rows[i]["UserID"]); sb.AppendFormat("<td style='width: 15%;'>{0}</td>", dt.Rows[i]["UserID"]); sb.AppendFormat("<td style='width: 20%;'>{0}</td>", dt.Rows[i]["UserName"]); sb.AppendFormat("<td style='width: 15%;'>{0}</td>", dt.Rows[i]["DeptName"]); sb.AppendFormat("<td style='width: 10%;'><img alt='编辑' title='编辑' src='/Image/common/edit.png' class='imgBtn' onclick='editUser(\"{0}\");' /></td>", dt.Rows[i]["UserID"]); sb.Append("</tr>"); } if (string.IsNullOrEmpty(sb.ToString())) { list.Clear(); list.Add("<td colspan='6' style='text-align:center;line-height:26px;'>没有数据</td>"); } else { list.Add(sb.ToString()); } list.Add("☭" + rowCount); context.Response.Write(string.Concat(list)); } #endregion #region 绑定部门列表 else if (context.Request.QueryString["opera"] == "depart") { DepartmentModel dept = new DepartmentModel(); if (context.Request.QueryString["deptName"] != null) { dept.DeptName = context.Request.QueryString["deptName"]; } if (context.Request.QueryString["manager"] != null) { dept.ManagerID = context.Request.QueryString["manager"]; } int pageCurrent = Convert.ToInt32(context.Request.QueryString["pageCurrent"]); int rowCount; DepartmentBLL bll = new DepartmentBLL(); DataTable dt = bll.GetDepartList(dept, pageCurrent, out rowCount); StringBuilder sb = new StringBuilder(); List<string> list = new List<string>(); list.Add("<tr><th scope='col'>序号</th><th scope='col'>部门名称</th><th scope='col'>主管</th><th scope='col'> </th></tr>"); for (int i = 0; i < dt.Rows.Count; i++) { string DeptID = dt.Rows[i]["DeptID"].ToString(); sb.Append("<tr>"); sb.AppendFormat("<td style='width: 10%;'><span>{0}</span></td>", dt.Rows[i][0]); sb.AppendFormat("<td style='width: 30%;'>{0}</td>", dt.Rows[i]["DeptName"]); sb.AppendFormat("<td style='width: 20%;'>{0}</td>", dt.Rows[i]["UserName"]); // 如果部门下没有员工即可删除 if (bll.IsEmptyDepart(DeptID)) sb.AppendFormat("<td style='width: 20%;'><img alt='编辑' title='编辑' src='/Image/common/edit.png' class='imgBtn' onclick='editDept(\"{0}\");' /> <input type='image' id='btnDelete' title='删除' class='imgBtn' src='/Image/common/delete.png' onclick='return deleteDept(\"{1}\");' style='border-width:0px;'></td>", DeptID, DeptID); else sb.AppendFormat("<td style='width: 20%;'><img alt='编辑' title='编辑' src='/Image/common/edit.png' class='imgBtn' onclick='editDept(\"{0}\");' /></td>", DeptID); sb.Append("</tr>"); } if (string.IsNullOrEmpty(sb.ToString())) { list.Clear(); list.Add("<td colspan='4' style='text-align:center;line-height:26px;'>没有数据</td>"); } else { list.Add(sb.ToString()); } list.Add("☭" + rowCount); context.Response.Write(string.Concat(list)); } #endregion #region 显示考勤列表 else if (context.Request.QueryString["opera"] == "setting") { int year = Convert.ToInt32(context.Request.QueryString["year"]); int month = Convert.ToInt32(context.Request.QueryString["month"]); int days = DateTime.DaysInMonth(year, month);// 获取当前月份的天数 StringBuilder sb = new StringBuilder(); sb.Append("<tr><th scope='col'>日期</th><th scope='col'>星期</th><th scope='col'>状态</th></tr>"); //string[] chsWeek = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; AttendanceSettingBLL bll = new AttendanceSettingBLL(); DataTable dt = bll.GetAttendanceSetting(); for (int i = 1; i <= days; i++) { sb.Append("<tr>"); DateTime time = Convert.ToDateTime(year + "-" + month + "-" + i); string date = time.ToString("yyyy-MM-dd"); sb.AppendFormat("<td style='width:30%;'>{0}</td>", date); // 判断当前日期是星期几 //string week = chsWeek[Convert.ToInt32(time.DayOfWeek)]; string week = time.ToString("dddd"); sb.AppendFormat("<td style='width:30%;'>{0}</td>", week); // 获取当前的考勤设置 DataRow[] rows = dt.Select("Date = '" + date + "'"); if (rows.Length > 0) { if (rows[0]["Status"].ToString().Equals("1")) { sb.AppendFormat("<td style='width:20%;'><select id='ddlStatus' date='{0}'><option value='0' style='color:Black;'>默认</option><option selected='selected' value='1' style='color:Green;'>上班</option><option value='2' style='color:Red;'>休假</option></select></td>", date); } else { sb.AppendFormat("<td style='width:20%;'><select id='ddlStatus' date='{0}'><option value='0' style='color:Black;'>默认</option><option value='1' style='color:Green;'>上班</option><option selected='selected' value='2' style='color:Red;'>休假</option></select></td>", date); } } else { sb.AppendFormat("<td style='width:20%;'><select id='ddlStatus' date='{0}'><option selected='selected' value='0' style='color:Black;'>默认</option><option value='1' style='color:Green;'>上班</option><option value='2' style='color:Red;'>休假</option></select></td>", date); } sb.Append("</tr>"); } context.Response.Write(sb.ToString()); } #endregion #region 显示部门员工 else if (context.Request.QueryString["opera"] == "deptuser") { if (context.Session["user"] == null) { context.Response.Write("<script>top.location='/View/Default.aspx'</script>"); context.Response.End(); } string userID = ((UserInfoModel)context.Session["user"]).UserID; int pageCurrent = Convert.ToInt32(context.Request.QueryString["pageCurrent"]); string order = string.IsNullOrEmpty(context.Request.QueryString["orderField"]) ? "UserID" : context.Request.QueryString["orderField"]; int rowCount; AttendanceInfoBLL bll = new AttendanceInfoBLL(); DataTable dt = bll.GetDeptUser(userID, pageCurrent, order, out rowCount); StringBuilder sb = new StringBuilder(); List<string> list = new List<string>(); list.Add("<tr><th scope='col'>序号</th><th scope='col'><a href='javascript:void(0);' onclick='order(\"UserID\");'>用户ID</a></th><th scope='col'><a href='javascript:void(0);' onclick='order(\"UserName\");'>用户名</a></th><th scope='col'><a href='javascript:void(0);' onclick='order(\"DeptName\");'>部门</a></th><th scope='col'>考勤信息</th></tr>"); for (int i = 0; i < dt.Rows.Count; i++) { sb.Append("<tr>"); sb.AppendFormat("<td style='width: 10%;'><span>{0}</span></td>", dt.Rows[i][0]); sb.AppendFormat("<td style='width: 20%;'>{0}</td>", dt.Rows[i]["UserID"]); sb.AppendFormat("<td style='width: 20%;'>{0}</td>", dt.Rows[i]["UserName"]); sb.AppendFormat("<td style='width: 20%;'>{0}</td>", dt.Rows[i]["DeptName"]); sb.AppendFormat("<td style='width: 10%;'><a href='javascript:showAttendance(\"{0}\");'>查看</a></td>", dt.Rows[i]["UserID"]); sb.Append("</tr>"); } if (string.IsNullOrEmpty(sb.ToString())) { list.Clear(); list.Add("<td colspan='5' style='text-align:center;line-height:26px;'>没有数据</td>"); } else { list.Add(sb.ToString()); } list.Add("☭" + rowCount); context.Response.Write(string.Concat(list)); } #endregion #region 显示请假列表 else if (context.Request.QueryString["opera"] == "leave") { if (context.Session["user"] == null) { context.Response.Write("<script>top.location='/View/Default.aspx'</script>"); context.Response.End(); } string userID = ((UserInfoModel)context.Session["user"]).UserID; string title = null, beginDate = null, endDate = null, statu = null, name = null; if (context.Request.QueryString["title"] != null) { title = context.Request.QueryString["title"]; } if (context.Request.QueryString["begin"] != null) { beginDate = context.Request.QueryString["begin"]; } if (context.Request.QueryString["end"] != null) { endDate = context.Request.QueryString["end"]; } if (context.Request.QueryString["statu"] != null) { statu = context.Request.QueryString["statu"]; } if (context.Request.QueryString["name"] != null) { name = context.Request.QueryString["name"]; } int pageCurrent = Convert.ToInt32(context.Request.QueryString["pageCurrent"]); string order = string.IsNullOrEmpty(context.Request.QueryString["orderField"]) ? "UserName" : context.Request.QueryString["orderField"]; int rowCount; ApproveBLL bll = new ApproveBLL(); DataTable dt = bll.GetLeave(userID, title, beginDate, endDate, statu, name, pageCurrent, order, out rowCount); StringBuilder sb = new StringBuilder(); List<string> list = new List<string>(); list.Add("<tr><th scope='col'>请假单ID</th><th scope='col'><a href='javascript:void(0);' onclick='order(\"UserName\");'>申请人</a></th><th scope='col'>标题</th><th scope='col'><a href='javascript:void(0);' onclick='order(\"BeginDate\");'>起始时间</a></th><th scope='col'><a href='javascript:void(0);' onclick='order(\"EndDate\");'>结束时间</a></th><th scope='col'><a href='javascript:void(0);' onclick='order(\"ApplyDate\");'>申请时间</a></th><th scope='col'>请假单状态</th><th scope='col'> </th></tr>"); for (int i = 0; i < dt.Rows.Count; i++) { sb.Append("<tr>"); sb.AppendFormat("<td style='width:8%;'>{0}</td>", dt.Rows[i]["ApproveID"]); sb.AppendFormat("<td style='width:10%;'>{0}</td>", dt.Rows[i]["UserName"]); sb.AppendFormat("<td style='width:15%;'>{0}</td>", dt.Rows[i]["Title"]); sb.AppendFormat("<td style='width:10%;'>{0}</td>", dt.Rows[i]["BeginDate"]); sb.AppendFormat("<td style='width:10%;'>{0}</td>", dt.Rows[i]["EndDate"]); sb.AppendFormat("<td style='width:10%;'>{0}</td>", dt.Rows[i]["ApplyDate"]); string status = dt.Rows[i]["Status"].ToString(); sb.AppendFormat("<td style='width:7%;'><span id='lblStatus'>{0}</span></td>", status == "0" ? "待审批" : "归档"); string opt = HttpUtility.UrlDecode(context.Request.QueryString["opt"], Encoding.UTF8); if (opt == "请假审批") { string type = status == "0" ? "apprv(\"{0}\")" : "show(\"{0}\")"; sb.AppendFormat("<td style='width:10%;'><a href='javascript:{0};'>查看</a></td>", string.Format(type, dt.Rows[i]["ApproveID"])); } else { if (status == "0") { sb.AppendFormat("<td style='width:10%;'><img alt='编辑' title='编辑' src='/Image/common/edit.png' class='imgBtn' onclick='editLeave(\"{0}\");'><input type='image' id='btnDelete' title='删除' class='imgBtn' src='/Image/common/delete.png' onclick='return deleteApp(\"{1}\");' style='border-width:0px;'></td>'", dt.Rows[i]["ApproveID"], dt.Rows[i]["ApproveID"]); } else { sb.AppendFormat("<td style='width:10%;'><a href='javascript:show(\"{0}\");'>查看</a></td>", dt.Rows[i]["ApproveID"]); } } sb.Append("</tr>"); } if (string.IsNullOrEmpty(sb.ToString())) { list.Clear(); list.Add("<td colspan='4' style='text-align:center;line-height:26px;'>没有数据</td>"); } else { list.Add(sb.ToString()); } list.Add("☭" + rowCount); context.Response.Write(string.Concat(list)); } #endregion #region 列表显示员工考勤 else if (context.Request.QueryString["opera"] == "userattc") { string userID = string.Empty; if (!string.IsNullOrEmpty(context.Request.QueryString["userID"])) { userID = context.Request.QueryString["userID"]; } else if (context.Session["user"] != null) { userID = ((UserInfoModel)context.Session["user"]).UserID; } else { context.Response.Write("<script>top.location='/View/Default.aspx'</script>"); context.Response.End(); } int year = Convert.ToInt32(context.Request.QueryString["year"]); int month = Convert.ToInt32(context.Request.QueryString["month"]); int days = DateTime.DaysInMonth(year, month); // 获取当前月份的天数 StringBuilder sb = new StringBuilder(); sb.Append("<table class='grid' cellspacing='0' rules='all' border='1' style='border-collapse: collapse;'>"); sb.Append("<tr><th scope='col'>日期</th><th scope='col'>星期</th><th scope='col'>首次打卡时间</th><th scope='col'>最后打卡时间</th><th scope='col'>考勤状态</th></tr>"); string[] chsWeek = { "周日", "周一", "周二", "周三", "周四", "周五", "周六" }; AttendanceInfoBLL bll = new AttendanceInfoBLL(); DataTable dt = bll.GetAskForLeaveTime(userID); for (int i = 1; i <= days; i++) { sb.Append("<tr>"); DateTime time = Convert.ToDateTime(year + "-" + month + "-" + i); string date = time.ToString("yyyy-MM-dd"); sb.AppendFormat("<td style='width:12%;'>{0}</td>", date); // 判断当前日期是周几 string week = chsWeek[Convert.ToInt32(time.DayOfWeek)]; sb.AppendFormat("<td style='width:8%;'>{0}</td>", week); // 获取当天的打卡时间 string min = bll.GetMinFaceTime(userID, date).ToString(); sb.AppendFormat("<td style='width:20%;'>{0}</td>", min); string max = bll.GetMaxFaceTime(userID, date).ToString(); sb.AppendFormat("<td style='width:20%;'>{0}</td>", max); DateTime? minTime = null; if (!string.IsNullOrEmpty(min)) { minTime = Convert.ToDateTime(min); } DateTime? maxTime = null; if (!string.IsNullOrEmpty(max)) { maxTime = Convert.ToDateTime(max); } // 正常的上下班时间 DateTime morInTime = Convert.ToDateTime(date + " 08:30:00"); DateTime morOutTime = Convert.ToDateTime(date + " 11:50:00"); DateTime aftInTime = Convert.ToDateTime(date + " 13:50:00"); DateTime aftOutTime = Convert.ToDateTime(date + " 17:00:00"); byte statu; try { statu = Convert.ToByte(bll.GetStatus(date)); } catch { statu = 0; } if (statu.Equals(0) || statu.Equals(2)) { sb.Append("<td style='width:20%;'><span style='color:gray'>休假</span></td>"); } else if (statu.Equals(1)) { // 如果当天存在请假信息,进行考勤状态的逻辑判断 if (bll.IsAskForLeaveTime(userID, date)) { DataRow[] row1 = dt.Select("BeginDate<='" + morInTime + "' and EndDate>='" + morOutTime + "'"); DataRow[] row2 = dt.Select("BeginDate<='" + aftInTime + "' and EndDate>='" + aftOutTime + "'"); if (minTime == null && maxTime == null) { if (row1.Length > 0 && row2.Length > 0) { sb.Append("<td style='width:20%;'><span style='color:#436EEE'>请假</span></td>"); } else if (row2.Length > 0) { sb.Append("<td style='width:20%;'><span style='color:red;margin-right:10px;'>缺勤</span><span style='color:#436EEE;margin-left:10px;'>请假</span></td>"); } else if (row1.Length > 0) { sb.Append("<td style='width:20%;'><span style='color:#436EEE;margin-right:10px;'>请假</span><span style='color:red;margin-left:10px;'>缺勤</span></td>"); } else { sb.Append("<td style='width:20%;'><span style='color:red'>缺勤</span></td>"); } } else { // 对比上下班时间判定考勤状态 int r1 = DateTime.Compare((DateTime)minTime, morInTime); int r2 = DateTime.Compare((DateTime)maxTime, aftOutTime); int r3 = DateTime.Compare((DateTime)maxTime, morOutTime); int r4 = DateTime.Compare((DateTime)minTime, aftInTime); if (row1.Length > 0 && row2.Length > 0) { sb.Append("<td style='width:20%;'><span style='color:#436EEE'>请假</span></td>"); } else if (DateTime.Compare((DateTime)minTime, (DateTime)maxTime) == 0 && row1.Length > 0) { sb.Append("<td style='width:20%;'><span style='color:#436EEE;margin-right:10px;'>请假</span><span style='color:pink;margin-left:10px;'>未打卡</span></td>"); } else if (DateTime.Compare((DateTime)minTime, (DateTime)maxTime) == 0 && row2.Length > 0) { sb.Append("<td style='width:20%;'><span style='color:pink;margin-right:10px;'>未打卡</span><span style='color:#436EEE;margin-left:10px;'>请假</span></td>"); } else if ((r4 > 0 && r2 < 0) && row1.Length > 0) { sb.Append("<td style='width:20%;'><span style='color:#436EEE;margin-right:10px;'>请假</span><span style='color:Aqua;margin-left:10px;'>迟到且早退</span></td>"); } else if ((r1 > 0 && r3 < 0) && row2.Length > 0) { sb.Append("<td style='width:20%;'><span style='color:Aqua;margin-right:10px;'>迟到且早退</span><span style='color:#436EEE;margin-left:10px;'>请假</span></td>"); } else if ((r4 <= 0 && r2 >= 0) && row1.Length > 0) { sb.Append("<td style='width:20%;'><span style='color:#436EEE;margin-right:10px;'>请假</span><span style='color:#3CB371;margin-left:10px;'>正常</span></td>"); } else if ((r1 <= 0 && r3 >= 0) && row2.Length > 0) { sb.Append("<td style='width:20%;'><span style='color:#3CB371;margin-right:10px;'>正常</span><span style='color:#436EEE;margin-left:10px;'>请假</span></td>"); } else if (r2 < 0 && row1.Length > 0) { sb.Append("<td style='width:20%;'><span style='color:#436EEE;margin-right:10px;'>请假</span><span style='color:Orange;margin-left:10px;'>早退</span></td>"); } else if (r4 > 0 && row1.Length > 0) { sb.Append("<td style='width:20%;'><span style='color:#436EEE;margin-right:10px;'>请假</span><span style='color:#CAFF70;margin-left:10px;'>迟到</span></td>"); } else if (r1 > 0 && row2.Length > 0) { sb.Append("<td style='width:20%;'><span style='color:#CAFF70;margin-right:10px;'>迟到</span><span style='color:#436EEE;margin-left:10px;'>请假</span></td>"); } else if (r3 < 0 && row2.Length > 0) { sb.Append("<td style='width:20%;'><span style='color:Orange;margin-right:10px;'>早退</span><span style='color:#436EEE;margin-left:10px;'>请假</span></td>"); } else if (r1 > 0) { sb.Append("<td style='width:20%;'><span style='color:#CAFF70;margin-right:10px;'>迟到</span><span style='color:red;margin-left:10px;'>缺勤</span></td>"); } else if (r2 < 0) { sb.Append("<td style='width:20%;'><span style='color:red;margin-right:10px;'>缺勤</span><span style='color:Orange;margin-left:10px;'>早退</span></td>"); } else { sb.Append("<td style='width:20%;'><span style='color:red'>缺勤</span></td>"); } } } else { if (minTime == null && maxTime == null) { sb.Append("<td style='width:20%;'><span style='color:red'>缺勤</span></td>"); } else { // 对比上下班时间判定考勤状态 int r1 = DateTime.Compare((DateTime)minTime, morInTime); int r2 = DateTime.Compare((DateTime)maxTime, aftOutTime); if (DateTime.Compare((DateTime)minTime, (DateTime)maxTime) == 0) { sb.Append("<td style='width:20%;'><span style='color:pink'>未打卡</span></td>"); } else if (r1 <= 0 && r2 >= 0) { sb.Append("<td style='width:20%;'><span style='color:#3CB371'>正常</span></td>"); } else if (r1 > 0 && r2 < 0) { sb.Append("<td style='width:20%;'><span style='color:Aqua'>迟到且早退</span></td>"); } else if (r1 > 0) { sb.Append("<td style='width:20%;'><span style='color:#CAFF70'>迟到</span></td>"); } else if (r2 < 0) { sb.Append("<td style='width:20%;'><span style='color:Orange'>早退</span></td>"); } else { sb.Append("<td style='width:20%;'><span style='color:#8B008B'>异常</span></td>"); } } } } sb.Append("</tr>"); } sb.Append("</table>"); context.Response.Write(sb.ToString()); } #endregion #region 日历显示员工考勤 else if (context.Request.QueryString["opera"] == "calendar") { if (context.Session["user"] == null) { context.Response.Write("<script>top.location='/View/Default.aspx'</script>"); context.Response.End(); } string userID = ((UserInfoModel)context.Session["user"]).UserID; int year = Convert.ToInt32(context.Request.QueryString["year"]); int month = Convert.ToInt32(context.Request.QueryString["month"]); int days = DateTime.DaysInMonth(year, month); // 获取当前月份的天数 StringBuilder sb = new StringBuilder(); sb.Append("<table class='calendar' cellspacing='0' rules='all' border='1' id='calendar' style='border-collapse:collapse;'>"); sb.Append("<tr><th scope='col'>一</th><th scope='col'>二</th><th scope='col'>三</th><th scope='col'>四</th><th scope='col'>五</th><th scope='col'>六</th><th scope='col'>日</th></tr>"); int day = 1; DateTime time = Convert.ToDateTime(year + "-" + month + "-" + day); AttendanceInfoBLL bll = new AttendanceInfoBLL(); DataTable dt = bll.GetAskForLeaveTime(userID); for (int i = 0; i < 6; i++) { sb.Append("<tr>"); // 遍历每个星期的考勤状态 for (int j = 0; j < 7; j++) { int week = (Convert.ToInt32(time.DayOfWeek) + 6) % 7; if (j == week && day <= days) { string date = time.ToString("yyyy-MM-dd"); // 获取当天的打卡时间 string min = bll.GetMinFaceTime(userID, date).ToString(); string max = bll.GetMaxFaceTime(userID, date).ToString(); sb.AppendFormat("<td Day='{0}' FirstTime='{1}' LastTime='{2}'>", time.ToString("yyyy年MM月dd日") + "\t" + time.ToString("dddd"), min, max); sb.AppendFormat("<div class='left'>{0}</div>", day); DateTime? minTime = null; if (!string.IsNullOrEmpty(min)) { minTime = Convert.ToDateTime(min); } DateTime? maxTime = null; if (!string.IsNullOrEmpty(max)) { maxTime = Convert.ToDateTime(max); } // 正常的上下班时间 DateTime morInTime = Convert.ToDateTime(date + " 08:30:00"); DateTime morOutTime = Convert.ToDateTime(date + " 11:50:00"); DateTime aftInTime = Convert.ToDateTime(date + " 13:50:00"); DateTime aftOutTime = Convert.ToDateTime(date + " 17:00:00"); byte statu; try { statu = Convert.ToByte(bll.GetStatus(date)); } catch { statu = 0; } if (statu.Equals(0) || statu.Equals(2)) { sb.Append("<div class='right'><div class='div1' style='background-color:gray;'>休假</div></div>"); } else if (statu.Equals(1)) { // 如果当天存在请假信息,进行考勤状态的逻辑判断 if (bll.IsAskForLeaveTime(userID, date)) { DataRow[] row1 = dt.Select("BeginDate<='" + morInTime + "' and EndDate>='" + morOutTime + "'"); DataRow[] row2 = dt.Select("BeginDate<='" + aftInTime + "' and EndDate>='" + aftOutTime + "'"); if (minTime == null && maxTime == null) { if (row1.Length > 0 && row2.Length > 0) { sb.Append("<div class='right'><div class='div1' style='background-color:#436EEE;'>请假</div></div>"); } else if (row2.Length > 0) { sb.Append("<div class='right'><div class='div2' style='background-color:red;'>缺勤</div><div class='div2' style='background-color:#436EEE;'>请假</div></div>"); } else if (row1.Length > 0) { sb.Append("<div class='right'><div class='div2' style='background-color:#436EEE;'>请假</div><div class='div2' style='background-color:red;'>缺勤</div></div>"); } else { sb.Append("<div class='right'><div class='div1' style='background-color:red;'>缺勤</div></div>"); } } else { // 对比上下班时间判定考勤状态 int r1 = DateTime.Compare((DateTime)minTime, morInTime); int r2 = DateTime.Compare((DateTime)maxTime, aftOutTime); int r3 = DateTime.Compare((DateTime)maxTime, morOutTime); int r4 = DateTime.Compare((DateTime)minTime, aftInTime); if (row1.Length > 0 && row2.Length > 0) { sb.Append("<div class='right'><div class='div1' style='background-color:#436EEE;'>请假</div></div>"); } else if (DateTime.Compare((DateTime)minTime, (DateTime)maxTime) == 0 && row1.Length > 0) { sb.Append("<div class='right'><div class='div2' style='background-color:#436EEE;'>请假</div><div class='div2' style='background-color:pink;'>未打卡</div></div>"); } else if (DateTime.Compare((DateTime)minTime, (DateTime)maxTime) == 0 && row2.Length > 0) { sb.Append("<div class='right'><div class='div2' style='background-color:pink;'>未打卡</div><div class='div2' style='background-color:#436EEE;'>请假</div></div>"); } else if ((r4 > 0 && r2 < 0) && row1.Length > 0) { sb.Append("<div class='right'><div class='div2' style='background-color:#436EEE;'>请假</div><div class='div2' style='background-color:Aqua;'>迟到且早退</div></div>"); } else if ((r1 > 0 && r3 < 0) && row2.Length > 0) { sb.Append("<div class='right'><div class='div2' style='background-color:Aqua;'>迟到且早退</div><div class='div2' style='background-color:#436EEE;'>请假</div></div>"); } else if ((r4 <= 0 && r2 >= 0) && row1.Length > 0) { sb.Append("<div class='right'><div class='div2' style='background-color:#436EEE;'>请假</div><div class='div2' style='background-color:#3CB371;'>正常</div></div>"); } else if ((r1 <= 0 && r3 >= 0) && row2.Length > 0) { sb.Append("<div class='right'><div class='div2' style='background-color:#3CB371;'>正常</div><div class='div2' style='background-color:#436EEE;'>请假</div></div>"); } else if (r2 < 0 && row1.Length > 0) { sb.Append("<div class='right'><div class='div2' style='background-color:#436EEE;'>请假</div><div class='div2' style='background-color:Orange;'>早退</div></div>"); } else if (r4 > 0 && row1.Length > 0) { sb.Append("<div class='right'><div class='div2' style='background-color:#436EEE;'>请假</div><div class='div2' style='background-color:#CAFF70;'>迟到</div></div>"); } else if (r1 > 0 && row2.Length > 0) { sb.Append("<div class='right'><div class='div2' style='background-color:#CAFF70;'>迟到</div><div class='div2' style='background-color:#436EEE;'>请假</div></div>"); } else if (r3 < 0 && row2.Length > 0) { sb.Append("<div class='right'><div class='div2' style='background-color:Orange;'>早退</div><div class='div2' style='background-color:#436EEE;'>请假</div></div>"); } else if (r1 > 0) { sb.Append("<div class='right'><div class='div2' style='background-color:#CAFF70;'>迟到</div><div class='div2' style='background-color:red;'>缺勤</div></div>"); } else if (r2 < 0) { sb.Append("<div class='right'><div class='div2' style='background-color:red;'>缺勤</div><div class='div2' style='background-color:Orange;'>早退</div></div>"); } else { sb.Append("<div class='right'><div class='div1' style='background-color:red;'>缺勤</div></div>"); } } } else { if (minTime == null && maxTime == null) { sb.Append("<div class='right'><div class='div1' style='background-color:red;'>缺勤</div></div>"); } else { // 对比上下班时间判定考勤状态 int r1 = DateTime.Compare((DateTime)minTime, morInTime); int r2 = DateTime.Compare((DateTime)maxTime, aftOutTime); if (DateTime.Compare((DateTime)minTime, (DateTime)maxTime) == 0) { sb.Append("<div class='right'><div class='div1' style='background-color:pink;'>未打卡</div></div>"); } else if (r1 <= 0 && r2 >= 0) { sb.Append("<div class='right'><div class='div1' style='background-color:#3CB371;'>正常</div></div>"); } else if (r1 > 0 && r2 < 0) { sb.Append("<div class='right'><div class='div1' style='background-color:Aqua;'>迟到且早退</div></div>"); } else if (r1 > 0) { sb.Append("<div class='right'><div class='div1' style='background-color:#CAFF70;'>迟到</div></div>"); } else if (r2 < 0) { sb.Append("<div class='right'><div class='div1' style='background-color:Orange;'>早退</div></div>"); } else { sb.Append("<div class='right'><div class='div1' style='background-color:#8B008B;'>异常</div></div>"); } } } } sb.Append("</td>"); time = time.AddDays(1); day++; } else { sb.Append("<td><div class='left'></div><div class='right'></div></td>"); } } sb.Append("</tr>"); if (day > days) break; } sb.Append("</table>"); context.Response.Write(sb.ToString()); } #endregion } else if (context.Request.QueryString["type"] == "delete") { #region 删除指定用户 if (context.Request.QueryString["opera"] == "users") { if (context.Request.QueryString["userID"] != null) { UserInfoBLL bll = new UserInfoBLL(); int res = bll.DeleteUsers(context.Request.QueryString["userID"]); int total = Convert.ToInt32(context.Request.QueryString["total"]); string msg = res > 0 ? "删除成功:" + res + "条,删除失败:" + (res - total) + "条。" : "删除失败!"; context.Response.Write(msg); } } #endregion #region 删除指定部门 else if (context.Request.QueryString["opera"] == "depart") { if (context.Request.QueryString["deptID"] != null) { DepartmentBLL bll = new DepartmentBLL(); try { bll.DeleteDepart(context.Request.QueryString["deptID"]); context.Response.Write("{'Result':'OK','Message':'删除成功!'}"); } catch { context.Response.Write("{'Result':'NO','Message':'删除失败!'}"); } } } #endregion #region 删除请假单 else if (context.Request.QueryString["opera"] == "leave") { if (context.Request.QueryString["appID"] != null) { ApproveBLL bll = new ApproveBLL(); try { bll.DeleteLeave(context.Request.QueryString["appID"]); context.Response.Write("{'Result':'OK','Message':'删除成功!'}"); } catch { context.Response.Write("{'Result':'NO','Message':'删除失败!'}"); } } } #endregion } else if (context.Request.QueryString["type"] == "append") { #region 添加请假单 if (context.Request.QueryString["opera"] == "leave") { if (context.Session["user"] == null) { context.Response.Write("<script>top.location='/View/Default.aspx'</script>"); context.Response.End(); } ApproveModel apprv = new ApproveModel { ApplyUser = ((UserInfoModel)context.Session["user"]).UserID, Title = context.Request.QueryString["title"], BeginDate = Convert.ToDateTime(context.Request.QueryString["beginDate"]), EndDate = Convert.ToDateTime(context.Request.QueryString["endDate"]), Reason = context.Request.QueryString["reason"] }; ApproveBLL bll = new ApproveBLL(); try { bll.AppendLeave(apprv); context.Response.Write("{'Result':'OK','Message':'保存成功!'}"); } catch { context.Response.Write("{'Result':'NO','Message':'保存失败!'}"); } } #endregion } else if (context.Request.QueryString["type"] == "edit") { #region 编辑个人资料 if (context.Request.QueryString["opera"] == "private") { if (context.Session["user"] == null) { context.Response.Write("<script>top.location='/View/Default.aspx'</script>"); context.Response.End(); } UserInfoModel user = new UserInfoModel { UserID = ((UserInfoModel)context.Session["user"]).UserID, Cellphone = context.Request.QueryString["phone"] }; // 检验用户是否修改密码 if (context.Request.QueryString["pwd"] != null) { user.Password = MD5Maker.GetMD5(context.Request.QueryString["pwd"]); } UserInfoBLL bll = new UserInfoBLL(); try { bll.EditPrivate(user); context.Response.Write("{'Result':'OK','Message':'保存成功!'}"); } catch { context.Response.Write("{'Result':'NO','Message':'保存失败!'}"); } } #endregion #region 设置日常考勤 else if (context.Request.QueryString["opera"] == "setting") { string date = context.Request.QueryString["date"]; string statu = context.Request.QueryString["statu"]; AttendanceSettingBLL bll = new AttendanceSettingBLL(); try { bll.SetAttendanceSetting(date, statu); context.Response.Write("{'Result':'OK','Message':'保存成功!'}"); } catch { context.Response.Write("{'Result':'NO','Message':'保存失败!'}"); } } #endregion #region 编辑请假单 else if (context.Request.QueryString["opera"] == "leave") { ApproveModel apprv = new ApproveModel { ApproveID = Convert.ToInt32(context.Request.QueryString["appID"]), Title = context.Request.QueryString["title"], BeginDate = Convert.ToDateTime(context.Request.QueryString["beginDate"]), EndDate = Convert.ToDateTime(context.Request.QueryString["endDate"]), Reason = context.Request.QueryString["reason"] }; ApproveBLL bll = new ApproveBLL(); try { bll.EditLeave(apprv); context.Response.Write("{'Result':'OK','Message':'保存成功!'}"); } catch { context.Response.Write("{'Result':'NO','Message':'保存失败!'}"); } } #endregion #region 审批请假单 else if (context.Request.QueryString["opera"] == "apprv") { if (context.Session["user"] == null) { context.Response.Write("<script>top.location='/View/Default.aspx'</script>"); context.Response.End(); } ApproveModel apprv = new ApproveModel { ApproveID = Convert.ToInt32(context.Request.QueryString["appID"]), ApproveUser = ((UserInfoModel)context.Session["user"]).UserID, Result = Convert.ToByte(context.Request.QueryString["result"]), Remark = context.Request.QueryString["remark"] }; ApproveBLL bll = new ApproveBLL(); try { bll.ApprvLeave(apprv); context.Response.Write("{'Result':'OK','Message':'保存成功!'}"); } catch { context.Response.Write("{'Result':'NO','Message':'保存失败!'}"); } } #endregion } else if (context.Request.QueryString["type"] == "validate") { #region 验证用户ID if (context.Request.QueryString["opera"] == "users") { string userID = context.Request.QueryString["userID"]; UserInfoBLL bll = new UserInfoBLL(); if (bll.IsExistsID(userID)) context.Response.Write("{'Result':'NO'}"); else context.Response.Write("{'Result':'OK'}"); } #endregion #region 验证部门名称 else if (context.Request.QueryString["opera"] == "depart") { string dept = context.Request.QueryString["dept"]; DepartmentBLL bll = new DepartmentBLL(); if (bll.IsExistsDept(dept)) context.Response.Write("{'Result':'NO'}"); else context.Response.Write("{'Result':'OK'}"); } #endregion } else if (context.Request.QueryString["type"] == "logout") { #region 清除Session context.Session["user"] = null; context.Response.Write("<script>location='/View/Default.aspx'</script>"); #endregion } } }