Files
thinkyu/教育訓練系統/Web/DAC/簽核/DAC_表單簽核主檔2.cs
T
sryang 577060bc78 chore: 首次簽入 Thinkyu ASP.NET 專案
- 加入 Visual Studio / ASP.NET .gitignore
- 排除建置輸出、IDE 設定、NuGet packages、大型 MSI 安裝檔
2026-09-10 09:42:37 +08:00

1061 lines
47 KiB
C#

//
// 這個檔案是 表單簽核主檔 資料表的資料存取類別 檔案二
// 您可以修改這個檔案,加入您自訂的屬性與方法
//
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using WebLib;
using System.Data.SqlClient;
namespace Education
{
///<summary>
/// 表單簽核主檔 資料存取類別
///</summary>
public partial class DAC_表單簽核主檔 : WebLib.DAC
{
///<summary>
/// 給查詢畫面用的 Select 方法
///</summary>
[DataObjectMethod(DataObjectMethodType.Select)]
public 表單簽核主檔List Select()
{
表單簽核主檔List result = new 表單簽核主檔List();
IDataList list = result as IDataList;
DbCommand cmdSelect = NewCommand();
cmdSelect.CommandText = _select + _from + _where;
cmdSelect.CommandText += _order;
Select(cmdSelect, ref list);
return result;
}
///<summary>
/// InsertOne 之前會執行此方法
/// 在這裡可以做一些檢查或是自動編號等動作
/// 回傳 false 會打斷 InsertOne 的執行
///</summary>
protected virtual bool BeforeInsertOne(表單簽核主檔 value)
{
return true;
}
///<summary>
/// InsertOne 之後會執行此方法
///</summary>
protected virtual void AfterInsertOne(表單簽核主檔 value)
{
}
///<summary>
/// InsertOne 發生錯誤時會執行此方法
///</summary>
protected virtual void OnInsertOneError(Exception error, out bool handled)
{
handled = false;
}
///<summary>
/// UpdateOne 之前會執行此方法
/// 在這裡可以做一些檢查
/// 回傳 false 會打斷 UpdateOne 的執行
///</summary>
protected virtual bool BeforeUpdateOne(表單簽核主檔 value)
{
return true;
}
///<summary>
/// UpdateOne 之後會執行此方法
///</summary>
protected virtual void AfterUpdateOne(表單簽核主檔 value)
{
}
///<summary>
/// UpdateOne 發生錯誤時會執行此方法
///</summary>
protected virtual void OnUpdateOneError(Exception error, out bool handled)
{
handled = false;
}
///<summary>
/// DeleteOne 之前會執行此方法
/// 在這裡可以做一些檢查
/// 回傳 false 會打斷 DeleteOne 的執行
///</summary>
protected virtual bool BeforeDeleteOne(表單簽核主檔 value)
{
return true;
}
///<summary>
/// DeleteOne 之後會執行此方法
///</summary>
protected virtual void AfterDeleteOne(表單簽核主檔 value)
{
}
///<summary>
/// DeleteOne 之前會執行此方法
/// 在這裡可以做一些檢查
/// 回傳 false 會打斷 DeleteOne 的執行
///</summary>
protected virtual bool BeforeDeleteOne(int 簽核ID, int DB_APPNO)
{
return true;
}
///<summary>
/// DeleteOne 之後會執行此方法
///</summary>
protected virtual void AfterDeleteOne(int 簽核ID, int DB_APPNO)
{
}
///<summary>
/// DeleteOne 發生錯誤時會執行此方法
///</summary>
protected virtual void OnDeleteOneError(Exception error, out bool handled)
{
handled = false;
}
// 有另外加上去的屬性及方法,請加在這裡
/// <summary>
/// 取得最後簽核狀態
/// </summary>
public 表單簽核主檔 GetLastStatus(int 簽核ID)
{
表單簽核主檔List d = SelectOne(簽核ID);
if (d.Count > 0)
return d[0];
else
return null;
}
/// <summary>
/// 取得最後簽核狀態
/// </summary>
public 表單簽核主檔 GetLastStatus(string 表單類別ID, string 表單ID)
{
DbCommand cmd = NewCommand(
"SELECT TOP 1 簽核ID FROM " + _tableName +
" WHERE 表單類別ID=@表單類別ID AND 表單ID=@表單ID " +
" ORDER BY 簽核ID DESC ");
AddParam(cmd, "表單類別ID", 表單類別ID);
AddParam(cmd, "表單ID", 表單ID);
int id;
ExecuteScalar(cmd, out id);
return GetLastStatus(id);
}
/// <summary>
/// 取得某人的表單
/// </summary>
/// <param name="送簽人員"></param>
/// <returns></returns>
[DataObjectMethod(DataObjectMethodType.Select)]
public 表單簽核主檔List Select我的表單(string 送簽人員, DateTime 送簽日期1, DateTime 送簽日期2)
{
表單簽核主檔List result = new 表單簽核主檔List();
IDataList list = result as IDataList;
DbCommand cmdSelect = NewCommand();
cmdSelect.CommandText = _select + _from + _where
+ " and 送簽人員 = @送簽人員 ";
AddParam(cmdSelect, "送簽人員", 送簽人員);
if (送簽日期1.Ticks > 0 && 送簽日期2.Ticks > 0)
{
cmdSelect.CommandText += " and 送簽日期 >= @送簽日期1 and 送簽日期 < @送簽日期2 ";
AddParam(cmdSelect, "送簽日期1", 送簽日期1);
AddParam(cmdSelect, "送簽日期2", 送簽日期2.AddDays(1));
}
cmdSelect.CommandText += " order by 訓練課程企劃編號, 簽核ID ";
Select(cmdSelect, ref list);
return result;
}
/// <summary>
/// 判斷此表單是否可以送簽
/// </summary>
public bool 可送簽(string 表單類別ID, string 表單ID)
{
表單簽核主檔 status = GetLastStatus(表單類別ID, 表單ID);
if (status == null) // 沒有送簽過,可送簽
return true;
else if (status.最終結果 == "N") // 最後結果為不同意,可重新送簽
return true;
else if (status.撤簽 == "Y" && status.最終結果 == "Y") // 已撤簽,已撤簽簽核,可重新送簽
return true;
else
return false;
}
/// <summary>
/// 判斷此表單是否可以由這個使用者取消簽核
/// </summary>
public bool 可取消(string 表單類別ID, string 表單ID, string UserId)
{
表單簽核主檔 status = GetLastStatus(表單類別ID, 表單ID);
if (status == null) // 沒有送簽過,不可取消
return false;
else if (status.撤簽 == "Y") // 撤簽,不可取消
return false;
else if (status.最終簽核人員.CompareTo(UserId) != 0) // 不是這個人簽的表單,不可由這個人取消
return false;
else if (status.最終結果.Length == 0) // 這個人還沒有簽過,不可由這個人取消
return false;
else
return true;
}
/// <summary>
/// 判斷此表單是否可以由這個使用者簽核
/// </summary>
public bool 可簽核(string 表單類別ID, string 表單ID, string UserId)
{
表單簽核主檔 status = GetLastStatus(表單類別ID, 表單ID);
if (status == null) // 沒有送簽過
return false;
if (status.應簽關數 == status.已簽關數) // 已簽完
return false;
//else if (status.撤簽 == "Y")
// return false;
DAC_表單簽核明細 Dao表單簽核明細 = new DAC_表單簽核明細(conn);
表單簽核明細List canApprove = Dao表單簽核明細.GetCanApprove(status.簽核ID);
foreach (表單簽核明細 item in canApprove)
{
if (item.簽核人員.CompareTo(UserId) == 0)
return true;
}
return false;
}
/// <summary>
/// 判斷此表單是否可以由這個使用者撤簽
/// </summary>
public bool 可撤簽(string 表單類別ID, string 表單ID, string UserId)
{
表單簽核主檔 status = GetLastStatus(表單類別ID, 表單ID);
if (status == null) // 沒有送簽過
return false;
else if (status.撤簽 == "Y") // 撤簽
return false;
else if (status.應簽關數 == status.已簽關數 && status.最終結果 == "Y") // 已簽完
return false;
else if (status.送簽人員.CompareTo(UserId) != 0) // 不是這個人送簽的表單
return false;
else
return true;
}
/// <summary>
/// 將表單送簽
/// </summary>
/// <param name="表單類別ID">表單類別</param>
/// <param name="表單ID">表單編號</param>
/// <returns>簽核單號</returns>
public int 送簽(string 表單類別ID, string 表單ID, string 送簽人員, string 應簽核人員, string 表單ID格式,
int 訓練課程企劃編號, int 編號2)
{
if (!可送簽(表單類別ID, 表單ID))
return 0;
string 應簽關數;
switch (表單類別ID)
{
case "課程企劃":
case "教學日誌暨異常狀況":
case "訓練檢討報告":
case "處理結果追蹤":
default:
應簽關數 = "2"; // 2022-03-15 由 3 關改回 2 關
break;
}
bool wantClose = OpenConnection();
tran = conn.BeginTransaction();
try
{
// 新增簽核單
表單簽核主檔 newItem = new 表單簽核主檔()
{
表單類別ID = 表單類別ID,
表單ID = 表單ID,
應簽關數 = 應簽關數,
已簽關數 = "0",
撤簽 = "",
最終結果 = "",
送簽人員 = 送簽人員,
送簽日期 = DateTime.UtcNow.AddHours(8).Date,
表單ID格式 = 表單ID格式,
訓練課程企劃編號 = 訓練課程企劃編號,
編號2 = 編號2
};
int newId = InsertOne(newItem);
// 新增簽核明細
表單簽核明細 newDetail = new 表單簽核明細()
{
簽核ID = newId,
ID = "1",
簽核人員 = 應簽核人員
};
DAC_表單簽核明細 Dao表單簽核明細 = new DAC_表單簽核明細(conn);
Dao表單簽核明細.Transaction = tran;
Dao表單簽核明細.InsertOne(newDetail);
tran.Commit();
return newId;
}
catch (Exception error)
{
tran.Rollback();
throw error;
}
finally
{
CloseConnection(wantClose);
}
}
public bool 核准(int 簽核ID, string 本關人員, string 簽核意見, string 下關人員)
{
// 1. 取出目前的狀態
表單簽核主檔 status = GetLastStatus(簽核ID);
DAC_表單簽核明細 Dao表單簽核明細 = new DAC_表單簽核明細(conn);
int 本關 = DAC.GetInt32(status.已簽關數 == "" ? "0" : status.已簽關數);
//switch (status.已簽關數)
//{
// case "":
// case "0":
bool wantClose = OpenConnection();
bool haveNext = false;
tran = conn.BeginTransaction();
Dao表單簽核明細.Transaction = tran;
try
{
// 更新主檔狀態
status.已簽關數 = (本關 + 1).ToString();
status.最終結果 = "Y";
status.最終簽核人員 = 本關人員;
status.最終簽核日期 = DateTime.UtcNow.AddHours(8);
status.最終簽核意見 = 簽核意見;
UpdateOne(status);
// 更新明細檔狀態
表單簽核明細 lastDetail = Dao表單簽核明細.GetLast(簽核ID);
lastDetail.簽核人員 = 本關人員;
lastDetail.簽核日期 = DateTime.UtcNow.AddHours(8);
lastDetail.簽核結果 = "Y";
lastDetail.簽核意見 = 簽核意見;
Dao表單簽核明細.UpdateOne(lastDetail);
// 若還未簽核完,新增下關簽核明細
if (status.已簽關數 != status.應簽關數)
{
表單簽核明細 newDetail = new 表單簽核明細()
{
簽核ID = 簽核ID,
ID = (本關 + 2).ToString(),
簽核人員 = 下關人員
};
Dao表單簽核明細.InsertOne(newDetail);
haveNext = true;
}
// 已簽核完
else
{
// 課程企劃書要把已簽核欄位改成 Y
if (status.表單類別ID == "課程企劃")
{
DAC_訓練課程企劃 Dao訓練課程企劃 = new DAC_訓練課程企劃();
Dao訓練課程企劃.Connection = conn;
Dao訓練課程企劃.Transaction = tran;
訓練課程企劃List d = Dao訓練課程企劃.SelectOne(Convert.ToInt32(status.表單ID));
if (d.Count > 0)
{
d[0].已簽核 = "Y";
Dao訓練課程企劃.UpdateOne(d[0]);
}
}
}
tran.Commit();
return haveNext;
}
catch (Exception error)
{
tran.Rollback();
throw error;
}
finally
{
CloseConnection(wantClose);
}
// case "1":
// wantClose = OpenConnection();
// tran = conn.BeginTransaction();
// Dao表單簽核明細.Transaction = tran;
// try
// {
// // 更新主檔狀態
// status.已簽關數 = "2";
// status.最終結果 = "Y";
// status.最終簽核人員 = 本關人員;
// status.最終簽核日期 = DateTime.UtcNow.AddHours(8);
// status.最終簽核意見 = 簽核意見;
// UpdateOne(status);
// // 更新明細檔狀態
// 表單簽核明細 lastDetail = Dao表單簽核明細.GetLast(簽核ID);
// lastDetail.簽核人員 = 本關人員;
// lastDetail.簽核日期 = DateTime.UtcNow.AddHours(8);
// lastDetail.簽核結果 = "Y";
// lastDetail.簽核意見 = 簽核意見;
// Dao表單簽核明細.UpdateOne(lastDetail);
// // 課程企劃書要把已簽核欄位改成 Y
// if (status.表單類別ID == "課程企劃")
// {
// DAC_訓練課程企劃 Dao訓練課程企劃 = new DAC_訓練課程企劃();
// Dao訓練課程企劃.Connection = conn;
// Dao訓練課程企劃.Transaction = tran;
// 訓練課程企劃List d = Dao訓練課程企劃.SelectOne(Convert.ToInt32(status.表單ID));
// if (d.Count > 0)
// {
// d[0].已簽核 = "Y";
// Dao訓練課程企劃.UpdateOne(d[0]);
// }
// }
// tran.Commit();
// return false;
// }
// catch (Exception error)
// {
// tran.Rollback();
// throw error;
// }
// finally
// {
// CloseConnection(wantClose);
// }
//}
//return false;
}
public void 不核准(int 簽核ID, string 本關人員, string 簽核意見)
{
// 1. 取出目前的狀態
表單簽核主檔 status = GetLastStatus(簽核ID);
DAC_表單簽核明細 Dao表單簽核明細 = new DAC_表單簽核明細(conn);
int 本關 = DAC.GetInt32(status.已簽關數 == "" ? "0" : status.已簽關數);
//switch (status.已簽關數)
//{
// case "":
// case "0":
bool wantClose = OpenConnection();
tran = conn.BeginTransaction();
Dao表單簽核明細.Transaction = tran;
try
{
// 更新主檔狀態
status.已簽關數 = (本關 + 1).ToString();
status.最終結果 = "N";
status.最終簽核人員 = 本關人員;
status.最終簽核日期 = DateTime.UtcNow.AddHours(8);
status.最終簽核意見 = 簽核意見;
UpdateOne(status);
// 更新明細檔狀態
表單簽核明細 lastDetail = Dao表單簽核明細.GetLast(簽核ID);
lastDetail.簽核人員 = 本關人員;
lastDetail.簽核日期 = DateTime.UtcNow.AddHours(8);
lastDetail.簽核結果 = "N";
lastDetail.簽核意見 = 簽核意見;
Dao表單簽核明細.UpdateOne(lastDetail);
tran.Commit();
}
catch
{
tran.Rollback();
}
finally
{
CloseConnection(wantClose);
}
// break;
// case "1":
// wantClose = OpenConnection();
// tran = conn.BeginTransaction();
// Dao表單簽核明細.Transaction = tran;
// try
// {
// // 更新主檔狀態
// status.已簽關數 = "2";
// status.最終結果 = "N";
// status.最終簽核人員 = 本關人員;
// status.最終簽核日期 = DateTime.UtcNow.AddHours(8);
// status.最終簽核意見 = 簽核意見;
// UpdateOne(status);
// // 更新明細檔狀態
// 表單簽核明細 lastDetail = Dao表單簽核明細.GetLast(簽核ID);
// lastDetail.簽核人員 = 本關人員;
// lastDetail.簽核日期 = DateTime.UtcNow.AddHours(8);
// lastDetail.簽核結果 = "N";
// lastDetail.簽核意見 = 簽核意見;
// Dao表單簽核明細.UpdateOne(lastDetail);
// tran.Commit();
// }
// catch
// {
// tran.Rollback();
// }
// finally
// {
// CloseConnection(wantClose);
// }
// break;
//}
}
public void 取消簽核(int 簽核ID)
{
// 1. 取出目前的狀態
表單簽核主檔 status = GetLastStatus(簽核ID);
if (status == null)
return;
DAC_表單簽核明細 Dao表單簽核明細 = new DAC_表單簽核明細(conn);
switch (status.已簽關數)
{
case "":
case "0": // 還沒有簽,不動作
break;
#region 第一關取消
case "1": // 取消第一關已簽核,回到第一關未簽核,刪除第二關簽核明細
bool wantClose = OpenConnection();
tran = conn.BeginTransaction();
Dao表單簽核明細.Transaction = tran;
try
{
// 更新主檔狀態
status.已簽關數 = "0";
status.最終結果 = "";
status.最終簽核人員 = "";
status.最終簽核日期 = new DateTime();
status.最終簽核意見 = "";
UpdateOne(status);
// 更新明細檔狀態
表單簽核明細List detail = Dao表單簽核明細.SelectOneId(簽核ID);
foreach (表單簽核明細 detailItem in detail)
{
if (detailItem.ID == "1")
{
detailItem.簽核日期 = new DateTime();
detailItem.簽核結果 = "";
detailItem.簽核意見 = "";
Dao表單簽核明細.UpdateOne(detailItem);
continue;
}
if (detailItem.ID == "2")
{
Dao表單簽核明細.DeleteOne(detailItem);
}
}
tran.Commit();
}
catch
{
tran.Rollback();
}
finally
{
CloseConnection(wantClose);
}
break;
#endregion
#region 第二關取消
case "2": // 取消第二關已簽核,回到第二關未簽核,第一關已簽核,刪除第三關簽核明細
wantClose = OpenConnection();
tran = conn.BeginTransaction();
Dao表單簽核明細.Transaction = tran;
try
{
// 更新明細檔狀態
表單簽核明細List detail = Dao表單簽核明細.SelectOneId(簽核ID);
foreach (表單簽核明細 detailItem in detail)
{
if (detailItem.ID == "1")
{
// 更新主檔狀態
status.已簽關數 = "1";
status.最終結果 = detailItem.簽核結果;
status.最終簽核人員 = detailItem.簽核人員;
status.最終簽核日期 = detailItem.簽核日期;
status.最終簽核意見 = detailItem.簽核意見;
UpdateOne(status);
continue;
}
if (detailItem.ID == "2")
{
detailItem.簽核日期 = new DateTime();
detailItem.簽核結果 = "";
detailItem.簽核意見 = "";
Dao表單簽核明細.UpdateOne(detailItem);
}
if (detailItem.ID == "3")
{
Dao表單簽核明細.DeleteOne(detailItem);
}
}
// 課程企劃書要把已簽核欄位改成 N
if (status.表單類別ID == "課程企劃")
{
DAC_訓練課程企劃 Dao訓練課程企劃 = new DAC_訓練課程企劃();
Dao訓練課程企劃.Connection = conn;
Dao訓練課程企劃.Transaction = tran;
訓練課程企劃List d = Dao訓練課程企劃.SelectOne(Convert.ToInt32(status.表單ID));
if (d.Count > 0)
{
d[0].已簽核 = "N";
Dao訓練課程企劃.UpdateOne(d[0]);
}
}
tran.Commit();
}
catch
{
tran.Rollback();
}
finally
{
CloseConnection(wantClose);
}
break;
#endregion
#region 第三關取消
case "3": // 取消第三關已簽核,回到第三關未簽核,第二關已簽核
wantClose = OpenConnection();
tran = conn.BeginTransaction();
Dao表單簽核明細.Transaction = tran;
try
{
// 更新明細檔狀態
表單簽核明細List detail = Dao表單簽核明細.SelectOneId(簽核ID);
foreach (表單簽核明細 detailItem in detail)
{
if (detailItem.ID == "2")
{
// 更新主檔狀態
status.已簽關數 = "2";
status.最終結果 = detailItem.簽核結果;
status.最終簽核人員 = detailItem.簽核人員;
status.最終簽核日期 = detailItem.簽核日期;
status.最終簽核意見 = detailItem.簽核意見;
UpdateOne(status);
continue;
}
if (detailItem.ID == "3")
{
detailItem.簽核日期 = new DateTime();
detailItem.簽核結果 = "";
detailItem.簽核意見 = "";
Dao表單簽核明細.UpdateOne(detailItem);
}
}
// 課程企劃書要把已簽核欄位改成 N
if (status.表單類別ID == "課程企劃")
{
DAC_訓練課程企劃 Dao訓練課程企劃 = new DAC_訓練課程企劃();
Dao訓練課程企劃.Connection = conn;
Dao訓練課程企劃.Transaction = tran;
訓練課程企劃List d = Dao訓練課程企劃.SelectOne(Convert.ToInt32(status.表單ID));
if (d.Count > 0)
{
d[0].已簽核 = "N";
Dao訓練課程企劃.UpdateOne(d[0]);
}
}
tran.Commit();
}
catch
{
tran.Rollback();
}
finally
{
CloseConnection(wantClose);
}
break;
#endregion
#region 撤簽取消
case "D": // 取消 D 關已簽核,回到 D 關未簽核
wantClose = OpenConnection();
tran = conn.BeginTransaction();
Dao表單簽核明細.Transaction = tran;
try
{
// 更新主檔狀態
status.已簽關數 = "0";
status.最終結果 = "";
status.最終簽核人員 = "";
status.最終簽核日期 = new DateTime();
status.最終簽核意見 = "";
UpdateOne(status);
// 更新明細檔狀態
表單簽核明細List detail = Dao表單簽核明細.SelectOneId(簽核ID);
foreach (表單簽核明細 detailItem in detail)
{
if (detailItem.ID == "D")
{
detailItem.簽核日期 = new DateTime();
detailItem.簽核結果 = "";
detailItem.簽核意見 = "";
Dao表單簽核明細.UpdateOne(detailItem);
}
}
tran.Commit();
}
catch
{
tran.Rollback();
}
finally
{
CloseConnection(wantClose);
}
break;
#endregion
}
}
public void 撤簽(int 簽核ID, string 撤簽簽核人員)
{
// 1. 取出目前的狀態
表單簽核主檔 status = GetLastStatus(簽核ID);
if (status == null)
return;
bool wantClose = OpenConnection();
tran = conn.BeginTransaction();
try
{
表單簽核明細 newDetail;
// 已送簽但尚未簽核,抽單等於直接回到未簽核狀態
if (status.已簽關數 == "" || status.已簽關數 == "0")
{
// 更新主檔狀態
status.應簽關數 = "D";
status.撤簽 = "Y";
status.已簽關數 = "D";
status.最終結果 = "Y";
status.最終簽核人員 = "SYSTEM";
status.最終簽核日期 = DateTime.UtcNow.AddHours(8);
status.最終簽核意見 = "尚未簽核抽單,自動審批";
// 新增撤簽明細
newDetail = new 表單簽核明細()
{
簽核ID = status.簽核ID,
ID = "D",
簽核人員 = "SYSTEM",
簽核日期 = status.最終簽核日期,
簽核結果 = "Y",
簽核意見 = "尚未簽核抽單,自動審批"
};
//DAC_表單簽核明細 Dao表單簽核明細 = new DAC_表單簽核明細(conn);
//Dao表單簽核明細.Transaction = tran;
//Dao表單簽核明細.InsertOne(newDetail);
}
else
{
// 更新主檔狀態
status.應簽關數 = "D";
status.撤簽 = "Y";
status.已簽關數 = "";
status.最終結果 = "";
status.最終簽核人員 = "";
status.最終簽核日期 = new DateTime();
status.最終簽核意見 = "";
//UpdateOne(status);
// 新增撤簽明細
newDetail = new 表單簽核明細()
{
簽核ID = status.簽核ID,
ID = "D",
簽核人員 = 撤簽簽核人員
};
//DAC_表單簽核明細 Dao表單簽核明細 = new DAC_表單簽核明細(conn);
//Dao表單簽核明細.Transaction = tran;
//Dao表單簽核明細.InsertOne(newDetail);
}
UpdateOne(status);
DAC_表單簽核明細 Dao表單簽核明細 = new DAC_表單簽核明細(conn);
Dao表單簽核明細.Transaction = tran;
Dao表單簽核明細.InsertOne(newDetail);
tran.Commit();
}
catch (Exception error)
{
tran.Rollback();
throw error;
}
finally
{
CloseConnection(wantClose);
}
}
public void 撤簽核准(int 簽核ID, string 本關人員, string 簽核意見)
{
撤簽批示(簽核ID, 本關人員, true, 簽核意見);
}
public void 撤簽不核准(int 簽核ID, string 本關人員, string 簽核意見)
{
撤簽批示(簽核ID, 本關人員, false, 簽核意見);
}
private void 撤簽批示(int 簽核ID, string 本關人員, bool 簽核結果, string 簽核意見)
{
表單簽核主檔 status = GetLastStatus(簽核ID);
if (status == null)
return;
DAC_表單簽核明細 Dao表單簽核明細 = new DAC_表單簽核明細(conn);
bool wantClose = OpenConnection();
tran = conn.BeginTransaction();
Dao表單簽核明細.Transaction = tran;
try
{
// 更新主檔狀態
status.已簽關數 = "D";
status.最終結果 = 簽核結果 ? "Y" : "N";
status.最終簽核人員 = 本關人員;
status.最終簽核日期 = DateTime.UtcNow.AddHours(8);
status.最終簽核意見 = 簽核意見;
UpdateOne(status);
// 更新明細檔狀態
表單簽核明細 lastDetail = Dao表單簽核明細.GetLast(簽核ID);
lastDetail.簽核人員 = 本關人員;
lastDetail.簽核日期 = DateTime.UtcNow.AddHours(8);
lastDetail.簽核結果 = 簽核結果 ? "Y" : "N";
lastDetail.簽核意見 = 簽核意見;
Dao表單簽核明細.UpdateOne(lastDetail);
tran.Commit();
}
catch (Exception error)
{
tran.Rollback();
throw error;
}
finally
{
CloseConnection(wantClose);
}
}
public bool 表單可異動(string 表單類別ID, string 表單ID)
{
// 1. 取出目前的狀態
表單簽核主檔 status = GetLastStatus(表單類別ID, 表單ID);
if (status == null) // 尚未送簽,可異動
return true;
else if (status.應簽關數.CompareTo("D") != 0 &&
status.最終結果 == "N") // 不准,可異動
return true;
else if (status.應簽關數 == "D" &&
status.最終結果 == "Y") // 抽單核准,可異動
return true;
else if (status.應簽關數.CompareTo("D") != 0 &&
status.最終結果 == "Y") // 已簽准,不可異動
return false;
else if (status.應簽關數.CompareTo(status.已簽關數) != 0) // 簽核中,不可異動
return false;
else
return true;
}
[DataObjectMethod(DataObjectMethodType.Select)]
public 表單簽核主檔List Get可簽核的表單(string UserId)
{
表單簽核主檔List result = new 表單簽核主檔List();
IDataList list = result as IDataList;
DbCommand cmd = NewCommand();
// cmd.CommandText =
// @"select 簽核ID, A.表單類別ID, A.表單ID, 送簽人員, 送簽日期, 應簽關數, 已簽關數, 撤簽, 最終結果, 最終簽核人員, 最終簽核日期, 最終簽核意見, 表單ID格式, 訓練課程企劃編號, 編號2,
// DB_APPNO, DB_CRDAT, DB_CRUSR, DB_TRDAT, DB_TRUSR
// from
// (
// select 簽核ID, 表單類別ID, 送簽人員, 送簽日期, 應簽關數, 已簽關數, 撤簽, 最終結果, 最終簽核人員, 最終簽核日期, 最終簽核意見, 表單ID格式,
// DB_APPNO, DB_CRDAT, DB_CRUSR, DB_TRDAT, DB_TRUSR,
// case when CHARINDEX('|', 表單ID) = 0 then 表單ID else SUBSTRING(表單ID, 1, CHARINDEX('|', 表單ID) - 1) end as 表單ID,
// case when CHARINDEX('|', 表單ID) = 0 then '' else SUBSTRING(表單ID, CHARINDEX('|', 表單ID) + 1, 10) end as 表單ID2
// from 表單簽核主檔
// ) AS A
// join
// (
// select 1 as 表單順序, '課程企劃' as 表單類別ID, CAST(編號 AS NVARCHAR(10)) as 表單ID, '' AS 表單ID2, 顯示編號 as 訓練課程編號 from 訓練課程企劃
// union all
// select 2 as 表單順序, '場地遴選' as 表單類別ID, CAST(課程企劃編號 AS NVARCHAR(10)) as 表單ID, '' AS 表單ID2,
// (select top 1 顯示編號 from 訓練課程企劃 where 場地遴選.課程企劃編號=訓練課程企劃.編號) as 訓練課程編號 from 場地遴選
// union all
// select 3 as 表單順序, '講師遴選' as 表單類別ID, CAST(課程企劃編號 AS NVARCHAR(10)) as 表單ID, CAST(課程序號 AS NVARCHAR(10)) AS 表單ID2,
// (select top 1 顯示編號 from 訓練課程企劃 where 講師遴選.課程企劃編號=訓練課程企劃.編號) as 訓練課程編號 from 講師遴選
// union all
// select 4 as 表單順序, '訓練檢討報告' as 表單類別ID, CAST(訓練課程企劃編號 AS NVARCHAR(10)) as 表單ID, '' AS 表單ID2,
// (select top 1 顯示編號 from 訓練課程企劃 where 訓練檢討報告.訓練課程企劃編號=訓練課程企劃.編號) as 訓練課程編號 from 訓練檢討報告
// union all
// select 5 as 表單順序, '教學日誌暨異常狀況' as 表單類別ID, CAST(課程企劃編號 AS NVARCHAR(10)) as 表單ID, CAST(課程序號 AS NVARCHAR(10)) AS 表單ID2,
// (select top 1 顯示編號 from 訓練課程企劃 where 教學日誌.課程企劃編號=訓練課程企劃.編號) as 訓練課程編號 from 教學日誌
// union all
// select 6 as 表單順序, '教育訓練效益追蹤調查表' as 表單類別ID, CAST(訓練課程企劃編號 AS NVARCHAR(10)) as 表單ID, CAST(填表序號 AS NVARCHAR(10)) AS 表單ID2,
// (select top 1 顯示編號 from 訓練課程企劃 where 訓練效益.訓練課程企劃編號=訓練課程企劃.編號) as 訓練課程編號 from 訓練效益
// ) as B on A.表單類別ID=B.表單類別ID and A.表單ID=B.表單ID and A.表單ID2=B.表單ID2
// where 簽核ID in (
// select 簽核ID from 表單簽核明細 A
// where 關ID = (select max(B.關ID) from 表單簽核明細 B where A.簽核ID=B.簽核ID)
// and (簽核結果 = '' or 簽核結果 is null)
// and 簽核人員 = @簽核人員
// )
// order by B.訓練課程編號, B.表單順序
// ";
cmd.CommandText = _select + _from +
@" where 簽核ID in (
select 簽核ID from 表單簽核明細 A
where 關ID = (select max(B.關ID) from 表單簽核明細 B where A.簽核ID=B.簽核ID)
and (簽核結果 = '' or 簽核結果 is null)
and 簽核人員 = @簽核人員
)
order by 訓練課程企劃編號, 簽核ID";
AddParam(cmd, "簽核人員", UserId);
Select(cmd, ref list);
return result;
}
[DataObjectMethod(DataObjectMethodType.Select)]
public 表單簽核主檔List Get已簽核的表單(string UserId)
{
表單簽核主檔List result = new 表單簽核主檔List();
IDataList list = result as IDataList;
DbCommand cmd = NewCommand();
cmd.CommandText =
// @"select 簽核ID, A.表單類別ID, A.表單ID, 送簽人員, 送簽日期, 應簽關數, 已簽關數, 撤簽, 最終結果, 最終簽核人員, 最終簽核日期, 最終簽核意見, 表單ID格式, 訓練課程企劃編號, 編號2,
// DB_APPNO, DB_CRDAT, DB_CRUSR, DB_TRDAT, DB_TRUSR
// from
// (
// select 簽核ID, 表單類別ID, 送簽人員, 送簽日期, 應簽關數, 已簽關數, 撤簽, 最終結果, 最終簽核人員, 最終簽核日期, 最終簽核意見, 表單ID格式,
// DB_APPNO, DB_CRDAT, DB_CRUSR, DB_TRDAT, DB_TRUSR,
// case when CHARINDEX('|', 表單ID) = 0 then 表單ID else SUBSTRING(表單ID, 1, CHARINDEX('|', 表單ID) - 1) end as 表單ID,
// case when CHARINDEX('|', 表單ID) = 0 then '' else SUBSTRING(表單ID, CHARINDEX('|', 表單ID) + 1, 10) end as 表單ID2
// from 表單簽核主檔
// ) AS A
// join
// (
// select 1 as 表單順序, '課程企劃' as 表單類別ID, CAST(編號 AS NVARCHAR(10)) as 表單ID, '' AS 表單ID2, 顯示編號 as 訓練課程編號 from 訓練課程企劃
// union all
// select 2 as 表單順序, '場地遴選' as 表單類別ID, CAST(課程企劃編號 AS NVARCHAR(10)) as 表單ID, '' AS 表單ID2,
// (select top 1 顯示編號 from 訓練課程企劃 where 場地遴選.課程企劃編號=訓練課程企劃.編號) as 訓練課程編號 from 場地遴選
// union all
// select 3 as 表單順序, '講師遴選' as 表單類別ID, CAST(課程企劃編號 AS NVARCHAR(10)) as 表單ID, CAST(課程序號 AS NVARCHAR(10)) AS 表單ID2,
// (select top 1 顯示編號 from 訓練課程企劃 where 講師遴選.課程企劃編號=訓練課程企劃.編號) as 訓練課程編號 from 講師遴選
// union all
// select 4 as 表單順序, '訓練檢討報告' as 表單類別ID, CAST(訓練課程企劃編號 AS NVARCHAR(10)) as 表單ID, '' AS 表單ID2,
// (select top 1 顯示編號 from 訓練課程企劃 where 訓練檢討報告.訓練課程企劃編號=訓練課程企劃.編號) as 訓練課程編號 from 訓練檢討報告
// union all
// select 5 as 表單順序, '教學日誌暨異常狀況' as 表單類別ID, CAST(課程企劃編號 AS NVARCHAR(10)) as 表單ID, CAST(課程序號 AS NVARCHAR(10)) AS 表單ID2,
// (select top 1 顯示編號 from 訓練課程企劃 where 教學日誌.課程企劃編號=訓練課程企劃.編號) as 訓練課程編號 from 教學日誌
// union all
// select 6 as 表單順序, '教育訓練效益追蹤調查表' as 表單類別ID, CAST(訓練課程企劃編號 AS NVARCHAR(10)) as 表單ID, CAST(填表序號 AS NVARCHAR(10)) AS 表單ID2,
// (select top 1 顯示編號 from 訓練課程企劃 where 訓練效益.訓練課程企劃編號=訓練課程企劃.編號) as 訓練課程編號 from 訓練效益
// ) as B on A.表單類別ID=B.表單類別ID and A.表單ID=B.表單ID and A.表單ID2=B.表單ID2
// where 簽核ID in (
// select distinct 簽核ID from 表單簽核明細 A
// where (簽核結果 = 'Y' or 簽核結果 = 'N')
// and 簽核人員 = @簽核人員
// )
// order by B.訓練課程編號, B.表單順序
// ";
cmd.CommandText = _select + _from +
@" where 簽核ID in (
select distinct 簽核ID from 表單簽核明細 A
where (簽核結果 = 'Y' or 簽核結果 = 'N')
and 簽核人員 = @簽核人員
)
order by 訓練課程企劃編號, 簽核ID";
AddParam(cmd, "簽核人員", UserId);
Select(cmd, ref list);
return result;
}
}
///<summary>
/// 表單簽核主檔 資料集合類別
///</summary>
public partial class 表單簽核主檔List : List<表單簽核主檔>
{
// 有另外加上去的屬性及方法,請加在這裡
}
///<summary>
/// 表單簽核主檔 資料紀錄類別
///</summary>
public partial class 表單簽核主檔
{
// 有另外加上去的屬性及方法,請加在這裡
}
}