Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.69 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.IO;
  11. using MySql.Data.MySqlClient;
  12.  
  13. namespace MaraphonSkills2
  14. {
  15.     public partial class Register : Form
  16.     {
  17.         public Register()
  18.         {
  19.             InitializeComponent();
  20.             String connectionString = "server=localhost;" +
  21.                                           "database=wstest;" +
  22.                                           "user=root;" +
  23.                                           "password=524656bnm";
  24.             String commandString = "select * from gender;";
  25.             MySqlConnection connection = new MySqlConnection(connectionString);
  26.             MySqlCommand command = new MySqlCommand(commandString, connection);
  27.             MySqlDataReader reader;
  28.             try
  29.             {
  30.                 command.Connection.Open();
  31.                 reader = command.ExecuteReader();
  32.                 while (reader.Read())
  33.                 {
  34.                     comboBox1.Items.Add(reader["Gender"]);
  35.                 }
  36.                 command.Connection.Close();
  37.             }
  38.             catch (MySqlException ex)
  39.             {
  40.                 Console.WriteLine("Error: \r\n{0}", ex.ToString());
  41.             }
  42.  
  43.             command.CommandText = "select CountryName from country";
  44.             try
  45.             {
  46.                 command.Connection.Open();
  47.                 reader = command.ExecuteReader();
  48.                 while (reader.Read())
  49.                 {
  50.                     comboBox2.Items.Add(reader["CountryName"]);
  51.                 }
  52.                 command.Connection.Close();
  53.             }
  54.             catch (MySqlException ex)
  55.             {
  56.                 Console.WriteLine("Error: \r\n{0}", ex.ToString());
  57.             }
  58.             command.Connection.Close();
  59.  
  60.         }
  61.  
  62.         private void textBox6_TextChanged(object sender, EventArgs e)
  63.         {
  64.  
  65.         }
  66.  
  67.         private void button7_Click(object sender, EventArgs e)
  68.         {
  69.             Form1 mainscreen = new Form1();
  70.             mainscreen.Show();
  71.             this.Close();
  72.         }
  73.  
  74.         private void button3_Click(object sender, EventArgs e)
  75.         {
  76.             Form1 mainscreen = new Form1();
  77.             mainscreen.Show();
  78.             this.Close();
  79.         }
  80.  
  81.         private void button1_Click(object sender, EventArgs e)
  82.         {
  83.             OpenFileDialog opf = new OpenFileDialog();
  84.             opf.Filter = "Choose image( *.jpg; *.png)| *. jpg; *.png";
  85.             if (opf.ShowDialog() == DialogResult.OK)
  86.             {
  87.                 pictureBox1.Image = Image.FromFile(opf.FileName);
  88.                 textBox6.Text = opf.FileName;
  89.             }
  90.         }
  91.  
  92.         private void Register_Load(object sender, EventArgs e)
  93.         {
  94.  
  95.         }
  96.  
  97.         private void button2_Click(object sender, EventArgs e)
  98.         {
  99.             if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || comboBox1.SelectedValue == "" || comboBox2.SelectedValue == "")
  100.             {
  101.                 label12.Text = "Все данные обязательны к заполнению!";
  102.             }
  103.             else
  104.             {
  105.                
  106.  
  107.                 if (textBox2.Text == textBox3.Text)
  108.                 {
  109.                     String connectionString = "server=localhost;" +
  110.                                               "database=wstest;" +
  111.                                               "user=root;" +
  112.                                               "password=524656bnm";
  113.                     String commandString = "select count(email) from user where email=@email";
  114.                     MySqlConnection connection = new MySqlConnection(connectionString);
  115.                     MySqlCommand command = new MySqlCommand(commandString, connection);
  116.                     DataTable dt = new DataTable();
  117.                     connection.Open();
  118.                     command.Parameters.Add("@email", MySqlDbType.VarChar, 100).Value = textBox1.Text;
  119.                     command.ExecuteNonQuery();
  120.                     MySqlDataAdapter adapter = new MySqlDataAdapter(command);
  121.                     adapter.Fill(dt);
  122.                     connection.Close();
  123.                     command.Parameters.Clear();
  124.  
  125.                     if (Convert.ToUInt32(dt.Rows[0][0]) != 0)
  126.                     {
  127.                         MessageBox.Show("Пользователь уже существует");
  128.                     }
  129.                     else
  130.                     {
  131.  
  132.                         commandString = "insert into user (Email, Password, FirstName, LastName, RoleId, image)" +
  133.                                         "value (@Email, @Password, @FirstName, @LastName, 'R', @image);";
  134.                         command.CommandText = commandString;
  135.                         connection.Open();
  136.                         //
  137.                         //
  138.                         //
  139.                         //ПЕРЕДЕЛАТЬ РЕГИСТРАЦИЮ
  140.  
  141.                         command.Parameters.Add("@Email", MySqlDbType.VarChar, 100).Value = textBox1.Text;
  142.                         command.Parameters.Add("@Password", MySqlDbType.VarChar, 100).Value = textBox2.Text;
  143.                         command.Parameters.Add("@FirstName", MySqlDbType.VarChar, 80).Value = textBox4.Text;
  144.                         command.Parameters.Add("@LastName", MySqlDbType.VarChar, 80).Value = textBox5.Text;
  145.                         command.Parameters.Add("@image", MySqlDbType.VarChar, 300).Value = textBox6.Text;
  146.                         command.ExecuteNonQuery();
  147.  
  148.                         command.Parameters.Clear();
  149.                        
  150.                         commandString = "insert into runner (Email, Gender, DateOfBirth, CountryCode) value " +
  151.                                         "(@Email, @gender, @date, (select CountryCode from country where CountryName = @Country);";
  152.  
  153.                         command.CommandText = commandString;
  154.  
  155.                         command.Parameters.Add("@Email", MySqlDbType.VarChar, 100).Value = textBox1.Text;
  156.                         command.Parameters.Add("@gender", MySqlDbType.VarChar, 7).Value = comboBox1.Text;
  157.                         command.Parameters.Add("@date", MySqlDbType.DateTime).Value = dateTimePicker1.Value;
  158.                         command.Parameters.Add("@country", MySqlDbType.VarChar, 100).Value = comboBox2.Text;
  159.                         command.ExecuteNonQuery();
  160.                         command.Parameters.Clear();
  161.                         connection.Close();
  162.  
  163.  
  164.                         //
  165.                         //
  166.                         //
  167.                         //
  168.  
  169.  
  170.                         label12.Text = "";
  171.                         RegisterComplete rc = new RegisterComplete();
  172.                         rc.Show();
  173.                         this.Close();
  174.                     }
  175.                 }
  176.                 else
  177.                 {
  178.                     label12.Text = "Введенные пароли не совпадают! Повторите ввод";
  179.                 }
  180.             }
  181.         }
  182.  
  183.      
  184.         /*
  185.  
  186. public bool valid_email(String email)
  187. {
  188.    int at_index = has_at(email);
  189.    if (at_index > 0)
  190.    {
  191.        if (!check_domain(email.Substring(at_index))) return false;
  192.  
  193.    }
  194.    else return false;
  195. }
  196.  
  197.  
  198. int has_at (String email)
  199.    {        
  200.    if (email.IndexOf('@') == -1) return 0;
  201.    if (email.IndexOf('@') != email.LastIndexOf('@')) return 0;
  202.    return email.IndexOf('@');
  203.    }
  204. bool check_domain(String domain)
  205. {
  206.  
  207. }*/
  208.  
  209.     }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement