コード例 #1
0
        public static AuthorDTO getAuthorName(string Name)
        {
            AuthorDTO dto = new AuthorDTO();
            string _connectionString = DataSource.GetConnectionString("library2");  // Make possible to define and use different connectionstrings 
            SqlConnection con = new SqlConnection(_connectionString);
            SqlCommand cmd = new SqlCommand("SELECT * FROM AUTHOR WHERE FirstName = " + Name, con);
            try
            {
                con.Open();
                SqlDataReader dar = cmd.ExecuteReader();
                if (dar.Read())
                {
                    dto.aId = (int)dar["Aid"];
                    dto.firstName = dar["FirstName"] as string;
                    dto.lastName = dar["LastName"] as string;
                    dto.birthYear = (int)dar["BirthYear"];
                }
            }
            catch (Exception er)
            {
                throw er;
            }
            finally
            {
                con.Close();
            }

            return dto;
        }
コード例 #2
0
        public static AuthorDTO loadAuthorDAL(int aId)
        {
            AuthorDTO dto = new AuthorDTO();
            string _connectionString = DataSource.GetConnectionString("library2");  // Make possible to define and use different connectionstrings 
            SqlConnection con = new SqlConnection(_connectionString);
            SqlCommand cmd = new SqlCommand("SELECT * FROM AUTHOR WHERE aid = " + aId.ToString(), con);
            try
            {
                con.Open();
                SqlDataReader dar = cmd.ExecuteReader();
                if (dar.Read())
                {
                    dto.aId = (int)dar["Aid"];
                    dto.firstName = dar["FirstName"] as string;
                    dto.lastName = dar["LastName"] as string;
                    dto.birthYear = (dar["BirthYear"] == DBNull.Value) ? 0 : Convert.ToInt32(dar["BirthYear"].ToString());
                }
            }
            catch (Exception er)
            {
                throw er;
            }
            finally
            {
                con.Close();
            }

            //Collect all isbn numbers from book_author table
            dto = getAuthorIsbnDAL(dto);
            dto.loadStatus = LoadStatus.Loaded;  // All the data has been loaded into the dto-object

            return dto;
        }
コード例 #3
0
 public AuthorDTO(AuthorDTO dto)
 {
     this.loadStatus = dto.loadStatus;  // Lazy load
     aId = dto.aId;
     firstName = dto.firstName;
     lastName = dto.lastName;
     birthYear = dto.birthYear;
 }
コード例 #4
0
 public AuthorDTO(AuthorDTO dto)
 {
     this.loadStatus = dto.loadStatus;  // Lazy load
     aId             = dto.aId;
     firstName       = dto.firstName;
     lastName        = dto.lastName;
     birthYear       = dto.birthYear;
 }
コード例 #5
0
ファイル: Author.cs プロジェクト: fredenholm/LibSysFiveTier
 private void Load()
 {
     // Initiates a read from the database of the DTO-object for a specific author, if loadstatus is set to "Ghost"   
     try
     {
         if(_authorDTO.loadStatus == LoadStatus.Ghost)
         {
             _authorDTO = LibraryDataAccess.loadAuthorDAL(_authorDTO.aId);
         }
     }
     catch (Exception ex)
     {
         //Do some error-log functionality with ex.Data
     }
 }
コード例 #6
0
ファイル: Author.cs プロジェクト: fredenholm/LibSysFiveTier
 //A constructor which creates a DTO-object with data from an existing DTO-object
 public Author(AuthorDTO _sourceDTO)
 {
     _authorDTO = new AuthorDTO(_sourceDTO);
 }
コード例 #7
0
ファイル: Author.cs プロジェクト: fredenholm/LibSysFiveTier
 //Initialize a new DTO-object for the transferring data about author
 public Author()
 {
     _authorDTO = new AuthorDTO();
 }
コード例 #8
0
ファイル: Author.cs プロジェクト: fredenholm/LibSysFiveTier
 public static AuthorDTO findAuthorDTO(string aId)
 {
     AuthorDTO dto = new AuthorDTO();
     return dto;
 }
コード例 #9
0
        public static List<AuthorDTO> getAllAuthorsDAL()
        {
            List<AuthorDTO> authorDtoList = new List<AuthorDTO>();

            //Connect to the database and read all authors
            string _connectionString = DataSource.GetConnectionString("library2");  // Make possible to define and use different connectionstrings 
            SqlConnection con = new SqlConnection(_connectionString);
            SqlCommand cmd = new SqlCommand("SELECT * FROM AUTHOR", con);
            try
            {
                con.Open();
                SqlDataReader dar = cmd.ExecuteReader();
                while (dar.Read())
                {
                    AuthorDTO dto = new AuthorDTO();
                    dto.aId = (int)dar["Aid"];
                    dto.firstName = dar["FirstName"] as string;
                    dto.lastName = dar["LastName"] as string;
                    dto.birthYear = (dar["BirthYear"] == DBNull.Value) ? 0 : Convert.ToInt32(dar["BirthYear"].ToString());
                    dto.loadStatus = LoadStatus.Ghost;  //Since we are not retrieving the isbn-number list
                    authorDtoList.Add(dto);
                }
            }
            catch (Exception er)
            {
                throw er;
            }
            finally
            {
                con.Close();
            }
            return authorDtoList;
        }
コード例 #10
0
 public static AuthorDTO getAuthorIsbnDAL(AuthorDTO dto)
 {
      //Connect to the database and read all books for given author
     string _connectionString = DataSource.GetConnectionString("library2");  // Make possible to define and use different connectionstrings 
     SqlConnection con = new SqlConnection(_connectionString);
     SqlCommand cmd = new SqlCommand("SELECT isbn FROM book_author WHERE aid = " + dto.aId.ToString(), con);
     try
     {
         string isbn;
         con.Open();
         SqlDataReader dar = cmd.ExecuteReader();
         while (dar.Read())
         {
             isbn = dar["ISBN"] as string;
             dto.isbnList.Add(isbn);
         }
     }
     catch (Exception er)
     {
         throw er;
     }
     finally
     {
         con.Close();
     }
     return dto;
 }