Guest User

Untitled

a guest
Jun 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data.SqlClient;
  6. using MySql.Data;
  7. using MySql.Data.MySqlClient;
  8.  
  9. namespace BTGAdmin
  10. {
  11. class Program
  12. {
  13.  
  14. static string btgConnect = "SERVER=50.63.244.26;" + "DATABASE=btgusers;" + "UID=btgusers;" + "PASSWORD= ;";
  15. static MySqlConnection btgXConnect = new MySqlConnection(btgConnect);
  16. static string sadduser = "INSERT INTO `btgusers`.`Members` (`USERID`, `PASSWORD`, `PIN`) VALUES (@USERID, @PASSWORD, @PIN)";
  17. static string slistuser = "SELECT * FROM `btgusers`.`Members`";
  18. static string sDelUser = "DELETE FROM `btgusers`.`Members` WHERE CONVERT(`Members`.`USERID` USING utf8) = (@USERID) LIMIT 1";
  19. static Dictionary<int, string> sUser = new Dictionary<int, string>();
  20.  
  21. static void Main(string[] args)
  22. {
  23. bool exit = false;
  24. while (!exit)
  25. {
  26. Console.WriteLine("Welcome To BeatTheGa.ME, Choose an Option");
  27. Console.WriteLine(" 1. Add User\r\n 2. Delete User\r\n 3. Exit");
  28. switch (Convert.ToInt32(Console.ReadLine()))
  29. {
  30. case 1:
  31. Console.WriteLine("Enter Username:");
  32. string userid = Console.ReadLine();
  33. Console.WriteLine("Enter Password:");
  34. string password = Console.ReadLine();
  35. Console.WriteLine("Enter Pin:");
  36. string pin = Console.ReadLine();
  37. Console.WriteLine("Adding User: " + userid);
  38. adduser(userid, password, pin);
  39. Console.WriteLine("User Added.");
  40.  
  41. break;
  42. case 2:
  43. Console.WriteLine("User List:\r\n");
  44. Console.WriteLine("KEY|USER|PASS|PIN");
  45. listuser();
  46. Console.WriteLine("Select User to Delete");
  47. string userchoice = Console.ReadLine();
  48. deluser(userchoice);
  49. break;
  50. case 3:
  51. Console.WriteLine("Goodbye.");
  52. exit = true;
  53. break;
  54. default:
  55. Console.WriteLine("Default");
  56. break;
  57. }
  58. }
  59. }
  60. static void deluser(string choice)
  61. {
  62. btgXConnect.Open();
  63. MySqlCommand cmdDeluser = new MySqlCommand(sDelUser, btgXConnect);
  64. cmdDeluser.Parameters.Add("@USERID", choice);
  65. cmdDeluser.ExecuteNonQuery();
  66. btgXConnect.Close();
  67. }
  68. static void listuser()
  69. {
  70. btgXConnect.Open();
  71. MySqlCommand cmdListuser = new MySqlCommand(slistuser, btgXConnect);
  72. MySqlDataReader Reader;
  73. int key = 1;
  74. Reader = cmdListuser.ExecuteReader();
  75. while (Reader.Read())
  76. {
  77. int FieldCount = Reader.FieldCount ;
  78. string row = "";
  79. for (int i = 0; i < FieldCount; i++)
  80. {
  81. row += Reader.GetValue(i).ToString().ToUpper() + ":";
  82. }
  83. sUser.Add(key, Reader.GetValue(0).ToString());
  84. key++;
  85. }
  86. btgXConnect.Close();
  87.  
  88. foreach (var pair in sUser)
  89. {
  90. Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
  91. }
  92.  
  93. }
  94. static void adduser(string userid, string password, string pin)
  95. {
  96. btgXConnect.Open();
  97. MySqlCommand cmdAdduser = new MySqlCommand(sadduser, btgXConnect);
  98. cmdAdduser.Parameters.Add("@USERID", userid);
  99. cmdAdduser.Parameters.Add("@PASSWORD", password);
  100. cmdAdduser.Parameters.Add("@PIN", pin);
  101. cmdAdduser.ExecuteNonQuery();
  102. btgXConnect.Close();
  103. }
  104. }
  105. }
Add Comment
Please, Sign In to add comment