Ejemplo n.º 1
0
        public static List <IArmor> ReadItems()
        {
            using (connection = new SQLiteConnection(ConnectionString))
            {
                connection.Open();
                var armors    = new List <IArmor>();
                var myCommand = new SQLiteCommand("SELECT * FROM Armors", connection);
                var reader    = myCommand.ExecuteReader();
                while (reader.Read())
                {
                    var armor = ArmorFactory.CreateArmor();
                    armor.Id                  = (uint)reader.GetInt32(0);
                    armor.Name                = reader.GetString(1);
                    armor.Type                = (ArmorType)reader.GetInt32(2);
                    armor.Price               = (ulong)reader.GetInt32(3);
                    armor.BaseArmor           = (byte)reader.GetInt32(4);
                    armor.MaxAgility          = (byte)reader.GetInt32(5);
                    armor.StrengthCap         = (byte)reader.GetInt32(6);
                    armor.StealthDisadvantage = reader.GetBoolean(7);
                    armor.Weight              = (byte)reader.GetInt32(8);
                    armors.Add(armor);
                }

                connection.Close();
                return(armors);
            }
        }
Ejemplo n.º 2
0
        public static IArmor ReadItem(uint id)
        {
            using (connection = new SQLiteConnection(ConnectionString))
            {
                connection.Open();
                IArmor armor     = null;
                var    query     = $@"
                    SELECT * 
                    FROM Armors 
                    WHERE Id = '{id}'";
                var    myCommand = new SQLiteCommand(query, connection);
                var    reader    = myCommand.ExecuteReader();
                while (reader.Read())
                {
                    armor                     = ArmorFactory.CreateArmor();
                    armor.Id                  = (uint)reader.GetInt32(0);
                    armor.Name                = reader.GetString(1);
                    armor.Type                = (ArmorType)reader.GetInt32(2);
                    armor.Price               = (ulong)reader.GetInt32(3);
                    armor.BaseArmor           = (byte)reader.GetInt32(4);
                    armor.MaxAgility          = (byte)reader.GetInt32(5);
                    armor.StrengthCap         = (byte)reader.GetInt32(6);
                    armor.StealthDisadvantage = reader.GetBoolean(7);
                    armor.Weight              = (byte)reader.GetInt32(8);
                }

                connection.Close();
                return(armor);
            }
        }