public void AddNew(User newUser) { MyConnection newConnection = new MyConnection(); MySqlCommand comm = new MySqlCommand(); MySqlConnection conn = new MySqlConnection(newConnection.ConnectionString); try { conn.Open(); String strQuery = "INSERT INTO tblUser(UserTypeID, Username, Password) VALUES" + " ('" + newUser.UserTypeID + "','" + newUser.strUsername + "','" + newUser.strPassword + "')"; comm.Connection = conn; comm.CommandText = strQuery; comm.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message, "PMIS", MessageBoxButtons.OK, MessageBoxIcon.Error); } conn.Close(); }
private void cmdLogin_Click(object sender, EventArgs e) { User newUser = new User(); ParishInformationManagement newMDI = new ParishInformationManagement(); if (string.IsNullOrEmpty(txtUsername.Text)) { MessageBox.Show("Please specify username.","User Login",MessageBoxButtons.OK,MessageBoxIcon.Information); txtUsername.Focus(); return; } else if (string.IsNullOrEmpty(txtPassword.Text)) { MessageBox.Show("Please specify password.", "User Login", MessageBoxButtons.OK, MessageBoxIcon.Information); txtPassword.Focus(); return; } else if (!newUser.UsernameExist(txtUsername.Text)) { MessageBox.Show("Username or Password does not match.", "User Login", MessageBoxButtons.OK, MessageBoxIcon.Information); txtUsername.Focus(); return; } else if (!newUser.PasswordExist(txtPassword.Text)) { MessageBox.Show("Username or Password does not match.", "User Login", MessageBoxButtons.OK, MessageBoxIcon.Information); txtUsername.Focus(); return; } MessageBox.Show("Successfully log-in"); newMDI.Show(); this.Hide(); }