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 oadparamemployees; ObjectsTemplate oempAppraisalRatings = null; private List _errorOrSuccessList; public DataUploadException() { _errorOrSuccessList = new List(); } public List 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 oemployees = Employee.Get(); Employee oemployee = null; int nRow = 0; oempAppraisalRatings = new ObjectsTemplate(); ObjectsTemplate 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); } } } }