private void GetImages() { var files = Directory.GetFiles(folderPath); var fileInfos = files.Select(o => new FileInfo(o)).ToList(); reportImages.Clear(); pictureEdit1.Image = null; foreach (FileInfo fileInfo in fileInfos) { var names = fileInfo.Name.Replace(fileInfo.Extension, "").Split('_'); if (names.Length < 4) { continue; } var reportImage = new ReportImage(); reportImage.FileFullName = fileInfo.FullName; reportImage.FileSafeName = fileInfo.Name; reportImage.Xm = names[0]; reportImage.Blh = names[1]; reportImage.Txxh = Convert.ToInt32(names.Last()); reportImages.Add(reportImage); } reportImages.Sort(CompareByBlhAndXh); reportImageBindingSource.DataSource = reportImages; gridView1.BestFitColumns(); }
private int CompareByBlhAndXh(ReportImage x, ReportImage y) { if (String.Compare(x.Blh, y.Blh, StringComparison.Ordinal) != 0) { return(String.Compare(x.Blh, y.Blh, StringComparison.Ordinal)); } return(x.Txxh.CompareTo(y.Txxh)); }
private void reportImageBindingSource_CurrentItemChanged(object sender, EventArgs e) { ReportImage ri = reportImageBindingSource.Current as ReportImage; if (ri == null) { return; } //防止image占用文件导致无法删除本地文件 Image img = Image.FromStream(new MemoryStream(File.ReadAllBytes(ri.FileFullName))); pictureEdit1.Image = img; }