CEL_Payroll/Payroll.Report/UI/frmIndvEmpLeave.cs
2024-09-17 14:30:13 +06:00

154 lines
6.3 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Payroll.BO;
using Microsoft.Reporting.WinForms;
using Ease.CoreV35.Model;
using Ease.CoreV35.Utility;
using Ease.CoreV35;
namespace Payroll.Report
{
public partial class frmIndvEmpLeave : Form
{
private Employee _oEmployee;
string embeddedResource;
List<ReportDataSource> dataSource;
string caption;
public frmIndvEmpLeave()
{
InitializeComponent();
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnPreview_Click(object sender, EventArgs e)
{
Leave _oLeave = new Leave();
if (_oEmployee == null)
{
MessageBox.Show("Please select employee.", "Input validation", MessageBoxButtons.OK, MessageBoxIcon.Information);
ctlEmployee1.Focus();
return;
}
if (cmbLeaveType.Text == "")
{
MessageBox.Show("Please select a leave type");
return;
}
this.Cursor = Cursors.WaitCursor;
fReportViewer fViewer = new fReportViewer();
_oLeave = _oLeave.GetIDByName(cmbLeaveType.Text.Trim());
if (cmbLeaveType.Text != "All")
{
ShowDlg(_oEmployee, dtpFromDate.Value, dtpToDate.Value, _oLeave.ID.Integer);
}
else
{
ShowDlg(_oEmployee, dtpFromDate.Value, dtpToDate.Value, 0);
//resetValues();
}
this.Cursor = Cursors.Default;
}
public void ShowDlg(Employee employee, DateTime fromDate, DateTime toDate, int leaveType)
{
embeddedResource = "Payroll.Report.LeaveLedger.rdlc";
caption = "Emplotee Leave Ledger";
this.RefreshReport(employee, fromDate, toDate, leaveType);
fReportViewer fViewer = new fReportViewer();
fViewer.PreviewReport(dataSource, embeddedResource, caption);
//fViewer.ShowDialog();
//else
// MessageBox.Show("No data available.", "Leave", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void RefreshReport(Employee employee, DateTime fromDate, DateTime toDate, int leaveType)
{
DataRow oRow = null;
LeaveYear ly = new LeaveYear();
ObjectsTemplate<LeaveYear> _leaveYear = new ObjectsTemplate<LeaveYear>();
_leaveYear = LeaveYear.Get();
List<LeaveEntry> oLeaveEntrys = new List<LeaveEntry>();
DataTable oBody = new Payroll.Report.PayrollDataSet.dsEmpLeaveLedger.EmpLeaveLedgerDataTable();
DataTable oBody2 = new Payroll.Report.PayrollDataSet.dsEmpLeaveLedger.EmpInformationDataTable();
DataTable oBody3 = new Payroll.Report.PayrollDataSet.dsEmpLeaveLedger.LeaveYearDataTable();
DataTable oBody4 = new Payroll.Report.PayrollDataSet.dsEmpLeaveLedger.LeaveBalanceDataTable();
oLeaveEntrys = LeaveEntry.GetEmployeeWiseLeaveDetailReport(employee.ID.Integer, fromDate, toDate, leaveType);
ObjectsTemplate<Employee> oEmps = new ObjectsTemplate<Employee>();
oEmps.Add(_oEmployee);
ObjectsTemplate<EmpLeaveStatus> oCurrYearStatus = EmpLeaveStatus.CurrentYearStatus(oEmps, LeaveYear.GetCurrentYear(), EnumLeaveStatus.Approved);
foreach (EmpLeaveStatus oItem in oCurrYearStatus)
{
ly = _leaveYear.Where(x => x.ID.Integer == oItem.LeaveYearID).FirstOrDefault();
oBody4.Rows.Add(oItem.Leave.Description, oItem.OpeningBalance.ToString(),oItem.LeaveAvailed.ToString(), oItem.ClosingBalance.ToString(), oItem.CFDays.ToString());
}
{
oRow = oBody2.NewRow();
oRow["EmpNo"] = employee.EmployeeNo;
oRow["EmpName"] = employee.Name;
string id = employee.ID.ToString();
DataSet LineManager = MiscellaneousDataset.GetLineManager(id);
oRow["Department"] = employee.Department.Name;
oRow["Designation"] = employee.Designation.Name;
oRow["JoiningDate"] = employee.JoiningDate.ToString("dd MMM yyyy");
oRow["LeaveNotifier"] = employee.Name;
foreach (DataRow or in LineManager.Tables[0].Rows)
{
oRow["LeaveApprover"] = or["Name"];
}
oRow["LeavePeriod"] = ly.Name;
oBody2.Rows.Add(oRow);
}
if (oLeaveEntrys != null)
{
foreach (LeaveEntry le in oLeaveEntrys)
{
oBody.Rows.Add(le.Leave.Description, le.ApprovedFromDate.ToString("dd MMM yyyy"), le.ApprovedToDate.ToString("dd MMM yyyy"), le.ApprovedTotalDays, le.ErnLeaveRemarks, le.AppliedLeaveDate.ToString("dd MMM yyyy"),le.ApprovedLeaveDate.ToString("dd MMM yyyy"), le.LeaveStatus.ToString());
}
dataSource = new List<ReportDataSource>();
dataSource.Add(new ReportDataSource("dsEmpLeaveLedger_EmpLeaveLedger", oBody));
}
dataSource.Add(new ReportDataSource("dsEmpLeaveLedger_LeaveBalance", oBody4));
dataSource.Add(new ReportDataSource("dsEmpLeaveLedger_EmpInformation", oBody2));
}
private void ctlEmployee1_ItemChanged()
{
if (ctlEmployee1.SelectedEmployee != null)
{
if (ctlEmployee1.SelectedEmployee.Employee != null)
{
_oEmployee = ctlEmployee1.SelectedEmployee.Employee;
}
}
}
private void frmIndvEmpLeave_Load(object sender, EventArgs e)
{
LeaveYear oCurrYear = LeaveYear.GetCurrentYear();
List<Leave> _oLeaves = Payroll.BO.Leave.Get();
cmbLeaveType.Items.Add("All");
foreach (Leave _oLeave in _oLeaves)
cmbLeaveType.Items.Add(_oLeave.Description.ToString());
if (oCurrYear != null)
{
dtpFromDate.Value = oCurrYear.StartDate;
dtpToDate.Value = oCurrYear.EndDate;
}
}
}
}