403 lines
14 KiB
C#
403 lines
14 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)
|
|
{
|
|
// 刪除訓練課程,同時要刪除講師遴選資料
|
|
DAC_講師遴選 Dao講師遴選 = new DAC_講師遴選(conn);
|
|
講師遴選List d = Dao講師遴選.SelectOne(value.訓練課程企劃編號, value.課程序號);
|
|
if (d.Count > 0)
|
|
Dao講師遴選.DeleteOne(value.訓練課程企劃編號, value.課程序號, d[0].DB_APPNO);
|
|
|
|
// 刪除訓練課程,同時要刪除教材遴選資料
|
|
DAC_教材遴選 Dao教材遴選 = new DAC_教材遴選(conn);
|
|
教材遴選List d2 = Dao教材遴選.SelectOne(value.訓練課程企劃編號, value.課程序號);
|
|
if (d2.Count > 0)
|
|
Dao教材遴選.DeleteOne(value.訓練課程企劃編號, value.課程序號, d2[0].DB_APPNO);
|
|
}
|
|
|
|
///<summary>
|
|
/// DeleteOne 之前會執行此方法
|
|
/// 在這裡可以做一些檢查
|
|
/// 回傳 false 會打斷 DeleteOne 的執行
|
|
///</summary>
|
|
protected virtual bool BeforeDeleteOne(int 訓練課程企劃編號, int 課程序號, int DB_APPNO)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
///<summary>
|
|
/// DeleteOne 之後會執行此方法
|
|
///</summary>
|
|
protected virtual void AfterDeleteOne(int 訓練課程企劃編號, int 課程序號, int DB_APPNO)
|
|
{
|
|
}
|
|
|
|
///<summary>
|
|
/// DeleteOne 發生錯誤時會執行此方法
|
|
///</summary>
|
|
protected virtual void OnDeleteOneError(Exception error, out bool handled)
|
|
{
|
|
handled = false;
|
|
}
|
|
|
|
// 有另外加上去的屬性及方法,請加在這裡
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Select)]
|
|
public 訓練課程內容List SelectBy課程企劃(int 訓練課程企劃編號)
|
|
{
|
|
訓練課程內容List result = new 訓練課程內容List();
|
|
IDataList list = result as IDataList;
|
|
DbCommand cmdSelect = NewCommand();
|
|
cmdSelect.CommandText = _select + _from + _where
|
|
+ " and 訓練課程企劃編號 = @訓練課程企劃編號 "
|
|
+ " order by 節次 ";
|
|
AddParam(cmdSelect, "訓練課程企劃編號", 訓練課程企劃編號);
|
|
Select(cmdSelect, ref list);
|
|
return result;
|
|
}
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Select)]
|
|
public DataTable Select上課講師(int 訓練課程企劃編號)
|
|
{
|
|
DataTable result = new DataTable();
|
|
result.Columns.Add("課程序號", typeof(int));
|
|
result.Columns.Add("講師編號", typeof(int));
|
|
result.Columns.Add("講師姓名", typeof(string));
|
|
result.Columns.Add("電子郵件", typeof(string));
|
|
result.Columns.Add("通知發送狀態", typeof(string));
|
|
result.Columns.Add("訓練日期", typeof(DateTime));
|
|
result.Columns.Add("時間起", typeof(string));
|
|
result.Columns.Add("時間迄", typeof(string));
|
|
|
|
訓練課程內容List d = new 訓練課程內容List();
|
|
IDataList list = d as IDataList;
|
|
DbCommand cmdSelect = NewCommand();
|
|
cmdSelect.CommandText = _select + _from + _where
|
|
+ " and 訓練課程企劃編號 = @訓練課程企劃編號 "
|
|
+ " order by 節次 ";
|
|
AddParam(cmdSelect, "訓練課程企劃編號", 訓練課程企劃編號);
|
|
Select(cmdSelect, ref list);
|
|
|
|
DAC_講師 Dao講師 = new DAC_講師(conn);
|
|
DAC_講師遴選 Dao講師遴選 = new DAC_講師遴選(conn);
|
|
|
|
// 把每一節課的講師查出來
|
|
foreach (訓練課程內容 item in d)
|
|
{
|
|
講師 d1 = new DAC_GetData(conn).取得選定講師(item.訓練課程企劃編號, item.課程序號);
|
|
|
|
if (result.Select(String.Format("講師編號={0}", d1.編號)).Length == 0)
|
|
{
|
|
DataRow newRow = result.NewRow();
|
|
newRow["課程序號"] = d[0].課程序號;
|
|
newRow["講師編號"] = d1.編號;
|
|
newRow["講師姓名"] = d1.姓名;
|
|
newRow["電子郵件"] = d1.電子郵件;
|
|
newRow["通知發送狀態"] = d[0].通知發送狀態;
|
|
newRow["訓練日期"] = item.訓練日期;
|
|
newRow["時間起"] = item.時間起;
|
|
newRow["時間迄"] = item.時間迄;
|
|
result.Rows.Add(newRow);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Delete)]
|
|
public int DeleteBy課程企劃(int 訓練課程企劃編號)
|
|
{
|
|
DbCommand cmdDelete = NewCommand();
|
|
cmdDelete.CommandText =
|
|
@"delete from 訓練課程內容
|
|
where 1=1
|
|
and 訓練課程企劃編號 = @訓練課程企劃編號";
|
|
AddParam(cmdDelete, "訓練課程企劃編號", 訓練課程企劃編號);
|
|
int rowsAffected = ExecuteNonQuery(cmdDelete);
|
|
return rowsAffected;
|
|
}
|
|
|
|
public int Next課程序號(int 訓練課程企劃編號)
|
|
{
|
|
DbCommand cmd = NewCommand();
|
|
cmd.CommandText = @"SELECT ISNULL(MAX(課程序號), 0) + 1 FROM " + _tableName + " WHERE 訓練課程企劃編號=@訓練課程企劃編號";
|
|
AddParam(cmd, "訓練課程企劃編號", 訓練課程企劃編號);
|
|
int result;
|
|
ExecuteScalar(cmd, out result);
|
|
return result;
|
|
}
|
|
|
|
public int Next節次(int 訓練課程企劃編號)
|
|
{
|
|
DbCommand cmd = NewCommand();
|
|
cmd.CommandText = @"SELECT ISNULL(MAX(節次), 0) + 1 FROM " + _tableName + " WHERE 訓練課程企劃編號=@訓練課程企劃編號";
|
|
AddParam(cmd, "訓練課程企劃編號", 訓練課程企劃編號);
|
|
int result;
|
|
ExecuteScalar(cmd, out result);
|
|
return result;
|
|
}
|
|
|
|
public void 節次Up(int 訓練課程企劃編號, int 節次)
|
|
{
|
|
// 取出這一筆的資料,與節次是上一筆的資料
|
|
DbCommand cmd = NewCommand();
|
|
cmd.CommandText = @"SELECT 節次 FROM " + _tableName + " WHERE 訓練課程企劃編號=@訓練課程企劃編號 AND 節次=@節次";
|
|
AddParam(cmd, "訓練課程企劃編號", 訓練課程企劃編號);
|
|
AddParam(cmd, "節次", 節次);
|
|
int 節次1;
|
|
ExecuteScalar(cmd, out 節次1);
|
|
cmd.CommandText = @"SELECT TOP 1 節次 FROM " + _tableName + " WHERE 訓練課程企劃編號=@訓練課程企劃編號 AND 節次 < @節次 ORDER BY 節次 DESC";
|
|
AddParam(cmd, "訓練課程企劃編號", 訓練課程企劃編號);
|
|
AddParam(cmd, "節次", 節次);
|
|
int 節次2;
|
|
ExecuteScalar(cmd, out 節次2);
|
|
|
|
if (節次2 == 0)
|
|
return;
|
|
else
|
|
{
|
|
交換節次(訓練課程企劃編號, 節次1, 節次2);
|
|
}
|
|
}
|
|
|
|
public void 節次Down(int 訓練課程企劃編號, int 節次)
|
|
{
|
|
// 取出這一筆的資料,與節次是上一筆的資料
|
|
DbCommand cmd = NewCommand();
|
|
cmd.CommandText = @"SELECT 節次 FROM " + _tableName + " WHERE 訓練課程企劃編號=@訓練課程企劃編號 AND 節次=@節次";
|
|
AddParam(cmd, "訓練課程企劃編號", 訓練課程企劃編號);
|
|
AddParam(cmd, "節次", 節次);
|
|
int 節次1;
|
|
ExecuteScalar(cmd, out 節次1);
|
|
cmd.CommandText = @"SELECT TOP 1 節次 FROM " + _tableName + " WHERE 訓練課程企劃編號=@訓練課程企劃編號 AND 節次 > @節次 ORDER BY 節次";
|
|
AddParam(cmd, "訓練課程企劃編號", 訓練課程企劃編號);
|
|
AddParam(cmd, "節次", 節次);
|
|
int 節次2;
|
|
ExecuteScalar(cmd, out 節次2);
|
|
|
|
if (節次2 == 0)
|
|
return;
|
|
else
|
|
{
|
|
交換節次(訓練課程企劃編號, 節次1, 節次2);
|
|
}
|
|
}
|
|
|
|
private void 交換節次(int 訓練課程企劃編號, int 節次1, int 節次2)
|
|
{
|
|
DbCommand cmdUpdate = NewCommand();
|
|
cmdUpdate.CommandText = @"UPDATE " + _tableName + " SET 節次=@新節次 WHERE 訓練課程企劃編號=@訓練課程企劃編號 AND 節次=@節次";
|
|
AddParam(cmdUpdate, "新節次", 9999);
|
|
AddParam(cmdUpdate, "訓練課程企劃編號", 訓練課程企劃編號);
|
|
AddParam(cmdUpdate, "節次", 節次1);
|
|
ExecuteNonQuery(cmdUpdate);
|
|
|
|
AddParam(cmdUpdate, "新節次", 節次1);
|
|
AddParam(cmdUpdate, "訓練課程企劃編號", 訓練課程企劃編號);
|
|
AddParam(cmdUpdate, "節次", 節次2);
|
|
ExecuteNonQuery(cmdUpdate);
|
|
|
|
AddParam(cmdUpdate, "新節次", 節次2);
|
|
AddParam(cmdUpdate, "訓練課程企劃編號", 訓練課程企劃編號);
|
|
AddParam(cmdUpdate, "節次", 9999);
|
|
ExecuteNonQuery(cmdUpdate);
|
|
}
|
|
|
|
public void 重排節次(int 訓練課程企劃編號)
|
|
{
|
|
// 1. 所有節次 +10000
|
|
DbCommand cmdUpdate = NewCommand();
|
|
cmdUpdate.CommandText = @"UPDATE " + _tableName + " SET 節次=節次+10000 WHERE 訓練課程企劃編號=@訓練課程企劃編號 ";
|
|
AddParam(cmdUpdate, "訓練課程企劃編號", 訓練課程企劃編號);
|
|
ExecuteNonQuery(cmdUpdate);
|
|
|
|
// 2. 取出節次
|
|
DbCommand cmdSelect = NewCommand();
|
|
cmdSelect.CommandText = @"SELECT 節次 FROM " + _tableName + " WHERE 訓練課程企劃編號=@訓練課程企劃編號 ORDER BY 節次";
|
|
AddParam(cmdSelect, "訓練課程企劃編號", 訓練課程企劃編號);
|
|
DataTable dt = Select(cmdSelect);
|
|
|
|
// 3. 一一更新為新節次
|
|
int 節次 = 1;
|
|
cmdUpdate.CommandText = @"UPDATE " + _tableName + " SET 節次=@新節次 WHERE 訓練課程企劃編號=@訓練課程企劃編號 AND 節次=@節次";
|
|
foreach (DataRow r in dt.Rows)
|
|
{
|
|
AddParam(cmdUpdate, "新節次", 節次);
|
|
AddParam(cmdUpdate, "訓練課程企劃編號", 訓練課程企劃編號);
|
|
AddParam(cmdUpdate, "節次", r[0]);
|
|
ExecuteNonQuery(cmdUpdate);
|
|
節次++;
|
|
}
|
|
}
|
|
|
|
public void 標記已發送講師通知(int 訓練課程編號, int 課程序號, string UserId)
|
|
{
|
|
訓練課程內容List values = SelectOne(訓練課程編號, 課程序號);
|
|
if (values.Count > 0)
|
|
{
|
|
values[0].通知發送狀態 = "Y";
|
|
values[0].DB_TRUSR = UserId;
|
|
UpdateOne(values[0]);
|
|
}
|
|
}
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Select)]
|
|
public List<DateTime> Select訓練日期List(int 訓練課程編號)
|
|
{
|
|
List<DateTime> result = new List<DateTime>();
|
|
DbCommand cmdSelect = NewCommand();
|
|
cmdSelect.CommandText = @"select distinct [訓練日期] " + _from
|
|
+ @" where [訓練課程企劃編號]=@訓練課程企劃編號 "
|
|
+ @" order by [訓練日期] ";
|
|
AddParam(cmdSelect, "@訓練課程企劃編號", 訓練課程編號);
|
|
|
|
bool wantClose = false;
|
|
IDataReader reader = ExecuteReader(cmdSelect, out wantClose);
|
|
try
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
if (!reader.IsDBNull(0))
|
|
result.Add(reader.GetDateTime(0));
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
cmdSelect.Cancel();
|
|
reader.Close();
|
|
CloseConnection(wantClose);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
///<summary>
|
|
/// 訓練課程內容 資料集合類別
|
|
///</summary>
|
|
public partial class 訓練課程內容List : List<訓練課程內容>
|
|
{
|
|
// 有另外加上去的屬性及方法,請加在這裡
|
|
}
|
|
|
|
///<summary>
|
|
/// 訓練課程內容 資料紀錄類別
|
|
///</summary>
|
|
public partial class 訓練課程內容
|
|
{
|
|
// 有另外加上去的屬性及方法,請加在這裡
|
|
|
|
public static string Get起訖時間Str(object 時間起, object 時間迄)
|
|
{
|
|
string s時間起 = DAC.GetString(時間起);
|
|
string s時間迄 = DAC.GetString(時間迄);
|
|
|
|
if (s時間起.Length > 0 && s時間迄.Length > 0)
|
|
return s時間起 + " 至 " + s時間迄;
|
|
else if (s時間起.Length > 0)
|
|
return s時間起;
|
|
else if (s時間迄.Length > 0)
|
|
return s時間迄;
|
|
else
|
|
return "";
|
|
}
|
|
}
|
|
}
|