public ThumbnailFiller(ThumbnailListView lvw) { this.lvw = lvw; this.bkgWork = new BackgroundWorker(); this.bkgWork.DoWork += new DoWorkEventHandler(this.bkgWork_DoWork); this.bkgWork.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.bkgWork_RunWorkerCompleted); this.time_MouseWheelListener = new System.Windows.Forms.Timer(); this.time_MouseWheelListener.Interval = 200; this.time_MouseWheelListener.Enabled = false; this.time_MouseWheelListener.Tick += new EventHandler(this.OnTick); }
public static void FillItemImage(ThumbnailListView lvw) { try { try { if ((!lvw.Visible || (lvw.TopItem == null)) || (lvw.TopItem.Index == -1)) { return; } } catch { return; } Cursor.Current = Cursors.WaitCursor; if ((lvw.SmallImageList == null) || (lvw.SmallImageList != lvw.ThumImageList)) { lvw.SmallImageList = lvw.ThumImageList; } int generation = GC.GetGeneration(lvw.ThumImageList); List <IBizItem> bizItems = new List <IBizItem>(); ArrayList masterOids = new ArrayList(); ArrayList revNums = new ArrayList(); for (int i = lvw.TopItem.Index; i < lvw.Items.Count; i++) { if ((lvw.Items[i] != null) && (lvw.Bounds.Bottom > lvw.Items[i].Bounds.Top)) { ListViewItem item = lvw.Items[i]; IBizItem tag = null; if (item.Tag is IBizItem) { tag = item.Tag as IBizItem; } else if (item.Tag is DataRowView) { try { masterOids.Add(new Guid((byte[])((DataRowView)item.Tag)[0])); revNums.Add(0); } catch { } } if (tag != null) { bizItems.Add(tag); } } } if (masterOids.Count > 0) { ArrayList list4 = PLItem.Agent.GetBizItemsByMasters(masterOids, revNums, lvw.ThumPSOption.CurView, ClientData.LogonUser.Oid, BizItemMode.BizItem); if (list4.Count > 0) { bizItems.AddRange((IBizItem[])list4.ToArray(typeof(IBizItem))); } } Dictionary <Guid, string> dictionary = new Dictionary <Guid, string>(); if (bizItems.Count > 0) { try { dictionary = UIThumbnailHelper.Instance.DownLoadThumFiles(bizItems, lvw.ThumPSOption); } catch (Exception exception) { PLMEventLog.WriteExceptionLog(exception); } } string key = 0.ToString() + ".jpg"; if (!lvw.ThumImageList.Images.ContainsKey(key)) { string path = Path.Combine(ConstConfig.GetTempfilePath(), "Thum"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string filename = Path.Combine(path, key); Image image = ClientData.ItemImages.imageList.Images[0]; image.Save(filename); lock (typeof(ImageList)) { lvw.ThumImageList.Images.Add(key, image); } image.Dispose(); } for (int j = lvw.TopItem.Index; j < lvw.Items.Count; j++) { if ((lvw.Items[j] != null) && (lvw.Bounds.Bottom > lvw.Items[j].Bounds.Top)) { ListViewItem item3 = lvw.Items[j]; IBizItem item4 = null; if (item3.Tag is IBizItem) { item4 = item3.Tag as IBizItem; } else if (item3.Tag is DataRowView) { try { Guid masterOid = new Guid((byte[])((DataRowView)item3.Tag)[0]); item4 = FindBizItems(bizItems, masterOid); } catch { } } if (item4 != null) { string str4 = ""; string fileName = ""; Image reducedImage = null; if (dictionary.ContainsKey(item4.IterOid)) { str4 = dictionary[item4.IterOid]; if (File.Exists(str4)) { fileName = Path.GetFileName(str4); reducedImage = UIThumbnailHelper.Instance.GetReducedImage(str4); if (reducedImage != null) { if (lvw.ThumImageList.Images.ContainsKey(fileName)) { int num5 = lvw.ThumImageList.Images.IndexOfKey(fileName); lvw.ThumImageList.Images[num5] = reducedImage; } else { lock (typeof(ImageList)) { lvw.ThumImageList.Images.Add(fileName, reducedImage); } } reducedImage.Dispose(); } } } else { fileName = ClientData.ItemImages.GetObjectImage(item4.ClassName, PLDataModel.GetStateByMasterInfo(item4.ExactState, item4.HasFile)).ToString() + ".jpg"; if (!lvw.ThumImageList.Images.ContainsKey(fileName)) { string str6 = Path.Combine(ConstConfig.GetTempfilePath(), "Thum"); if (!Directory.Exists(str6)) { Directory.CreateDirectory(str6); } string str7 = Path.Combine(str6, fileName); reducedImage = ClientData.ItemImages.GetObjectImage1(item4.ClassName, PLDataModel.GetStateByMasterInfo(item4.ExactState, item4.HasFile)); reducedImage.Save(str7); lock (typeof(ImageList)) { lvw.ThumImageList.Images.Add(fileName, reducedImage); } reducedImage.Dispose(); } } item3.ImageIndex = lvw.ThumImageList.Images.IndexOfKey(fileName); } } } lvw.Refresh(); GC.GetGeneration(generation); } finally { Cursor.Current = Cursors.Default; } }