CEL_Payroll/Payroll.Service/Assets/DA/AssetDA.cs

101 lines
4.3 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.Model;
using System.Data.SqlClient;
using Ease.CoreV35.DataAccess;
using Payroll.BO;
using System.Data;
using Ease.CoreV35.DataAccess.SQL;
namespace Payroll.Service
{
public class AssetDA
{
#region Constructor
private AssetDA() { }
#endregion
#region Get
internal static IDataReader Get(TransactionContext tc, ID id)
{
return tc.ExecuteReader("SELECT * FROM Asset WHERE AssetID=%n", id.Integer);
}
internal static IDataReader Get(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM Asset");
}
internal static IDataReader Get(TransactionContext tc, Employee oEmployee, EnumAssetInventoryType assetType, bool defaultItem)
{
return tc.ExecuteReader("SELECT * FROM Asset where (AssignUserNo1=%s OR AssignUserNo2=%s) AND AssetType=%n AND DefaultItem=%b",
oEmployee.EmployeeNo, oEmployee.EmployeeNo, assetType, defaultItem);
}
internal static IDataReader Get(TransactionContext tc, Employee oEmployee, EnumAssetInventoryType assetType)
{
return tc.ExecuteReader("SELECT * FROM Asset where (AssignUserNo1=%s OR AssignUserNo2=%s) AND AssetType=%n ",
oEmployee.EmployeeNo, oEmployee.EmployeeNo, assetType);
}
internal static IDataReader Get(TransactionContext tc, EnumAssetInventoryType assetType)
{
return tc.ExecuteReader("SELECT * FROM Asset where AssetType=%n",
assetType);
}
internal static IDataReader GetLineManagerItem(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM Asset where IsLinemanager=%b ",true
);
}
internal static IDataReader Get(TransactionContext tc, string name)
{
return tc.ExecuteReader("SELECT * FROM Asset WHERE Name=%s", name);
}
#endregion
#region Insert
internal static void Insert(TransactionContext tc, Asset oAsset)
{
string sql = SQLParser.MakeSQL(@"INSERT INTO Asset(AssetID, Code, Name, Description,
BuyTime, Remarks, IsUsing,BuyPrice,Section,AssignUserId1,AssignUserId2,IsLinemanager,CreatedBy, CreationDate, AssetType, DefaultItem)
VALUES(%n, %s, %s, %s, %d, %s, %n,%n, %s, %n, %n,%b,%n,%d,%n,%b)",
oAsset.ID.Integer, oAsset.Code, oAsset.Name, oAsset.Description,
oAsset.BuyTime, oAsset.Remarks, Convert.ToInt32(oAsset.IsUsing),
oAsset.BuyPrice, oAsset.Section, DataReader.GetNullValue(oAsset.AssignUserId1, IDType.Integer), DataReader.GetNullValue(oAsset.AssignUserId2, IDType.Integer), oAsset.IsLinemanager, DataReader.GetNullValue(oAsset.CreatedBy.Integer),
DataReader.GetNullValue(oAsset.CreatedDate), oAsset.AssetType, oAsset.DefaultItem);
tc.ExecuteNonQuery(sql);
}
#endregion
#region Update
internal static void Update(TransactionContext tc, Asset oAsset)
{
string sSQL = SQLParser.MakeSQL("UPDATE Asset SET [Code]=%s,[Name]=%s,[Description]=%s," +
" [BuyTime]=%d,[Remarks]=%s,[IsUsing]=%n,[BuyPrice]=%n,[Section]=%s,[AssignUserId1]=%n,[AssignUserId2]=%n,[IsLinemanager]=%b," +
" [ModifiedBy]=%n,[ModifiedDate]=%d, AssetType=%n, DefaultItem=%b WHERE [AssetID]=%n",
oAsset.Code, oAsset.Name,oAsset.Description,oAsset.BuyTime,
oAsset.Remarks, oAsset.IsUsing, oAsset.BuyPrice, oAsset.Section, DataReader.GetNullValue(oAsset.AssignUserId1,IDType.Integer), DataReader.GetNullValue(oAsset.AssignUserId2,IDType.Integer),oAsset.IsLinemanager,
DataReader.GetNullValue(oAsset.ModifiedBy.Integer),
DataReader.GetNullValue(oAsset.ModifiedDate), oAsset.AssetType, oAsset.DefaultItem,
oAsset.ID.Integer);
tc.ExecuteNonQuery(sSQL);
}
#endregion
#region Delete
internal static void Delete(TransactionContext tc, ID id)
{
tc.ExecuteNonQuery("DELETE FROM [Asset] WHERE AssetID=%n", id.Integer);
}
#endregion
}
}