// // 這個檔案是 心得報告討論 資料表的資料存取類別 檔案二 // 您可以修改這個檔案,加入您自訂的屬性與方法 // 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) { value.樓 = Next樓(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 樓, int DB_APPNO) { return true; } /// /// DeleteOne 之後會執行此方法 /// protected virtual void AfterDeleteOne(int 心得報告編號, int 樓, int DB_APPNO) { } /// /// DeleteOne 發生錯誤時會執行此方法 /// ///錯誤是否已經處理妥當 protected virtual void OnDeleteOneError(Exception error, out bool handled) { handled = false; } #endregion // 有另外加上去的屬性及方法,請加在這裡 public int Next樓(int 心得報告編號) { DbCommand cmdSelect = NewCommand(); cmdSelect.CommandText = @"select isnull(max(樓), 0) + 1 from " + _tableName + " where 心得報告編號 = @心得報告編號 "; AddParam(cmdSelect, "心得報告編號", 心得報告編號); int i; ExecuteScalar(cmdSelect, out i); return i; } [DataObjectMethod(DataObjectMethodType.Select)] public 心得報告討論List Select整棟(int 心得報告編號, bool 只包含上架) { 心得報告討論List result = new 心得報告討論List(); IDataList list = result as IDataList; DbCommand cmdSelect = NewCommand(); cmdSelect.CommandText = _select + _from + _where + " and 心得報告編號 = @心得報告編號 "; if (只包含上架) cmdSelect.CommandText += " and (下架 is null or 下架 = '' or 下架 = 'N') "; cmdSelect.CommandText += " order by 樓 "; AddParam(cmdSelect, "心得報告編號", 心得報告編號); Select(cmdSelect, ref list); return result; } public int Select討論數(int 心得報告編號, bool 只包含上架) { DbCommand cmdSelect = NewCommand(); cmdSelect.CommandText = "select count(1) from " + _tableName + " where 心得報告編號 = @心得報告編號 "; if (只包含上架) cmdSelect.CommandText += " and (下架 is null or 下架 = '' or 下架 = 'N') "; AddParam(cmdSelect, "心得報告編號", 心得報告編號); int i; ExecuteScalar(cmdSelect, out i); return i; } public void 下架(int 心得報告編號, int 樓) { 心得報告討論List d = SelectOne(心得報告編號, 樓); if (d.Count == 0) return; d[0].下架 = "Y"; UpdateOne(d[0]); } public void 上架(int 心得報告編號, int 樓) { 心得報告討論List d = SelectOne(心得報告編號, 樓); if (d.Count == 0) return; d[0].下架 = ""; UpdateOne(d[0]); } } /// /// 心得報告討論 資料集合類別 /// public partial class 心得報告討論List : List<心得報告討論> { // 有另外加上去的屬性及方法,請加在這裡 } /// /// 心得報告討論 資料紀錄類別 /// public partial class 心得報告討論 { // 有另外加上去的屬性及方法,請加在這裡 } }