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); } /// /// Every item of one header row in a single INSERT, so a large upload does not make one /// round trip per item. /// internal static void InsertDetails(TransactionContext tc, List items) { if (items == null || items.Count == 0) return; List rows = new List(); 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); } /// HistorySalaryMonthlyID and EmployeeNo of every row of one salary month, in one query. 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); } /// /// EmployeeNo, Name, PayrollTypeID and Status of every employee — any payroll type, any /// status — whose Employee No is one of . /// internal static IDataReader GetEmployeesByNo(TransactionContext tc, IEnumerable 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 /// /// Deletes the given header rows and their items. is built by the /// service from IDs it read itself, never from user input. /// 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 }