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 ctlApprovedRequisitionPicker : UserControl { public delegate void ItemChangedEventHandeler(); public event ItemChangedEventHandeler ItemChanged; private ObjectsTemplate _oSelectedRequisitions; private CreatedRequisition _oSelectedRequisition; private string _selText = ""; public ctlApprovedRequisitionPicker() { 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 public void Clear() { this.btnClear_Click(null, null); } public ObjectsTemplate SelectedRequisitions { get { return _oSelectedRequisitions; } set { _oSelectedRequisitions = value; RefreshControls(); } } public string SelectedText { get { return _selText; } set { _selText = value; } } public CreatedRequisition SelectedRequisition { get { return _oSelectedRequisition; } set { _oSelectedRequisition = value; RefreshControls(); } } private void btnSearch_Click(object sender, EventArgs e) { fCreatedRequisition oItem = new fCreatedRequisition(); oItem.Showdlg(this.IsMultiple); if (this.IsMultiple) { if (oItem.SelectedRequisitions != null) { _oSelectedRequisitions = oItem.SelectedRequisitions; RefreshControls(); } } else { if (oItem.SelectedRequisition != null) { _oSelectedRequisition = oItem.SelectedRequisition; RefreshControl(); } } } private void RefreshControl() { if (_oSelectedRequisition != null) { lblText.Text = _oSelectedRequisition.Name; _selText = lblText.Text; } try { if (ItemChanged != null) { ItemChanged(); } } catch { } } private void RefreshControls() { string s = ""; if (_oSelectedRequisitions != null) { foreach (CreatedRequisition item in _oSelectedRequisitions) { s += item.Name + " , "; } if (s.Length > 2) lblText.Text = s.Remove(s.Length - 2); _selText = lblText.Text; } try { if (ItemChanged != null) { ItemChanged(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error occured during populate control.", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void btnClear_Click(object sender, EventArgs e) { _oSelectedRequisitions = null; _oSelectedRequisition = null; lblText.Text = ""; } private void ctlApprovedRequisitionPicker_Resize(object sender, EventArgs e) { lblText.Left = 1; btnSearch.Left = lblText.Width + 1; btnClear.Left = btnSearch.Left + btnSearch.Width + 3; } } }