Пример #1
0
        public static void Create_database(string file_path)
        {
            SQLiteConnection connection = new SQLiteConnection(string.Format("DataSource={0}", file_path));

            connection.Open();

            // Create registries table
            SQLiteCommand registries_command = new SQLiteCommand(connection)
            {
                CommandText = "CREATE TABLE IF NOT EXISTS registries (id INTEGER PRIMARY KEY AUTOINCREMENT, date TEXT, category TEXT, type TEXT, amount REAL, description TEXT, currency TEXT);"
            };

            registries_command.ExecuteNonQuery();
            // Create categories table
            SQLiteCommand categories_command = new SQLiteCommand(connection)
            {
                CommandText = "CREATE TABLE IF NOT EXISTS categories (id INTEGER PRIMARY KEY AUTOINCREMENT, category TEXT);"
            };

            categories_command.ExecuteNonQuery();
            // Create categories table
            SQLiteCommand currencies_command = new SQLiteCommand(connection)
            {
                CommandText = "CREATE TABLE IF NOT EXISTS currencies (id INTEGER PRIMARY KEY AUTOINCREMENT, currency TEXT, vs_usd_rate REAL);"
            };

            currencies_command.ExecuteNonQuery();
            connection.Close();
            DatabaseHandler.Add_currency(file_path, "USD", 1);
        }
        private void Add_new_currency(object sender, RoutedEventArgs e)
        {
            string currency_name = AddCurrencyDialogCurrencyNameBox.Text;

            if (DatabaseHandler.Sanitize_string(currency_name))
            {
                if (DatabaseHandler.Currency_exists(GlobalVariables.temporary_file_path, currency_name) != true)
                {
                    double vs_usd_rate;
                    try
                    {
                        vs_usd_rate = Convert.ToDouble(AddCurrencyDialogCurrencyRateBox.Text);
                    }
                    catch
                    {
                        return;
                    }
                    if (vs_usd_rate > 0)
                    {
                        DatabaseHandler.Add_currency(GlobalVariables.temporary_file_path, currency_name, vs_usd_rate);
                        this.correcly_created = true;
                        this.Close();
                    }
                    else
                    {
                        InvalidInputDialog invalid_input_dialog = new InvalidInputDialog();
                        invalid_input_dialog.Set_msg("The Currency rate can't be negative");
                        invalid_input_dialog.ShowDialog();
                    }
                }
            }
            else
            {
                InvalidInputDialog invalid_input_dialog = new InvalidInputDialog();
                invalid_input_dialog.Set_msg("Are you using any ilegal chars ('!@#$%^&*()_+=,./\";:[]{}\\|)?");
                invalid_input_dialog.ShowDialog();
            }
        }