コード例 #1
0
        /// <summary>
        /// 出勤查询Json
        /// </summary>
        /// <returns></returns>
        public ActionResult getHHUCheckINCountJson()
        {
            HUCheckINCount_SW sw = new HUCheckINCount_SW();

            sw.ORGNO     = Request.Params["BYORGNO"];
            sw.DateBegin = Request.Params["TIMEBegin"];
            sw.DateEnd   = Request.Params["TIMEEnd"];
            var list = HUCheckCls.getCheckInModel(sw);

            StringBuilder sb   = new StringBuilder();
            DateTime      dt1  = Convert.ToDateTime(sw.DateBegin);
            DateTime      dt2  = Convert.ToDateTime(sw.DateEnd);
            int           days = ClsStr.getDateDiff(sw.DateBegin, sw.DateEnd) + 1;//日期包含天数

            sb.AppendFormat("<table cellpadding=\"0\" cellspacing=\"0\">");
            sb.AppendFormat("<thead>");
            sb.AppendFormat("    <tr>");
            sb.AppendFormat("        <th rowspan=\"2\">单位<br>(姓名)</th>");
            sb.AppendFormat("        <th rowspan=\"2\">考勤<br>人数</th>");
            sb.AppendFormat("        <th colspan=\"{1}\">{0}</th>", "日期(日)", days.ToString());
            sb.AppendFormat("        <th rowspan=\"2\">总出勤<br>(天数)</th>");
            sb.AppendFormat("        <th rowspan=\"2\">已出勤<br>(天数)</th>");
            sb.AppendFormat("        <th rowspan=\"2\">出勤率</th>");
            sb.AppendFormat("    </tr>");
            sb.AppendFormat("    <tr>");
            for (DateTime tm = dt1; tm <= dt2; tm = tm.AddDays(1))
            {
                sb.AppendFormat("        <th>{0}</th>", tm.ToString("dd"));
            }
            sb.AppendFormat("    </tr>");
            sb.AppendFormat("</thead>");
            sb.AppendFormat("<tbody>");
            //var list = HUCheckCls.getCheckInModel(new HUCheckINCount_SW { DateBegin = arr[1], DateEnd = arr[2], ORGNO = arr[0], HUNM = arr[3] });
            int j = 0;

            foreach (var v in list)
            {
                j++;
                string orgName = v.ORGName;
                string orgNo   = v.ORGNo;
                if (j % 2 == 0)
                {
                    sb.AppendFormat("<tr>");
                }
                else
                {
                    sb.AppendFormat("<tr class='row1'>");
                }
                sb.AppendFormat("<td class=\"center\">{0}</td>", v.ORGName);
                sb.AppendFormat("<td class=\"center\">{0}</td>", v.HUCount);//总
                string[] arr1 = v.DayCountList.Split(',');
                for (int i = 0; i < days; i++)
                {
                    sb.AppendFormat("<td class=\"center\">{0}</td>", arr1[i]);
                }
                sb.AppendFormat("<td class=\"center\">{0}</td>", v.daysC);   //总
                sb.AppendFormat("<td class=\"center\">{0}</td>", v.daysOK);  //完成
                sb.AppendFormat("<td class=\"center\">{0}</td>", v.daysPer); //完成率
                sb.AppendFormat("</tr>");
            }
            sb.AppendFormat("</tbody>");
            sb.AppendFormat("</table>");

            return(Content(JsonConvert.SerializeObject(new Message(true, sb.ToString(), "")), "text/html;charset=UTF-8"));
        }
コード例 #2
0
        /// <summary>
        /// 考勤统计 Model
        /// </summary>
        /// <param name="sw">参见HUCheckINCount_SW</param>
        /// <returns>参见HUCheck_CheckInCount_Model</returns>
        public static IEnumerable <HUCheck_CheckInCount_Model> getCheckInModel(HUCheckINCount_SW sw)
        {
            var result = new List <HUCheck_CheckInCount_Model>();

            if (string.IsNullOrEmpty(sw.DateBegin))//开始时间为空
            {
                return(result);
            }
            if (string.IsNullOrEmpty(sw.DateEnd))//结束时间为空
            {
                return(result);
            }
            if (string.IsNullOrEmpty(sw.ORGNO))//组织机构编码
            {
                return(result);
            }

            DateTime dt1  = Convert.ToDateTime(sw.DateBegin);
            DateTime dt2  = Convert.ToDateTime(sw.DateEnd);
            int      days = ClsStr.getDateDiff(sw.DateBegin, sw.DateEnd) + 1;//日期包含天数

            //根据机构编码获取下属组织机构 注意:这个函数含本级及所有下级的
            //DataTable dtOrg = BaseDT.T_SYS_ORG.getDT(new T_SYS_ORGSW { TopORGNO = sw.ORGNO });
            DataTable dtHRRealData = BaseDT.T_IPS_REALDATATEMPORARY.getDTByOrgNoToDate(new PatrolRouteStat_SW {
                DateBegin = sw.DateBegin, DateEnd = sw.DateEnd, TopORGNO = sw.ORGNO
            });

            DataTable dtHU = BaseDT.T_IPSFR_USER.getDTByOrgSum(new T_IPSFR_USER_SW {
                BYORGNO = sw.ORGNO, ISENABLE = "1"
            });

            if (PublicCls.OrgIsZhen(sw.ORGNO) == false) //市、县处理
            {                                           //只获取该市下面的县 县下面的乡
                T_SYS_ORGSW swOrg = new T_SYS_ORGSW();
                swOrg.SYSFLAG  = ConfigCls.getSystemFlag();
                swOrg.TopORGNO = sw.ORGNO;

                if (PublicCls.OrgIsShi(sw.ORGNO))
                {
                    swOrg.GetContyORGNOByCity = sw.ORGNO;//获取所有县
                }
                if (PublicCls.OrgIsXian(sw.ORGNO))
                {
                    swOrg.GetXZOrgNOByConty = sw.ORGNO;//获取所有镇
                }
                DataTable dtOrg = BaseDT.T_SYS_ORG.getDT(swOrg);
                DataRow[] drOrg = dtOrg.Select("", "ORGNO");//取所有

                for (int i = 0; i < drOrg.Length; i++)
                {
                    HUCheck_CheckInCount_Model m = new HUCheck_CheckInCount_Model();


                    m.ORGName = drOrg[i]["ORGNAME"].ToString();
                    m.ORGNo   = drOrg[i]["ORGNO"].ToString();
                    string CHr = dtHU.Compute("sum(C)", "BYORGNO=" + m.ORGNo).ToString(); //计算该单位下总人数
                    CHr       = (string.IsNullOrEmpty(CHr) ? "0" : CHr);
                    m.HUCount = CHr;                                                      //考勤人数
                    string cList = "";
                    for (DateTime tm = dt1; tm <= dt2; tm = tm.AddDays(1))
                    {
                        string tm1 = PublicClassLibrary.ClsSwitch.SwitDate(tm).ToString();
                        if (string.IsNullOrEmpty(cList) == false)
                        {
                            cList += ",";
                        }
                        string tmp = dtHRRealData.Compute("sum(C)", "BYORGNO='" + m.ORGNo + "' and SBDATE='" + tm1 + "'").ToString(); //计算该日期下人数
                        cList += (string.IsNullOrEmpty(tmp) ? "0" : tmp);                                                             //各日期以逗号分隔
                    }
                    m.DayCountList = cList;                                                                                           //日期考勤列表
                    if (CHr != "0")
                    {
                        CHr = (int.Parse(CHr) * days).ToString();

                        string Chr0 = dtHRRealData.Compute("sum(C)", "BYORGNO='" + m.ORGNo + "'").ToString();
                        Chr0 = (string.IsNullOrEmpty(Chr0) ? "0" : Chr0);; // BaseDT.T_IPS_REALDATATEMPORARY.getCountByOrgNo(dtHRRealData, orgNo).ToString();
                        string Chr1 = ClsStr.getDiff(CHr, Chr0).ToString("F0");
                        Chr1 = (string.IsNullOrEmpty(Chr1) ? "0" : Chr1);
                        string Chr2 = ClsStr.getPercent(Chr0, CHr).ToString("F0");
                        Chr2      = (string.IsNullOrEmpty(Chr2) ? "0" : Chr2);
                        m.daysC   = CHr;        //总
                        m.daysOK  = Chr0;       //完成
                        m.daysPer = Chr2 + "%"; //完成率
                    }
                    result.Add(m);
                }
                dtOrg.Clear();
                dtOrg.Dispose();
            }
            else//显示乡的,乡的列出各个护林员
            {
                DataRow[] drOrg = dtHU.Select("", "");//取所有

                for (int i = 0; i < drOrg.Length; i++)
                {
                    HUCheck_CheckInCount_Model m = new HUCheck_CheckInCount_Model();


                    m.ORGName = drOrg[i]["hname"].ToString();
                    m.ORGNo   = drOrg[i]["hid"].ToString();
                    string CHr = "1";                                    // dtHU.Compute("BYORGNO=" + m.ORGNo, "").ToString();//计算该单位下总人数
                    m.HUCount = (string.IsNullOrEmpty(CHr) ? "0" : CHr); //考勤人数
                    string cList = "";
                    for (DateTime tm = dt1; tm <= dt2; tm = tm.AddDays(1))
                    {
                        if (string.IsNullOrEmpty(cList) == false)
                        {
                            cList += ",";
                        }
                        string tmp = dtHRRealData.Compute("sum(C)", "BYORGNO='" + m.ORGNo + "' and SBDATE='" + PublicClassLibrary.ClsSwitch.SwitDate(tm).ToString() + "'").ToString(); //计算该日期下人数
                        cList += (string.IsNullOrEmpty(tmp) ? "0" : tmp);                                                                                                              //各日期以逗号分隔
                    }
                    m.DayCountList = cList;                                                                                                                                            //日期考勤列表
                    if (CHr != "0")
                    {
                        CHr = (int.Parse(CHr) * days).ToString();

                        string Chr0 = dtHRRealData.Compute("sum(C)", "BYORGNO='" + m.ORGNo + "'").ToString();
                        Chr0 = (string.IsNullOrEmpty(Chr0) ? "0" : Chr0);; // BaseDT.T_IPS_REALDATATEMPORARY.getCountByOrgNo(dtHRRealData, orgNo).ToString();
                        string Chr1 = ClsStr.getDiff(CHr, Chr0).ToString("F0");
                        Chr1 = (string.IsNullOrEmpty(Chr1) ? "0" : Chr1);
                        string Chr2 = ClsStr.getPercent(Chr0, CHr).ToString("F0");
                        Chr2      = (string.IsNullOrEmpty(Chr2) ? "0" : Chr2);
                        m.daysC   = CHr;        //总
                        m.daysOK  = Chr0;       //完成
                        m.daysPer = Chr2 + "%"; //完成率
                    }
                    result.Add(m);
                }
            }
            dtHU.Clear();
            dtHU.Dispose();

            //根据机构编码获取所有护林员信息
            // DataTable dtHU = BaseDT.T_IPSFR_USER.getDT(new T_IPSFR_USER_SW { BYORGNO = sw.ORGNO, ISENABLE = "1" });

            dtHRRealData.Clear();
            dtHRRealData.Dispose();

            if (1 == 1)
            {
                HUCheck_CheckInCount_Model m = new HUCheck_CheckInCount_Model();
                m.ORGName = "合计";
                string HUCount = result.Sum(item => Convert.ToDecimal(item.HUCount)).ToString();//总数
                string daysC   = result.Sum(item => Convert.ToDecimal(item.daysC)).ToString();
                string daysOK  = result.Sum(item => Convert.ToDecimal(item.daysOK)).ToString();
                HUCount = (string.IsNullOrEmpty(HUCount) ? "0" : HUCount);
                daysC   = (string.IsNullOrEmpty(daysC) ? "0" : daysC);
                daysOK  = (string.IsNullOrEmpty(daysOK) ? "0" : daysOK);
                //string PointCount0 = result.Sum(item => Convert.ToDecimal(item.PointCount0)).ToString();
                m.HUCount = HUCount;
                m.daysC   = daysC;  //总天数
                m.daysOK  = daysOK; //已出勤
                int[] arrI = new int[days];
                foreach (var v in result)
                {
                    string[] a = v.DayCountList.Split(',');//组合列表
                    for (int i = 0; i < days; i++)
                    {
                        if (string.IsNullOrEmpty(arrI[i].ToString()))
                        {
                            arrI[i] = 0;
                        }
                        arrI[i] += int.Parse(a[i]);
                    }
                }
                string cList = "";
                for (int i = 0; i < days; i++)
                {
                    if (string.IsNullOrEmpty(cList) == false)
                    {
                        cList += ",";
                    }
                    cList += arrI[i];
                }
                m.DayCountList = cList;
                //m.LineCount2 = ClsStr.getPercent(LineCount0, LineCount).ToString("F0") + "%";
                //m.PointCount = PointCount;
                //m.PointCount0 = PointCount0;
                //m.PointCount1 = result.Sum(item => Convert.ToDecimal(item.PointCount1)).ToString();
                m.daysPer = ClsStr.getPercent(m.daysOK, m.daysC).ToString("F0") + "%";
                result.Insert(0, m);
            }

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// 导出
        /// </summary>
        /// <returns></returns>
        public FileResult CheckInCountExportExcel()
        {
            HUCheckINCount_SW sw = new HUCheckINCount_SW();

            sw.ORGNO     = Request.Params["BYORGNO"];
            sw.DateBegin = Request.Params["TIMEBegin"];
            sw.DateEnd   = Request.Params["TIMEEnd"];
            var list = HUCheckCls.getCheckInModel(sw);

            DateTime dt1  = Convert.ToDateTime(sw.DateBegin);
            DateTime dt2  = Convert.ToDateTime(sw.DateEnd);
            int      days = ClsStr.getDateDiff(sw.DateBegin, sw.DateEnd) + 1;//日期包含天数

            //vMenu.MENUNAME 页面/菜单名称
            NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
            //添加一个sheet
            NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet("Sheet1");
            sheet1.IsPrintGridlines = true; //打印时显示网格线
            sheet1.DisplayGridlines = true; //查看时显示网格线
            sheet1.SetColumnWidth(0, 30 * 256);
            sheet1.SetColumnWidth(1, 10 * 256);
            for (int i = 0; i < days; i++)
            {
                sheet1.SetColumnWidth(i + 2, 10 * 256);
            }
            sheet1.SetColumnWidth(days + 2, 20 * 256);
            sheet1.SetColumnWidth(days + 3, 20 * 256);
            sheet1.SetColumnWidth(days + 4, 20 * 256);
            IRow row = sheet1.CreateRow(0);

            row.CreateCell(0).SetCellValue("考勤统计表");
            row.GetCell(0).CellStyle = getCellStyleTitle(book);
            row = sheet1.CreateRow(1);
            row.CreateCell(0).SetCellValue("单位/姓名");
            row.CreateCell(1).SetCellValue("考勤人数");
            row.CreateCell(2).SetCellValue("日期(日)");
            row.CreateCell(days + 2).SetCellValue("总出勤(天数)");
            row.CreateCell(days + 3).SetCellValue("已出勤(天数)");
            row.CreateCell(days + 4).SetCellValue("出勤率");
            row.GetCell(0).CellStyle        = getCellStyleHead(book);
            row.GetCell(1).CellStyle        = getCellStyleHead(book);
            row.GetCell(2).CellStyle        = getCellStyleHead(book);
            row.GetCell(days + 2).CellStyle = getCellStyleHead(book);
            row.GetCell(days + 3).CellStyle = getCellStyleHead(book);
            row.GetCell(days + 4).CellStyle = getCellStyleHead(book);
            row = sheet1.CreateRow(2);
            for (int i = 0; i < days; i++)
            {
                DateTime tm = dt1.AddDays(i);
                row.CreateCell(i + 2).SetCellValue(tm.ToString("dd"));
                row.GetCell(i + 2).CellStyle = getCellStyleHead(book);
            }
            sheet1.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(0, 0, 0, days + 4));
            sheet1.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(1, 1, 2, days + 1));
            sheet1.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(1, 2, 0, 0));
            sheet1.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(1, 2, 1, 1));
            sheet1.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(1, 2, days + 2 + 2, days + 2 + 2));
            sheet1.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(1, 2, days + 0 + 2, days + 0 + 2));
            sheet1.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(1, 2, days + 1 + 2, days + 1 + 2));
            int rowI = 0;

            foreach (var v in list)
            {
                row = sheet1.CreateRow(rowI + 3);

                row.CreateCell(0).SetCellValue(v.ORGName);
                row.CreateCell(1).SetCellValue(v.HUCount);
                string[] arr = v.DayCountList.Split(',');
                for (int i = 0; i < days; i++)
                {
                    row.CreateCell(i + 2).SetCellValue(arr[i]);
                }
                row.CreateCell(days + 2).SetCellValue(v.daysC);
                row.CreateCell(days + 3).SetCellValue(v.daysOK);
                row.CreateCell(days + 4).SetCellValue(v.daysPer);
                rowI++;
            }
            // 写入到客户端
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            book.Write(ms);
            ms.Seek(0, SeekOrigin.Begin);
            string fileName = "考勤统计表" + DateTime.Now.ToString("yyyy-MM-dd") + ".xls";

            return(File(ms, "application/vnd.ms-excel", fileName));
        }