Advertisement
dave_kamenenko

logs

Dec 10th, 2021
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.39 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using System.Windows.Forms;
  4. using System.Data.SqlClient;
  5.  
  6. namespace encrypt
  7. {
  8.     public partial class logs : Form
  9.     {
  10.         Thread th;
  11.         SqlConnection sqlConnection;
  12.         public logs()
  13.         {
  14.             InitializeComponent();
  15.         }
  16.  
  17.         private async void logs_Load(object sender, EventArgs e)
  18.         {
  19.             string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\webda\source\repos\encrypt\encrypt\EncryptDB.mdf;Integrated Security = True";
  20.             sqlConnection = new SqlConnection(connectionString);
  21.             await sqlConnection.OpenAsync();
  22.             SqlDataReader sqlReader = null;
  23.             SqlCommand command = new SqlCommand("SELECT * FROM [Encrypt_text]", sqlConnection);
  24.  
  25.             try
  26.             {
  27.                 sqlReader = await command.ExecuteReaderAsync();
  28.                 while (await sqlReader.ReadAsync())
  29.                 {
  30.                     listBox1.Items.Add(Convert.ToString(sqlReader["id"]) + "        " + Convert.ToString(sqlReader["time"]) + "     " + Convert.ToString(sqlReader["encrypt_text"]));
  31.                 }
  32.             }
  33.             catch (Exception ex)
  34.             {
  35.                 MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
  36.             }
  37.             finally
  38.             {
  39.                 if (sqlReader != null) sqlReader.Close();
  40.             }
  41.  
  42.             SqlDataReader sqlReader_2 = null;
  43.             SqlCommand command_2 = new SqlCommand("SELECT * FROM [Decrypt_text]", sqlConnection);
  44.  
  45.             try
  46.             {
  47.                 sqlReader_2 = await command_2.ExecuteReaderAsync();
  48.                 while (await sqlReader_2.ReadAsync())
  49.                 {
  50.                     listBox2.Items.Add(Convert.ToString(sqlReader_2["id"]) + "        " + Convert.ToString(sqlReader_2["time"]) + "     " + Convert.ToString(sqlReader_2["decrypt_text"]));
  51.                 }
  52.             }
  53.             catch (Exception ex)
  54.             {
  55.                 MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
  56.             }
  57.             finally
  58.             {
  59.                 if (sqlReader_2 != null) sqlReader_2.Close();
  60.             }
  61.         }
  62.  
  63.         private void button1_Click(object sender, EventArgs e)
  64.         {
  65.  
  66.             this.Close();
  67.             th = new Thread(encrypt);
  68.             th.SetApartmentState(ApartmentState.STA);
  69.             th.Start();
  70.         }
  71.  
  72.         public void encrypt()
  73.         {
  74.             encrypt encrypt = new encrypt();
  75.             encrypt.ShowDialog();
  76.         }
  77.  
  78.         private void button2_Click(object sender, EventArgs e)
  79.         {
  80.             this.Close();
  81.             th = new Thread(decrypt);
  82.             th.SetApartmentState(ApartmentState.STA);
  83.             th.Start();
  84.         }
  85.  
  86.         public void decrypt()
  87.         {
  88.             decrypt decrypt = new decrypt();
  89.             decrypt.ShowDialog();
  90.         }
  91.  
  92.         private void button3_Click(object sender, EventArgs e)
  93.         {
  94.             this.Close();
  95.             th = new Thread(home);
  96.             th.SetApartmentState(ApartmentState.STA);
  97.             th.Start();
  98.         }
  99.         public void home()
  100.         {
  101.             main home = new main();
  102.             home.ShowDialog();
  103.         }
  104.     }
  105. }
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement