Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. public int IsAuth { get; set; }
  2.  
  3. //[DataTable("User_Cred")]
  4. public class User_Cred
  5. {
  6. public string id { get; set; }
  7. public string Username { get; set; }
  8. public string Password { get; set; }
  9.  
  10. }
  11.  
  12.  
  13.  
  14. private IMobileServiceSyncTable<User_Cred> todoGetTable = App.MobileService.GetSyncTable<User_Cred>();
  15.  
  16.  
  17.  
  18. private async Task InitLocalStoreAsync()
  19. {
  20. if (!App.MobileService.SyncContext.IsInitialized)
  21. {
  22. var store = new MobileServiceSQLiteStore("CIS4910C-DB");
  23. store.DefineTable<User_Cred>();
  24. await App.MobileService.SyncContext.InitializeAsync(store);
  25. }
  26. await SyncAsync();
  27. }
  28.  
  29. private async Task SyncAsync()
  30. {
  31. await App.MobileService.SyncContext.PushAsync();
  32. await todoGetTable.PullAsync("User_Cred", todoGetTable.CreateQuery());
  33. }
  34.  
  35.  
  36.  
  37. async public void submitAuthBtn_Click(object sender, RoutedEventArgs e)
  38. {
  39. await InitLocalStoreAsync();
  40.  
  41. GetAuthentication();
  42.  
  43. }
  44.  
  45. async public void GetAuthentication()
  46. {
  47. try
  48. {
  49.  
  50. //IMobileServiceTable<User_Cred> todoTable = App.MobileService.GetTable<User_Cred>();
  51.  
  52. List<User_Cred> items = await todoGetTable
  53. .Where(User_Cred => User_Cred.Username == textBoxUsername.Text)
  54. .ToListAsync();
  55.  
  56. IsAuth = items.Count();
  57.  
  58.  
  59.  
  60. // Return a List UI control value back to the form
  61.  
  62. foreach (var value in items)
  63. {
  64.  
  65. var dialog = new MessageDialog("Welcome Back " + value.Username);
  66. await dialog.ShowAsync();
  67. this.Frame.Navigate(typeof(home));
  68. }
  69.  
  70.  
  71. if (IsAuth > 0)
  72. {
  73. var dialog = new MessageDialog("You are Authenticated");
  74. await dialog.ShowAsync();
  75.  
  76.  
  77. }
  78. else
  79. {
  80. var dialog = new MessageDialog(" Account Does Not Exist, please Register to get Started.");
  81. await dialog.ShowAsync();
  82. }
  83. }
  84. catch (Exception em)
  85. {
  86. var dialog = new MessageDialog("An Error Occured: " + em.Message);
  87. await dialog.ShowAsync();
  88. }
  89. }
  90.  
  91. async private void submitAuthBtn_Copy_Click(object sender, RoutedEventArgs e)
  92. {
  93. try
  94. {
  95. User_Cred itemReg = new User_Cred
  96. {
  97. Username = textBoxUsername.Text,
  98. Password = textBoxPassword.Text
  99.  
  100. };
  101. await App.MobileService.GetTable<User_Cred>().InsertAsync(itemReg);
  102. var dialog = new MessageDialog("Thank you for Registering! Now just hit log in");
  103. await dialog.ShowAsync();
  104.  
  105. }
  106. catch (Exception em)
  107. {
  108. var dialog = new MessageDialog("An Error Occured: " +em.Message);
  109.  
  110. await dialog.ShowAsync();
  111. }
  112. }
  113.  
  114. public string globalUserLabel;
  115.  
  116. public void SaveSetting(string userLabel, string userNamelabel)
  117. {
  118. globalUserLabel = userLabel;
  119. ApplicationDataContainer localSettings =
  120. ApplicationData.Current.LocalSettings;
  121. //Saving your setting
  122. localSettings.Values[userLabel] = textBoxUsername.Text;
  123. }
  124.  
  125. public home()
  126. {
  127. this.InitializeComponent();
  128. UserNameLabelBox.Text = ReadSetting(MainPage.globalUserLabel );
  129. }
  130.  
  131.  
  132.  
  133. private string ReadSetting(string userLabel)
  134. {
  135. Windows.Storage.ApplicationDataContainer localSettings =
  136. Windows.Storage.ApplicationData.Current.LocalSettings;
  137. //Reading and returning your setting value
  138. var value = localSettings.Values[userLabel];
  139. if (value != null)
  140. return value.ToString();
  141. else
  142. return userLabel;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement