Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace WindowsFormsApp5
- {
- public partial class Form9 : Form
- {
- MySqlConnection polaczenie = new MySqlConnection("server=sql.djkelvin.nazwa.pl; user=djkelvin_drukarnia; password=ZAQ!2wsx; database=djkelvin_drukarnia");
- MySqlCommand komenda;
- string zapytanieSQL = "";
- public Form9()
- {
- InitializeComponent();
- }
- void Rejestracja(string imie, string nazwisko, string pesel, string email, string login, string haslo, TextBox textbox1)
- {
- try
- {
- if (polaczenie.State == ConnectionState.Closed)
- polaczenie.Open();
- zapytanieSQL = string.Format("select count(Id) from uzytkownicy where Login = '{0}'" , login);
- komenda = new MySqlCommand(zapytanieSQL, polaczenie);
- int wartosc = Convert.ToInt32(komenda.ExecuteScalar());
- if (wartosc == 1)
- {
- MessageBox.Show(string.Format("Użytwkonik z loginem '{0}' już istnieje.", login), "Informacja", MessageBoxButtons.OK, MessageBoxIcon.Information);
- textBox1.Select();
- }
- else
- {
- zapytanieSQL = string.Format("insert into uzytkownicy(imie,nazwisko,pesel,email,login,haslo) values('{0}', '{1}','{2}','{3}','{4}','{5}')",
- imie, nazwisko, pesel, email, login, haslo);
- komenda.CommandText = zapytanieSQL;
- komenda.ExecuteNonQuery();
- MessageBox.Show("Użytkownik dodany.", "Informacja", MessageBoxButtons.OK, MessageBoxIcon.Information);
- WyczyscPola();
- }
- }
- catch (Exception ex)
- {
- string byk = string.Format("Problem podczas rejestracji:\n{0}", ex.Message);
- MessageBox.Show(byk, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- finally
- {
- polaczenie.Close();
- }
- }
- void WyczyscPola()
- {
- textBox1.Text = "";
- textBox2.Text = "";
- textBox3.Text = "";
- textBox6.Text = "";
- textBox5.Text = "";
- textBox4.Text = "";
- textBox1.Select();
- }
- private void Form9_Load(object sender, EventArgs e)
- {
- }
- private void zap_Click(object sender, EventArgs e)
- {
- new start().Show();
- this.Hide();
- }
- private void zapis_Click(object sender, EventArgs e)
- {
- if(string.IsNullOrWhiteSpace(textBox1.Text) || string.IsNullOrWhiteSpace(textBox2.Text) ||string.IsNullOrWhiteSpace(textBox3.Text) || string.IsNullOrWhiteSpace(textBox6.Text) || string.IsNullOrWhiteSpace(textBox5.Text) ||string.IsNullOrWhiteSpace(textBox4.Text))
- {
- MessageBox.Show("Wszystkie pola muszą być wypełnione", "Informacja", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- else
- Rejestracja(textBox1.Text, textBox2.Text, textBox3.Text, textBox6.Text, textBox5.Text, textBox4.Text, textBox1);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- new start().Show();
- this.Hide();
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void label4_Click(object sender, EventArgs e)
- {
- }
- private void wyczysc_Click(object sender, EventArgs e)
- {
- WyczyscPola();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement