예제 #1
0
        /*
         * Gets all the officers from the database and returns it in a list
         * so that the list can then be compared in other functions. It can be used to login
         * a user or display all officers
         */


        /* Gets All of the officers from the database */
        public List <Officer> GetOfficers()
        {
            List <Officer> listToReturn = new List <Officer>();


            /* All database related functions */
            connection.Open();
            com             = new SqlCommand("sp_SelectAllOffices", connection);
            com.CommandType = CommandType.StoredProcedure;
            reader          = com.ExecuteReader();

            while (reader.Read())
            {
                Officer officerToAdd = new Officer();
                officerToAdd.NationId  = (string)reader["OfficerID"];
                officerToAdd.FirstName = (string)reader["FirstName"];
                officerToAdd.LastName  = (string)reader["LastName"];
                officerToAdd.Age       = (int)reader["Age"];
                officerToAdd.Rank      = (int)reader["Rank"];
                officerToAdd.Username  = (string)reader["Username"];
                officerToAdd.Password  = (string)reader["Password"];
                listToReturn.Add(officerToAdd);
            }

            connection.Close();


            /* Database functionality end */

            return(listToReturn);
        }