255 lines
6.9 KiB
C#
255 lines
6.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using Ease.CoreV35.Utility;
|
|
using Payroll.BO;
|
|
using Ease.CoreV35;
|
|
using Ease.CoreV35.Model;
|
|
using Payroll.BO;
|
|
|
|
namespace Payroll.Controls.CustomControls
|
|
{
|
|
public partial class frmSearchCard : Form
|
|
{
|
|
#region Declaration
|
|
ObjectsTemplate<AccessCard> _accessCards = null;
|
|
Employee _employee = null;
|
|
AccessCard _accessCard = null;
|
|
private bool _MultipleSelection = false;
|
|
ObjectsTemplate<AccessCard> _selectedAccessCards = null;
|
|
AccessCard _selectedAccessCard = null;
|
|
private bool _onlyFreeCard = false;
|
|
#endregion
|
|
|
|
public frmSearchCard()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void frmSearchCard_Load(object sender, EventArgs e)
|
|
{
|
|
RefreshStatus();
|
|
}
|
|
|
|
public void ShowDlg(bool OnlyFreeCard)
|
|
{
|
|
_onlyFreeCard = OnlyFreeCard;
|
|
if (_onlyFreeCard)
|
|
{
|
|
pnlSlection.Enabled = false;
|
|
ctlEmployee.Enabled = false;
|
|
//cboStatus.IsAccessible = false;
|
|
}
|
|
this.ShowDialog();
|
|
}
|
|
|
|
#region Properties
|
|
|
|
public ObjectsTemplate<AccessCard> SelectedCards
|
|
{
|
|
get
|
|
{
|
|
return _selectedAccessCards;
|
|
}
|
|
}
|
|
|
|
public AccessCard SelectedCard
|
|
{
|
|
get
|
|
{
|
|
return _selectedAccessCard;
|
|
}
|
|
}
|
|
|
|
public Employee SelectedEmployee
|
|
{
|
|
get
|
|
{
|
|
return _employee;
|
|
}
|
|
}
|
|
|
|
public bool MultipleSelection
|
|
{
|
|
get
|
|
{
|
|
return _MultipleSelection;
|
|
}
|
|
set
|
|
{
|
|
lsvCard.MultiSelect = value;
|
|
lsvCard.CheckBoxes = value;
|
|
_MultipleSelection = value;
|
|
btnSelectAll.Visible = value;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
private void RefreshStatus()
|
|
{
|
|
cboStatus.Items.Clear();
|
|
if (_onlyFreeCard)
|
|
{
|
|
cboStatus.Items.Add(EnumCardStatus.Free);
|
|
}
|
|
else
|
|
{
|
|
foreach (string sIten in Enum.GetNames(typeof(EnumCardStatus)))
|
|
{
|
|
cboStatus.Items.Add(sIten);
|
|
}
|
|
}
|
|
cboStatus.SelectedIndex = 0 ;
|
|
}
|
|
|
|
private void ctlEmployee_ItemChanged()
|
|
{
|
|
if (ctlEmployee.SelectedEmployee != null)
|
|
{
|
|
_employee = ctlEmployee.SelectedEmployee.Employee;
|
|
_accessCard = AccessCard.Get(_employee.CardID);
|
|
}
|
|
}
|
|
|
|
private void cboStatus_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (cboStatus.SelectedIndex >= 0)
|
|
{
|
|
_accessCards = AccessCard.Get((EnumCardStatus)Enum.Parse(typeof(EnumCardStatus), cboStatus.SelectedItem.ToString(), true));
|
|
}
|
|
|
|
}
|
|
|
|
private void RefreshControl()
|
|
{
|
|
if (rdoEmployeeWise.Checked)
|
|
{
|
|
ListViewItem item = null;
|
|
lsvCard.Items.Clear();
|
|
if (_accessCard != null)
|
|
{
|
|
item = new ListViewItem(_accessCard.CardNumber);
|
|
item.SubItems.Add(_accessCard.Status.ToString());
|
|
item.Tag = _accessCard;
|
|
lsvCard.Items.Add(item);
|
|
}
|
|
|
|
}
|
|
if(rdoStatusWise.Checked)
|
|
{
|
|
ListViewItem item = null;
|
|
lsvCard.Items.Clear();
|
|
if (_accessCards != null)
|
|
{
|
|
foreach (AccessCard ac in _accessCards)
|
|
{
|
|
item = new ListViewItem(ac.CardNumber);
|
|
item.SubItems.Add(ac.Status.ToString());
|
|
item.Tag = ac;
|
|
lsvCard.Items.Add(item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnOK_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
if (!MultipleSelection)
|
|
{
|
|
if (lsvCard.SelectedItems != null && lsvCard.SelectedItems.Count > 0)
|
|
{
|
|
_selectedAccessCard = (AccessCard)lsvCard.SelectedItems[0].Tag;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_selectedAccessCards = new ObjectsTemplate<AccessCard>();
|
|
foreach (ListViewItem item in lsvCard.CheckedItems)
|
|
{
|
|
if (item.Checked)
|
|
{
|
|
_selectedAccessCards.Add((AccessCard)item.Tag);
|
|
}
|
|
}
|
|
}
|
|
this.Close();
|
|
}
|
|
|
|
private void rdoEmployeeWise_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (rdoEmployeeWise.Checked)
|
|
{
|
|
ctlEmployee.Enabled = true;
|
|
cboStatus.SelectedIndex = -1;
|
|
cboStatus.Enabled = false;
|
|
|
|
}
|
|
}
|
|
|
|
private void rdoStatusWise_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (rdoStatusWise.Checked)
|
|
{
|
|
cboStatus.Enabled = true;
|
|
ctlEmployee.Clear();
|
|
ctlEmployee.Enabled = false;
|
|
lsvCard.Items.Clear();
|
|
}
|
|
}
|
|
|
|
private void btnSelectAll_Click(object sender, EventArgs e)
|
|
{
|
|
bool bSelected = false;
|
|
if (btnSelectAll.Text.Equals("&Select All"))
|
|
{
|
|
bSelected = true;
|
|
btnSelectAll.Text = "&Unselect All";
|
|
}
|
|
else
|
|
{
|
|
btnSelectAll.Text = "&Select All";
|
|
}
|
|
|
|
foreach (ListViewItem item in lsvCard.Items)
|
|
{
|
|
item.Checked = bSelected;
|
|
}
|
|
}
|
|
|
|
private void lsvCard_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
btnOK_Click(sender,e);
|
|
}
|
|
|
|
private void btnFind_Click(object sender, EventArgs e)
|
|
{
|
|
RefreshControl();
|
|
}
|
|
|
|
private void lsvCard_ColumnClick(object sender, ColumnClickEventArgs e)
|
|
{
|
|
this.Cursor = Cursors.WaitCursor;
|
|
|
|
SortOrder order = SortOrder.Ascending;
|
|
if (order == lsvCard.Sorting)
|
|
order = SortOrder.Descending;
|
|
else
|
|
order = SortOrder.Ascending;
|
|
|
|
lsvCard.ListViewItemSorter = new Global.ItemSorter(e.Column, order);
|
|
lsvCard.Sorting = order;
|
|
|
|
this.Cursor = Cursors.Default;
|
|
}
|
|
|
|
|
|
}
|
|
}
|