126 lines
4.9 KiB
C#
126 lines
4.9 KiB
C#
using Ease.Core.DataAccess;
|
|
using HRM.BO;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Data;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
#region HistorySalaryMonthlyDA
|
|
|
|
internal class HistorySalaryMonthlyDA
|
|
{
|
|
#region Constructor
|
|
|
|
private HistorySalaryMonthlyDA()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Insert function
|
|
|
|
internal static void Insert(TransactionContext tc, HistorySalaryMonthly item)
|
|
{
|
|
string sSql = SQLParser.MakeSQL(
|
|
"INSERT INTO HistorySalaryMonthly(HistorySalaryMonthlyID, SalaryMonth, EmployeeNo, Name," +
|
|
" Department, Designation, Location, CostCenter, Grade, IsConfirm, PayrollTypeID," +
|
|
" CreatedBy, CreatedDate)" +
|
|
" VALUES(%n, %d, %u, %u, %u, %u, %u, %u, %u, %u, %n, %n, %D)",
|
|
item.ID, item.SalaryMonth, item.EmployeeNo, item.Name,
|
|
item.Department, item.Designation, item.Location, item.CostCenter, item.Grade,
|
|
item.IsConfirm, item.PayrollTypeID,
|
|
item.CreatedBy, item.CreatedDate);
|
|
tc.ExecuteNonQuery(sSql);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Every item of one header row in a single INSERT, so a large upload does not make one
|
|
/// round trip per item.
|
|
/// </summary>
|
|
internal static void InsertDetails(TransactionContext tc, List<HistorySalaryMonthlyDetail> items)
|
|
{
|
|
if (items == null || items.Count == 0)
|
|
return;
|
|
|
|
List<string> rows = new List<string>();
|
|
foreach (HistorySalaryMonthlyDetail item in items)
|
|
{
|
|
rows.Add(SQLParser.MakeSQL("(%n, %n, %u, %u, %u, %n, %n)",
|
|
item.ID, item.HistorySalaryMonthlyID, item.EmployeeNo, item.ItemName, item.ItemSide,
|
|
item.Amount, item.Sequence));
|
|
}
|
|
|
|
string sSql = SQLParser.MakeSQL(
|
|
"INSERT INTO HistorySalaryMonthlyDetail(HistorySalaryMonthlyDetailID, HistorySalaryMonthlyID," +
|
|
" EmployeeNo, ItemName, ItemSide, Amount, Sequence) VALUES %q",
|
|
string.Join(", ", rows));
|
|
tc.ExecuteNonQuery(sSql);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Get Function
|
|
|
|
internal static IDataReader Get(TransactionContext tc, DateTime salaryMonth, int payrollTypeID)
|
|
{
|
|
return tc.ExecuteReader(
|
|
"SELECT * FROM HistorySalaryMonthly WHERE SalaryMonth=%d AND PayrollTypeID=%n ORDER BY EmployeeNo",
|
|
salaryMonth, payrollTypeID);
|
|
}
|
|
|
|
internal static IDataReader GetDetails(TransactionContext tc, DateTime salaryMonth, int payrollTypeID)
|
|
{
|
|
return tc.ExecuteReader(
|
|
"SELECT d.* FROM HistorySalaryMonthlyDetail d" +
|
|
" INNER JOIN HistorySalaryMonthly h ON h.HistorySalaryMonthlyID = d.HistorySalaryMonthlyID" +
|
|
" WHERE h.SalaryMonth=%d AND h.PayrollTypeID=%n" +
|
|
" ORDER BY d.HistorySalaryMonthlyID, d.Sequence",
|
|
salaryMonth, payrollTypeID);
|
|
}
|
|
|
|
/// <summary>HistorySalaryMonthlyID and EmployeeNo of every row of one salary month, in one query.</summary>
|
|
internal static IDataReader GetEmployeeNos(TransactionContext tc, DateTime salaryMonth, int payrollTypeID)
|
|
{
|
|
return tc.ExecuteReader(
|
|
"SELECT HistorySalaryMonthlyID, EmployeeNo FROM HistorySalaryMonthly" +
|
|
" WHERE SalaryMonth=%d AND PayrollTypeID=%n",
|
|
salaryMonth, payrollTypeID);
|
|
}
|
|
|
|
/// <summary>
|
|
/// EmployeeNo, Name, PayrollTypeID and Status of every employee — any payroll type, any
|
|
/// status — whose Employee No is one of <paramref name="employeeNos"/>.
|
|
/// </summary>
|
|
internal static IDataReader GetEmployeesByNo(TransactionContext tc, IEnumerable<string> employeeNos)
|
|
{
|
|
// Each number is quoted and escaped by MakeSQL's %u before it is joined into the IN list.
|
|
string list = string.Join(",", employeeNos.Select(x => SQLParser.MakeSQL("%u", x)));
|
|
return tc.ExecuteReader(
|
|
"SELECT EmployeeID, EmployeeNo, Name, PayrollTypeID, Status FROM Employee WHERE EmployeeNo IN (%q)", list);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Delete Function
|
|
|
|
/// <summary>
|
|
/// Deletes the given header rows and their items. <paramref name="ids"/> is built by the
|
|
/// service from IDs it read itself, never from user input.
|
|
/// </summary>
|
|
internal static void Delete(TransactionContext tc, string ids)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(ids))
|
|
return;
|
|
|
|
tc.ExecuteNonQuery("DELETE FROM HistorySalaryMonthlyDetail WHERE HistorySalaryMonthlyID IN (%q)", ids);
|
|
tc.ExecuteNonQuery("DELETE FROM HistorySalaryMonthly WHERE HistorySalaryMonthlyID IN (%q)", ids);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
}
|