Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. using SQLite;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using PCLStorage;
  5.  
  6. namespace DevEnvExe_LocalStorage
  7. {
  8. public class SqlHelper
  9. {
  10. static object locker = new object();
  11. SQLiteConnection database;
  12. public SqlHelper()
  13. {
  14. database = GetConnection();
  15. // create the tables
  16. database.CreateTable<RegEntity>();
  17. }
  18. public SQLite.SQLiteConnection GetConnection()
  19. {
  20. SQLiteConnection sqlitConnection;
  21. var sqliteFilename = "Employee.db3";
  22. IFolder folder = FileSystem.Current.LocalStorage;
  23. string path = PortablePath.Combine(folder.Path.ToString(), sqliteFilename);
  24. sqlitConnection = new SQLite.SQLiteConnection(path);
  25. return sqlitConnection;
  26. }
  27.  
  28. public IEnumerable<RegEntity> GetItems()
  29. {
  30. lock (locker)
  31. {
  32. return (from i in database.Table<RegEntity>() select i).ToList();
  33. }
  34. }
  35.  
  36. public RegEntity GetItem(string userName)
  37. {
  38. lock (locker)
  39. {
  40. return database.Table<RegEntity>().FirstOrDefault(x => x.Username == userName);
  41. }
  42. }
  43. public RegEntity GetItem(string userName ,string passWord)
  44. {
  45. lock (locker)
  46. {
  47. return database.Table<RegEntity>().FirstOrDefault(x => x.Username == userName && x.Password ==passWord);
  48. }
  49. }
  50. public int SaveItem(RegEntity item)
  51. {
  52. lock (locker)
  53. {
  54. if (item.ID != 0)
  55. {
  56. //Update Item
  57. database.Update(item);
  58. return item.ID;
  59. }
  60. else
  61. {
  62. //Insert item
  63. return database.Insert(item);
  64. }
  65. }
  66. }
  67.  
  68. public int DeleteItem(int id)
  69. {
  70. lock (locker)
  71. {
  72. return database.Delete<RegEntity>(id);
  73. }
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement