223 lines
10 KiB
C#
223 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Web;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
using NPOI.SS.UserModel;
|
|
using NPOI.HSSF.UserModel;
|
|
using NPOI.HSSF.Util;
|
|
using System.IO;
|
|
using NPOI.SS.Util;
|
|
using Wellan.Data;
|
|
using System.Linq;
|
|
using System.Diagnostics.Eventing.Reader;
|
|
|
|
/// <summary>
|
|
/// 差勤日報表
|
|
/// </summary>
|
|
public class 差勤日報表 : ExcelReportBase
|
|
{
|
|
|
|
public 差勤日報表()
|
|
{
|
|
報表名稱 = "差勤日報表";
|
|
}
|
|
|
|
public DateTime 開始日期 { get; set; }
|
|
public DateTime 結束日期 { get; set; }
|
|
|
|
public List<ProjectEmployeeItem> 人員Data { get; set; }
|
|
public List<差勤日報表Item> 請假Data { get; set; }
|
|
public List<差勤日報表Item> 加班Data { get; set; }
|
|
public List<差勤日報表Item> 出差Data { get; set; }
|
|
public List<RASNBRHItem> 站別分組 { get; set; }
|
|
|
|
private RparDAC rparDao = new RparDAC();
|
|
|
|
public override MemoryStream 產生報表()
|
|
{
|
|
var groupIdList = new List<string>();
|
|
foreach (var 站別 in 站別分組)
|
|
{
|
|
if (!groupIdList.Contains(站別.GroupID))
|
|
groupIdList.Add(站別.GroupID);
|
|
}
|
|
|
|
var row = 0;
|
|
foreach (var groupId in groupIdList)
|
|
{
|
|
var 本組站別 = 站別分組.FindAll(p => p.GroupID.CompareTo(groupId) == 0);
|
|
var branchID = String.Join(",", (from 站別 in 本組站別 select 站別.BranchID).ToArray());
|
|
var branchName = String.Join("+", (from 站別 in 本組站別 select 站別.BranchName).ToArray());
|
|
|
|
row += 產生單位報表(row, branchName, branchID) + 2;
|
|
}
|
|
|
|
excel.SetColumnWidth(0, 8);
|
|
excel.SetColumnWidth(1, 20);
|
|
excel.SetColumnWidth(2, 40);
|
|
excel.SetColumnWidth(3, 20);
|
|
excel.SetColumnWidth(4, 40);
|
|
excel.SetColumnWidth(5, 20);
|
|
excel.SetColumnWidth(6, 40);
|
|
excel.SetColumnWidth(7, 60);
|
|
excel.SetColumnWidth(8, 20);
|
|
|
|
MemoryStream ms = new MemoryStream();
|
|
workbook.Write(ms);
|
|
return ms;
|
|
}
|
|
|
|
|
|
public int 產生單位報表(int startRow, string branchName, string branchID)
|
|
{
|
|
var rows = 報表抬頭(startRow, branchName);
|
|
rows += 報表明細與結尾(startRow + rows, branchID);
|
|
return rows;
|
|
}
|
|
|
|
public int 報表抬頭(int startRow, string branchName)
|
|
{
|
|
excel.MergeCell(startRow + 0, 0, startRow + 1, 0);
|
|
excel.SetCellValue(startRow + 0, 0, "單位", titleStyleCenter);
|
|
excel.SetRangeOuterBorder(startRow + 0, 0, startRow + 1, 0, BorderStyle.Thin);
|
|
|
|
excel.MergeCell(startRow + 0, 1, startRow + 1, 1);
|
|
excel.SetCellValue(startRow + 0, 1, branchName, titleStyleCenter);
|
|
excel.SetRangeOuterBorder(startRow + 0, 1, startRow + 1, 1, BorderStyle.Thin);
|
|
|
|
excel.MergeCell(startRow + 0, 2, startRow + 0, 3);
|
|
excel.SetCellValue(startRow + 0, 2, String.Format("日期-{0:MM月dd日}", 開始日期), titleStyleCenter);
|
|
excel.SetRangeOuterBorder(startRow + 0, 2, startRow + 0, 3, BorderStyle.Thin);
|
|
|
|
excel.MergeCell(startRow + 1, 2, startRow + 1, 3);
|
|
excel.SetCellValue(startRow + 1, 2, "加班申請", titleStyleCenter);
|
|
excel.SetRangeOuterBorder(startRow + 1, 2, startRow + 1, 3, BorderStyle.Thin);
|
|
|
|
excel.MergeCell(startRow + 0, 4, startRow + 0, 7);
|
|
excel.SetCellValue(startRow + 0, 4, String.Format("日期-{0:MM月dd日}", 結束日期), titleStyleCenter);
|
|
excel.SetRangeOuterBorder(startRow + 0, 4, startRow + 0, 7, BorderStyle.Thin);
|
|
|
|
excel.MergeCell(startRow + 1, 4, startRow + 1, 5);
|
|
excel.SetCellValue(startRow + 1, 4, "請假申請", titleStyleCenter);
|
|
excel.SetRangeOuterBorder(startRow + 1, 4, startRow + 1, 5, BorderStyle.Thin);
|
|
|
|
excel.MergeCell(startRow + 1, 6, startRow + 1, 7);
|
|
excel.SetCellValue(startRow + 1, 6, "出差申請", titleStyleCenter);
|
|
excel.SetRangeOuterBorder(startRow + 1, 6, startRow + 1, 7, BorderStyle.Thin);
|
|
|
|
excel.MergeCell(startRow + 0, 8, startRow + 1, 8);
|
|
excel.SetCellValue(startRow + 0, 8, "備註說明", titleStyleCenter);
|
|
excel.SetRangeOuterBorder(startRow + 0, 8, startRow + 1, 8, BorderStyle.Thin);
|
|
|
|
excel.SetCellValue(startRow + 2, 0, "序號", titleStyleCenter);
|
|
excel.SetCellValue(startRow + 2, 1, "姓名", titleStyleCenter);
|
|
excel.SetCellValue(startRow + 2, 2, "起迄時間", titleStyleCenter);
|
|
excel.SetCellValue(startRow + 2, 3, "時數", titleStyleCenter);
|
|
excel.SetCellValue(startRow + 2, 4, "起迄時間", titleStyleCenter);
|
|
excel.SetCellValue(startRow + 2, 5, "假別/事由", titleStyleCenter);
|
|
excel.SetCellValue(startRow + 2, 6, "起迄時間", titleStyleCenter);
|
|
excel.SetCellValue(startRow + 2, 7, "地點", titleStyleCenter);
|
|
excel.SetCellValue(startRow + 2, 8, "剩餘補休時數", titleStyleCenter);
|
|
|
|
return 3;
|
|
}
|
|
|
|
public int 報表明細與結尾(int startRow, string branchID)
|
|
{
|
|
int rows = 0;
|
|
|
|
var 人員Data1 = 人員Data.FindAll(p => branchID.Contains(p.BPBRH)).OrderBy(p => p.BPENO);
|
|
|
|
foreach (var 人員Item in 人員Data1)
|
|
{
|
|
excel.SetCellValue(startRow + rows, 0, rows + 1, bodyStyleCenter);
|
|
excel.SetCellValue(startRow + rows, 1, 人員Item.BPNME, bodyStyleCenter);
|
|
|
|
var 加班 = "";
|
|
var 加班時數 = 0D;
|
|
foreach (var 加班Item in 加班Data.FindAll(p => p.員工編號 == 人員Item.BPENO).OrderBy(p => p.起日))
|
|
{
|
|
加班 += (加班.Length > 0 ? "\n" : "") + String.Format("{0:yyyy/MM/dd} {1}~{2}", 加班Item.起日, 加班Item.起時, 加班Item.迄時);
|
|
加班時數 += 加班Item.時數;
|
|
}
|
|
excel.SetCellValue(startRow + rows, 2, 加班, bodyStyleCenter);
|
|
if (加班時數 > 0)
|
|
excel.SetCellValue(startRow + rows, 3, (int)加班時數, bodyStyleCenter);
|
|
else
|
|
excel.SetCellValue(startRow + rows, 3, "", bodyStyleCenter);
|
|
|
|
|
|
var 請假 = "";
|
|
var 請假假別 = "";
|
|
foreach (var 請假Item in 請假Data.FindAll(p => p.員工編號 == 人員Item.BPENO).OrderBy(p => p.起日))
|
|
{
|
|
請假 += (請假.Length > 0 ? "\n" : "")
|
|
+ (請假Item.起日 == 請假Item.迄日
|
|
? String.Format("{0:yyyy/MM/dd} {1}~{2}", 請假Item.起日, 請假Item.起時, 請假Item.迄時)
|
|
: String.Format("{0:yyyy/MM/dd} {1}~{2:yyyy/MM/dd} {3}", 請假Item.起日, 請假Item.起時, 請假Item.迄日, 請假Item.迄時));
|
|
請假假別 += (請假假別.Length > 0 ? "\n" : "") + 請假Item.類別名稱;
|
|
}
|
|
|
|
excel.SetCellValue(startRow + rows, 4, 請假, bodyStyleCenter);
|
|
excel.SetCellValue(startRow + rows, 5, 請假假別, bodyStyleCenter);
|
|
|
|
var 出差 = "";
|
|
var 出差地點 = "";
|
|
foreach (var 出差Item in 出差Data.FindAll(p => p.員工編號 == 人員Item.BPENO).OrderBy(p => p.起日))
|
|
{
|
|
出差 += (出差.Length > 0 ? "\n" : "")
|
|
+ (出差Item.起日 == 出差Item.迄日
|
|
? String.Format("{0:yyyy/MM/dd} {1}~{2}", 出差Item.起日, 出差Item.起時, 出差Item.迄時)
|
|
: String.Format("{0:yyyy/MM/dd} {1}~{2:yyyy/MM/dd} {3}", 出差Item.起日, 出差Item.起時, 出差Item.迄日, 出差Item.迄時));
|
|
出差地點 += (出差地點.Length > 0 ? "\n" : "") + 出差Item.出差地點;
|
|
}
|
|
|
|
excel.SetCellValue(startRow + rows, 6, 出差, bodyStyleCenter);
|
|
excel.SetCellValue(startRow + rows, 7, 出差地點, bodyStyleCenter);
|
|
|
|
|
|
var 補休分數 = 0D;
|
|
var 補休明細 = "";
|
|
foreach (var 補休Item in rparDao.取得補休明細資料(人員Item.BPENO))
|
|
{
|
|
補休分數 += 補休Item.可用時數 * 60 + 補休Item.可用分數;
|
|
if (以時分顯示時數)
|
|
補休明細 += (補休明細.Length > 0 ? "\n" : "")
|
|
+ String.Format("{0}:{1:00} {2:yyyy/MM/dd}", 補休Item.可用時數, 補休Item.可用分數, 補休Item.有效期限);
|
|
else
|
|
補休明細 += (補休明細.Length > 0 ? "\n" : "")
|
|
+ String.Format("{0}H {1:yyyy/MM/dd}", 補休Item.可用時數, 補休Item.有效期限);
|
|
}
|
|
|
|
if (補休分數 > 0) {
|
|
if (以時分顯示時數)
|
|
excel.SetCellValue(startRow + rows, 8, String.Format("{0}:{1:00}\n{2}", (int)補休分數 / 60, (int)補休分數 % 60, 補休明細), bodyStyleCenter);
|
|
else
|
|
excel.SetCellValue(startRow + rows, 8, String.Format("{0}H\n{1}", (int)補休分數 / 60, 補休明細), bodyStyleCenter);
|
|
}
|
|
else
|
|
excel.SetCellValue(startRow + rows, 8, "", bodyStyleCenter);
|
|
|
|
excel.SetRowHeight(startRow + rows, 35);
|
|
|
|
rows++;
|
|
}
|
|
|
|
excel.SetCellValue(startRow + rows, 0, "小計", bodyStyleCenter);
|
|
excel.SetCellValue(startRow + rows, 1, String.Format("共 {0} 位", 人員Data1.ToList().Count), bodyStyleCenter);
|
|
excel.SetCellValue(startRow + rows, 2, "總申請時數", bodyStyleCenter);
|
|
if (人員Data1.ToList().Count > 0)
|
|
excel.SetCellFormula(startRow + rows, 3, String.Format("SUM({0}:{1})", excel.RCtoA1(startRow, 3), excel.RCtoA1(startRow + rows - 1, 3)) , bodyStyleCenter);
|
|
else
|
|
excel.SetCellValue(startRow + rows, 3, 0, bodyStyleCenter);
|
|
excel.SetCellValue(startRow + rows, 4, "", bodyStyleCenter);
|
|
excel.SetCellValue(startRow + rows, 5, "", bodyStyleCenter);
|
|
excel.SetCellValue(startRow + rows, 6, "", bodyStyleCenter);
|
|
excel.SetCellValue(startRow + rows, 7, "", bodyStyleCenter);
|
|
excel.SetCellValue(startRow + rows, 8, "", bodyStyleCenter);
|
|
|
|
rows++;
|
|
return rows;
|
|
}
|
|
} |