Ejemplo n.º 1
0
 public AchievementCategory(int id, string location, string name, Function function, int functionValue, AchievementCategory parent = null)
 {
     ID            = id;
     Location      = location;
     Name          = name;
     Parent        = parent;
     Function      = function;
     FunctionValue = functionValue;
     Achievements  = new List <Achievement>();
 }
Ejemplo n.º 2
0
        private static void GetAllCategories(SqliteConnection connection)
        {
            var selectCmd = connection.CreateCommand();

            selectCmd.CommandText = @"WITH CTE_AchievementCategory(ID, ParentID, Location, LocationPath) AS (
                                    SELECT ID, ParentID, Location, substr('0' || Location, -2, 2)
                                    FROM AchievementCategory AC
                                    WHERE ParentID IS NULL
                                    UNION ALL
                                    SELECT AC.ID, AC.ParentID, AC.Location, CTEAC.LocationPath || '.' || substr('0' || AC.Location, -2, 2)
                                    FROM AchievementCategory AC INNER JOIN CTE_AchievementCategory CTEAC
                                    ON CTEAC.ID = AC.ParentID
                                    )
                                    SELECT
                                        AC.*, F.*, CTEAC.LocationPath
                                    FROM
                                        CTE_AchievementCategory CTEAC
                                        left join AchievementCategory AC
                                        on CTEAC.ID = AC.ID
                                        left join AchievementCategory P
                                        on AC.ParentID = P.ID
                                        left join Function F
                                        on AC.FunctionID = F.ID
                                    ORDER BY CTEAC.LocationPath";

            using (var reader = selectCmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    var category = new AchievementCategory(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), new Function(reader.GetInt32(6), reader.GetString(7)), reader.IsDBNull(5) ? 0 : reader.GetInt32(5), reader.IsDBNull(3) ? null : Categories.Find(c => c.ID == reader.GetInt32(3)));
                    Categories.Add(category);
                    var location = reader.GetString(8);
                    var padding  = location.Length / 3;
                    var spacing  = "";
                    for (int i = 0; i < padding; i++)
                    {
                        spacing += "-";
                    }
                    Console.WriteLine(spacing + category);
                }
            }
        }