Advertisement
Nithisaran

Billion2

Oct 15th, 2020 (edited)
2,097
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.70 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. using System.IO;
  13. using System.Security.Policy;
  14. using MySqlX.XDevAPI.Common;
  15.  
  16.  
  17. namespace BillionRec
  18. {
  19.     public partial class Form1 : Form
  20.     {
  21.         public Form1()
  22.         {
  23.             InitializeComponent();
  24.         }
  25.  
  26.         public static string connectorString = "server = localhost;Database=billion2;User ID=root;Password=";
  27.  
  28.         static string loremIpsum2(string url)
  29.         {
  30.             var rand = new Random();
  31.             string result = null;
  32.             string[] words = File.ReadLines(url).ToArray();
  33.             int leaght = 20;
  34. for (int j = 0; j <10; j++)
  35.             {
  36.                 for (int k = 0; k < 2; k++)
  37.                 {
  38.                     for (int i = 0; i < leaght; i++)
  39.                     {
  40.                         result = string.Concat(result, words[rand.Next(words.Length)]);
  41.                         if (i < leaght)
  42.                         {
  43.                             result = string.Concat(result, "");
  44.                         }
  45.                     }
  46.                 }
  47.  
  48.             }
  49.  
  50.             return result;
  51.  
  52.         }
  53.  
  54.         static string loremIpsum(int vlenght)
  55.         {
  56.             var rand = new Random();
  57.             string result = null;
  58.             var words = new[] { "lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", "adipiscing", "elit", "sed", "diam", "nonummy", "nibh", "euismod", "tincidunt", "ut", "laoreet", "dolore", "magna", "aliquam", "erat" };
  59.             for (int i = 0; i < vlenght; i++)
  60.             {
  61.                 result = string.Concat(result, words[rand.Next(words.Length)]);
  62.                 if (i < vlenght)
  63.                 {
  64.                     result = string.Concat(result, " ");
  65.                 }
  66.             }
  67.             return result;
  68.            
  69.         }
  70.  
  71.         private void button1_Click(object sender, EventArgs e)
  72.         {
  73.             textBox1.Text = loremIpsum(Convert.ToInt32(maskedTextBox1.Text));
  74.         }
  75.  
  76.         private void maskedTextBox1_TextChanged(object sender, EventArgs e)
  77.         {
  78.             if (System.Text.RegularExpressions.Regex.IsMatch(maskedTextBox1.Text, "[^0-9]"))
  79.             {
  80.                 MessageBox.Show("Please enter only numbers.");
  81.                 maskedTextBox1.Text = maskedTextBox1.Text.Remove(maskedTextBox1.Text.Length - 1);
  82.             }
  83.         }
  84.  
  85.         private void button2_Click(object sender, EventArgs e)
  86.         {
  87.             MySqlConnection myConn = new MySqlConnection(connectorString);
  88.             myConn.Open();
  89.             for (int i = 0; i<1000000; i++)
  90.             {
  91.                 textBox1.Text = loremIpsum(Convert.ToInt32(maskedTextBox1.Text));
  92.                 string query = $"INSERT INTO rec(rec_Name) VALUES('{textBox1.Text}')";
  93.                 MySqlCommand myCommand = new MySqlCommand(query, myConn);
  94.                 myCommand.ExecuteNonQuery();
  95.             }
  96.             MessageBox.Show("Finish");
  97.             myConn.Close();
  98.         }
  99.  
  100.         private void button4_Click(object sender, EventArgs e)
  101.         {
  102.             MySqlConnection myConn = new MySqlConnection(connectorString);
  103.             myConn.Open();
  104.             string query = "truncate rec;";
  105.             MySqlCommand myCommand = new MySqlCommand(query, myConn);
  106.             myCommand.ExecuteNonQuery();
  107.             myConn.Close();
  108.             MessageBox.Show("Finish");
  109.             string query2 = "SELECT * FROM rec";
  110.             MySqlConnection MyConn = new MySqlConnection(connectorString);
  111.             MySqlCommand MyComm = new MySqlCommand(query2, MyConn);
  112.             MySqlDataAdapter MyAdap = new MySqlDataAdapter();
  113.             MyAdap.SelectCommand = MyComm;
  114.             DataTable dTable = new DataTable();
  115.             MyAdap.Fill(dTable);
  116.             dataGridView1.DataSource = dTable;
  117.         }
  118.  
  119.         private void button3_Click(object sender, EventArgs e)
  120.         {
  121.             string query = "SELECT * FROM rec";
  122.             MySqlConnection MyConn = new MySqlConnection(connectorString);
  123.             MySqlCommand MyComm = new MySqlCommand(query, MyConn);
  124.             MySqlDataAdapter MyAdap = new MySqlDataAdapter();
  125.             MyAdap.SelectCommand = MyComm;
  126.             DataTable dTable = new DataTable();
  127.             MyAdap.Fill(dTable);
  128.             dataGridView1.DataSource = dTable;
  129.             MessageBox.Show("Finish");
  130.         }
  131.  
  132.         private void button5_Click(object sender, EventArgs e)
  133.         {
  134.             OpenFileDialog openFileDialog1 = new OpenFileDialog();
  135.             openFileDialog1.ShowDialog();
  136.             string url = openFileDialog1.FileName;
  137.             textBox2.Text = url;
  138.         }
  139.  
  140.         private void button6_Click(object sender, EventArgs e)
  141.         {
  142.             string url = textBox2.Text;
  143.             MySqlConnection myConn = new MySqlConnection(connectorString);
  144.             myConn.Open();
  145.            for (int i = 0; i < 1000000; i++)
  146.             {
  147.                 textBox1.Text = loremIpsum(Convert.ToInt32(maskedTextBox1.Text));
  148.  
  149.                 string Des = loremIpsum2(url);
  150.  
  151.                 Des = MySqlHelper.EscapeString(Des);
  152.                 richTextBox1.Text = Des;
  153.                 string query = $"INSERT INTO rec(rec_Name,rec_Descript) VALUES ('{textBox1.Text}','{richTextBox1.Text}')";
  154.               MySqlCommand myCommand = new MySqlCommand(query, myConn);
  155.                myCommand.ExecuteNonQuery();
  156.             }
  157.             MessageBox.Show("Finish");
  158.             myConn.Close();
  159.         }
  160.     }
  161. }
  162.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement