/// <summary> /// Gets the list of ISBNs /// </summary> /// <returns></returns> public List<Book> GetImgISBNList() { List<Book> l_ISBNs = new List<Book>(); OleDbCommand command = new OleDbCommand("SELECT ISBN , ISBN13 FROM BOOKS_WEB", conn); Book isbn = null; OleDbDataReader reader = null; try { conn.Open(); reader = command.ExecuteReader(); int ind_ISBN10 = 0; int ind_ISBN13 = 0; bool updateISBNFlag = false; if (reader.HasRows) { while (reader.Read()) { updateISBNFlag = false; isbn = new Book(); ind_ISBN10 = reader.GetOrdinal("ISBN"); ind_ISBN13 = reader.GetOrdinal("ISBN13"); if (!reader.IsDBNull(ind_ISBN10)) { isbn.ISBN10 = reader.GetString(ind_ISBN10); } else { updateISBNFlag = true; } if (!reader.IsDBNull(ind_ISBN13)) { isbn.ISBN13 = reader.GetString(ind_ISBN13); } if (updateISBNFlag) { isbn.ISBN10 = ISBNManager.UpdateISBN10(isbn.ISBN13, conn); } l_ISBNs.Add(isbn); } } } catch (OleDbException ex) { throw ex; } finally { reader.Close(); conn.Close(); } return l_ISBNs; }
private void btnCopy_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(txtDestination.Text)) { MessageBox.Show("Destination path is empty"); } else if (String.IsNullOrEmpty(txtSource.Text)) { MessageBox.Show("Source path is empty"); } else { //1. Gets all the images list from SQL Server. ImgManager mgr = new ImgManager(); List<Book> books = mgr.GetImgISBNList(); List<Book> ISBNsImg = new List<Book>(); Book bk = null; int c_ISBN13Image = 0; int c_ISBN10Image = 0; int c_NoImage = 0; //2. Goes through the list foreach (Book book in books) { if (imgFiles.Contains(String.Format(@"{0}\{1}.jpg", txtSource.Text, book.ISBN13))) { bk = new Book(book.ISBN10, book.ISBN13, String.Format("{0}.jpg", book.ISBN13), String.Format("{0}_th.jpg", book.ISBN13)); //File.Move(String.Format(@"{0}\{1}", txtSource.Text, bk.IMAGE_NAME), String.Format(@"{0}\{1}", txtDestination.Text, bk.IMAGE_NAME)); c_ISBN13Image++; } else if (imgFiles.Contains(String.Format(@"{0}\{1}.jpg", txtSource.Text, book.ISBN10))) { bk = new Book(book.ISBN10, book.ISBN13, String.Format("{0}.jpg", book.ISBN10), String.Format("{0}_th.jpg", book.ISBN10)); //File.Move(String.Format(@"{0}\{1}", txtSource.Text, bk.IMAGE_NAME), String.Format(@"{0}\{1}", txtDestination.Text, bk.IMAGE_NAME)); c_ISBN10Image++; } else // No Image { bk = new Book(book.ISBN10, book.ISBN13, "no_image.jpg", "no_image_small.jpg"); c_NoImage++; } ISBNsImg.Add(bk); } //3. Updates DB with new entries (UBCC_SITE) mgr.UpdateBookImg(ISBNsImg); MessageBox.Show("Completed :), The number of books without image is: " + c_NoImage + ", with ISBN13 image is:" + c_ISBN13Image + ", and with ISBN10 is:" + c_ISBN10Image); } }