using System; using Payroll.BO; using System.Data; using System.Linq; using Ease.CoreV35.Model; using System.Data.SqlClient; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Ease.CoreV35.DataAccess.SQL; namespace Payroll.Service { #region MailSenderErrorListDA internal class MailSenderErrorListDA { #region Constructor private MailSenderErrorListDA() { } #endregion #region Insert function internal static void Insert(TransactionContext tc, MailSenderErrorList item) { tc.ExecuteNonQuery("INSERT INTO MailSenderErrorList(MailSenderErrorListID,BatchNo,ToEmpID, ReceiveTime, SendTime, IsSuccessfull, Reason, [To], CC, Subject,Attachments,[From])" + " VALUES(%n,%n,%n,%D, %D, %b, %s, %s, %s, %s,%s,%s)", item.ID.Integer, DataReader.GetNullValue(item.BatchNo, IDType.Integer), DataReader.GetNullValue(item.ToEmpID, IDType.Integer), item.ReceiveTime, item.SendTime, false, item.Reason, item.To, item.CC, item.Subject, item.Attachments, item.From); } #endregion #region Update function internal static void Update(TransactionContext tc, MailSenderErrorList item) { tc.ExecuteNonQuery("UPDATE MailSenderErrorList SET BatchNo=%n,ToEmpID=%n,[From]=%s, ReceiveTime=%D, SendTime=%D, IsSuccessfull=%b, Reason=%s, [To]=%s, CC=%s, Subject=%s,Attachments=%s" + "WHERE MailSenderErrorListID=%n", DataReader.GetNullValue(item.BatchNo, IDType.Integer), DataReader.GetNullValue(item.ToEmpID, IDType.Integer), item.From, item.ReceiveTime, item.SendTime, item.IsSuccessfull, item.Reason, item.To, item.CC, item.Subject, item.Attachments, item.ID.Integer); } internal static void UpdateSendStatus(TransactionContext tc,int nID, bool bStatus) { tc.ExecuteNonQuery("UPDATE MailSenderErrorList SET IsSuccessfull=%b" + "WHERE MailSenderErrorListID=%n", bStatus,nID); } public static void UpdateBody(SqlConnection connection, ID id, byte[] body) { SqlCommand command = new SqlCommand("UPDATE MailSenderErrorList SET " + "Body=@BODY WHERE MailSenderErrorListID=@ID ", connection); command.Parameters.Add("@ID", SqlDbType.Int).Value = id.Integer; command.Parameters.Add("@BODY", SqlDbType.Image, body.Length).Value = body; connection.Open(); command.ExecuteNonQuery(); } #endregion #region Get Function internal static IDataReader Get(TransactionContext tc) { return tc.ExecuteReader("SELECT * FROM MailSenderErrorList Order By MailSenderErrorListID"); } internal static IDataReader Get(TransactionContext tc, ID nID) { return tc.ExecuteReader("SELECT * FROM MailSenderErrorList Where MailSenderErrorListID=%n",nID.Integer ); } internal static DataTable GetBatchNoWiseErrorList(TransactionContext tc) { string sql = SQLParser.MakeSQL(@"SELECT ms.BatchNo,ms.[Subject],ms.SendTime,COUNT(*) AS MailCount FROM MailSenderErrorList ms WHERE ms.IsSuccessfull=0 GROUP BY BatchNo,ms.SendTime,ms.[Subject] ORDER BY ms.BatchNo"); return tc.ExecuteDataSet(sql).Tables[0]; } public static IDataReader GetByBatch(TransactionContext tc, int batchNo) { return tc.ExecuteReader("SELECT * FROM MailSenderErrorList ms WHERE ms.IsSuccessfull=0 AND BatchNo=%n",batchNo); } public static SqlDataReader GetBody(SqlConnection connection, int nMailID) { SqlCommand command = new SqlCommand("SELECT Body FROM MailSenderErrorList WHERE MailSenderErrorListID=@ID", connection); command.Parameters.Add("@ID", SqlDbType.Int).Value = nMailID; SqlDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess); return reader; } #endregion #region Delete function internal static void Delete(TransactionContext tc, ID nID) { tc.ExecuteNonQuery("DELETE FROM [MailSenderErrorList] Where MailSenderErrorListID=%n",nID.Integer); } #endregion } #endregion }