protected void btnLogin_Click(object sender, EventArgs e) { //validate input before connecting to database if (txtUsername.Text.Length < 5 || txtUsername.Text.Length > 20) { lblError.Text = "Entered username length is not less than 5 or greater than 20 characters"; } else if (txtPassword.Text.Length < 6) { lblError.Text = "Entered password is not less than 6 characters "; } else { try { RestaurantUser user = new RestaurantUser(); user.UserName = txtUsername.Text; user.UserPassword = txtPassword.Text; if (user.authenticateUser()) { Response.Redirect("~/UserAccount.aspx"); } } catch { lblError.Text = "Incorrect username and/or password"; } } }
protected void btnUpdateRestaurant_Click(object sender, EventArgs e) { if (lstRestaurants.SelectedIndex != -1) { //create instane of middle layer business object RestaurantUser user = new RestaurantUser(); //set property, so it can be used as a parameter for the query user.UserId = int.Parse(HttpContext.Current.Session["UserID"].ToString()); user.RestaurantId = int.Parse(lstRestaurants.SelectedValue); if (user.updateRestaurantByUserId()) { // System.Threading.Thread.Sleep(4000); lblError.Text = "Restaurant Updated Successfully"; lblError.ForeColor = System.Drawing.Color.Green; UpdatedRestaurantList(); //string RestaurantID = (string)Session["RestaurantID"]; //System.Threading.Thread.Sleep(4000); //txtRestaurant.Text = user.getRestaurantUsingRestaurantID(); //lblError.Text = "Restaurant Updated Successfully"; //lblError.ForeColor = System.Drawing.Color.Green; //Response.Redirect("~/UserAccount.aspx?UpdateSuccess=Restaurant"); } else { //exception thrown so display error lblError.Text = "Database connection error - failed to update record."; } } else { lblError.Text = "Select a Restaurant to update"; } }
protected void btnUpdatePassword_Click(object sender, EventArgs e) { string passWord; RestaurantUser rest_user_class = new RestaurantUser(); // condition to check whether the fields are empty if (txtCurrentPassword.Text == "" || txtNewPassword.Text == "" || txtConfirmPassword.Text == "") { lblError.Text = "Enter password fields correctly...."; } else if (txtNewPassword.Text.Length < 6) { lblError.Text = "password should be 6 character"; } else if (!txtNewPassword.Text.Equals(txtConfirmPassword.Text)) { lblError.Text = "Password did not match"; } else { string input_pass = txtCurrentPassword.Text; // Used to decrypt string string decrypt_pass = DecryptMd5Hash(PassWord); // Compare strings if equal or not bool verify_pass = string.Equals(decrypt_pass, input_pass); // Update password if strings are equals if (verify_pass) { rest_user_class.UserName = UserName; rest_user_class.UserPassword = PassWord; rest_user_class.UpdatedUserPassword = txtConfirmPassword.Text; System.Threading.Thread.Sleep(1000); // check if both passwords are equal bool update_pass = rest_user_class.updatePassword(); //if true then display password is updated if (update_pass) { // If password is updated then the page is redirected to the User account with the url containing password Response.Redirect("~/UserAccount.aspx?UpdateSuccess=" + txtConfirmPassword.Text); lblError.Text = "Password Sucessfully updated.."; lblError.ForeColor = System.Drawing.Color.Green; } else { lblError.Text = "Database connection error - cannot update password..."; lblError.ForeColor = System.Drawing.Color.Red; } } else { lblError.Text = "Incorrect current password"; lblError.ForeColor = System.Drawing.Color.Red; } } }
protected void btnRemoveWaiter_Click(object sender, EventArgs e) { try { if (lstWaiters.SelectedItem.Text == null) { lblError.Text = "Select Waiter to remove"; } else { RestaurantUser user = new RestaurantUser(); user.UserId = Int32.Parse(lstWaiters.SelectedValue); //create instane of middle layer business object DataTable dt = user.removeWaiter(); if (dt != null) { lblSuccess.Text = "Waiter Successfully Removed"; lstWaiters.Items.RemoveAt(lstWaiters.SelectedIndex); } else { lblError.Text = "Datebase Connection Error!!"; } } } catch { lblError.Text = "Database connection error - cannot display Restaurants."; } }
protected void Page_Load(object sender, EventArgs e) { if (Session.Count == 0) { Response.Redirect("~/UserLogin.aspx"); } else { // Used to access functions from the RestaurantUser class RestaurantUser rest_user_class = new RestaurantUser(); PassWord = Session["UserPassword"].ToString(); UserName = Session["UserName"].ToString(); } }
protected void btnUpdatePassword_Click(object sender, EventArgs e) { try { if (txtCurrentPassword.Text.Length < 6) { lblError.Text = "Current password is invalid length."; } else if (txtNewPassword.Text.Length < 6) { lblError.Text = "New password is invalid length."; } else if (!txtConfirmPassword.Text.Equals(txtNewPassword.Text)) { lblError.Text = "Please confirm new password."; } else { RestaurantUser user = new RestaurantUser(); user.UserId = Int32.Parse(Session["UserID"].ToString()); string password = user.getPasswordUsingID(); if (verifyMd5Hash(txtCurrentPassword.Text, password)) { user.UserPassword = txtNewPassword.Text; //UserId already set if (user.updatePasswordByUserId()) { lblError.Text = "Password updated"; Response.Redirect("~/UserAccount.aspx?change=success"); } else { lblError.Text = "Database connection error - could not update password"; } } else { lblError.Text = "Password is incorrect"; } } } catch { lblError.Text = "Current password is incorrect"; } }
protected void txtEmailAddress_TextChanged(object sender, EventArgs e) { EmailExist.Text = ""; RestaurantUser rest_user = new RestaurantUser(); //set property, so it can be used as a parameter for the query rest_user.EmailAddress = txtEmailAddress.Text; //check if username exists if (rest_user.emailExists()) { //already exists so output error EmailExist.Text = "Email already exists...!"; EmailExist.ForeColor = System.Drawing.Color.Red; } else { EmailExist.Text = "Email Available...!"; EmailExist.ForeColor = System.Drawing.Color.Green; } }
protected void TextBox1_TextChanged(object sender, EventArgs e) { UserName_exists.Text = ""; RestaurantUser rest_user = new RestaurantUser(); //set property, so it can be used as a parameter for the query rest_user.UserName = txtUsername.Text; //check if username exists if (rest_user.userNameExists()) { //already exists so output error UserName_exists.Text = "Username already exists...!"; UserName_exists.ForeColor = System.Drawing.Color.Red; } else { UserName_exists.Text = "Username Available...!"; UserName_exists.ForeColor = System.Drawing.Color.Green; } }
protected void btnRegister_Click(object sender, EventArgs e) { if (IsPostBack) { string username, password, real_name, email_add; Console.WriteLine("email_valid", checkforEmail(txtEmailAddress.Text.ToString())); if (txtUsername.Text.Length < 5 || txtUsername.Text.Length > 20) { lblError.Text = "User name should be greater than 5 or less than 20"; } else if (txtPassword.Text.Length < 6) { lblError.Text = "password should be 6 character"; } else if (!txtPassword.Text.Equals(txtConfirmPassword.Text)) { lblError.Text = "Password did not match"; } else if (String.IsNullOrWhiteSpace(txtRealName.Text)) { lblError.Text = "please enter full name"; } else if (String.IsNullOrWhiteSpace(txtEmailAddress.Text) || !checkforEmail(txtEmailAddress.Text.ToString())) { lblError.Text = "please enter valid email"; } else { lblError.Text = ""; RestaurantUser rest_user = new RestaurantUser(); //set property, so it can be used as a parameter for the query rest_user.UserName = txtUsername.Text; //check if username exists if (rest_user.userNameExists()) { //already exists so output error lblError.Text = "Username already exists, please select another"; } else { //midle layar = //presentation layar rest_user.UserName = txtUsername.Text; rest_user.UserPassword = txtPassword.Text; rest_user.RealName = txtRealName.Text; rest_user.EmailAddress = txtEmailAddress.Text; rest_user.RoleID = Int32.Parse(ddlRestaurants.SelectedValue); rest_user.RestaurantID = Int32.Parse(ddlRestaurants0.SelectedValue); //attempt to add a worker and test if it is successful if (rest_user.addUser()) { System.Threading.Thread.Sleep(2000); //redirect user to login page //redirect user to login page Response.Redirect("~/UserLogin.aspx?Registration=Successfull"); } else { //exception thrown so display error lblError.Text = "Database connection error - failed to insert record."; } } } } }
private void UpdatedRestaurantList() { RestaurantUser user = new RestaurantUser(); user.RealName = RealName; // Fetch data from the restaurantUser table to load all the data DataTable dt_chef_details = user.getUserDetails(); if (dt_chef_details.Rows.Count > 0) { // assign session with the new updated data Session["UserID"] = dt_chef_details.Rows[0]["UserID"].ToString(); Session["UserName"] = dt_chef_details.Rows[0]["UserName"].ToString(); Session["UserPassword"] = dt_chef_details.Rows[0]["UserPassword"].ToString(); Session["RealName"] = dt_chef_details.Rows[0]["RealName"].ToString(); Session["EmailAddress"] = dt_chef_details.Rows[0]["EmailAddress"].ToString(); Session["RoleID"] = dt_chef_details.Rows[0]["RoleID"].ToString(); Session["RestaurantID"] = dt_chef_details.Rows[0]["RestaurantID"].ToString(); int RestaurantID = Convert.ToInt32(Session["RestaurantID"].ToString()); Restaurant restaurant = new Restaurant(); restaurant.RestaurantId = RestaurantID; // Fetch chef restaurant and all the other restaurants present DataTable dt_restaurant = restaurant.getsingleRestaurant(); DataTable dt_all_restaurant = restaurant.getRestaurants(); if (dt_restaurant.Rows.Count > 0 && dt_all_restaurant.Rows.Count > 0) { txtRestaurant.Text = dt_restaurant.Rows[0]["RestaurantName"].ToString(); lstRestaurants.DataSource = dt_all_restaurant; //assign WorkerID database field to the value property lstRestaurants.DataValueField = "RestaurantID"; //assign WorkerName database field to the text property lstRestaurants.DataTextField = "RestaurantName"; //bind data lstRestaurants.DataBind(); System.Threading.Thread.Sleep(3000); lblError.Text = "Restaurants listbox Updated"; lblError.ForeColor = System.Drawing.Color.Green; Response.Redirect("~/UserAccount.aspx?UpdateSuccess=Restaurant"); } else { lblError.Text = "Database connection error - cannot display RestaurantNames."; lblError.ForeColor = System.Drawing.Color.Red; } } else { lblError.Text = "Database connection error while updating."; lblError.ForeColor = System.Drawing.Color.Red; } }
protected void btnRegister_Click(object sender, EventArgs e) { try { //validate input if (txtUsername.Text.Length < 5 || txtUsername.Text.Length > 20) { lblError.Text = "Entered username length is not less than 5 or greater than 20 characters"; } else if (txtPassword.Text.Length < 6) { lblError.Text = "Password must be at least 6 characters long."; } else if (!txtConfirmPassword.Text.Equals(txtPassword.Text)) { lblError.Text = "Please confirm password."; } else if (txtRealName.Text.Equals("")) { lblError.Text = "Please enter your full name."; } else { try { //create instane of middle layer business object RestaurantUser user = new RestaurantUser(); //set username property, so it can be used as a parameter for the query user.UserName = txtUsername.Text; user.EmailAddress = txtEmailAddress.Text; //check if the username exists if (user.userNameExists()) { //already exists so output error lblError.Text = "Username already exists, please select another"; } else if (user.emailaddressExists()) { //already exists so output error lblError.Text = "EmailAddress already exists, please enter another one"; } else { //INSERT NEW USER... //set properties, so it can be used as a parameter for the query user.UserName = txtUsername.Text; user.UserPassword = txtPassword.Text; user.RealName = txtRealName.Text; user.EmailAddress = txtEmailAddress.Text; string selectedvalue = rblist1.SelectedValue; user.RoleId = Int32.Parse(selectedvalue);; user.RestaurantId = Int32.Parse(ddlRestaurants.SelectedValue); //attempt to add a User and test if it is successful if (user.adduser()) { //redirect user to login page System.Threading.Thread.Sleep(3000); Response.Redirect("~/UserLogin.aspx"); } } } catch { //exception thrown so display error lblError.Text = "Database connection error - failed to insert record."; } } } catch { //exception thrown so display error lblError.Text = "Database connection error - failed to insert record."; } }
protected void btnLogin_Click(object sender, EventArgs e) { if (IsPostBack) { if (txtUsername.Text.Length < 5) { lblError.Text = "invalid username"; } else if (txtPassword.Text.Length < 6) { lblError.Text = "invalid password"; } else { // Used to access functions and fetch data from RestaurantUser class RestaurantUser Rest_user_login = new RestaurantUser(); // Passing parameters to RestaurantUser class Rest_user_login.UserName = txtUsername.Text; Rest_user_login.UserPassword = txtPassword.Text; // calling function to check username exists or not DataTable check_user = Rest_user_login.CheckUser(); // condition to check if data table is not empty if (check_user.Rows.Count > 0) { string user = check_user.Rows[0]["UserName"].ToString(); Rest_user_login.UserName = txtUsername.Text; // calling function to check user credentials DataTable dt_user_login = Rest_user_login.LoginCredentials(); // condition to check if strings are equal or not bool check_user_name = string.Equals(user, txtUsername.Text); // condition to check if data table is not empty if (dt_user_login.Rows.Count > 0) { string pass = dt_user_login.Rows[0]["UserPassword"].ToString(); string input_pass = txtPassword.Text; // Decrypt password based on the input string decrypt_pass = DecryptMd5Hash(pass); // condition to check if strings are equal or not bool verify_pass = string.Equals(decrypt_pass, input_pass); // condition if strings are equal proceed to login and create session for user if (verify_pass) { Session["UserName"] = dt_user_login.Rows[0]["UserName"].ToString(); Session["UserPassword"] = dt_user_login.Rows[0]["UserPassword"].ToString(); Session["RealName"] = dt_user_login.Rows[0]["RealName"].ToString(); Session["EmailAddress"] = dt_user_login.Rows[0]["EmailAddress"].ToString(); Session["RoleID"] = dt_user_login.Rows[0]["RoleID"].ToString(); Session["RestaurantID"] = dt_user_login.Rows[0]["RestaurantID"].ToString(); // Redirect to the User login Response.Redirect("~/UserAccount.aspx"); } else { lblError.Text = "Credentials are not correct"; } } else { lblError.Text = "Credentials are not correct"; } } else { lblError.Text = "User not found"; } } } }
protected void Page_Load(object sender, EventArgs e) { int roleid = 1; //check if Session has expired or user has not logged in if (Session.Count == 0) { Response.Redirect("~/UserLogin.aspx"); } else { int RestaurantID = Int32.Parse(Session["RestaurantID"].ToString()); RestaurantUser user = new RestaurantUser(); Cuisine cuisine = new Cuisine(); cuisine.RestaurantId = RestaurantID; try { //if request is NOT a post back if (!Page.IsPostBack) { user.RestaurantId = RestaurantID; user.RoleId = roleid; DataTable dt2 = user.getWaiters(); //create instane of middle layer business object Restaurant restaurant = new Restaurant(); // retrieve departments from middle layer into a DataTable restaurant.RestaurantId = int.Parse(HttpContext.Current.Session["RestaurantID"].ToString()); DataTable dt = restaurant.getsingleRestaurant(); // DataTable dt2 = restaurant.getRestaurantUser(); // check if query was successful if (dt.Rows.Count > 0 && dt2 != null) { // bind data txtRestaurant.Text = dt.Rows[0]["RestaurantName"].ToString(); lstWaiters.DataSource = dt2; lstWaiters.DataTextField = "RealName";//bind data lstWaiters.DataValueField = "UserID"; lstWaiters.DataBind(); } else { lblError.Text = " No data fetched-- Database error"; } //retrieve cuisines from middle layer into a DataTable DataTable dt3 = cuisine.bindCuisine(); //check if query was successful if (dt3 != null) { //set RepeaterControls's data source to the DataTable rptCuisines.DataSource = dt3; //bind data rptCuisines.DataBind(); } else { lblError.Text = "Database connection error - cannot display Cuisines."; } } } catch { lblError.Text = "Database connection error - cannot display Restaurants."; } } }