You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
186 lines
7.4 KiB
186 lines
7.4 KiB
3 months ago
|
using BiskLog_Point_Of_Sale;
|
||
|
using BiskLog_Point_Of_Sale.Cashier_Module;
|
||
|
using BiskLog_Point_Of_Sale.Company_Setup;
|
||
|
using BiskLog_Point_Of_Sale.Multiple_Login;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.ComponentModel;
|
||
|
using System.Data;
|
||
|
using System.Data.SqlClient;
|
||
|
using System.Drawing;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using System.Threading.Tasks;
|
||
|
using System.Windows.Forms;
|
||
|
|
||
|
namespace Point_Of_Sale_Managment
|
||
|
{
|
||
|
public partial class AdminUser : Form
|
||
|
{
|
||
|
SqlConnection cn;
|
||
|
SqlCommand cm;
|
||
|
DatabaseConn conn = new DatabaseConn();
|
||
|
SqlDataReader dr;
|
||
|
string firstname = "", surname = "", address1 = "", address2 = "", state = "", phone = "", email = "", pass = "";
|
||
|
private void TxtPassword_KeyDown(object sender, KeyEventArgs e)
|
||
|
{
|
||
|
if (e.KeyCode == Keys.Back)
|
||
|
{
|
||
|
txtPassword.Text = "";
|
||
|
txtConfirmation.Text = "";
|
||
|
}
|
||
|
}
|
||
|
private async void Button1_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
if ((txtPassword.Text.Equals(txtConfirmation.Text)) && !String.IsNullOrEmpty(txtPassword.Text))
|
||
|
{
|
||
|
Task<int> task = new Task<int>(updateDetails);
|
||
|
holding.Visible = true;
|
||
|
button1.Enabled = false;
|
||
|
button2.Enabled = false;
|
||
|
task.Start();
|
||
|
int result = await task;
|
||
|
if (result == 1)
|
||
|
{
|
||
|
string title = "Success";
|
||
|
string message = "Update successful";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
string title = "Error Occurred";
|
||
|
string message = "An error occurred while updating user details, please try again later";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
holding.Visible = false;
|
||
|
button1.Enabled = true;
|
||
|
button2.Enabled = true;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
public AdminUser()
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
cn = new SqlConnection(conn.MyConnection());
|
||
|
holding.Left = (ClientSize.Width - holding.Width) / 2;
|
||
|
}
|
||
|
private async void AdminUser_Load(object sender = null, EventArgs e = null)
|
||
|
{
|
||
|
Task<int> task = new Task<int>(getUser);
|
||
|
holding.Visible = true;
|
||
|
task.Start();
|
||
|
int result = await task;
|
||
|
if (result == 0)
|
||
|
{
|
||
|
string title = "Error Occurred";
|
||
|
string message = "An error occurred while getting user details, please try again later";
|
||
|
NoAction noAction = new NoAction(title, message);
|
||
|
noAction.BringToFront();
|
||
|
noAction.ShowDialog();
|
||
|
}
|
||
|
holding.Visible = false;
|
||
|
}
|
||
|
public int getUser()
|
||
|
{
|
||
|
string currentUser;
|
||
|
currentUser = MainLogin.login_user;
|
||
|
|
||
|
try
|
||
|
{
|
||
|
cn.Open();
|
||
|
cm = new SqlCommand("Select firstname,surname,street_address1,street_address2,tblUsers.state_or_province,telephone,email,access_level," +
|
||
|
"tblBranches.branchName,username,password from tblUsers Left Join tblBranches On tblBranches.branchID = tblUsers.branchID where username = @username", cn);
|
||
|
cm.Parameters.AddWithValue("@username", currentUser);
|
||
|
cm.ExecuteNonQuery();
|
||
|
dr = cm.ExecuteReader();
|
||
|
dr.Read();
|
||
|
if (dr.HasRows)
|
||
|
{
|
||
|
txtBranch.Invoke(new Action(() =>
|
||
|
{
|
||
|
txtBranch.Text = dr["branchName"].ToString();
|
||
|
firstname = txtFirstname.Text = dr[0].ToString();
|
||
|
surname = txtSurname.Text = dr[1].ToString();
|
||
|
address1 = txtAddress1.Text = dr[2].ToString();
|
||
|
address2 = txtAddress2.Text = dr[3].ToString();
|
||
|
state = txtState.Text = dr[4].ToString();
|
||
|
phone = txtPhone.Text = dr[5].ToString();
|
||
|
email = txtEmail.Text = dr[6].ToString();
|
||
|
switch (dr[7].ToString())
|
||
|
{
|
||
|
case "owner":
|
||
|
acesslevel.Text = "Owner";
|
||
|
break;
|
||
|
case "manager":
|
||
|
acesslevel.Text = "Manager";
|
||
|
break;
|
||
|
case "assist":
|
||
|
acesslevel.Text = "Assistant Manager";
|
||
|
break;
|
||
|
case "cashier":
|
||
|
acesslevel.Text = "Cashier";
|
||
|
break;
|
||
|
}
|
||
|
txtusername.Text = dr[9].ToString();
|
||
|
pass = txtPassword.Text = passwordEncryption.Decrypt(dr[10].ToString());
|
||
|
txtConfirmation.Text = passwordEncryption.Decrypt(dr[10].ToString());
|
||
|
}));
|
||
|
}
|
||
|
dr.Close();
|
||
|
cn.Close();
|
||
|
return 1;
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
cn.Close();
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
public int updateDetails()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
cn.Open();
|
||
|
cm = new SqlCommand("Update tblUsers set firstname = @firstname,surname = @surname,street_address1=@address1,street_address2 = @address2,state_or_province = @state," +
|
||
|
"telephone = @telephone,email = @email,password = @password where username = @username", cn);
|
||
|
cm.Parameters.AddWithValue("@username", MainLogin.login_user);
|
||
|
txtFirstname.Invoke(new Action(() =>
|
||
|
{
|
||
|
cm.Parameters.AddWithValue("@firstname", txtFirstname.Text);
|
||
|
cm.Parameters.AddWithValue("@surname", txtSurname.Text);
|
||
|
cm.Parameters.AddWithValue("@address1", txtAddress1.Text);
|
||
|
cm.Parameters.AddWithValue("@address2", txtAddress2.Text);
|
||
|
cm.Parameters.AddWithValue("@state", txtState.Text);
|
||
|
cm.Parameters.AddWithValue("@email", txtEmail.Text);
|
||
|
cm.Parameters.AddWithValue("@telephone", txtPhone.Text);
|
||
|
cm.Parameters.AddWithValue("@password", passwordEncryption.Encrypt(txtPassword.Text));
|
||
|
cm.ExecuteNonQuery();
|
||
|
}));
|
||
|
cn.Close();
|
||
|
return 1;
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
cn.Close();
|
||
|
return 0;
|
||
|
}
|
||
|
}
|
||
|
private void Button2_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
txtFirstname.Text = firstname;
|
||
|
txtSurname.Text = surname;
|
||
|
txtAddress1.Text = address1;
|
||
|
txtAddress2.Text = address2;
|
||
|
txtState.Text = state;
|
||
|
txtPhone.Text = phone;
|
||
|
txtEmail.Text = email;
|
||
|
txtPassword.Text = pass;
|
||
|
txtConfirmation.Text = pass;
|
||
|
}
|
||
|
}
|
||
|
}
|