private void button1_Click(object sender, EventArgs e) { //Validation if (textBox1.Text == "FullName" && textBox2.Text == "0333-XXXXXXX" && textBox3.Text == "" && textBox4.Text == "*****@*****.**") { // txtEmptyString_Validated("",e); textBox1.BackColor = Color.Red; textBox2.BackColor = Color.Red; textBox3.BackColor = Color.Red; textBox4.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.Focus(); textBox2.BackColor = Color.White; textBox3.Focus(); textBox3.BackColor = Color.White; textBox4.Focus(); textBox4.BackColor = Color.White; this.errorProvider1.SetError(textBox1, "This field must contain text"); this.errorProvider3.SetError(textBox2, "This field must contain text"); this.errorProvider2.SetError(textBox3, "This field must contain text"); this.errorProvider4.SetError(textBox4, "This field must contain text"); } else if (textBox1.Text != "FullName" && textBox2.Text == "0333-XXXXXXX" && textBox3.Text == "" && textBox4.Text == "*****@*****.**") { textBox3.BackColor = Color.Red; textBox2.BackColor = Color.Red; textBox4.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.Focus(); textBox3.BackColor = Color.White; textBox4.Focus(); textBox4.BackColor = Color.White; this.errorProvider3.SetError(textBox2, ""); } else if (textBox1.Text != "FullName" && textBox2.Text != "0333-XXXXXXX" && textBox3.Text == "" && textBox4.Text == "*****@*****.**") { if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text == "" && textBox4.Text == "") { textBox3.BackColor = Color.Red; textBox4.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.Focus(); textBox3.BackColor = Color.White; textBox4.Focus(); textBox4.BackColor = Color.White; } } else if (textBox1.Text != "FullName" && textBox2.Text != "0333-XXXXXXX" && textBox3.Text != "" && textBox4.Text == "*****@*****.**") { textBox4.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data ", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.BackColor = Color.White; textBox4.Focus(); textBox4.BackColor = Color.White; // code } else if (textBox1.Text != "FullName" && textBox2.Text != "0333-XXXXXXX" && textBox3.Text != "" && textBox4.Text != "*****@*****.**") { textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.BackColor = Color.White; textBox4.BackColor = Color.White; MessageBox.Show("OK! "); //Insert data SqlConnection sqlcon = new SqlConnection(@"Data Source=DESKTOP-4DB2DSO;Initial Catalog=Connection;Integrated Security=True"); SqlCommand cmd = new SqlCommand(@"INSERT INTO[dbo].[tbl_Login] ( [username] ,[password] ,[repassword] ,[email]) VALUES ('" + textBox1.Text + "' , ' " + textBox2.Text + "' ,'" + textBox3.Text + "' , '" + textBox4.Text + "' )", sqlcon); sqlcon.Open(); cmd.ExecuteNonQuery(); sqlcon.Close(); MessageBox.Show("Register Successfully"); DialogResult dialogResult = MessageBox.Show("Do you want to Sign up", "Some Title", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { this.Show(); } else if (dialogResult == DialogResult.No) { //do something else Form1Login obj = new Form1Login(); this.Hide(); obj.Show(); } //end insertion // code } else if (textBox1.Text != "FullName" && textBox2.Text == "0333-XXXXXXX" && textBox3.Text != "" && textBox4.Text == "*****@*****.**") { textBox2.BackColor = Color.Red; textBox4.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.Focus(); textBox3.BackColor = Color.White; textBox4.Focus(); textBox4.BackColor = Color.White; // code } else if (textBox1.Text == "FullName" && textBox2.Text != "0333-XXXXXXX" && textBox3.Text == "" && textBox4.Text != "*****@*****.**") { textBox1.BackColor = Color.Red; textBox3.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.Focus(); textBox3.BackColor = Color.White; textBox4.Focus(); textBox4.BackColor = Color.White; } else if (textBox1.Text != "FullName" && textBox2.Text == "0333-XXXXXXX" && textBox3.Text == "" && textBox4.Text != "*****@*****.**") { textBox2.BackColor = Color.Red; textBox3.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.Focus(); textBox3.BackColor = Color.White; textBox4.Focus(); textBox4.BackColor = Color.White; } else if (textBox1.Text != "FullName" && textBox2.Text != "0333-XXXXXXX" && textBox3.Text == "" && textBox4.Text != "*****@*****.**") { textBox3.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.BackColor = Color.White; textBox4.Focus(); textBox4.BackColor = Color.White; } else if (textBox1.Text != "FullName" && textBox2.Text == "0333-XXXXXXX" && textBox3.Text != "" && textBox4.Text != "*****@*****.**") { textBox2.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.BackColor = Color.White; textBox4.Focus(); textBox4.BackColor = Color.White; // code } else if (textBox1.Text == "FullName" && textBox2.Text != "0333-XXXXXXX" && textBox3.Text != "" && textBox4.Text != "*****@*****.**") { textBox1.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.Focus(); textBox3.BackColor = Color.White; textBox4.Focus(); textBox4.BackColor = Color.White; // code } else if (textBox1.Text == "FullName" && textBox2.Text == "0333-XXXXXXX" && textBox3.Text != "" && textBox4.Text != "*****@*****.**") { textBox1.BackColor = Color.Red; textBox2.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.Focus(); textBox3.BackColor = Color.White; textBox4.Focus(); textBox4.BackColor = Color.White; // code } else if (textBox1.Text == "FullName" && textBox2.Text != "" && textBox3.Text == "" && textBox4.Text == "*****@*****.**") { textBox1.BackColor = Color.Red; textBox3.BackColor = Color.Red; textBox4.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.Focus(); textBox3.BackColor = Color.White; textBox4.Focus(); textBox4.BackColor = Color.White; } else if (textBox1.Text == "FullName" && textBox2.Text == "0333-XXXXXXX" && textBox3.Text != "" && textBox4.Text == "*****@*****.**") { textBox1.BackColor = Color.Red; textBox2.BackColor = Color.Red; textBox4.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.Focus(); textBox3.BackColor = Color.White; textBox4.Focus(); textBox4.BackColor = Color.White; } else if (textBox1.Text == "FullName" && textBox2.Text == "0333-XXXXXXX" && textBox3.Text == "" && textBox4.Text != "*****@*****.**") { textBox1.BackColor = Color.Red; textBox2.BackColor = Color.Red; textBox3.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.Focus(); textBox3.BackColor = Color.White; textBox4.Focus(); textBox4.BackColor = Color.White; } //Validation End else if (textBox1.Text != "" && textBox2.Text != "") { MessageBox.Show("OK! "); SqlConnection sqlcon = new SqlConnection(@"Data Source=DESKTOP-4DB2DSO;Initial Catalog=Connection;Integrated Security=True"); SqlCommand cmd = new SqlCommand(@"INSERT INTO[dbo].[tbl_Login] ( [username] ,[password] ,[repassword] ,[email]) VALUES ('" + textBox1.Text + "' , ' " + textBox2.Text + "' ,'" + textBox3.Text + "' , '" + textBox4.Text + "' )", sqlcon); sqlcon.Open(); cmd.ExecuteNonQuery(); sqlcon.Close(); MessageBox.Show("Register Successfully"); DialogResult dialogResult = MessageBox.Show("Do you want to Sign up", "Some Title", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { this.Show(); } else if (dialogResult == DialogResult.No) { //do something else Form1Login obj = new Form1Login(); this.Hide(); obj.Show(); } } }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text == "" && textBox2.Text == "") { // txtEmptyString_Validated("",e); textBox1.BackColor = Color.Red; textBox2.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.Focus(); textBox2.BackColor = Color.White; } else if (textBox1.Text != "" && textBox2.Text == "") { // txtEmptyString_Validated("",e); textBox2.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.Focus(); textBox2.BackColor = Color.White; } else if (textBox1.Text == "" && textBox2.Text != "") { // txtEmptyString_Validated("",e); textBox1.BackColor = Color.Red; MessageBox.Show(this, "Invalid Data", "Exit", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); textBox1.BackColor = Color.White; textBox2.Focus(); textBox2.BackColor = Color.White; } else if (textBox1.Text != "" && textBox2.Text != "") { MessageBox.Show("OK! "); SqlConnection sqlcon = new SqlConnection(@"Data Source=DESKTOP-4DB2DSO;Initial Catalog=Connection;Integrated Security=True"); SqlCommand cmd = new SqlCommand(@"INSERT INTO[dbo].[tbl_Login] ( [username] ,[password]) VALUES ('" + textBox1.Text + "' , ' " + textBox2.Text + "')", sqlcon); sqlcon.Open(); cmd.ExecuteNonQuery(); sqlcon.Close(); MessageBox.Show("Register Successfully"); DialogResult dialogResult = MessageBox.Show("Do you want to Sign up", "Some Title", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { this.Show(); } else if (dialogResult == DialogResult.No) { //do something else Form1Login obj = new Form1Login(); this.Hide(); obj.Show(); } } }