CEL_Payroll/Payroll.BO/Common/DataUploadException.cs

116 lines
4.1 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.Model;
using System.Data;
namespace Payroll.BO
{
[Serializable]
public class DataUploadException
{
ObjectsTemplate<ADParameterEmployee> oadparamemployees;
ObjectsTemplate<EmpAppraisalRating> oempAppraisalRatings = null;
private List<UploadErrorOrSuccess> _errorOrSuccessList;
public DataUploadException()
{
_errorOrSuccessList = new List<UploadErrorOrSuccess>();
}
public List<UploadErrorOrSuccess> ErrorOrSuccessList
{
get
{
return _errorOrSuccessList;
}
}
public void UploadException(int uploadId, DataTable _uploadData, DataUploadColumnDefinition oColumnDefinition)
{
switch (uploadId)
{
case (int)42:
{
this.UploadAppraisalPoint(_uploadData, oColumnDefinition);
break;
}
default:
break;
}
}
public void SaveException(int uploadId)
{
switch (uploadId)
{
case (int)42:
{
this.SaveAppraisalPoint();
break;
}
default:
break;
}
}
private void SaveAppraisalPoint()
{
try
{
if (oempAppraisalRatings != null && oempAppraisalRatings.Count >= 1)
{
EmpAppraisalRating.Save(oempAppraisalRatings);
}
}
catch (Exception ex)
{
throw new ServiceException(ex.Message);
}
}
private void UploadAppraisalPoint(DataTable _uploadData, DataUploadColumnDefinition oColumnDefinition)
{
List<Employee> oemployees = Employee.Get();
Employee oemployee = null;
int nRow = 0;
oempAppraisalRatings = new ObjectsTemplate<EmpAppraisalRating>();
ObjectsTemplate<AppraisalPoint> allpoints = AppraisalPoint.Get(EnumStatus.Active);
try
{
foreach (DataRow dr in _uploadData.Rows)
{
nRow = nRow + 1;
oemployee = oemployees.Find(delegate(Employee emp) { return emp.EmployeeNo == dr["Employee No"].ToString().Trim(); });
if (oemployee != null)
{
EmpAppraisalRating obEmpAppRating = new EmpAppraisalRating();
string ratingName = dr["Rating"].ToString().Trim();
var findRatingName = allpoints.Where(ob => ob.Name.ToLower() == ratingName.ToLower());
if (findRatingName.Count() > 0)
{
obEmpAppRating.AppraisalPointRatingID = findRatingName.First().ID;
obEmpAppRating.EmployeeID = oemployee.ID;
obEmpAppRating.AppraisalYear = Ease.CoreV35.Utility.Global.DateFunctions.LastDateOfYear(oColumnDefinition.ItemThreeSelectedDate.Value);
oempAppraisalRatings.Add(obEmpAppRating);
}
else
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Employee No.", nRow, "(" + dr["Employee No"].ToString() + ")" + "Rating not found in the existing data"));
}
}
else
{
_errorOrSuccessList.Add(UploadErrorOrSuccess.Create("Employee No.", nRow, "(" + dr["Employee No"].ToString() + ")" + "Employee not found for in the existing data"));
}
}
}
catch (Exception ex)
{
throw new ServiceException("Error occurred on row:" + nRow + " Reason:" + ex.Message);
}
}
}
}