Files
sryang 577060bc78 chore: 首次簽入 Thinkyu ASP.NET 專案
- 加入 Visual Studio / ASP.NET .gitignore
- 排除建置輸出、IDE 設定、NuGet packages、大型 MSI 安裝檔
2026-09-10 09:42:37 +08:00

246 lines
12 KiB
C#
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
/// <summary>
/// 加班申請單
/// </summary>
public class 加班申請單 : ExcelReportBase
{
public 加班申請單()
{
報表名稱 = "加班申請單";
}
public override MemoryStream 產生報表()
{
BodyRowHeight = 35;
#region 報表抬頭
excel.MergeCell(0, 0, 0, 8);
excel.SetCellValue(0, 0, String.Format("{0}\r\n承辦{1}\r\n『{2}』\r\n{3}", 公司名稱, 客戶名稱, 專案名稱, 報表名稱), headerStyle);
excel.SetCellValue(1, 0, "月份:", titleStyleRightNoBorder);
excel.SetCellValue(1, 1, 報表時間.ToString("MM月"), titleStyleLeftNoBorder);
excel.SetCellValue(1, 2, "單位:", titleStyleRightNoBorder);
excel.SetCellValue(1, 3, WDAC.GetStringValue(資料來源.Tables[0].Rows[0]["站別"]), titleStyleLeftNoBorder);
excel.SetCellValue(1, 4, "職稱:", titleStyleRightNoBorder);
excel.SetCellValue(1, 5, WDAC.GetStringValue(資料來源.Tables[0].Rows[0]["職稱"]), titleStyleLeftNoBorder);
excel.SetCellValue(1, 6, "姓名:", titleStyleRightNoBorder);
excel.SetCellValue(1, 7, WDAC.GetStringValue(資料來源.Tables[0].Rows[0]["BPNME"]), titleStyleLeftNoBorder);
excel.SetRowHeight(0, HeaderRowHeight * 4);
excel.SetRowHeight(1, BodyRowHeight);
excel.SetCellValue(2, 0, "加班日期", titleStyleCenter);
excel.SetCellValue(2, 1, "開始時間", titleStyleCenter);
excel.SetCellValue(2, 2, "結束時間", titleStyleCenter);
excel.SetCellValue(2, 3, "核定加班時數", titleStyleCenter);
excel.SetCellValue(2, 4, "核定加班費時數", titleStyleCenter);
excel.SetCellValue(2, 5, "核定補休時數", titleStyleCenter);
excel.MergeCell(2, 6, 2, 7);
excel.SetCellValue(2, 6, "加班事由", titleStyleCenter);
excel.SetRangeOuterBorder(2, 6, 2, 7, BorderStyle.Thin);
excel.SetCellValue(2, 8, "備註", titleStyleCenter);
excel.SetRowHeight(2, BodyRowHeight * 2);
#endregion
#region 報表資料
int RPTC1_SUM = 0;
int RPTC2_SUM = 0;
int RPTC3_SUM = 0;
int RPTC4_SUM = 0;
int RPTC5_SUM = 0;
int RPTCT_SUM = 0;
int FEE_THIS = 0;
int RST_THIS = 0;
int RST_SUM = 0;
int FEE_SUM = 0;
int rowId = 3;
foreach (DataRow r in 資料來源.Tables[0].Rows)
{
int RPTCT = WDAC.GetInt32Value(r["RPTCT"]);
RPTCT_SUM += RPTCT;
#region 區分假別統計
switch (WDAC.GetStringValue(r["RPTYP"]))
{
case RPAR_TYPE.T11_非休息日累積補休時數:
case RPAR_TYPE.T13_休息日累積補休時數:
case RPAR_TYPE.T15_國定假日累積補休時數:
case RPAR_TYPE.T17_例假日累積補休時數:
RST_SUM += RPTCT;
RST_THIS = RPTCT;
FEE_THIS = 0;
break;
default:
RPTC1_SUM += WDAC.GetInt32Value(r["RPTC1"]);
RPTC2_SUM += WDAC.GetInt32Value(r["RPTC2"]);
RPTC3_SUM += WDAC.GetInt32Value(r["RPTC3"]);
RPTC4_SUM += WDAC.GetInt32Value(r["RPTC4"]);
RPTC5_SUM += WDAC.GetInt32Value(r["RPTC5"]);
FEE_SUM += RPTCT;
RST_THIS = 0;
FEE_THIS = RPTCT;
break;
}
#endregion
excel.SetCellValue(rowId, 0, WDAC.GetDateTimeValue(r["RPRDT"]).ToString("MM月dd日"), titleStyleCenter);
excel.SetCellValue(rowId, 1, WDAC.GetStringValue(r["RPRTM"]), titleStyleCenter);
excel.SetCellValue(rowId, 2, WDAC.GetStringValue(r["RPETM"]), titleStyleCenter);
if (以時分顯示時數)
{
excel.SetCellValue(rowId, 3, String.Format("{0:00}:{1:00}", RPTCT / 60, RPTCT % 60), titleStyleCenter);
excel.SetCellValue(rowId, 4, String.Format("{0:00}:{1:00}", FEE_THIS / 60, FEE_THIS % 60), titleStyleCenter);
excel.SetCellValue(rowId, 5, String.Format("{0:00}:{1:00}", RST_THIS / 60, RST_THIS % 60), titleStyleCenter);
}
else
{
excel.SetCellValue(rowId, 3, String.Format("{0:00}", RPTCT / 60), titleStyleCenter);
excel.SetCellValue(rowId, 4, String.Format("{0:00}", FEE_THIS / 60), titleStyleCenter);
excel.SetCellValue(rowId, 5, String.Format("{0:00}", RST_THIS / 60), titleStyleCenter);
}
excel.MergeCell(rowId, 6, rowId, 7);
excel.SetCellValue(rowId, 6, WDAC.GetStringValue(r["RPRSN"]), bodyStyleCenterS);
excel.SetRangeOuterBorder(rowId, 6, rowId, 7, BorderStyle.Thin);
excel.SetCellValue(rowId, 8, WDAC.GetStringValue(r["RPDOC"]), bodyStyleCenterS);
excel.SetRowHeight(rowId, BodyRowHeight);
rowId++;
}
#region 底下的統計
// 左
excel.MergeCell(rowId + 2, 0, rowId + 7, 0);
excel.MergeCell(rowId + 2, 1, rowId + 7, 1);
excel.MergeCell(rowId + 2, 2, rowId + 7, 2);
excel.SetCellValue(rowId + 2, 0, "總加班時數:", titleStyleRightNoBorder);
if (以時分顯示時數)
excel.SetCellValue(rowId + 2, 1, String.Format("{0:00}:{1:00}", RPTCT_SUM / 60, RPTCT_SUM % 60), titleStyleCenterNoBorder);
else
excel.SetCellValue(rowId + 2, 1, String.Format("{0:00}", RPTCT_SUM / 60), titleStyleCenterNoBorder);
excel.SetCellValue(rowId + 2, 2, "hrs", titleStyleLeftNoBorder);
excel.SetRangeOuterBorder(rowId + 2, 0, rowId + 7, 2, BorderStyle.Thin);
// 中
excel.SetCellValue(rowId + 2, 3, "申請加班費:", titleStyleLeftNoBorder);
excel.SetCellValue(rowId + 7, 3, "申請補休:", titleStyleLeftNoBorder);
if (以時分顯示時數)
{
excel.SetCellValue(rowId + 2, 4, String.Format("{0:00}:{1:00}", FEE_SUM / 60, FEE_SUM % 60), titleStyleCenterNoBorder);
excel.SetCellValue(rowId + 7, 4, String.Format("{0:00}:{1:00}", RST_SUM / 60, RST_SUM % 60), titleStyleCenterNoBorder);
}
else
{
excel.SetCellValue(rowId + 2, 4, String.Format("{0:00}", FEE_SUM / 60), titleStyleCenterNoBorder);
excel.SetCellValue(rowId + 7, 4, String.Format("{0:00}", RST_SUM / 60), titleStyleCenterNoBorder);
}
excel.SetCellValue(rowId + 2, 5, "hrs", titleStyleLeftNoBorder);
excel.SetCellValue(rowId + 7, 5, "hrs", titleStyleLeftNoBorder);
excel.SetRangeOuterBorder(rowId + 2, 3, rowId + 6, 5, BorderStyle.Thin);
excel.SetRangeOuterBorder(rowId + 7, 3, rowId + 7, 5, BorderStyle.Thin);
// 右
excel.SetCellValue(rowId + 2, 6, "一又三分之一:", titleStyleLeftNoBorder);
excel.SetCellValue(rowId + 3, 6, "一又三分之二:", titleStyleLeftNoBorder);
excel.SetCellValue(rowId + 4, 6, "國定假日:", titleStyleLeftNoBorder);
excel.SetCellValue(rowId + 5, 6, "休息日再延長:", titleStyleLeftNoBorder);
excel.SetCellValue(rowId + 6, 6, "例假日再延長:", titleStyleLeftNoBorder);
if (以時分顯示時數)
{
excel.SetCellValue(rowId + 2, 7, String.Format("{0:00}:{1:00}", RPTC1_SUM / 60, RPTC1_SUM % 60), titleStyleCenterNoBorder);
excel.SetCellValue(rowId + 3, 7, String.Format("{0:00}:{1:00}", RPTC2_SUM / 60, RPTC2_SUM % 60), titleStyleCenterNoBorder);
excel.SetCellValue(rowId + 4, 7, String.Format("{0:00}:{1:00}", RPTC3_SUM / 60, RPTC3_SUM % 60), titleStyleCenterNoBorder);
excel.SetCellValue(rowId + 5, 7, String.Format("{0:00}:{1:00}", RPTC4_SUM / 60, RPTC4_SUM % 60), titleStyleCenterNoBorder);
excel.SetCellValue(rowId + 6, 7, String.Format("{0:00}:{1:00}", RPTC5_SUM / 60, RPTC5_SUM % 60), titleStyleCenterNoBorder);
}
else
{
excel.SetCellValue(rowId + 2, 7, String.Format("{0:00}", RPTC1_SUM / 60), titleStyleCenterNoBorder);
excel.SetCellValue(rowId + 3, 7, String.Format("{0:00}", RPTC2_SUM / 60), titleStyleCenterNoBorder);
excel.SetCellValue(rowId + 4, 7, String.Format("{0:00}", RPTC3_SUM / 60), titleStyleCenterNoBorder);
excel.SetCellValue(rowId + 5, 7, String.Format("{0:00}", RPTC4_SUM / 60), titleStyleCenterNoBorder);
excel.SetCellValue(rowId + 6, 7, String.Format("{0:00}", RPTC5_SUM / 60), titleStyleCenterNoBorder);
}
excel.SetCellValue(rowId + 2, 8, "hrs", titleStyleLeftNoBorder);
excel.SetCellValue(rowId + 3, 8, "hrs", titleStyleLeftNoBorder);
excel.SetCellValue(rowId + 4, 8, "hrs", titleStyleLeftNoBorder);
excel.SetCellValue(rowId + 5, 8, "hrs", titleStyleLeftNoBorder);
excel.SetCellValue(rowId + 6, 8, "hrs", titleStyleLeftNoBorder);
excel.SetRangeOuterBorder(rowId + 2, 6, rowId + 2, 8, BorderStyle.Thin);
excel.SetRangeOuterBorder(rowId + 3, 6, rowId + 3, 8, BorderStyle.Thin);
excel.SetRangeOuterBorder(rowId + 4, 6, rowId + 4, 8, BorderStyle.Thin);
excel.SetRangeOuterBorder(rowId + 5, 6, rowId + 5, 8, BorderStyle.Thin);
excel.SetRangeOuterBorder(rowId + 6, 6, rowId + 6, 8, BorderStyle.Thin);
excel.SetRangeOuterBorder(rowId + 7, 6, rowId + 7, 8, BorderStyle.Thin);
excel.SetRowHeight(rowId + 2, BodyRowHeight);
excel.SetRowHeight(rowId + 3, BodyRowHeight);
excel.SetRowHeight(rowId + 4, BodyRowHeight);
excel.SetRowHeight(rowId + 5, BodyRowHeight);
excel.SetRowHeight(rowId + 6, BodyRowHeight);
excel.SetRowHeight(rowId + 7, BodyRowHeight);
rowId += 7;
#endregion
#region 表尾批示
//excel.MergeCell(rowId + 7, 0, rowId + 7, 8);
//excel.SetCellValue(rowId + 7, 0, "申請人:               計畫督導:               人事單位:", titleStyleLeftNoBorder);
//excel.SetRowHeight(rowId + 7, BodyRowHeight);
//excel.MergeCell(rowId + 2, 0, rowId + 2, 2);
//excel.MergeCell(rowId + 3, 0, rowId + 3, 2);
//excel.SetCellValue(rowId + 2, 0, "申請人", titleStyleCenter);
//excel.SetRangeOuterBorder(rowId + 2, 0, rowId + 2, 2, BorderStyle.Thin);
//excel.SetRangeOuterBorder(rowId + 3, 0, rowId + 3, 2, BorderStyle.Thin);
//excel.MergeCell(rowId + 2, 3, rowId + 2, 5);
//excel.MergeCell(rowId + 3, 3, rowId + 3, 5);
//excel.SetCellValue(rowId + 2, 3, "公司計畫督導", titleStyleCenter);
//excel.SetRangeOuterBorder(rowId + 2, 3, rowId + 2, 5, BorderStyle.Thin);
//excel.SetRangeOuterBorder(rowId + 3, 3, rowId + 3, 5, BorderStyle.Thin);
//excel.MergeCell(rowId + 2, 6, rowId + 2, 8);
//excel.MergeCell(rowId + 3, 6, rowId + 3, 8);
//excel.SetCellValue(rowId + 2, 6, "公司計畫主持人", titleStyleCenter);
//excel.SetRangeOuterBorder(rowId + 2, 6, rowId + 2, 8, BorderStyle.Thin);
//excel.SetRangeOuterBorder(rowId + 3, 6, rowId + 3, 8, BorderStyle.Thin);
//excel.SetRowHeight(rowId + 2, BodyRowHeight);
//excel.SetRowHeight(rowId + 3, BodyRowHeight);
#endregion
#endregion
excel.SetColumnWidth(0, 15);
excel.SetColumnWidth(1, 12);
excel.SetColumnWidth(2, 12);
excel.SetColumnWidth(3, 15);
excel.SetColumnWidth(4, 15);
excel.SetColumnWidth(5, 15);
excel.SetColumnWidth(6, 15);
excel.SetColumnWidth(7, 15);
excel.SetColumnWidth(8, 15);
MemoryStream ms = new MemoryStream();
workbook.Write(ms);
return ms;
}
}