Exemplo n.º 1
0
/// <summary>
/// Reads the values from an <see cref="IDataReader"/> and assigns the read values to this
/// object's properties. Unlike ReadValues(), this method not only doesn't require
/// all values to be in the <see cref="IDataReader"/>, but also does not require the values in
/// the <see cref="IDataReader"/> to be a defined field for the table this class represents.
/// Because of this, you need to be careful when using this method because values
/// can easily be skipped without any indication.
/// </summary>
/// <param name="source">The object to add the extension method to.</param>
/// <param name="dataRecord">The <see cref="IDataReader"/> to read the values from. Must already be ready to be read from.</param>
        public static void TryReadValues(this MapSpawnTable source, System.Data.IDataRecord dataRecord)
        {
            for (int i = 0; i < dataRecord.FieldCount; i++)
            {
                switch (dataRecord.GetName(i))
                {
                case "amount":
                    source.Amount = (System.Byte)(System.Byte) dataRecord.GetByte(i);
                    break;


                case "character_template_id":
                    source.CharacterTemplateID = (DemoGame.CharacterTemplateID)(DemoGame.CharacterTemplateID) dataRecord.GetUInt16(i);
                    break;


                case "direction_id":
                    source.DirectionId = (NetGore.Direction)(NetGore.Direction) dataRecord.GetInt16(i);
                    break;


                case "height":
                    source.Height = (System.Nullable <System.UInt16>)(System.Nullable <System.UInt16>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i));
                    break;


                case "id":
                    source.ID = (DemoGame.MapSpawnValuesID)(DemoGame.MapSpawnValuesID) dataRecord.GetInt32(i);
                    break;


                case "map_id":
                    source.MapID = (NetGore.World.MapID)(NetGore.World.MapID) dataRecord.GetUInt16(i);
                    break;


                case "respawn":
                    source.Respawn = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i);
                    break;


                case "width":
                    source.Width = (System.Nullable <System.UInt16>)(System.Nullable <System.UInt16>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i));
                    break;


                case "x":
                    source.X = (System.Nullable <System.UInt16>)(System.Nullable <System.UInt16>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i));
                    break;


                case "y":
                    source.Y = (System.Nullable <System.UInt16>)(System.Nullable <System.UInt16>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i));
                    break;
                }
            }
        }
Exemplo n.º 2
0
/// <summary>
/// Reads the values from an <see cref="IDataRecord"/> and assigns the read values to this
/// object's properties. The database column's name is used to as the key, so the value
/// will not be found if any aliases are used or not all columns were selected.
/// </summary>
/// <param name="source">The object to add the extension method to.</param>
/// <param name="dataRecord">The <see cref="IDataRecord"/> to read the values from. Must already be ready to be read from.</param>
        public static void ReadValues(this MapSpawnTable source, System.Data.IDataRecord dataRecord)
        {
            System.Int32 i;

            i = dataRecord.GetOrdinal("amount");

            source.Amount = (System.Byte)(System.Byte) dataRecord.GetByte(i);

            i = dataRecord.GetOrdinal("character_template_id");

            source.CharacterTemplateID = (DemoGame.CharacterTemplateID)(DemoGame.CharacterTemplateID) dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("direction_id");

            source.DirectionId = (NetGore.Direction)(NetGore.Direction) dataRecord.GetInt16(i);

            i = dataRecord.GetOrdinal("height");

            source.Height = (System.Nullable <System.UInt16>)(System.Nullable <System.UInt16>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i));

            i = dataRecord.GetOrdinal("id");

            source.ID = (DemoGame.MapSpawnValuesID)(DemoGame.MapSpawnValuesID) dataRecord.GetInt32(i);

            i = dataRecord.GetOrdinal("map_id");

            source.MapID = (NetGore.World.MapID)(NetGore.World.MapID) dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("respawn");

            source.Respawn = (System.UInt16)(System.UInt16) dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("width");

            source.Width = (System.Nullable <System.UInt16>)(System.Nullable <System.UInt16>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i));

            i = dataRecord.GetOrdinal("x");

            source.X = (System.Nullable <System.UInt16>)(System.Nullable <System.UInt16>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i));

            i = dataRecord.GetOrdinal("y");

            source.Y = (System.Nullable <System.UInt16>)(System.Nullable <System.UInt16>)(dataRecord.IsDBNull(i) ? (System.Nullable <System.UInt16>)null : dataRecord.GetUInt16(i));
        }
        /// <summary>
        /// Reads the values from an <see cref="IDataReader"/> and assigns the read values to this
        /// object's properties. Unlike ReadValues(), this method not only doesn't require
        /// all values to be in the <see cref="IDataReader"/>, but also does not require the values in
        /// the <see cref="IDataReader"/> to be a defined field for the table this class represents.
        /// Because of this, you need to be careful when using this method because values
        /// can easily be skipped without any indication.
        /// </summary>
        /// <param name="source">The object to add the extension method to.</param>
        /// <param name="dataRecord">The <see cref="IDataReader"/> to read the values from. Must already be ready to be read from.</param>
        public static void TryReadValues(this MapSpawnTable source, IDataRecord dataRecord)
        {
            for (var i = 0; i < dataRecord.FieldCount; i++)
            {
                switch (dataRecord.GetName(i))
                {
                case "amount":
                    source.Amount = dataRecord.GetByte(i);
                    break;

                case "character_template_id":
                    source.CharacterTemplateID = (CharacterTemplateID)dataRecord.GetUInt16(i);
                    break;

                case "height":
                    source.Height = (dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i));
                    break;

                case "id":
                    source.ID = (MapSpawnValuesID)dataRecord.GetInt32(i);
                    break;

                case "map_id":
                    source.MapID = (MapID)dataRecord.GetUInt16(i);
                    break;

                case "width":
                    source.Width = (dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i));
                    break;

                case "x":
                    source.X = (dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i));
                    break;

                case "y":
                    source.Y = (dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i));
                    break;
                }
            }
        }
        /// <summary>
        /// Reads the values from an <see cref="IDataRecord"/> and assigns the read values to this
        /// object's properties. The database column's name is used to as the key, so the value
        /// will not be found if any aliases are used or not all columns were selected.
        /// </summary>
        /// <param name="source">The object to add the extension method to.</param>
        /// <param name="dataRecord">The <see cref="IDataRecord"/> to read the values from. Must already be ready to be read from.</param>
        public static void ReadValues(this MapSpawnTable source, IDataRecord dataRecord)
        {
            Int32 i;

            i = dataRecord.GetOrdinal("amount");

            source.Amount = dataRecord.GetByte(i);

            i = dataRecord.GetOrdinal("character_template_id");

            source.CharacterTemplateID = (CharacterTemplateID)dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("height");

            source.Height = (dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i));

            i = dataRecord.GetOrdinal("id");

            source.ID = (MapSpawnValuesID)dataRecord.GetInt32(i);

            i = dataRecord.GetOrdinal("map_id");

            source.MapID = (MapID)dataRecord.GetUInt16(i);

            i = dataRecord.GetOrdinal("width");

            source.Width = (dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i));

            i = dataRecord.GetOrdinal("x");

            source.X = (dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i));

            i = dataRecord.GetOrdinal("y");

            source.Y = (dataRecord.IsDBNull(i) ? (ushort?)null : dataRecord.GetUInt16(i));
        }
        /// <summary>
        /// Handles the Click event of the <see cref="btnNew"/> control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void btnNew_Click(object sender, EventArgs e)
        {
            var map = Map;
            if (map == null)
                return;

            // Create new spawn
            var charID = CharacterTemplateManager.Instance.First().TemplateTable.ID;
            var value = new MapSpawnTable { MapID = map.ID, Amount = 1, CharacterTemplateID = charID };

            var q = DbControllerBase.GetInstance().GetQuery<InsertMapSpawnQuery>();
            q.Execute(value);

            // Update list
            lstSpawns.ReloadSpawns();
        }