private void btnOk_Click(object sender, RoutedEventArgs e)
{
try
{
intCountSeconds = 0;
Uri pageFunctionUri;
//bool bolIgnoreAttempts = false;
if (clsCommonCarrier.strKeyPadMode.Equals(Convert.ToString(eKeypadMode.PINENTRY)))
{
if (clsCommonCarrier.strValidcardDetails[10] == null)
{
clsCommonCarrier.strValidcardDetails[10] = "1234";
}
if (clsCommonCarrier.strValidcardDetails[9] != null && clsCommonCarrier.strValidcardDetails[9].Contains("registered"))
clsCommonCarrier.strValidcardDetails[10] = "1234";
if (strPin == clsCommonCarrier.strValidcardDetails[10])
{
if (bolApplicationCloseRequest)
{
bolApplicationCloseRequest = false;
if (!clsCommonCarrier.bolIsNetworkDisConnected)
objBL.RegisterLCD(0);
clsCommonCarrier.TcpList.Stop();
GC.Collect();
Environment.Exit(0);
}
else if (clsCommonCarrier.bytMAButton == 2)
{
Multimode();
clsCommonCarrier.strKeyPadMode = Convert.ToString(eKeypadMode.TIMEENTRY);
}
}
else
{
objCls = new clsCommonCollection();
if (clsCommonCarrier.strValidcardDetails[7] != null)
{
if (bytCount == Convert.ToInt32(clsCommonCarrier.strValidcardDetails[7].Split(',')[5]) && !clsCommonCarrier.strValidcardDetails[9].Contains("registered"))
{
if (!clsCommonCarrier.bolIsCardBlocked)
{
clsCommonCarrier.bolIsCardBlocked = true;
if (clsCommonCarrier.strValidcardDetails[7].Split(',')[5] != null)
{
objCls.MsgBox("You have reached " + clsCommonCarrier.strValidcardDetails[7].Split(',')[5] + " times with invalid credentials, So your access is blocked", "InfoMsg", "Invalid Access");
}
else
objCls.MsgBox("You have reached 3 times with invalid credentials, So your access is blocked", "InfoMsg", "Invalid Access");
}
// ................................
bytCount = 0;
objBL.BlockPIN(clsCommonCarrier.strValidcardDetails[6].Split(',')[0]);
pageFunctionUri = new Uri(NavigationFilePaths.PgWelcome, UriKind.Relative);
}
}
//-----
if (clsCommonCarrier.strValidcardDetails[7] == null)
{
if (bytCount == 3)
{
objCls.MsgBox("Invalid PIN", "InfoMsg", "Invalid Access");
bytCount = 0;
pageFunctionUri = new Uri(NavigationFilePaths.PgWelcome, UriKind.Relative);
}
else//objCls.ShowMessage_Information("Invalid PIN, you have " + (3 - bytCount).ToString() + " chance.", "Invalid Access");
objCls.MsgBox("Invalid PIN.", "InfoMsg", "Invalid Access");
}
//------
else if (clsCommonCarrier.strValidcardDetails[7] != null && !clsCommonCarrier.strValidcardDetails[9].Contains("registered"))
{
if (clsCommonCarrier.strValidcardDetails[7].Split(',')[5] != null)
{
if (clsCommonCarrier.bolIsCardBlocked)
{
objCls.MsgBox("Your card is blocked\nPlease contact Admin.", "InfoMsg", "Invalid Access");
//clsCommonCarrier.strValidcardDetails[10] = "1234";
}
else
objCls.MsgBox("Invalid PIN! \nAfter " + (Convert.ToInt32(clsCommonCarrier.strValidcardDetails[7].Split(',')[5]) - bytCount).ToString() + " attempts your access will be blocked", "InfoMsg", "Invalid Access");
}
}
else//objCls.ShowMessage_Information("Invalid PIN, you have " + (3 - bytCount).ToString() + " chance.", "Invalid Access");
{
objCls.MsgBox("Invalid PIN.", "InfoMsg", "Invalid Access");
bytCount = 0;
}
bytCount++;
lblCardInform.Content = strPin = string.Empty;
}
}
}
catch (Exception ex)
{
objBL.LogRecord("Error-> :btnOk_click " + ex.Message);
//objCls.ShowMessage_Error(ex.Message);
objCls.MsgBox(ex.Message, "ErrorMsg", "Error!");
}
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
try
{
GoToModeActivation();
}
catch (Exception ex)
{
objBL.LogRecord("Error-> :btnCancel_click " + ex.Message);
//objCls.ShowMessage_Error(ex.Message);
objCls.MsgBox(ex.Message, "ErrorMsg", "Error!");
}
}
///
/// To ide keypad and to display mode activation page.
///
private void GoToModeActivation()
{
try
{
if (bolApplicationCloseRequest)
{
stkpnl.Visibility = Visibility.Visible;
grdWinKeypad.Visibility = Visibility.Hidden;
EnableCloseButtons();
EnableMultimodeButton();
bolApplicationCloseRequest = false;
lblCardInform.Content = strPin = string.Empty;
this.DisTimKeyPad.Stop();
intCountSeconds = 0;
return;
}
this.DisTimKeyPad.Stop();
lblCardInform.Content = strPin = string.Empty;
grdWinKeypad.Visibility = Visibility.Hidden;
EnableCloseButtons();
EnableMultimodeButton();//btnMultiMode.IsEnabled = true;
if (frmSub1.Content != null)
{
stkpnl.Visibility = Visibility.Visible;
thTCPWatcher = null; //added on 22-may-2014 for making thread lve for second swipe
CallThread();
}
}
catch (Exception ex)
{
objBL.LogRecord("Error-> :GoToModeActivation " + ex.Message);
//objCls.ShowMessage_Error(ex.Message);
objCls.MsgBox(ex.Message, "ErrorMsg", "Error!");
}
}
///
/// This will be called by all buttons (btn0-btn9).
/// validates whether valid user.
///
/// <param name="btn" />instance of a button
private void ButtonPress(Button btn)
{
try
{
intCountSeconds = 0;
strPin += btn.Content.ToString();
strTmp = string.Empty;
for (int i = 0; i < strPin.Length; i++)
{
strTmp += "*";
if (Convert.ToString(strTmp).Length > 10)
{
//objCls.ShowMessage_Information("Maximum PIN Length is 10 digits", "Invalid PIN");
objCls.MsgBox("Maximum PIN Length is 10 digits", "ErrorMsg", "Invalid PIN");
lblCardInform.Content = strPin = strTmp = string.Empty;
break;
}
}
lblCardInform.Content = strTmp;
}
catch (Exception e)
{
objBL.LogRecord("Error-> :ButtonPress " + e.Message);
throw e;
}
}
private void btnBksp_Click(object sender, RoutedEventArgs e)
{
try
{
intCountSeconds = 0;
if (Convert.ToString(lblCardInform.Content) != "")
{
strTmp = lblCardInform.Content.ToString();
strPin = strPin.Substring(0, strPin.Length - 1);
lblCardInform.Content = strTmp.Substring(0, strTmp.Length - 1);
}
}
catch (Exception ex)
{
objBL.LogRecord("Error-> :btnBksp_click " + ex.Message);
//objCls.ShowMessage_Error(ex.Message);
objCls.MsgBox(ex.Message, "ErrorMsg", "Error!");
}
}
#endregion
#region screen Idle time management
string[] strScreenIdleTime = new string[5];
DispatcherTimer DisTimKeyPad;
int intCountSeconds;
///
/// To navigate to Welcome/ModeActivation page after epiration of screen idle time
///
void CheckIdleTime()
{
try
{
DisTimKeyPad = new DispatcherTimer();
DisTimKeyPad.Tick += new EventHandler(TickTimeKeyPad);
DisTimKeyPad.Interval = new TimeSpan(0, 0, 1);
DisTimKeyPad.Start();
}
catch (Exception ex)
{
objBL.LogRecord("Error-> :CheckIdleTime " + ex.Message);
objCls.SetMessage("CheckDoor()", ex.Message, (int)ePageID.LCDClient);
}
}
///
/// To navigate to Welcome/ModeActivation page after epiration of screen idle time
/// this method will be called for every 1 sec.
///
void TickTimeKeyPad(object sender, EventArgs e)
{
try
{
if (intCountSeconds >= Convert.ToInt16(strScreenIdleTime[0]))
{
if (bolApplicationCloseRequest)
{
if (intCountSeconds >= 5)
{
bolApplicationCloseRequest = false;
stkpnl.Visibility = Visibility.Visible;
grdWinKeypad.Visibility = Visibility.Hidden;
EnableCloseButtons();
EnableMultimodeButton();
lblCardInform.Content = strPin = string.Empty;
this.DisTimKeyPad.Stop();
intCountSeconds = 0;
}
intCountSeconds++;
return;
}
intCountSeconds = 0;
GoToModeActivation();
if (isInvalidCard == true)
{
NavigateToWelcome();
isInvalidCard = false;
}
this.DisTimKeyPad.Stop();
}
intCountSeconds++;
}
catch (Exception ex)
{
objBL.LogRecord("Error-> :TickTimeKeyPad " + ex.Message);
throw ex;
}
}
#endregion
///
/// to navigate to Welcome page
/// may be on idle time up or on click of cancel button.
///
private void NavigateToWelcome()
{
try
{
clsCommonCarrier.bolIsLCDStarted = false;
DisTimKeyPad.Stop();
Uri pageFunctionUri = new Uri(NavigationFilePaths.PgWelcome, UriKind.Relative);
frmSub1.Navigate(pageFunctionUri);
clsCommonCarrier.strKeyPadMode = Convert.ToString(eKeypadMode.PINENTRY);
}
catch (Exception ex)
{
objBL.LogRecord("Error-> :NavigateToWelcome " + ex.Message);
throw ex;
}
}
private void CallThread()
{
if ((thTCPWatcher != null && thTCPWatcher.ThreadState != ThreadState.WaitSleepJoin))
//&& (clsCommonCarrier.strThisDoor != null && clsCommonCarrier.strThisDoor != string.Empty))
{
return;
}
try
{
thTCPWatcher = new Thread(new ThreadStart(ReceivePIN));
thTCPWatcher.SetApartmentState(ApartmentState.STA);
thTCPWatcher.Start();
}
catch (Exception ex)
{
objBL.LogRecord("Error-> :CallThread " + ex.Message);
//objCls.ShowMessage_Error("Process failure...");
objCls.MsgBox("Process failure...", "ErrorMsg", "Error!");
}
}