chore: 首次簽入 Thinkyu ASP.NET 專案
- 加入 Visual Studio / ASP.NET .gitignore - 排除建置輸出、IDE 設定、NuGet packages、大型 MSI 安裝檔
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Text;
|
||||
|
||||
namespace Education
|
||||
{
|
||||
public class EncDec
|
||||
{
|
||||
/// <summary>
|
||||
/// WLIB 新版密碼的加密函數
|
||||
/// </summary>
|
||||
/// <param name="S">欲加密之密碼字串,最大長度 8 位,僅可包含A-Z、a-z、0-9</param>
|
||||
/// <returns>加密後之密碼字串</returns>
|
||||
public static string KeyEnc(string S)
|
||||
{
|
||||
int k1 = 0;
|
||||
int k2 = 0;
|
||||
int i, j;
|
||||
Random rnd = new Random(DateTime.UtcNow.AddHours(8).Millisecond);
|
||||
byte[] inBuf = new byte[8];
|
||||
byte[] outBuf = new byte[10];
|
||||
string tmp;
|
||||
|
||||
while (true)
|
||||
{
|
||||
k1 = rnd.Next(31);
|
||||
k2 = rnd.Next(31);
|
||||
outBuf[0] = (byte)(k1 + 44);
|
||||
outBuf[9] = (byte)(k2 + 66);
|
||||
|
||||
if (S.Length < 8)
|
||||
inBuf = Encoding.ASCII.GetBytes(S.PadRight(8));
|
||||
else
|
||||
inBuf = Encoding.ASCII.GetBytes(S);
|
||||
|
||||
for (i = 1; i <= 8; i++)
|
||||
{
|
||||
j = (k1 % 31) + i;
|
||||
j = ((k2 + j) % 31) + 1;
|
||||
|
||||
outBuf[i] = (byte)(inBuf[i - 1] ^ j);
|
||||
}
|
||||
tmp = Encoding.ASCII.GetString(outBuf);
|
||||
if (tmp.IndexOf('\'') < 0 && tmp.IndexOf('"') < 0)
|
||||
break;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// WLIB 新版密碼的解密函數
|
||||
/// </summary>
|
||||
/// <param name="S">欲解密之密碼字串,固定 10 位</param>
|
||||
/// <returns>解密後之密碼字串。若參數 S 長度不是 10 位,則傳回".." + S + ".."</returns>
|
||||
public static string KeyDec(string S)
|
||||
{
|
||||
int i, j;
|
||||
int Key1, Key2;
|
||||
byte[] inBuf;
|
||||
byte[] outBuf = new byte[8];
|
||||
|
||||
if (S.Length != 10)
|
||||
return ".." + S + "..";
|
||||
|
||||
//解密
|
||||
inBuf = Encoding.ASCII.GetBytes(S);
|
||||
Key1 = inBuf[0] - 44;
|
||||
Key2 = inBuf[9] - 66;
|
||||
|
||||
for (i = 1; i <= 8; i++)
|
||||
{
|
||||
j = Key1 % 31 + i;
|
||||
j = (Key2 + j) % 31 + 1;
|
||||
outBuf[i - 1] = (byte)(inBuf[i] ^ j);
|
||||
}
|
||||
return Encoding.ASCII.GetString(outBuf).Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Timers;
|
||||
using System.IO;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.SqlClient;
|
||||
using WebLib;
|
||||
|
||||
namespace Education
|
||||
{
|
||||
public class FollowService
|
||||
{
|
||||
private static FollowService _instance = null;
|
||||
private Timer _timer = null;
|
||||
private static int _interval = 30;
|
||||
private static string _doWorkTime = "00:00";
|
||||
private static bool _enabled = false;
|
||||
private static bool _busy = false;
|
||||
private static 發送郵件 發送郵件 = new 發送郵件();
|
||||
private DAC_BPSN Dao員工;
|
||||
private DbConnection conn;
|
||||
|
||||
/// <summary>
|
||||
/// 發動時間,預設值為 00:00
|
||||
/// </summary>
|
||||
public static string DoWorkTime
|
||||
{
|
||||
get
|
||||
{
|
||||
return _doWorkTime;
|
||||
}
|
||||
set
|
||||
{
|
||||
_doWorkTime = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 郵件模版路徑
|
||||
/// </summary>
|
||||
public static string TemplatePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 設定或取得簽核跟催服務是否啟動
|
||||
/// </summary>
|
||||
public static bool Enabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _enabled;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
if (_enabled)
|
||||
return;
|
||||
|
||||
Instance._timer.Interval = _interval * 1000;
|
||||
Instance._timer.AutoReset = true;
|
||||
Instance._timer.Enabled = true;
|
||||
_enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_enabled)
|
||||
return;
|
||||
|
||||
_enabled = false;
|
||||
Instance._timer.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private FollowService()
|
||||
{
|
||||
_timer = new Timer();
|
||||
_timer.Enabled = false;
|
||||
_timer.Elapsed += new ElapsedEventHandler(DoFollowWork);
|
||||
conn = DAC.NewConnection();
|
||||
Dao員工 = new DAC_BPSN(conn);
|
||||
}
|
||||
|
||||
public static FollowService Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
_instance = new FollowService();
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
private void DoFollowWork(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
string nowTime = DateTime.UtcNow.AddHours(8).ToString("HH:mm");
|
||||
if (nowTime.CompareTo(_doWorkTime) == 0 && !_busy)
|
||||
{
|
||||
_busy = true;
|
||||
try
|
||||
{
|
||||
DAC_表單簽核明細 dao表單簽核明細 = new DAC_表單簽核明細(conn);
|
||||
表單簽核明細List first = dao表單簽核明細.Select第一次稽催();
|
||||
表單簽核明細List second = dao表單簽核明細.Select第二次稽催();
|
||||
表單簽核明細List third = dao表單簽核明細.Select第三次稽催();
|
||||
|
||||
foreach (表單簽核明細 item in first)
|
||||
{
|
||||
SendFollowMail(item, 3);
|
||||
item.稽催狀態 = 1;
|
||||
dao表單簽核明細.UpdateOne(item);
|
||||
}
|
||||
|
||||
foreach (表單簽核明細 item in second)
|
||||
{
|
||||
SendFollowMail(item, 7);
|
||||
item.稽催狀態 = 2;
|
||||
dao表單簽核明細.UpdateOne(item);
|
||||
}
|
||||
|
||||
foreach (表單簽核明細 item in third)
|
||||
{
|
||||
SendFollowMail(item, 14);
|
||||
item.稽催狀態 = 3;
|
||||
dao表單簽核明細.UpdateOne(item);
|
||||
}
|
||||
|
||||
DoSurveyReminderWork();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_busy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SendFollowMail(表單簽核明細 item, int 天數)
|
||||
{
|
||||
string 電子郵件 = Dao員工.Get電子郵件(item.簽核人員);
|
||||
string 員工姓名 = Dao員工.Get員工姓名(item.簽核人員);
|
||||
發送郵件 發送郵件 = new 發送郵件();
|
||||
發送郵件.發送簽核跟催郵件(item.簽核ID, 員工姓名, 電子郵件, 天數, TemplatePath);
|
||||
}
|
||||
|
||||
private void DoSurveyReminderWork()
|
||||
{
|
||||
if (string.IsNullOrEmpty(PublicVariable.SiteBaseUrl))
|
||||
return;
|
||||
|
||||
string 手機版網址 = PublicVariable.SiteBaseUrl + "/MobileSurvey/Login.aspx";
|
||||
int deadlineDays = PublicVariable.SurveyReminderDeadlineDays;
|
||||
DateTime minDate = PublicVariable.SurveyReminderMinCourseDate;
|
||||
string[] excludeEmps = PublicVariable.SurveyReminderExcludeEmployees
|
||||
.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
DbCommand cmd = conn.CreateCommand();
|
||||
cmd.CommandText =
|
||||
@"select A.學員編號, A.訓練課程編號, C.BPNME as 學員姓名, C.BPEML as 電子郵件,
|
||||
B.顯示編號, B.訓練名稱, B.訓練日期, B.訓練日期迄
|
||||
from 課程報名 A
|
||||
inner join 訓練課程企劃 B on A.訓練課程編號 = B.編號
|
||||
inner join BPSNView C on A.學員編號 = C.BPENO
|
||||
where (A.報名狀態 = 'Y' or A.報名狀態 = 'R')
|
||||
and B.訓練日期 >= @MinCourseDate
|
||||
and (A.滿意度催填狀態 is null or A.滿意度催填狀態 = '')
|
||||
and not exists (
|
||||
select 1 from 滿意度調查 D
|
||||
where D.訓練課程企劃編號 = A.訓練課程編號 and D.學員編號 = A.學員編號
|
||||
)
|
||||
and dateadd(day, @DeadlineDays, B.訓練日期迄) < getdate()
|
||||
order by A.學員編號";
|
||||
cmd.Parameters.Add(new SqlParameter("@MinCourseDate", minDate));
|
||||
cmd.Parameters.Add(new SqlParameter("@DeadlineDays", deadlineDays));
|
||||
|
||||
DataTable dt = new DataTable();
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
dt.Load(reader);
|
||||
}
|
||||
|
||||
foreach (DataRow row in dt.Rows)
|
||||
{
|
||||
string 學員編號 = DAC.GetString(row["學員編號"]);
|
||||
if (excludeEmps.Contains(學員編號))
|
||||
continue;
|
||||
|
||||
string 學員姓名 = DAC.GetString(row["學員姓名"]);
|
||||
string 電子郵件 = DAC.GetString(row["電子郵件"]);
|
||||
string 訓練名稱 = DAC.GetString(row["訓練名稱"]);
|
||||
DateTime 訓練日期 = DAC.GetDateTime(row["訓練日期"]);
|
||||
DateTime 訓練日期迄 = DAC.GetDateTime(row["訓練日期迄"]);
|
||||
int 訓練課程編號 = DAC.GetInt32(row["訓練課程編號"]);
|
||||
|
||||
發送郵件 發送郵件 = new 發送郵件();
|
||||
發送郵件.發送滿意度催填郵件(學員姓名, 電子郵件, 訓練名稱, 訓練日期, 訓練日期迄, 手機版網址);
|
||||
|
||||
DbCommand cmdUpd = conn.CreateCommand();
|
||||
cmdUpd.CommandText =
|
||||
"update 課程報名 set 滿意度催填狀態 = 'Y'" +
|
||||
" where 訓練課程編號 = @訓練課程編號 and 學員編號 = @學員編號";
|
||||
cmdUpd.Parameters.Add(new SqlParameter("@訓練課程編號", 訓練課程編號));
|
||||
cmdUpd.Parameters.Add(new SqlParameter("@學員編號", 學員編號));
|
||||
cmdUpd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Web;
|
||||
using System.Web.UI.WebControls;
|
||||
using WebLib;
|
||||
|
||||
namespace Education
|
||||
{
|
||||
public class PublicVariable : WebLib.PublicVariable
|
||||
{
|
||||
private static Random r = new Random();
|
||||
|
||||
// 常用變數
|
||||
public static string[] 換行分隔 = { "\r\n" };
|
||||
|
||||
#region SESSION 變數名稱
|
||||
public const string CompanyId = "CompanyId";
|
||||
public const string EmployeeId = "EmployeeId";
|
||||
public const string EmployeeName = "EmployeeName";
|
||||
public const string EmployeeFunction = "EmployeeFunction";
|
||||
public const string CurrentPlace = "CurrentPlace";
|
||||
public const string CurrentPlaceName = "CurrentPlaceName";
|
||||
public const string UserGroups = "UserGroups";
|
||||
public const string EventPicturePath = "~/Upload/Event/";
|
||||
public const string BulletinAttachPath = "~/Upload/Attach/";
|
||||
public const string IsManager = "IsManager";
|
||||
public const string IsWorker = "IsWorker";
|
||||
public const string IsBackend = "IsBackend";
|
||||
#endregion
|
||||
|
||||
#region 檔案上傳/圖檔上傳路徑
|
||||
public const string 講師照片路徑 = "~/PhotoUpload/Teacher/";
|
||||
public const string 場地照片路徑 = "~/PhotoUpload/Place/";
|
||||
public const string 課程剪影路徑 = "~/PhotoUpload/Class/";
|
||||
public const string 證照上傳路徑 = "~/DocUpload/Certificate/";
|
||||
public const string 溝通記錄上傳路徑 = "~/DocUpload/Communication/";
|
||||
#endregion
|
||||
|
||||
#region 系統設定變數,由 Global.asax 讀取 web.config 中的設定
|
||||
|
||||
/// <summary>
|
||||
/// 系統名稱
|
||||
/// </summary>
|
||||
public static string SystemName = "Education";
|
||||
|
||||
/// <summary>
|
||||
/// 未登入時開放某些功能
|
||||
/// </summary>
|
||||
public static bool NoLoginFunction = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否為偵錯模式,會將系統錯誤訊息顯示在網頁上
|
||||
/// </summary>
|
||||
public static bool DEBUG = true;
|
||||
|
||||
/// <summary>
|
||||
/// 管理員群組
|
||||
/// </summary>
|
||||
public static string ManagerGroup = "'TR01'";
|
||||
|
||||
/// <summary>
|
||||
/// 承辦人群組
|
||||
/// </summary>
|
||||
public static string WorkerGroup = "'TR02'";
|
||||
|
||||
/// <summary>
|
||||
/// 總管理處ID
|
||||
/// </summary>
|
||||
public static int 總管理處ID = 2;
|
||||
|
||||
/// <summary>
|
||||
/// 人資部ID
|
||||
/// </summary>
|
||||
public static int 人資部ID = 56;
|
||||
|
||||
/// <summary>
|
||||
/// 財務部ID
|
||||
/// </summary>
|
||||
public static int 財務部ID = 60;
|
||||
|
||||
/// <summary>
|
||||
/// 是否使用 SSL 登入發郵件
|
||||
/// </summary>
|
||||
public static bool SendMailBySSL = false;
|
||||
|
||||
/// <summary>
|
||||
/// 郵件發送主機
|
||||
/// </summary>
|
||||
public static string SendMailHost = "";
|
||||
|
||||
/// <summary>
|
||||
/// 郵件發送通訊埠,不使用 SSL 的通常是 25,使用 SSL 的通常是 465
|
||||
/// </summary>
|
||||
public static int SendMailPort = 25;
|
||||
|
||||
/// <summary>
|
||||
/// 郵件發送帳號
|
||||
/// </summary>
|
||||
public static string SendMailUserName = "";
|
||||
|
||||
/// <summary>
|
||||
/// 郵件發送密碼
|
||||
/// </summary>
|
||||
public static string SendMailPassword = "";
|
||||
|
||||
#region 滿意度調查催填設定
|
||||
public const string SurveyReminderDeadlineDaysKey = "SurveyReminderDeadlineDays";
|
||||
public const string SurveyReminderExcludeEmployeesKey = "SurveyReminderExcludeEmployees";
|
||||
public const string SurveyReminderMinCourseDateKey = "SurveyReminderMinCourseDate";
|
||||
public const string SiteBaseUrlKey = "SiteBaseUrl";
|
||||
|
||||
/// <summary>
|
||||
/// 上課後幾天內要填寫滿意度調查
|
||||
/// </summary>
|
||||
public static int SurveyReminderDeadlineDays = 10;
|
||||
|
||||
/// <summary>
|
||||
/// 排除催填的員工編號(逗號分隔)
|
||||
/// </summary>
|
||||
public static string SurveyReminderExcludeEmployees = "00002,00003";
|
||||
|
||||
/// <summary>
|
||||
/// 只催填此日期之後的課程
|
||||
/// </summary>
|
||||
public static DateTime SurveyReminderMinCourseDate = new DateTime(2026, 7, 1);
|
||||
|
||||
/// <summary>
|
||||
/// 站台基礎 URL(如 http://hostname:port)
|
||||
/// </summary>
|
||||
public static string SiteBaseUrl = "";
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
public static string SystemVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
|
||||
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
|
||||
return fvi.FileVersion;
|
||||
}
|
||||
}
|
||||
|
||||
private static DateTime? _領據關帳年月UpdateTime = null;
|
||||
private static string _領據關帳年月 = string.Empty;
|
||||
public static string 領據關帳年月
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_領據關帳年月) || !_領據關帳年月UpdateTime.HasValue || _領據關帳年月UpdateTime < DateTime.Now.AddMinutes(-10))
|
||||
{
|
||||
using (var conn = DAC.NewConnection())
|
||||
{
|
||||
var daoBWEX = new DAC_BWEX(conn);
|
||||
_領據關帳年月 = daoBWEX.Read領據關帳年月;
|
||||
_領據關帳年月UpdateTime = DateTime.Now;
|
||||
}
|
||||
}
|
||||
return _領據關帳年月;
|
||||
}
|
||||
set
|
||||
{
|
||||
_領據關帳年月 = value;
|
||||
_領據關帳年月UpdateTime = DateTime.Now;
|
||||
using (var conn = DAC.NewConnection())
|
||||
{
|
||||
new DAC_BWEX(conn).WriteSetting("領據關帳年月", 1, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static decimal? _領據執行業務所得課稅門檻 = null;
|
||||
public static decimal 領據執行業務所得課稅門檻
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_領據執行業務所得課稅門檻.HasValue)
|
||||
{
|
||||
using (var conn = DAC.NewConnection())
|
||||
{
|
||||
_領據執行業務所得課稅門檻 = new DAC_BRTE(conn).領據執行業務所得課稅門檻;
|
||||
}
|
||||
}
|
||||
return _領據執行業務所得課稅門檻.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private static decimal? _領據薪資課稅門檻 = null;
|
||||
public static decimal 領據薪資課稅門檻
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_領據薪資課稅門檻.HasValue)
|
||||
{
|
||||
using (var conn = DAC.NewConnection())
|
||||
{
|
||||
_領據薪資課稅門檻 = new DAC_BRTE(conn).領據薪資課稅門檻;
|
||||
}
|
||||
}
|
||||
return _領據薪資課稅門檻.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private static decimal? _領據基本工資 = null;
|
||||
public static decimal 領據基本工資
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_領據基本工資.HasValue)
|
||||
{
|
||||
using (var conn = DAC.NewConnection())
|
||||
{
|
||||
_領據基本工資 = new DAC_BRTE(conn).領據基本工資;
|
||||
}
|
||||
}
|
||||
return _領據基本工資.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private static decimal? _領據執行業務所得稅率 = null;
|
||||
public static decimal 領據執行業務所得稅率
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_領據執行業務所得稅率.HasValue)
|
||||
{
|
||||
using (var conn = DAC.NewConnection())
|
||||
{
|
||||
_領據執行業務所得稅率 = new DAC_BRTE(conn).領據執行業務所得稅率;
|
||||
}
|
||||
}
|
||||
return _領據執行業務所得稅率.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private static decimal? _領據薪資稅率 = null;
|
||||
public static decimal 領據薪資稅率
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_領據薪資稅率.HasValue)
|
||||
{
|
||||
using (var conn = DAC.NewConnection())
|
||||
{
|
||||
_領據薪資稅率 = new DAC_BRTE(conn).領據薪資稅率;
|
||||
}
|
||||
}
|
||||
return _領據薪資稅率.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using WebLib;
|
||||
|
||||
namespace Education
|
||||
{
|
||||
/// <summary>
|
||||
/// 取得權限設定
|
||||
/// </summary>
|
||||
public class MWEB: DAC
|
||||
{
|
||||
public MWEB()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 檢查目前登入的員工是否有某程式的權限
|
||||
/// </summary>
|
||||
/// <param name="programId">程式編號</param>
|
||||
/// <param name="rightName">權限名稱</param>
|
||||
/// <param name="employeeId">員工編號</param>
|
||||
/// <returns></returns>
|
||||
public bool CheckRight(string programId, WRightName rightName, string employeeId)
|
||||
{
|
||||
if (programId == null)
|
||||
programId = "NO PROGRAM ID";
|
||||
if (employeeId == null)
|
||||
employeeId = "NOBODY";
|
||||
|
||||
// 取得員工權限
|
||||
string right1 = BWCPE_GetRight(programId, employeeId, rightName);
|
||||
|
||||
// 取得這個員工隸屬的群組
|
||||
string[] bpglps = BWEH_GetBpglpListByBpeno(employeeId);
|
||||
|
||||
// 取得各群組權限
|
||||
string[] right2 = new string[bpglps.Length];
|
||||
for (int i = 0; i < right2.Length; i++)
|
||||
{
|
||||
right2[i] = BWCPG_GetRight(programId, bpglps[i], rightName);
|
||||
}
|
||||
|
||||
// 綜合判斷權限
|
||||
string right = "";
|
||||
|
||||
if (right1 != "")
|
||||
right = right1;
|
||||
|
||||
if (right != "Y")
|
||||
for (int i = 0; i < right2.Length; i++)
|
||||
{
|
||||
if (right2[i] != "")
|
||||
{
|
||||
if (right != "Y" && right2[i] == "Y")
|
||||
right = "Y";
|
||||
else if (right != "Y" && right2[i] == "N")
|
||||
right = "N";
|
||||
}
|
||||
}
|
||||
return right == "Y";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取員工權限
|
||||
/// </summary>
|
||||
/// <param name="rightId">權限編號</param>
|
||||
/// <param name="employId">員工編號</param>
|
||||
/// <param name="functionName">功能名稱</param>
|
||||
/// <returns></returns>
|
||||
private string BWCPE_GetRight(string rightId, string employId, WRightName functionName)
|
||||
{
|
||||
string funcName = "";
|
||||
switch (functionName)
|
||||
{
|
||||
case WRightName.Execute:
|
||||
funcName = "BPRT1";
|
||||
break;
|
||||
case WRightName.Insert:
|
||||
funcName = "BPRTI";
|
||||
break;
|
||||
case WRightName.Update:
|
||||
funcName = "BPRTM";
|
||||
break;
|
||||
case WRightName.Delete:
|
||||
funcName = "BPRTD";
|
||||
break;
|
||||
case WRightName.Search:
|
||||
funcName = "BPRTF";
|
||||
break;
|
||||
case WRightName.Print:
|
||||
funcName = "BPRTP";
|
||||
break;
|
||||
}
|
||||
|
||||
DbCommand cmd = NewCommand();
|
||||
cmd.CommandText = @"SELECT BPRT1, BPRTI, BPRTM, BPRTD, BPRTF, BPRTP FROM BWCPE WHERE BPPRG=@BPPRG AND BPENO=@BPENO";
|
||||
|
||||
AddParam(cmd, "BPPRG", rightId);
|
||||
AddParam(cmd, "BPENO", employId);
|
||||
|
||||
DataTable data = Select(cmd);
|
||||
if (data.Rows.Count != 0)
|
||||
{
|
||||
return data.Rows[0][funcName].ToString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取員工所屬群組
|
||||
/// </summary>
|
||||
/// <param name="employeeId"></param>
|
||||
/// <returns></returns>
|
||||
private string[] BWEH_GetBpglpListByBpeno(string employeeId)
|
||||
{
|
||||
DbCommand cmd = NewCommand();
|
||||
cmd.CommandText = @"SELECT E.BPGLP AS BPGLP
|
||||
FROM BWEG E, BWEH G
|
||||
WHERE E.BPGLP=G.BPGLP AND G.BPENO=@BPENO
|
||||
ORDER BY E.BPGLP ";
|
||||
AddParam(cmd, "BPENO", employeeId);
|
||||
|
||||
DataTable inGroup = Select(cmd);
|
||||
if (inGroup.Rows.Count == 0)
|
||||
return new string[0];
|
||||
else
|
||||
{
|
||||
string[] result = new string[inGroup.Rows.Count];
|
||||
for (int i = 0; i < inGroup.Rows.Count; i++)
|
||||
{
|
||||
result[i] = inGroup.Rows[i][0].ToString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取群組權限
|
||||
/// </summary>
|
||||
/// <param name="rightId">權限編號</param>
|
||||
/// <param name="groupId">群組編號</param>
|
||||
/// <param name="functionName">功能名稱</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
private string BWCPG_GetRight(string rightId, string groupId, WRightName functionName)
|
||||
{
|
||||
string funcName = "";
|
||||
switch (functionName)
|
||||
{
|
||||
case WRightName.Execute:
|
||||
funcName = "BPRT1";
|
||||
break;
|
||||
case WRightName.Insert:
|
||||
funcName = "BPRTI";
|
||||
break;
|
||||
case WRightName.Update:
|
||||
funcName = "BPRTM";
|
||||
break;
|
||||
case WRightName.Delete:
|
||||
funcName = "BPRTD";
|
||||
break;
|
||||
case WRightName.Search:
|
||||
funcName = "BPRTF";
|
||||
break;
|
||||
case WRightName.Print:
|
||||
funcName = "BPRTP";
|
||||
break;
|
||||
}
|
||||
|
||||
DbCommand cmd = NewCommand();
|
||||
cmd.CommandText = @"SELECT BPRT1, BPRTI, BPRTM, BPRTD, BPRTF, BPRTP FROM BWCPG WHERE BPPRG=@BPPRG AND BPGLP=@BPGLP";
|
||||
|
||||
AddParam(cmd, "BPPRG", rightId);
|
||||
AddParam(cmd, "BPGLP", groupId);
|
||||
|
||||
DataTable data = Select(cmd);
|
||||
if (data.Rows.Count != 0)
|
||||
{
|
||||
return data.Rows[0][funcName].ToString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public enum WRightName
|
||||
{
|
||||
/// <summary>
|
||||
/// 主檔
|
||||
/// </summary>
|
||||
Execute,
|
||||
/// <summary>
|
||||
/// 新增
|
||||
/// </summary>
|
||||
Insert,
|
||||
/// <summary>
|
||||
/// 更正
|
||||
/// </summary>
|
||||
Update,
|
||||
/// <summary>
|
||||
/// 刪除
|
||||
/// </summary>
|
||||
Delete,
|
||||
/// <summary>
|
||||
/// 查詢
|
||||
/// </summary>
|
||||
Search,
|
||||
/// <summary>
|
||||
/// 印表
|
||||
/// </summary>
|
||||
Print
|
||||
}
|
||||
|
||||
public class ProgramID
|
||||
{
|
||||
public const string 匯出基本資料 = "TR_EXPORT";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Timers;
|
||||
using System.IO;
|
||||
|
||||
namespace Wellan.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 檔案定時清除服務
|
||||
/// </summary>
|
||||
public class WDeleteFileService
|
||||
{
|
||||
private WDeleteFileService()
|
||||
{
|
||||
_deleteFilePatterns = new List<string>();
|
||||
_timer = new Timer();
|
||||
_timer.Enabled = false;
|
||||
_timer.Elapsed += new ElapsedEventHandler(DoDeleteFile);
|
||||
}
|
||||
|
||||
public static WDeleteFileService GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
_instance = new WDeleteFileService();
|
||||
return _instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 檔案刪除間隔時間,單位為秒。預設值為 600 秒
|
||||
/// </summary>
|
||||
public int Interval
|
||||
{
|
||||
get
|
||||
{
|
||||
return _interval;
|
||||
}
|
||||
set
|
||||
{
|
||||
_interval = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 要刪除多久之前的檔案,單位為秒。預設值為 600 秒
|
||||
/// </summary>
|
||||
public int FileAgeToDelete
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(_fileAge.TotalSeconds);
|
||||
}
|
||||
set
|
||||
{
|
||||
_fileAge = new TimeSpan(value * TimeSpan.TicksPerSecond);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 設定或取得檔案定時清除服務是否啟動
|
||||
/// </summary>
|
||||
public bool Enabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _enabled;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
if (_enabled)
|
||||
return;
|
||||
|
||||
_timer.Interval = _interval * 1000;
|
||||
_timer.AutoReset = true;
|
||||
_timer.Enabled = true;
|
||||
_enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_enabled)
|
||||
return;
|
||||
|
||||
_enabled = false;
|
||||
_timer.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>欲清除的檔案路徑及檔案名稱,檔案名稱可以使用萬用字元</para>
|
||||
/// <para>需要多個檔案路徑及檔案名稱時,請將所需的檔案路徑及檔案名稱一一加入</para>
|
||||
/// <para>例如:c:\temp\*.mdb 表示要清除 c:\temp 目錄下的 *.mdb</para>
|
||||
/// </summary>
|
||||
public List<string> DeletePatterns
|
||||
{
|
||||
get
|
||||
{
|
||||
return _deleteFilePatterns;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 實際執行刪除的動作
|
||||
/// </summary>
|
||||
private void DoDeleteFile(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
if (!_enabled)
|
||||
{
|
||||
_timer.Enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_timer.Enabled = false;
|
||||
try
|
||||
{
|
||||
foreach (string pattern in _deleteFilePatterns)
|
||||
{
|
||||
string namepart = Path.GetFileName(pattern);
|
||||
string pathPart = pattern.Substring(0, pattern.Length - namepart.Length);
|
||||
try
|
||||
{
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(pathPart);
|
||||
FileInfo[] matchFiles = dirInfo.GetFiles(namepart);
|
||||
foreach (FileInfo file in matchFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (DateTime.Now - file.LastWriteTime > _fileAge)
|
||||
file.Delete();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_timer.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static WDeleteFileService _instance = null;
|
||||
private List<string> _deleteFilePatterns = null;
|
||||
private Timer _timer = null;
|
||||
private int _interval = 600;
|
||||
private TimeSpan _fileAge = new TimeSpan(TimeSpan.TicksPerSecond * 600);
|
||||
private bool _enabled = false;
|
||||
|
||||
#region UNIT TEST
|
||||
public static void Main()
|
||||
{
|
||||
WDeleteFileService delSrv = WDeleteFileService.GetInstance();
|
||||
delSrv.DeletePatterns.Add(@"c:\temp\*.*");
|
||||
delSrv.Interval = 5;
|
||||
delSrv.FileAgeToDelete = 1;
|
||||
delSrv.Enabled = true;
|
||||
Console.WriteLine("Press ENTER to end program");
|
||||
Console.ReadLine();
|
||||
delSrv.Enabled = false;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Configuration;
|
||||
using System.Net;
|
||||
using System.Net.Mail;
|
||||
using System.Collections.Generic;
|
||||
using System.Timers;
|
||||
|
||||
/// <summary>
|
||||
/// 郵件傳送服務
|
||||
/// </summary>
|
||||
public class WMailSender
|
||||
{
|
||||
private static WMailSender _instance = null;
|
||||
private Queue<MailMessage> _queue = null;
|
||||
private bool _enabled = false;
|
||||
private int _interval = 30;
|
||||
private Timer _timer = null;
|
||||
private string _host = "";
|
||||
|
||||
private WMailSender()
|
||||
{
|
||||
_queue = new Queue<MailMessage>();
|
||||
|
||||
_timer = new Timer();
|
||||
_timer.Enabled = false;
|
||||
_timer.Elapsed += new ElapsedEventHandler(SendMailLoop);
|
||||
}
|
||||
|
||||
public static WMailSender GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
_instance = new WMailSender();
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public string Host
|
||||
{
|
||||
set
|
||||
{
|
||||
_host = value;
|
||||
}
|
||||
get
|
||||
{
|
||||
return _host;
|
||||
}
|
||||
}
|
||||
|
||||
public void Send(MailMessage message)
|
||||
{
|
||||
_queue.Enqueue(message);
|
||||
}
|
||||
|
||||
private void SendMailLoop(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
if (!_enabled)
|
||||
{
|
||||
_timer.Enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
_timer.Enabled = false;
|
||||
|
||||
SmtpClient _client = new SmtpClient();
|
||||
//_client.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
|
||||
try
|
||||
{
|
||||
while (_queue.Count > 0)
|
||||
{
|
||||
MailMessage message = _queue.Dequeue();
|
||||
try
|
||||
{
|
||||
_client.Send(message);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 如果傳送失敗,需重傳
|
||||
_queue.Enqueue(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_timer.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public int Interval
|
||||
{
|
||||
get
|
||||
{
|
||||
return _interval;
|
||||
}
|
||||
set
|
||||
{
|
||||
_interval = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return _enabled;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
if (_enabled)
|
||||
return;
|
||||
|
||||
_timer.Interval = _interval * 1000;
|
||||
_timer.AutoReset = true;
|
||||
_timer.Enabled = true;
|
||||
_enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_enabled)
|
||||
return;
|
||||
|
||||
_enabled = false;
|
||||
_timer.Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user