public static Boolean updateUser(UserLoginDTO userLoginDTO) { try { string query = "update pos.userlogin SET password=@password,position=@position,name=@name where username=@username"; MySqlCommand command = new MySqlCommand(query, conn); command.Parameters.AddWithValue("@password", userLoginDTO.getPassword()); command.Parameters.AddWithValue("@position", userLoginDTO.getPosition()); command.Parameters.AddWithValue("@username", userLoginDTO.getUsername()); command.Parameters.AddWithValue("@name", userLoginDTO.getName()); conn.Open(); if (command.ExecuteNonQuery() != 1) { return(false); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); conn.Close(); return(false); } Console.Read(); conn.Close(); return(true); }
public static Boolean createUser(UserLoginDTO userLoginDTO) { int result = 0; try { String query = "INSERT INTO pos.userlogin (username,name,password,position) VALUES (@username, @name, @password,@position)"; MySqlCommand command = new MySqlCommand(query, conn); //Console.WriteLine(custDTO.getNic()+" "+custDTO.getName()); command.Parameters.AddWithValue("username", userLoginDTO.getUsername()); command.Parameters.AddWithValue("@name", userLoginDTO.getName()); command.Parameters.AddWithValue("@password", userLoginDTO.getPassword()); command.Parameters.AddWithValue("@position", userLoginDTO.getPosition()); conn.Open(); result = command.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); conn.Close(); return(false); } Console.Read(); conn.Close(); if (result == 1) { return(true); } else { return(false); } }
private void Loginbtn_Click(object sender, EventArgs e) { try { /*LoginDTO loginDTO = LoginController.searchUser(int.Parse(txtUserName.text)); * if (loginDTO.getLoginid() == int.Parse(txtUserName.text) && loginDTO.getPassword() == txtPassword.text) * { * this.Hide(); * main m = new main(loginDTO.getUsername()); * m.ShowDialog(); * } * else * { * MessageBox.Show("Invalid Username or password "); * txtUserName.text = ""; * txtPassword.text = ""; * txtUserName.Focus(); * }*/ UserLoginDTO loginDTO = LoginController.searchUser((txtUserName.text)); if (loginDTO.getUsername() == txtUserName.text && loginDTO.getPassword() == txtPassword1.Text) { this.Hide(); main m = new main(loginDTO.getName(), loginDTO.getPosition()); m.ShowDialog(); } else { MessageBox.Show("Invalid Username or password "); txtUserName.text = ""; txtPassword1.Text = ""; txtUserName.Focus(); } } catch (Exception ex) { MessageBox.Show("Invalid Username or password "); Console.WriteLine(ex.ToString()); } }
private void BtnUserSearch_Click(object sender, EventArgs e) { string searchUser = txtUserSearch.Text; UserLoginDTO userLoginDTO = LoginController.searchUser(searchUser); if (userLoginDTO == null) { MessageBox.Show("No user found...."); } else { txtUsername.Text = userLoginDTO.getUsername(); txtName.Text = userLoginDTO.getName(); if (userLoginDTO.getPosition() == "M") { rdbManager.Checked = true; } else { rdbUser.Checked = true; } } }