Beispiel #1
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            var NewPasswordCollection = new ObservableCollection <Passwordclass>();
            var PasswordModel         = new Passwordclass();
            var PasswordXml           = new PasswordsXml();

            NewPasswordCollection = PasswordXml.LoadDataFromXml();

            if (this.newName.Text.ToString() == String.Empty || this.newCategory.Text.ToString() == String.Empty)
            {
                MessageBox.Show("Żadne pole nie może być puste!...");
            }
            else
            {
                bool IfExist = PasswordModel.SearchDataInCollection(NewPasswordCollection, this.newName.Text.ToString(), this.newCategory.Text.ToString());

                if (IfExist == true)
                {
                    MessageBox.Show("Przykro mi, takie hasło jest już w bazie...");
                }
                else
                {
                    int lastId = PasswordModel.GetLastIdIndexValue(NewPasswordCollection) + 1;
                    PasswordXml.AddDataToXml(lastId, this.newName.Text.ToString(), this.newCategory.Text.ToString(), this.newLevel.Text.ToString());
                    PasswordModel.Id       = lastId;
                    PasswordModel.Category = this.newCategory.Text.ToString();
                    PasswordModel.Name     = this.newName.Text.ToString();
                    PasswordModel.Level    = this.newLevel.Text.ToString();

                    NewPasswordCollection.Add(PasswordModel);
                    MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                    mainWindow.PasswordCollection = NewPasswordCollection;
                    mainWindow.UpdateListView(mainWindow.PasswordCollection);
                    // this.Close();
                    //MessageBox.Show("Dodano nowe hasło!"); - optionally
                }
            }
        }
Beispiel #2
0
        private void FindButton_Click(object sender, RoutedEventArgs e)
        {
            if ((NameState == true && this.NameTextBox.Text == String.Empty) ||
                (CategoryState == true && this.CategoryTextBox.Text == String.Empty))
            {
                MessageBox.Show("Uzupełnij pola po których chcesz szukać!");
            }
            else
            {
                PasswordsXml newPasswordXml = new PasswordsXml();
                ObservableCollection <Passwordclass> FindedCollection = new ObservableCollection <Passwordclass>();
                List <string> ListOFParameters = new List <string>();

                if (NameState == true)
                {
                    ListOFParameters.Add(this.NameTextBox.Text);
                    ListOFParameters.Add("nazwa");
                }

                if (CategoryState == true)
                {
                    ListOFParameters.Add(this.CategoryTextBox.Text);
                    ListOFParameters.Add("kategoria");
                }

                if (LevelState == true)
                {
                    ListOFParameters.Add(this.LevelTextBox.Text.ToString());
                    ListOFParameters.Add("poziom");
                }

                if (ListOFParameters.Count == 2)
                {
                    FindedCollection = newPasswordXml.LookForDataInXml(ListOFParameters[0], ListOFParameters[1]);
                }

                else if (ListOFParameters.Count == 4)
                {
                    FindedCollection = newPasswordXml.LookForDataInXml(ListOFParameters[0], ListOFParameters[1],
                                                                       ListOFParameters[2], ListOFParameters[3]);
                }

                else if (ListOFParameters.Count == 6)
                {
                    FindedCollection = newPasswordXml.LookForDataInXml(ListOFParameters[0], ListOFParameters[1],
                                                                       ListOFParameters[2], ListOFParameters[3], ListOFParameters[4], ListOFParameters[5]);
                }

                if (FindedCollection.Count > 0)
                {
                    MainWindow mainWindow = (MainWindow)Application.Current.MainWindow;
                    mainWindow.PasswordCollection = FindedCollection;
                    mainWindow.UpdateListView(mainWindow.PasswordCollection);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Nie ma takiego rejestru w bazie...");
                }
            }
        }