230 lines
6.6 KiB
C#
230 lines
6.6 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.Model;
|
|
using Payroll.BO;
|
|
using Payroll.BO;
|
|
|
|
namespace Payroll.UI
|
|
{
|
|
public partial class fCardLost : BaseFormTest
|
|
{
|
|
#region Declaration
|
|
|
|
ObjectsTemplate<AccessCard> _accessCards;
|
|
AccessCard _accessCard;
|
|
CardOperation _cardOperation;
|
|
Employee _employee;
|
|
|
|
#endregion
|
|
|
|
#region Frm_Load & Constructor
|
|
|
|
public fCardLost()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
|
|
|
|
private void fCardLost_Load(object sender, EventArgs e)
|
|
{
|
|
RefreshCard();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
private void RefreshCard()
|
|
{
|
|
_accessCards = new ObjectsTemplate<AccessCard>();
|
|
_accessCards = AccessCard.Get(new EnumCardStatus[] { EnumCardStatus.Free, EnumCardStatus.Temporary, EnumCardStatus.Found, EnumCardStatus.Attached });
|
|
cboCard.Items.Clear();
|
|
if (_accessCards != null)
|
|
{
|
|
foreach (AccessCard ac in _accessCards)
|
|
{
|
|
cboCard.Items.Add(ac.CardNumber + "[" + ac.Status + "]");
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private bool ValidateInput()
|
|
{
|
|
bool Valid = true;
|
|
if (rdoCardWise.Checked)
|
|
{
|
|
if (cboCard.SelectedIndex < 0)
|
|
{
|
|
MessageBox.Show("Please Select Card", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
Valid = false;
|
|
cboCard.Focus();
|
|
return Valid;
|
|
}
|
|
}
|
|
if (rdoEmployeeWise.Checked)
|
|
{
|
|
if (txtAssignCard.Text.Trim() == string.Empty)
|
|
{
|
|
MessageBox.Show("No Card Is Assigned For This Employee", "UnAssigned", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
Valid = false;
|
|
cboCard.Focus();
|
|
return Valid;
|
|
}
|
|
}
|
|
return Valid;
|
|
}
|
|
|
|
private void RefreshObject()
|
|
{
|
|
if (_cardOperation == null)
|
|
{
|
|
_cardOperation = new CardOperation();
|
|
}
|
|
_cardOperation.CardID = _accessCard.ID;
|
|
_cardOperation.CardNumber = _accessCard.CardNumber;
|
|
_cardOperation.Status = EnumCardStatus.Lost;
|
|
_cardOperation.AssignDate = dtpLostDate.Value;
|
|
_cardOperation.Comments = txtComments.Text.Trim();
|
|
|
|
_accessCard.Status = EnumCardStatus.Lost;
|
|
|
|
_employee.CardID = ID.FromInteger(0);
|
|
|
|
}
|
|
|
|
private void RefreshValue()
|
|
{
|
|
cboCard.SelectedIndex = -1;
|
|
txtComments.Text = "";
|
|
ctlEmployee.Clear();
|
|
txtAssignCard.Text = "";
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Btn Event
|
|
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (!ValidateInput())
|
|
{
|
|
return;
|
|
}
|
|
if (MessageBox.Show("Do you want to save the information?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
RefreshObject();
|
|
|
|
_cardOperation.Save();
|
|
_accessCard.Save();
|
|
_employee.UpdateCardInformation(_employee.ID, _employee.CardID, _employee.IsAutoProcess);
|
|
MessageBox.Show("Data saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
RefreshValue();
|
|
RefreshCard();
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (ex.InnerException == null)
|
|
MessageBox.Show(ex.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
else
|
|
MessageBox.Show(ex.InnerException.Message, "Failed to save", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Miscellaneous
|
|
|
|
private void cboCard_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (!(cboCard.SelectedIndex < 0))
|
|
{
|
|
_accessCard = _accessCards[cboCard.SelectedIndex];
|
|
_cardOperation = CardOperation.Get(_accessCard.CardNumber);
|
|
if (_cardOperation != null)
|
|
{
|
|
if (_cardOperation.EmployeeID.Integer != 0)
|
|
{
|
|
_employee = Employee.GetByCardID(_accessCard.ID);
|
|
if (_employee != null)
|
|
ctlEmployee.SelectedEmployee = _employee.SearchEmployee;
|
|
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
ctlEmployee.Clear();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ctlEmployee.Clear();
|
|
}
|
|
}
|
|
|
|
private void rdoEmployeeWise_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (rdoEmployeeWise.Checked)
|
|
{
|
|
ctlEmployee.Enabled = true;
|
|
cboCard.Enabled = false;
|
|
RefreshValue();
|
|
}
|
|
}
|
|
|
|
private void rdoCardWise_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (rdoCardWise.Checked)
|
|
{
|
|
|
|
ctlEmployee.Enabled = false;
|
|
cboCard.Enabled = true;
|
|
RefreshValue();
|
|
}
|
|
}
|
|
|
|
private void ctlEmployee_ItemChanged()
|
|
{
|
|
if (ctlEmployee.SelectedEmployee != null)
|
|
{
|
|
_employee = ctlEmployee.SelectedEmployee.Employee;
|
|
if (_employee.CardID.IsUnassigned)
|
|
{
|
|
MessageBox.Show("No Card Is Assigned For This Employee", "UnAssigned", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
return;
|
|
}
|
|
_cardOperation = CardOperation.GetByCardID(_employee.CardID);
|
|
if (_cardOperation != null)
|
|
{
|
|
txtAssignCard.Text = _cardOperation.CardNumber;
|
|
}
|
|
|
|
_accessCard = AccessCard.Get(_employee.CardID);
|
|
|
|
//RefreshControl();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|