Advertisement
Guest User

Form1

a guest
Feb 6th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 18.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using MySql.Data.MySqlClient;
  11.  
  12. namespace insert_into_db
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void button1_Click(object sender, EventArgs e)
  22.         {
  23.             //try
  24.             //{
  25.             //    string myConnection = "datasource=" + textBox_hostname.Text + ";port=" + textBox_port.Text + ";username=" + textBox_mysql_username.Text + ";password=" + textBox_mysql_pass.Text;
  26.             //    MySqlConnection myConn = new MySqlConnection(myConnection);
  27.             //    MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
  28.             //    myDataAdapter.SelectCommand = new MySqlCommand("SET" +
  29.             //        "@username = " + textbox_username.Text + "," +
  30.             //        "@password = " + textBox_password.Text + "," +
  31.             //        "@email = NULL," +
  32.             //        "@expansion = 2, /* Set this to 0 for vanilla expansion, 1 for TBC Expansion, 2 for WOTLK, 3 for Cataclysm, 4 for MoP, 5 for WoD */" +
  33.             //        "@gmlevel = 0, /* 0 = player, 1=GM, 2=Moderator, 3=Admin, 4=Console */" +
  34.             //        "@realmid = -1; /* -1 = All Realms */" +
  35.             //        "INSERT INTO account(username, sha_pass_hash, email, expansion)" +
  36.             //        "VALUES(UPPER(@username), (SHA1(CONCAT(UPPER(@username), ':', UPPER(@password)))), @email, @expansion);" +
  37.             //        "INSERT INTO account_access(id, gmlevel, RealmID)" +
  38.             //        "VALUES((SELECT id FROM account WHERE username = @username), @gmlevel, @realmid); ");
  39.             //    MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter);
  40.             //    myConn.Open();
  41.             //    DataSet ds = new DataSet();
  42.             //    //label2.Visible = false;
  43.             //    //label3.Visible = true;
  44.             //    //timer1.Enabled = true;
  45.             //    myConn.Close();
  46.             //}
  47.             //catch (Exception ex)
  48.             //{
  49.             //    MessageBox.Show(ex.Message);
  50.             //}
  51.  
  52.             MySqlConnection connection = new MySqlConnection("datasource=" + textBox_hostname.Text + ";port=" + textBox_port.Text + ";username=" + textBox_mysql_username.Text + ";password=" + textBox_mysql_pass.Text);
  53.             //string insertQuery = "SET " +
  54.             //        "@username = '" + textbox_username.Text + "', " +
  55.             //        "@password = '" + textBox_password.Text + "', " +
  56.             //        "@expansion = 4, " +
  57.             //        "@gmlevel = " + textBox_account_access_level.Text + "; " +
  58.             //        "INSERT INTO " + textBox_authDB.Text + ".account(username, sha_pass_hash, expansion) " +
  59.             //        "VALUES (UPPER(@username), (SHA1(CONCAT(UPPER(@username), ':', UPPER(@password)))), @expansion); " +
  60.             //        "INSERT INTO " + textBox_authDB.Text + ".account_access(id, gmlevel, RealmID) " +
  61.             //        "VALUES ((SELECT id FROM account WHERE username = @username), @gmlevel, -1);";
  62.  
  63.  
  64.             string insertQuery = SQL_textbox.Text;
  65.             connection.Open();
  66.             MySqlCommand command = new MySqlCommand(insertQuery, connection);
  67.  
  68.             // Test
  69.             try
  70.             {
  71.                 label_Account_Created.Visible = true;
  72.                 if (command.ExecuteNonQuery() == 1)
  73.                 {
  74.                     label_Account_Created.Visible = true;
  75.                 }
  76.                 //else
  77.                 //{
  78.                 //    //MessageBox.Show("Data Not Inserted");
  79.                 //    //label2.ForeColor = Color.Red;
  80.                 //    //label2.Text = "Eroare!";
  81.                 //    //MessageBox.Show("Unable to connect to any of the specified MySQL hosts.");
  82.                 //}
  83.             }
  84.             catch (Exception ex)
  85.             {
  86.                 MessageBox.Show(ex.Message);
  87.             }
  88.             connection.Close();
  89.         }
  90.  
  91.         private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  92.         {
  93.  
  94.         }
  95.  
  96.        
  97.  
  98.         private void textbox_username_TextChanged(object sender, EventArgs e)
  99.         {
  100.             label_Account_Created.Visible = false;
  101.             label14.Visible = false;
  102.  
  103.             SQL_textbox.Text = "DELETE FROM " + textBox_authDB.Text + ".account WHERE username='" + textbox_username.Text + "';" +
  104.                 "INSERT INTO " + textBox_authDB.Text + ".account(username, sha_pass_hash, expansion) " +
  105.                 "VALUES(UPPER('" + textbox_username.Text + "'), (SHA1(CONCAT(UPPER('" + textbox_username.Text + "'), ':', UPPER('" + textBox_password.Text + "')))), 4); " +
  106.                 "INSERT INTO " + textBox_authDB.Text + ".account_access(id, gmlevel, RealmID) VALUES((SELECT id FROM " + textBox_authDB.Text + ".account WHERE username = '" + textbox_username.Text + "'), " + textBox_account_access_level.Text + ", -1);";
  107.         }
  108.  
  109.         private void button_create_acc_Click(object sender, EventArgs e)
  110.         {
  111.  
  112.             if (textbox_username.Text == "")
  113.             {
  114.                 MessageBox.Show("Username column should not be empty", "Error");
  115.                 return;
  116.             }
  117.             if (textBox_password.Text == "")
  118.             {
  119.                 MessageBox.Show("Password column should not be empty", "Error");
  120.                 return;
  121.             }
  122.  
  123.             MySqlConnection connection = new MySqlConnection("datasource=" + textBox_hostname.Text + ";port=" + textBox_port.Text + ";username=" + textBox_mysql_username.Text + ";password=" + textBox_mysql_pass.Text);
  124.             //string insertQuery = "SET " +
  125.             //        "@username = '" + textbox_username.Text + "', " +
  126.             //        "@password = '" + textBox_password.Text + "', " +
  127.             //        "@expansion = 4, " +
  128.             //        "@gmlevel = " + textBox_account_access_level.Text + "; " +
  129.             //        "INSERT INTO " + textBox_authDB.Text + ".account(username, sha_pass_hash, expansion) " +
  130.             //        "VALUES (UPPER(@username), (SHA1(CONCAT(UPPER(@username), ':', UPPER(@password)))), @expansion); " +
  131.             //        "INSERT INTO " + textBox_authDB.Text + ".account_access(id, gmlevel, RealmID) " +
  132.             //        "VALUES ((SELECT id FROM account WHERE username = @username), @gmlevel, -1);";
  133.  
  134.  
  135.             string insertQuery = SQL_textbox.Text;
  136.             connection.Open();
  137.             MySqlCommand command = new MySqlCommand(insertQuery, connection);
  138.  
  139.             // Test
  140.             try
  141.             {
  142.                 label_Account_Created.Visible = true;
  143.                 if (command.ExecuteNonQuery() == 1)
  144.                 {
  145.                     label_Account_Created.Visible = true;
  146.                 }
  147.                 else
  148.                 {
  149.                     //MessageBox.Show("Data Not Inserted");
  150.                     //label2.ForeColor = Color.Red;
  151.                     //label2.Text = "Eroare!";
  152.                     //MessageBox.Show("Unable to connect to any of the specified MySQL hosts.");
  153.                 }
  154.             }
  155.             catch (Exception ex)
  156.             {
  157.                 MessageBox.Show(ex.Message);
  158.             }
  159.             connection.Close();
  160.  
  161.             //---------------------------
  162.             //try
  163.             //{
  164.             //    string myConnection = "datasource=" + textBox_hostname.Text + ";port=" + textBox_port.Text + ";username=" + textBox_mysql_username.Text + ";password=" + textBox_mysql_pass.Text;
  165.             //    MySqlConnection myConn = new MySqlConnection(myConnection);
  166.             //    MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
  167.             //    myDataAdapter.SelectCommand = new MySqlCommand("SET" +
  168.             //        "@username = " + textbox_username.Text + "," +
  169.             //        "@password = " + textBox_password.Text + "," +
  170.             //        "@email = NULL," +
  171.             //        "@expansion = 4, /* Set this to 0 for vanilla expansion, 1 for TBC Expansion, 2 for WOTLK, 3 for Cataclysm, 4 for MoP, 5 for WoD */" +
  172.             //        "@gmlevel = " + textBox_account_access_level.Text + ", /* 0 = player, 1=GM, 2=Moderator, 3=Admin, 4=Console */" +
  173.             //        "@realmid = -1; /* -1 = All Realms */" +
  174.             //        "INSERT INTO " + textBox_authDB.Text + ".account(username, sha_pass_hash, expansion)" +
  175.             //        "VALUES (UPPER(@username), (SHA1(CONCAT(UPPER(@username), ':', UPPER(@password)))), @expansion);" +
  176.             //        "INSERT INTO " + textBox_authDB.Text + ".account_access(id, gmlevel, RealmID)" +
  177.             //        "VALUES (SELECT id FROM account WHERE username = @username), @gmlevel, @realmid); ");
  178.             //    MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter);
  179.             //    myConn.Open();
  180.             //    DataSet ds = new DataSet();
  181.             //    label_Account_Created.Visible = true;
  182.             //    //label3.Visible = true;
  183.             //    //timer1.Enabled = true;
  184.             //    myConn.Close();
  185.             //}
  186.             //catch (Exception ex)
  187.             //{
  188.             //    MessageBox.Show(ex.Message);
  189.             //}
  190.         }
  191.  
  192.         private void textBox_password_TextChanged(object sender, EventArgs e)
  193.         {
  194.             label_Account_Created.Visible = false;
  195.             label14.Visible = false;
  196.  
  197.             SQL_textbox.Text = "DELETE FROM " + textBox_authDB.Text + ".account WHERE username='" + textbox_username.Text + "';" +
  198.                 "INSERT INTO " + textBox_authDB.Text + ".account(username, sha_pass_hash, expansion) " +
  199.                 "VALUES(UPPER('" + textbox_username.Text + "'), (SHA1(CONCAT(UPPER('" + textbox_username.Text + "'), ':', UPPER('" + textBox_password.Text + "')))), 4); " +
  200.                 "INSERT INTO " + textBox_authDB.Text + ".account_access(id, gmlevel, RealmID) VALUES((SELECT id FROM " + textBox_authDB.Text + ".account WHERE username = '" + textbox_username.Text + "'), " + textBox_account_access_level.Text + ", -1);";
  201.         }
  202.  
  203.         private void label7_Click(object sender, EventArgs e)
  204.         {
  205.  
  206.         }
  207.  
  208.         private void label1_Click(object sender, EventArgs e)
  209.         {
  210.  
  211.         }
  212.  
  213.         private void button1_Click_1(object sender, EventArgs e)
  214.         {
  215.            Properties.Settings.Default.Save();
  216.             try
  217.             {
  218.                 string myConnection = "datasource=" + textBox_hostname.Text + ";port=" + textBox_port.Text + ";username=" + textBox_mysql_username.Text + ";password=" + textBox_mysql_pass.Text;
  219.                 MySqlConnection myConn = new MySqlConnection(myConnection);
  220.                 MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
  221.                
  222.                 MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter);
  223.                 myConn.Open();
  224.                 DataSet ds = new DataSet();
  225.                 label7.Visible = true;
  226.                 label1.Visible = true;
  227.                 label2.Visible = true;
  228.                 textbox_username.Visible = true;
  229.                 textBox_password.Visible = true;
  230.                 button_create_acc.Visible = true;
  231.                 tabControl1.Visible = false;
  232.                 label_MySQL_Connected.Visible = true;
  233.                 label_MySQL_NotConnected.Visible = false;
  234.  
  235.                 label13.Visible = true;
  236.                 textBox_realm_Name.Visible = true;
  237.                 button_Add_realm.Visible = true;
  238.                 comboBox_account_access_level.Visible = true;
  239.                 label11.Visible = true;
  240.                 timer1.Enabled = true;
  241.                 myConn.Close();
  242.             }
  243.             catch (Exception ex)
  244.             {
  245.                 MessageBox.Show(ex.Message);
  246.             }
  247.         }
  248.  
  249.         private void comboBox_account_access_level_SelectedIndexChanged(object sender, EventArgs e)
  250.         {
  251.             label_Account_Created.Visible = false;
  252.             label14.Visible = false;
  253.  
  254.             SQL_textbox.Text = "DELETE FROM " + textBox_authDB.Text + ".account WHERE username='" + textbox_username.Text + "';" +
  255.                 "INSERT INTO " + textBox_authDB.Text + ".account(username, sha_pass_hash, expansion) " +
  256.                 "VALUES(UPPER('" + textbox_username.Text + "'), (SHA1(CONCAT(UPPER('" + textbox_username.Text + "'), ':', UPPER('" + textBox_password.Text + "')))), 4); " +
  257.                 "INSERT INTO " + textBox_authDB.Text + ".account_access(id, gmlevel, RealmID) VALUES((SELECT id FROM " + textBox_authDB.Text + ".account WHERE username = '" + textbox_username.Text + "'), " + textBox_account_access_level.Text + ", -1);";
  258.  
  259.             textBox_account_access_level.Text = comboBox_account_access_level.Text;
  260.  
  261.             if (comboBox_account_access_level.Text == "0 (Player)") textBox_account_access_level.Text = "0";
  262.             else if (comboBox_account_access_level.Text == "1 (GM)") textBox_account_access_level.Text = "1";
  263.             else if (comboBox_account_access_level.Text == "2 (Moderator)") textBox_account_access_level.Text = "2";
  264.             else if (comboBox_account_access_level.Text == "3 (Admin)") textBox_account_access_level.Text = "3";
  265.             else if (comboBox_account_access_level.Text == "4 (Console)") textBox_account_access_level.Text = "4";
  266.  
  267.         }
  268.  
  269.         private void button2_Click(object sender, EventArgs e)
  270.         {
  271.             if (textBox_realm_Name.Text == "")
  272.             {
  273.                 MessageBox.Show("Realm Name should not be empty", "Error");
  274.                 return;
  275.             }
  276.             MySqlConnection connection = new MySqlConnection("datasource=" + textBox_hostname.Text + ";port=" + textBox_port.Text + ";username=" + textBox_mysql_username.Text + ";password=" + textBox_mysql_pass.Text);
  277.             string insertQuery = "DELETE FROM " + textBox_authDB.Text + ".realmlist WHERE id=1;" +
  278.                 "INSERT INTO " + textBox_authDB.Text + ".realmlist " +
  279.                 "Values (1, '" + textBox_realm_Name.Text + "', '127.0.0.1', 8085, 0, 0, 1, 0, 0, 18019, 1, 0, 0);";
  280.             connection.Open();
  281.             MySqlCommand command = new MySqlCommand(insertQuery, connection);
  282.  
  283.             try
  284.             {
  285.                 label14.Visible = true;
  286.                 if (command.ExecuteNonQuery() == 1)
  287.                 {
  288.                     label14.Visible = true;
  289.                 }
  290.                 //else
  291.                 //{
  292.                 //    //MessageBox.Show("Data Not Inserted");
  293.                 //    //label2.ForeColor = Color.Red;
  294.                 //    //label2.Text = "Eroare!";
  295.                 //    //MessageBox.Show("Unable to connect to any of the specified MySQL hosts.");
  296.                 //}
  297.             }
  298.             catch (Exception ex)
  299.             {
  300.                 MessageBox.Show(ex.Message);
  301.             }
  302.             connection.Close();
  303.  
  304.             //------------------------------
  305.             //try
  306.             //{
  307.             //    string myConnection = "datasource=" + textBox_hostname.Text + ";port=" + textBox_port.Text + ";username=" + textBox_mysql_username.Text + ";password=" + textBox_mysql_pass.Text;
  308.             //    MySqlConnection myConn = new MySqlConnection(myConnection);
  309.             //    MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
  310.             //    myDataAdapter.SelectCommand = new MySqlCommand("INSERT INTO " + textBox_authDB.Text + ".realmlist (`name`, `address`, `port`, `icon`, `flag`, `timezone`, `allowedSecurityLevel`, `population`, `gamebuild`, `online`, `delay`, `queued`)" +
  311.             //        "Values ('" + textBox_realm_Name.Text + "', '127.0.0.1', 8085, 0, 0, 1, 0, 0, 18019, 1, 0, 0);"  );
  312.             //    MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter);
  313.             //    myConn.Open();
  314.             //    DataSet ds = new DataSet();
  315.             //    label14.Visible = true;
  316.             //    //timer1.Enabled = true;
  317.             //    myConn.Close();
  318.             //}
  319.             //catch (Exception ex)
  320.             //{
  321.             //    MessageBox.Show(ex.Message);
  322.             //}
  323.         }
  324.  
  325.         private void textBox_realm_Name_TextChanged(object sender, EventArgs e)
  326.         {
  327.             label14.Visible = false;
  328.             label_Account_Created.Visible = false;
  329.         }
  330.  
  331.         private void label13_Click(object sender, EventArgs e)
  332.         {
  333.  
  334.         }
  335.  
  336.         private void textBox_account_access_level_TextChanged(object sender, EventArgs e)
  337.         {
  338.             SQL_textbox.Text = "DELETE FROM " + textBox_authDB.Text + ".account WHERE username='" + textbox_username.Text + "';" +
  339.                 "INSERT INTO " + textBox_authDB.Text + ".account(username, sha_pass_hash, expansion) " +
  340.                 "VALUES(UPPER('" + textbox_username.Text + "'), (SHA1(CONCAT(UPPER('" + textbox_username.Text + "'), ':', UPPER('" + textBox_password.Text + "')))), 4); " +
  341.                 "INSERT INTO " + textBox_authDB.Text + ".account_access(id, gmlevel, RealmID) VALUES((SELECT id FROM " + textBox_authDB.Text + ".account WHERE username = '" + textbox_username.Text + "'), " + textBox_account_access_level.Text + ", -1);";
  342.         }
  343.  
  344.         private void textBox_authDB_TextChanged(object sender, EventArgs e)
  345.         {
  346.  
  347.         }
  348.  
  349.         private void Form1_FormClosed(object sender, FormClosedEventArgs e)
  350.         {
  351.             Properties.Settings.Default.textbox = textBox_mysql_pass.Text;
  352.             Properties.Settings.Default.Save();
  353.         }
  354.  
  355.         private void Form1_Load(object sender, EventArgs e)
  356.         {
  357.             textBox_mysql_pass.Text = Properties.Settings.Default.textbox;
  358.  
  359.         }
  360.  
  361.         private void textBox_mysql_pass_TextChanged(object sender, EventArgs e)
  362.         {
  363.            
  364.         }
  365.  
  366.         private void timer1_Tick(object sender, EventArgs e)
  367.         {
  368.             try
  369.             {
  370.                 string myConnection = "datasource = " + textBox_hostname.Text + "; port = " + textBox_port.Text + "; username = " + textBox_mysql_username.Text + "; password = " + textBox_mysql_pass.Text;
  371.                 MySqlConnection myConn = new MySqlConnection(myConnection);
  372.                 MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
  373.                 //myDataAdapter.SelectCommand = new MySqlCommand("select * from auth.account;");
  374.                 MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter);
  375.                 myConn.Open();
  376.                 DataSet ds = new DataSet();
  377.                 label_con_lost.Visible = false;
  378.                 label_MySQL_NotConnected.Visible = false;
  379.                 label_MySQL_Connected.Visible = true;
  380.                 myConn.Close();
  381.             }
  382.             catch (Exception ex)
  383.             {
  384.                 //MessageBox.Show(ex.Message);
  385.                 label_con_lost.Visible = true;
  386.                 label_MySQL_NotConnected.Visible = false;
  387.                 label_MySQL_Connected.Visible = false;
  388.             }
  389.         }
  390.     }
  391. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement