public welcome() { errorValue = createDatabasePd.EROR(); createDatabasePd cdbPd = new createDatabasePd(errorValue); InitializeComponent(); this.button3.Enabled = false; this.button3.Hide(); this.button4.Enabled = false; this.button4.Hide(); }
private void button1_Click(object sender, EventArgs e) { this.button2.Text = "SIGN UP"; this.label10.Hide(); this.label10.Enabled = false; this.textBox3.Enabled = false; this.textBox3.Hide(); this.label9.Enabled = false; this.label9.Hide(); // if either of one of three textbox is empty raise null error if (textBox1.Text.Equals("") || textBox2.Text.Equals("")) { if (textBox1.Text.Equals("")) { this.label6.ForeColor = Color.Red; label6.Text = "username field can not be empty"; } //if (textBox3.Text.Equals("") && textBox3.Enabled) { this.label10.ForeColor = Color.Red; label10.Text = "email field can not be empty"; } if (textBox2.Text.Equals("")) { this.label7.ForeColor = Color.Red; label7.Text = "password field can not be empty"; } } else { string connectionString = @"Data Source=" + PhoneDirectory.PDirectory.COMPUTER_NAME.ToUpper() + ";Initial Catalog=PhoneDirectory;Integrated Security=true"; using (SqlConnection sqlconn = new SqlConnection(connectionString)) { try { sqlconn.Open(); } catch (SqlException _) { MessageBox.Show(_.Message.ToString()); errorValue = createDatabasePd.EROR(); createDatabasePd cdbPd = new createDatabasePd(errorValue); } string sqlInput = "SELECT USERNAME, PASS FROM USERS WHERE USERNAME='******' AND PASS = '******'"; using (SqlDataAdapter sqa = new SqlDataAdapter(sqlInput, sqlconn)) { DataTable DS = new DataTable(); try { sqa.Fill(DS); }catch (SqlException _) { /*create the database and entire thing thast is neccessery for the program*/ errorValue = createDatabasePd.EROR(); createDatabasePd cdbPd = new createDatabasePd(errorValue); // MessageBox.Show("can not create the databse refere to README.txt"); } if (DS.Rows.Count == 1) { MessageBox.Show("welcome " + textBox1.Text.ToUpper()); isSuccess = true; this.label1_Click(null, null); } else { MessageBox.Show(textBox1.Text.ToUpper() + " not found "); if (count == 2) { Application.Exit(); } count += 1; } } sqlconn.Close(); } } }
private void button2_Click(object sender, EventArgs e) { if (this.button2.Text == "SIGN UP") { this.button2.Text = "SIGN ME UP"; this.textBox2.Text = ""; this.textBox1.Text = ""; this.textBox3.Enabled = true; this.textBox3.Show(); this.label9.Enabled = true; this.label9.Show(); this.counter++; } else { //this.button2.Text = "SIGN UP"; //this.textBox3.Enabled = true; //this.textBox3.Show(); //this.label9.Enabled = true; //this.label9.Show(); if (/*counter % 2 == 0 && */ (this.button2.Text == "SIGN ME UP")) { if (textBox1.Text.Equals("") || textBox2.Text.Equals("") || textBox3.Text.Equals("")) { if (textBox1.Text.Equals("")) { this.label6.ForeColor = Color.Red; label6.Text = "username field can not be empty"; } if (textBox3.Text.Equals("") && textBox3.Enabled) { this.label10.Enabled = true; this.label10.Show(); this.label10.ForeColor = Color.Red; label10.Text = "email field can not be empty"; } if (textBox2.Text.Equals("")) { this.label7.ForeColor = Color.Red; label7.Text = "password field can not be empty"; } } else { // do the registretion // FIRST CHECK WHETHER THE FIELD IS REGIDSTERED BEFORE string connectionString = @"Data Source=" + PhoneDirectory.PDirectory.COMPUTER_NAME.ToUpper() + ";Initial Catalog=PhoneDirectory;Integrated Security=true"; try { using (SqlConnection sqlconn = new SqlConnection(connectionString)) { sqlconn.Open(); string sqlInput = @"INSERT INTO USERS (USERNAME, PASS, EMAIL) VALUES ('" + textBox1.Text.ToUpper() + "', '" + textBox2.Text.ToUpper() + "', '" + textBox3.Text.ToUpper() + "')"; using (SqlCommand sqlcmd = new SqlCommand(sqlInput, sqlconn)) { try{ sqlcmd.ExecuteNonQuery(); MessageBox.Show("REGISTERED SUCCESSFULLY"); //RESETV(); }catch (SqlException _) { MessageBox.Show(_.Message.ToString()); errorValue = createDatabasePd.EROR(); createDatabasePd cdbPd = new createDatabasePd(errorValue); // MessageBox.Show("can not create the databse refere to README.txt"); } } } } catch (Exception _) { MessageBox.Show(_.Message.ToString()); } } } else { } //this.button2.Text = "SIGN UP"; } }