using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.DataAccess; using Payroll.BO; using System.Data; using Ease.CoreV35.Model; using Payroll.BO; using System.Data.SqlClient; namespace Payroll.Service.Attendence { #region AccessCardDA internal class AccessCardDA { #region Constructor private AccessCardDA() { } #endregion #region Insert function internal static void Insert(TransactionContext tc, AccessCard item) { tc.ExecuteNonQuery("INSERT INTO AccessCard(AccessCardID, CardNumber, TypeID,Status)" + " VALUES(%n, %s, %n, %n)", item.ID.Integer, item.CardNumber, item.TypeID.Integer, item.Status); //SqlCommand cmd = new SqlCommand(); //tc.ExecuteNonQuery(CommandType.StoredProcedure, "InsertUser", item.ID.Integer, item.CardNumber, item.TypeID.Integer, item.Status); } #endregion #region Update function internal static void Update(TransactionContext tc, AccessCard item) { tc.ExecuteNonQuery("UPDATE AccessCard SET CardNumber=%s, TypeID=%n, Status=%n" + " WHERE AccessCardID=%n", item.CardNumber, item.TypeID.Integer, item.Status, item.ID.Integer); } internal static void UpdateStatus(TransactionContext tc, ID cardID, EnumCardStatus status) { tc.ExecuteNonQuery("UPDATE AccessCard SET Status=%n WHERE AccessCardID=%n", status, cardID.Integer); } #endregion #region Get Function internal static IDataReader Get(TransactionContext tc) { return tc.ExecuteReader("SELECT * FROM AccessCard"); } internal static IDataReader Get(TransactionContext tc, EnumCardStatus status) { return tc.ExecuteReader("SELECT * FROM AccessCard WHERE Status=%n", status); } internal static IDataReader Get(TransactionContext tc, params EnumCardStatus[] status) { StringBuilder statusEnums = new StringBuilder(); if (status != null) { for (int i = 0; i < status.Length; ++i) { statusEnums.Append((int)status[i]); statusEnums.Append(", "); } } if (statusEnums.Length > 2) { statusEnums.Remove(statusEnums.Length - 2, 2); return tc.ExecuteReader("SELECT * FROM AccessCard WHERE Status IN (%q)", statusEnums.ToString()); } else { return tc.ExecuteReader("SELECT * FROM AccessCard"); } } internal static IDataReader Get(TransactionContext tc, ID nID) { return tc.ExecuteReader("SELECT * FROM AccessCard WHERE AccessCardID=%n", nID.Integer); } internal static IDataReader Get(TransactionContext tc, string CardNumber) { return tc.ExecuteReader("SELECT * FROM AccessCard WHERE CardNumber=%s", CardNumber); } #endregion #region Delete function internal static void Delete(TransactionContext tc, ID nID) { tc.ExecuteNonQuery("DELETE FROM [AccessCard] WHERE AccessCardID=%n", nID.Integer); } #endregion #region IsExist internal static bool IsExist(TransactionContext tc, string CardNumber) { bool isExist = false; object obj = tc.ExecuteScalar("SELECT Count(*) from AccessCard Where CardNumber=%s", CardNumber); isExist = Convert.ToInt32(obj) > 0 ? true : false; return isExist; } #endregion } #endregion }