2017-09-05 43 views
-10

我有以下代碼,我發現是VB.NET,我想稍微修改它,所以當它獲取PNG圖像時,它會選擇文件夾中最大的文件大小。任何幫助非常感謝!從文件夾中選擇圖像文件基於文件大小(選擇最大)

Imports system.data 
imports system.io 
imports system.windows.forms 
Imports system.drawing 

Private Sub xtraReport1_BeforePrint(ByVal sender As Object, ByVal e As 
System.Drawing.Printing.PrintEventArgs) 
Dim ReportDS As system.data.dataset = CType(Report.DataSource, 
System.Data.DataSet) 

if CType(Report.DataSource, DataSet).Tables("Data").Rows.Count = 0 then 
Exit Sub 
End if 

if CType(Report.DataSource, 
DataSet).Tables("Data").columns.contains("CourierLabel") = false then 
CType(Report.DataSource, DataSet).Tables("Data").columns.add("CourierLabel", 
gettype(String)) 
end if 

Dim ExportPath as string = SystemBusiness.Executescalarstr("select 
cod_cdd_export_path from courier_detail where cod_id = " & 
CType(Report.DataSource, DataSet).Tables("Data").rows(0).item("dh_cod_id")) 

Dim DelNumber as string = CType(Report.DataSource, 
DataSet).Tables("Data").rows(0).item("dh_number").tostring 
Dim DelDate as string = cdate(CType(Report.DataSource, 
DataSet).Tables("Data").rows(0).item("dh_datetime")).tostring("yyyy-MM-dd") 

Dim DirPath as string = System.IO.Path.Combine(ExportPath, DelDate, 
DelNumber) 
'DirPath = "C:\temp" 

For each f as string In Directory.GetFiles(DirPath) 

if f.contains("png") Then 
CType(Report.DataSource, 
DataSet).Tables("Data").rows(0).item("CourierLabel") = 
System.IO.Path.Combine(DirPath, f) 
'messagebox.show(System.IO.Path.Combine(DirPath, f)) 
'system.windows.forms.messagebox.show(System.IO.Path.Combine(DirPath, f)) 
PictureBox1.Image = Image.FromFile(System.IO.Path.Combine(DirPath, f)) 
picturebox1.image.rotateflip(RotateFlipType.Rotate90FlipNone) 

end if 

Next 

End Sub 
+5

我認爲這是VBA。它不是C或C++。 – NathanOliver

+1

我很感興趣,看到一些語言標籤打開問題! – CinCout

+0

謝謝,我認爲它會自動修復。希望有人能夠提供幫助。 – Tom

回答

1

及其基本:(

我可以提供的路要走:

首先找到最大的文件: maxFileSize爲= 0; 環文件和文件大小各用maxFileSize爲,如果比較大保存文件路徑。 你的路徑,在目錄中最大的文件循環後。

Dim maxFileSize = 0 
Dim filePath = Nothing 
For each f as string In Directory.GetFiles(DirPath) 
    if f.Size > maxFileSize Then 
     maxFileSize = f.Size 
     filePath = f.FullPath 
    end if 
Next 

我不確定f.Size和f.FullPath,但這應該很容易在調試器中解決;)

+0

聽起來很對,謝謝。我不認爲你知道代碼會怎麼樣? – Tom