// // 這個檔案是 數位課程 資料表的資料存取類別 檔案二 // 您可以修改這個檔案,加入您自訂的屬性與方法 // 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 自動產生的資料存取方法 /// /// 給查詢畫面用的 Select 方法 /// [DataObjectMethod(DataObjectMethodType.Select)] public 數位課程List Select(bool noInputReturnAll, string 課程名稱, string 課程類別, string 講師, string 課程簡介) { 數位課程List result = new 數位課程List(); bool noInput = true; IDataList list = result as IDataList; DbCommand cmdSelect = NewCommand(); cmdSelect.CommandText = _select + _from + _where; if (課程名稱 != null && 課程名稱.Length > 0) { noInput = false; cmdSelect.CommandText += " and 課程名稱 like @課程名稱 "; AddParam(cmdSelect, "課程名稱", 課程名稱 + "%"); } if (課程類別 != null && 課程類別.Length > 0) { noInput = false; cmdSelect.CommandText += " and 課程類別 like @課程類別 "; AddParam(cmdSelect, "課程類別", 課程類別 + "%"); } if (講師 != null && 講師.Length > 0) { noInput = false; cmdSelect.CommandText += " and 講師 like @講師 "; AddParam(cmdSelect, "講師", 講師 + "%"); } if (課程簡介 != null && 課程簡介.Length > 0) { noInput = false; cmdSelect.CommandText += " and 課程簡介 like @課程簡介 "; AddParam(cmdSelect, "課程簡介", 課程簡介 + "%"); } cmdSelect.CommandText += _order; if (!noInputReturnAll && noInput) return result; Select(cmdSelect, ref list); return result; } /// /// 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 課程編號, int DB_APPNO) { return true; } /// /// DeleteOne 之後會執行此方法 /// protected virtual void AfterDeleteOne(int 課程編號, int DB_APPNO) { } /// /// DeleteOne 發生錯誤時會執行此方法 /// ///錯誤是否已經處理妥當 protected virtual void OnDeleteOneError(Exception error, out bool handled) { handled = false; } #endregion // 有另外加上去的屬性及方法,請加在這裡 [DataObjectMethod(DataObjectMethodType.Select)] public 數位課程List Select可看課程(string 學員編號) { 數位課程List result = new 數位課程List(); IDataList list = result as IDataList; DbCommand cmdSelect = NewCommand(); cmdSelect.CommandText = _select + _from + _where + @" and 開放觀看 = 'Y' or exists (select 1 from 數位課程觀看紀錄 where 數位課程.課程編號 = 數位課程觀看紀錄.課程編號 and 數位課程觀看紀錄.學員編號 = @學員編號) order by 課程編號"; AddParam(cmdSelect, "學員編號", 學員編號); Select(cmdSelect, ref list); return result; } [DataObjectMethod(DataObjectMethodType.Select)] public 數位課程List Select非開放課程() { 數位課程List result = new 數位課程List(); IDataList list = result as IDataList; DbCommand cmdSelect = NewCommand(); cmdSelect.CommandText = _select + _from + _where + @" and 開放觀看 <> 'Y' order by 課程編號"; Select(cmdSelect, ref list); return result; } } /// /// 數位課程 資料集合類別 /// public partial class 數位課程List : List<數位課程> { // 有另外加上去的屬性及方法,請加在這裡 } /// /// 數位課程 資料紀錄類別 /// public partial class 數位課程 { // 有另外加上去的屬性及方法,請加在這裡 } }