CEL_Payroll/Payroll.Controls/CustomControls/ctlOrgControl.cs

179 lines
4.2 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;
namespace Payroll.Controls.CustomControls
{
public partial class ctlOrgControl : UserControl
{
public delegate void ItemChangedEventHandeler();
public event ItemChangedEventHandeler ItemChanged;
private OrganogramBasic _oOrg;
private ObjectsTemplate<OrganogramBasic> _oOrgs;
public ctlOrgControl()
{
InitializeComponent();
}
#region Property IsEmpty : bool
private bool _isEmpty;
public bool IsEmpty
{
get
{
_isEmpty = (lblText.Text.Trim().Length <= 0);
return _isEmpty;
}
}
#endregion
#region Is Multiple
private bool _isMultiple;
public bool IsMultiple
{
get
{
return _isMultiple;
}
set
{
_isMultiple = value;
}
}
#endregion
#region ShowVacantNode
private bool _showVacantNode;
public bool ShowVacantNode
{
get
{
return _showVacantNode;
}
set
{
_showVacantNode = value;
}
}
#endregion
public void Clear()
{
this.btnClear_Click(null, null);
}
public OrganogramBasic SelectedNode
{
get
{
return _oOrg;
}
set
{
_oOrg = value;
RefreshControl();
}
}
public ObjectsTemplate<OrganogramBasic> SelectedNodes
{
get
{
return _oOrgs;
}
set
{
_oOrgs = value;
RefreshControls();
}
}
private void btnSearch_Click(object sender, EventArgs e)
{
fOrg oItem = new fOrg();
oItem.Showdlg(this.IsMultiple,this._showVacantNode);
if (this.IsMultiple)
{
if (oItem.SelNodes != null)
{
_oOrgs = oItem.SelNodes;
RefreshControls();
}
}
else
{
if (oItem.SelNode != null)
{
_oOrg = oItem.SelNode;
RefreshControl();
}
}
}
private void RefreshControl()
{
if (_oOrg != null)
{
lblText.Text = _oOrg.PositionName;
}
try
{
if (ItemChanged != null)
{
ItemChanged();
}
}
catch { }
}
private void RefreshControls()
{
string s = "";
if (_oOrgs != null)
{
foreach (OrganogramBasic org in _oOrgs)
{
s += org.PositionName + " , ";
}
if(s.Length >2)
lblText.Text = s.Remove(s.Length - 2);
}
try
{
if (ItemChanged != null)
{
ItemChanged();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error occured during populate control.", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ctlOrgControl_Resize(object sender, EventArgs e)
{
lblText.Left = 1;
btnSearch.Left = lblText.Width + 1;
btnClear.Left = btnSearch.Left + btnSearch.Width + 3;
}
private void btnClear_Click(object sender, EventArgs e)
{
_oOrgs=null;
_oOrg = null;
lblText.Text = "";
}
}
}