423 lines
12 KiB
C#
423 lines
12 KiB
C#
//
|
|
// 這個檔案是 組織圖 資料表的資料存取類別 檔案一
|
|
// 請不要修改這個檔案,重新產生資料存取類別時,這個檔案會被覆蓋掉
|
|
//
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
using System.Transactions;
|
|
using WebLib;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace Education
|
|
{
|
|
///<summary>
|
|
/// 組織圖 資料存取類別
|
|
///</ summary>
|
|
[DataObject]
|
|
public partial class DAC_組織圖 : WebLib.DAC
|
|
{
|
|
private string _tableName = "組織圖";
|
|
private string _select = "select 組織ID, 組織名稱, 組織類別ID, 上層ID, 排序, 部門主管, DB_APPNO, DB_CRDAT, DB_CRUSR, DB_TRDAT, DB_TRUSR";
|
|
private string _insert = "組織名稱, 組織類別ID, 上層ID, 排序, 部門主管, DB_APPNO, DB_CRDAT, DB_CRUSR, DB_TRDAT, DB_TRUSR";
|
|
private string _insertValue = "@組織名稱, @組織類別ID, @上層ID, @排序, @部門主管, @DB_APPNO, @DB_CRDAT, @DB_CRUSR, @DB_TRDAT, @DB_TRUSR";
|
|
private string _from = " from 組織圖 ";
|
|
private string _where = " where 1=1 ";
|
|
private string _order = " order by 組織ID ";
|
|
|
|
public DAC_組織圖()
|
|
: base()
|
|
{
|
|
}
|
|
|
|
public DAC_組織圖(DbConnection conn)
|
|
: base(conn)
|
|
{
|
|
}
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Select)]
|
|
public 組織圖List SelectAll()
|
|
{
|
|
組織圖List result = new 組織圖List();
|
|
IDataList list = result as IDataList;
|
|
DbCommand cmdSelect = NewCommand();
|
|
cmdSelect.CommandText = _select + _from + _where + _order;
|
|
Select(cmdSelect, ref list);
|
|
return result;
|
|
}
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Select)]
|
|
public 組織圖List SelectOne(int 組織ID)
|
|
{
|
|
組織圖List result = new 組織圖List();
|
|
IDataList list = result as IDataList;
|
|
DbCommand cmdSelect = NewCommand();
|
|
cmdSelect.CommandText = _select + _from + _where
|
|
+ " and 組織ID = @組織ID "
|
|
;
|
|
AddParam(cmdSelect, "組織ID", 組織ID);
|
|
Select(cmdSelect, ref list);
|
|
return result;
|
|
}
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Insert)]
|
|
public int InsertOne(組織圖 value)
|
|
{
|
|
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
|
|
{
|
|
try
|
|
{
|
|
if (!BeforeInsertOne(value))
|
|
return -1;
|
|
|
|
DbCommand cmdInsert = NewCommand();
|
|
cmdInsert.CommandText =
|
|
"insert into 組織圖"
|
|
+ " (" + _insert + ")"
|
|
+ "values "
|
|
+ " (" + _insertValue + ");"
|
|
+ "select @@identity"
|
|
;
|
|
AddParam(cmdInsert, "組織名稱", value.組織名稱);
|
|
AddParam(cmdInsert, "組織類別ID", value.組織類別ID);
|
|
AddParam(cmdInsert, "上層ID", value.上層ID);
|
|
AddParam(cmdInsert, "排序", value.排序);
|
|
AddParam(cmdInsert, "部門主管", value.部門主管);
|
|
AddParam(cmdInsert, "DB_APPNO", 1);
|
|
AddParam(cmdInsert, "DB_CRDAT", DateTime.UtcNow.AddHours(8));
|
|
AddParam(cmdInsert, "DB_CRUSR", CurrentUserId);
|
|
AddParam(cmdInsert, "DB_TRDAT", DBNull.Value);
|
|
AddParam(cmdInsert, "DB_TRUSR", DBNull.Value);
|
|
int newId;
|
|
ExecuteScalar(cmdInsert, out newId);
|
|
AfterInsertOne(value);
|
|
ts.Complete();
|
|
return newId;
|
|
}
|
|
catch (Exception error)
|
|
{
|
|
bool handled;
|
|
OnInsertOneError(error, out handled);
|
|
if(!handled)
|
|
throw error;
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Update)]
|
|
public int UpdateOne(組織圖 value)
|
|
{
|
|
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
|
|
{
|
|
try
|
|
{
|
|
if (!BeforeUpdateOne(value))
|
|
return -1;
|
|
|
|
組織圖List oldValues = SelectOne(value.組織ID);
|
|
if (oldValues.Count == 0 || oldValues[0].DB_APPNO != value.DB_APPNO)
|
|
{
|
|
throw new DBConcurrencyException("在更新 \"組織圖\" 資料表時發生並行例外:找不到要更新的資料列");
|
|
}
|
|
DbCommand cmdUpdate = NewCommand();
|
|
cmdUpdate.CommandText =
|
|
@"update 組織圖
|
|
set
|
|
組織名稱 = @組織名稱 ,
|
|
組織類別ID = @組織類別ID ,
|
|
上層ID = @上層ID ,
|
|
排序 = @排序 ,
|
|
部門主管 = @部門主管 ,
|
|
DB_APPNO = DB_APPNO + 1,
|
|
DB_TRDAT = @DB_TRDAT,
|
|
DB_TRUSR = @DB_TRUSR
|
|
where 1=1
|
|
and 組織ID = @original_組織ID
|
|
and DB_APPNO = @original_DB_APPNO
|
|
";
|
|
AddParam(cmdUpdate, "組織名稱", value.組織名稱);
|
|
AddParam(cmdUpdate, "組織類別ID", value.組織類別ID);
|
|
AddParam(cmdUpdate, "上層ID", value.上層ID);
|
|
AddParam(cmdUpdate, "排序", value.排序);
|
|
AddParam(cmdUpdate, "部門主管", value.部門主管);
|
|
AddParam(cmdUpdate, "DB_TRDAT", DateTime.UtcNow.AddHours(8));
|
|
AddParam(cmdUpdate, "DB_TRUSR", CurrentUserId);
|
|
AddParam(cmdUpdate, "original_組織ID", value.組織ID);
|
|
AddParam(cmdUpdate, "original_DB_APPNO", value.DB_APPNO);
|
|
int rowsAffected = ExecuteNonQuery(cmdUpdate);
|
|
AfterUpdateOne(value);
|
|
ts.Complete();
|
|
return rowsAffected;
|
|
}
|
|
catch (Exception error)
|
|
{
|
|
bool handled;
|
|
OnUpdateOneError(error, out handled);
|
|
if(!handled)
|
|
throw error;
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Delete)]
|
|
public int DeleteOne(int 組織ID, int DB_APPNO)
|
|
{
|
|
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
|
|
{
|
|
try
|
|
{
|
|
if (!BeforeDeleteOne(組織ID, DB_APPNO))
|
|
return -1;
|
|
|
|
組織圖List oldValues = SelectOne(組織ID);
|
|
if (oldValues.Count == 0 || oldValues[0].DB_APPNO != DB_APPNO)
|
|
{
|
|
throw new DBConcurrencyException("在刪除 \"組織圖\" 資料表時發生並行例外:找不到要刪除的資料列");
|
|
}
|
|
DbCommand cmdDelete = NewCommand();
|
|
cmdDelete.CommandText =
|
|
@"delete from 組織圖
|
|
where 1=1
|
|
and 組織ID = @組織ID
|
|
and DB_APPNO = @DB_APPNO
|
|
";
|
|
AddParam(cmdDelete, "組織ID", 組織ID);
|
|
AddParam(cmdDelete, "DB_APPNO", DB_APPNO);
|
|
int rowsAffected = ExecuteNonQuery(cmdDelete);
|
|
AfterDeleteOne(組織ID, DB_APPNO);
|
|
ts.Complete();
|
|
return rowsAffected;
|
|
}
|
|
catch (Exception error)
|
|
{
|
|
bool handled;
|
|
OnDeleteOneError(error, out handled);
|
|
if(!handled)
|
|
throw error;
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
|
|
[DataObjectMethod(DataObjectMethodType.Delete)]
|
|
public int DeleteOne(組織圖 value)
|
|
{
|
|
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
|
|
{
|
|
try
|
|
{
|
|
if (!BeforeDeleteOne(value))
|
|
return -1;
|
|
|
|
組織圖List oldValues = SelectOne(value.組織ID);
|
|
if (oldValues.Count == 0 || oldValues[0].DB_APPNO != value.DB_APPNO)
|
|
{
|
|
throw new DBConcurrencyException("在刪除 \"組織圖\" 資料表時發生並行例外:找不到要刪除的資料列");
|
|
}
|
|
DbCommand cmdDelete = NewCommand();
|
|
cmdDelete.CommandText =
|
|
@"delete from 組織圖
|
|
where 1=1
|
|
and 組織ID = @組織ID
|
|
and DB_APPNO = @DB_APPNO
|
|
";
|
|
AddParam(cmdDelete, "組織ID", value.組織ID);
|
|
AddParam(cmdDelete, "DB_APPNO", value.DB_APPNO);
|
|
int rowsAffected = ExecuteNonQuery(cmdDelete);
|
|
AfterDeleteOne(value);
|
|
ts.Complete();
|
|
return rowsAffected;
|
|
}
|
|
catch (Exception error)
|
|
{
|
|
bool handled;
|
|
OnDeleteOneError(error, out handled);
|
|
if(!handled)
|
|
throw error;
|
|
return -1;
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool IsDuplicate(int 組織ID)
|
|
{
|
|
DbCommand cmdSelect = NewCommand();
|
|
cmdSelect.CommandText = "select count(1)" + _from + _where
|
|
+ " and 組織ID = @組織ID "
|
|
;
|
|
AddParam(cmdSelect, "組織ID", 組織ID);
|
|
int count;
|
|
ExecuteScalar(cmdSelect, out count);
|
|
return count > 0;
|
|
}
|
|
}
|
|
|
|
///<summary>
|
|
/// 組織圖 資料集合類別
|
|
///</summary>
|
|
public partial class 組織圖List : List<組織圖>, IDataList
|
|
{
|
|
public void Fill(DbDataReader reader)
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
組織圖 newItem = new 組織圖();
|
|
newItem.組織ID = DAC.GetInt32(reader[0]);
|
|
newItem.組織名稱 = DAC.GetString(reader[1]);
|
|
newItem.組織類別ID = DAC.GetInt32(reader[2]);
|
|
newItem.上層ID = DAC.GetInt32(reader[3]);
|
|
newItem.排序 = DAC.GetInt32(reader[4]);
|
|
newItem.部門主管 = DAC.GetString(reader[5]);
|
|
newItem.DB_APPNO = DAC.GetInt32(reader[6]);
|
|
newItem.DB_CRDAT = DAC.GetDateTime(reader[7]);
|
|
newItem.DB_CRUSR = DAC.GetString(reader[8]);
|
|
newItem.DB_TRDAT = DAC.GetDateTime(reader[9]);
|
|
newItem.DB_TRUSR = DAC.GetString(reader[10]);
|
|
Add(newItem);
|
|
}
|
|
}
|
|
}
|
|
|
|
///<summary>
|
|
/// 組織圖 資料紀錄類別
|
|
///</summary>
|
|
[Serializable]
|
|
public partial class 組織圖 : DataItemBase
|
|
{
|
|
private int _組織ID;
|
|
private string _組織名稱;
|
|
private int _組織類別ID;
|
|
private int _上層ID;
|
|
private int _排序;
|
|
private string _部門主管;
|
|
|
|
#region 資料欄位
|
|
///<summary>
|
|
///
|
|
///</summary>
|
|
[DataObjectField(true, false, false)]
|
|
public int 組織ID
|
|
{
|
|
get
|
|
{
|
|
return _組織ID;
|
|
}
|
|
set
|
|
{
|
|
if (value != _組織ID)
|
|
{
|
|
_組織ID = value;
|
|
OnPropertyChanged("組織ID");
|
|
}
|
|
}
|
|
}
|
|
|
|
///<summary>
|
|
///
|
|
///</summary>
|
|
[DataObjectField(false, false, false, 30)]
|
|
public string 組織名稱
|
|
{
|
|
get
|
|
{
|
|
return _組織名稱;
|
|
}
|
|
set
|
|
{
|
|
if (value != _組織名稱)
|
|
{
|
|
_組織名稱 = value;
|
|
OnPropertyChanged("組織名稱");
|
|
}
|
|
}
|
|
}
|
|
|
|
///<summary>
|
|
///
|
|
///</summary>
|
|
[DataObjectField(false, false, false)]
|
|
public int 組織類別ID
|
|
{
|
|
get
|
|
{
|
|
return _組織類別ID;
|
|
}
|
|
set
|
|
{
|
|
if (value != _組織類別ID)
|
|
{
|
|
_組織類別ID = value;
|
|
OnPropertyChanged("組織類別ID");
|
|
}
|
|
}
|
|
}
|
|
|
|
///<summary>
|
|
///
|
|
///</summary>
|
|
[DataObjectField(false, false, true)]
|
|
public int 上層ID
|
|
{
|
|
get
|
|
{
|
|
return _上層ID;
|
|
}
|
|
set
|
|
{
|
|
if (value != _上層ID)
|
|
{
|
|
_上層ID = value;
|
|
OnPropertyChanged("上層ID");
|
|
}
|
|
}
|
|
}
|
|
|
|
///<summary>
|
|
///
|
|
///</summary>
|
|
[DataObjectField(false, false, true)]
|
|
public int 排序
|
|
{
|
|
get
|
|
{
|
|
return _排序;
|
|
}
|
|
set
|
|
{
|
|
if (value != _排序)
|
|
{
|
|
_排序 = value;
|
|
OnPropertyChanged("排序");
|
|
}
|
|
}
|
|
}
|
|
|
|
///<summary>
|
|
///
|
|
///</summary>
|
|
[DataObjectField(false, false, true, 10)]
|
|
public string 部門主管
|
|
{
|
|
get
|
|
{
|
|
return _部門主管;
|
|
}
|
|
set
|
|
{
|
|
if (value != _部門主管)
|
|
{
|
|
_部門主管 = value;
|
|
OnPropertyChanged("部門主管");
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|