public static bool isUserAdded(AddUser_Model add_user) { int count = 0; string connString = ConfigurationManager.ConnectionStrings["pos"].ConnectionString; SqlConnection conn = new SqlConnection(connString); SqlCommand cmd1 = new SqlCommand("SELECT COUNT(*) FROM admin WHERE username='******'", conn); conn.Open(); count = (int)cmd1.ExecuteScalar(); conn.Close(); if (count == 0) { SqlCommand cmd = new SqlCommand("INSERT INTO admin(name,username,password,phone,role,secure) VALUES('" + add_user.name + "','" + add_user.username + "','" + add_user.password + "','" + add_user.phone + "','" + add_user.role + "','0')", conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); return(true); } return(false); }
public static bool addUser(AddUser_Model add_user) { bool user_added = AddUser_DB.isUserAdded(add_user);; return(user_added); }
private void btn_add_user_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(txt_name.Text)) { MessageBox.Show("Name field is required"); txt_name.Focus(); } else if (String.IsNullOrEmpty(txt_username.Text)) { MessageBox.Show("Username field is required"); txt_username.Focus(); } else if (String.IsNullOrEmpty(txt_password.Text)) { MessageBox.Show("Password field is required"); txt_password.Focus(); } else if (String.IsNullOrEmpty(txt_cpassword.Text)) { MessageBox.Show("Confirm Password field is required"); txt_cpassword.Focus(); } else if (String.IsNullOrEmpty(combo_role.Text)) { MessageBox.Show("Role field is required"); combo_role.Focus(); } else if (!txt_phone.MaskCompleted) { MessageBox.Show("Phone field is required"); txt_phone.Focus(); } else { if (txt_password.Text == txt_cpassword.Text) { AddUser_Model add_user = new AddUser_Model() { name = txt_name.Text, username = txt_username.Text, password = txt_password.Text, phone = txt_phone.Text, role = combo_role.Text, }; bool user_added = AddUser_Bus.addUser(add_user); if (user_added) { ResetAllControls(this); MessageBox.Show("New User added."); this.Close(); } else { MessageBox.Show("This Username already exist."); } } else { MessageBox.Show("Your password does not match with confirm password"); } } }