Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <SymbolIcon
- Grid.Row = "1" Grid.Column = "1"
- Margin = "10"
- Symbol = "Contact"/>
- <TextBox
- x:Name = "txtUsername"
- Grid.Row = "1" Grid.Column = "2"
- Witdh = "200"
- VerticalAlignment = "Center"
- PlaceholderText = "Username"/>
- <SymbolIcon
- Grid.Row = "2" Grid.Coloumn = "1"
- Margin = "10"
- Symbol = "Permissions"/>
- <PasswordBox
- x:Name = "txtPassword"
- Grid.Row = "2" Grid.Column = "2"
- Width = "200"
- VerticalAlignment = "Center"
- PlaceholderText = "Password"/>
- if(string.IsNullOrWhiteSpace(txtUsername.Text)
- ||string.IsNullOrWhiteSpace(txtPassword.Password)||
- string.IsNullOrWhiteSpace(txtConfirmPassword.Password)){
- ContentDialod contentDialod = new ContentDialog{
- Title = "Information",
- Content = "Please fill all field",
- PrimaryButtonText = "OK"
- };
- await contentDialog.ShowAsync();
- }else if (!txtPassword.Password.Equals(txtConfirmPassword.Password)){
- ContentDialog contentDialog = new ContentDialog{
- Title = "Information",
- Content = "Password doesn't match",
- PrimaryButtonText = "OK"
- };
- await contentDialog.ShowAsync();
- }else
- {
- var vault = new Windows.Security.Credentials.PasswordVault();
- try{
- var retreive = vault.Retreive("Week 10", txtUsername.Text);
- ConcnteDialog contentDialog = new ContentDialog{
- Title = "Information",
- Content = "Username already exists",
- PrimaryButtonText = "OK"
- };
- await contentDialog.ShowAsync();
- }catch(Exception ex){
- vault.Add(new Windows.Security.Credentials.PasswordCredential("Week 10", txtUsername.Text, txtPassword.Password));
- await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
- ()=>{
- Windows.Current.Close();
- })
- }
- }
- private async void btnRegister_Click(object sender,
- RoutedEventArgs e){
- CoreApplicationView newView = CoreApplication.CreateNewView();
- int newViewId = 0;
- await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, ()=>{
- var frame = new Frame();
- frame.Navigation(typeof(RegisterPage));
- Window.Current.Content= frame;
- Window.Current.Activate();
- newViewId = ApplicationView.GetForCurrentView().id;
- });
- bool success = await ApplicationViewSwitcher. TryShowAsStandaloneAsync(newViewId);
- }
- private async void btnLogin_Click(object sender, RoutedEventArgs e){
- string username = txtUsername.Text.ToString();
- string password = txtPassword.Password.ToString();
- var vault = new Windows.Security.Credentials.PasswordVault();
- ContentDialog contentDoalog = new ContentDialog{
- }
- }
- private async void btnLogin_Click(object sender, RoutedEventArgs e){
- string username = txtUsername.Text.ToString();
- string password = txtPassword.Password.ToString();
- var vault = new Windows.Security.Credentials.PasswordValut();
- ContentDiallog contentDialog = new ContentDialog{
- Content = "Username / Password invalid",
- PrimaryButtonText = "OK"
- };
- try{
- result = vault.Retrieve("Week 10", username);
- result.RetrievePassword();
- if(result.Password.ToString().Equals(password)){
- this.Frame.Navigate(typeof(MainMenu), username);
- }else {
- await contentDialog.ShowAsync();
- }
- }catch (Exeption ex){
- await contentDialog.ShowAsync();
- }
- }
- protected override void OnNavigatedTo(NavigationEventArgs e){
- base.OnNavigated(e);
- username = e.Paremeter as string;
- }
- Windows.Storage.ApplicationDataContainer localSettings = windows.Strorage.ApplicationData.Current.LocalSettings;
- if(!localSettings.Values.ContainsKey("theme"))
- {
- localSettings.Values["theme"] = "Light";
- }
- protected override void OnNavigatedFrom(NavigationEventArgs e){
- base.OnNavigatatedFrom(e);
- AdjustTheme();
- }
- public void AdjustTheme(){
- if(localSettings.Values["theme"].Equals("Dark"))
- RequestedTheme = ElementTheme.Dark;
- else
- RequestedTheme = ElementTheme.Light;
- }
- private void toggleColor_Click(object sender, RoutedEventArgs e){
- if(toggleColor.IsChcked == true){
- RequestedTheme = ElementTheme.Dark;
- localSettings.Values["theme"] = "Dark";
- }else {
- RequestTheme = ElementTheme.Light;
- localSettings.Values["theme"] = "Light";
- }
- }
- private void btnLogout_Click(object sender, RoutedEventArgs e){
- if(this.Frame != null && this.Frame.CanGoBack){
- this.Frame.GoBack();
- }
- }
- private StorageFolder localFolder = ApplicationData.Current.LocalFolder;
- private StorageFolder userFolder;
- try{
- userFolder = await localFolder.GetFolderAsync(username);
- }catch(Exeption ex){
- userFolder = await localFolder.CreateAsync(username);
- }
- getFolderContent();
- private async void getFolderContent(){
- IReadOnlyList<StorageFile> fileList = await userfolder.GetFileAsync();
- lvwTextFile.Items.Clear();
- foreach (Storage file in fileList){
- lvwTextFile.Items.Add(file.DisplayName);
- }
- Debug.WriteLine("Retreive done");
- }
- private async void btnOpenFile_Click(object sender, RoutedEventArgs e){
- fileOpenPicker openPicker = new FileOpenPicker();
- openPicker.ViewMode = PickerViewMode.Thumbnail;
- openpicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
- openPicker.FileTypeFilter.Add(".txt");
- StorageFile file = await openPicker.PickSingleFileAsync();
- if(file != null){
- StorageFile historyFile = await userFolder.CreateFileAsync(file.Name, CreationCollisionOption.ReplaceExisting);
- await FileIO.WriteTextAsync(historyFile, file.Path);
- StorageApplicationPermissions.FutureAccessList.AddorReplace(historyFile.name, file);
- string text = await FileIO.ReadTextAsync(file);
- txtContentText.Document.SetText(Windows.UI.Text.TextSetOptions.None, text);
- textContentText.IsEnabled = true;
- }
- getFolderContent();
- }
- private async void lvwTextFile_SelectionChanged(object sender, SelectionChangedEventArgs e){
- var selected = lvwTextFile.SelectedItem;
- if(selected != null){
- StorageFile selectedFile = await userFolder.GetFileAsync(selected + ".txt");
- StorageFile realFile = await StorageApplicationPermissions.FutureAccesList.GetFileAsync(SelectedFile.Name);
- string text = await FileIO.ReadTextAsync(realFile);
- txtContentText.Document.SetText(Windows.UI.Text.TextSetOptions.One, Text);
- txtContentText.IsEnabled = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement