Advertisement
Guest User

Untitled

a guest
Jan 8th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. // Decompiled with JetBrains decompiler
  2. // Type: PassSaver.Interaction
  3. // Assembly: PassSaver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
  4. // MVID: 63F4F655-5AF4-4653-8798-AD5E71C943D1
  5. // Assembly location: C:\Users\kiril\Desktop\Release\PassSaver.exe
  6.  
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data.Common;
  10. using System.Data.SQLite;
  11. using System.IO;
  12.  
  13. namespace PassSaver
  14. {
  15. internal class Interaction
  16. {
  17. private static SQLiteConnection connection;
  18. private static SQLiteCommand command;
  19. public User[] users;
  20.  
  21. public void Connect(bool first)
  22. {
  23. Directory.GetCurrentDirectory();
  24. if (first)
  25. {
  26. SQLiteConnection.CreateFile("users.db");
  27. Interaction.connection = new SQLiteConnection(string.Format("Data Source={0}\\users.db", (object) Directory.GetCurrentDirectory()));
  28. Interaction.connection.Open();
  29. Interaction.command = new SQLiteCommand(Interaction.connection);
  30. Interaction.command.CommandText = "CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT,Username TEXT NOT NULL,Password TEXT NOT NULL,Description TEXT NULL);";
  31. Interaction.command.ExecuteNonQuery();
  32. }
  33. else
  34. {
  35. Interaction.connection = new SQLiteConnection(string.Format("Data Source={0}\\users.db", (object) Directory.GetCurrentDirectory()));
  36. Interaction.connection.Open();
  37. Interaction.command = new SQLiteCommand(Interaction.connection);
  38. this.UpdateListUsers();
  39. }
  40. }
  41.  
  42. public void AddUser(string username, string password)
  43. {
  44. string str = "INSERT INTO users (Username, Password) VALUES ('" + username + "','" + password + "');";
  45. Interaction.command.CommandText = str;
  46. Interaction.command.ExecuteNonQuery();
  47. this.UpdateListUsers();
  48. }
  49.  
  50. public void AddUser(string username, string password, string description)
  51. {
  52. string str = "INSERT INTO users (Username, Password, Description) VALUES ('" + username + "', '" + password + "', '" + description + "');";
  53. Interaction.command.CommandText = str;
  54. Interaction.command.ExecuteNonQuery();
  55. this.UpdateListUsers();
  56. }
  57.  
  58. public void UpdateListUsers()
  59. {
  60. string str1 = "SELECT * FROM users;";
  61. Interaction.command.CommandText = str1;
  62. SQLiteDataReader sqLiteDataReader = Interaction.command.ExecuteReader();
  63. List<User> userList = new List<User>();
  64. userList.Clear();
  65. foreach (DbDataRecord dbDataRecord in (DbDataReader) sqLiteDataReader)
  66. {
  67. User user = new User();
  68. int int32 = Convert.ToInt32(dbDataRecord["id"].ToString());
  69. string str2 = dbDataRecord["Username"].ToString();
  70. string str3 = dbDataRecord["Password"].ToString();
  71. string str4 = dbDataRecord["Description"].ToString();
  72. user.id = int32;
  73. user.Username = str2;
  74. user.Password = str3;
  75. user.Description = str4;
  76. userList.Add(user);
  77. }
  78. Interaction.command.Reset();
  79. this.users = userList.ToArray();
  80. }
  81.  
  82. public void RemoveUser(int id)
  83. {
  84. string str = string.Format("DELETE FROM users WHERE Username = {0}", (object) id);
  85. Interaction.command.CommandText = str;
  86. Interaction.command.ExecuteNonQuery();
  87. this.UpdateListUsers();
  88. }
  89.  
  90. public void Disconnect()
  91. {
  92. Interaction.connection.Close();
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement