public int GetId() { int id = 0; try { DatabaseConnectivity dc = new DatabaseConnectivity(); dc.Connect(); MySqlCommand command = new MySqlCommand(); command.Parameters.AddWithValue("@el", Email); command.Parameters.AddWithValue("@pd", Password); dc.ExecuteReader(command, "SELECT AccountId FROM accounts WHERE Email=@el AND Password=@pd;"); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { id = Convert.ToInt32(reader["AccountId"]); } } catch { MessageBox.Show("Something went wrong.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Id = id; return(Id); }
private Task <bool> ServerValidate() { Task <bool> validate = new Task <bool>(() => { try { DatabaseConnectivity dc = new DatabaseConnectivity(); dc.Connect(); MySqlDataReader reader = dc.ExecuteReader("SELECT Email FROM accounts;"); while (reader.Read()) { if (Email.Equals(reader["Email"])) { Message = "This Email is already exists."; return(false); } } dc.Unconnect(); Message = ""; return(true); } catch (Exception e) { Message = e.Message; return(false); } }); validate.Start(); return(validate); }
private Task <bool> AddAccount() { Task <bool> addAccount = new Task <bool>(() => { try { DatabaseConnectivity dc = new DatabaseConnectivity(); dc.Connect(); MySqlCommand command = new MySqlCommand(); command.Parameters.AddWithValue("@un", Username); command.Parameters.AddWithValue("@el", Email); command.Parameters.AddWithValue("@pd", Password); command.Parameters.AddWithValue("@sid", 1); dc.Execute(command, "INSERT INTO accounts (Username, Email, Password, SettingsId) VALUES (@un, @el, @pd, @sid);"); dc.Unconnect(); return(true); } catch { Message = "Something went wrong."; return(false); } }); addAccount.Start(); return(addAccount); }
public string GetUsername() { string username = ""; try { DatabaseConnectivity dc = new DatabaseConnectivity(); dc.Connect(); MySqlCommand command = new MySqlCommand(); command.Parameters.AddWithValue("@el", Email); command.Parameters.AddWithValue("@pd", Password); dc.ExecuteReader(command, "SELECT Username FROM accounts WHERE Email=@el AND Password=@pd;"); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { username = reader["Username"].ToString(); } dc.Unconnect(); } catch { MessageBox.Show("Something went wrong.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Username = username; return(Username); }
private Task <bool> Login() { Task <bool> login = new Task <bool>(() => { try { bool isFound = false; if (!Email.Equals(string.Empty) && !Password.Equals(string.Empty)) { DatabaseConnectivity dc = new DatabaseConnectivity(); dc.Connect(); MySqlCommand command = new MySqlCommand(); command.Parameters.AddWithValue("@el", Email); command.Parameters.AddWithValue("@pd", Password); dc.ExecuteReader(command, "SELECT * FROM accounts WHERE Email=@el and Password=@pd"); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { if (reader["Email"].Equals(Email) && reader["Password"].Equals(Password)) { isFound = true; } } Message = isFound ? "" : "Email address or password is incorrect."; dc.Unconnect(); } else { isFound = false; Message = "Fill the empty fields."; } return(isFound); } catch { Message = "Something went wrong"; return(false); } }); login.Start(); return(login); }