Advertisement
Guest User

Untitled

a guest
Dec 10th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.07 KB | None | 0 0
  1. <SymbolIcon
  2. Grid.Row = "1" Grid.Column = "1"
  3. Margin = "10"
  4. Symbol = "Contact"/>
  5. <TextBox
  6. x:Name = "txtUsername"
  7. Grid.Row = "1" Grid.Column = "2"
  8. Witdh = "200"
  9. VerticalAlignment = "Center"
  10. PlaceholderText = "Username"/>
  11. <SymbolIcon
  12. Grid.Row = "2" Grid.Coloumn = "1"
  13. Margin = "10"
  14. Symbol = "Permissions"/>
  15. <PasswordBox
  16. x:Name = "txtPassword"
  17. Grid.Row = "2" Grid.Column = "2"
  18. Width = "200"
  19. VerticalAlignment = "Center"
  20. PlaceholderText = "Password"/>
  21.  
  22.  
  23. if(string.IsNullOrWhiteSpace(txtUsername.Text)
  24. ||string.IsNullOrWhiteSpace(txtPassword.Password)||
  25. string.IsNullOrWhiteSpace(txtConfirmPassword.Password)){
  26. ContentDialod contentDialod = new ContentDialog{
  27. Title = "Information",
  28. Content = "Please fill all field",
  29. PrimaryButtonText = "OK"
  30. };
  31. await contentDialog.ShowAsync();
  32. }else if (!txtPassword.Password.Equals(txtConfirmPassword.Password)){
  33. ContentDialog contentDialog = new ContentDialog{
  34. Title = "Information",
  35. Content = "Password doesn't match",
  36. PrimaryButtonText = "OK"
  37. };
  38. await contentDialog.ShowAsync();
  39. }else
  40. {
  41. var vault = new Windows.Security.Credentials.PasswordVault();
  42. try{
  43. var retreive = vault.Retreive("Week 10", txtUsername.Text);
  44. ConcnteDialog contentDialog = new ContentDialog{
  45. Title = "Information",
  46. Content = "Username already exists",
  47. PrimaryButtonText = "OK"
  48. };
  49. await contentDialog.ShowAsync();
  50. }catch(Exception ex){
  51. vault.Add(new Windows.Security.Credentials.PasswordCredential("Week 10", txtUsername.Text, txtPassword.Password));
  52. await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
  53. ()=>{
  54. Windows.Current.Close();
  55. })
  56. }
  57. }
  58.  
  59. private async void btnRegister_Click(object sender,
  60. RoutedEventArgs e){
  61. CoreApplicationView newView = CoreApplication.CreateNewView();
  62. int newViewId = 0;
  63. await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, ()=>{
  64. var frame = new Frame();
  65. frame.Navigation(typeof(RegisterPage));
  66. Window.Current.Content= frame;
  67. Window.Current.Activate();
  68. newViewId = ApplicationView.GetForCurrentView().id;
  69.  
  70. });
  71. bool success = await ApplicationViewSwitcher. TryShowAsStandaloneAsync(newViewId);
  72. }
  73.  
  74. private async void btnLogin_Click(object sender, RoutedEventArgs e){
  75. string username = txtUsername.Text.ToString();
  76. string password = txtPassword.Password.ToString();
  77. var vault = new Windows.Security.Credentials.PasswordVault();
  78. ContentDialog contentDoalog = new ContentDialog{
  79.  
  80. }
  81. }
  82.  
  83. private async void btnLogin_Click(object sender, RoutedEventArgs e){
  84. string username = txtUsername.Text.ToString();
  85. string password = txtPassword.Password.ToString();
  86. var vault = new Windows.Security.Credentials.PasswordValut();
  87. ContentDiallog contentDialog = new ContentDialog{
  88. Content = "Username / Password invalid",
  89. PrimaryButtonText = "OK"
  90. };
  91. try{
  92. result = vault.Retrieve("Week 10", username);
  93. result.RetrievePassword();
  94. if(result.Password.ToString().Equals(password)){
  95. this.Frame.Navigate(typeof(MainMenu), username);
  96. }else {
  97. await contentDialog.ShowAsync();
  98. }
  99. }catch (Exeption ex){
  100. await contentDialog.ShowAsync();
  101. }
  102. }
  103.  
  104. protected override void OnNavigatedTo(NavigationEventArgs e){
  105. base.OnNavigated(e);
  106. username = e.Paremeter as string;
  107. }
  108.  
  109. Windows.Storage.ApplicationDataContainer localSettings = windows.Strorage.ApplicationData.Current.LocalSettings;
  110. if(!localSettings.Values.ContainsKey("theme"))
  111. {
  112. localSettings.Values["theme"] = "Light";
  113. }
  114.  
  115. protected override void OnNavigatedFrom(NavigationEventArgs e){
  116. base.OnNavigatatedFrom(e);
  117. AdjustTheme();
  118. }
  119.  
  120. public void AdjustTheme(){
  121. if(localSettings.Values["theme"].Equals("Dark"))
  122. RequestedTheme = ElementTheme.Dark;
  123. else
  124. RequestedTheme = ElementTheme.Light;
  125. }
  126.  
  127. private void toggleColor_Click(object sender, RoutedEventArgs e){
  128. if(toggleColor.IsChcked == true){
  129. RequestedTheme = ElementTheme.Dark;
  130. localSettings.Values["theme"] = "Dark";
  131. }else {
  132. RequestTheme = ElementTheme.Light;
  133. localSettings.Values["theme"] = "Light";
  134. }
  135. }
  136.  
  137. private void btnLogout_Click(object sender, RoutedEventArgs e){
  138. if(this.Frame != null && this.Frame.CanGoBack){
  139. this.Frame.GoBack();
  140. }
  141. }
  142.  
  143. private StorageFolder localFolder = ApplicationData.Current.LocalFolder;
  144. private StorageFolder userFolder;
  145.  
  146. try{
  147. userFolder = await localFolder.GetFolderAsync(username);
  148.  
  149. }catch(Exeption ex){
  150. userFolder = await localFolder.CreateAsync(username);
  151. }
  152. getFolderContent();
  153.  
  154. private async void getFolderContent(){
  155.  
  156. IReadOnlyList<StorageFile> fileList = await userfolder.GetFileAsync();
  157. lvwTextFile.Items.Clear();
  158. foreach (Storage file in fileList){
  159. lvwTextFile.Items.Add(file.DisplayName);
  160. }
  161. Debug.WriteLine("Retreive done");
  162. }
  163.  
  164. private async void btnOpenFile_Click(object sender, RoutedEventArgs e){
  165. fileOpenPicker openPicker = new FileOpenPicker();
  166. openPicker.ViewMode = PickerViewMode.Thumbnail;
  167. openpicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
  168. openPicker.FileTypeFilter.Add(".txt");
  169.  
  170. StorageFile file = await openPicker.PickSingleFileAsync();
  171. if(file != null){
  172. StorageFile historyFile = await userFolder.CreateFileAsync(file.Name, CreationCollisionOption.ReplaceExisting);
  173. await FileIO.WriteTextAsync(historyFile, file.Path);
  174.  
  175. StorageApplicationPermissions.FutureAccessList.AddorReplace(historyFile.name, file);
  176.  
  177. string text = await FileIO.ReadTextAsync(file);
  178. txtContentText.Document.SetText(Windows.UI.Text.TextSetOptions.None, text);
  179. textContentText.IsEnabled = true;
  180. }
  181. getFolderContent();
  182. }
  183.  
  184. private async void lvwTextFile_SelectionChanged(object sender, SelectionChangedEventArgs e){
  185. var selected = lvwTextFile.SelectedItem;
  186. if(selected != null){
  187. StorageFile selectedFile = await userFolder.GetFileAsync(selected + ".txt");
  188. StorageFile realFile = await StorageApplicationPermissions.FutureAccesList.GetFileAsync(SelectedFile.Name);
  189. string text = await FileIO.ReadTextAsync(realFile);
  190. txtContentText.Document.SetText(Windows.UI.Text.TextSetOptions.One, Text);
  191. txtContentText.IsEnabled = true;
  192. }
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement