Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.87 KB | None | 0 0
  1. using System;
  2.  
  3. using System.Data;
  4.  
  5. using System.Windows.Forms;
  6.  
  7. using MySql.Data.MySqlClient;
  8.  
  9. namespace WindowsFormsApp5
  10. {
  11.     public partial class Form9 : Form
  12.     {
  13.        
  14.         MySqlConnection polaczenie = new MySqlConnection("server=sql.djkelvin.nazwa.pl; user=djkelvin_drukarnia; password=ZAQ!2wsx; database=djkelvin_drukarnia");
  15.         MySqlCommand komenda;
  16.         string zapytanieSQL = "";
  17.  
  18.         public Form9()
  19.         {
  20.             InitializeComponent();
  21.            
  22.         }
  23.  
  24.         void Rejestracja(string imie, string nazwisko, string pesel, string email, string login, string haslo, TextBox textbox1)
  25.         {
  26.             try
  27.             {
  28.                 if (polaczenie.State == ConnectionState.Closed)
  29.                     polaczenie.Open();
  30.  
  31.                 zapytanieSQL = string.Format("select count(Id) from uzytkownicy where Login = '{0}'" , login);
  32.                 komenda = new MySqlCommand(zapytanieSQL, polaczenie);
  33.                 int wartosc = Convert.ToInt32(komenda.ExecuteScalar());
  34.  
  35.                 if (wartosc == 1)
  36.                 {
  37.                     MessageBox.Show(string.Format("Użytwkonik z loginem '{0}' już istnieje.", login), "Informacja", MessageBoxButtons.OK, MessageBoxIcon.Information);
  38.                     textBox1.Select();
  39.                 }
  40.                 else
  41.                 {
  42.                     zapytanieSQL = string.Format("insert into uzytkownicy(imie,nazwisko,pesel,email,login,haslo) values('{0}', '{1}','{2}','{3}','{4}','{5}')",
  43.                         imie, nazwisko, pesel, email, login, haslo);
  44.                     komenda.CommandText = zapytanieSQL;
  45.                     komenda.ExecuteNonQuery();
  46.  
  47.                     MessageBox.Show("Użytkownik dodany.", "Informacja",  MessageBoxButtons.OK, MessageBoxIcon.Information);
  48.                     WyczyscPola();
  49.  
  50.                 }
  51.             }
  52.             catch (Exception ex)
  53.             {
  54.                 string byk = string.Format("Problem podczas rejestracji:\n{0}", ex.Message);
  55.                 MessageBox.Show(byk, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
  56.             }
  57.             finally
  58.             {
  59.                 polaczenie.Close();
  60.  
  61.             }
  62.  
  63.  
  64.         }
  65.  
  66.         void WyczyscPola()
  67.         {
  68.  
  69.             textBox1.Text = "";
  70.             textBox2.Text = "";
  71.             textBox3.Text = "";
  72.             textBox6.Text = "";
  73.             textBox5.Text = "";
  74.             textBox4.Text = "";
  75.             textBox1.Select();
  76.         }
  77.  
  78.         private void Form9_Load(object sender, EventArgs e)
  79.         {
  80.  
  81.         }
  82.  
  83.         private void zap_Click(object sender, EventArgs e)
  84.         {
  85.             new start().Show();
  86.             this.Hide();
  87.         }
  88.  
  89.         private void zapis_Click(object sender, EventArgs e)
  90.         {
  91.             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))
  92.             {
  93.  
  94.             MessageBox.Show("Wszystkie pola muszą być wypełnione", "Informacja", MessageBoxButtons.OK, MessageBoxIcon.Information);
  95.             return;
  96.  
  97.             }
  98.             else
  99.             Rejestracja(textBox1.Text, textBox2.Text, textBox3.Text, textBox6.Text, textBox5.Text, textBox4.Text, textBox1);
  100.         }
  101.        
  102.  
  103.         private void button1_Click(object sender, EventArgs e)
  104.         {
  105.             new start().Show();
  106.             this.Hide();
  107.         }
  108.  
  109.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  110.         {
  111.  
  112.         }
  113.  
  114.         private void label4_Click(object sender, EventArgs e)
  115.         {
  116.  
  117.         }
  118.  
  119.         private void wyczysc_Click(object sender, EventArgs e)
  120.         {
  121.             WyczyscPola();
  122.         }
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement