Exemplo n.º 1
0
        // insert image book
        public bool insert(ImageBook imgb)
        {
            SqlCommand cmd        = null;
            string     sqlCommand = "INSERT INTO ImageBook(urlImage, idBook) values('" + imgb.urlImage + "', " + imgb.idBook + ")";

            try
            {
                cmd = new SqlCommand(sqlCommand, connection);

                connection.Open(); // open connect
                return(cmd.ExecuteNonQuery() != 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
                cmd.Dispose();
            }
        }
Exemplo n.º 2
0
        public Notification InsertImageBook(ImageBook imageBook)
        {
            string strSQL = "INSERT INTO RawImageBook VALUES(@ID_Book, @ID_Image, @Path)";

            return(sql.ExecuteNonQuery(strSQL, CommandType.Text, new SqlParameter("@ID_Book", imageBook.id_book),
                                       new SqlParameter("@ID_Image", imageBook.id_image), new SqlParameter("@Path", imageBook.path)));
        }
Exemplo n.º 3
0
        public void uploadCoverBook(string rootPath, string[] fileName, byte[][] bytes, int idBook)
        {
            CoverBookDAO dao = new CoverBookDAO();

            for (int i = 0; i < 5; i++)
            {
                if (bytes[i] != null && fileName[i] != "")
                {
                    dao.uploadImage(rootPath, fileName[i], bytes[i]);
                    ImageBook imb = new ImageBook()
                    {
                        urlImage = fileName[i], idBook = idBook
                    };
                    dao.insert(imb);
                }
                else
                {
                    ImageBook imb = new ImageBook()
                    {
                        urlImage = "coverbook.jpg", idBook = idBook
                    };
                    dao.insert(imb);
                }
            }
        }
Exemplo n.º 4
0
        public void CrawlImageBook(string link, string book_name)
        {
            HtmlDocument document = htmlWeb.Load(link, "POST");
            var          item_id  = document.DocumentNode.QuerySelectorAll("table.table-striped > tbody > tr")
                                    .ToList()[0];
            var id_book = RemoveBlankBeforeText(item_id.QuerySelector("td").InnerHtml.Replace("\n", "")
                                                .Replace("\t", ""));

            if (int.Parse(imageBookBal.CheckExistedBook(id_book).Obj.ToString()).Equals(1) &&
                int.Parse(imageBookBal.CheckDuplicateBook(id_book).Obj.ToString()).Equals(0))
            {
                var item_image = document.DocumentNode.QuerySelector(
                    "div.product-essential > div.col-md-5 > div.more-views > div.row > div.lightgallery");
                if (item_image != null)
                {
                    var images = item_image.QuerySelectorAll("a.include-in-gallery").ToList();
                    images = images.Where(x => Path.GetExtension(x.Attributes["href"].Value).Equals(".jpg") ||
                                          Path.GetExtension(x.Attributes["href"].Value).Equals(".png") ||
                                          Path.GetExtension(x.Attributes["href"].Value).Equals(".jpeg") ||
                                          Path.GetExtension(x.Attributes["href"].Value).Equals(".svg") ||
                                          Path.GetExtension(x.Attributes["href"].Value).Equals(".gif"))
                             .ToList();

                    ImageBook img = new ImageBook()
                    {
                        id_book = RemoveBlankBeforeText(id_book)
                    };
                    for (int i = 0; i < images.Count; i++)
                    {
                        img.id_image = i + 1;
                        img.path     = images[i].Attributes["href"].Value;
                        imageBookBal.InsertImageBook(img);
                    }
                    Console.Write(images.Count);
                }
            }
        }