222 lines
7.5 KiB
C#
222 lines
7.5 KiB
C#
using Ease.Core.DataAccess;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.Utility;
|
|
using HRM.BO;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static iTextSharp.text.pdf.AcroFields;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
public class FMLoanAttachmentService : ServiceTemplate, IFMLoanAttachmentService
|
|
{
|
|
private void MapLoanAttachmentObject(FMLoanAttachment oLoanAttachment, DataReader oReader)
|
|
{
|
|
SetObjectID(oLoanAttachment, oReader.GetInt32("LoanAttachmentID").Value);
|
|
oLoanAttachment.LoanAppID = oReader.GetInt32("LoanAppID") == null ? 0 : oReader.GetInt32("LoanAppID").Value;
|
|
oLoanAttachment.LoanID = oReader.GetInt32("LoanID") == null ? 0 : oReader.GetInt32("LoanAppID").Value;
|
|
oLoanAttachment.LoanDocType = (enumLoanDocType)oReader.GetInt32("LoanDocType").Value;
|
|
oLoanAttachment.FileName = oReader.GetString("FileName");
|
|
oLoanAttachment.FileData = oReader.GetLob("FileData");
|
|
//oLoanAttachment.FileDataString = oReader.GetString("FileDataString");
|
|
oLoanAttachment.uploadDate = oReader.GetDateTime("uploadDate").Value;
|
|
oLoanAttachment.uploadBy = oReader.GetInt32("uploadBy").Value;
|
|
SetObjectState(oLoanAttachment, Ease.Core.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
FMLoanAttachment oLoanApplication = new FMLoanAttachment();
|
|
MapLoanAttachmentObject(oLoanApplication, oReader);
|
|
return oLoanApplication as T;
|
|
}
|
|
|
|
public void Save(TransactionContext tc, FMLoanAttachment attachment)
|
|
{
|
|
try
|
|
{
|
|
int attid = tc.GenerateID("FM_LoanAttachment", "LoanAttachmentID");
|
|
base.SetObjectID(attachment, attid);
|
|
FMLoanAttachmentDA.Insert(tc, attachment);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public void DeleteByLoanID(TransactionContext tc, int loanID)
|
|
{
|
|
try
|
|
{
|
|
FMLoanAttachmentDA.DeleteByLoanID(tc, loanID);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public void DeleteByLoanAppID(TransactionContext tc, int loanAppID)
|
|
{
|
|
try
|
|
{
|
|
FMLoanAttachmentDA.DeleteByLoanAppID(tc, loanAppID);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public FMLoanAttachment GetByLoanID(TransactionContext tc, int loanID)
|
|
{
|
|
try
|
|
{
|
|
FMLoanAttachment loanAttachment = new FMLoanAttachment();
|
|
DataReader oreader = new DataReader(FMLoanAttachmentDA.GetByLoanID(tc, loanID));
|
|
if (oreader.Read())
|
|
{
|
|
loanAttachment = this.CreateObject<FMLoanAttachment>(oreader);
|
|
}
|
|
return loanAttachment;
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
public FMLoanAttachment GetByLoanID(int loanID)
|
|
{
|
|
try
|
|
{
|
|
TransactionContext tc = TransactionContext.Begin();
|
|
FMLoanAttachment loanAttachment = new FMLoanAttachment();
|
|
DataReader oreader = new DataReader(FMLoanAttachmentDA.GetByLoanID(tc, loanID));
|
|
if (oreader.Read())
|
|
{
|
|
loanAttachment = this.CreateObject<FMLoanAttachment>(oreader);
|
|
}
|
|
tc.End();
|
|
return loanAttachment;
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
public FMLoanAttachment GetByLoanAppID(TransactionContext tc, int loanAppID)
|
|
{
|
|
try
|
|
{
|
|
|
|
FMLoanAttachment loanAttachment = new FMLoanAttachment();
|
|
DataReader oreader = new DataReader(FMLoanAttachmentDA.GetByLoanAppID(tc, loanAppID));
|
|
if (oreader.Read())
|
|
{
|
|
loanAttachment = this.CreateObject<FMLoanAttachment>(oreader);
|
|
}
|
|
return loanAttachment;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
public List<FMLoanAttachment> LoadLoanAttachments(TransactionContext tc, LoanApplication oLoanApplication)
|
|
{
|
|
List<FMLoanAttachment> oLoanAttachments = new List<FMLoanAttachment>();
|
|
FMLoanAttachment item = null;
|
|
try
|
|
{
|
|
DataTable dTLoanAttachment = GetLoanAttachmentsByLoanAppID(tc, oLoanApplication.LoanAppID);
|
|
|
|
if (dTLoanAttachment != null && dTLoanAttachment.Rows.Count > 0)
|
|
{
|
|
foreach (DataRow dr in dTLoanAttachment.Rows)
|
|
{
|
|
item = new FMLoanAttachment();
|
|
item.FileName = dr["filename"].ToString();
|
|
item.FileData = (byte[])(dr["filedata"]);
|
|
item.FileDataString = Convert.ToBase64String(item.FileData);
|
|
item.LoanAppID = (int)dr["loanappid"];
|
|
item.LoanAttachmentID = (int)dr["loanattachmentid"];
|
|
item.LoanDocType = (enumLoanDocType)dr["loandoctype"];
|
|
oLoanAttachments.Add(item);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
return oLoanAttachments;
|
|
}
|
|
internal static DataTable GetLoanAttachmentsByLoanAppID(TransactionContext tc, int LoanAppID)
|
|
{
|
|
|
|
DataSet Dset = new DataSet();
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
string sql = "";
|
|
sql = SQLParser.MakeSQL(@"SELECT * FROM FM_LoanAttachment WHERE LOANAPPID = %n", LoanAppID);
|
|
|
|
Dset = tc.ExecuteDataSet(sql);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
return Dset.Tables[0];
|
|
}
|
|
}
|
|
}
|