コード例 #1
0
        /// <summary>
        /// Handle save changes event.
        /// </summary>
        private async void BtnSaveChanges_Click(object sender, System.EventArgs e)
        {
            Cursor previous = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                //remove accounts
                foreach (var account in m_accountData.Where(a => a.Action == AccountAction.REMOVE))
                {
                    if (m_datalayer.RemoveAccountDataItem(account) == false)
                    {
                        m_logger.LogError($"Failed to remove account: {account.Name}. Already exists");
                    }
                }

                //now add and edit accounts
                foreach (var account in m_accountData.Where(a => a.Action == AccountAction.ADD || a.Action == AccountAction.EDIT))
                {
                    if (m_datalayer.AddOrEditItem(account) == false)
                    {
                        m_logger.LogError($"Failed to AddorRemove account {account.Name}.");
                    }
                }
                //now pesist the data
                m_datalayer.CommitData();
                m_modified = false;
                UpdateDisplayState();

                if (string.IsNullOrEmpty(m_password))
                {
                    var passwordDlg = new PasswordConfirm();
                    if (passwordDlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    m_password = passwordDlg.EnteredPassword;
                }

                await PasswordFileEncrypter.StringEncrypt(m_datalayer.ConnectionString, _encryptedFileName, m_password);
            }
            catch (Exception ex)
            {
                m_logger.LogError(ex.Message);
                MessageBox.Show("Load Database Failed", $"{ex.Message}");
            }
            finally
            {
                Cursor.Current = previous;
            }
        }
コード例 #2
0
        /// <summary>
        /// reload the account data from the database
        /// </summary>
        private async Task LoadData()
        {
            try
            {
                if (File.Exists(_directLoadFileName))
                {
                    m_datalayer.ConnectionString = File.ReadAllText(_directLoadFileName);
                }
                else
                {
                    var passwordDlg = new Password();
                    if (passwordDlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    m_password = passwordDlg.EnteredPassword;

                    m_datalayer.ConnectionString = await PasswordFileEncrypter.FileDecrypt(_encryptedFileName, m_password);
                }

                m_accountData.Clear();
                m_accountData.AddRange(m_datalayer.LoadAccountData().ToList());
                PopulateDisplayedList(m_accountData);

                passwordDataSource.DataSource = m_displayedaccountData;
                dataGridView.DataSource       = passwordDataSource;

                //dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
                dataGridView.AutoResizeColumns();
                dataGridView.AutoResizeRows();

                UpdateDisplayState();
                m_loaded = true;
            }
            catch (Exception ex)
            {
                m_logger.LogError(ex.Message);
                MessageBox.Show("Load Database Failed", $"{ex.Message}");
            }
        }