Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.93 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 System.Data.SqlClient;
  11. using Ini;
  12. using MSTSCLib;
  13.  
  14. namespace WindowsFormsApplication1
  15. {
  16. public partial class Form1 : Form
  17. {
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. }
  22. // VARIABLES
  23. SqlConnection Connection;
  24. string sname, userid, password,query;
  25. SqlDataAdapter adapter;
  26. DataSet dset;
  27. SqlCommand myCommand;
  28. SqlDataReader myReader;
  29. int useruid;
  30.  
  31. // VARIABLES
  32.  
  33. //OPEN Query Sender
  34. private async void sendquery_Click(object sender, EventArgs e)
  35. {
  36. queryeditor inputquery = new queryeditor();
  37. inputquery.Show();
  38. while (inputquery.Visible == true)
  39. await Task.Delay(500);
  40. query = inputquery.response;
  41. try
  42. {
  43. dset = new DataSet();
  44. adapter = new SqlDataAdapter(query, Connection);
  45. adapter.Fill(dset);
  46. dataGridView1.DataSource = dset.Tables[0];
  47. status_label.Text = "Status: " + query + " - sent succesfully.";
  48. }
  49. catch (Exception)
  50. { }
  51. }
  52. // Enable editing
  53. private void button2_Click(object sender, EventArgs e)
  54. {
  55. dataGridView1.ReadOnly = !dataGridView1.ReadOnly;
  56. enable_editing.Text = (enable_editing.Text == "Enable editing"? "Disable editing":"Enable editing");
  57. status_label.Text = "Status: " + (enable_editing.Text == "Enable editing" ? "Editing disabled" : "Editing enabled");
  58. }
  59. // FORM LOAD
  60. private void Form1_Load(object sender, EventArgs e)
  61. {
  62. status_label.Text = "Status: Established connection.";
  63. dset = new DataSet();
  64. adapter = new SqlDataAdapter("SELECT * FROM PS_GameData.dbo.Chars", Connection);
  65. adapter.Fill(dset);
  66. dataGridView1.DataSource = dset.Tables[0];
  67. myCommand = new SqlCommand("SELECT name FROM master.sys.databases", Connection);
  68. SqlDataReader myReader = null;
  69. myReader = myCommand.ExecuteReader();
  70. myReader.GetSchemaTable();
  71. while (myReader.Read())
  72. comboBox1.Items.Add(myReader["name"].ToString());
  73. myReader.Close();
  74. comboBox1.SelectedItem = "PS_GameData";
  75. UpdateSchema();
  76. comboBox2.SelectedItem = "UserID";
  77.  
  78.  
  79. IniFile queries_saved = new IniFile("config.ini");
  80. string read = null;
  81. for(int i = 1; !String.IsNullOrWhiteSpace(read = queries_saved.IniReadValue("QUERIES", "s" + i));i++)
  82. {
  83. }
  84.  
  85.  
  86.  
  87.  
  88.  
  89. }
  90.  
  91. public void save_var(SqlConnection conn,string servername,string uname,string pwd)
  92. {
  93. Connection = conn;
  94. sname = servername;
  95. userid = uname;
  96. password = pwd;
  97. }
  98. // FORM CLOSING
  99. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  100. {
  101. Application.Exit();
  102. }
  103. // Browse database
  104. private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  105. {
  106. string selected_item = listBox1.GetItemText(listBox1.SelectedItem);
  107. query = "SELECT * FROM " + selected_item;
  108. dset = new DataSet();
  109. adapter = new SqlDataAdapter(query, Connection);
  110. adapter.Fill(dset);
  111. dataGridView1.DataSource = dset.Tables[0];
  112. status_label.Text = "Status: " + query + " - sent succesfully.";
  113. }
  114. // Still database surfing
  115. private void comboBox1_TextChanged(object sender, EventArgs e)
  116. {
  117. Connection = new SqlConnection("user id=" + userid +
  118. ";password=" + password +
  119. ";server=" + sname +
  120. ";Trusted_Connection=no" +
  121. ";database=" + comboBox1.Text +
  122. ";connection timeout=30");
  123. try
  124. {
  125. Connection.Open();
  126. }
  127. catch (Exception exc) { MessageBox.Show(exc.ToString()); }
  128. UpdateSchema();
  129. }
  130. // IDK?
  131. void UpdateSchema()
  132. {
  133. myCommand = new SqlCommand("SELECT name FROM sysobjects WHERE xtype = 'U'", Connection);
  134. myReader = myCommand.ExecuteReader();
  135. listBox1.Items.Clear();
  136. while (myReader.Read())
  137. listBox1.Items.Add(myReader["name"].ToString());
  138. myReader.Close();
  139. }
  140. // Create a connection
  141. SqlConnection sql_connection()
  142. {
  143. return new SqlConnection("user id=" + userid +
  144. ";password=" + password +
  145. ";server=" + sname +
  146. ";Trusted_Connection=no" +
  147. ";database=PS_GameData" +
  148. ";connection timeout=30");
  149.  
  150. }
  151.  
  152. // Send a command
  153. public SqlDataReader SendQuery(string Command, SqlConnection Connection)
  154. {
  155. SqlCommand com = new SqlCommand(Command, Connection);
  156. SqlDataReader read = com.ExecuteReader();
  157. return read;
  158. }
  159. // UPDATE DB
  160. private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  161. {
  162. var dc = dset.GetChanges();
  163. adapter.Update(dc);
  164. string new_value = dataGridView1.CurrentCell.Value.ToString();
  165. //MessageBox.Show(dataGridView1.CurrentRow.ToString());
  166. //dataGridView1.Rows[0]
  167. //string Query = "UPDATE PS_GameData.dbo.Chars set Charname = '"+new_value+"' WHERE charname = '"+old_value+"'";
  168. //SendQuery(Query);
  169. //status_label.Text = "Status: '" + Query + "' executed.";
  170. }
  171. // rdp connection
  172. private void button1_Click_1(object sender, EventArgs e)
  173. {
  174. RDP.Server = "ec2-23-23-253-48.compute-1.amazonaws.com";
  175. RDP.UserName = "Denallix\\K2RDPTest";
  176. IMsTscNonScriptable secured = (IMsTscNonScriptable)RDP.GetOcx();
  177. secured.ClearTextPassword = "K2pass!";
  178. RDP.Connect();
  179. }
  180. // Search button in tab2
  181. private void button3_Click(object sender, EventArgs e)
  182. {
  183. // prepara una nuova lettura
  184.  
  185. string filter = comboBox2.SelectedItem.ToString();
  186. string Table = filter.Contains("Char") ? "PS_GameData.dbo.Chars" : "PS_UserData.dbo.Users_Master";
  187. string query = "SELECT * FROM " + Table + " WHERE " + filter + " = '" + textBox1.Text + "'";
  188.  
  189. SqlConnection temp_connection = sql_connection();
  190. SqlCommand temp_command = null;
  191. SqlDataReader temp_reader = null;
  192.  
  193. temp_connection.Open();
  194. // esegue una query e ne legge il risultato
  195. temp_command = new SqlCommand(query, temp_connection);
  196. temp_reader = temp_command.ExecuteReader();
  197. temp_reader.Read();
  198.  
  199. try
  200. {
  201.  
  202. useruid = (int)temp_reader["UserUID"];
  203. ChargeInfo(useruid, "PS_UserData.dbo.Users_Master");
  204. ChargeInfo(useruid, "PS_GameData.dbo.Chars");
  205. ChargeInfo(1, "PS_GameData.dbo.CharItems");
  206.  
  207. temp_reader.Close();
  208.  
  209. temp_command = new SqlCommand("SELECT CharName FROM Chars Where UserUID = " + useruid + "", temp_connection);
  210. temp_reader = temp_command.ExecuteReader();
  211. CharListBox_T2.Items.Clear();
  212. while (temp_reader.Read())
  213. CharListBox_T2.Items.Add(temp_reader["CharName"].ToString());
  214. temp_reader.Close();
  215.  
  216. temp_connection.Close();
  217. CharListBox_T2.SelectedIndex = 0;
  218. }
  219.  
  220. catch (InvalidOperationException )
  221. {MessageBox.Show("Unable to find any result","Not Found");}
  222.  
  223. }
  224. // Form resize
  225. private void Form1_Resize(object sender, EventArgs e)
  226. {
  227.  
  228. }
  229. // Change pg in selection
  230. private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
  231. {
  232. ChargeInfo(useruid, "PS_GameData.dbo.Chars");
  233. }
  234.  
  235. void ChargeInfo(int identifier,string source)
  236. {
  237.  
  238.  
  239. if (source.Equals("PS_UserData.dbo.Users_Master"))
  240. {
  241. SqlConnection temp_connection = sql_connection();
  242.  
  243. temp_connection.Open();
  244. string query = "SELECT * FROM PS_UserData.dbo.Users_Master WHERE UserUID = '" + useruid + "'";
  245. SqlCommand cmd = new SqlCommand(query, temp_connection);
  246. SqlDataReader reader2 = cmd.ExecuteReader();
  247. reader2.Read();
  248.  
  249. textBox2.Text = reader2["UserID"].ToString();
  250. label15.Text = "UserUID: " + reader2["UserUID"].ToString();
  251. label6.Text = "Username: " + reader2["UserID"].ToString();
  252. label16.Text = "UserIP: " + reader2["UserIP"].ToString();
  253. textBox3.Text = reader2["Pw"].ToString();
  254. textBox4.Text = reader2["Status"].ToString();
  255. textBox11.Text = reader2["Point"].ToString();
  256.  
  257.  
  258. }
  259. else if (source.Equals("PS_GameData.dbo.Chars"))
  260. {
  261. SqlConnection temp_connection = sql_connection();
  262.  
  263. temp_connection.Open();
  264. string query = "SELECT * FROM PS_GameData.dbo.Chars WHERE UserUID = '" + useruid + "'";
  265. SqlCommand cmd = new SqlCommand(query, temp_connection);
  266. SqlDataReader reader2 = cmd.ExecuteReader();
  267. reader2.Read();
  268.  
  269. for (int i = 0; i < CharListBox_T2.SelectedIndex; i++)
  270. reader2.Read();
  271.  
  272. textBox7.Text = reader2["CharName"].ToString();
  273. textBox6.Text = reader2["K1"].ToString();
  274. textBox5.Text = reader2["K2"].ToString();
  275. if (reader2["Del"].ToString().Equals("1"))
  276. {
  277. label17.Text = "IsDead? Yes";
  278. button6.Text = "Resurrect";
  279. }
  280. else
  281. {
  282. label17.Text = "IsDead? No";
  283. button6.Text = "Kill";
  284. }
  285.  
  286. ChargeInfo((int)reader2["CharID"], "PS_GameData.dbo.CharItems");
  287. ChargeInfo((int)reader2["UserUID"], "PS_GameData.dbo.UserStoredItems");
  288.  
  289.  
  290. textBox10.Text = reader2["Str"].ToString();
  291. textBox8.Text = reader2["Dex"].ToString();
  292. textBox9.Text = reader2["Rec"].ToString();
  293. textBox20.Text = reader2["Int"].ToString();
  294. textBox19.Text = reader2["Luc"].ToString();
  295. textBox21.Text = reader2["Wis"].ToString();
  296. textBox15.Text = reader2["Map"].ToString();
  297. textBox18.Text = reader2["Level"].ToString();
  298. label21.Text = "Creation date: " + reader2["RegDate"].ToString();
  299. label22.Text = reader2["LoginStatus"].ToString().Equals("0") ? "State: Offline" : "State:Online" ;
  300.  
  301. }
  302.  
  303. else if (source.Equals("PS_GameData.dbo.CharItems"))
  304. {
  305. SqlConnection temp_connection = sql_connection();
  306.  
  307. temp_connection.Open();
  308. string query = "SELECT * FROM PS_GameData.dbo.CharItems WHERE CharID = '" + identifier + "'";
  309.  
  310. DataSet temp_dset = new DataSet();
  311. SqlDataAdapter temp_adapter = new SqlDataAdapter(query, temp_connection);
  312. temp_adapter.Fill(temp_dset);
  313. CharItemsDataGrid_2.DataSource = temp_dset.Tables[0];
  314. }
  315. else if (source.Equals("PS_GameData.dbo.UserStoredItems"))
  316. {
  317. SqlConnection temp_connection = sql_connection();
  318.  
  319. temp_connection.Open();
  320. string query = "SELECT * FROM PS_GameData.dbo.UserStoredItems WHERE UserUID = '" + identifier + "'";
  321.  
  322. DataSet temp_dset = new DataSet();
  323. SqlDataAdapter temp_adapter = new SqlDataAdapter(query, temp_connection);
  324. temp_adapter.Fill(temp_dset);
  325. UserStItemsDataGrid_2.DataSource = temp_dset.Tables[0];
  326.  
  327. }
  328.  
  329.  
  330. }
  331.  
  332. private void button8_Click(object sender, EventArgs e)
  333. {
  334. if (this.Height >= 705)
  335. {
  336. this.Height = 427;
  337. groupBox5.Visible = !groupBox5.Visible;
  338. }
  339. else if(this.Height <= 427)
  340. {
  341. this.Height = 705;
  342. groupBox5.Visible = !groupBox5.Visible;
  343.  
  344. }
  345. }
  346. private void comboBox7_SelectedIndexChanged(object sender, EventArgs e)
  347. {
  348.  
  349. }
  350. private void comboBox6_SelectedIndexChanged(object sender, EventArgs e)
  351. {
  352.  
  353. }
  354. private void comboBox5_SelectedIndexChanged(object sender, EventArgs e)
  355. {
  356.  
  357. }
  358. private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
  359. {
  360.  
  361. }
  362. private void comboBox9_SelectedIndexChanged(object sender, EventArgs e)
  363. {
  364.  
  365. }
  366.  
  367. private void button7_Click(object sender, EventArgs e)
  368. {
  369. if (!String.IsNullOrEmpty(textBox33.Text.ToString()))
  370. {
  371. SqlConnection conn = sql_connection();
  372. string Query = "SELECT * FROM PS_GameData.dbo." + comboBox3.Text.ToString() + " WHERE ItemUID = " + textBox33.Text.ToString();
  373. }
  374. }
  375.  
  376.  
  377.  
  378. }
  379. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement