Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data.OleDb;
- using SC = System.Console;
- /// <summary>
- /// Summary description for User
- /// </summary>
- namespace StarCrime
- {
- public class User
- {
- public string userIdStr;
- public string userNameStr;
- public string userAddressStr;
- public string userContactStr;
- public string userEmailStr;
- public DateTime regDt;
- public string userPwd;
- public string userType;
- public string userPwdStr;
- //======= toSql help function =========
- public static string toSql(int valueInt)
- {
- return valueInt.ToString();
- }
- public static string toSql(string valueStr)
- {
- return "'" + valueStr.Replace("'", "''") + "'";
- }
- //======= toSql help function =========
- //========= Verify User On Login =========
- public bool verifyUser(OleDbConnection mDB, string userIdStr, string userPwd)
- {
- string sqlQuery;
- OleDbCommand cmd;
- OleDbDataReader rdr;
- /* SC.Write("\n[Login] \nUser ID: ");
- userIdStr = SC.ReadLine();
- SC.Write("Password: ");
- {//===== Masking Password
- ConsoleKeyInfo userPassword;
- string pass = "";
- do
- {
- userPassword = Console.ReadKey(true);
- if (userPassword.Key != ConsoleKey.Backspace && userPassword.Key != ConsoleKey.Enter)
- {
- pass += userPassword.KeyChar;
- Console.Write("*");
- }
- } while (userPassword.Key != ConsoleKey.Enter);
- Console.WriteLine();
- userPwd = pass;
- }//====== eNd */
- sqlQuery = "SELECT userID,userPassword,userName,userType FROM userTable WHERE userID= " +
- toSql(userIdStr);
- cmd = new OleDbCommand(sqlQuery, mDB);
- Boolean valid = false;
- Boolean HasRows = false;
- try
- {
- rdr = cmd.ExecuteReader();
- if (rdr.HasRows)
- {
- while (rdr.Read())
- if (userPwd == (string)rdr["userPassword"])
- {
- valid = true;
- userType = (string)rdr["userType"];
- userIdStr = (string)rdr["userID"];
- }
- HasRows = true;
- }
- rdr.Close();
- }
- catch (Exception ex)
- {
- SC.WriteLine(ex.Message);
- }
- if (valid == true)
- {
- SC.WriteLine("\nWelcome to Star Crime Management System" + " " + userIdStr + "!");
- return true;
- }
- else if (HasRows == false)
- {
- SC.WriteLine("Invalid login, please try again!");
- }
- else
- {
- SC.WriteLine("Invalid password, please try again!");
- }
- return false;
- } //===== eNd
- public string getUserType() //===== Return the user type which needed in logon process
- {
- return userType;
- }
- public string getUserId() //==== Return the user ID which capture all the field item based on ID
- {
- return userIdStr;
- }
- //=========== Insert New User ===========
- public void InsertNewUser(OleDbConnection mDB)
- {
- string sqlQuery;
- OleDbCommand cmd;
- //readNewCustomer();
- sqlQuery = "INSERT INTO userTable("
- + "userID, "
- + "userPassword, "
- + "userName, "
- + "userAddress, "
- + "userContact, "
- + "userEmail, "
- + "userType, "
- + "regDateTime"
- + ") VALUES ("
- + toSql(userIdStr) + ", "
- + toSql(userPwdStr) + ", "
- + toSql(userNameStr) + ", "
- + toSql(userAddressStr) + ", "
- + toSql(userContactStr) + ", "
- + toSql(userEmailStr) + ", "
- + toSql(userType) + ", "
- + "'" + regDt.ToString() + "'"
- + ")";
- // try
- {
- cmd = new OleDbCommand(sqlQuery, mDB);
- cmd.ExecuteNonQuery();
- // SC.WriteLine("\nNew customer has been added successfully.");
- }
- // catch (Exception ex)
- {
- // SC.WriteLine("\nError Message :" + ex.Message);
- }
- } //====== eNd
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement