public MainAppForm() { custInfo = CustomerInfo.getSample(); InitializeComponent(); }
public CustomerInfo SelectUser(string customer_username, string customer_password) { CustomerInfo customer = null; string connectionString = GetConnectionString(); try { using (sql_connection = new MySqlConnection(connectionString)) { sql_connection.Open(); using (sql_command = new MySqlCommand("Select * from customer where customer_username = @CustomerName", sql_connection)) { sql_command.Parameters.AddWithValue("CustomerName", customer_username); } MySqlDataReader reader = sql_command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { bool securingResult = false; SecurePassword pw = new SecurePassword(); securingResult = pw.Verifing((string)reader["customer_password"], customer_password.ToString()); if (securingResult == false) { MessageBox.Show("Password is incorrect"); } else { customer = CustomerInfo.getSample(); customer.Customerid = (int)reader["customer_id"]; customer.Customername = (string)reader["customer_name"]; customer.Customeraddress = (string)reader["customer_adress"]; customer.Customeremail = (string)reader["customer_email"]; customer.Customerusername = (string)reader["customer_username"]; customer.Customerpassword = (string)reader["customer_password"]; using (MemoryStream ms = new MemoryStream((byte[])reader["customer_image"])) { customer.Customerimage = Image.FromStream(ms); } int value = reader.GetByte("customer_gender"); if (value == 1) { customer.Customergender = true; } else { customer.Customergender = false; } } } reader.Close(); sql_command.ExecuteNonQuery(); } else { MessageBox.Show("Login or password is incorect!"); } } } catch (Exception ex) { MessageBox.Show("Connection failed!!! \n" + ex.Message, "FAIL", MessageBoxButtons.OK, MessageBoxIcon.Error); } db_oper.sql_connection.Close(); return(customer); }