Kyaria

Login/Registration Page

Mar 26th, 2017
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 16.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Media;
  11. using System.Data.SqlClient;
  12.  
  13. namespace AlexandriasBibliothek
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         private bool check_name = false;
  18.         private bool check_nachname = false;
  19.         private bool check_user_id = false;
  20.         private bool check_password = false;
  21.         private bool check_birthday = false;
  22.  
  23.         public Form1()
  24.         {
  25.             InitializeComponent();
  26.  
  27.             SoundPlayer StartUp = new SoundPlayer(@"C:\Alexandria\Sound\320664_pizzaiolo_lovelyboot1.wav");
  28.             StartUp.Play();
  29.  
  30.             textBox2.Enabled = false;
  31.  
  32.             textBox3.ForeColor = System.Drawing.Color.Gray;
  33.             textBox4.ForeColor = System.Drawing.Color.Gray;
  34.             textBox5.ForeColor = System.Drawing.Color.Gray;
  35.             textBox6.ForeColor = System.Drawing.Color.Gray;
  36.             textBox7.ForeColor = System.Drawing.Color.Gray;
  37.             textBox8.ForeColor = System.Drawing.Color.Gray;
  38.             textBox9.ForeColor = System.Drawing.Color.Gray;
  39.             textBox10.ForeColor = System.Drawing.Color.Gray;
  40.  
  41.             dateTimePicker1.CalendarForeColor = System.Drawing.Color.Gray;
  42.  
  43.             textBox2.UseSystemPasswordChar = true;
  44.  
  45.             checkBox1.Enabled = false;
  46.             checkBox2.Enabled = false;
  47.             checkBox3.Enabled = false;
  48.             checkBox4.Enabled = false;
  49.             checkBox5.Enabled = false;
  50.             checkBox6.Enabled = false;
  51.             checkBox7.Enabled = false;
  52.             checkBox8.Enabled = false;
  53.             checkBox9.Enabled = false;
  54.         }
  55.  
  56.         private void Form1_Load(object sender, EventArgs e)
  57.         {
  58.  
  59.         }
  60.  
  61.         private void textBox1_TextChanged(object sender, EventArgs e)
  62.         {
  63.             if (textBox1.Text != "") { textBox2.Enabled = true; checkBox5.Enabled = true; }
  64.             else { textBox2.Enabled = false; checkBox5.Enabled = false; }
  65.         }
  66.  
  67.         private void button1_Click(object sender, EventArgs e)
  68.         {
  69.             try
  70.             {
  71.                 if (textBox1.Text != "" && textBox2.Text != "")
  72.                 {
  73.                     try
  74.                     {
  75.                         using (SqlConnection conn = new SqlConnection())
  76.                         {
  77.                             conn.ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Alexandria\Database\Database1.mdf;Integrated Security=True;";
  78.                             conn.Open();            //Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Alexandria\Database\Database1.mdf;Integrated Security=True
  79.  
  80.                             SqlCommand SelectCommand = new SqlCommand("SELECT * FROM USERS WHERE @0 = user_id and @1 = user_password;", conn);
  81.  
  82.                             SelectCommand.Parameters.Add(new SqlParameter("@0", textBox1.Text));
  83.                             SelectCommand.Parameters.Add(new SqlParameter("@1", textBox2.Text));
  84.  
  85.                             if (SelectCommand.ExecuteNonQuery() > 0)
  86.                             {
  87.                                 MessageBox.Show("Welcome, " + textBox1.Text);
  88.  
  89.                                 /*Form2 scd_screen = new Form2();
  90.                                 scd_screen.Location = this.Location;
  91.                                 scd_screen.Size = this.Size;
  92.                                 scd_screen.Show();
  93.                                 this.Hide();*/
  94.                             }
  95.                             else { MessageBox.Show("Wrong UserID or password!"); }
  96.                         }
  97.                     }
  98.                     catch { MessageBox.Show("Wrong UserID or password!"); }
  99.                 }
  100.                 else { MessageBox.Show("Wrong UserID or password!"); }
  101.             }
  102.             catch { MessageBox.Show("Wrong UserID or password!"); }
  103.         }
  104.  
  105.         private void button2_Click(object sender, EventArgs e)
  106.         {
  107.             if (check_name == true && check_nachname == true && check_user_id == true && check_password == true && check_birthday)
  108.             {
  109.                 int plz = 0;
  110.                 int.TryParse(textBox6.Text, out plz);
  111.  
  112.                 using (SqlConnection conn = new SqlConnection())
  113.                 {
  114.                     try
  115.                     {
  116.                         conn.ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Alexandria\Database\Database1.mdf;Integrated Security=True;";
  117.                         conn.Open();            //Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Alexandria\Database\Database1.mdf;Integrated Security=True
  118.  
  119.                         SqlCommand insertCommand = new SqlCommand("Insert into USERS values(@a,@b,@c,@d,@e,@f,@g,@h,@i);", conn);
  120.  
  121.                         insertCommand.Parameters.Add(new SqlParameter("@a", textBox5.Text));
  122.                         insertCommand.Parameters.Add(new SqlParameter("@b", textBox4.Text));
  123.                         insertCommand.Parameters.Add(new SqlParameter("@c", textBox3.Text));
  124.                         insertCommand.Parameters.Add(new SqlParameter("@d", dateTimePicker1.Text));
  125.                         insertCommand.Parameters.Add(new SqlParameter("@e", textBox10.Text));
  126.                         insertCommand.Parameters.Add(new SqlParameter("@f", textBox7.Text));
  127.                         insertCommand.Parameters.Add(new SqlParameter("@g", plz));
  128.                         insertCommand.Parameters.Add(new SqlParameter("@h", textBox9.Text));
  129.                         insertCommand.Parameters.Add(new SqlParameter("@i", textBox8.Text));
  130.  
  131.                         if (insertCommand.ExecuteNonQuery() == 1)
  132.                         {
  133.                             MessageBox.Show("Welcome, " + textBox3.Text + " " + textBox4.Text);
  134.  
  135.                             /*Form2 scd_screen = new Form2();
  136.                             scd_screen.Location = this.Location;
  137.                             scd_screen.Size = this.Size;
  138.                             scd_screen.Show();
  139.                             this.Hide();*/
  140.                         }
  141.                     }
  142.                     catch
  143.                     {
  144.                         MessageBox.Show(textBox5.Text + " has alredy been taken. Sorry");
  145.  
  146.                         textBox5.ForeColor = System.Drawing.Color.Gray;
  147.                         textBox5.Text = "UserID";
  148.                     }
  149.                 }
  150.             }
  151.             else
  152.             {
  153.                 if (check_name != true) MessageBox.Show("Please enter a valid name");
  154.                 if (check_nachname != true) MessageBox.Show("Please enter a valid surname");
  155.                 if (check_user_id != true) MessageBox.Show("Please enter a valid UserID");
  156.                 if (check_password != true) MessageBox.Show("Please enter a valid password");
  157.                 if (check_birthday != true) MessageBox.Show("Please enter a valid birthday");
  158.             }
  159.         }
  160.  
  161.         private void checkBox5_CheckedChanged(object sender, EventArgs e)
  162.         {
  163.             if (checkBox5.Checked == true)
  164.             {
  165.                 textBox2.UseSystemPasswordChar = false;
  166.             }
  167.             else textBox2.UseSystemPasswordChar = true;
  168.         }
  169.  
  170.         private void checkBox6_CheckedChanged(object sender, EventArgs e)
  171.         {
  172.             if (textBox10.ForeColor == System.Drawing.Color.Black && checkBox6.Checked == false)
  173.             {
  174.                 textBox10.UseSystemPasswordChar = true;
  175.             }
  176.             else if (textBox10.ForeColor == System.Drawing.Color.Gray || checkBox6.Checked == true)
  177.             {
  178.                 textBox10.UseSystemPasswordChar = false;
  179.             }
  180.         }
  181.  
  182.         private void textBox3_Enter(object sender, EventArgs e)
  183.         {
  184.             if(textBox3.ForeColor == System.Drawing.Color.Gray)
  185.             {
  186.                 textBox3.ForeColor = System.Drawing.Color.Black;
  187.                 textBox3.Text = "";
  188.             }
  189.         }
  190.  
  191.         private void textBox3_Leave(object sender, EventArgs e)
  192.         {
  193.             if (textBox3.Text == "")
  194.             {
  195.                 textBox3.ForeColor = System.Drawing.Color.Gray;
  196.                 textBox3.Text = "Name";
  197.             }
  198.             else check_name = true;
  199.         }
  200.  
  201.         private void textBox4_Enter(object sender, EventArgs e)
  202.         {
  203.             if (textBox4.ForeColor == System.Drawing.Color.Gray)
  204.             {
  205.                 textBox4.ForeColor = System.Drawing.Color.Black;
  206.                 textBox4.Text = "";
  207.             }
  208.         }
  209.  
  210.         private void textBox4_Leave(object sender, EventArgs e)
  211.         {
  212.             if (textBox4.Text == "")
  213.             {
  214.                 textBox4.ForeColor = System.Drawing.Color.Gray;
  215.                 textBox4.Text = "Surname";
  216.             }
  217.             else check_nachname = true;
  218.         }
  219.  
  220.         private void textBox5_Enter(object sender, EventArgs e)
  221.         {
  222.             if (textBox5.ForeColor == System.Drawing.Color.Gray)
  223.             {
  224.                 textBox5.ForeColor = System.Drawing.Color.Black;
  225.                 textBox5.Text = "";
  226.             }
  227.         }
  228.  
  229.         private void textBox5_Leave(object sender, EventArgs e)
  230.         {
  231.             if (textBox5.Text == "")
  232.             {
  233.                 textBox5.ForeColor = System.Drawing.Color.Gray;
  234.                 textBox5.Text = "UserID";
  235.             }
  236.         }
  237.  
  238.         private void textBox6_Enter(object sender, EventArgs e)
  239.         {
  240.             if (textBox6.ForeColor == System.Drawing.Color.Gray)
  241.             {
  242.                 textBox6.ForeColor = System.Drawing.Color.Black;
  243.                 textBox6.Text = "";
  244.             }
  245.         }
  246.  
  247.         private void textBox6_Leave(object sender, EventArgs e)
  248.         {
  249.             if (textBox6.Text == "")
  250.             {
  251.                 textBox6.ForeColor = System.Drawing.Color.Gray;
  252.                 textBox6.Text = "ZIP";
  253.             }
  254.         }
  255.  
  256.         private void textBox7_Enter(object sender, EventArgs e)
  257.         {
  258.             if (textBox7.ForeColor == System.Drawing.Color.Gray)
  259.             {
  260.                 textBox7.ForeColor = System.Drawing.Color.Black;
  261.                 textBox7.Text = "";
  262.             }
  263.         }
  264.  
  265.         private void textBox7_Leave(object sender, EventArgs e)
  266.         {
  267.             if (textBox7.Text == "")
  268.             {
  269.                 textBox7.ForeColor = System.Drawing.Color.Gray;
  270.                 textBox7.Text = "Town";
  271.             }
  272.         }
  273.  
  274.         private void textBox8_Enter(object sender, EventArgs e)
  275.         {
  276.             if (textBox8.ForeColor == System.Drawing.Color.Gray)
  277.             {
  278.                 textBox8.ForeColor = System.Drawing.Color.Black;
  279.                 textBox8.Text = "";
  280.             }
  281.         }
  282.  
  283.         private void textBox8_Leave(object sender, EventArgs e)
  284.         {
  285.             if (textBox8.Text == "")
  286.             {
  287.                 textBox8.ForeColor = System.Drawing.Color.Gray;
  288.                 textBox8.Text = "Street";
  289.             }
  290.         }
  291.  
  292.         private void textBox9_Enter(object sender, EventArgs e)
  293.         {
  294.             if (textBox9.ForeColor == System.Drawing.Color.Gray)
  295.             {
  296.                 textBox9.ForeColor = System.Drawing.Color.Black;
  297.                 textBox9.Text = "";
  298.             }
  299.         }
  300.  
  301.         private void textBox9_Leave(object sender, EventArgs e)
  302.         {
  303.             if (textBox9.Text == "")
  304.             {
  305.                 textBox9.ForeColor = System.Drawing.Color.Gray;
  306.                 textBox9.Text = "Housenumber";
  307.             }
  308.         }
  309.  
  310.         private void textBox10_Enter(object sender, EventArgs e)
  311.         {
  312.             if (textBox10.ForeColor == System.Drawing.Color.Gray)
  313.             {
  314.                 textBox10.ForeColor = System.Drawing.Color.Black;
  315.                 textBox10.Text = "";
  316.             }
  317.         }
  318.  
  319.         private void textBox10_Leave(object sender, EventArgs e)
  320.         {
  321.             if (textBox10.Text == "")
  322.             {
  323.                 textBox10.ForeColor = System.Drawing.Color.Gray;
  324.                 textBox10.Text = "Password";
  325.             }
  326.         }
  327.  
  328.         private void dateTimePicker1_Enter(object sender, EventArgs e)
  329.         {
  330.  
  331.         }
  332.  
  333.         private void dateTimePicker1_Leave(object sender, EventArgs e)
  334.         {
  335.  
  336.         }
  337.  
  338.         private void textBox10_TextChanged(object sender, EventArgs e)
  339.         {
  340.             if (textBox10.Text == "")
  341.             {
  342.                 checkBox1.Checked = false;
  343.                 checkBox2.Checked = false;
  344.                 checkBox3.Checked = false;
  345.                 checkBox4.Checked = false;
  346.                 checkBox7.Checked = false;
  347.             }
  348.  
  349.             if (textBox10.ForeColor == System.Drawing.Color.Black && checkBox6.Checked == false)
  350.             {
  351.                 textBox10.UseSystemPasswordChar = true;
  352.             }
  353.             else if (textBox10.ForeColor == System.Drawing.Color.Gray || checkBox6.Checked == true)
  354.             {
  355.                 textBox10.UseSystemPasswordChar = false;
  356.             }
  357.  
  358.             if (textBox10.Text != "" && textBox10.Text != "Password")
  359.             {
  360.                 checkBox6.Enabled = true;
  361.  
  362.                 int pass_length = textBox10.Text.Length;
  363.  
  364.                 int a = 0, b = 0, c = 0, d = 0, f = 0;
  365.  
  366.                 for (int i = 0; i < pass_length; i++)
  367.                 {
  368.                     if (pass_length >= 8)
  369.                     {
  370.                         checkBox7.Checked = true;
  371.                     }
  372.                     else if (pass_length < 8) checkBox7.Checked = false;
  373.  
  374.                     if (Char.IsUpper(textBox10.Text[i]))
  375.                     {
  376.                         checkBox1.Checked = true;
  377.                         b = i;
  378.                     }
  379.                     else if(Char.IsUpper(textBox10.Text[b]) != true) checkBox1.Checked = false;
  380.  
  381.                     if (Char.IsLower(textBox10.Text[i]))
  382.                     {
  383.                         checkBox2.Checked = true;
  384.                         c = i;
  385.                     }
  386.                     else if (Char.IsLower(textBox10.Text[c]) != true) checkBox2.Checked = false;
  387.  
  388.                     if (int.TryParse(Convert.ToString(textBox10.Text[i]), out a))
  389.                     {
  390.                         checkBox3.Checked = true;
  391.                         d = i;
  392.                     }
  393.                     else if (int.TryParse(Convert.ToString(textBox10.Text[d]), out a) != true) checkBox3.Checked = false;
  394.  
  395.                     if ((textBox10.Text[i]>32) && (textBox10.Text[i]<48))
  396.                     {
  397.                         checkBox4.Checked = true;
  398.                         f = i;
  399.                     }
  400.                     else if ((textBox10.Text[f] > 32) && (textBox10.Text[f] < 48) != true) checkBox4.Checked = false;
  401.  
  402.                     if (checkBox1.Checked == true && checkBox2.Checked == true && checkBox3.Checked == true && checkBox4.Checked == true && checkBox7.Checked == true)
  403.                     {
  404.                         check_password = true;
  405.                     }
  406.                     else { check_password = false; }
  407.                 }
  408.             }
  409.             else { checkBox6.Enabled = false; }
  410.         }
  411.  
  412.         private void textBox5_TextChanged(object sender, EventArgs e)
  413.         {
  414.             int check_length = textBox5.Text.Length;
  415.  
  416.             if (check_length >= 6 && check_length <= 20)
  417.             {
  418.                 checkBox8.Checked = true;
  419.                 check_user_id = true;
  420.             }
  421.             else { checkBox8.Checked = false; check_user_id = false; }
  422.         }
  423.  
  424.         private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
  425.         {
  426.             DateTime current_time = DateTime.Now;
  427.             DateTime picked_time = Convert.ToDateTime(dateTimePicker1.Text);
  428.  
  429.             int value = DateTime.Compare(current_time, picked_time);
  430.  
  431.             if (value > 0) { checkBox9.Checked = true; check_birthday = true; }
  432.             else { checkBox9.Checked = false; check_birthday = false; }
  433.         }
  434.  
  435.         private void groupBox2_Enter(object sender, EventArgs e)
  436.         {
  437.  
  438.         }
  439.     }
  440. }
Advertisement
Add Comment
Please, Sign In to add comment