using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Media; using System.Data.SqlClient; namespace AlexandriasBibliothek { public partial class Form1 : Form { private bool check_name = false; private bool check_nachname = false; private bool check_user_id = false; private bool check_password = false; private bool check_birthday = false; public Form1() { InitializeComponent(); SoundPlayer StartUp = new SoundPlayer(@"C:\Alexandria\Sound\320664_pizzaiolo_lovelyboot1.wav"); StartUp.Play(); textBox2.Enabled = false; textBox3.ForeColor = System.Drawing.Color.Gray; textBox4.ForeColor = System.Drawing.Color.Gray; textBox5.ForeColor = System.Drawing.Color.Gray; textBox6.ForeColor = System.Drawing.Color.Gray; textBox7.ForeColor = System.Drawing.Color.Gray; textBox8.ForeColor = System.Drawing.Color.Gray; textBox9.ForeColor = System.Drawing.Color.Gray; textBox10.ForeColor = System.Drawing.Color.Gray; dateTimePicker1.CalendarForeColor = System.Drawing.Color.Gray; textBox2.UseSystemPasswordChar = true; checkBox1.Enabled = false; checkBox2.Enabled = false; checkBox3.Enabled = false; checkBox4.Enabled = false; checkBox5.Enabled = false; checkBox6.Enabled = false; checkBox7.Enabled = false; checkBox8.Enabled = false; checkBox9.Enabled = false; } private void Form1_Load(object sender, EventArgs e) { } private void textBox1_TextChanged(object sender, EventArgs e) { if (textBox1.Text != "") { textBox2.Enabled = true; checkBox5.Enabled = true; } else { textBox2.Enabled = false; checkBox5.Enabled = false; } } private void button1_Click(object sender, EventArgs e) { try { if (textBox1.Text != "" && textBox2.Text != "") { try { using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Alexandria\Database\Database1.mdf;Integrated Security=True;"; conn.Open(); //Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Alexandria\Database\Database1.mdf;Integrated Security=True SqlCommand SelectCommand = new SqlCommand("SELECT * FROM USERS WHERE @0 = user_id and @1 = user_password;", conn); SelectCommand.Parameters.Add(new SqlParameter("@0", textBox1.Text)); SelectCommand.Parameters.Add(new SqlParameter("@1", textBox2.Text)); if (SelectCommand.ExecuteNonQuery() > 0) { MessageBox.Show("Welcome, " + textBox1.Text); /*Form2 scd_screen = new Form2(); scd_screen.Location = this.Location; scd_screen.Size = this.Size; scd_screen.Show(); this.Hide();*/ } else { MessageBox.Show("Wrong UserID or password!"); } } } catch { MessageBox.Show("Wrong UserID or password!"); } } else { MessageBox.Show("Wrong UserID or password!"); } } catch { MessageBox.Show("Wrong UserID or password!"); } } private void button2_Click(object sender, EventArgs e) { if (check_name == true && check_nachname == true && check_user_id == true && check_password == true && check_birthday) { int plz = 0; int.TryParse(textBox6.Text, out plz); using (SqlConnection conn = new SqlConnection()) { try { conn.ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Alexandria\Database\Database1.mdf;Integrated Security=True;"; conn.Open(); //Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Alexandria\Database\Database1.mdf;Integrated Security=True SqlCommand insertCommand = new SqlCommand("Insert into USERS values(@a,@b,@c,@d,@e,@f,@g,@h,@i);", conn); insertCommand.Parameters.Add(new SqlParameter("@a", textBox5.Text)); insertCommand.Parameters.Add(new SqlParameter("@b", textBox4.Text)); insertCommand.Parameters.Add(new SqlParameter("@c", textBox3.Text)); insertCommand.Parameters.Add(new SqlParameter("@d", dateTimePicker1.Text)); insertCommand.Parameters.Add(new SqlParameter("@e", textBox10.Text)); insertCommand.Parameters.Add(new SqlParameter("@f", textBox7.Text)); insertCommand.Parameters.Add(new SqlParameter("@g", plz)); insertCommand.Parameters.Add(new SqlParameter("@h", textBox9.Text)); insertCommand.Parameters.Add(new SqlParameter("@i", textBox8.Text)); if (insertCommand.ExecuteNonQuery() == 1) { MessageBox.Show("Welcome, " + textBox3.Text + " " + textBox4.Text); /*Form2 scd_screen = new Form2(); scd_screen.Location = this.Location; scd_screen.Size = this.Size; scd_screen.Show(); this.Hide();*/ } } catch { MessageBox.Show(textBox5.Text + " has alredy been taken. Sorry"); textBox5.ForeColor = System.Drawing.Color.Gray; textBox5.Text = "UserID"; } } } else { if (check_name != true) MessageBox.Show("Please enter a valid name"); if (check_nachname != true) MessageBox.Show("Please enter a valid surname"); if (check_user_id != true) MessageBox.Show("Please enter a valid UserID"); if (check_password != true) MessageBox.Show("Please enter a valid password"); if (check_birthday != true) MessageBox.Show("Please enter a valid birthday"); } } private void checkBox5_CheckedChanged(object sender, EventArgs e) { if (checkBox5.Checked == true) { textBox2.UseSystemPasswordChar = false; } else textBox2.UseSystemPasswordChar = true; } private void checkBox6_CheckedChanged(object sender, EventArgs e) { if (textBox10.ForeColor == System.Drawing.Color.Black && checkBox6.Checked == false) { textBox10.UseSystemPasswordChar = true; } else if (textBox10.ForeColor == System.Drawing.Color.Gray || checkBox6.Checked == true) { textBox10.UseSystemPasswordChar = false; } } private void textBox3_Enter(object sender, EventArgs e) { if(textBox3.ForeColor == System.Drawing.Color.Gray) { textBox3.ForeColor = System.Drawing.Color.Black; textBox3.Text = ""; } } private void textBox3_Leave(object sender, EventArgs e) { if (textBox3.Text == "") { textBox3.ForeColor = System.Drawing.Color.Gray; textBox3.Text = "Name"; } else check_name = true; } private void textBox4_Enter(object sender, EventArgs e) { if (textBox4.ForeColor == System.Drawing.Color.Gray) { textBox4.ForeColor = System.Drawing.Color.Black; textBox4.Text = ""; } } private void textBox4_Leave(object sender, EventArgs e) { if (textBox4.Text == "") { textBox4.ForeColor = System.Drawing.Color.Gray; textBox4.Text = "Surname"; } else check_nachname = true; } private void textBox5_Enter(object sender, EventArgs e) { if (textBox5.ForeColor == System.Drawing.Color.Gray) { textBox5.ForeColor = System.Drawing.Color.Black; textBox5.Text = ""; } } private void textBox5_Leave(object sender, EventArgs e) { if (textBox5.Text == "") { textBox5.ForeColor = System.Drawing.Color.Gray; textBox5.Text = "UserID"; } } private void textBox6_Enter(object sender, EventArgs e) { if (textBox6.ForeColor == System.Drawing.Color.Gray) { textBox6.ForeColor = System.Drawing.Color.Black; textBox6.Text = ""; } } private void textBox6_Leave(object sender, EventArgs e) { if (textBox6.Text == "") { textBox6.ForeColor = System.Drawing.Color.Gray; textBox6.Text = "ZIP"; } } private void textBox7_Enter(object sender, EventArgs e) { if (textBox7.ForeColor == System.Drawing.Color.Gray) { textBox7.ForeColor = System.Drawing.Color.Black; textBox7.Text = ""; } } private void textBox7_Leave(object sender, EventArgs e) { if (textBox7.Text == "") { textBox7.ForeColor = System.Drawing.Color.Gray; textBox7.Text = "Town"; } } private void textBox8_Enter(object sender, EventArgs e) { if (textBox8.ForeColor == System.Drawing.Color.Gray) { textBox8.ForeColor = System.Drawing.Color.Black; textBox8.Text = ""; } } private void textBox8_Leave(object sender, EventArgs e) { if (textBox8.Text == "") { textBox8.ForeColor = System.Drawing.Color.Gray; textBox8.Text = "Street"; } } private void textBox9_Enter(object sender, EventArgs e) { if (textBox9.ForeColor == System.Drawing.Color.Gray) { textBox9.ForeColor = System.Drawing.Color.Black; textBox9.Text = ""; } } private void textBox9_Leave(object sender, EventArgs e) { if (textBox9.Text == "") { textBox9.ForeColor = System.Drawing.Color.Gray; textBox9.Text = "Housenumber"; } } private void textBox10_Enter(object sender, EventArgs e) { if (textBox10.ForeColor == System.Drawing.Color.Gray) { textBox10.ForeColor = System.Drawing.Color.Black; textBox10.Text = ""; } } private void textBox10_Leave(object sender, EventArgs e) { if (textBox10.Text == "") { textBox10.ForeColor = System.Drawing.Color.Gray; textBox10.Text = "Password"; } } private void dateTimePicker1_Enter(object sender, EventArgs e) { } private void dateTimePicker1_Leave(object sender, EventArgs e) { } private void textBox10_TextChanged(object sender, EventArgs e) { if (textBox10.Text == "") { checkBox1.Checked = false; checkBox2.Checked = false; checkBox3.Checked = false; checkBox4.Checked = false; checkBox7.Checked = false; } if (textBox10.ForeColor == System.Drawing.Color.Black && checkBox6.Checked == false) { textBox10.UseSystemPasswordChar = true; } else if (textBox10.ForeColor == System.Drawing.Color.Gray || checkBox6.Checked == true) { textBox10.UseSystemPasswordChar = false; } if (textBox10.Text != "" && textBox10.Text != "Password") { checkBox6.Enabled = true; int pass_length = textBox10.Text.Length; int a = 0, b = 0, c = 0, d = 0, f = 0; for (int i = 0; i < pass_length; i++) { if (pass_length >= 8) { checkBox7.Checked = true; } else if (pass_length < 8) checkBox7.Checked = false; if (Char.IsUpper(textBox10.Text[i])) { checkBox1.Checked = true; b = i; } else if(Char.IsUpper(textBox10.Text[b]) != true) checkBox1.Checked = false; if (Char.IsLower(textBox10.Text[i])) { checkBox2.Checked = true; c = i; } else if (Char.IsLower(textBox10.Text[c]) != true) checkBox2.Checked = false; if (int.TryParse(Convert.ToString(textBox10.Text[i]), out a)) { checkBox3.Checked = true; d = i; } else if (int.TryParse(Convert.ToString(textBox10.Text[d]), out a) != true) checkBox3.Checked = false; if ((textBox10.Text[i]>32) && (textBox10.Text[i]<48)) { checkBox4.Checked = true; f = i; } else if ((textBox10.Text[f] > 32) && (textBox10.Text[f] < 48) != true) checkBox4.Checked = false; if (checkBox1.Checked == true && checkBox2.Checked == true && checkBox3.Checked == true && checkBox4.Checked == true && checkBox7.Checked == true) { check_password = true; } else { check_password = false; } } } else { checkBox6.Enabled = false; } } private void textBox5_TextChanged(object sender, EventArgs e) { int check_length = textBox5.Text.Length; if (check_length >= 6 && check_length <= 20) { checkBox8.Checked = true; check_user_id = true; } else { checkBox8.Checked = false; check_user_id = false; } } private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { DateTime current_time = DateTime.Now; DateTime picked_time = Convert.ToDateTime(dateTimePicker1.Text); int value = DateTime.Compare(current_time, picked_time); if (value > 0) { checkBox9.Checked = true; check_birthday = true; } else { checkBox9.Checked = false; check_birthday = false; } } private void groupBox2_Enter(object sender, EventArgs e) { } } }