190 lines
4.8 KiB
C#
190 lines
4.8 KiB
C#
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 ctlEmployee : UserControl
|
|
{
|
|
public delegate void ItemChangedEventHandeler();
|
|
private bool _IsInternal = false;
|
|
private SearchEmployee _Employee = null;
|
|
public event ItemChangedEventHandeler ItemChanged;
|
|
public ObjectsTemplate<Grade> _Grades = null;
|
|
|
|
public ctlEmployee()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
|
|
public void SetSelectedEmployee(SearchEmployee omp)
|
|
{
|
|
_Employee = omp;
|
|
SelectedEmployee = _Employee;
|
|
RefreshControl();
|
|
}
|
|
|
|
|
|
public SearchEmployee SelectedEmployee
|
|
{
|
|
get
|
|
{
|
|
return _Employee;
|
|
}
|
|
set
|
|
{
|
|
if(ValidEmployee(value))
|
|
{
|
|
_Employee = value;
|
|
RefreshControl();
|
|
}
|
|
}
|
|
}
|
|
|
|
public ObjectsTemplate<Grade> Grades
|
|
{
|
|
get
|
|
{
|
|
return _Grades;
|
|
}
|
|
set
|
|
{
|
|
_Grades = value;
|
|
}
|
|
}
|
|
|
|
private void ctlEmployee_Resize(object sender, EventArgs e)
|
|
{
|
|
txtCode.Left = 4;
|
|
txtCode.Top = 4;
|
|
txtCode.Width = Convert.ToInt32(Convert.ToDouble(this.Width) * 0.30);
|
|
txtCode.Width = txtCode.Width > 100 ? 100 : txtCode.Width;
|
|
btnPeek.Top = 2;
|
|
btnPeek.Left = txtCode.Width + 7;
|
|
txtDescription.Top = 4;
|
|
txtDescription.Left = txtCode.Width + 10 + btnPeek.Width;
|
|
txtDescription.Width = this.Width - txtCode.Width - btnPeek.Width - 10;
|
|
}
|
|
|
|
private void txtCode_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (!_IsInternal)
|
|
{
|
|
GetEmployee();
|
|
}
|
|
}
|
|
|
|
private void GetEmployee()
|
|
{
|
|
try
|
|
{
|
|
Employee oEmp = null;
|
|
if (txtCode.Text.Trim().Length > 0)
|
|
{
|
|
oEmp = Employee.Get(txtCode.Text);
|
|
}
|
|
_Employee = null;
|
|
if (oEmp != null)
|
|
{
|
|
if (ValidEmployee(oEmp.GetSearchEmployee()))
|
|
{
|
|
_Employee = oEmp.GetSearchEmployee();
|
|
}
|
|
}
|
|
if(_Employee != null)
|
|
RefreshControl();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
_IsInternal = true;
|
|
txtCode.Text = string.Empty;
|
|
_IsInternal = false;
|
|
_Employee = null;
|
|
RefreshControl();
|
|
}
|
|
|
|
private bool ValidEmployee(SearchEmployee oEmp)
|
|
{
|
|
bool isValid = true;
|
|
if (_Grades != null)
|
|
{
|
|
isValid = _Grades.Contains(oEmp.GradeID);
|
|
}
|
|
return isValid;
|
|
}
|
|
|
|
private void RefreshControl()
|
|
{
|
|
_IsInternal = true;
|
|
txtDescription.Text = string.Empty;
|
|
txtCode.ForeColor = Color.Black;
|
|
if (_Employee != null)
|
|
{
|
|
txtCode.Text = _Employee.EmployeeNo;
|
|
txtDescription.Text = _Employee.Name;
|
|
|
|
}
|
|
else
|
|
{
|
|
txtCode.ForeColor = Color.Red;
|
|
}
|
|
_IsInternal = false;
|
|
if (ItemChanged != null)
|
|
{
|
|
ItemChanged();
|
|
}
|
|
}
|
|
|
|
private void btnPeek_Click(object sender, EventArgs e)
|
|
{
|
|
fSearchEmployee search = new fSearchEmployee();
|
|
search.MultipleSelection = false;
|
|
if (this.Grades != null)
|
|
{
|
|
search.Grades = this.Grades;
|
|
}
|
|
search.ShowDialog();
|
|
_Employee = null;
|
|
if (search.SelectedEmployee != null)
|
|
{
|
|
_Employee = search.SelectedEmployee;
|
|
}
|
|
RefreshControl();
|
|
}
|
|
|
|
|
|
private string _employeeNo;
|
|
public string EmployeeNo
|
|
{
|
|
get
|
|
{
|
|
_employeeNo = txtCode.Text;
|
|
return _employeeNo;
|
|
}
|
|
set { _employeeNo = value; }
|
|
}
|
|
|
|
public void FocusEmployeeNo()
|
|
{
|
|
txtCode.Focus();
|
|
|
|
}
|
|
|
|
}
|
|
}
|