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.Threading.Tasks;
- using System.Configuration;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace WoodsideCommunityHub.Classes.SystemClasses
- {
- class LoginDetails : dbConnection
- {
- public static string _connectionString = ConfigurationManager.ConnectionStrings["WoodsideCommunityHub"].ConnectionString;
- public static List<int> StaffIDs = new List<int>() { };
- public static List<string> Usernames = new List<string>() { };
- public static List<string> Passwords = new List<string>() { };
- public static int StaffID = 0;
- public static string Username = "";
- public static string Password = "";
- public static void SelectAllLoginDetails()
- {
- using (SqlConnection connection = new SqlConnection(_connectionString))
- {
- string Query = "SELECT * FROM LoginDetails";
- SqlCommand Select = new SqlCommand(Query, connection);
- SqlDataReader Reader;
- try
- {
- connection.Open();
- Reader = Select.ExecuteReader();
- while (Reader.Read())
- {
- int sID = Reader.GetInt32(0);
- StaffIDs.Add(sID);
- string uName = Reader.GetString(1);
- Usernames.Add(uName);
- string pass = Reader.GetString(2);
- Passwords.Add(pass);
- }
- }-
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- connection.Close();
- }
- }
- }
- private string username;
- private string password;
- private bool okFlag = true;
- private List<string> messages = new List<string>() { };
- public void setUsername(string _Username)
- {
- if (!string.IsNullOrWhiteSpace(_Username))
- {
- if (_Username.Length <= 30)
- {
- this.username = _Username;
- }
- else
- {
- messages.Add("The username must be less than 30 characters long.");
- okFlag = false;
- }
- }
- else
- {
- messages.Add("Username cannot be blank. Please enter a username.");
- okFlag = false;
- }
- }
- public string getUsername()
- {
- return username;
- }
- public void setPassword(string _Password)
- {
- if (!string.IsNullOrWhiteSpace(_Password))
- {
- if (_Password.Length <= 30)
- {
- this.password = _Password;
- }
- else
- {
- messages.Add("The password must be less than 30 characters long.");
- okFlag = false;
- }
- }
- else
- {
- messages.Add("Password cannot be blank. Please enter a password.");
- okFlag = false;
- }
- }
- public string getPassword()
- {
- return password;
- }
- public void setOkFlag(bool OkFlag)
- {
- this.okFlag = OkFlag;
- }
- public bool getOkFlag()
- {
- return okFlag;
- }
- public void InsertAllLoginDetails()
- {
- using (SqlConnection connection = new SqlConnection(_connectionString))
- {
- string Query = $"INSERT INTO LoginDetails(Username, Password) VALUES('{getUsername()}', '{getPassword()}')";
- SqlCommand Insert = new SqlCommand(Query, connection);
- if (okFlag == false)
- {
- MessageBox.Show("The request could not be compelted as errors have occured.");
- }
- else
- {
- try
- {
- connection.Open();
- Insert.ExecuteNonQuery();
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- finally
- {
- connection.Close();
- messages.ForEach(Console.WriteLine);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement