示例#1
0
        private Hull(Datamodel.Hull h)
        {
            id       = h.id;
            name     = h.series;
            symbol   = h.symbol;
            ordering = h.ordering;

            _roleId = h.role;
            Datamodel.HullRole hr = null;
            if (!Datamodel.HullRole.FetchById(ref hr, _roleId))
            {
                throw new ArgumentException(
                          "Hull does not have valid role ID");
            }
            role = hr.name;

            _vendorId = h.vendor;
            Datamodel.HullVendor hv = null;
            if (!Datamodel.HullVendor.FetchById(ref hv, _vendorId))
            {
                throw new ArgumentException(
                          "Hull does not have valid vendor ID");
            }
            vendor = hv.name;
        }
示例#2
0
        public static HullRole Factory(SQLiteDataReader reader)
        {
            HullRole result = new HullRole(
                id: Convert.ToInt32(reader["id"]),
                name: (string)reader["name"],
                icon: (string)reader["icon"]
                );

            return(result);
        }
示例#3
0
        public static HullRole Factory(int id, string name, string icon)
        {
            HullRole result = new HullRole(
                id: id,
                name: name,
                icon: icon
                );

            return(result);
        }
示例#4
0
        public static HullRole Factory()
        {
            HullRole result = new HullRole(
                id: -1,
                name: "",
                icon: ""
                );

            return(result);
        }
示例#5
0
        /// <summary>
        /// Gets a role by id
        /// </summary>
        /// <param name="output"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool FetchById(ref HullRole output, int id)
        {
            SQLiteDataReader reader = DBI.DoPreparedQuery(
                @"SELECT * FROM HullRole 
				WHERE id = @id LIMIT 1;"                ,
                new Tuple <string, object>("@id", id));

            if (reader != null && reader.Read())
            {
                output = HullRole.Factory(reader);
                return(true);
            }
            return(false);
        }
示例#6
0
        /// <summary>
        /// Gets a role by name
        /// </summary>
        /// <param name="output"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static bool FetchByName(ref HullRole output, string name)
        {
            SQLiteDataReader reader = DBI.DoPreparedQuery(
                @"SELECT * FROM HullRole 
				WHERE name = @name LIMIT 1;"                ,
                new Tuple <string, object>("@name", name));

            if (reader != null && reader.Read())
            {
                output = HullRole.Factory(reader);
                return(true);
            }
            return(false);
        }
示例#7
0
        /// <summary>
        /// Creates a new Hull Role
        /// </summary>
        /// <param name="output"></param>
        /// <param name="name"></param>
        /// <param name="icon"></param>
        /// <returns></returns>
        public static bool Create(ref HullRole output, string name,
                                  string icon = "")
        {
            int result = DBI.DoPreparedAction(
                @"INSERT INTO HullRole (name, icon) 
				VALUES (@name, @icon);"                ,
                new Tuple <string, object>("@name", name),
                new Tuple <string, object>("@icon", icon));

            if (result == 1)
            {
                return(HullRole.FetchById(ref output, DBI.LastInsertRowId));
            }
            return(false);
        }
示例#8
0
        /// <summary>
        /// Updates a role
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool Store(HullRole input)
        {
            int result = DBI.DoPreparedAction(
                @"UPDATE HullRole 
				SET name = @name, icon = @icon 
				WHERE id = @id;"                ,
                new Tuple <string, object>("@name", input.name),
                new Tuple <string, object>("@icon", input.icon),
                new Tuple <string, object>("@id", input.id));

            if (result == 1)
            {
                return(true);
            }
            return(false);
        }