Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Data;
  7. using MySql.Data.MySqlClient;
  8. using System.Windows.Forms;
  9.  
  10. namespace GitKernel.Classes
  11. {
  12. class User
  13. {
  14. public int id { get; set; }
  15. public String name { get; set; }
  16. public String password { get; set; }
  17. public String bio { get; set; }
  18. public int count { get; set; }
  19.  
  20. public List<int> repoIDs = new List<int>();
  21. public List<string> repoNames = new List<string>();
  22. public List<string> repoDescriptions = new List<string>();
  23. public List<string> repoUrls = new List<string>();
  24. public List<string> fileUrls = new List<string>();
  25.  
  26. public User()
  27. {
  28.  
  29. }
  30.  
  31. public User(int id, String name, String password, String bio, List<int> repoIDs, List<string> repoNames, List<string> repoDescriptions, List<string> repoUrls, List<string> fileUrls)
  32. {
  33. this.id = id;
  34. this.name = name;
  35. this.password = password;
  36. this.bio = bio;
  37. this.repoIDs = repoIDs;
  38. this.repoNames = repoNames;
  39. this.repoDescriptions = repoDescriptions;
  40. this.repoUrls = repoUrls;
  41. this.fileUrls = fileUrls;
  42. }
  43. public static void createRepoList()
  44. {
  45. //prepare an SQL query to retrieve all the events on the same, specified date
  46. DataTable myTable = new DataTable();
  47. string connStr = "server=csdatabase.eku.edu;user=stu_csc440;database=csc440_db;port=3306;password=Maroons18";
  48. MySqlConnection conn = new MySqlConnection(connStr);
  49. Program.currentUser.repoIDs.Clear();
  50. Program.currentUser.repoNames.Clear();
  51. Program.currentUser.repoDescriptions.Clear();
  52. Program.currentUser.repoUrls.Clear();
  53. Program.currentUser.fileUrls.Clear();
  54. try
  55. {
  56. conn.Open();
  57.  
  58. string sql = "SELECT * FROM user_connections WHERE userID=@userID";
  59. MySqlCommand cmd = new MySqlCommand(sql, conn);
  60. cmd.Parameters.AddWithValue("@userID", Program.currentUser.id);
  61. MySqlDataReader myReader = cmd.ExecuteReader();
  62. while (myReader.Read())
  63. {
  64. Program.currentUser.repoIDs.Add(int.Parse(myReader["repoID"].ToString()));
  65. Program.currentUser.repoNames.Add("");
  66. Program.currentUser.repoDescriptions.Add("");
  67. Program.currentUser.repoUrls.Add("");
  68. Program.currentUser.fileUrls.Add("");
  69. }
  70. myReader.Close();
  71.  
  72. }
  73. catch (Exception ex)
  74. {
  75. Console.WriteLine(ex.ToString());
  76. }
  77. conn.Close();
  78.  
  79. getRepoInfo();
  80.  
  81. }
  82. private static void getRepoInfo()
  83. {
  84. //prepare an SQL query to retrieve all the events on the same, specified date
  85. DataTable myTable = new DataTable();
  86. string connStr = "server=csdatabase.eku.edu;user=stu_csc440;database=csc440_db;port=3306;password=Maroons18";
  87. MySqlConnection conn = new MySqlConnection(connStr);
  88. try
  89. {
  90. conn.Open();
  91. for (int i = 0; i < Program.currentUser.count; i++)
  92. {
  93. //selecting computer number i in lab
  94. string sql = "SELECT * FROM repository WHERE repoID=@repoID";
  95. MySqlCommand cmd = new MySqlCommand(sql, conn);
  96. cmd.Parameters.AddWithValue("@repoID", Program.currentUser.repositories[i].id);
  97. MySqlDataReader myReader = cmd.ExecuteReader();
  98. if (myReader.Read())
  99. {
  100. Program.currentUser.repositories[i] = new Repository(int.Parse(myReader["repoID"].ToString()),
  101. myReader["repoName"].ToString(), myReader["repoDescription"].ToString(), myReader["repoURL"].ToString(),
  102. myReader["fileURL"].ToString());
  103. }
  104. myReader.Close();
  105. }
  106. }
  107. catch (Exception ex)
  108. {
  109. Console.WriteLine(ex.ToString());
  110. }
  111. conn.Close();
  112. }
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement