Beispiel #1
0
 /// <summary>Initializes a new instance of the <see cref="ShipModel"/> class.</summary>
 /// <param name="id">The id.</param>
 /// <param name="name">The name.</param>
 /// <param name="type">The type.</param>
 /// <param name="x">The x.</param>
 /// <param name="y">The y.</param>
 public ShipModel(int id, string name, ShipTypeModel type, int x, int y)
 {
     this.Y = y;
     this.X = x;
     this.Type = type;
     this.Name = name;
     this.ID = id;
 }
        /// <summary></summary>
        /// <returns>The <see cref="List"/>.</returns>
        public List<ShipModel> GetAllShips()
        {
            List<ShipModel> ships = new List<ShipModel>();
            ShipModel shipModel = null;

            string query = "select s.*, st.* from Ship s join shiptype st on (s.shiptypetype = st.type) ";
            OracleCommand command = new OracleCommand(query, DatabaseSettings.Connection);

            OracleDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                ShipTypeModel.ShipTypeEnum shipType;
                ShipTypeModel.ShipTypeEnum.TryParse(reader[2].ToString(), true, out shipType);
                ShipTypeModel shipTypeModel = new ShipTypeModel(shipType, Convert.ToInt32(reader[6]), Convert.ToInt32(reader[7]));
                shipModel = new ShipModel(Convert.ToInt32(reader[0]), reader[1].ToString(), shipTypeModel, Convert.ToInt32(reader[3]), Convert.ToInt32(reader[4]));
                ships.Add(shipModel);
            }

            return ships;
        }
        /// <summary>The get ship by id.</summary>
        /// <param name="id">The id.</param>
        /// <returns>The <see cref="ShipModel"/>.</returns>
        public ShipModel GetShipById(int id)
        {
            ShipModel shipModel = null;

            string query = string.Format("select s.*, st.* from Ship s join shiptype st on (s.shiptypetype = st.type) where id = {0}", id);
                OracleCommand command = new OracleCommand(query, DatabaseSettings.Connection);

                    OracleDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        ShipTypeModel.ShipTypeEnum shipType;
                        ShipTypeModel.ShipTypeEnum.TryParse(reader[2].ToString(), true, out shipType);
                        ShipTypeModel shipTypeModel = new ShipTypeModel(shipType, Convert.ToInt32(reader[6]), Convert.ToInt32(reader[7]));
                        shipModel = new ShipModel(Convert.ToInt32(reader[0]), reader[1].ToString(), shipTypeModel, Convert.ToInt32(reader[3]), Convert.ToInt32(reader[4]));
                    }

            return shipModel;
        }