Interaction logic for ProgressPage.xaml
Наследование: System.Windows.Controls.Page
Пример #1
0
        /// <summary>
        /// Handles the Click event of the btnNext control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnNext_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(txtPasswordKey.Text) && !string.IsNullOrEmpty(txtDataEncryption.Text))
            {
                var appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                if (appConfig.AppSettings.Settings.Count < 3)
                {
                    appConfig.AppSettings.Settings.Add("ImportUser", string.Empty);
                    appConfig.AppSettings.Settings.Add("PasswordKey", string.Empty);
                    appConfig.AppSettings.Settings.Add("DataEncryptionKey", string.Empty);
                }

                try
                {
                    appConfig.AppSettings.Settings["ImportUser"].Value        = txtImportUser.Text;
                    appConfig.AppSettings.Settings["PasswordKey"].Value       = txtPasswordKey.Text;
                    appConfig.AppSettings.Settings["DataEncryptionKey"].Value = txtDataEncryption.Text;
                    appConfig.Save(ConfigurationSaveMode.Modified);
                    ConfigurationManager.RefreshSection("appSettings");

                    var progressPage = new ProgressPage(excavator);
                    this.NavigationService.Navigate(progressPage);
                }
                catch
                {
                    lblNoData.Content    = "Unable to save the configuration keys. Please check the permissions on the current directory.";
                    lblNoData.Visibility = Visibility.Visible;
                }
            }
        }
        /// <summary>
        /// Handles the Click event of the btnNext control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnNext_Click( object sender, RoutedEventArgs e )
        {
            if ( !string.IsNullOrEmpty( txtPasswordKey.Text ) && !string.IsNullOrEmpty( txtDataEncryption.Text ) )
            {
                var appConfig = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None );
                if ( appConfig.AppSettings.Settings.Count < 3 )
                {
                    appConfig.AppSettings.Settings.Add( "ImportUser", string.Empty );
                    appConfig.AppSettings.Settings.Add( "PasswordKey", string.Empty );
                    appConfig.AppSettings.Settings.Add( "DataEncryptionKey", string.Empty );
                }

                try
                {
                    appConfig.AppSettings.Settings["ImportUser"].Value = txtImportUser.Text;
                    appConfig.AppSettings.Settings["PasswordKey"].Value = txtPasswordKey.Text;
                    appConfig.AppSettings.Settings["DataEncryptionKey"].Value = txtDataEncryption.Text;
                    appConfig.Save( ConfigurationSaveMode.Modified );
                    ConfigurationManager.RefreshSection( "appSettings" );

                    var progressPage = new ProgressPage( excavator );
                    this.NavigationService.Navigate( progressPage );
                }
                catch
                {
                    lblNoData.Content = "Unable to save the configuration keys. Please check the permissions on the current directory.";
                    lblNoData.Visibility = Visibility.Visible;
                }
            }
            else
            {
                lblNoData.Content = "PasswordKey and DataEncryptionKey are required to import accounts.";
                lblNoData.Visibility = Visibility.Visible;
            }
        }