/// <summary> /// 页面初始化 /// </summary> /// <param name="id">操作ID</param> protected void PageInit() { string txtNum = Utils.GetQueryStringValue("txtNum"); string txtName = Utils.GetQueryStringValue("txtName"); string sectionID = Utils.GetQueryStringValue(this.SelectSection1.SelectIDClient); string sectionName = Utils.GetQueryStringValue(this.SelectSection1.SelectNameClient); this.SelectSection1.SectionName = sectionName; this.SelectSection1.SectionID = sectionID; BAttendance BLL = new BAttendance(); MSearchInfo Model = new MSearchInfo(); if (!string.IsNullOrEmpty(sectionID)) { Model.DepartIds = sectionID; } Model.DepartName = sectionName; Model.FileNumber = txtNum; Model.Month = month; Model.StaffName = txtName; Model.Year = year; IList <MGovAttendanceList> lst = BLL.GetList(this.SiteUserInfo.CompanyId, Model); if (null != lst && lst.Count > 0) { this.RepList.DataSource = lst; this.RepList.DataBind(); this.ExporPageInfoSelect2.intRecordCount = lst.Count; } }
/// <summary> /// 初始化 /// </summary> private void DataInit(String id) { //查询参数 int selYear = Utils.GetInt(Utils.GetQueryStringValue("selYear")); //年 int selMonth = Utils.GetInt(Utils.GetQueryStringValue("selMonth")); //月 //绑定表格数据 if (selYear >= 1 && selYear <= 9999 && selMonth >= 1 && selMonth <= 12) { //统计信息 BAttendance attBLL = new BAttendance(); MAttendanceAbout attModel = attBLL.GetAttendanceAbout(this.SiteUserInfo.CompanyId, id, selYear, selMonth); if (null != attModel) { this.lbAttInfo.Text = string.Format("准点<strong class=\"red\">{0}</strong>天,迟到<strong class=\"red\">{1}</strong>天,早退<strong class=\"red\">{2}</strong>天,旷工<strong class=\"red\">{3}</strong>天,请假<strong class=\"red\">{4}</strong>天,加班<strong class=\"red\">{5}</strong>小时", attModel.Punctuality, attModel.Late, attModel.LeaveEarly, attModel.Absenteeism, Math.Round(attModel.Vacation, 1), Math.Round(attModel.OverTime, 1)); } //表头编号 List <string> lstDays = new List <string>(); for (int i = 0; i < DateTime.DaysInMonth(selYear, selMonth); i++) { lstDays.Add(i.ToString()); } this.RepDateList.DataSource = lstDays; this.RepDateList.DataBind(); //考勤状况 this.RepList.DataSource = lstDays; this.RepList.DataBind(); } }
/// <summary> /// 生成单元格(包括日期和考勤情况信息) /// </summary> /// <param name="i">当月几号</param> /// <returns></returns> protected string getUnit(int i) { Dictionary <EyouSoft.Model.EnumType.GovStructure.AttendanceType, string> dic = new Dictionary <EyouSoft.Model.EnumType.GovStructure.AttendanceType, string>(); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.迟到, "class=\"rl-red\""); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.出差, "class=\"rl-perpel\""); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.加班, "class=\"rl-blue\""); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.旷工, "class=\"rl-yellow\""); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.请假, "class=\"rl-gray\""); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.停职, "class=\"rl-skyblue\""); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.休假, "class=\"rl-lime\""); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.早退, "class=\"rl-green\""); DateTime dtCurrent = Convert.ToDateTime(string.Format("{0}{1}", string.Format("{0:yyyy-MM-}", dt), i < 10 ? "0" + i.ToString() : i.ToString())); BAttendance BLL = new BAttendance(); IList <MGovAttendance> lst = BLL.GetList(this.SiteUserInfo.CompanyId, Utils.GetQueryStringValue("id"), dtCurrent); string classStr = string.Empty; string type = string.Empty; StringBuilder strInfo = new StringBuilder(); string id = Utils.GetQueryStringValue("id"); if (null != lst && lst.Count > 0) { foreach (MGovAttendance m in lst) { if (m.AttendanceType != AttendanceType.全勤) { classStr = dic[m.AttendanceType]; } if (m.AttendanceType == AttendanceType.全勤) { strInfo.AppendFormat("<a href='AttDetail.aspx?doType=update&attID={0}&date={2}&sl={3}' data-class='attDetail'>{1}</a>", m.AttendanceId, m.AttendanceType.ToString(), string.Format("{0:yyyy-MM-dd}", dtCurrent), Utils.GetQueryStringValue("sl")); } else { bool flag = m.AttendanceType == EyouSoft.Model.EnumType.GovStructure.AttendanceType.加班; strInfo.AppendFormat("<a href='AttDetail.aspx?doType=update&attID={1}&date={2}&sl={3}' class='attendBt' data-class='attDetail'>{0}</a>", m.AttendanceType.ToString(), m.AttendanceId, string.Format("{0:yyyy-MM-dd}", dtCurrent), Utils.GetQueryStringValue("sl")); strInfo.AppendFormat("<div style='display: none'>"); strInfo.AppendFormat("<table cellspacing='0' cellpadding='0' border='0' width='100%'><tr>"); strInfo.AppendFormat("<td height='23' align='right'>考勤时间:</td>"); strInfo.AppendFormat("<td align='left'>{0}</td></tr>", string.Format("{0:yyyy-MM-dd}", m.AttendanceTime)); strInfo.AppendFormat("<tr><th align='right' valign='top'>考勤情况:</th>"); strInfo.AppendFormat("<td>{0}时间:{1}至{2} {0}{3}:", m.AttendanceType.ToString(), string.Format("{0:yyyy-MM-dd HH:mm}", m.StartTime), string.Format("{0:yyyy-MM-dd HH:mm}", m.EndTime), flag ? "时数" : "天数"); strInfo.AppendFormat("<strong class='fontred'>{0}{1}</strong>", string.Format("({0})", Math.Round(m.TimeCount, 1)), flag ? "小时" : "天"); strInfo.AppendFormat(" <p>{0}原因:{1}</p></td></tr></table></div> ", m.AttendanceType.ToString(), m.Subject); } } } return(string.Format("<li {0}><p> {1} </p><p> {2} </p></li>", classStr, i < 10 ? "0" + i.ToString() : i.ToString(), strInfo.ToString())); }
/// <summary> /// 页面初始化 /// </summary> /// <param name="id">操作ID</param> protected void PageInit(string id) { BAttendance BLL = new BAttendance(); //统计信息(当月考勤情况) if (!string.IsNullOrEmpty(id)) { EyouSoft.Model.GovStructure.MAttendanceAbout m = BLL.GetAttendanceAbout(this.SiteUserInfo.CompanyId, id, dt.Year, dt.Month); if (m != null) { this.lbAttInfo.Text = string.Format("全勤<strong class=\"red\">{0}</strong>天,迟到<strong class=\"red\">{1}</strong>天,早退<strong class=\"red\">{2}</strong>天,旷工<strong class=\"red\">{3}</strong>天,请假<strong class=\"red\">{4}</strong>天,加班<strong class=\"red\">{5}</strong>小时,停职<strong class=\"red\">{6}</strong>天,出差<strong class=\"red\">{7}</strong>天,休假<strong class=\"red\">{8}</strong>天", m.Punctuality, m.Late, m.LeaveEarly, m.Absenteeism, Math.Round(m.Vacation, 1), Math.Round(m.OverTime, 1), Math.Round(m.Suspension, 1), Math.Round(m.Travel, 1), Math.Round(m.Rest, 1)); } } }
/// <summary> /// 生成单元格(包括日期和考勤情况信息) /// </summary> /// <param name="i">当月几号</param> /// <returns></returns> protected string getUnit(int i) { int selYear = Utils.GetInt(Utils.GetQueryStringValue("selYear")); //年 int selMonth = Utils.GetInt(Utils.GetQueryStringValue("selMonth")); //月 DateTime dtCurrent = Convert.ToDateTime(String.Format("{0}-{1}-{2}", selYear, selMonth, i)); BAttendance BLL = new BAttendance(); IList <MGovAttendance> lst = BLL.GetList(this.SiteUserInfo.CompanyId, Utils.GetQueryStringValue("id"), dtCurrent); String type = String.Empty; StringBuilder strInfo = new StringBuilder(); if (null != lst && lst.Count > 0) { foreach (MGovAttendance m in lst) { strInfo.Append(m.AttendanceType); } } return(strInfo.ToString()); }
/// <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> /// <param name="id">用户ID</param> /// <returns></returns> protected String getTables(object AttendanceList) { StringBuilder str = new StringBuilder(); BAttendance BLL = new BAttendance(); IList <MGovAttendance> lst = (List <MGovAttendance>)AttendanceList; Dictionary <EyouSoft.Model.EnumType.GovStructure.AttendanceType, string> dic = new Dictionary <EyouSoft.Model.EnumType.GovStructure.AttendanceType, string>(); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.迟到, "<font color='#FF0000'><strong>迟</strong></font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.出差, "<font color='#800080'><strong>差</strong></font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.加班, "<font color='#0000FF'><strong>加</strong></font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.旷工, "<font color='#6600CC'><strong>旷</strong></font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.请假, "<font color='#FFA500'><strong>请</strong></font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.全勤, "<font color='#A9A9A9'>准</font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.停职, "<font color='#00BFFF'><strong>停</strong></font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.休假, "<font color='#00FF00'><strong>休</strong></font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.早退, "<font color='#008000'><strong>退</strong></font>"); for (int i = 0; i < DateTime.DaysInMonth(year, month); i++) { if (null != lst && lst.Count > 0) { StringBuilder s = new StringBuilder(); DateTime dtCurrent = Convert.ToDateTime(String.Format("{0}-{1}-{2}", year, month, i + 1)); var slst = (lst.Where(item => (item.AttendanceTime.Value.Date == dtCurrent))); if (slst != null && slst.ToList().Count > 0) { str.Append(string.Format("<td>{0}</td>", dic[slst.ToList().First().AttendanceType])); } else { str.Append(string.Format("<td></td>")); } } else { str.Append(String.Format("<td></td>")); } } return(str.ToString()); }
/// <summary> /// 导出 /// </summary> void ToXls() { int toXlsRecordCount = UtilsCommons.GetToXlsRecordCount(); if (toXlsRecordCount < 1) { ResponseToXls(string.Empty); } StringBuilder str = new StringBuilder(); string txtNum = Utils.GetQueryStringValue("txtNum"); string txtName = Utils.GetQueryStringValue("txtName"); string sectionID = Utils.GetQueryStringValue(this.SelectSection1.SelectIDClient); string sectionName = Utils.GetQueryStringValue(this.SelectSection1.SelectNameClient); BAttendance BLL = new BAttendance(); MSearchInfo Model = new MSearchInfo(); if (!string.IsNullOrEmpty(sectionID)) { Model.DepartIds = sectionID; } Model.DepartName = sectionName; Model.FileNumber = txtNum; Model.Month = month; Model.StaffName = txtName; Model.Year = year; IList <MGovAttendanceList> data = BLL.GetList(this.SiteUserInfo.CompanyId, Model); //加载表头 str.AppendFormat("<meta http-equiv=\"content-type\" content=\"application/ms-excel; charset=UTF-8\"/><table border='1' style='border-collapse:collapse;'><tr><th width='105'>员工编号" + "</th><th width='105'>部门</th><th width='107'>姓名</th>"); //循环读取当前月的天数 int days = DateTime.DaysInMonth(year, month); for (int i = 0; i < days; i++) { str.AppendFormat("<th>{0}</th>", i + 1); } str.AppendFormat("</tr>"); //查询出来的数据读取 if (data != null && data.Count > 0) { Dictionary <EyouSoft.Model.EnumType.GovStructure.AttendanceType, string> dic = new Dictionary <EyouSoft.Model.EnumType.GovStructure.AttendanceType, string>(); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.迟到, "<font color='#FF0000'><strong>迟</strong></font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.出差, "<font color='#800080'><strong>差</strong></font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.加班, "<font color='#0000FF'><strong>加</strong></font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.旷工, "<font color='#6600CC'><strong>旷</strong></font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.请假, "<font color='#FFA500'><strong>请</strong></font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.全勤, "<font color='#A9A9A9'>准</font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.停职, "<font color='#00BFFF'><strong>停</strong></font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.休假, "<font color='#00FF00'><strong>休</strong></font>"); dic.Add(EyouSoft.Model.EnumType.GovStructure.AttendanceType.早退, "<font color='#008000'><strong>退</strong></font>"); for (int i = 0; i < data.Count; i++) { str.AppendFormat("<tr><td align='center' style='vnd.ms-excel.numberformat:@'>{0}</td><td align='center'>{1}</td><td align='center'>{2}</td>", data[i].FileNumber, data[i].DepartName, data[i].Name); for (int j = 0; j < days; j++) { DateTime dtCurrent = Convert.ToDateTime(String.Format("{0}-{1}-{2}", year, month, j + 1)); if (data[i].AttendanceList != null && data[i].AttendanceList.Count > 0) { IList <MGovAttendance> list = data[i].AttendanceList.Where(a => (a.AttendanceTime.Value.Date == dtCurrent)).ToList(); if (list != null && list.Count > 0) { str.AppendFormat("<td>{0}</td>", dic[list.First().AttendanceType]); } else { str.Append("<td></td>"); } } else { str.Append("<td></td>"); } } str.Append("</tr>"); } } str.AppendFormat("</table>"); string browser = this.Context.Request.UserAgent.ToUpper(); String fileName = "考勤汇总信息.xls"; if (browser.Contains("MS") && browser.Contains("IE")) { fileName = System.Web.HttpUtility.UrlEncode(fileName, Encoding.UTF8); } ResponseToXls(str.ToString(), Encoding.UTF8, fileName); }
/// <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 }