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 System.Data.SqlClient;
- using Ini;
- using MSTSCLib;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- // VARIABLES
- SqlConnection Connection;
- string sname, userid, password,query;
- SqlDataAdapter adapter;
- DataSet dset;
- SqlCommand myCommand;
- SqlDataReader myReader;
- int useruid;
- // VARIABLES
- //OPEN Query Sender
- private async void sendquery_Click(object sender, EventArgs e)
- {
- queryeditor inputquery = new queryeditor();
- inputquery.Show();
- while (inputquery.Visible == true)
- await Task.Delay(500);
- query = inputquery.response;
- try
- {
- dset = new DataSet();
- adapter = new SqlDataAdapter(query, Connection);
- adapter.Fill(dset);
- dataGridView1.DataSource = dset.Tables[0];
- status_label.Text = "Status: " + query + " - sent succesfully.";
- }
- catch (Exception)
- { }
- }
- // Enable editing
- private void button2_Click(object sender, EventArgs e)
- {
- dataGridView1.ReadOnly = !dataGridView1.ReadOnly;
- enable_editing.Text = (enable_editing.Text == "Enable editing"? "Disable editing":"Enable editing");
- status_label.Text = "Status: " + (enable_editing.Text == "Enable editing" ? "Editing disabled" : "Editing enabled");
- }
- // FORM LOAD
- private void Form1_Load(object sender, EventArgs e)
- {
- status_label.Text = "Status: Established connection.";
- dset = new DataSet();
- adapter = new SqlDataAdapter("SELECT * FROM PS_GameData.dbo.Chars", Connection);
- adapter.Fill(dset);
- dataGridView1.DataSource = dset.Tables[0];
- myCommand = new SqlCommand("SELECT name FROM master.sys.databases", Connection);
- SqlDataReader myReader = null;
- myReader = myCommand.ExecuteReader();
- myReader.GetSchemaTable();
- while (myReader.Read())
- comboBox1.Items.Add(myReader["name"].ToString());
- myReader.Close();
- comboBox1.SelectedItem = "PS_GameData";
- UpdateSchema();
- comboBox2.SelectedItem = "UserID";
- IniFile queries_saved = new IniFile("config.ini");
- string read = null;
- for(int i = 1; !String.IsNullOrWhiteSpace(read = queries_saved.IniReadValue("QUERIES", "s" + i));i++)
- {
- }
- }
- public void save_var(SqlConnection conn,string servername,string uname,string pwd)
- {
- Connection = conn;
- sname = servername;
- userid = uname;
- password = pwd;
- }
- // FORM CLOSING
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- Application.Exit();
- }
- // Browse database
- private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- string selected_item = listBox1.GetItemText(listBox1.SelectedItem);
- query = "SELECT * FROM " + selected_item;
- dset = new DataSet();
- adapter = new SqlDataAdapter(query, Connection);
- adapter.Fill(dset);
- dataGridView1.DataSource = dset.Tables[0];
- status_label.Text = "Status: " + query + " - sent succesfully.";
- }
- // Still database surfing
- private void comboBox1_TextChanged(object sender, EventArgs e)
- {
- Connection = new SqlConnection("user id=" + userid +
- ";password=" + password +
- ";server=" + sname +
- ";Trusted_Connection=no" +
- ";database=" + comboBox1.Text +
- ";connection timeout=30");
- try
- {
- Connection.Open();
- }
- catch (Exception exc) { MessageBox.Show(exc.ToString()); }
- UpdateSchema();
- }
- // IDK?
- void UpdateSchema()
- {
- myCommand = new SqlCommand("SELECT name FROM sysobjects WHERE xtype = 'U'", Connection);
- myReader = myCommand.ExecuteReader();
- listBox1.Items.Clear();
- while (myReader.Read())
- listBox1.Items.Add(myReader["name"].ToString());
- myReader.Close();
- }
- // Create a connection
- SqlConnection sql_connection()
- {
- return new SqlConnection("user id=" + userid +
- ";password=" + password +
- ";server=" + sname +
- ";Trusted_Connection=no" +
- ";database=PS_GameData" +
- ";connection timeout=30");
- }
- // Send a command
- public SqlDataReader SendQuery(string Command, SqlConnection Connection)
- {
- SqlCommand com = new SqlCommand(Command, Connection);
- SqlDataReader read = com.ExecuteReader();
- return read;
- }
- // UPDATE DB
- private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
- {
- var dc = dset.GetChanges();
- adapter.Update(dc);
- string new_value = dataGridView1.CurrentCell.Value.ToString();
- //MessageBox.Show(dataGridView1.CurrentRow.ToString());
- //dataGridView1.Rows[0]
- //string Query = "UPDATE PS_GameData.dbo.Chars set Charname = '"+new_value+"' WHERE charname = '"+old_value+"'";
- //SendQuery(Query);
- //status_label.Text = "Status: '" + Query + "' executed.";
- }
- // rdp connection
- private void button1_Click_1(object sender, EventArgs e)
- {
- RDP.Server = "ec2-23-23-253-48.compute-1.amazonaws.com";
- RDP.UserName = "Denallix\\K2RDPTest";
- IMsTscNonScriptable secured = (IMsTscNonScriptable)RDP.GetOcx();
- secured.ClearTextPassword = "K2pass!";
- RDP.Connect();
- }
- // Search button in tab2
- private void button3_Click(object sender, EventArgs e)
- {
- // prepara una nuova lettura
- string filter = comboBox2.SelectedItem.ToString();
- string Table = filter.Contains("Char") ? "PS_GameData.dbo.Chars" : "PS_UserData.dbo.Users_Master";
- string query = "SELECT * FROM " + Table + " WHERE " + filter + " = '" + textBox1.Text + "'";
- SqlConnection temp_connection = sql_connection();
- SqlCommand temp_command = null;
- SqlDataReader temp_reader = null;
- temp_connection.Open();
- // esegue una query e ne legge il risultato
- temp_command = new SqlCommand(query, temp_connection);
- temp_reader = temp_command.ExecuteReader();
- temp_reader.Read();
- try
- {
- useruid = (int)temp_reader["UserUID"];
- ChargeInfo(useruid, "PS_UserData.dbo.Users_Master");
- ChargeInfo(useruid, "PS_GameData.dbo.Chars");
- ChargeInfo(1, "PS_GameData.dbo.CharItems");
- temp_reader.Close();
- temp_command = new SqlCommand("SELECT CharName FROM Chars Where UserUID = " + useruid + "", temp_connection);
- temp_reader = temp_command.ExecuteReader();
- CharListBox_T2.Items.Clear();
- while (temp_reader.Read())
- CharListBox_T2.Items.Add(temp_reader["CharName"].ToString());
- temp_reader.Close();
- temp_connection.Close();
- CharListBox_T2.SelectedIndex = 0;
- }
- catch (InvalidOperationException )
- {MessageBox.Show("Unable to find any result","Not Found");}
- }
- // Form resize
- private void Form1_Resize(object sender, EventArgs e)
- {
- }
- // Change pg in selection
- private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
- {
- ChargeInfo(useruid, "PS_GameData.dbo.Chars");
- }
- void ChargeInfo(int identifier,string source)
- {
- if (source.Equals("PS_UserData.dbo.Users_Master"))
- {
- SqlConnection temp_connection = sql_connection();
- temp_connection.Open();
- string query = "SELECT * FROM PS_UserData.dbo.Users_Master WHERE UserUID = '" + useruid + "'";
- SqlCommand cmd = new SqlCommand(query, temp_connection);
- SqlDataReader reader2 = cmd.ExecuteReader();
- reader2.Read();
- textBox2.Text = reader2["UserID"].ToString();
- label15.Text = "UserUID: " + reader2["UserUID"].ToString();
- label6.Text = "Username: " + reader2["UserID"].ToString();
- label16.Text = "UserIP: " + reader2["UserIP"].ToString();
- textBox3.Text = reader2["Pw"].ToString();
- textBox4.Text = reader2["Status"].ToString();
- textBox11.Text = reader2["Point"].ToString();
- }
- else if (source.Equals("PS_GameData.dbo.Chars"))
- {
- SqlConnection temp_connection = sql_connection();
- temp_connection.Open();
- string query = "SELECT * FROM PS_GameData.dbo.Chars WHERE UserUID = '" + useruid + "'";
- SqlCommand cmd = new SqlCommand(query, temp_connection);
- SqlDataReader reader2 = cmd.ExecuteReader();
- reader2.Read();
- for (int i = 0; i < CharListBox_T2.SelectedIndex; i++)
- reader2.Read();
- textBox7.Text = reader2["CharName"].ToString();
- textBox6.Text = reader2["K1"].ToString();
- textBox5.Text = reader2["K2"].ToString();
- if (reader2["Del"].ToString().Equals("1"))
- {
- label17.Text = "IsDead? Yes";
- button6.Text = "Resurrect";
- }
- else
- {
- label17.Text = "IsDead? No";
- button6.Text = "Kill";
- }
- ChargeInfo((int)reader2["CharID"], "PS_GameData.dbo.CharItems");
- ChargeInfo((int)reader2["UserUID"], "PS_GameData.dbo.UserStoredItems");
- textBox10.Text = reader2["Str"].ToString();
- textBox8.Text = reader2["Dex"].ToString();
- textBox9.Text = reader2["Rec"].ToString();
- textBox20.Text = reader2["Int"].ToString();
- textBox19.Text = reader2["Luc"].ToString();
- textBox21.Text = reader2["Wis"].ToString();
- textBox15.Text = reader2["Map"].ToString();
- textBox18.Text = reader2["Level"].ToString();
- label21.Text = "Creation date: " + reader2["RegDate"].ToString();
- label22.Text = reader2["LoginStatus"].ToString().Equals("0") ? "State: Offline" : "State:Online" ;
- }
- else if (source.Equals("PS_GameData.dbo.CharItems"))
- {
- SqlConnection temp_connection = sql_connection();
- temp_connection.Open();
- string query = "SELECT * FROM PS_GameData.dbo.CharItems WHERE CharID = '" + identifier + "'";
- DataSet temp_dset = new DataSet();
- SqlDataAdapter temp_adapter = new SqlDataAdapter(query, temp_connection);
- temp_adapter.Fill(temp_dset);
- CharItemsDataGrid_2.DataSource = temp_dset.Tables[0];
- }
- else if (source.Equals("PS_GameData.dbo.UserStoredItems"))
- {
- SqlConnection temp_connection = sql_connection();
- temp_connection.Open();
- string query = "SELECT * FROM PS_GameData.dbo.UserStoredItems WHERE UserUID = '" + identifier + "'";
- DataSet temp_dset = new DataSet();
- SqlDataAdapter temp_adapter = new SqlDataAdapter(query, temp_connection);
- temp_adapter.Fill(temp_dset);
- UserStItemsDataGrid_2.DataSource = temp_dset.Tables[0];
- }
- }
- private void button8_Click(object sender, EventArgs e)
- {
- if (this.Height >= 705)
- {
- this.Height = 427;
- groupBox5.Visible = !groupBox5.Visible;
- }
- else if(this.Height <= 427)
- {
- this.Height = 705;
- groupBox5.Visible = !groupBox5.Visible;
- }
- }
- private void comboBox7_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void comboBox6_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void comboBox5_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void comboBox9_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void button7_Click(object sender, EventArgs e)
- {
- if (!String.IsNullOrEmpty(textBox33.Text.ToString()))
- {
- SqlConnection conn = sql_connection();
- string Query = "SELECT * FROM PS_GameData.dbo." + comboBox3.Text.ToString() + " WHERE ItemUID = " + textBox33.Text.ToString();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement