예제 #1
0
        public static ShipEquipment Factory(int id, int hull, int ship)
        {
            ShipEquipment result = new ShipEquipment(
                id: id,
                hull: hull,
                ship: ship,
                count: 1
                );

            return(result);
        }
예제 #2
0
        public static ShipEquipment Factory(SQLiteDataReader reader)
        {
            ShipEquipment result = new ShipEquipment(
                id: Convert.ToInt32(reader["id"]),
                hull: Convert.ToInt32(reader["hull"]),
                ship: Convert.ToInt32(reader["ship"]),
                count: Convert.ToInt32(reader["count"])
                );

            return(result);
        }
예제 #3
0
        public static ShipEquipment Factory()
        {
            ShipEquipment result = new ShipEquipment(
                id: -1,
                hull: -1,
                ship: -1,
                count: 0
                );

            return(result);
        }
예제 #4
0
 /// <summary>
 /// Gets a summary count of the hulls embarked on a ship
 /// </summary>
 /// <param name="hullId"></param>
 /// <param name="shipId"></param>
 /// <returns></returns>
 public static ShipEquipment FetchByHullShip(int hullId, int shipId)
 {
     Datamodel.ShipEquipment e = null;
     if (Datamodel.ShipEquipment.FetchHullByShip(ref e, hullId, shipId))
     {
         return(new ShipEquipment(e));
     }
     else
     {
         return(null);
     }
 }
예제 #5
0
        /// <summary>
        /// Fetches a single row by ID.
        /// </summary>
        /// <param name="output"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool FetchById(ref ShipEquipment output, int id)
        {
            SQLiteDataReader reader = DBI.DoPreparedQuery(
                @"SELECT id, hull, ship, 0 AS count
				FROM ShipEquipment WHERE id = @id;"                ,
                new Tuple <string, object>("@id", id));

            if (reader != null && reader.Read())
            {
                output = ShipEquipment.Factory(reader);
                return(true);
            }
            return(false);
        }
예제 #6
0
        /// <summary>
        /// Creates a new piece of equipment embarked on a ship
        /// </summary>
        /// <param name="output"></param>
        /// <param name="hull"></param>
        /// <param name="ship"></param>
        /// <returns></returns>
        public static bool Create(ref ShipEquipment output, int hull,
                                  int ship)
        {
            int result = DBI.DoPreparedAction(
                @"INSERT INTO ShipEquipment (hull, ship) 
				VALUES (@hull, @ship);"                ,
                new Tuple <string, object>("@hull", hull),
                new Tuple <string, object>("@ship", ship));

            if (result == 1)
            {
                return(ShipEquipment.FetchById(ref output, DBI.LastInsertRowId));
            }
            return(false);
        }
예제 #7
0
        /// <summary>
        /// Fetches the count of a certain hull on a ship
        /// </summary>
        /// <param name="output"></param>
        /// <param name="hullId"></param>
        /// <param name="shipId"></param>
        /// <returns></returns>
        public static bool FetchHullByShip(ref ShipEquipment output, int hullId,
                                           int shipId)
        {
            SQLiteDataReader reader = DBI.DoPreparedQuery(
                @"SELECT id, hull, ship, COUNT(id) AS count
				FROM ShipEquipment
				WHERE ship = @ship AND hull = @hull
				GROUP BY hull;"                ,
                new Tuple <string, object>("@ship", shipId),
                new Tuple <string, object>("@hull", hullId));

            if (reader != null && reader.Read())
            {
                output = ShipEquipment.Factory(reader);
                return(true);
            }
            return(false);
        }
예제 #8
0
        AddEquipment(int shipId, int hullId)
        {
            Datamodel.ShipEquipment e = null;
            bool success
                = Datamodel.ShipEquipment.Create(ref e, hullId, shipId);

            if (success)
            {
                logger.Info($"Added new equipment {hullId} to ship {shipId}");
            }
            else
            {
                logger.Error($"Failed to add equipment to ship {shipId}");
            }

            return(new ANWI.Messaging.ConfirmUpdate(
                       typeof(ANWI.Messaging.Request), success, shipId));
        }
예제 #9
0
        /// <summary>
        /// Updates a row
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool Store(ShipEquipment input)
        {
            int result = DBI.DoPreparedAction(
                @"UPDATE ShipEquipment
				SET hull = @hull, ship = @ship
				WHERE id = @id;"                ,
                new Tuple <string, object>("@hull", input.hull),
                new Tuple <string, object>("@ship", input.ship),
                new Tuple <string, object>("@id", input.id));

            if (result == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #10
0
        /// <summary>
        /// Selects all hulls embarked on a given ship
        /// </summary>
        /// <param name="output"></param>
        /// <param name="shipId"></param>
        /// <returns></returns>
        public static bool FetchAllByShip(ref List <ShipEquipment> output,
                                          int shipId)
        {
            output = new List <ShipEquipment>();

            SQLiteDataReader reader = DBI.DoPreparedQuery(
                @"SELECT 0 AS id, hull, ship, COUNT(id) AS count
				FROM ShipEquipment
				WHERE ship = @ship
				GROUP BY hull;"                ,
                new Tuple <string, object>("@ship", shipId));

            while (reader != null && reader.Read())
            {
                output.Add(ShipEquipment.Factory(reader));
            }

            return(true);
        }
예제 #11
0
 private ShipEquipment(Datamodel.ShipEquipment e)
 {
     count   = e.count;
     _hullId = e.hull;
     shipId  = e.ship;
 }