Advertisement
Nithisaran

Untitled

Sep 21st, 2020
1,282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.77 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.Text;
  9. using MySql.Data.MySqlClient;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12.  
  13. namespace BillionRec
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         public static string connectorString = "server = localhost;Database=billion;User ID=root;Password=";
  23.  
  24.         static string loremIpsum(int vlenght)
  25.         {
  26.             var rand = new Random();
  27.             string result = null;
  28.             var words = new[] { "lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", "adipiscing", "elit", "sed", "diam", "nonummy", "nibh", "euismod", "tincidunt", "ut", "laoreet", "dolore", "magna", "aliquam", "erat" };
  29.             for (int i = 0; i < vlenght; i++)
  30.             {
  31.                 result = string.Concat(result, words[rand.Next(words.Length)]);
  32.                 if (i < vlenght)
  33.                 {
  34.                     result = string.Concat(result, " ");
  35.                 }
  36.             }
  37.             return result;
  38.            
  39.         }
  40.  
  41.         private void button1_Click(object sender, EventArgs e)
  42.         {
  43.             textBox1.Text = loremIpsum(Convert.ToInt32(maskedTextBox1.Text));
  44.         }
  45.  
  46.         private void maskedTextBox1_TextChanged(object sender, EventArgs e)
  47.         {
  48.             if (System.Text.RegularExpressions.Regex.IsMatch(maskedTextBox1.Text, "[^0-9]"))
  49.             {
  50.                 MessageBox.Show("Please enter only numbers.");
  51.                 maskedTextBox1.Text = maskedTextBox1.Text.Remove(maskedTextBox1.Text.Length - 1);
  52.             }
  53.         }
  54.  
  55.         private void button2_Click(object sender, EventArgs e)
  56.         {
  57.             MySqlConnection myConn = new MySqlConnection(connectorString);
  58.             myConn.Open();
  59.             for (int i = 0; i<1000000; i++)
  60.             {
  61.                 textBox1.Text = loremIpsum(Convert.ToInt32(maskedTextBox1.Text));
  62.                 string query = $"INSERT INTO record(name) VALUES('{textBox1.Text}')";
  63.                 MySqlCommand myCommand = new MySqlCommand(query, myConn);
  64.                 myCommand.ExecuteNonQuery();
  65.             }
  66.             MessageBox.Show("Finish");
  67.             myConn.Close();
  68.         }
  69.  
  70.         private void button4_Click(object sender, EventArgs e)
  71.         {
  72.             MySqlConnection myConn = new MySqlConnection(connectorString);
  73.             myConn.Open();
  74.             string query = "truncate record;";
  75.             MySqlCommand myCommand = new MySqlCommand(query, myConn);
  76.             myCommand.ExecuteNonQuery();
  77.             myConn.Close();
  78.             MessageBox.Show("Finish");
  79.             string query2 = "SELECT * FROM record";
  80.             MySqlConnection MyConn = new MySqlConnection(connectorString);
  81.             MySqlCommand MyComm = new MySqlCommand(query2, MyConn);
  82.             MySqlDataAdapter MyAdap = new MySqlDataAdapter();
  83.             MyAdap.SelectCommand = MyComm;
  84.             DataTable dTable = new DataTable();
  85.             MyAdap.Fill(dTable);
  86.             dataGridView1.DataSource = dTable;
  87.         }
  88.  
  89.         private void button3_Click(object sender, EventArgs e)
  90.         {
  91.             string query = "SELECT * FROM record";
  92.             MySqlConnection MyConn = new MySqlConnection(connectorString);
  93.             MySqlCommand MyComm = new MySqlCommand(query, MyConn);
  94.             MySqlDataAdapter MyAdap = new MySqlDataAdapter();
  95.             MyAdap.SelectCommand = MyComm;
  96.             DataTable dTable = new DataTable();
  97.             MyAdap.Fill(dTable);
  98.             dataGridView1.DataSource = dTable;
  99.             MessageBox.Show("Finish");
  100.         }
  101.     }
  102. }
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement