public PublisherDTO GetPublisherById(int publisherId)
        {
            PublisherDTO publisherDto = null;

            try
            {
                SqlDataReader reader = ConnectionManager.GetCommand("SP0401PI",
                                                                    new Dictionary<string, SqlDbType>() { { "@Param1", SqlDbType.Int } },
                                                                    new List<object>() { publisherId }).ExecuteReader();

                if (reader.Read())
                {
                    publisherDto = new PublisherDTO();
                    publisherDto.PublisherId = int.Parse(reader["PublisherID"].ToString());
                    publisherDto.PublisherName = reader["PublisherName"].ToString();
                    publisherDto.CreatedDate = (DateTime)reader["CreatedDate"];
                    publisherDto.UpdatedDate = (DateTime)reader["UpdatedDate"];
                }

                reader.Close();
            }
            catch (Exception e)
            {
                Log.Error("Error at PublisherDAO - GetPublisherByID", e);
                return null;
            }

            return publisherDto;
        }
        public List<PublisherDTO> GetAllPublisher()
        {
            List<PublisherDTO> list = new List<PublisherDTO>();

            try
            {
                SqlDataReader reader = ConnectionManager.GetCommand("SP0401ALL",
                                                                    new Dictionary<string, SqlDbType>() { },
                                                                    new List<object>() { }).ExecuteReader();

                while (reader.Read())
                {
                    PublisherDTO publisherDto = new PublisherDTO();
                    publisherDto.PublisherId = int.Parse(reader["PublisherID"].ToString());
                    publisherDto.PublisherName = reader["PublisherName"].ToString();
                    publisherDto.CreatedDate = (DateTime)reader["CreatedDate"];
                    publisherDto.UpdatedDate = (DateTime)reader["UpdatedDate"];
                    list.Add(publisherDto);
                }

                reader.Close();
            }
            catch (Exception e)
            {
                Log.Error("Error at AuthorDAO - GetAllPublisher", e);
                return null;
            }

            return list;
        }
        public CatalogueDTO GetCatalogueById(String isbn)
        {
            CatalogueDTO catalogueDto = null;

            try
            {
                SqlDataReader reader = ConnectionManager.GetCommand("SP0101ISBN",
                                                                    new Dictionary<string, SqlDbType>() { { "@Param1", SqlDbType.NVarChar } },
                                                                    new List<object>() { isbn }).ExecuteReader();

                if (reader.Read())
                {
                    catalogueDto = new CatalogueDTO();

                    PublisherDTO publisherDto = new PublisherDTO();
                    CategoryDTO categoryDto = new CategoryDTO();

                    catalogueDto.ISBN = reader["ISBN"].ToString();
                    catalogueDto.Title = reader["Title"].ToString();
                    // add code for get data
                    publisherDto.PublisherId = int.Parse(reader["PublisherID"].ToString());
                    catalogueDto.Publisher = publisherDto;
                    catalogueDto.ShortDescription = reader["ShortDescription"].ToString();
                    // add code for get data
                    categoryDto.CategoryId = reader["CategoryID"].ToString();
                    catalogueDto.Category = categoryDto;
                    catalogueDto.Language = reader["Language"].ToString();
                    catalogueDto.Year = int.Parse(reader["Year"].ToString());
                    catalogueDto.ExpandLimit = int.Parse(reader["ExpandLimit"].ToString());
                    catalogueDto.ExpandDateLimit = int.Parse(reader["ExpandDateLimit"].ToString());
                    catalogueDto.NumberOfCopies = int.Parse(reader["NumberOfCopies"].ToString());
                    catalogueDto.AvailableCopies = int.Parse(reader["AvailableCopies"].ToString());
                    catalogueDto.Price = float.Parse(reader["Price"].ToString());
                    catalogueDto.Image = reader["Image"].ToString();
                    catalogueDto.HitTime = int.Parse(reader["HitTime"].ToString());
                    catalogueDto.RentalTime = int.Parse(reader["RentalTime"].ToString());
                    catalogueDto.CreatedDate = (DateTime) reader["CreatedDate"];
                    catalogueDto.UpdatedDate = (DateTime) reader["UpdatedDate"];
                }

                reader.Close();
            }
            catch (Exception e)
            {
                Log.Error("Error at CatalogueDAO - GetCatalogueByID", e);
                return null;
            }

            return catalogueDto;
        }
        public int DeletePublisher(PublisherDTO publisher)
        {
            try
            {
                ConnectionManager.GetCommand("SP0404",
                                             new Dictionary<string, SqlDbType>()
                                                 {
                                                     {"@Param1", SqlDbType.Int}
                                                 },
                                             new List<object>()
                                                 {
                                                     publisher.PublisherId
                                                 }).ExecuteNonQuery();

            }
            catch (Exception e)
            {
                Log.Error("Error at PublisherDAO - DeletePublisher", e);
                return 0;
            }

            return 1;
        }
 private void btnSave_Click(object sender, EventArgs e)
 {
     PublisherBUS bus = new PublisherBUS();
     if (String.IsNullOrEmpty(txtPublisherID.Text))
     {
         if (String.IsNullOrEmpty(txtPublisherName.Text))
         {
             MessageBox.Show(Resources.ADD_NULL_PUBLISHER_NAME);
         }
         else
         {
             PublisherDTO publisherDTO = new PublisherDTO()
                                             {
                                                 PublisherName = txtPublisherName.Text,
                                                 CreatedDate = DateTime.Now,
                                                 UpdatedDate = DateTime.Now
                                             };
             if (bus.InsertPublisher(publisherDTO) == 1)
             {
                 MessageBox.Show(Resources.ADD_PUBLISHER_SUCCESS);
                 lst.Add(publisherDTO);
                 grdPublisher.RefreshDataSource();
             }
             else
             {
                 MessageBox.Show(Resources.ADD_PUBLISHER_FAIL);
             }
         }
     }
     else
     {
         if (String.IsNullOrEmpty(txtPublisherName.Text))
         {
             MessageBox.Show(Resources.ADD_NULL_PUBLISHER_NAME);
         }
         else
         {
             PublisherDTO publisherDTO = (PublisherDTO)grvPublisher.GetFocusedRow();
             publisherDTO.PublisherName = txtPublisherName.Text;
             if (bus.UpdatePublisher(publisherDTO) == 1)
             {
                 MessageBox.Show(Resources.UPDATE_PUBLISHER_SUCCESS);
                 grdPublisher.RefreshDataSource();
             }
             else
             {
                 MessageBox.Show(Resources.UPDATE_PUBLISHER_FAIL);
             }
         }
     }
 }
 public int UpdatePublisher(PublisherDTO publisher)
 {
     PublisherDAO dao = new PublisherDAO();
     return dao.UpdatePublisher(publisher);
 }
 public int InsertPublisher(PublisherDTO publisher)
 {
     PublisherDAO dao = new PublisherDAO();
     return dao.InsertPublisher(publisher);
 }
 public int DeletePublisher(PublisherDTO publisher)
 {
     PublisherDAO dao = new PublisherDAO();
     return dao.DeletePublisher(publisher);
 }
        public int UpdatePublisher(PublisherDTO publisher)
        {
            publisher.UpdatedDate = DateTime.Now;
            try
            {
                ConnectionManager.GetCommand("SP0403",
                                             new Dictionary<string, SqlDbType>()
                                                 {
                                                     {"@Param1", SqlDbType.Int},
                                                     {"@Param2", SqlDbType.NVarChar},
                                                     {"@Param3", SqlDbType.DateTime},
                                                     {"@Param4", SqlDbType.DateTime}
                                                 },
                                             new List<object>()
                                                 {
                                                     publisher.PublisherId,
                                                     publisher.PublisherName,
                                                     publisher.CreatedDate,
                                                     publisher.UpdatedDate
                                                 }).ExecuteNonQuery();

            }
            catch (Exception e)
            {
                Log.Error("Error at PublisherDAO - UpdatePublisher", e);
                return 0;
            }

            return 1;
        }
        public List<PublisherDTO> SearchPublisher(string info)
        {
            List<PublisherDTO> list=new List<PublisherDTO>();
            PublisherDTO publisherDTO;
            try
            {
                SqlDataReader reader = ConnectionManager.GetCommand("sp0005publisher",
                                                                    new Dictionary<string, SqlDbType>() { { "@publisher", SqlDbType.NVarChar } },
                                                                    new List<object>() { info }).ExecuteReader();

                while (reader.Read())
                {
                    publisherDTO = new PublisherDTO();
                    publisherDTO.PublisherId = int.Parse(reader["publisherID"].ToString());
                    publisherDTO.PublisherName = reader["publisherName"].ToString();
                    publisherDTO.CreatedDate = (DateTime)reader["CreatedDate"];
                    publisherDTO.UpdatedDate = (DateTime)reader["UpdatedDate"];
                    list.Add(publisherDTO);
                }

                reader.Close();
            }
            catch (Exception e)
            {
                Log.Logger.Error("Error at AuthorDAO - GetAuthorByID", e);
                return null;
            }
            return list;
        }