tima18

Untitled

Jun 9th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Reflection.Emit;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using MetroFramework;
  13. using System.Data.SQLite;
  14.  
  15. namespace PyCharm
  16. {
  17.    
  18.     public partial class FormAuthorization : MetroFramework.Forms.MetroForm
  19.     {
  20.         Database Data;
  21.         public FormAuthorization()
  22.         {
  23.             InitializeComponent();
  24.             metroTabControl1.SelectedTab = Authorizationtab;
  25.  
  26.         }
  27.  
  28.         private void txtUsername_Click(object sender, EventArgs e)
  29.         {
  30.             txtUsername.Text = "";
  31.         }
  32.  
  33.         private void txtPassword_Click(object sender, EventArgs e)
  34.         {
  35.             txtPassword.Text = "";
  36.         }
  37.  
  38.        
  39.  
  40.         private void txtRegistrLogin_Click(object sender, EventArgs e)
  41.         {
  42.             RegistrLogin.Text = "";
  43.         }
  44.  
  45.         private void txtRegistrPassword_Click(object sender, EventArgs e)
  46.         {
  47.             RegistrPassword.Text = "";
  48.         }
  49.  
  50.         private void FormAuthorization_Load(object sender, EventArgs e)
  51.         {
  52.             Data = new Database();
  53.             Data.getconnection();
  54.         }
  55.         private void insert(string username,string password)
  56.         {
  57.             try
  58.             {
  59.                 using (SQLiteConnection con=new SQLiteConnection(Data.connectionString))
  60.                 {
  61.                     con.Open();
  62.                     SQLiteCommand command = new SQLiteCommand();
  63.  
  64.                     string query = @"INSERT INTO LOGIN (Username,Password)VALUES(@Username,@Password)";
  65.                     command.CommandText = query;
  66.                     command.Connection = con;
  67.                     command.Parameters.Add(new SQLiteParameter("@Username",username));
  68.                     command.Parameters.Add(new SQLiteParameter("@Password",password));
  69.                     command.ExecuteNonQuery();
  70.                     MessageBox.Show("Успешная регистрация","Уведомление",MessageBoxButtons.OK,MessageBoxIcon.Information);
  71.                     con.Close();
  72.                 }
  73.             }
  74.             catch
  75.             {
  76.                 MessageBox.Show("Ошибка при добавлении в базу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  77.  
  78.             }
  79.         }
  80.  
  81.         private void btnRegistr_Click(object sender, EventArgs e)
  82.         {
  83.             if(RegistrLogin.Text != string.Empty && RegistrPassword.Text != string.Empty)
  84.             {
  85.                 insert(RegistrLogin.Text,RegistrPassword.Text);
  86.             }
  87.             else
  88.             {
  89.                 MessageBox.Show("Заполните все поля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  90.             }
  91.         }
  92.     }
  93. }
Add Comment
Please, Sign In to add comment