Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace insert_into_db
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
- {
- }
- private void textbox_username_TextChanged(object sender, EventArgs e)
- {
- label_Account_Created.Visible = false;
- label14.Visible = false;
- SQL_textbox.Text = "DELETE FROM " + textBox_authDB.Text + ".account WHERE username='" + textbox_username.Text + "';" +
- "INSERT INTO " + textBox_authDB.Text + ".account(username, sha_pass_hash, expansion) " +
- "VALUES(UPPER('" + textbox_username.Text + "'), (SHA1(CONCAT(UPPER('" + textbox_username.Text + "'), ':', UPPER('" + textBox_password.Text + "')))), 4); " +
- "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);";
- }
- private void button_create_acc_Click(object sender, EventArgs e)
- {
- if (textbox_username.Text == "")
- {
- MessageBox.Show("Username column should not be empty", "Error");
- return;
- }
- if (textBox_password.Text == "")
- {
- MessageBox.Show("Password column should not be empty", "Error");
- return;
- }
- MySqlConnection connection = new MySqlConnection("datasource=" + textBox_hostname.Text + ";port=" + textBox_port.Text + ";username=" + textBox_mysql_username.Text + ";password=" + textBox_mysql_pass.Text);
- string insertQuery = SQL_textbox.Text;
- connection.Open();
- MySqlCommand command = new MySqlCommand(insertQuery, connection);
- // Test
- try
- {
- label_Account_Created.Visible = true;
- if (command.ExecuteNonQuery() == 1)
- {
- label_Account_Created.Visible = true;
- }
- else
- {
- //MessageBox.Show("Data Not Inserted");
- //label2.ForeColor = Color.Red;
- //label2.Text = "Eroare!";
- //MessageBox.Show("Unable to connect to any of the specified MySQL hosts.");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- connection.Close();
- }
- private void textBox_password_TextChanged(object sender, EventArgs e)
- {
- label_Account_Created.Visible = false;
- label14.Visible = false;
- SQL_textbox.Text = "DELETE FROM " + textBox_authDB.Text + ".account WHERE username='" + textbox_username.Text + "';" +
- "INSERT INTO " + textBox_authDB.Text + ".account(username, sha_pass_hash, expansion) " +
- "VALUES(UPPER('" + textbox_username.Text + "'), (SHA1(CONCAT(UPPER('" + textbox_username.Text + "'), ':', UPPER('" + textBox_password.Text + "')))), 4); " +
- "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);";
- }
- private void label7_Click(object sender, EventArgs e)
- {
- }
- private void label1_Click(object sender, EventArgs e)
- {
- }
- private void button1_Click_1(object sender, EventArgs e)
- {
- Properties.Settings.Default.Save();
- try
- {
- string myConnection = "datasource=" + textBox_hostname.Text + ";port=" + textBox_port.Text + ";username=" + textBox_mysql_username.Text + ";password=" + textBox_mysql_pass.Text;
- MySqlConnection myConn = new MySqlConnection(myConnection);
- MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
- MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter);
- myConn.Open();
- DataSet ds = new DataSet();
- label7.Visible = true;
- label1.Visible = true;
- label2.Visible = true;
- textbox_username.Visible = true;
- textBox_password.Visible = true;
- button_create_acc.Visible = true;
- tabControl1.Visible = false;
- label_MySQL_Connected.Visible = true;
- label_MySQL_NotConnected.Visible = false;
- label13.Visible = true;
- textBox_realm_Name.Visible = true;
- button_Add_realm.Visible = true;
- comboBox_account_access_level.Visible = true;
- label11.Visible = true;
- timer1.Enabled = true;
- myConn.Close();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void comboBox_account_access_level_SelectedIndexChanged(object sender, EventArgs e)
- {
- label_Account_Created.Visible = false;
- label14.Visible = false;
- SQL_textbox.Text = "DELETE FROM " + textBox_authDB.Text + ".account WHERE username='" + textbox_username.Text + "';" +
- "INSERT INTO " + textBox_authDB.Text + ".account(username, sha_pass_hash, expansion) " +
- "VALUES(UPPER('" + textbox_username.Text + "'), (SHA1(CONCAT(UPPER('" + textbox_username.Text + "'), ':', UPPER('" + textBox_password.Text + "')))), 4); " +
- "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);";
- textBox_account_access_level.Text = comboBox_account_access_level.Text;
- if (comboBox_account_access_level.Text == "0 (Player)") textBox_account_access_level.Text = "0";
- else if (comboBox_account_access_level.Text == "1 (GM)") textBox_account_access_level.Text = "1";
- else if (comboBox_account_access_level.Text == "2 (Moderator)") textBox_account_access_level.Text = "2";
- else if (comboBox_account_access_level.Text == "3 (Admin)") textBox_account_access_level.Text = "3";
- else if (comboBox_account_access_level.Text == "4 (Console)") textBox_account_access_level.Text = "4";
- }
- private void button2_Click(object sender, EventArgs e)
- {
- if (textBox_realm_Name.Text == "")
- {
- MessageBox.Show("Realm Name should not be empty", "Error");
- return;
- }
- MySqlConnection connection = new MySqlConnection("datasource=" + textBox_hostname.Text + ";port=" + textBox_port.Text + ";username=" + textBox_mysql_username.Text + ";password=" + textBox_mysql_pass.Text);
- string insertQuery = "DELETE FROM " + textBox_authDB.Text + ".realmlist WHERE id=1;" +
- "INSERT INTO " + textBox_authDB.Text + ".realmlist " +
- "Values (1, '" + textBox_realm_Name.Text + "', '127.0.0.1', 8085, 0, 0, 1, 0, 0, 18019, 1, 0, 0);";
- connection.Open();
- MySqlCommand command = new MySqlCommand(insertQuery, connection);
- try
- {
- label14.Visible = true;
- if (command.ExecuteNonQuery() == 1)
- {
- label14.Visible = true;
- }
- //else
- //{
- // //MessageBox.Show("Data Not Inserted");
- // //label2.ForeColor = Color.Red;
- // //label2.Text = "Eroare!";
- // //MessageBox.Show("Unable to connect to any of the specified MySQL hosts.");
- //}
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- connection.Close();
- }
- private void textBox_realm_Name_TextChanged(object sender, EventArgs e)
- {
- label14.Visible = false;
- label_Account_Created.Visible = false;
- }
- private void label13_Click(object sender, EventArgs e)
- {
- }
- private void textBox_account_access_level_TextChanged(object sender, EventArgs e)
- {
- SQL_textbox.Text = "DELETE FROM " + textBox_authDB.Text + ".account WHERE username='" + textbox_username.Text + "';" +
- "INSERT INTO " + textBox_authDB.Text + ".account(username, sha_pass_hash, expansion) " +
- "VALUES(UPPER('" + textbox_username.Text + "'), (SHA1(CONCAT(UPPER('" + textbox_username.Text + "'), ':', UPPER('" + textBox_password.Text + "')))), 4); " +
- "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);";
- }
- private void textBox_authDB_TextChanged(object sender, EventArgs e)
- {
- }
- private void Form1_FormClosed(object sender, FormClosedEventArgs e)
- {
- Properties.Settings.Default.textbox = textBox_mysql_pass.Text;
- Properties.Settings.Default.Save();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- textBox_mysql_pass.Text = Properties.Settings.Default.textbox;
- }
- private void textBox_mysql_pass_TextChanged(object sender, EventArgs e)
- {
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- try
- {
- string myConnection = "datasource = " + textBox_hostname.Text + "; port = " + textBox_port.Text + "; username = " + textBox_mysql_username.Text + "; password = " + textBox_mysql_pass.Text;
- MySqlConnection myConn = new MySqlConnection(myConnection);
- MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
- //myDataAdapter.SelectCommand = new MySqlCommand("select * from auth.account;");
- MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter);
- myConn.Open();
- DataSet ds = new DataSet();
- label_con_lost.Visible = false;
- label_MySQL_NotConnected.Visible = false;
- label_MySQL_Connected.Visible = true;
- myConn.Close();
- }
- catch (Exception ex)
- {
- //MessageBox.Show(ex.Message);
- label_con_lost.Visible = true;
- label_MySQL_NotConnected.Visible = false;
- label_MySQL_Connected.Visible = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement