541 lines
20 KiB
C#
541 lines
20 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;
|
|
|
|
namespace Payroll.Controls
|
|
{
|
|
public partial class ctlSingleControl : UserControl
|
|
{
|
|
public delegate void ItemChangedEventHandeler();
|
|
private ControlManager _Manager = null;
|
|
//private string _SelectedValues = string.Empty;
|
|
private ToolTip _oToolTip = new ToolTip();
|
|
public event ItemChangedEventHandeler ItemChanged;
|
|
//private string _sReferenceTableName;
|
|
// private string _sReferenceFieldName;
|
|
public event System.EventHandler Changed;
|
|
private System.ComponentModel.Container components = null;
|
|
private bool _IsInternal = false;
|
|
|
|
public ctlSingleControl()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#region Properties
|
|
#region Output Type
|
|
|
|
//public string ReferenceTableName
|
|
//{
|
|
// get
|
|
// {
|
|
// return _sReferenceTableName;
|
|
// }
|
|
// set
|
|
// {
|
|
// _sReferenceTableName = value;
|
|
// }
|
|
//}
|
|
//public string ReferenceFieldName
|
|
//{
|
|
// get
|
|
// {
|
|
// return _sReferenceFieldName;
|
|
// }
|
|
// set
|
|
// {
|
|
// _sReferenceFieldName = value;
|
|
// }
|
|
//}
|
|
private EnumCustomBasicControl _eOutputType;
|
|
public EnumCustomBasicControl OutputType
|
|
{
|
|
get { return _eOutputType; }
|
|
set { _eOutputType = value; }
|
|
}
|
|
#endregion
|
|
|
|
#region Multiple Selection
|
|
public bool MultipleSelection
|
|
{
|
|
get { return false; }
|
|
}
|
|
#endregion
|
|
|
|
#region Collection Object
|
|
private CollectionBase _objectCollection;
|
|
public CollectionBase CollectionObject
|
|
{
|
|
get { return _objectCollection; }
|
|
set { _objectCollection = value; }
|
|
}
|
|
#endregion
|
|
|
|
#region Control Type
|
|
private EnumCustomBasicControlType _controlType; // Tree or List
|
|
public EnumCustomBasicControlType ControlType
|
|
{
|
|
get { return _controlType; }
|
|
set { _controlType = value; }
|
|
}
|
|
#endregion
|
|
|
|
#region Picker Caption
|
|
private string _pickerCaption;
|
|
public string PickerCaption
|
|
{
|
|
get { return _pickerCaption; }
|
|
set { _pickerCaption = value; }
|
|
}
|
|
#endregion
|
|
|
|
#region Child Property Name
|
|
private string _childPropertyName;
|
|
public string ChildPropertyName
|
|
{
|
|
get { return _childPropertyName; }
|
|
set { _childPropertyName = value; }
|
|
}
|
|
|
|
private string _customSearchString;
|
|
public string CustomSearchString
|
|
{
|
|
get { return _customSearchString; }
|
|
set { _customSearchString = value; }
|
|
}
|
|
#endregion
|
|
|
|
#region Selected IDs
|
|
private int[] _nSelectedIDs;
|
|
//public int[] SelectedIDs
|
|
//{
|
|
// get
|
|
// {
|
|
// if (_Manager == null)
|
|
// {
|
|
// return null;
|
|
// }
|
|
// return _Manager.SelectedIDs;
|
|
// }
|
|
// set
|
|
// {
|
|
// _nSelectedIDs = value;
|
|
// RefreshMe();
|
|
// }
|
|
//}
|
|
#endregion
|
|
|
|
#region get String Seleceted IDs
|
|
public string GetStringSelectedIDs
|
|
{
|
|
get
|
|
{
|
|
if (_nSelectedIDs == null) { return ""; }
|
|
string sValues = "";
|
|
for (int n = 0; n < _nSelectedIDs.Length; n++)
|
|
{
|
|
if (sValues == "")
|
|
sValues = _nSelectedIDs[n].ToString();
|
|
else
|
|
sValues = sValues + ", " + _nSelectedIDs[n].ToString();
|
|
}
|
|
if (sValues != "")
|
|
sValues = "(" + sValues + ")";
|
|
return sValues;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Selected Objects
|
|
private ObjectsTemplate<ObjectTemplate> _oSelectedObjects;
|
|
public object SelectedObject
|
|
{
|
|
get
|
|
{
|
|
if (_Manager != null)
|
|
{
|
|
return _Manager.SelectedItems;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
private object[] _oSelectedObjectsCol;
|
|
public object[] SelectedObjectsCol
|
|
{
|
|
get
|
|
{
|
|
return _oSelectedObjectsCol;
|
|
}
|
|
set
|
|
{
|
|
_oSelectedObjectsCol = value;
|
|
RefreshMe();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region HeadLine
|
|
private string _sHeadLine = "";
|
|
public string PickerHeadLine
|
|
{
|
|
get { return _sHeadLine; }
|
|
set { _sHeadLine = value; }
|
|
}
|
|
#endregion
|
|
|
|
#region MHLevel
|
|
private int _nMHTire = 0;
|
|
public int MHTire
|
|
{
|
|
get { return _nMHTire; }
|
|
set { _nMHTire = value; }
|
|
}
|
|
#endregion
|
|
|
|
#region LastLevel
|
|
private int _nLastLevel = -1;
|
|
public int LastLevel
|
|
{
|
|
get { return _nLastLevel; }
|
|
set { _nLastLevel = value; }
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region RefreshMe
|
|
private void RefreshMe()
|
|
{
|
|
_IsInternal = true;
|
|
txtDescription.Text = string.Empty;
|
|
if (_Manager != null && _Manager.SelectedIDs != null)
|
|
{
|
|
txtCode.Text = _Manager.SelectedCode;
|
|
txtDescription.Text = _Manager.SelectedDescription;
|
|
|
|
}
|
|
if (_Manager != null && _Manager.SelectedValues != null)
|
|
{
|
|
_oToolTip.SetToolTip(txtCode, _Manager.SelectedValues);
|
|
}
|
|
_IsInternal = false;
|
|
if (ItemChanged != null)
|
|
{
|
|
ItemChanged();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
//public void SetValues(int[] selectedIDs, string selectedValues)
|
|
//{
|
|
// SelectedIDs = selectedIDs;
|
|
// _SelectedValues = selectedValues;
|
|
// RefreshMe();
|
|
//}
|
|
|
|
//public void SetValues(string[] selectedIDs, string selectedValues)
|
|
//{
|
|
// SelectedIDs = new int[selectedIDs.Length];
|
|
// for (int count = 0; count < selectedIDs.Length; count++)
|
|
// {
|
|
// SelectedIDs[count] = Convert.ToInt32(selectedIDs[count]);
|
|
// }
|
|
// _SelectedValues = selectedValues;
|
|
// RefreshMe();
|
|
//}
|
|
|
|
//public void SetValues(int selectedID, string selectedValues)
|
|
//{
|
|
// SelectedIDs = new int[1];
|
|
// SelectedIDs[0] = selectedID;
|
|
// _SelectedValues = selectedValues;
|
|
// RefreshMe();
|
|
//}
|
|
|
|
private void GetValues(object sender, EventArgs e)
|
|
{
|
|
this.Cursor = Cursors.WaitCursor;
|
|
|
|
frmCustomBasic oFrom = new frmCustomBasic();
|
|
if (_Manager != null) _Manager.SelectedObjects.Clear();
|
|
#region NewObjects
|
|
switch (_eOutputType)
|
|
{
|
|
case EnumCustomBasicControl.Category:
|
|
if (_Manager == null) _Manager = new ControlManager("Code,Name", "Code,Name",MultipleSelection, ControlType, ChildPropertyName,
|
|
PickerCaption, _eOutputType);
|
|
ObjectsTemplate<Category> oCategories = Category.Get(EnumStatus.Active);
|
|
this.Cursor = Cursors.Default;
|
|
oFrom.CopyCollList(oCategories);
|
|
oFrom.ShowDialog(_Manager);
|
|
RefreshMe();
|
|
break;
|
|
case EnumCustomBasicControl.CostCenter:
|
|
if (_Manager == null) _Manager = new ControlManager("Code,Name", "Code,Name", MultipleSelection,
|
|
ControlType, ChildPropertyName, PickerCaption, _eOutputType);
|
|
ObjectsTemplate<Costcenter> oCCs = Costcenter.GetParents(EnumStatus.Active);
|
|
this.Cursor = Cursors.Default;
|
|
oFrom.CopyCollList(oCCs);
|
|
oFrom.ShowDialog(_Manager);
|
|
RefreshMe();
|
|
break;
|
|
case EnumCustomBasicControl.Department:
|
|
if (_Manager == null) _Manager = new ControlManager("Code,Name", "Code,Name", MultipleSelection, ControlType,
|
|
ChildPropertyName, PickerCaption, _eOutputType);
|
|
ObjectsTemplate<Department> oDepts = Department.GetParents(EnumStatus.Active);
|
|
this.Cursor = Cursors.Default;
|
|
oFrom.CopyCollList(oDepts);
|
|
oFrom.ShowDialog(_Manager);
|
|
RefreshMe();
|
|
break;
|
|
case EnumCustomBasicControl.Designation:
|
|
if (_Manager == null) _Manager = new ControlManager("Code,Name", "Code,Name", MultipleSelection,
|
|
ControlType, ChildPropertyName, PickerCaption, _eOutputType);
|
|
ObjectsTemplate<Designation> oDesig = Designation.Get(EnumStatus.Active);
|
|
this.Cursor = Cursors.Default;
|
|
oFrom.CopyCollList(oDesig);
|
|
oFrom.ShowDialog(_Manager);
|
|
RefreshMe();
|
|
break;
|
|
case EnumCustomBasicControl.Grade:
|
|
if (_Manager == null) _Manager = new ControlManager( "Code,Name", "Code,Name", MultipleSelection, ControlType,
|
|
ChildPropertyName, PickerCaption, _eOutputType);
|
|
ObjectsTemplate<Grade> oGrades = Grade.Get(EnumStatus.Active);
|
|
this.Cursor = Cursors.Default;
|
|
oFrom.CopyCollList(oGrades);
|
|
oFrom.ShowDialog(_Manager);
|
|
RefreshMe();
|
|
break;
|
|
case EnumCustomBasicControl.GradeSagment:
|
|
if (_Manager == null) _Manager = new ControlManager( "Code,Name", "Code,Name", MultipleSelection,
|
|
ControlType, ChildPropertyName, PickerCaption, _eOutputType);
|
|
ObjectsTemplate<GradeSegment> oGradeSags = GradeSegment.Get(EnumStatus.Active);
|
|
this.Cursor = Cursors.Default;
|
|
oFrom.CopyCollList(oGradeSags);
|
|
oFrom.ShowDialog(_Manager);
|
|
RefreshMe();
|
|
break;
|
|
case EnumCustomBasicControl.Location:
|
|
if (_Manager == null) _Manager = new ControlManager("Code,Name", "Code,Name", MultipleSelection, ControlType,
|
|
ChildPropertyName, PickerCaption, _eOutputType);
|
|
ObjectsTemplate<Payroll.BO.Location> oLocations = Payroll.BO.Location.GetParents(EnumStatus.Active);
|
|
this.Cursor = Cursors.Default;
|
|
oFrom.CopyCollList(oLocations);
|
|
oFrom.ShowDialog(_Manager);
|
|
RefreshMe();
|
|
break;
|
|
case EnumCustomBasicControl.Religion:
|
|
if (_Manager == null) _Manager = new ControlManager("Code,Name", "Code,Name", MultipleSelection,
|
|
ControlType, ChildPropertyName, PickerCaption, _eOutputType);
|
|
ObjectsTemplate<Payroll.BO.Religion> oReligions = Payroll.BO.Religion.Get(EnumStatus.Active);
|
|
this.Cursor = Cursors.Default;
|
|
oFrom.CopyCollList(oReligions);
|
|
oFrom.ShowDialog(_Manager);
|
|
RefreshMe();
|
|
break;
|
|
case EnumCustomBasicControl.Function:
|
|
if (_Manager == null) _Manager = new ControlManager("Code,Name", "Code,Name", MultipleSelection,
|
|
ControlType, ChildPropertyName, PickerCaption, _eOutputType);
|
|
ObjectsTemplate<Payroll.BO.Function> oFunctions = Payroll.BO.Function.Get(EnumStatus.Active);
|
|
this.Cursor = Cursors.Default;
|
|
oFrom.CopyCollList(oFunctions);
|
|
oFrom.ShowDialog(_Manager);
|
|
RefreshMe();
|
|
break;
|
|
}
|
|
|
|
#endregion
|
|
|
|
try
|
|
{
|
|
if (Changed != null)
|
|
{
|
|
Changed(sender, e);
|
|
}
|
|
this.Cursor = Cursors.Default;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void GetValue(object sender, EventArgs e)
|
|
{
|
|
if (_Manager == null)
|
|
{
|
|
_Manager = new ControlManager();
|
|
_Manager.ChildPropertyName = ChildPropertyName;
|
|
_Manager.ControlType = ControlType;
|
|
_Manager.PickerCaption = PickerCaption;
|
|
_Manager.SelectedObjects = _oSelectedObjects;
|
|
}
|
|
|
|
switch (_eOutputType)
|
|
{
|
|
case EnumCustomBasicControl.Category :
|
|
//Category cat = Category.Get();
|
|
break;
|
|
case EnumCustomBasicControl.CostCenter:
|
|
Costcenter cc = Costcenter.Get(txtCode.Text.Trim());
|
|
if (cc != null)
|
|
{
|
|
_Manager.SelectedIDs = new int[] { cc.ID.Integer };
|
|
_Manager.SelectedValues = cc.Name;
|
|
_Manager.SelectedItems = cc;
|
|
_Manager.SelectedCode = cc.Code;
|
|
_Manager.SelectedDescription = cc.Name;
|
|
}
|
|
else
|
|
{
|
|
_Manager = null;
|
|
}
|
|
break;
|
|
case EnumCustomBasicControl.Department:
|
|
Department dept = Department.Get(txtCode.Text.Trim());
|
|
if (dept != null)
|
|
{
|
|
_Manager.SelectedIDs = new int[] {dept.ID.Integer};
|
|
_Manager.SelectedValues = dept.Name;
|
|
_Manager.SelectedItems = dept;
|
|
_Manager.SelectedCode = dept.Code;
|
|
_Manager.SelectedDescription = dept.Name;
|
|
}
|
|
else
|
|
{
|
|
_Manager = null;
|
|
}
|
|
break;
|
|
case EnumCustomBasicControl.Designation:
|
|
Designation desig = Designation.Get(txtCode.Text.Trim());
|
|
if (desig != null)
|
|
{
|
|
_Manager.SelectedIDs = new int[] { desig.ID.Integer };
|
|
_Manager.SelectedValues = desig.Name;
|
|
_Manager.SelectedItems = desig;
|
|
_Manager.SelectedCode = desig.Code;
|
|
_Manager.SelectedDescription = desig.Name;
|
|
}
|
|
else
|
|
{
|
|
_Manager = null;
|
|
}
|
|
break;
|
|
case EnumCustomBasicControl.Grade:
|
|
Grade grade = Grade.Get(txtCode.Text.Trim());
|
|
if (grade != null)
|
|
{
|
|
_Manager.SelectedIDs = new int[] { grade.ID.Integer };
|
|
_Manager.SelectedValues = grade.Name;
|
|
_Manager.SelectedItems = grade;
|
|
_Manager.SelectedCode = grade.Code;
|
|
_Manager.SelectedDescription = grade.Name;
|
|
}
|
|
else
|
|
{
|
|
_Manager = null;
|
|
}
|
|
break;
|
|
case EnumCustomBasicControl.GradeSagment:
|
|
GradeSegment sagment = GradeSegment.Get(txtCode.Text.Trim());
|
|
if (sagment != null)
|
|
{
|
|
_Manager.SelectedIDs = new int[] { sagment.ID.Integer };
|
|
_Manager.SelectedValues = sagment.Name;
|
|
_Manager.SelectedItems = sagment;
|
|
_Manager.SelectedCode = sagment.Code;
|
|
_Manager.SelectedDescription = sagment.Name;
|
|
}
|
|
else
|
|
{
|
|
_Manager = null;
|
|
}
|
|
break;
|
|
case EnumCustomBasicControl.Location:
|
|
Payroll.BO.Location location = Payroll.BO.Location.Get(txtCode.Text.Trim());
|
|
if (location != null)
|
|
{
|
|
_Manager.SelectedIDs = new int[] { location.ID.Integer };
|
|
_Manager.SelectedValues = location.Name;
|
|
_Manager.SelectedItems = location;
|
|
_Manager.SelectedCode = location.Code;
|
|
_Manager.SelectedDescription = location.Name;
|
|
}
|
|
else
|
|
{
|
|
_Manager = null;
|
|
}
|
|
break;
|
|
case EnumCustomBasicControl.Religion:
|
|
Payroll.BO.Religion religion = Payroll.BO.Religion.Get(txtCode.Text.Trim());
|
|
if (religion != null)
|
|
{
|
|
_Manager.SelectedIDs = new int[] { religion.ID.Integer };
|
|
_Manager.SelectedValues = religion.Name;
|
|
_Manager.SelectedItems = religion;
|
|
_Manager.SelectedCode = religion.Code;
|
|
_Manager.SelectedDescription = religion.Name;
|
|
}
|
|
else
|
|
{
|
|
_Manager = null;
|
|
}
|
|
break;
|
|
case EnumCustomBasicControl.Function:
|
|
Function Func = Function.Get(txtCode.Text.Trim());
|
|
if (Func != null)
|
|
{
|
|
_Manager.SelectedIDs = new int[] { Func.ID.Integer };
|
|
_Manager.SelectedValues = Func.Name;
|
|
_Manager.SelectedItems = Func;
|
|
_Manager.SelectedCode = Func.Code;
|
|
_Manager.SelectedDescription = Func.Name;
|
|
}
|
|
else
|
|
{
|
|
_Manager = null;
|
|
}
|
|
break;
|
|
}
|
|
RefreshMe();
|
|
}
|
|
|
|
private void ctlSingleControl_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)
|
|
{
|
|
GetValue(sender, e);
|
|
}
|
|
}
|
|
|
|
private void btnPeek_Click(object sender, EventArgs e)
|
|
{
|
|
GetValues(sender,e);
|
|
}
|
|
}
|
|
}
|