Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data.OleDb;
  6. using SC = System.Console;
  7.  
  8. /// <summary>
  9. /// Summary description for User
  10. /// </summary>
  11.  
  12. namespace StarCrime
  13. {
  14. public class User
  15. {
  16. public string userIdStr;
  17. public string userNameStr;
  18. public string userAddressStr;
  19. public string userContactStr;
  20. public string userEmailStr;
  21. public DateTime regDt;
  22. public string userPwd;
  23. public string userType;
  24. public string userPwdStr;
  25.  
  26. //======= toSql help function =========
  27. public static string toSql(int valueInt)
  28. {
  29. return valueInt.ToString();
  30. }
  31. public static string toSql(string valueStr)
  32. {
  33. return "'" + valueStr.Replace("'", "''") + "'";
  34. }
  35. //======= toSql help function =========
  36.  
  37. //========= Verify User On Login =========
  38. public bool verifyUser(OleDbConnection mDB, string userIdStr, string userPwd)
  39. {
  40. string sqlQuery;
  41. OleDbCommand cmd;
  42. OleDbDataReader rdr;
  43.  
  44. /* SC.Write("\n[Login] \nUser ID: ");
  45. userIdStr = SC.ReadLine();
  46.  
  47. SC.Write("Password: ");
  48. {//===== Masking Password
  49. ConsoleKeyInfo userPassword;
  50. string pass = "";
  51.  
  52. do
  53. {
  54. userPassword = Console.ReadKey(true);
  55. if (userPassword.Key != ConsoleKey.Backspace && userPassword.Key != ConsoleKey.Enter)
  56. {
  57. pass += userPassword.KeyChar;
  58. Console.Write("*");
  59. }
  60. } while (userPassword.Key != ConsoleKey.Enter);
  61. Console.WriteLine();
  62.  
  63. userPwd = pass;
  64. }//====== eNd */
  65.  
  66. sqlQuery = "SELECT userID,userPassword,userName,userType FROM userTable WHERE userID= " +
  67. toSql(userIdStr);
  68. cmd = new OleDbCommand(sqlQuery, mDB);
  69.  
  70. Boolean valid = false;
  71. Boolean HasRows = false;
  72. try
  73. {
  74. rdr = cmd.ExecuteReader();
  75. if (rdr.HasRows)
  76. {
  77. while (rdr.Read())
  78. if (userPwd == (string)rdr["userPassword"])
  79. {
  80. valid = true;
  81. userType = (string)rdr["userType"];
  82. userIdStr = (string)rdr["userID"];
  83. }
  84. HasRows = true;
  85. }
  86. rdr.Close();
  87. }
  88. catch (Exception ex)
  89. {
  90. SC.WriteLine(ex.Message);
  91. }
  92.  
  93. if (valid == true)
  94. {
  95. SC.WriteLine("\nWelcome to Star Crime Management System" + " " + userIdStr + "!");
  96. return true;
  97. }
  98. else if (HasRows == false)
  99. {
  100. SC.WriteLine("Invalid login, please try again!");
  101. }
  102. else
  103. {
  104. SC.WriteLine("Invalid password, please try again!");
  105. }
  106. return false;
  107. } //===== eNd
  108.  
  109. public string getUserType() //===== Return the user type which needed in logon process
  110. {
  111. return userType;
  112. }
  113.  
  114. public string getUserId() //==== Return the user ID which capture all the field item based on ID
  115. {
  116. return userIdStr;
  117. }
  118.  
  119. //=========== Insert New User ===========
  120. public void InsertNewUser(OleDbConnection mDB)
  121. {
  122. string sqlQuery;
  123. OleDbCommand cmd;
  124.  
  125. //readNewCustomer();
  126.  
  127. sqlQuery = "INSERT INTO userTable("
  128. + "userID, "
  129. + "userPassword, "
  130. + "userName, "
  131. + "userAddress, "
  132. + "userContact, "
  133. + "userEmail, "
  134. + "userType, "
  135. + "regDateTime"
  136.  
  137. + ") VALUES ("
  138.  
  139. + toSql(userIdStr) + ", "
  140. + toSql(userPwdStr) + ", "
  141. + toSql(userNameStr) + ", "
  142. + toSql(userAddressStr) + ", "
  143. + toSql(userContactStr) + ", "
  144. + toSql(userEmailStr) + ", "
  145. + toSql(userType) + ", "
  146. + "'" + regDt.ToString() + "'"
  147. + ")";
  148.  
  149. // try
  150. {
  151. cmd = new OleDbCommand(sqlQuery, mDB);
  152. cmd.ExecuteNonQuery();
  153. // SC.WriteLine("\nNew customer has been added successfully.");
  154. }
  155. // catch (Exception ex)
  156. {
  157. // SC.WriteLine("\nError Message :" + ex.Message);
  158. }
  159. } //====== eNd
  160.  
  161. }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement