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.Text;
- using System.Windows.Forms;
- using ANHDBI;
- using ANHDBI.MySQL;
- using Utilities;
- using MySql.Data.MySqlClient;
- namespace ANHAcctMgr
- {
- public partial class frmAcctMgr : Form
- {
- public frmAcctMgr()
- {
- InitializeComponent();
- }
- private void frmAccounts_Load(object sender, EventArgs e)
- {
- MySQLRunner.ConnectionString = clsDBStrings.maindbcon;
- listaccts();
- }
- public void listaccts()
- {
- MySqlConnection conGet = new MySqlConnection(MySQLRunner.ConnectionString);
- MySqlDataReader drGet = null;
- string sSQL = "";
- sSQL = "SELECT * FROM account";
- if (MySQLRunner.ExecuteQuery(sSQL, conGet, ref drGet) == true)
- {
- ListViewItem lsvItem;
- while (drGet.Read())
- {
- lsvItem = new ListViewItem(drGet.GetString(drGet.GetOrdinal("account_username")));
- lsvItem.Tag = drGet.GetString(drGet.GetOrdinal("account_id"));
- lsvAccounts.Items.Add(lsvItem);
- }
- }
- else
- {
- MessageBox.Show("Error connecting to the database.");
- }
- if (conGet.State == ConnectionState.Open)
- {
- if (drGet != null)
- drGet.Close();
- conGet.Close();
- }
- }
- private void lsvAccounts_DoubleClick(object sender, EventArgs e)
- {
- if (lsvAccounts.SelectedItems.Count <= 0)
- {
- return;
- }
- string ID = lsvAccounts.SelectedItems[0].Tag.ToString();
- MySqlConnection conGet = new MySqlConnection(MySQLRunner.ConnectionString);
- MySqlDataReader drGet = null;
- string sSQL = "";
- sSQL = "SELECT * FROM account where account_id = '" + ID.ToString() + "'";
- if (MySQLRunner.ExecuteQuery(sSQL, conGet, ref drGet) == true)
- {
- drGet.Read();
- if (drGet.HasRows == false)
- {
- txtUserName.Text = "";
- txtEmail.Text = "";
- //txtCSR.Text = "";
- txtBanned.Text = "";
- txtChars.Text = "";
- }
- else
- {
- txtUserName.Text = drGet.GetString(drGet.GetOrdinal("account_username"));
- txtEmail.Text = drGet.GetString(drGet.GetOrdinal("account_email"));
- int csrflag = drGet.GetInt32(drGet.GetOrdinal("account_csr"));
- if (csrflag == 0)
- {
- cmbCSR.SelectedIndex = 1;
- }
- if (csrflag == 1)
- {
- cmbCSR.SelectedIndex = 2;
- }
- if (csrflag == 2)
- {
- cmbCSR.SelectedIndex = 3;
- }
- //txtCSR.Text = drGet.GetString(drGet.GetOrdinal("account_csr"));
- txtBanned.Text = drGet.GetString(drGet.GetOrdinal("account_banned"));
- txtChars.Text = drGet.GetString(drGet.GetOrdinal("account_characters_allowed"));
- }
- }
- if (conGet.State == ConnectionState.Open)
- {
- if (drGet != null)
- drGet.Close();
- conGet.Close();
- }
- }
- private void btnCreate_Click(object sender, EventArgs e)
- {
- MySQLRunner.ConnectionString = clsDBStrings.configdbcon;
- MySqlConnection conAdd = new MySqlConnection(MySQLRunner.ConnectionString);
- string sSQL = "";
- bool flgReturn = false;
- sSQL = "CALL sp_AdminAddAccount('" + txtCreateUser.Text + "','" + txtCreatePass.Text + "','" + txtCreateEmail.Text + "');";
- if (MySQLRunner.ExecuteNonQuery(sSQL, conAdd) == false)
- {
- MessageBox.Show("Error creating Account.");
- }
- else
- {
- MessageBox.Show("Account Creation Successful.");
- }
- if (conAdd.State == ConnectionState.Open)
- {
- conAdd.Close();
- }
- //return flgReturn;
- listaccts();
- }
- private void btnSave_Click(object sender, EventArgs e)
- {
- MySQLRunner.ConnectionString = clsDBStrings.maindbcon;
- MySqlConnection conAdd = new MySqlConnection(MySQLRunner.ConnectionString);
- string sSQL = "";
- bool flgReturn = false;
- string banned = "";
- string csr = "";
- string ID = lsvAccounts.SelectedItems[0].Tag.ToString();
- if (txtBanned.Text == "True")
- {
- banned = "1";
- }
- else
- {
- banned = "0";
- }
- if (cmbCSR.SelectedItem == "Normal")
- {
- csr = "0";
- }
- if (cmbCSR.SelectedItem == "CSR")
- {
- csr = "1";
- }
- if (cmbCSR.SelectedItem == "Developer")
- {
- csr = "2";
- }
- sSQL = "UPDATE account SET " +
- "account_username='" + txtUserName.Text + "', " +
- "account_email='" + txtEmail.Text + "', " +
- "account_banned='" + banned + "', " +
- "account_csr='" + csr + "', " +
- "account_characters_allowed='" + txtChars.Text + "' " +
- "WHERE account_id=" + ID.ToString();
- if (MySQLRunner.ExecuteNonQuery(sSQL, conAdd) == false)
- MessageBox.Show("Error creating Account.");
- else
- MessageBox.Show("Account Creation Successful.");
- if (conAdd.State == ConnectionState.Open)
- {
- conAdd.Close();
- }
- listaccts();
- }
- private void btnPassUpdate_Click(object sender, EventArgs e)
- {
- MySQLRunner.ConnectionString = clsDBStrings.maindbcon;
- MySqlConnection conAdd = new MySqlConnection(MySQLRunner.ConnectionString);
- string sSQL = "";
- string ID = lsvAccounts.SelectedItems[0].Tag.ToString();
- sSQL = "UPDATE account SET " +
- "account_password=SHA1('" + txtUpdatePass.Text + "') " +
- "WHERE account_id=" + ID.ToString();
- if (MySQLRunner.ExecuteNonQuery(sSQL, conAdd) == false)
- MessageBox.Show("Error changing Password.");
- else
- MessageBox.Show("Password Change Successful.");
- if (conAdd.State == ConnectionState.Open)
- {
- conAdd.Close();
- }
- listaccts();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement