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

211 lines
8.4 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 Ease.CoreV35.Model;
using Ease.CoreV35;
using Microsoft.Reporting.WinForms;
using Ease.CoreV35.DataAccess;
using Payroll.BO;
using Payroll.Controls;
namespace Payroll.Report
{
public partial class fWorkflowReport : Form
{
private ReportItem _reportitem = null;
private EnumReportType _Type = EnumReportType.None;
private EnumReportType _reportType = EnumReportType.None;
public fWorkflowReport()
{
InitializeComponent();
PopulateControl();
}
public void ShowDlg()
{
this.ShowDialog();
}
public EnumReportType Type
{
set
{
_Type = value;
}
}
private void PopulateControl()
{
cboWFType.Items.Clear();
ObjectsTemplate<WFType> _wfTypes = new ObjectsTemplate<WFType>();
_wfTypes = WFType.Get();
cboWFType.DataSource = _wfTypes;
cboWFType.DisplayMember = "Name";
cboWFType.ValueMember = "ID";
if (cboWFType.Items.Count > 0) cboWFType.SelectedIndex = 0;
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnPreview_Click(object sender, EventArgs e)
{
//Payroll.Report.PayrollDataSet.PayrollDataSet.EmpLifeCycleDataTable oBody = new Payroll.Report.PayrollDataSet.PayrollDataSet.EmpLifeCycleDataTable();
DataTable infoTable = new Payroll.Report.Workflow.WFDataSet.WorkflowDataTable();
List<ReportDataSource> dataSource;
try
{
if (cboWFType.SelectedIndex < 0)
{
MessageBox.Show("Please select a Workflow type.", "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
cboWFType.Focus();
return;
}
//Prepare Report Data
this.Cursor = Cursors.WaitCursor;
ObjectsTemplate<Employee> _employees = new ObjectsTemplate<Employee>();
_employees = Employee.Get();
//_employees = new ObjectsTemplate<Employee>();
//Employee oe = Employee.Get("H003");
//_employees.Add(oe);
string WFPath = string.Empty;
if (_employees != null && _employees.Count > 0)
{
foreach (Employee oEmp in _employees)
{
DataRow dr = infoTable.NewRow();
if (oEmp.DepartmentID == null || oEmp.DepartmentID.IsUnassigned == true || oEmp.DepartmentID.Integer <= 0)
{
dr["SBU"] = string.Empty;
}
else
{
dr["SBU"] = oEmp.Department.Code.ToString();
}
dr["EmployeeID"] = oEmp.EmployeeNo.ToString();
dr["Name"] = oEmp.Name.ToString();
try
{
ObjectsTemplate<OrganogramEmployee> ogEmployee = new ObjectsTemplate<OrganogramEmployee>();
ogEmployee = OrganogramEmployee.GetByEmp(oEmp.ID);
if(ogEmployee.Count <= 0)
{
dr["NodeName"] = "Employee is not posted in Organ-O-Gram.";
dr["WorkflowPath"] = "No Workflow Path Found";
infoTable.Rows.Add(dr);
continue;
}
else
{
OrganogramBasic ogNode = new OrganogramBasic();
ogNode = OrganogramBasic.Get(ogEmployee[0].NodeID);
dr["NodeName"] = ogNode.PositionName;
WFSetup wfSetup = new WFSetup();
wfSetup = WFSetup.GetByWFTypeID((ID)cboWFType.SelectedValue);
ObjectsTemplate<OrganogramBasic>[] oPath = wfSetup.GetFullPath(ogNode);
int index = 0;
if (oPath != null)
{
for (int i = 0; i < oPath.Length-1; i++)
{
foreach (OrganogramBasic oNode in oPath[i])
{
if (index == 0)
WFPath = oNode.PositionName.ToString() + "> ";
else
{
if (oNode != null) WFPath += oNode.PositionName.ToString() + "> ";
}
index = index + 1;
}
}
if (WFPath.Length > 2)
{
WFPath = WFPath.Substring(0, WFPath.Length - 2);
}
dr["WorkflowPath"] = WFPath;
}
}
}
catch (Exception ex)
{
dr["NodeName"] = ex.Message;
dr["WorkflowPath"] = "No Workflow Path Found.";
infoTable.Rows.Add(dr);
continue;
}
infoTable.Rows.Add(dr);
WFPath = "";
}
}
DataSet rdset = new DataSet();
infoTable.TableName = "WFDataSet_Workflow";
rdset.Tables.Add(infoTable);
string embeddedResource = "Payroll.Report.Workflow.rptWorkflowPath.rdlc";
string caption = "Employee Workflow History";
dataSource = new List<ReportDataSource>();
dataSource.Add(new ReportDataSource("WFDataSet_Workflow", infoTable));
Cursor.Current = Cursors.WaitCursor;
fReportViewer fViewer = new fReportViewer();
fViewer.PreviewReport(_reportitem, dataSource, embeddedResource, caption);
this.Cursor = Cursors.Default;
}
catch (Exception ex)
{
this.Cursor = Cursors.Default;
MessageBox.Show(ex.Message, "Can't Print.", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
private void btnSearch_Click(object sender, EventArgs e)
{
//_FSearchEmp = new Payroll.UI.fSearchEmployee();
//_FSearchEmp.MultipleSelection = true;
//_FSearchEmp.ShowDialog();
//lsvEmployees.Items.Clear();
//if (_FSearchEmp.SelectedEmployees != null)
//{
// lblCount.Text = "Count : " + _FSearchEmp.SelectedEmployees.Count.ToString();
// try
// {
// foreach (SearchEmployee oEmp in _FSearchEmp.SelectedEmployees)
// {
// ListViewItem item = new ListViewItem();
// item.Tag = oEmp;
// item.Text = oEmp.HREmployee.EmployeeNo;
// item.SubItems.Add(oEmp.HREmployee.Name);
// lsvEmployees.Items.Add(item);
// }
// }
// catch { }
//}
}
private void fWorkflowReport_Load(object sender, EventArgs e)
{
this._reportType = _Type;
_reportitem = ReportItem.Get(ID.FromInteger(Convert.ToInt32(_reportType)));
}
}
}