using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using Payroll.BO; namespace Payroll.Controls.CustomControls { public partial class ctlCard : UserControl { AccessCard _accessCard = null; Employee _employee = null; public delegate void ItemChangedEventHandeler(); public event ItemChangedEventHandeler ItemChanged; public ctlCard() { InitializeComponent(); } #region Properties public AccessCard AccessCard { get { return _accessCard; } set { _accessCard = value; } } #endregion #region BtnEvent private void btnPeek_Click(object sender, EventArgs e) { frmSearchCard srcCard = new frmSearchCard(); srcCard.MultipleSelection = false; srcCard.ShowDialog(); _accessCard = null; if (srcCard.SelectedCard != null) { _accessCard = srcCard.SelectedCard; } if (srcCard.SelectedEmployee != null) { _employee = srcCard.SelectedEmployee; } RefreshControl(); } #endregion public void Clear() { txtCode.Text = string.Empty; _accessCard = null; RefreshControl(); } private void RefreshControl() { txtDescription.Text = string.Empty; txtCode.ForeColor = Color.Black; if(_accessCard != null && _employee != null) { txtCode.Text = _accessCard.CardNumber; txtDescription.Text = _accessCard.Status.ToString()+" ["+_employee.Name+"]"; } else if (_accessCard != null) { txtCode.Text = _accessCard.CardNumber; txtDescription.Text = _accessCard.Status.ToString(); } else { txtCode.ForeColor = Color.Red; } if (ItemChanged != null) { ItemChanged(); } } private void txtCode_TextChanged(object sender, EventArgs e) { try { _accessCard = null; _employee = null; if (txtCode.Text.Trim().Length > 0) { _accessCard = AccessCard.Get(txtCode.Text); } if (_accessCard != null && _accessCard.Status == EnumCardStatus.Attached) { CardOperation oCardOP = new CardOperation(); oCardOP = CardOperation.Get(_accessCard.CardNumber); if (oCardOP != null) { _employee = oCardOP.Employee; } } //_accessCard = null; //if (oEmp != null) //{ // if (ValidEmployee(oEmp.GetSearchEmployee())) // { // _Employee = oEmp.GetSearchEmployee(); // } //} RefreshControl(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void ctlCard_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; } } }