private void ConnectionToDB(string userPhone, string userPass) { DB db = new DB(); db.openConnection(); DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(); MySqlCommand command = new MySqlCommand("SELECT * FROM `users` WHERE `PhoneNum` = @uL" + " AND `Password` = @uP", db.GetConnection()); command.Parameters.Add("@uL", MySqlDbType.VarChar).Value = userPhone; command.Parameters.Add("@uP", MySqlDbType.VarChar).Value = userPass; adapter.SelectCommand = command; adapter.Fill(table); if (table.Rows.Count > 0) { this.Hide(); MainWin mw = new MainWin(userPhone, userPass); SavePassword(userPhone, userPass); mw.Show(); } }
public void CreateCard(string type, string age, string pin, string phone, string pass) { if (Int16.Parse(age) >= 18) { DB db = new DB(); db.openConnection(); DataTable table = new DataTable(); MySqlDataAdapter adapter = new MySqlDataAdapter(); MySqlCommand command = new MySqlCommand("UPDATE `users` SET `CardNum` = @card, `PIN` = @pin WHERE `PhoneNum` = @phone AND Password = @pass", db.GetConnection()); command.Parameters.Add("@card", MySqlDbType.VarChar).Value = CardNumGenenerate(type); command.Parameters.Add("@pin", MySqlDbType.VarChar).Value = pin; command.Parameters.Add("@phone", MySqlDbType.VarChar).Value = phone; command.Parameters.Add("@pass", MySqlDbType.VarChar).Value = pass; if (command.ExecuteNonQuery() == 1) { this.Close(); MainWin mw = new MainWin(phone, pass); mw.Show(); } db.closeConnection(); } }
private void Button_Click(object sender, RoutedEventArgs e) { String username1 = username.Text.ToString(); String password1 = password.Password.ToString(); //connection.Open(); string myconnstrng = "server=localhost;user=root;database=saledb;port=3306;password=123456"; MySqlConnection conn = new MySqlConnection(myconnstrng); try { //SQL Query to check login //string sql = "SELECT userName , password FROM operator WHERE userName=@username AND password=@password "; string sql = " SELECT saleOperatorUserName , saleOperatorPassword from saleoperator WHERE saleOperatorUserName='******'and saleOperatorPassword='******'"; //Creating SQL Command to pass value MySqlCommand cmd = new MySqlCommand(sql, conn); //cmd.Parameters.AddWithValue("@username", username1); //cmd.Parameters.AddWithValue("@password", password1); MySqlDataAdapter adapter = new MySqlDataAdapter(cmd); DataTable dt = new DataTable(); adapter.Fill(dt); //Checking The rows in DataTable if (dt.Rows.Count > 0) { //Login Sucessful MainOperatorWindow mainoperatorwindow = new MainOperatorWindow(); MessageBox.Show("Sucsess login!"); mainoperatorwindow.Show(); this.Close(); } else if (username1.Equals("admin") && password1.Equals("admin")) { MainWin adminpage = new MainWin(); MessageBox.Show("Sucsess login! Welcome to administrator account"); adminpage.Show(); this.Close(); } else { //Login Failed MessageBox.Show("Invalid Login please check username and password"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } }