protected void commonModel(MGovAttendance Model, String id, HtmlInputCheckBox ck, DateTime dt) { Model.AttendanceType = (EyouSoft.Model.EnumType.GovStructure.AttendanceType)Utils.GetInt(ck.Value); //如果是“准点、迟到、早退、旷工”,考勤时间为第一个文本框的值 。 //如果是“请假、加班”,则为遍历时的当天时间。 Model.AttendanceTime = dt; Model.CompanyId = this.SiteUserInfo.CompanyId; Model.IssueTime = DateTime.Now; Model.OperatorId = this.SiteUserInfo.UserId; Model.StaffId = id; if (ck == this.ckLeave) { Model.Subject = this.txtLeaveCause.Value; } if (ck == this.ckAdd) { Model.Subject = this.txtAddContent.Value; } }
/// <summary> /// 页面初始化 /// </summary> /// <param name="id">操作ID</param> protected void PageInit(string doType) { //考勤编号 string attId = Utils.GetQueryStringValue("attID"); string date = Utils.GetQueryStringValue("date"); //如果为修改 if (doType == "update" && !string.IsNullOrEmpty(attId)) { BAttendance BLL = new BAttendance(); MGovAttendance model = BLL.GetGovAttendanceModel(attId, this.SiteUserInfo.CompanyId); if (model != null) { //考勤编号 this.attentID.Value = model.AttendanceId; //考勤类型 this.attType.Value = ((int)model.AttendanceType).ToString(); //部门编号 this.deptID.Value = model.DeptId.ToString(); //员工编号 this.staffID.Value = model.StaffId; //开始时间 this.sTime.Value = model.StartTime.HasValue ? model.StartTime.Value.ToString("yyyy-MM-dd HH:mm") : ""; //结束时间 this.eTime.Value = model.EndTime.HasValue ? model.EndTime.Value.ToString("yyyy-MM-dd HH:mm") : ""; //考勤时间 this.tbtime.Text = model.AttendanceTime.HasValue ? model.AttendanceTime.Value.ToString("yyyy-MM-dd") : ""; //原因 this.subject.Value = model.Subject; } } else //考勤登记 { //员工编号 string id = Utils.GetQueryStringValue("id"); //员工部门编号 string deptid = Utils.GetQueryStringValue("deptid"); //考勤默认时间为当前日期 this.tbtime.Text = string.Format("{0:yyyy-MM-dd}", DateTime.Now); this.deptID.Value = deptid; this.staffID.Value = id; } }
/// <summary> /// 保存按钮点击事件执行方法 /// </summary> protected void PageSave(string id) { //数据验证开始 StringBuilder strMsg = new StringBuilder(); if (String.IsNullOrEmpty(this.txtTime.Value)) { strMsg.Append("考勤时间不能为空!\\n"); } if (!this.ckChiDao.Checked && !this.ckKuangGong.Checked && !this.ckZaoTui.Checked && !this.ckZuiDian.Checked && !this.ckLeave.Checked && !this.ckAdd.Checked) { strMsg.Append("考勤类型必须选择!\\n"); } if (this.ckLeave.Checked) { if (String.IsNullOrEmpty(this.txtLeaveStartTime.Value) || String.IsNullOrEmpty(this.txtLeaveEndTime.Value)) { strMsg.Append("请假时间不能为空!\\n"); } else { if (Convert.ToDateTime(this.txtLeaveEndTime.Value).Subtract(Convert.ToDateTime(this.txtLeaveStartTime.Value)).Ticks < 0) { strMsg.Append("请假结束时间不能早于开始时间!\\n"); } } } if (this.ckAdd.Checked) { if (String.IsNullOrEmpty(this.txtAddEndTime.Value) || String.IsNullOrEmpty(this.txtAddStartTime.Value)) { strMsg.Append("加班时间不能为空!\\n"); } else { if (Convert.ToDateTime(this.txtAddEndTime.Value).Subtract(Convert.ToDateTime(this.txtAddStartTime.Value)).Ticks < 0) { strMsg.Append("加班结束时间不能早于开始时间!\\n"); } } } if (strMsg.Length > 0) { MessageBox.ResponseScript(this, String.Format("alert('{0}');", strMsg)); return; } //数据验证结束 EyouSoft.BLL.GovStructure.BAttendance BLL = new EyouSoft.BLL.GovStructure.BAttendance(); List <EyouSoft.Model.GovStructure.MGovAttendance> lst = new List <EyouSoft.Model.GovStructure.MGovAttendance>(); String workStart = "08:00"; //工作时间(始) String workEnd = "18:00"; //工作时间(终) foreach (Control c in this.form1.Controls) { if (c.GetType().ToString().Equals("System.Web.UI.HtmlControls.HtmlInputCheckBox")) { System.Web.UI.HtmlControls.HtmlInputCheckBox ck = (System.Web.UI.HtmlControls.HtmlInputCheckBox)c; if (ck.Checked) { if (ck == this.ckLeave)//请假 { DateTime?leaveStartTime = Utils.GetDateTimeNullable(this.txtLeaveStartTime.Value); DateTime?leaveEndTime = Utils.GetDateTimeNullable(this.txtLeaveEndTime.Value); if (null != leaveStartTime && null != leaveEndTime) { this.getDays(leaveStartTime.ToString(), leaveEndTime.ToString(), workStart, workEnd, lst, ck, id); } } else if (ck == this.ckAdd)//加班 { DateTime?addStartTime = Utils.GetDateTimeNullable(this.txtAddStartTime.Value); DateTime?addEndTime = Utils.GetDateTimeNullable(this.txtAddEndTime.Value); if (null != addStartTime && null != addEndTime) { this.getDays(addStartTime.ToString(), addEndTime.ToString(), workStart, workEnd, lst, ck, id); } } else { //检查是否已经登记过考勤 if (BLL.ExistsNum(this.SiteUserInfo.CompanyId, id, Convert.ToDateTime(this.txtTime.Value), (AttendanceType)Utils.GetInt(ck.Value), "")) { MessageBox.ResponseScript(this, "alert('抱歉, 该用户的考勤已经登记过了!');"); return; } MGovAttendance Model = new MGovAttendance(); this.commonModel(Model, id, ck, Convert.ToDateTime(this.txtTime.Value)); lst.Add(Model); } } } } bool result = BLL.AddAllGovAttendanceList(lst); if (result) { Utils.ShowMsgAndCloseBoxy("登记成功!", Utils.GetQueryStringValue("IframeId"), true); } else { EyouSoft.Common.Function.MessageBox.ResponseScript(this, "alert('登记失败!');"); } }
/// <summary> /// 时间分段 /// </summary> /// <param name="start">开始时间</param> /// <param name="end">结束时间</param> /// <param name="workStart">工作时间(始)</param> /// <param name="workEnd">工作时间(终)</param> protected void getDays(String start, String end, String workStart, String workEnd, List <MGovAttendance> lst, HtmlInputCheckBox ck, String id) { MGovAttendance Model; DateTime dtStart = Convert.ToDateTime(start); DateTime dtEnd = Convert.ToDateTime(end); DateTime oldStartDay = Convert.ToDateTime(dtStart.ToShortDateString()); DateTime oldEndDay = Convert.ToDateTime(dtEnd.ToShortDateString()); String oldStartStr = Convert.ToDateTime(start).ToShortTimeString(); String oldEndStr = Convert.ToDateTime(end).ToShortTimeString(); String newStartStr = workStart; //如:"08:00" 工作时间(始) String newEndStr = workEnd; //如:"18:00" 工作时间(终) String[] oldStart = oldStartStr.Split(':'); String[] oldEnd = oldEndStr.Split(':'); String[] newStart = newStartStr.Split(':'); String[] newEnd = newEndStr.Split(':'); int oldStartSec = Utils.GetInt(oldStart[0]) * 3600 + Utils.GetInt(oldStart[1]) * 60; int oldEndSec = Utils.GetInt(oldEnd[0]) * 3600 + Utils.GetInt(oldEnd[1]) * 60; int newStartSec = Utils.GetInt(newStart[0]) * 3600 + Utils.GetInt(newStart[1]) * 60; int newEndSec = Utils.GetInt(newEnd[0]) * 3600 + Utils.GetInt(newEnd[1]) * 60; //2011-10-25 邵:按8:00-18:00拆分 if (String.Equals(oldStartDay, oldEndDay)) { //开始日期和结束日期是同一天 Model = new MGovAttendance(); String strStart = (oldStartSec > newStartSec) ? oldStartStr : newStartStr; String strEnd = (oldEndSec > newEndSec) ? newEndStr : oldEndStr; this.commonModel(Model, id, ck, dtStart); Model.StartTime = Utils.GetDateTimeNullable(String.Format("{0} {1}", String.Format("{0:yyyy-MM-dd}", oldStartDay), strStart)); Model.EndTime = Utils.GetDateTimeNullable(String.Format("{0} {1}", String.Format("{0:yyyy-MM-dd}", oldEndDay), strEnd)); decimal timecouts = Convert.ToDecimal(Math.Round(Convert.ToDateTime(Model.EndTime).Subtract(Convert.ToDateTime(Model.StartTime)).TotalSeconds / ((newEndSec - newStartSec) * 1.0), 1)); if (ck == this.ckAdd) { Model.TimeCount = timecouts * 24;//加班是按小时算 } else { Model.TimeCount = timecouts;//请假是按天算 } lst.Add(Model); } else { //开始日期和结束日期不是同一天,且结束日期大于开始日期(数据验证中有验证) int span = oldEndDay.Subtract(oldStartDay).Days; DateTime dt = oldStartDay; String strStart = (oldStartSec > newStartSec) ? oldStartStr : newStartStr; String strEnd = (oldEndSec > newEndSec) ? newEndStr : oldEndStr; String st = String.Empty; String se = String.Empty; for (int i = 0; i <= span; i++) { Model = new MGovAttendance(); this.commonModel(Model, id, ck, dt); st = i == 0 ? strStart : newStartStr; se = i == span ? strEnd : newEndStr; Model.StartTime = Utils.GetDateTimeNullable(String.Format("{0} {1}", String.Format("{0:yyyy-MM-dd}", dt), st)); Model.EndTime = Utils.GetDateTimeNullable(String.Format("{0} {1}", String.Format("{0:yyyy-MM-dd}", dt), se)); decimal timecouts = Convert.ToDecimal(Math.Round(Convert.ToDateTime(Model.EndTime).Subtract(Convert.ToDateTime(Model.StartTime)).TotalSeconds / ((newEndSec - newStartSec) * 1.0), 1)); if (ck == this.ckAdd) { Model.TimeCount = timecouts * 24;//加班是按小时算 } else { Model.TimeCount = timecouts;//请假是按天算 } lst.Add(Model); dt = dt.AddDays(1); } } }
/// <summary> /// 保存 /// </summary> protected void PageSave() { #region 表单取值 string atttype = Utils.GetFormValue(attType.UniqueID); string stime = Utils.GetFormValue(tbStime.UniqueID); string etime = Utils.GetFormValue(tbEtime.UniqueID); string sub = Utils.GetFormValue(subject.UniqueID); string ids = Utils.GetFormValue(hdattenIds.UniqueID); string names = Utils.GetFormValue(hdattenNames.UniqueID); string depts = Utils.GetFormValue(hdattenDepts.UniqueID); string timecount = Utils.GetFormValue(timeCount.UniqueID); #endregion #region 表单验证 string msg = string.Empty; if (string.IsNullOrEmpty(stime)) { msg += "请选择考勤开始时间!"; } if (string.IsNullOrEmpty(etime)) { msg += "请选择考勤结束时间!"; } if (string.IsNullOrEmpty(sub) && Utils.GetInt(atttype, 0) > 0) { msg += "请输入原因!"; } if (!string.IsNullOrEmpty(msg)) { Response.Clear(); Response.Write(UtilsCommons.AjaxReturnJson("0", msg)); Response.End(); } #endregion #region 实体赋值 //时间 TimeSpan ts = new TimeSpan(Utils.GetDateTime(stime).Ticks); TimeSpan te = new TimeSpan(Utils.GetDateTime(etime).Ticks); TimeSpan total = ts.Subtract(te).Duration(); IList <MGovAttendance> list = new List <MGovAttendance>(); string[] arryIds = ids.Split(','); string[] arryNames = names.Split('、'); string[] arryDepts = depts.Split(','); if (arryIds.Length == arryNames.Length && arryIds.Length == arryDepts.Length) { //小于一天 if (total.Days == 0) { for (int i = 0; i < arryIds.Length; i++) { MGovAttendance model = new MGovAttendance(); model.StaffId = arryIds[i]; model.CompanyId = this.SiteUserInfo.CompanyId; model.DeptId = Utils.GetInt(arryDepts[i]); model.OperatorId = this.SiteUserInfo.UserId; model.AttendanceType = (AttendanceType)(Utils.GetInt(atttype)); model.StartTime = Utils.GetDateTimeNullable(stime); model.AttendanceTime = Utils.GetDateTimeNullable(stime); model.EndTime = Utils.GetDateTimeNullable(etime); model.Subject = sub; model.TimeCount = string.IsNullOrEmpty(timecount) ? 1 : Utils.GetDecimal(timecount);; model.IssueTime = DateTime.Now; model.OperatorId = this.SiteUserInfo.UserId; list.Add(model); } } else { //大于一天 for (int j = 0; j < total.Days; j++) { for (int i = 0; i < arryIds.Length; i++) { MGovAttendance model = new MGovAttendance(); model.StaffId = arryIds[i]; model.CompanyId = this.SiteUserInfo.CompanyId; model.DeptId = Utils.GetInt(arryDepts[i]); model.OperatorId = this.SiteUserInfo.UserId; model.AttendanceType = (AttendanceType)(Utils.GetInt(atttype)); model.AttendanceTime = Utils.GetDateTime(stime).AddDays(j); model.StartTime = Utils.GetDateTime(stime).AddDays(j); model.EndTime = Utils.GetDateTime(etime).AddDays(-total.Days + j); model.Subject = sub; model.TimeCount = (AttendanceType)(Utils.GetInt(atttype, 0)) == AttendanceType.加班 ? Utils.GetDecimal(timecount) : 1;; model.IssueTime = DateTime.Now; model.OperatorId = this.SiteUserInfo.UserId; list.Add(model); } } //多出的小时数 if (total.Hours > 0) { for (int i = 0; i < arryIds.Length; i++) { MGovAttendance model = new MGovAttendance(); model.StaffId = arryIds[i]; model.CompanyId = this.SiteUserInfo.CompanyId; model.DeptId = Utils.GetInt(arryDepts[i]); model.OperatorId = this.SiteUserInfo.UserId; model.AttendanceType = (AttendanceType)(Utils.GetInt(atttype)); model.AttendanceTime = Utils.GetDateTime(stime).AddDays(total.Days); model.StartTime = Utils.GetDateTime(stime).AddDays(total.Days); model.EndTime = Utils.GetDateTimeNullable(etime); model.Subject = sub; model.TimeCount = (AttendanceType)(Utils.GetInt(atttype, 0)) == AttendanceType.加班 ? Utils.GetDecimal(timecount) : 1;; model.IssueTime = DateTime.Now; model.OperatorId = this.SiteUserInfo.UserId; list.Add(model); } } } } #endregion #region 提交验证 EyouSoft.BLL.GovStructure.BAttendance BLL = new EyouSoft.BLL.GovStructure.BAttendance(); bool result = BLL.AddAllGovAttendanceList(list); msg = result ? "批量考勤成功!" : "批量考勤失败!"; Response.Clear(); Response.Write(UtilsCommons.AjaxReturnJson(result ? "1" : "0", msg)); Response.End(); #endregion }
/// <summary> /// 保存 /// <param name="id">考勤ID</param> /// </summary> protected void PageSave(string doType) { #region 表单取值 //考勤编号 string attid = Utils.GetFormValue(this.attentID.UniqueID); //员工编号 string staffid = Utils.GetFormValue(this.staffID.UniqueID); //部门编号 string deptid = Utils.GetFormValue(this.deptID.UniqueID); //考勤时间 string atttime = Utils.GetFormValue(this.tbtime.UniqueID); //考勤类型 string atttype = Utils.GetFormValue(this.attType.UniqueID); //开始时间 string stime = Utils.GetFormValue(this.sTime.UniqueID); //结束时间 string etime = Utils.GetFormValue(this.eTime.UniqueID); //天数/时数 string count = Utils.GetFormValue(this.timeCount.UniqueID); //理由 string sub = Utils.GetFormValue(this.subject.UniqueID); #endregion #region 表单验证 string msg = string.Empty; if (string.IsNullOrEmpty(atttime) && Utils.GetInt(atttype, 0) < 4) { msg += "请选择考勤时间!<br/>"; } if (string.IsNullOrEmpty(stime) && Utils.GetInt(atttype, 0) > 3) { msg += "请选择开始时间!<br/>"; } if (string.IsNullOrEmpty(etime) && Utils.GetInt(atttype, 0) > 3) { msg += "请选择结束时间!<br/>"; } if (string.IsNullOrEmpty(sub) && Utils.GetInt(atttype, 0) > 0) { msg += "请输入原因!<br/>"; } if (!string.IsNullOrEmpty(msg)) { Response.Clear(); Response.Write(UtilsCommons.AjaxReturnJson("0", msg)); Response.End(); } #endregion #region 实体赋值 IList <MGovAttendance> list = new List <MGovAttendance>(); TimeSpan ts = new TimeSpan(Utils.GetDateTime(stime).Ticks); TimeSpan te = new TimeSpan(Utils.GetDateTime(etime).Ticks); TimeSpan total = ts.Subtract(te).Duration(); //时间不超过一天 if (total.Days == 0) { MGovAttendance model = new MGovAttendance(); model.AttendanceId = attid; model.AttendanceTime = string.IsNullOrEmpty(stime) ? Utils.GetDateTimeNullable(atttime) : Utils.GetDateTimeNullable(stime); model.AttendanceType = (AttendanceType)(Utils.GetInt(atttype, 0)); model.CompanyId = this.SiteUserInfo.CompanyId; model.DeptId = Utils.GetInt(deptid); model.EndTime = string.IsNullOrEmpty(etime) ? Utils.GetDateTimeNullable(atttime) : Utils.GetDateTimeNullable(etime); model.IssueTime = DateTime.Now; model.OperatorId = this.SiteUserInfo.UserId; model.StaffId = staffid; model.StartTime = string.IsNullOrEmpty(stime) ? Utils.GetDateTimeNullable(atttime) : Utils.GetDateTimeNullable(stime); model.Subject = sub; //全、迟、退、旷工 算一天 其他的用户自己填 model.TimeCount = string.IsNullOrEmpty(count) ? 1 : Utils.GetDecimal(count); //total.Hours > 4 ? 1 : Utils.GetDecimal("0.5"); list.Add(model); } else//时间超过一天 { for (int i = 0; i < total.Days; i++) { MGovAttendance model = new MGovAttendance(); model.AttendanceId = attid; model.AttendanceTime = Utils.GetDateTime(stime).AddDays(i); model.AttendanceType = (AttendanceType)(Utils.GetInt(atttype, 0)); model.CompanyId = this.SiteUserInfo.CompanyId; model.DeptId = Utils.GetInt(deptid); model.EndTime = Utils.GetDateTime(etime).AddDays(-total.Days + i); model.IssueTime = DateTime.Now; model.OperatorId = this.SiteUserInfo.UserId; model.StaffId = staffid; model.StartTime = Utils.GetDateTime(stime).AddDays(i); model.Subject = sub; model.TimeCount = (AttendanceType)(Utils.GetInt(atttype, 0)) == AttendanceType.加班 ? Utils.GetDecimal(count) : 1; list.Add(model); } if (total.Hours > 0) { MGovAttendance model = new MGovAttendance(); model.AttendanceId = attid; model.AttendanceTime = Utils.GetDateTime(stime).AddDays(total.Days); model.AttendanceType = (AttendanceType)(Utils.GetInt(atttype, 0)); model.CompanyId = this.SiteUserInfo.CompanyId; model.DeptId = Utils.GetInt(deptid); model.EndTime = Utils.GetDateTime(etime); model.IssueTime = DateTime.Now; model.OperatorId = this.SiteUserInfo.UserId; model.StaffId = staffid; model.StartTime = Utils.GetDateTime(stime).AddDays(total.Days); model.Subject = sub; model.TimeCount = (AttendanceType)(Utils.GetInt(atttype, 0)) == AttendanceType.加班 ? Utils.GetDecimal(count) : 1; list.Add(model); } } #endregion #region 提交保存 BAttendance BLL = new BAttendance(); bool result = BLL.UpdateGovAttendance(Utils.GetFormValue(staffID.UniqueID), this.SiteUserInfo.CompanyId, list); msg = result ? "提交保存成功!" : "提交保存失败"; Response.Clear(); Response.Write(UtilsCommons.AjaxReturnJson(result ? "1" : "0", msg)); Response.End(); #endregion }