CEL_Payroll/Payroll.Controls/CustomControls/ctlMultipleEmployee.cs

197 lines
5.0 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Payroll.BO;
using Ease.CoreV35.Model;
using Payroll.UI;
namespace Payroll.Controls.CustomControls
{
public partial class ctlMultipleEmployee : UserControl
{
#region Declaration and Contructor
public delegate void ItemChangedEventHandeler();
private bool _IsInternal = false;
private ObjectsTemplate<SearchEmployee> _Employees = null;
public event ItemChangedEventHandeler ItemChanged;
public ObjectsTemplate<Grade> _Grades = null;
public ctlMultipleEmployee()
{
InitializeComponent();
}
#endregion
#region Property
public ObjectsTemplate<SearchEmployee> SelectedEmployees
{
get
{
return _Employees;
}
set
{
if(value!= null && value.TrueForAll(o=> ValidEmployee(o)))
{
_Employees = value;
RefreshControl();
}
}
}
public ObjectsTemplate<Grade> Grades
{
get
{
return _Grades;
}
set
{
_Grades = value;
}
}
public string SearchCriteria
{
get;
private set;
}
#endregion
#region Public Function
public void Clear()
{
_IsInternal = true;
lblText.Text = string.Empty;
_IsInternal = false;
_Employees = null;
SearchCriteria = string.Empty;
RefreshControl();
}
#endregion
#region Private Function
private bool ValidEmployee(SearchEmployee oEmp)
{
bool isValid = true;
if (_Grades != null)
{
isValid = _Grades.Contains(oEmp.GradeID);
}
return isValid;
}
private void RefreshControl()
{
_IsInternal = true;
if (_Employees != null)
{
lblText.Text = "Employee Count: " + _Employees.Count;
btnClear.Enabled = true;
}
else
{
lblText.Text = string.Empty;
btnClear.Enabled = false;
}
_IsInternal = false;
if (ItemChanged != null)
{
ItemChanged();
}
}
#endregion
#region Events
private void btnPeek_Click(object sender, EventArgs e)
{
fSearchEmployee search = new fSearchEmployee();
// search.SetEmployees(_Employees);
search.MultipleSelection = true;
if (this.Grades != null)
{
search.Grades = this.Grades;
}
search.ShowDialog();
if (search.SelectedEmployees != null)
{
_Employees = search.SelectedEmployees;
SearchCriteria = search.SearchCriteria;
RefreshControl();
}
}
private void btnClear_Click(object sender, EventArgs e)
{
Clear();
}
#endregion
//private void ctlEmployee_Resize(object sender, EventArgs e)
//{
// //lblText.Left = 4;
// //lblText.Top = 4;
// //lblText.Width = Convert.ToInt32(Convert.ToDouble(this.Width) * 0.30);
// //lblText.Width = lblText.Width > 100 ? 100 : lblText.Width;
// //btnPeek.Top = 2;
// //btnPeek.Left = lblText.Width + 7;
// //txtDescription.Top = 4;
// //txtDescription.Left = lblText.Width + 10 + btnPeek.Width;
// //txtDescription.Width = this.Width - lblText.Width - btnPeek.Width - 10;
//}
//private void lblText_TextChanged(object sender, EventArgs e)
//{
// if (!_IsInternal)
// {
// GetEmployee();
// }
//}
//private void GetEmployee()
//{
// try
// {
// Employee oEmp = null;
// if (lblText.Text.Trim().Length > 0)
// {
// oEmp = Employee.Get(lblText.Text);
// }
// _Employees = null;
// if (oEmp != null)
// {
// if (ValidEmployee(oEmp.GetSearchEmployee()))
// {
// _Employees = oEmp.GetSearchEmployee();
// }
// }
// if(_Employees != null)
// RefreshControl();
// }
// catch (Exception ex)
// {
// MessageBox.Show(ex.Message);
// }
//}
}
}