private void SyncEbayData_ActiveListingTab(object sender, EventArgs e) { this.buttonSyncEbayData.Enabled = false; // // For simplicity, we will delete all active listings before updating. // EbayListingDAL.DeleteAllListings(); List <AccountType> allAccounts = AccountUtil.GetAllAccounts(); foreach (AccountType account in allAccounts) { List <EbayActiveListingType> activeListings = EbaySellingBiz.GetMyActiveListing(account); if (activeListings == null) { continue; } foreach (EbayActiveListingType activeListing in activeListings) { EbayListingDAL.InsertOrUpdateOneActiveListing(activeListing); } } this.buttonSyncEbayData.Enabled = true; }
private void LoadListingImageData() { DataTable dtActiveSelling = AllListingCacheTable; { dtActiveSelling.Columns.Add(new DataColumn("Img", typeof(Bitmap))); Bitmap bitmap = new Bitmap(64, 42); using (Graphics g = Graphics.FromImage(bitmap)) { g.DrawString("Loading...", this.Font, new SolidBrush(Color.Black), 0f, 0f); } foreach (DataRow dr in dtActiveSelling.Rows) { dr["Img"] = bitmap; } } this.dataGridViewActiveListing.DataSource = dtActiveSelling; ThreadPool.QueueUserWorkItem(delegate { foreach (DataRow row in dtActiveSelling.Rows) { String imagePath = StringUtil.GetSafeString(row["ImagePath"]); // Check whether image really exists. if (imagePath != "" && System.IO.File.Exists(imagePath)) { System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(imagePath); row["Img"] = bmp; } else { HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(row["GalleryURL"].ToString()); myRequest.Method = "GET"; HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(myResponse.GetResponseStream()); myResponse.Close(); String listingId = StringUtil.GetSafeString(row["ListId"]); String itemID = StringUtil.GetSafeString(row["ItemID"]); String folderPath = Application.StartupPath + String.Format("\\listings"); if (!System.IO.Directory.Exists(folderPath)) { System.IO.Directory.CreateDirectory(folderPath); } String filePath = Application.StartupPath + String.Format("\\listings\\{0}.jpg", itemID); if (!System.IO.File.Exists(filePath)) { bmp.Save(filePath); } EbayListingDAL.UpdateActingListImagePath(listingId, filePath); row["Img"] = bmp; } } }); }
private void LoadActiveListingData() { ListingCount = EbayListingDAL.GetListingCount(); int listingPageCnt = ListingCount / ListingPageSize + 1; if (CurrentListingPage < 1) { CurrentListingPage = 1; } else if (CurrentListingPage > listingPageCnt) { CurrentListingPage = listingPageCnt; } this.buttonListingFirstPage.Enabled = true; this.buttonListingLastPage.Enabled = true; this.buttonListingPrevPage.Enabled = true; this.buttonListingNextPage.Enabled = true; if (CurrentListingPage == 1) { this.buttonListingFirstPage.Enabled = false; this.buttonListingPrevPage.Enabled = false; } if (CurrentListingPage == listingPageCnt) { this.buttonListingLastPage.Enabled = false; this.buttonListingNextPage.Enabled = false; } this.labelListingPage.Text = string.Format("{0} / {1}", CurrentListingPage, listingPageCnt); AllListingCacheTable = EbayListingDAL.GetPagedActiveListings(CurrentListingPage, ListingPageSize); this.dataGridViewActiveListing.DataSource = AllListingCacheTable; LoadListingImageData(); }