public void ChangeAddPassword()
        {
            var newPassword = new PasswordInfo
            {
                Website    = textBox.Text,
                Categoty   = GetCategory(),
                Username   = textBox2.Text,
                Email      = comboBox2.Text,
                Password   = textBox3.Text,
                UpdateDate = DateTime.Now.ToString("dd.MM.yyyy"),
                Note       = textBox4.Text
            };

            if (editPasswordInfo != null)
            {
                var index = MainWindow.Passwords.IndexOf(editPasswordInfo);
                // Change date if password changed
                if (newPassword.Password == MainWindow.Passwords[index].Password)
                {
                    newPassword.UpdateDate = MainWindow.Passwords[index].UpdateDate;
                }
                newPassword.ID = MainWindow.Passwords[index].ID;
                MainWindow.Passwords[index] = newPassword;
                mainWindow.textBlock.Text   = $"{MainWindow.Passwords[index].Website} data has been changed";
            }
            else
            {
                newPassword.ID = GetNewId();
                MainWindow.Passwords.Add(newPassword);
                mainWindow.textBlock.Text = $"{newPassword.Website} password has been added";
            }
            ParseTxt.WritePasswords(MainWindow.Passwords);
            mainWindow.UpdateListView();
            this.Close();
        }
Exemple #2
0
 private void RemoveItem(object sender, RoutedEventArgs e)
 {
     if (currentID != 0)
     {
         MessageBoxResult dialogResult = MessageBox.Show("Are you sure you want to remove this password?", "Delete password", MessageBoxButton.YesNo, MessageBoxImage.Question);
         if (dialogResult == MessageBoxResult.Yes)
         {
             PasswordInfo removePasswordInfo = Passwords.First(x => x.ID == currentID);
             textBlock.Text = $"{removePasswordInfo.Website} password has been deleted";
             Passwords.Remove(removePasswordInfo);
             ParseTxt.WritePasswords(Passwords);
             UpdateListView();
         }
     }
 }