PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/AT870Mobile/LoginForm.cs

https://bitbucket.org/bborad/rfidmobile
C# | 246 lines | 190 code | 27 blank | 29 comment | 38 complexity | 2fb6b8884d51d33d0f9d03bf7652b964 MD5 | raw file
  1. /**************************************************************************************
  2. * Author : Deepanshu Jouhari
  3. * Created Date : 21 Sep 2008
  4. * Last Modified by :
  5. * Last Modified : 18 Aug 2009
  6. * Module Name : Ramp Mobile
  7. * Decription : For Login functionality
  8. **************************************************************************************/
  9. using System;using HHDeviceInterface.RFIDSp; using ReaderTypes; using ClslibHotkey;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Text;using CS101UILib;
  15. using System.Windows.Forms;
  16. using System.Threading;
  17. using ClsRampdb;
  18. using ClslibSerialNo;
  19. using ClsLibBKLogs;
  20. namespace OnRamp
  21. {
  22. public partial class LoginForm : Form
  23. {
  24. public LoginForm()
  25. {
  26. InitializeComponent();
  27. /* Select the prompt message */
  28. this.UsrNameTxtBx.SelectAll();
  29. }
  30. private void SkipButtonClicked(object sender, EventArgs e)
  31. {
  32. /*
  33. // Close LoginForm and Open MainMenuForm
  34. MainMenuForm MainMenu = new MainMenuForm();
  35. MainMenu.Show();
  36. this.Close();
  37. */
  38. this.Close();
  39. Program.ReqEnd = true;
  40. }
  41. private void OnOKButtonClicked(object sender, EventArgs e)
  42. {
  43. /*
  44. if (VerifyPassword() == true)
  45. SkipButtonClicked(sender, e);
  46. */
  47. try
  48. {
  49. Cursor.Current = Cursors.WaitCursor;
  50. UserPref Pref = UserPref.GetInstance();
  51. Login.urlStr = Pref.ServiceURL;
  52. Login.OnLineMode = chkOnline.Checked;
  53. bool IsRegistered = true;
  54. if (Login.verifyPassword(UsrNameTxtBx.Text, PwdTxtBx.Text))
  55. {
  56. Pref.UserName = UsrNameTxtBx.Text.Trim();
  57. Pref.Passwd = PwdTxtBx.Text.Trim();
  58. String appCode;
  59. DateTime ExpiryDate;
  60. string NoOfItemCode;
  61. if (chkRegistration.Checked || Pref.Key.Trim().Length ==0 )
  62. {
  63. IsRegistered = false;
  64. }
  65. else if (Encrypt.IsValidKey(Pref.Key, SerialNo.GetDeviceID(),out appCode,out ExpiryDate,out NoOfItemCode))
  66. {
  67. ///
  68. if (appCode.Length != 4 || appCode.Substring(1, 1) != "1")
  69. {
  70. MessageBox.Show("Invalid Registration key, Please contact your vendor.");
  71. IsRegistered = false;
  72. }
  73. else if (ExpiryDate <= DateTime.Now)
  74. {
  75. MessageBox.Show("Your subscription has expired. Please contact your vendor.");
  76. IsRegistered = false;
  77. }
  78. else if(ExpiryDate.ToString("dd/MM/yyyy").Trim() != Pref.OnExpired.Trim())
  79. {
  80. MessageBox.Show("Corrupted Expiry Date.");
  81. IsRegistered = false;
  82. }
  83. else if (Pref.ItemLimit.Trim() != NoOfItemCode.Trim())
  84. {
  85. MessageBox.Show("Corrupted Item Limit.");
  86. IsRegistered = false;
  87. }
  88. if (IsRegistered)
  89. {
  90. Int32 NoOfItems = Encrypt.GetMaxNoofItems(Pref.ItemLimit);
  91. if (NoOfItems != 0)
  92. {
  93. if (!Login.OnLineMode)
  94. {
  95. Login._ItemLimit = NoOfItems - Assets.getNoOfItems();
  96. if (Login.ItemLimit < 0)
  97. {
  98. MessageBox.Show("You are crossing registered item limit(" + NoOfItems + "). Please upgrade your registration.");
  99. IsRegistered = false;
  100. }
  101. }
  102. else
  103. {
  104. Login._ItemLimit = NoOfItems;
  105. if (Assets.getNoOfItems() > NoOfItems)
  106. {
  107. MessageBox.Show("You are crossing registered item limit(" + NoOfItems + "). Please upgrade your registration.");
  108. IsRegistered = false;
  109. }
  110. }
  111. }
  112. else
  113. {
  114. Login._ItemLimit = 50000;
  115. }
  116. }
  117. }
  118. Cursor.Current = Cursors.Default;
  119. if (IsRegistered)
  120. {
  121. MainMenuForm MainMenu = new MainMenuForm();
  122. MainMenu.Show();
  123. this.Close();
  124. }
  125. else
  126. {
  127. frmRegister fReg = new frmRegister();
  128. fReg.Show();
  129. this.Close();
  130. }
  131. /*
  132. * MainMenuForm MainMenu = new MainMenuForm();
  133. MainMenu.Show();
  134. this.Close();
  135. * */
  136. //this.Enabled = false;
  137. //MainMenu.Closed += new EventHandler(MainMenu_Closed);
  138. }
  139. else
  140. {
  141. Cursor.Current = Cursors.Default;
  142. if (Login.err.Length != 0)
  143. MessageBox.Show(Login.err);
  144. else
  145. MessageBox.Show("Invalid User Name or Password.");
  146. Logger.LogError("Invalid User Name or Password.");
  147. }
  148. //Login.OnLineMode = false;// chkOnline.Checked;
  149. }
  150. catch (ApplicationException AP)
  151. {
  152. Logger.LogError(AP.Message);
  153. Program.ShowError(AP.Message);
  154. }
  155. catch (System.Data.SqlServerCe.SqlCeException sEx)
  156. {
  157. Logger.LogError(sEx.Message);
  158. Program.ShowError("Data File is not able to access.");
  159. }
  160. catch (System.Net.WebException wEx)
  161. {
  162. Logger.LogError(wEx.Message);
  163. Program.ShowError("Web exception occured.");
  164. }
  165. catch (Exception ep)
  166. {
  167. Logger.LogError(ep.Message);
  168. Program.ShowError(ep.Message.ToString());
  169. }
  170. Cursor.Current = Cursors.Default;
  171. }
  172. void MainMenu_Closed(object sender, EventArgs e)
  173. {
  174. this.Enabled = true;
  175. //throw new NotImplementedException();
  176. }
  177. private bool VerifyPassword()
  178. {
  179. UserPref Pref = UserPref.GetInstance();
  180. if (Pref.UserName == null || Pref.UserName.Length == 0)
  181. return true;
  182. if (String.Compare(Pref.UserName, UsrNameTxtBx.Text, true) != 0)
  183. {
  184. MessageBox.Show("Unrecognized Login Name", "Failed");
  185. return false;
  186. }
  187. if (Pref.Passwd == null || Pref.Passwd.Length == 0)
  188. return true;
  189. if (String.Compare(Pref.Passwd, PwdTxtBx.Text, false) != 0)
  190. {
  191. MessageBox.Show("Incorrect Password", "Failed");
  192. return false;
  193. }
  194. return true;
  195. }
  196. private void OnUsrNameTxtBxKeyPress(object sender, KeyPressEventArgs e)
  197. {
  198. Program.AlphaNumKeyPressChk(sender, e);
  199. }
  200. private void OnPwdTxtBxKeyPress(object sender, KeyPressEventArgs e)
  201. {
  202. Program.AlphaNumKeyPressChk(sender, e);
  203. }
  204. private void PwdTxtBx_TextChanged(object sender, EventArgs e)
  205. {
  206. }
  207. private void LoginForm_Closed(object sender, EventArgs e)
  208. {
  209. }
  210. private void LoginForm_Load(object sender, EventArgs e)
  211. {
  212. lblVersion.Text = UserPref.CurVersionNo;
  213. UserPref Pref = UserPref.GetInstance();
  214. UsrNameTxtBx.Text = Pref.UserName;
  215. PwdTxtBx.Text = Pref.Passwd;
  216. Logger.enableErrorLogging = Pref.EnableErrorLogging;
  217. }
  218. }
  219. }