private void Generate_Click(object sender, RoutedEventArgs e)
 {
     btnDown(sender, (MouseEventArgs)e);
     //chars.Clear();
     using (var db = new AccountsDbContext())
     {
         try
         {
             AccountModel acc = (AccountModel)data.Items[rowIndex];
             acc.Password = generatePassword();
             db.Passwords.Update(acc);
         }
         catch (Exception ex)
         {
             AccountModel acc = new AccountModel()
             {
                 Notes    = "",
                 Website  = "",
                 Password = generatePassword()
             };
             db.Passwords.Update(acc);
             db.SaveChanges();
         }
         data.ItemsSource = db.Passwords.ToList();
     }
 }
 public void Refresh_Click(object sender, RoutedEventArgs e)
 {
     using (var db = new AccountsDbContext())
     {
         data.ItemsSource = db.Passwords.ToList();
     }
 }
        private void searchText_Changed(object sender, TextChangedEventArgs e)
        {
            TextBox search = sender as TextBox;

            using (var db = new AccountsDbContext())
            {
                data.ItemsSource = db.Passwords.Where(w => w.Website.ToLower().Contains(search.Text.ToLower())).ToList();
            }
        }
 private void CopyToClipboard(object sender, RoutedEventArgs e)
 {
     btnDown(sender, (MouseEventArgs)e);
     using (var db = new AccountsDbContext())
     {
         try
         {
             var s = (AccountModel)data.Items[rowIndex];
             Clipboard.SetText(s.Password);
         }
         catch (Exception ex)
         {
             Clipboard.SetText("");
         }
     }
 }
        //List<char> s = new List<char> { };
        public MainWindow()
        {
            InitializeComponent();
            //((INotifyCollectionChanged)lvSpecials.ItemsSource).CollectionChanged += new NotifyCollectionChangedEventHandler(lvChange);
            try
            {
                using (var db = new AccountsDbContext())
                {
                    data.ItemsSource = db.Passwords.ToList();
                }
                //int rowi = data.Items.IndexOf(data.Items.Count - 1);
                //DataGridRow row = (DataGridRow)data.Items[3];
                //row.Background = new SolidColorBrush(Color.FromRgb(255, 0, 0));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Connection Error", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

            //CheckBox all = new CheckBox();
            all.Content   = "All";
            all.IsChecked = true;

            all.Checked   += new RoutedEventHandler(CheckAll);
            all.Unchecked += new RoutedEventHandler(UncheckAll);

            //Create the checkboxes for the specials list
            foreach (var c in specials)
            {
                ListViewItem item = new ListViewItem();

                item.Content    = c.Key + "\t" + c.Value;
                item.IsSelected = true;

                chars.Add(c.Key);
                cbList.Add(item);
            }
            lvSpecials.ItemsSource = cbList;
        }
        private void DeleteAccount(object sender, RoutedEventArgs e)
        {
            btnDown(sender, (MouseEventArgs)e);
            try
            {
                MessageBoxResult res = MessageBox.Show("Are you sure you want to delete Id " + ((AccountModel)data.Items[rowIndex]).Id, "Deleting Account", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                if (res == MessageBoxResult.Yes)
                {
                    using (var db = new AccountsDbContext())
                    {
                        var s = (AccountModel)data.Items[rowIndex];
                        db.Passwords.Remove(s);
                        db.SaveChanges();

                        data.ItemsSource = db.Passwords.ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: account does not exist in database", "Account Error", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        private void Save_Click(object sender, MouseEventArgs e)
        {
            using (var db = new AccountsDbContext())
            {
                try
                {
                    AccountModel acc = (AccountModel)data.Items[rowIndex];
                    //acc.Id = indexDb;
                    //acc.Notes = notes;
                    //acc.Website = website;
                    //acc.Password = password;
                    db.Passwords.Update(acc);
                    //db.Entry(acc).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    //db.Passwords.Add(new AccountModel());
                }

                data.ItemsSource = db.Passwords.ToList();
            }
        }