Ejemplo n.º 1
0
    //-- DATABASE METHODS

    public static void Load(bool defaultOnly)
    {
        // Reset color schemes
        ColorSchemes = new List <ColorSchemeObj> ();

        // Get color schemes
        if (Database.Connect() && Settings.Selected.Visualization != null && Settings.Selected.Visualization.ID > 0 &&
            Application.CanStreamedLevelBeLoaded(Settings.Selected.Visualization.BuildNumber))
        {
            // Database command
            SqliteCommand cmd = new SqliteCommand(Database.Connection);

            // Query statement
            string sql = "SELECT id,name,viz_id,colors FROM color_scheme WHERE viz_id = @Viz_ID " +
                         (defaultOnly ? "AND name = @Name " : "") +
                         "ORDER BY name ASC";
            cmd.CommandText = sql;

            // Add Parameters to statement
            cmd.Parameters.Add(new SqliteParameter("Viz_ID", Settings.Selected.Visualization.ID));
            if (defaultOnly)
            {
                cmd.Parameters.Add(new SqliteParameter("Name", Settings.Selected.Visualization.Name));
            }

            // Get sql results
            SqliteDataReader reader = cmd.ExecuteReader();

            // Read sql results
            while (reader.Read())
            {
                // Create color scheme object
                ColorSchemeObj obj = new ColorSchemeObj(reader.GetString(1));

                // Set values
                obj.ID            = reader.GetInt64(0);
                obj.Visualization = Visualization.GetVisualization(reader.GetInt64(2), false);
                obj.Colors        = GetColors(reader.GetString(3));

                // Add color scheme to colorSchemes array
                ColorSchemes.Add(obj);
            }

            // Close reader
            reader.Close();
            cmd.Dispose();

            // Close database connection
            Database.Close();
        }
    }