Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.IO;
- using MySql.Data.MySqlClient;
- namespace MaraphonSkills2
- {
- public partial class Register : Form
- {
- public Register()
- {
- InitializeComponent();
- String connectionString = "server=localhost;" +
- "database=wstest;" +
- "user=root;" +
- "password=524656bnm";
- String commandString = "select * from gender;";
- MySqlConnection connection = new MySqlConnection(connectionString);
- MySqlCommand command = new MySqlCommand(commandString, connection);
- MySqlDataReader reader;
- try
- {
- command.Connection.Open();
- reader = command.ExecuteReader();
- while (reader.Read())
- {
- comboBox1.Items.Add(reader["Gender"]);
- }
- command.Connection.Close();
- }
- catch (MySqlException ex)
- {
- Console.WriteLine("Error: \r\n{0}", ex.ToString());
- }
- command.CommandText = "select CountryName from country";
- try
- {
- command.Connection.Open();
- reader = command.ExecuteReader();
- while (reader.Read())
- {
- comboBox2.Items.Add(reader["CountryName"]);
- }
- command.Connection.Close();
- }
- catch (MySqlException ex)
- {
- Console.WriteLine("Error: \r\n{0}", ex.ToString());
- }
- command.Connection.Close();
- }
- private void textBox6_TextChanged(object sender, EventArgs e)
- {
- }
- private void button7_Click(object sender, EventArgs e)
- {
- Form1 mainscreen = new Form1();
- mainscreen.Show();
- this.Close();
- }
- private void button3_Click(object sender, EventArgs e)
- {
- Form1 mainscreen = new Form1();
- mainscreen.Show();
- this.Close();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- OpenFileDialog opf = new OpenFileDialog();
- opf.Filter = "Choose image( *.jpg; *.png)| *. jpg; *.png";
- if (opf.ShowDialog() == DialogResult.OK)
- {
- pictureBox1.Image = Image.FromFile(opf.FileName);
- textBox6.Text = opf.FileName;
- }
- }
- private void Register_Load(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || comboBox1.SelectedValue == "" || comboBox2.SelectedValue == "")
- {
- label12.Text = "Все данные обязательны к заполнению!";
- }
- else
- {
- if (textBox2.Text == textBox3.Text)
- {
- String connectionString = "server=localhost;" +
- "database=wstest;" +
- "user=root;" +
- "password=524656bnm";
- String commandString = "select count(email) from user where email=@email";
- MySqlConnection connection = new MySqlConnection(connectionString);
- MySqlCommand command = new MySqlCommand(commandString, connection);
- DataTable dt = new DataTable();
- connection.Open();
- command.Parameters.Add("@email", MySqlDbType.VarChar, 100).Value = textBox1.Text;
- command.ExecuteNonQuery();
- MySqlDataAdapter adapter = new MySqlDataAdapter(command);
- adapter.Fill(dt);
- connection.Close();
- command.Parameters.Clear();
- if (Convert.ToUInt32(dt.Rows[0][0]) != 0)
- {
- MessageBox.Show("Пользователь уже существует");
- }
- else
- {
- commandString = "insert into user (Email, Password, FirstName, LastName, RoleId, image)" +
- "value (@Email, @Password, @FirstName, @LastName, 'R', @image);";
- command.CommandText = commandString;
- connection.Open();
- //
- //
- //
- //ПЕРЕДЕЛАТЬ РЕГИСТРАЦИЮ
- command.Parameters.Add("@Email", MySqlDbType.VarChar, 100).Value = textBox1.Text;
- command.Parameters.Add("@Password", MySqlDbType.VarChar, 100).Value = textBox2.Text;
- command.Parameters.Add("@FirstName", MySqlDbType.VarChar, 80).Value = textBox4.Text;
- command.Parameters.Add("@LastName", MySqlDbType.VarChar, 80).Value = textBox5.Text;
- command.Parameters.Add("@image", MySqlDbType.VarChar, 300).Value = textBox6.Text;
- command.ExecuteNonQuery();
- command.Parameters.Clear();
- commandString = "insert into runner (Email, Gender, DateOfBirth, CountryCode) value " +
- "(@Email, @gender, @date, (select CountryCode from country where CountryName = @Country);";
- command.CommandText = commandString;
- command.Parameters.Add("@Email", MySqlDbType.VarChar, 100).Value = textBox1.Text;
- command.Parameters.Add("@gender", MySqlDbType.VarChar, 7).Value = comboBox1.Text;
- command.Parameters.Add("@date", MySqlDbType.DateTime).Value = dateTimePicker1.Value;
- command.Parameters.Add("@country", MySqlDbType.VarChar, 100).Value = comboBox2.Text;
- command.ExecuteNonQuery();
- command.Parameters.Clear();
- connection.Close();
- //
- //
- //
- //
- label12.Text = "";
- RegisterComplete rc = new RegisterComplete();
- rc.Show();
- this.Close();
- }
- }
- else
- {
- label12.Text = "Введенные пароли не совпадают! Повторите ввод";
- }
- }
- }
- /*
- public bool valid_email(String email)
- {
- int at_index = has_at(email);
- if (at_index > 0)
- {
- if (!check_domain(email.Substring(at_index))) return false;
- }
- else return false;
- }
- int has_at (String email)
- {
- if (email.IndexOf('@') == -1) return 0;
- if (email.IndexOf('@') != email.LastIndexOf('@')) return 0;
- return email.IndexOf('@');
- }
- bool check_domain(String domain)
- {
- }*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement