Ejemplo n.º 1
0
        /// <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;
        }
Ejemplo n.º 2
0
        /// <summary></summary>
        /// <param name="description">The description.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="startDate">The start date.</param>
        /// <param name="endDate">The end date.</param>
        /// <param name="ship">The ship.</param>
        /// <returns>The <see cref="MissionModel"/>.</returns>
        public MissionModel CreateHopeMission(string description, int x, int y, DateTime startDate, DateTime endDate, ShipModel ship)
        {
            MissionModel missionModel = new MissionModel(0, ship.ID, description, startDate, x, y, MissionModel.MissionType.Hope, endDate);

            try
            {
                string query =
                    string.Format(
                        "INSERT INTO MISSION (ID, SHIPID, STARTDATE, DISCRIPTION, X, Y, ACTIVE, MISSIONTYPE, APPROVED, ENDDATE) "
                        + "VALUES (seq_mission.nextval, '{0}', TO_TIMESTAMP('{1} 11:39:02.070000000', 'YYYY-MM-DD HH24:MI:SS.FF'), '{2}', '{3}', '{4}', '0', 'HOPE', '0', TO_DATE('{5} 11:39:31', 'YYYY-MM-DD HH24:MI:SS'))",
                        missionModel.ShipId, missionModel.StartDate.ToShortDateString(), missionModel.Description, missionModel.X, missionModel.Y, missionModel.EndDate.ToShortDateString());

                OracleCommand command = new OracleCommand(query, DatabaseSettings.Connection);
                command.ExecuteNonQuery();

                DatabaseSettings.Commit();
                return missionModel;
            }
            catch (Exception)
            {
                return null;
            }
        }
Ejemplo n.º 3
0
        /// <summary></summary>
        /// <param name="AvailableCrew">The available crew.</param>
        /// <param name="ship">The ship.</param>
        /// <returns>The <see cref="bool"/>.</returns>
        public bool ManShip(List<CrewMemberModel> AvailableCrew, ShipModel ship )
        {
            List<CrewMemberModel> shipsCrew = new List<CrewMemberModel>();

            // First search for a captain
            foreach (CrewMemberModel crewMemberModel in AvailableCrew)
            {
                if (crewMemberModel.Job == CrewMemberModel.JobEnum.Kapitein)
                {
                    shipsCrew.Add(crewMemberModel);
                    break;
                }
            }

            int i = 0;
            foreach (CrewMemberModel crewMemberModel in AvailableCrew)
                {
                    if (i < ship.Type.MaxCrew)
                    {
                        if (crewMemberModel.Job == CrewMemberModel.JobEnum.Bioloog
                                || crewMemberModel.Job == CrewMemberModel.JobEnum.Politie)
                        {
                             shipsCrew.Add(crewMemberModel);
                            i++;
                        }
                    }
                }

                foreach (CrewMemberModel crewMemberModel in shipsCrew)
                {
                    string query = string.Format(
                        "insert into crewmember_ship(shipID,crewmemberID) values({0},{1})",
                        ship.ID,
                        crewMemberModel.Id);
                    OracleCommand command = new OracleCommand(query, DatabaseSettings.Connection);
                    command.ExecuteNonQuery();
                }

            return true;
        }
Ejemplo n.º 4
0
        /// <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;
        }