コード例 #1
0
ファイル: DeskDB.cs プロジェクト: jakemmarsh/coyote-moves
        public List<Desk> GetAllDesks()
        {
            List<Desk> deskList = new List<Desk>();
            SqlConnection connection = new SqlConnection(_connectionString);
            string commandString = "EXEC dbo.spDesk_GetAllDesks";
            SqlCommand command = new SqlCommand(commandString);

            try
            {
                command.Connection = connection;
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();

                SqlToDeskModelFactory DeskFactory = new SqlToDeskModelFactory(reader);
                deskList = DeskFactory.GetAllDesks();
                connection.Close();
                return deskList;
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #2
0
ファイル: DeskDB.cs プロジェクト: jakemmarsh/coyote-moves
        /// <summary>
        /// Function to query the database for 
        /// desks on a particular floor
        /// </summary>
        public List<Desk> GetDesksFromFloor(int floor)
        {
            List<Desk> deskList = new List<Desk>();
            SqlConnection connection = new SqlConnection(_connectionString);
            string commandString = "EXEC dbo.spDesk_GetDesksByFloor @FloorNumber = @floor";
            SqlCommand command = new SqlCommand(commandString);

            try
            {
                command.Parameters.AddWithValue("@floor", floor);
                command.Connection = connection;
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();

                SqlToDeskModelFactory DeskFactory = new SqlToDeskModelFactory(reader);
                deskList = DeskFactory.GetAllDesks(floor);
                connection.Close();
                return deskList;
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }