Esempio n. 1
0
        public List<characteristic> GetCharacteristics(uint id_type = 0)
        {
            List<characteristic> new_characteristics = new List<characteristic>();

            string query_characteristics = @"SELECT 
                characteristic.id_characteristic as id_characteristic,
                characteristic.name AS name, 
                characteristic.description AS description, 
                characteristic.abreviation AS abreviation, 
                characteristic.characteristic_type AS type
                FROM dnd.characteristic";
            if (id_type > 0)
                query_characteristics += " where characteristic_type = " + id_type;
            query_characteristics += ";";

            List<uint> characteristic_type_id = new List<uint>();

            if (OpenConnection())
            {
                //Get the characteristics values and modifiers of this template (summing all existing ones)
                using (MySqlCommand cmd_cha = new MySqlCommand(query_characteristics, connection))
                {
                    MySqlDataReader dataReader_cha = cmd_cha.ExecuteReader();

                    while (dataReader_cha.Read() && !dataReader_cha.IsDBNull(0))
                    {
                        var nc = new characteristic()
                        {
                            uid = dataReader_cha.GetUInt16(0),
                            name = dataReader_cha.IsDBNull(1) ? null : dataReader_cha.GetString(1),
                            description = dataReader_cha.IsDBNull(2) ? null : dataReader_cha.GetString(2),
                            abreviation = dataReader_cha.IsDBNull(3) ? null : dataReader_cha.GetString(3)
                        };
                        new_characteristics.Add(nc);
                        characteristic_type_id.Add(dataReader_cha.GetUInt32(4));
                    }

                    dataReader_cha.Close();
                }
                CloseConnection();

                var j = 0;
                foreach(uint i in characteristic_type_id)
                {
                    new_characteristics[j].type = GetCharacteristicType(i);
                    ++j;
                }
            }

            return new_characteristics;

        }
Esempio n. 2
0
        public List<characteristic> GetTemplateCharacteristics(uint id_template, uint id_type=0)
        {
            List<characteristic> new_characteristic = new List<characteristic>();

            string query_characteristics = @"SELECT 
                characteristic.id_characteristic AS uid, 
                characteristic.name AS name, 
                characteristic.description AS description, 
                characteristic.abreviation AS abreviation, 
                SUM(template_has_characteristic.value) AS base, 
                SUM(template_has_modifier.modifier) AS modifier,
                characteristic.characteristic_type AS type
                FROM characteristic 
                LEFT JOIN template_has_characteristic 
                ON characteristic.id_characteristic = template_has_characteristic.characteristic 
                LEFT JOIN template_has_modifier 
                ON characteristic.id_characteristic = template_has_modifier.characteristic 
                WHERE template_has_characteristic.template = " + id_template;

            if (id_type > 0)
                query_characteristics += " AND characteristic.characteristic_type =" + id_type;
            query_characteristics += " GROUP BY characteristic.id_characteristic; ";

            List<uint> type = new List<uint>();

            if (OpenConnection())
            {
                //Get the characteristics values and modifiers of this template (summing all existing ones)
                using (MySqlCommand cmd_cha = new MySqlCommand(query_characteristics, connection))
                {
                    MySqlDataReader dataReader_cha = cmd_cha.ExecuteReader();
                    while (dataReader_cha.Read() && !dataReader_cha.IsDBNull(0))
                    {
                        var c = new characteristic()
                        {
                            uid = dataReader_cha.GetUInt32(0),
                            name = dataReader_cha.IsDBNull(1) ? null : dataReader_cha.GetString(1),
                            description = dataReader_cha.IsDBNull(2) ? null : dataReader_cha.GetString(2),
                            abreviation = dataReader_cha.IsDBNull(3) ? null : dataReader_cha.GetString(3),

                            value = dataReader_cha.GetInt32(4),
                            modifier = dataReader_cha.IsDBNull(5) ? 0 : dataReader_cha.GetInt32(5)
                        };
                        new_characteristic.Add(c);
                        type.Add(dataReader_cha.GetUInt32(6));
                    }
                    dataReader_cha.Close();
                }
                CloseConnection();
            }

            var j = 0;
            foreach (uint i in type)
            {
                new_characteristic[j].type = GetCharacteristicType(i);
                ++j;
            }

            return new_characteristic;
               
        }
Esempio n. 3
0
        public characteristic GetCharacteristic(uint id_characteristic)
        {
            characteristic new_characteristic = new characteristic();

            string query_characteristics = @"SELECT 
                characteristic.name AS name, 
                characteristic.description AS description, 
                characteristic.abreviation AS abreviation, 
                characteristic.characteristic_type AS type 
                FROM dnd.characteristic
                WHERE characteristic.id_characteristic = " + id_characteristic + ";";

            uint characteristic_type_id = 0;

            if (OpenConnection())
            {
                //Get the characteristics values and modifiers of this template (summing all existing ones)
                using (MySqlCommand cmd_cha = new MySqlCommand(query_characteristics, connection))
                {
                    MySqlDataReader dataReader_cha = cmd_cha.ExecuteReader();

                    while (dataReader_cha.Read() && !dataReader_cha.IsDBNull(0))
                    {
                        new_characteristic = new characteristic()
                        {
                            uid = id_characteristic,
                            name = dataReader_cha.IsDBNull(0) ? null : dataReader_cha.GetString(0),
                            description = dataReader_cha.IsDBNull(1) ? null : dataReader_cha.GetString(1),
                            abreviation = dataReader_cha.IsDBNull(2) ? null : dataReader_cha.GetString(2)
                        };
                        characteristic_type_id = dataReader_cha.GetUInt32(3);
                    }

                    dataReader_cha.Close();
                }
                CloseConnection();

                if (characteristic_type_id > 0)
                    new_characteristic.type = GetCharacteristicType(characteristic_type_id);
            }

            return new_characteristic;

        }