// // 這個檔案是 數位課程觀看紀錄 資料表的資料存取類別 檔案二 // 您可以修改這個檔案,加入您自訂的屬性與方法 // 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 { /// /// 數位課程觀看紀錄 資料存取類別 /// public partial class DAC_數位課程觀看紀錄 : WebLib.DAC { #region 自動產生的資料存取方法 /// /// InsertOne 之前會執行此方法 /// 在這裡可以做一些檢查或是自動編號等動作 /// 回傳 false 會打斷 InsertOne 的執行 /// protected virtual bool BeforeInsertOne(數位課程觀看紀錄 value) { return true; } /// /// InsertOne 之後會執行此方法 /// protected virtual void AfterInsertOne(數位課程觀看紀錄 value) { } /// /// InsertOne 發生錯誤時會執行此方法 /// ///錯誤是否已經處理妥當 protected virtual void OnInsertOneError(Exception error, out bool handled) { handled = false; } /// /// UpdateOne 之前會執行此方法 /// 在這裡可以做一些檢查 /// 回傳 false 會打斷 UpdateOne 的執行 /// protected virtual bool BeforeUpdateOne(數位課程觀看紀錄 value) { return true; } /// /// UpdateOne 之後會執行此方法 /// protected virtual void AfterUpdateOne(數位課程觀看紀錄 value) { } /// /// UpdateOne 發生錯誤時會執行此方法 /// ///錯誤是否已經處理妥當 protected virtual void OnUpdateOneError(Exception error, out bool handled) { handled = false; } /// /// DeleteOne 之前會執行此方法 /// 在這裡可以做一些檢查 /// 回傳 false 會打斷 DeleteOne 的執行 /// protected virtual bool BeforeDeleteOne(數位課程觀看紀錄 value) { return true; } /// /// DeleteOne 之後會執行此方法 /// protected virtual void AfterDeleteOne(數位課程觀看紀錄 value) { } /// /// DeleteOne 之前會執行此方法 /// 在這裡可以做一些檢查 /// 回傳 false 會打斷 DeleteOne 的執行 /// protected virtual bool BeforeDeleteOne(int 課程編號, string 學員編號, int DB_APPNO) { return true; } /// /// DeleteOne 之後會執行此方法 /// protected virtual void AfterDeleteOne(int 課程編號, string 學員編號, int DB_APPNO) { } /// /// DeleteOne 發生錯誤時會執行此方法 /// ///錯誤是否已經處理妥當 protected virtual void OnDeleteOneError(Exception error, out bool handled) { handled = false; } #endregion // 有另外加上去的屬性及方法,請加在這裡 public void 報名(int 課程編號, string 學員編號, string userId) { 數位課程觀看紀錄List d = SelectOne(課程編號, 學員編號); if (d.Count == 0) { 數位課程觀看紀錄 newValue = new 數位課程觀看紀錄(); newValue.課程編號 = 課程編號; newValue.學員編號 = 學員編號; newValue.必看 = "Y"; newValue.DB_CRUSR = userId; InsertOne(newValue); } else { d[0].必看 = "Y"; d[0].DB_TRUSR = userId; UpdateOne(d[0]); } } public void 取消報名(int 課程編號, string 學員編號) { 數位課程觀看紀錄List d = SelectOne(課程編號, 學員編號); if (d.Count > 0) { if (d[0].觀看日期.Ticks == 0) DeleteOne(d[0]); } } public bool 是否報名(int 課程編號, string 學員編號) { 數位課程觀看紀錄List d = SelectOne(課程編號, 學員編號); return d.Count > 0; } public bool 是否觀看(int 課程編號, string 學員編號) { 數位課程觀看紀錄List d = SelectOne(課程編號, 學員編號); return (d.Count > 0 && d[0].觀看日期.Ticks > 0); } public void Insert(int 課程編號, string 學員編號, string userId) { 數位課程觀看紀錄List d = SelectOne(課程編號, 學員編號); if (d.Count == 0) { 數位課程觀看紀錄 newValue = new 數位課程觀看紀錄(); newValue.課程編號 = 課程編號; newValue.學員編號 = 學員編號; newValue.觀看日期 = DateTime.UtcNow.AddHours(8).Date; newValue.DB_CRUSR = userId; InsertOne(newValue); } else { d[0].觀看日期 = DateTime.UtcNow.AddHours(8).Date; UpdateOne(d[0]); } } [DataObjectMethod(DataObjectMethodType.Select)] public DataTable Select必修學員(int 課程編號) { DbCommand cmdSelect = NewCommand(); cmdSelect.CommandText = @"select A.學員編號, A.學員編號 + ' ' + B.BPNME as 學員姓名 from 數位課程觀看紀錄 A inner join BPSNView B on A.學員編號=B.BPENO where A.課程編號 = @課程編號 and A.必看 = 'Y' order by A.學員編號"; AddParam(cmdSelect, "課程編號", 課程編號); return Select(cmdSelect); } [DataObjectMethod(DataObjectMethodType.Select)] public DataTable Select觀看紀錄(string 學員編號) { DbCommand cmdSelect = NewCommand(); cmdSelect.CommandText = @"SELECT A.課程編號, A.學員編號, A.觀看日期, B.課程名稱, B.講師, B.課程簡介, B.長度, B.課程網址, B.課程文件, B.評量文件, C.BSSCR AS 課程類別 FROM 數位課程觀看紀錄 A INNER JOIN 數位課程 B ON A.課程編號=B.課程編號 LEFT OUTER JOIN BCLS C ON B.課程類別=C.BSCLS AND C.BSPAR='課程類別' WHERE 學員編號 = @學員編號 AND 觀看日期 IS NOT NULL ORDER BY A.課程編號"; AddParam(cmdSelect, "學員編號", 學員編號); return Select(cmdSelect); } } /// /// 數位課程觀看紀錄 資料集合類別 /// public partial class 數位課程觀看紀錄List : List<數位課程觀看紀錄> { // 有另外加上去的屬性及方法,請加在這裡 } /// /// 數位課程觀看紀錄 資料紀錄類別 /// public partial class 數位課程觀看紀錄 { // 有另外加上去的屬性及方法,請加在這裡 } }