Private Sub cmdExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExport.Click
sb.Remove(0, sb.Length)
'sb.Append(" SELECT Human.FullName, Position.PositionName From Human INNER JOIN Position ON Human.PID = Position.PID ")
sb.Append("SELECT Position.PositionName, Human.FullName ")
sb.Append(" FROM Position, Human ")
sb.Append(" WHERE Position.PID = Human.PID ")
' sb.Append(" AND Position.PID = @PID")
Dim sqlSearch As String
sqlSearch = sb.ToString()
With com
.CommandText = sqlSearch
.CommandType = CommandType.Text
.Connection = Conn
.Parameters.Clear()
' .Parameters.Add("@PID", SqlDbType.NVarChar).Value = cboPosition.SelectedValue.ToString()
dr = .ExecuteReader()
If dr.HasRows Then
Dim dtHuman As DataTable
dtHuman = New DataTable()
dtHuman.Load(dr)
With sfDlg2
.Title = "บันทึกไฟล์"
.Filter = "ไฟล์ Crystal Report (*.rpt)|*.rpt|ไฟล์ Excel (*.xls)|*.xls|ไฟล์ Adobe Acobat (*.pdf)|*.pdf|ไฟล์ Rich Text Box (*.rtf)|*.rtf|ไฟล์ Word (*.doc)|*.doc"
.FileName = "Time_Card"
.FilterIndex = 5
End With
If sfDlg2.ShowDialog() = Windows.Forms.DialogResult.OK Then
Me.Cursor = Cursors.WaitCursor
Dim strFileName As String
strFileName = sfDlg2.FileName
Dim HumanDetail2 As CryHumanDetail2
HumanDetail2 = New CryHumanDetail2()
HumanDetail2.SetDataSource(dtHuman)
Dim dfdo As DiskFileDestinationOptions
dfdo = New DiskFileDestinationOptions()
dfdo.DiskFileName = strFileName
Dim eo As ExportOptions = HumanDetail2.ExportOptions
With eo
eo.DestinationOptions = dfdo
eo.ExportDestinationType = ExportDestinationType.DiskFile
Select Case sfDlg2.FilterIndex
Case 1
eo.ExportFormatType = ExportFormatType.CrystalReport
Case 2
eo.ExportFormatType = ExportFormatType.Excel
Case 3
eo.ExportFormatType = ExportFormatType.PortableDocFormat
Case 4
eo.ExportFormatType = ExportFormatType.RichText
Case 5
eo.ExportFormatType = ExportFormatType.WordForWindows
End Select
End With
HumanDetail2.Export()
Me.Cursor = Cursors.Default
MessageBox.Show("Export ไฟล์ เรียบร้อยแล้ว !!!", "ผลการค้นหา", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Else
MessageBox.Show("ตำแหน่งงานที่คุณเลือก ไม่มีรายชื่อพนักงาน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If