private void button1_Click(object sender, EventArgs e) { if (NametextBox.Text == "") { NametextBox.Focus(); } else if (PasswordtextBox.Text == "") { PasswordtextBox.Focus(); } else { // Sign in process int usertype; if (radioButton1.Checked == true) { //User 0 usertype = 0; } else { //Admin 1 usertype = 1; } try { conn.Open(); // Insert to table SqlCommand com = new SqlCommand("INSERT INTO[user] (UserName,Password,UserType,Sign) VALUES(@UserName,@Password,@UserType,@Sign)", conn); com.Parameters.AddWithValue("@UserName", NametextBox.Text); com.Parameters.AddWithValue("@Password", PasswordtextBox.Text); com.Parameters.AddWithValue("@UserType", usertype); com.Parameters.AddWithValue("@Sign", 0); com.ExecuteNonQuery(); conn.Close(); //After Insert Job : FUser_Load(sender, e); // Load again the form to refresh NametextBox.Text = PasswordtextBox.Text = ""; NametextBox.Focus(); MessageBox.Show("User has been registered", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception) { MessageBox.Show("This Username has been already exsit!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private bool IsFormValidate() { if (UserNametextBox.Text.Trim() == "") { MessageBox.Show("User Name is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); UserNametextBox.Clear(); UserNametextBox.Focus(); return(false); } if (PasswordtextBox.Text.Trim() == "") { MessageBox.Show("Password is required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); PasswordtextBox.Clear(); PasswordtextBox.Focus(); return(false); } return(true); }
public bool ValidarCampos() { if (UsuariotextBox.Text.Trim().Length < 1) { MessageBox.Show("Favor llenar los campos vacio."); UsuariotextBox.Focus(); return(false); } if (PasswordtextBox.Text.Trim().Length < 1) { MessageBox.Show("Favor llenar los campos vacios."); PasswordtextBox.Focus(); return(false); } return(true); }