예제 #1
0
 private void Basic_search(object sender, RoutedEventArgs e)
 {
     if (this.Verify_category())
     {
         RegistrySearchCondition condition = new RegistrySearchCondition
         {
             Default_search = false,
             Category       = SearchCategoryButton.Content.ToString(),
             Currency       = "",
             Amount_from    = -1,
             Amount_to      = -1,
             Type           = "",
             From_date      = new DateTime(),
             To_date        = new DateTime(),
             In_description = ""
         };
         List <RegistryRow> results = DatabaseHandler.Get_registries(GlobalVariables.temporary_file_path, condition);
         if (results.Count() >= 1)
         {
             SearchResultsDialog results_dialog = new SearchResultsDialog();
             results_dialog.Set_rows(results);
             if (results_dialog.custom_show_dialog())
             {
                 GlobalVariables.registry_view.Set_rows();
             }
         }
         else
         {
             NoResultsDialog no_results_dialog = new NoResultsDialog();
             no_results_dialog.ShowDialog();
         }
     }
 }
 private void Search_button(object sender, RoutedEventArgs e)
 {
     if (this.Verify_search())
     {
         RegistrySearchCondition condition = new RegistrySearchCondition
         {
             Type           = this.Type_,
             In_description = this.Description,
             Category       = this.Category,
             Currency       = this.Currency,
             To_date        = this.Date_to,
             From_date      = this.Date_from,
             Amount_from    = this.Amount_from,
             Amount_to      = this.Amount_to
         };
         List <RegistryRow> search_results = DatabaseHandler.Get_registries(GlobalVariables.temporary_file_path, condition);
         if (search_results.Count() >= 1)
         {
             SearchResultsDialog results_dialog = new SearchResultsDialog();
             results_dialog.Set_rows(search_results);
             if (results_dialog.custom_show_dialog())
             {
                 this.success = true;
             }
         }
         else
         {
             NoResultsDialog no_results_dialog = new NoResultsDialog();
             no_results_dialog.ShowDialog();
         }
     }
 }
예제 #3
0
        public static List <RegistryRow> Get_registries(string file_path, RegistrySearchCondition condition)
        {
            SQLiteConnection connection = new SQLiteConnection(string.Format("DataSource={0}", file_path));

            connection.Open();
            SQLiteCommand command = new SQLiteCommand(connection)
            {
                CommandText = "SELECT * FROM registries"
            };
            SQLiteDataReader   results_reader = command.ExecuteReader();
            List <RegistryRow> rows           = new List <RegistryRow>();

            while (results_reader.Read())
            {
                RegistryRow row = new RegistryRow
                {
                    ID          = Convert.ToInt32(results_reader["id"]),
                    Amount      = Convert.ToDouble(results_reader["amount"]),
                    Date        = Convert.ToDateTime(results_reader["date"]),
                    Category    = Convert.ToString(results_reader["category"]),
                    Type_       = Convert.ToString(results_reader["type"]),
                    Description = Convert.ToString(results_reader["description"]),
                    Currency    = Convert.ToString(results_reader["currency"])
                };
                if (condition.Default_search)
                {
                    if (row.Type_ == "outcome")
                    {
                        row.Amount *= -1;
                    }
                    rows.Add(row);
                }
                else
                {
                    if (condition.Check_condition(row.Date, row.Category, row.Type_, row.Amount, row.Description, row.Currency))
                    {
                        if (row.Type_ == "outcome")
                        {
                            row.Amount *= -1;
                        }
                        rows.Add(row);
                    }
                }
            }
            results_reader.Close();
            connection.Close();
            return(rows);
        }