281 lines
9.2 KiB
C#
281 lines
9.2 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 Payroll.BO;
|
|
using Ease.CoreV35.Model;
|
|
|
|
namespace Payroll.UI
|
|
{
|
|
public partial class fCardInformation : BaseFormTest
|
|
{
|
|
#region Declaration
|
|
|
|
private bool _IsCanceled = true;
|
|
AccessCard _AccessCard = null;
|
|
ObjectsTemplate<AccessCardType> _AccessCardTypes = null;
|
|
ObjectsTemplate<AccessCard> _accessCards = null;
|
|
private bool _Edit = false;
|
|
|
|
#endregion
|
|
|
|
#region Constructor & ShowDialog
|
|
public fCardInformation()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
public bool ShowDlg(AccessCard oAccessCard, bool Edit)
|
|
{
|
|
_AccessCard = oAccessCard;
|
|
_Edit = Edit;
|
|
RefreshCardtype();
|
|
RefreshValue();
|
|
if (_Edit)
|
|
{
|
|
numNoOfNewCard.Enabled = false;
|
|
}
|
|
//grpAutoGenerate.Enabled = false;
|
|
this.ShowDialog();
|
|
return !_IsCanceled;
|
|
}
|
|
#endregion
|
|
|
|
#region Function
|
|
|
|
private void RefreshValue()
|
|
{
|
|
if (_AccessCard.TypeID.Integer != 0)
|
|
{
|
|
cboType.SelectedIndex = _AccessCardTypes.GetIndex(_AccessCard.TypeID);
|
|
dgvCardNumber.Rows.Add(_AccessCard.CardNumber);
|
|
}
|
|
}
|
|
|
|
private void RefreshCardtype()
|
|
{
|
|
_AccessCardTypes = AccessCardType.Get();
|
|
cboType.Items.Clear();
|
|
|
|
if (_AccessCardTypes != null)
|
|
{
|
|
foreach (AccessCardType actype in _AccessCardTypes)
|
|
{
|
|
cboType.Items.Add(actype.Description);
|
|
}
|
|
//cboType.SelectedIndex = 0;
|
|
}
|
|
|
|
}
|
|
|
|
private void RefreshObject()
|
|
{
|
|
_accessCards = new ObjectsTemplate<AccessCard>();
|
|
|
|
if (_AccessCard.IsNew)
|
|
{
|
|
for (int i = 0; i < dgvCardNumber.Rows.Count; i++)
|
|
{
|
|
_AccessCard = new AccessCard();
|
|
if (dgvCardNumber["clmCardNumber", i].Value != null)
|
|
{
|
|
if (cboType.SelectedIndex < 0)
|
|
{
|
|
MessageBox.Show("Please select Card Type", "Card Type", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
cboType.Focus();
|
|
return;
|
|
}
|
|
_AccessCard.TypeID = _AccessCardTypes[cboType.SelectedIndex].ID;
|
|
_AccessCard.CardNumber = dgvCardNumber["clmCardNumber", i].Value.ToString();
|
|
_accessCards.Add(_AccessCard);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_AccessCard.TypeID = _AccessCardTypes[cboType.SelectedIndex].ID;
|
|
_AccessCard.CardNumber = dgvCardNumber["clmCardNumber", 0].Value.ToString();
|
|
_accessCards.Add(_AccessCard);
|
|
}
|
|
}
|
|
|
|
private bool ValidateInput()
|
|
{
|
|
bool Valid = true;
|
|
if (dgvCardNumber.Rows.Count == 0)
|
|
{
|
|
MessageBox.Show("Nothing To Save", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
Valid = false;
|
|
return Valid;
|
|
}
|
|
if (dgvCardNumber["clmCardNumber", 0].Value == null)
|
|
{
|
|
MessageBox.Show("Nothing To Save", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
Valid = false;
|
|
return Valid;
|
|
}
|
|
if (dgvCardNumber["clmCardNumber", 0].Value.ToString().Trim() == string.Empty)
|
|
{
|
|
MessageBox.Show("Nothing To Save", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
Valid = false;
|
|
return Valid;
|
|
}
|
|
|
|
//StringBuilder cardExist = new StringBuilder();
|
|
|
|
//for (int i = 0; i < dgvCardNumber.Rows.Count; i++)
|
|
//{
|
|
// if (dgvCardNumber["clmCardNumber", i].Value != null)
|
|
// {
|
|
// string cardNumber = dgvCardNumber["clmCardNumber", i].Value.ToString();
|
|
// if (_AccessCard.IsExist(cardNumber))
|
|
// {
|
|
// cardExist.Append(cardNumber);
|
|
// cardExist.Append(", ");
|
|
// dgvCardNumber["clmCardNumber", i].Selected = true;
|
|
// }
|
|
// }
|
|
//}
|
|
//if (cardExist.Length > 2)
|
|
//{
|
|
// cardExist.Remove(cardExist.Length - 2, 2);
|
|
//}
|
|
//if (cardExist.Length > 0)
|
|
//{
|
|
// MessageBox.Show("Card:" + cardExist + " already Exist", " Card Exist", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
// Valid = false;
|
|
// return Valid;
|
|
//}
|
|
|
|
|
|
return Valid;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Button Event
|
|
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (!ValidateInput())
|
|
{
|
|
return;
|
|
}
|
|
RefreshObject();
|
|
if (MessageBox.Show("Do you want to save the information?", "Save Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
_AccessCard.Save(_accessCards);
|
|
_IsCanceled = false;
|
|
if (_Edit)
|
|
{
|
|
MessageBox.Show("Data Updated successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Data Saved successfully.", "Save Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
}
|
|
this.Close();
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void btnGenerate_Click(object sender, EventArgs e)
|
|
{
|
|
string prefix = txtPrefix.Text;
|
|
int postfix = Convert.ToInt32(numPostfix.Value);
|
|
int intialAmount = Convert.ToInt32(numInitialAmount.Value);
|
|
dgvCardNumber.Rows.Clear();
|
|
for (int i = 0; i < intialAmount; i++)
|
|
{
|
|
string cardNumber = prefix + postfix;
|
|
dgvCardNumber.Rows.Add(cardNumber);
|
|
postfix++;
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Miscellaneous
|
|
|
|
private void chkAutoGenerate_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (chkAutoGenerate.Checked)
|
|
{
|
|
grpAutoGenerate.Enabled = true;
|
|
numNoOfNewCard.Enabled = false;
|
|
|
|
}
|
|
else
|
|
{
|
|
grpAutoGenerate.Enabled = false;
|
|
numNoOfNewCard.Enabled = true;
|
|
}
|
|
}
|
|
|
|
private void numNoOfNewCard_ValueChanged(object sender, EventArgs e)
|
|
{
|
|
dgvCardNumber.Rows.Clear();
|
|
int no = Convert.ToInt32(numNoOfNewCard.Value);
|
|
for (int i = 0; i < no; i++)
|
|
{
|
|
dgvCardNumber.Rows.Add();
|
|
}
|
|
}
|
|
|
|
private void dgvCardNumber_CellValueChanged(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
int count = 0;
|
|
if (dgvCardNumber.Rows.Count > 0)
|
|
{
|
|
if (dgvCardNumber["clmCardNumber", e.RowIndex].Value != null)
|
|
{
|
|
string s = dgvCardNumber["clmCardNumber", e.RowIndex].Value.ToString();
|
|
for (int i = 0; i < dgvCardNumber.Rows.Count; i++)
|
|
{
|
|
if (dgvCardNumber["clmCardNumber", i].Value == null)
|
|
continue;
|
|
else
|
|
{
|
|
if (dgvCardNumber["clmCardNumber", i].Value.ToString().Equals(s))
|
|
{
|
|
count++;
|
|
}
|
|
}
|
|
}
|
|
if (count > 1)
|
|
{
|
|
MessageBox.Show("Card Number Already Exist", "Duplicate Entry", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
dgvCardNumber["clmCardNumber", e.RowIndex].Value = null;
|
|
}
|
|
if (_AccessCard.IsExist(s))
|
|
{
|
|
MessageBox.Show("Card Number Already Exist", "Duplicate Entry", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|