/// <summary> /// This function login the our store. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLogin_Click(object sender, EventArgs e) { try { Database db = new Database(); db.CustomerList(); List <Customer> _cuslist = db.getCustomerList(); foreach (Customer _customer in _cuslist) { if (_customer.IsValid(txtUsername.Text, txtPassword.Text)) { LoginedUser.getInstance().Customer = _customer; MW = new MainWindow(); MW.Show(); this.Hide(); return; } } MessageBox.Show("Invalid username or password!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// This function brings user control settings to front. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSettings_Click(object sender, EventArgs e) { Logger.log("Click to Settings Button."); btnDashboard.BackColor = Color.LightBlue; btnBooks.BackColor = Color.LightBlue; btnMusicCDs.BackColor = Color.LightBlue; btnMagazine.BackColor = Color.LightBlue; btnMyOrders.BackColor = Color.LightBlue; btnMyCart.BackColor = Color.LightBlue; btnSetting.BackColor = Color.Teal; pnlSelectedButton.Visible = true; pnlSelectedButton.Location = new Point(0, 360); if (LoginedUser.getInstance().Customer.Username == "admin") { if (pnlContainer.Controls["UC_AdminControl"] == null) { UC_AdminControl ucAC = new UC_AdminControl(); ucAC.Dock = DockStyle.Fill; pnlContainer.Controls.Add(ucAC); } pnlContainer.Controls["UC_AdminControl"].BringToFront(); } else { if (pnlContainer.Controls["UC_CustomerSettings"] == null) { UC_CustomerSettings ucCS = new UC_CustomerSettings(); ucCS.Dock = DockStyle.Fill; pnlContainer.Controls.Add(ucCS); } pnlContainer.Controls["UC_CustomerSettings"].BringToFront(); } }
private void UC_CustomerSettings_Load(object sender, EventArgs e) { Customer tmpCust = LoginedUser.getInstance().Customer; txtBoxCustomerName.Text = tmpCust.Name; txtBoxCustomerUsername.Text = tmpCust.Username; txtBoxCustomerAddress.Text = tmpCust.Address; txtBoxCustomerEmail.Text = tmpCust.Email; }
private void PaymentForm_Load(object sender, EventArgs e) { try { txtName.Text = LoginedUser.getInstance().Customer.Name; txtAddress.Text = LoginedUser.getInstance().Customer.Address; txtEmail.Text = LoginedUser.getInstance().Customer.Email; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnChangePassword_Click(object sender, EventArgs e) { Logger.log("Click to Change Password Button."); if (Util.ComputeSha256Hash(txtBoxCustomerOldPassword.Text) == LoginedUser.getInstance().Customer.Password) { LoginedUser.getInstance().Customer.Password = Util.ComputeSha256Hash(txtBoxCustomerNewPassword.Text); Database db = new Database(); db.UpdateCustomer(LoginedUser.getInstance().Customer); } else { MessageBox.Show("Please Enter Correct Old Password."); } }
private void btnUptadeCustomerInformations_Click(object sender, EventArgs e) { Logger.log("Click to Uptade Customer Information Button."); if (Util.ComputeSha256Hash(txtBoxPasswordControl.Text) == LoginedUser.getInstance().Customer.Password) { Database db = new Database(); string ID = LoginedUser.getInstance().Customer.CustomerID; db.UpdateCustomer(new Customer(ID, txtBoxCustomerName.Text, txtBoxCustomerAddress.Text, txtBoxCustomerEmail.Text, txtBoxCustomerUsername.Text, Util.ComputeSha256Hash(txtBoxPasswordControl.Text))); } else { MessageBox.Show("Please Enter Correct Password."); } }
/// <summary> /// This function saves user's every event to a txt file. /// </summary> /// <param name="btnlog">This parameter is user's event.</param> public static void log(string btnlog) { Customer cstmr = LoginedUser.getInstance().Customer; string log = cstmr.Username + "\t\t" + btnlog + " Button\t\t" + DateTime.Now.ToShortDateString() + "\t" + DateTime.Now.ToLongTimeString(); string path = Application.StartupPath + @"/Log.txt"; if (!File.Exists(path)) { using (StreamWriter sw = File.CreateText(path)) { sw.WriteLine(string.Format("{0,-25} {1,-50} {2,-15} {3,-15}", "Username", "Button Info", "Date", "Time")); sw.WriteLine(string.Format("{0,-25} {1,-50} {2,-15} {3,-15}", cstmr.Username, btnlog, DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString())); } } using (StreamWriter sw = File.AppendText(path)) { sw.WriteLine(string.Format("{0,-25} {1,-50} {2,-15} {3,-15}", cstmr.Username, btnlog, DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString())); } }