EchoTex_Payroll/HRM.BO/Common/DataUploadException.cs

111 lines
4.0 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using Ease.Core.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace HRM.BO
{
public class DataUploadException
{
//List<ADParameterEmployee> oadparamemployees;
List<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 = new List<Employee>(); //Employee.Get();
Employee oemployee = null;
int nRow = 0;
oempAppraisalRatings = new List<EmpAppraisalRating>();
List<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);
}
}
}
}