Dim IniFile As New Clini(App_Path() & "ConF.ini")
Dim StrFile As String
Dim pictures() As String
Dim picture_number As Integer = 0 '--เริ่มรูปแรก
Dim RootDirectory As String
Private Sub frmSlideShow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Connstring = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source="
StrFile = IniFile.GetString("Database", "Server", "Error File")
Connstring = Connstring & StrFile
Connstring = Connstring & "Persist Security Info = False"
Cn = New OleDbConnection(Connstring)
Cn.Open()
RootDirectory = IniFile.GetString("Directory", "Root", "Error File")
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
pictures = System.IO.Directory.GetFiles("D:\Pictures\'" & txtCode.Text & "'") '--พาธไฟล์
Picturebox1.Image = System.Drawing.Image.FromFile(pictures(picture_number))
End Sub
Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
Timer1.Start() '--เริ่มทำงาน
End Sub
'--<<Previous
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
picture_number = (picture_number + 1) Mod pictures.Length
End Sub
'--Next >>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
picture_number = (picture_number + 1) Mod pictures.Length
End Sub
Public Class Form1
Dim ListFile() As String
Dim _Index As Integer = 0
Dim _Main As String = Application.StartupPath & "\Annimal\"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.Rows.Add("สัตว์บก")
DataGridView1.Rows.Add("สัตว์น้ำ")
DataGridView1.Rows.Add("สัตว์ปีก")
End Sub
Private Sub DataGridView1_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
_Index = 0
ListFile = Directory.GetFiles(_Main & DataGridView1.Rows(e.RowIndex).Cells(0).Value, "*.JPG")
Label1.Text = "จำนวนภาพ : " & ListFile.Length
Label2.Text = "ภาพที่ : " & _Index + 1
If ListFile.Length <> 0 Then
PictureBox1.Image = Image.FromFile(ListFile(_Index))
Button1.Enabled = False
Button2.Enabled = IIf(ListFile.Length = 1, False, True)
Else
PictureBox1.Image = Nothing
Button1.Enabled = False
Button2.Enabled = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
_Index -= 1
Label2.Text = "ภาพที่ : " & _Index + 1
PictureBox1.Image = Image.FromFile(ListFile(_Index))
Button2.Enabled = True
If _Index = 0 Then Button1.Enabled = False
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
_Index += 1
Label2.Text = "ภาพที่ : " & _Index + 1
PictureBox1.Image = Image.FromFile(ListFile(_Index))
Button1.Enabled = True
If _Index = ListFile.Length - 1 Then Button2.Enabled = False
End Sub
End Class
... ลองทำแร้วค่ะ... มัน Error ตรงบรรทัดนี้ค่ะ..
ListFile = Directory.GetFiles(_Main & DataGridView1.Rows(e.RowIndex).Cells(0).Value, "*.JPG")
ขึ้นว่า.. The given path's format is not supported.
Dim _Main As String = Application.StartupPath & "\Annimal\" ตรงนี้คืออะไรคะ...
มัน Error ตรงบรรทัดนี้ค่ะ..
ListFile = Directory.GetFiles(_Main & DataGridView1.Rows(e.RowIndex).Cells(0).Value, "*.JPG")
ขึ้นว่า.. The given path's format is not supported.
TxtFile.Text = "" '--ตรงนี้เค้าเขียนจำลองการอ่านไฟล์มาให้ดูน่ะค่ะ
For Each File In FD.Files
TxtFile.Text = TxtFile.Text & File.Name & vbNewLine '--เค้าบอกว่า ให้ เอาไฟล์ที่อ่านได้ มาเช้คเอาเฉพาะ .jpg แร้วเอาไปเก้บในตัวแปลอาเรย์ แร้วเอา ในอาเรย์ไปโชว์ Picturebox โชว์รุปแรก แร้วก้เลื่อนรูปถัดไป เดินหน้า ถอยหลังได้
Next File
FD = Nothing
End Sub
End Class
Dim Cn As OleDbConnection
Dim Cm As OleDbCommand
Dim dr As OleDbDataReader
Dim dt As DataTable
Dim IniFile As New Clini(App_Path() & "ConF.ini")
Dim StrFile As String
Dim RootDirectory As String
Private Sub frmSlideShow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Connstring = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source="
StrFile = IniFile.GetString("Database", "Server", "Error File")
Connstring = Connstring & StrFile
Connstring = Connstring & "Persist Security Info = False"
Cn = New OleDbConnection(Connstring)
Cn.Open()
RootDirectory = IniFile.GetString("Directory", "Root", "Error File")
.End Sub
Imports System.Windows.Forms
Imports System.Data
Imports System.Data.OleDb
Imports System.IO
Public Class frmSlideShow
Dim Cn As OleDbConnection
Dim Cm As OleDbCommand
Dim dr As OleDbDataReader
Dim dt As DataTable
Dim IniFile As New Clini(App_Path() & "ConF.ini")
Dim StrFile As String
Dim RootDirectory As String
Dim ListFile() As String
Dim _Index As Integer
Dim _Main As String = Application.StartupPath & "D:\Pictures\"
Private Sub frmSlideShow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Connstring = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source="
StrFile = IniFile.GetString("Database", "Server", "Error File")
Connstring = Connstring & StrFile
Connstring = Connstring & "Persist Security Info = False"
Cn = New OleDbConnection(Connstring)
Cn.Open()
RootDirectory = IniFile.GetString("Directory", "Root", "Error File")
Dim str As String = ""
str = "SELECT * FROM TBZONE"
Cm = New OleDbCommand(str, Cn)
dr = Cm.ExecuteReader
dr.Read()
dt = New DataTable
dt.Load(dr)
With ComboBox1
.DisplayMember = "ZoneName"
.ValueMember = "ZoneCode"
.DataSource = dt
End With
Dim str1 As String = ""
str1 = "SELECT * FROM TBTypeProduct"
Cm = New OleDbCommand(str1, Cn)
dr = Cm.ExecuteReader
dr.Read()
dt = New DataTable
dt.Load(dr)
With ComboBox2
.DisplayMember = "TypeName"
.ValueMember = "TypeCode"
.DataSource = dt
End With
End Sub
Private Sub GridviewList()
With DataGridView1
If .RowCount > 0 Then
.Columns(0).HeaderText = "รหัสลูกค้า"
.Columns(1).HeaderText = "รหัสลูกค้า"
.Columns(2).HeaderText = "ชื่อลูกค้า"
.Columns(0).Width = 130
.Columns(1).Width = 100
End If
End With
End Sub
'--คลิก กริดวิว ลูกค้า
Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
_Index = 0
ListFile = Directory.GetFiles(_Main & DataGridView1.Rows(e.RowIndex).Cells(0).Value, "*.JPG") '--Error บรรทัดนี้ค่ะ
Label3.Text = "จำนวนภาพ : " & ListFile.Length
Label4.Text = "ภาพที่ : " & _Index + 1
If ListFile.Length <> 0 Then
Picturebox1.Image = Image.FromFile(ListFile(_Index))
Button1.Enabled = False
Button2.Enabled = IIf(ListFile.Length = 1, False, True)
Else
Picturebox1.Image = Nothing
Button1.Enabled = False
Button2.Enabled = False
End If
If e.RowIndex < 0 Then
Exit Sub
End If
With DataGridView1.Rows.Item(e.RowIndex)
txtCode.Text = .Cells(0).Value
txtName1.Text = .Cells(2).Value
Dim strSearch As String = ""
strSearch = "select * from QryCustomer where CODE = '" & txtCode.Text & "'" '--รหัสลูกค้า
Cm = New OleDbCommand(strSearch, Cn)
dr = Cm.ExecuteReader
If dr.HasRows Then
Do While dr.Read()
If dr("NAME2") Is DBNull.Value Then
txtName2.Text = "-"
Else
txtName2.Text = dr("NAME2")
End If
If dr("NameGroup") Is DBNull.Value Then
txtTypegroup.Text = "-"
Else
txtTypegroup.Text = dr("NameGroup")
End If
If dr("Address") Is DBNull.Value Then
txtAddress.Text = "-"
Else
txtAddress.Text = dr("Address")
End If
If dr("Road") Is DBNull.Value Then
txtRoad.Text = "-"
Else
txtRoad.Text = dr("Road")
End If
If dr("Tom") Is DBNull.Value Then
txtTum.Text = "-"
Else
txtTum.Text = dr("Tom")
End If
If dr("Amp") Is DBNull.Value Then
txtAum.Text = "-"
Else
txtAum.Text = dr("Amp")
End If
If dr("City") Is DBNull.Value Then
txtCity.Text = "-"
Else
txtCity.Text = dr("City")
End If
If dr("Tel") Is DBNull.Value Then
txtTel.Text = "-"
Else
txtTel.Text = dr("Tel")
End If
If dr("DateLast") Is DBNull.Value Then
txtDateLast.Text = "-"
Else
txtDateLast.Text = dr("DateLast")
End If
If dr("SN") Is DBNull.Value Then
txtSN.Text = "-"
Else
txtSN.Text = dr("SN")
End If
If dr("GP") Is DBNull.Value Then
txtGP.Text = "-"
Else
txtGP.Text = dr("GP")
End If
If dr("Rent") Is DBNull.Value Then
txtRent.Text = "-"
Else
txtRent.Text = dr("Rent")
End If
If dr("At") Is DBNull.Value Then
txtAt.Text = "-"
Else
txtAt.Text = dr("At")
End If
If dr("DateAt") Is DBNull.Value Then
txtDateAt.Text = "-"
Else
txtDateAt.Text = dr("DateAt")
End If
If dr("ZoneName") Is DBNull.Value Then
txtZone.Text = "-"
Else
txtZone.Text = dr("ZoneName")
End If
If dr("TypeName") Is DBNull.Value Then
txtTypeName.Text = "-"
Else
txtTypeName.Text = dr("TypeName")
End If
Loop
Else
MsgBox("ไม่พบข้อมูล")
End If
End With
End Sub
'--ปุ่มค้นหา
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim strSearch As String = ""
If RadioButton2.Checked = True Then '--ตามประเภทสินค้า
strSearch = " SELECT CODE,CODESC,NAME1 from qrycustomer where [Zone] = '" & ComboBox1.SelectedValue & "' and GroupType = '" & ComboBox2.SelectedValue & "'"
Cm = New OleDbCommand(strSearch, Cn)
dr = Cm.ExecuteReader
If dr.HasRows Then
dt = New DataTable
dt.Load(dr)
DataGridView1.DataSource = dt
GridviewList()
Else
MessageBox.Show("ไม่พบข้อมูล !!!.. & กรุณาค้นหาใหม่ ", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
DataGridView1.DataSource = Nothing
ClearTextAll()
ClearTextAll2()
End If
Else '-- สินค้าทุกประเภท
strSearch = " SELECT CODE,CODESC,NAME1 from qrycustomer where [Zone] = '" & ComboBox1.SelectedValue & "' "
Cm = New OleDbCommand(strSearch, Cn)
dr = Cm.ExecuteReader
If dr.HasRows Then
dt = New DataTable
dt.Load(dr)
DataGridView1.DataSource = dt
GridviewList()
Else
MessageBox.Show("ไม่พบข้อมูล !!!.. & กรุณาค้นหาใหม่ ", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
DataGridView1.DataSource = Nothing
ClearTextAll()
ClearTextAll2()
End If
End If
End Sub
'--ประเภทสินค้า
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then
ComboBox2.Enabled = True
End If
End Sub
'--สินค้าทุกประเภท
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then
ComboBox2.Enabled = False
End If
End Sub
Private Sub ClearTextAll() '---เคลียร์ข้อมูลทั้งหมด
Dim c As Control
For Each c In Me.Panel3.Controls
If c.GetType Is GetType(TextBox) Then
CType(c, TextBox).Clear()
End If
Next
End Sub
Private Sub ClearTextAll2() '---เคลียร์ข้อมูลทั้งหมด
Dim c As Control
For Each c In Me.Panel4.Controls
If c.GetType Is GetType(TextBox) Then
CType(c, TextBox).Clear()
End If
Next
End Sub
'--ปุ่ม<<Previous
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
_Index -= 1
Label3.Text = "ภาพที่ : " & _Index + 1
Picturebox1.Image = Image.FromFile(ListFile(_Index))
Button2.Enabled = True
If _Index = 0 Then Button1.Enabled = False
End Sub
'--ปุ่ม Next >>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
_Index += 1
Label4.Text = "ภาพที่ : " & _Index + 1
Picturebox1.Image = Image.FromFile(ListFile(_Index))
Button1.Enabled = True
If _Index = ListFile.Length - 1 Then Button2.Enabled = False
End Sub
End Class
ถ้าคลิกกริดวิวเซลแรกที่ไม่มีโฟลเดอร์ชื่อ 48-04-00001 บรรทัดนี้จะError
ListFile = Directory.GetFiles(_Main & DataGridView1.Rows(e.RowIndex).Cells(0).Value, "*.JPG") '--error ว่า Could not find a part of the path 'D:\Pictures\48-04-00001'.
ปุ่ม next>>
Picturebox1.Image = Image.FromFile(ListFile(_Index)) '--error ว่า Index was outside the bounds of the array.
Private Sub frmSlideShow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Connstring = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source="
StrFile = IniFile.GetString("Database", "Server", "Error File")
Connstring = Connstring & StrFile
Connstring = Connstring & "Persist Security Info = False"
Cn = New OleDbConnection(Connstring)
Cn.Open()
RootDirectory = IniFile.GetString("Directory", "Root", "Error File")
_Main = RootDirectory & "\"
Dim str As String = ""
str = "SELECT * FROM TBZONE"
Cm = New OleDbCommand(str, Cn)
dr = Cm.ExecuteReader
dr.Read()
dt = New DataTable
dt.Load(dr)
With ComboBox1
.DisplayMember = "ZoneName" '--ชื่อโซน
.ValueMember = "ZoneCode" '--รหัสโซน
.DataSource = dt
End With
End Sub
โค๊ตที่เหตุการณ์ ComboBox1_SelectedValueChanged คือ
Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
Try
Dim strSearch As String = "SELECT CODE,CODESC,NAME1 from qrycustomer where [Zone] = '" & ComboBox1.SelectedValue & "' "
Cm = New OleDbCommand(strSearch, Cn)
dr = Cm.ExecuteReader
If dr.HasRows Then
dt = New DataTable
dt.Load(dr)
DataGridView1.DataSource = dt
GridviewList()
Else
MessageBox.Show("ไม่พบข้อมูล !!!.. & กรุณาค้นหาใหม่ ", "", MessageBoxButtons.OK, MessageBoxIcon.Warning)
DataGridView1.DataSource = Nothing
ClearTextAll()
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
End Try
End Sub