211 lines
10 KiB
C#
211 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;
|
||
|
||
/// <summary>
|
||
/// 請假申請單
|
||
/// </summary>
|
||
public class 請假申請單 : ExcelReportBase
|
||
{
|
||
public 請假申請單()
|
||
{
|
||
報表名稱 = "請假申請單";
|
||
}
|
||
|
||
public override MemoryStream 產生報表()
|
||
{
|
||
BodyRowHeight = 35;
|
||
TimeCalc timeCalc = new TimeCalc();
|
||
|
||
#region 報表抬頭
|
||
|
||
excel.MergeCell(0, 0, 0, 9);
|
||
excel.SetCellValue(0, 0, String.Format("{0}\r\n承辦{1}\r\n『{2}』\r\n{3}", 公司名稱, 客戶名稱, 專案名稱, 報表名稱), headerStyle);
|
||
excel.SetCellValue(1, 0, "月份:", titleStyleRightNoBorder);
|
||
excel.MergeCell(1, 1, 1, 2);
|
||
excel.SetCellValue(1, 1, 報表時間.ToString("MM月"), titleStyleLeftNoBorder);
|
||
excel.SetCellValue(1, 3, "單位:", titleStyleRightNoBorder);
|
||
excel.SetCellValue(1, 4, WDAC.GetStringValue(資料來源.Tables[0].Rows[0]["站別"]), titleStyleLeftNoBorder);
|
||
excel.SetCellValue(1, 5, "職稱:", titleStyleRightNoBorder);
|
||
excel.SetCellValue(1, 6, WDAC.GetStringValue(資料來源.Tables[0].Rows[0]["職稱"]), titleStyleLeftNoBorder);
|
||
excel.SetCellValue(1, 7, "姓名:", titleStyleRightNoBorder);
|
||
excel.SetCellValue(1, 8, WDAC.GetStringValue(資料來源.Tables[0].Rows[0]["BPNME"]), titleStyleLeftNoBorder);
|
||
excel.SetRowHeight(0, HeaderRowHeight * 4);
|
||
excel.SetRowHeight(1, BodyRowHeight);
|
||
|
||
excel.MergeCell(2, 0, 2, 2);
|
||
excel.SetRangeOuterBorder(2, 0, 2, 2, BorderStyle.Thin);
|
||
excel.SetCellValue(2, 0, "請假日期", titleStyleCenter);
|
||
excel.SetCellValue(2, 3, "開始時間", titleStyleCenter);
|
||
excel.SetCellValue(2, 4, "結束時間", titleStyleCenter);
|
||
excel.SetCellValue(2, 5, "請假類別", titleStyleCenter);
|
||
excel.SetCellValue(2, 6, "請假時數", titleStyleCenter);
|
||
excel.SetCellValue(2, 7, "代理人", titleStyleCenter);
|
||
excel.SetCellValue(2, 8, "請假事由", titleStyleCenter);
|
||
excel.SetCellValue(2, 9, "備註", titleStyleCenter);
|
||
excel.SetRowHeight(2, BodyRowHeight);
|
||
|
||
#endregion
|
||
|
||
#region 報表資料
|
||
|
||
DateTime 月初 = 報表時間;
|
||
DateTime 月底 = 報表時間.AddMonths(1).AddDays(-1);
|
||
|
||
var summarys = new List<Summary>()
|
||
{
|
||
new Summary() { Title = "補休" , RparTyps = new List<string>() { RPAR_TYPE.T00_補休 } },
|
||
new Summary() { Title = "特休" , RparTyps = new List<string>() { RPAR_TYPE.T01_特休 } } ,
|
||
new Summary() { Title = "事假" , RparTyps = new List<string>() { RPAR_TYPE.T02_事假 } },
|
||
new Summary() { Title = "病假" , RparTyps = new List<string>() { RPAR_TYPE.T03_病假 } },
|
||
new Summary() { Title = "喪假" , RparTyps = new List<string>() { RPAR_TYPE.T04_喪假 } },
|
||
new Summary() { Title = "產假" , RparTyps = new List<string>() { RPAR_TYPE.T05_產假 } },
|
||
new Summary() { Title = "婚假" , RparTyps = new List<string>() { RPAR_TYPE.T06_婚假 } },
|
||
new Summary() { Title = "陪產假" , RparTyps = new List<string>() { RPAR_TYPE.T07_陪產假 } },
|
||
new Summary() { Title = "公假(出)" , RparTyps = new List<string>() { RPAR_TYPE.T08_公假 } },
|
||
new Summary() { Title = "公傷假" , RparTyps = new List<string>() { RPAR_TYPE.T09_公傷假 } },
|
||
new Summary() { Title = "生理假" , RparTyps = new List<string>() { RPAR_TYPE.T0A_生理假 } },
|
||
new Summary() { Title = "家庭照顧假" , RparTyps = new List<string>() { RPAR_TYPE.T0B_家庭照顧假 } },
|
||
new Summary() { Title = "育嬰假" , RparTyps = new List<string>() { RPAR_TYPE.T0C_育嬰假 } },
|
||
new Summary() { Title = "原民祭儀假" , RparTyps = new List<string>() { RPAR_TYPE.T0D_原民祭儀假 } },
|
||
new Summary() { Title = "產檢假" , RparTyps = new List<string>() { RPAR_TYPE.T0E_產檢假 } },
|
||
new Summary() { Title = "其他假別(一)", RparTyps = new List<string>() { RPAR_TYPE.T0F_防疫照顧假,
|
||
RPAR_TYPE.T0G_無薪假,
|
||
RPAR_TYPE.T0H_防疫隔離假 } }
|
||
};
|
||
|
||
int 總時數 = 0;
|
||
|
||
int rowId = 3;
|
||
foreach (DataRow r in 資料來源.Tables[0].Rows)
|
||
{
|
||
DateTime 起日 = WDAC.GetDateTimeValue(r["RPRDT"]);
|
||
DateTime 迄日 = WDAC.GetDateTimeValue(r["RPEDT"]);
|
||
string 起時 = WDAC.GetStringValue(r["RPRTM"]);
|
||
string 迄時 = WDAC.GetStringValue(r["RPETM"]);
|
||
string 類別 = WDAC.GetStringValue(r["RPTYP"]);
|
||
|
||
if (起日 < 月初)
|
||
{
|
||
起日 = 月初;
|
||
起時 = timeCalc.上班時間;
|
||
}
|
||
if (迄日 > 月底)
|
||
{
|
||
迄日 = 月底;
|
||
迄時 = timeCalc.下班時間;
|
||
}
|
||
|
||
//Double 時數 = WDAC.GetDoubleValue(r["RPTCT"]) / 60;
|
||
int 時數 = timeCalc.計算請假總時數(WDAC.GetStringValue(資料來源.Tables[0].Rows[0]["RPNUM"]), 起日, 迄日, 起時, 迄時, 類別, !以時分顯示時數);
|
||
總時數 += 時數;
|
||
|
||
#region 區分假別統計
|
||
var summary = summarys.FirstOrDefault(p => p.RparTyps.Contains(類別));
|
||
if (summary != null) {
|
||
summary.Minutes += 時數;
|
||
}
|
||
#endregion
|
||
|
||
excel.SetCellValue(rowId, 0, 起日.ToString("MM月dd日"), titleStyleCenter);
|
||
excel.SetCellValue(rowId, 1, "~", titleStyleCenter);
|
||
excel.SetCellValue(rowId, 2, 迄日.ToString("MM月dd日"), titleStyleCenter);
|
||
excel.SetCellValue(rowId, 3, 起時, titleStyleCenter);
|
||
excel.SetCellValue(rowId, 4, 迄時, titleStyleCenter);
|
||
excel.SetCellValue(rowId, 5, WDAC.GetStringValue(r["類別"]), titleStyleCenter);
|
||
excel.SetCellValue(rowId, 6, MinuteToTime(時數), titleStyleCenter);
|
||
excel.SetCellValue(rowId, 7, WDAC.GetStringValue(r["RPAGT"]), titleStyleCenter);
|
||
excel.SetCellValue(rowId, 8, WDAC.GetStringValue(r["RPRSN"]), bodyStyleCenterS);
|
||
excel.SetCellValue(rowId, 9, WDAC.GetStringValue(r["RPDOC"]), bodyStyleCenterS);
|
||
excel.SetRowHeight(rowId, BodyRowHeight);
|
||
rowId++;
|
||
}
|
||
|
||
#region 底下的統計
|
||
var summaryRows = summarys.Count + 1;
|
||
|
||
excel.MergeCell(rowId + 2, 2, rowId + summaryRows, 3);
|
||
excel.MergeCell(rowId + 2, 4, rowId + summaryRows, 4);
|
||
excel.MergeCell(rowId + 2, 5, rowId + summaryRows, 5);
|
||
excel.SetCellValue(rowId + 2, 2, "總請假時數:", titleStyleRightNoBorder);
|
||
excel.SetCellValue(rowId + 2, 4, MinuteToTime(總時數), titleStyleCenterNoBorder);
|
||
excel.SetCellValue(rowId + 2, 5, "hrs", titleStyleLeftNoBorder);
|
||
excel.SetRangeOuterBorder(rowId + 2, 2, rowId + summaryRows, 5, BorderStyle.Thin);
|
||
|
||
var rr = 2;
|
||
foreach (var symmary in summarys)
|
||
{
|
||
excel.SetCellValue(rowId + rr, 6, symmary.Title + ":", titleStyleLeftNoBorder);
|
||
excel.SetCellValue(rowId + rr, 7, MinuteToTime(symmary.Minutes), titleStyleCenterNoBorder);
|
||
excel.SetCellValue(rowId + rr, 8, "hrs", titleStyleLeftNoBorder);
|
||
excel.SetRangeOuterBorder(rowId + rr, 6, rowId + rr, 8, BorderStyle.Thin);
|
||
excel.SetRowHeight(rowId + rr, BodyRowHeight);
|
||
rr++;
|
||
}
|
||
|
||
rowId += summaryRows;
|
||
#endregion
|
||
|
||
#region 表尾批示
|
||
|
||
//excel.MergeCell(rowId + 10, 0, rowId + 10, 9);
|
||
//excel.SetCellValue(rowId + 10, 0, "申請人: 計畫督導: 人事單位:", titleStyleLeftNoBorder);
|
||
//excel.SetRowHeight(rowId + 10, BodyRowHeight);
|
||
|
||
//excel.MergeCell(rowId + 1, 1, rowId + 1, 3);
|
||
//excel.MergeCell(rowId + 2, 1, rowId + 2, 3);
|
||
//excel.SetCellValue(rowId + 1, 1, "申請人", titleStyleCenter);
|
||
//excel.SetRangeOuterBorder(rowId + 1, 1, rowId + 1, 3, BorderStyle.Thin);
|
||
//excel.SetRangeOuterBorder(rowId + 2, 1, rowId + 2, 3, BorderStyle.Thin);
|
||
|
||
//excel.MergeCell(rowId + 1, 4, rowId + 1, 6);
|
||
//excel.MergeCell(rowId + 2, 4, rowId + 2, 6);
|
||
//excel.SetCellValue(rowId + 1, 4, "公司計畫督導", titleStyleCenter);
|
||
//excel.SetRangeOuterBorder(rowId + 1, 4, rowId + 1, 6, BorderStyle.Thin);
|
||
//excel.SetRangeOuterBorder(rowId + 2, 4, rowId + 2, 6, BorderStyle.Thin);
|
||
|
||
//excel.MergeCell(rowId + 1, 7, rowId + 1, 8);
|
||
//excel.MergeCell(rowId + 2, 7, rowId + 2, 8);
|
||
//excel.SetCellValue(rowId + 1, 7, "公司計畫主持人", titleStyleCenter);
|
||
//excel.SetRangeOuterBorder(rowId + 1, 7, rowId + 1, 8, BorderStyle.Thin);
|
||
//excel.SetRangeOuterBorder(rowId + 2, 7, rowId + 2, 8, BorderStyle.Thin);
|
||
|
||
//excel.SetRowHeight(rowId + 1, BodyRowHeight);
|
||
//excel.SetRowHeight(rowId + 2, BodyRowHeight);
|
||
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
excel.SetColumnWidth(0, 11);
|
||
excel.SetColumnWidth(1, 4);
|
||
excel.SetColumnWidth(2, 11);
|
||
excel.SetColumnWidth(3, 11);
|
||
excel.SetColumnWidth(4, 11);
|
||
excel.SetColumnWidth(5, 11);
|
||
excel.SetColumnWidth(6, 18);
|
||
excel.SetColumnWidth(7, 12);
|
||
excel.SetColumnWidth(8, 20);
|
||
excel.SetColumnWidth(9, 15);
|
||
|
||
MemoryStream ms = new MemoryStream();
|
||
workbook.Write(ms);
|
||
return ms;
|
||
}
|
||
}
|
||
|
||
class Summary
|
||
{
|
||
public string Title;
|
||
public int Minutes;
|
||
public List<string> RparTyps;
|
||
} |