SHARE
TWEET

VB .NET : Berhasil Cetak Multiple PDF

stevennathaniel Mar 5th, 2018 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System
  2.  
  3. Imports System.IO
  4.  
  5. Imports System.Data.SqlClient
  6.  
  7. Imports System.Data.Odbc
  8.  
  9. Imports System.Data.DataRowExtensions
  10.  
  11. Imports System.Data.DataTableExtensions
  12.  
  13. Imports System.Data.DataTableCollection
  14.  
  15. Imports System.Linq
  16.  
  17. Imports System.Xml
  18.  
  19. Imports System.Windows.Forms
  20.  
  21. Imports DevExpress.XtraReports.UI
  22.  
  23.  
  24.  
  25. Public Class Form2
  26.  
  27.  
  28.     ' Source code di bawah ini berhasil mencetak multiple file PDF:
  29.  
  30.  
  31.     Dim KODE_BAG As String
  32.  
  33.     Dim NAMA_BAG As String
  34.  
  35.     Dim nip As String
  36.  
  37.     Dim bulanTahun As String
  38.  
  39.     Dim alamatemail As String
  40.  
  41.     Dim TGL As String
  42.  
  43.     Dim nama As String
  44.  
  45.     Dim jumlahBaris As Integer
  46.  
  47.  
  48.     Dim tabelBayangan As DataTable = New DataTable("tabelBayangan")
  49.  
  50.     Dim columnBayangan As DataColumn
  51.  
  52.     Dim rowBayangan As DataRow
  53.  
  54.  
  55.     Sub kotakKombo()
  56.  
  57.         Dim datasetBagian As New DataSet
  58.  
  59.         Dim tabelDataBagian As New DataTable
  60.  
  61.         Dim koneksi As New OdbcConnection("DSN=latihan")
  62.  
  63.         datasetBagian = New DataSet("datasetBagian")
  64.  
  65.         tabelDataBagian = New DataTable("tabelDataBagian")
  66.  
  67.  
  68.         datasetBagian.Tables.Add(tabelDataBagian)
  69.  
  70.         tabelDataBagian.AcceptChanges()
  71.  
  72.         datasetBagian.AcceptChanges()
  73.  
  74.         Try
  75.  
  76.             koneksi.Open()
  77.  
  78.             Dim dAdapter As OdbcDataAdapter = New OdbcDataAdapter("SELECT bag.KODE_BAG,bag.NAMA_BAG FROM bag", koneksi)
  79.  
  80.             dAdapter.Fill(tabelDataBagian)
  81.  
  82.             tabelDataBagian.AcceptChanges()
  83.  
  84.             ComboBox1.DataSource = tabelDataBagian
  85.  
  86.             ComboBox1.DisplayMember = "NAMA_BAG"
  87.  
  88.             ComboBox1.ValueMember = "KODE_BAG"
  89.  
  90.  
  91.  
  92.         Catch ex As OdbcException
  93.  
  94.             Console.WriteLine(ex.ToString)
  95.  
  96.         End Try
  97.  
  98.     End Sub
  99.  
  100.  
  101.     Sub hapus()
  102.  
  103.         Dim perintah As OdbcCommand = New OdbcCommand
  104.  
  105.         Dim koneksi As New OdbcConnection("DSN=latihan")
  106.  
  107.         Try
  108.  
  109.             koneksi.Open()
  110.  
  111.             perintah.Connection = koneksi
  112.  
  113.             perintah.CommandText = "DELETE FROM slipgaji1"
  114.  
  115.             perintah.ExecuteNonQuery()
  116.  
  117.             koneksi.Close()
  118.  
  119.             koneksi.Dispose()
  120.  
  121.  
  122.         Catch ex As OdbcException
  123.  
  124.             Console.WriteLine(ex.ToString)
  125.  
  126.         End Try
  127.     End Sub
  128.  
  129.  
  130.     Sub simpan()
  131.  
  132.         Dim koneksi As New OdbcConnection("DSN=latihan")
  133.  
  134.         Dim perintah As New OdbcCommand
  135.  
  136.         Try
  137.  
  138.             bulanTahun = DateTimePicker1.Value.Date.ToString("yyyy-MM")
  139.  
  140.             KODE_BAG = ComboBox1.SelectedValue.ToString
  141.  
  142.             koneksi.Open()
  143.  
  144.             perintah.Connection = koneksi
  145.  
  146.             perintah.CommandText = "INSERT INTO slipgaji1(slipgaji1.nip,slipgaji1.alamatemail,slipgaji1.KODE_BAG,slipgaji1.nama,slipgaji1.NAMA_BAG,slipgaji1.TGL) SELECT emailtest.nip,emailtest.alamatemail,sdmgaji.KODE_BAG,pegawai_lookup.nama,bag.NAMA_BAG,sdmgaji.TGL FROM sdmgaji INNER JOIN emailtest ON sdmgaji.NIP=emailtest.nip INNER JOIN pegawai_lookup ON sdmgaji.NIP=pegawai_lookup.nip INNER JOIN bag ON sdmgaji.KODE_BAG=bag.KODE_BAG WHERE sdmgaji.KODE_BAG='" & KODE_BAG & "' AND sdmgaji.TGL LIKE '" & bulanTahun & "%';"
  147.  
  148.             perintah.ExecuteNonQuery()
  149.  
  150.  
  151.  
  152.  
  153.         Catch ex As OdbcException
  154.  
  155.             Console.WriteLine(ex.ToString)
  156.  
  157.         End Try
  158.  
  159.     End Sub
  160.  
  161.  
  162.     Sub tampilIsiDataGrid()
  163.  
  164.         Dim koneksi As New OdbcConnection("DSN=latihan")
  165.  
  166.         Dim tabelDataGrid As New DataTable
  167.  
  168.         Try
  169.  
  170.             koneksi.Open()
  171.  
  172.             Dim dAdapter As OdbcDataAdapter = New OdbcDataAdapter("SELECT slipgaji1.nip,slipgaji1.alamatemail,slipgaji1.KODE_BAG,slipgaji1.TGL,slipgaji1.nama,slipgaji1.NAMA_BAG FROM slipgaji1;", koneksi)
  173.  
  174.             dAdapter.Fill(tabelDataGrid)
  175.  
  176.             tabelDataGrid.AcceptChanges()
  177.  
  178.  
  179.             DataGridView1.DataSource = tabelDataGrid
  180.  
  181.             DataGridView1.Columns(0).Name = "nip"
  182.  
  183.             DataGridView1.Columns(0).DataPropertyName = "NIP"
  184.  
  185.             DataGridView1.Columns(0).HeaderText = "NIP"
  186.  
  187.             DataGridView1.Columns(0).HeaderCell.Style.Font = New System.Drawing.Font("Arial", 10, Drawing.FontStyle.Bold)
  188.  
  189.  
  190.  
  191.             DataGridView1.Columns(1).Name = "alamatemail"
  192.  
  193.             DataGridView1.Columns(1).DataPropertyName = "alamatemail"
  194.  
  195.             DataGridView1.Columns(1).HeaderText = "Alamat E-Mail"
  196.  
  197.             DataGridView1.Columns(1).HeaderCell.Style.Font = New System.Drawing.Font("Arial", 10, Drawing.FontStyle.Bold)
  198.  
  199.  
  200.             DataGridView1.Columns(2).Name = "KODE_BAG"
  201.  
  202.             DataGridView1.Columns(2).DataPropertyName = "KODE_BAG"
  203.  
  204.             DataGridView1.Columns(2).HeaderText = "Kode Bagian"
  205.  
  206.             DataGridView1.Columns(2).HeaderCell.Style.Font = New System.Drawing.Font("Arial", 10, Drawing.FontStyle.Bold)
  207.  
  208.  
  209.  
  210.             DataGridView1.Columns(3).Name = "TGL"
  211.  
  212.             DataGridView1.Columns(3).DefaultCellStyle.Format = "MMMM yyyy"
  213.  
  214.             DataGridView1.Columns(3).DataPropertyName = "TGL"
  215.  
  216.             DataGridView1.Columns(3).HeaderText = "Periode"
  217.  
  218.             DataGridView1.Columns(3).HeaderCell.Style.Font = New System.Drawing.Font("Arial", 10, Drawing.FontStyle.Bold)
  219.  
  220.  
  221.  
  222.             DataGridView1.Columns(4).Name = "nama"
  223.  
  224.             DataGridView1.Columns(4).DataPropertyName = "nama"
  225.  
  226.             DataGridView1.Columns(4).HeaderText = "Nama Pegawai"
  227.  
  228.             DataGridView1.Columns(4).HeaderCell.Style.Font = New System.Drawing.Font("Arial", 10, Drawing.FontStyle.Bold)
  229.  
  230.  
  231.  
  232.             DataGridView1.Columns(5).Name = "NAMA_BAG"
  233.  
  234.             DataGridView1.Columns(5).DataPropertyName = "NAMA_BAG"
  235.  
  236.             DataGridView1.Columns(5).HeaderText = "Nama Bagian"
  237.  
  238.  
  239.  
  240.  
  241.             DataGridView1.AutoResizeColumns()
  242.  
  243.  
  244.  
  245.         Catch ex As OdbcException
  246.  
  247.             Console.WriteLine(ex.ToString)
  248.  
  249.         End Try
  250.  
  251.         koneksi.Close()
  252.  
  253.         koneksi.Dispose()
  254.  
  255.  
  256.     End Sub
  257.  
  258.  
  259.     Sub buatLaporan()
  260.  
  261.         Dim datasetLaporan As New DataSet("datasetLaporan")
  262.  
  263.         Dim tabelLaporan As New DataTable("tabelLaporan")
  264.  
  265.  
  266.  
  267.         datasetLaporan.Tables.Add(tabelLaporan)
  268.  
  269.         tabelLaporan.AcceptChanges()
  270.  
  271.         datasetLaporan.AcceptChanges()
  272.  
  273.  
  274.         Dim koneksi As New OdbcConnection("DSN=latihan")
  275.  
  276.  
  277.         Try
  278.  
  279.  
  280.             koneksi.Open()
  281.  
  282.  
  283.             Dim dAdapter As OdbcDataAdapter = New OdbcDataAdapter("SELECT slipgaji1.nip,slipgaji1.alamatemail,slipgaji1.KODE_BAG,slipgaji1.TGL,slipgaji1.nama,slipgaji1.NAMA_BAG,slipgaji1.idslipgaji1 FROM slipgaji1", koneksi)
  284.  
  285.  
  286.             dAdapter.Fill(tabelLaporan)
  287.  
  288.             tabelLaporan.AcceptChanges()
  289.  
  290.             datasetLaporan.AcceptChanges()
  291.  
  292.             tabelLaporan.WriteXml("C:\STEVEN\ProyekVB\Latihan7\Latihan7\Latihan7\bin\Debug\data\test.xml", XmlWriteMode.WriteSchema, True)
  293.  
  294.             jumlahBaris = tabelLaporan.Rows.Count
  295.  
  296.             Label5.Text = jumlahBaris.ToString
  297.  
  298.  
  299.  
  300.  
  301.             For i As Integer = 1 To jumlahBaris
  302.  
  303.                 Dim query = From laporan In tabelLaporan.AsEnumerable() Where laporan("idslipgaji1") = i Select laporan
  304.  
  305.                 tabelBayangan = query.CopyToDataTable
  306.  
  307.  
  308.                 For Each rowBayangan In tabelBayangan.Rows
  309.  
  310.  
  311.                     Dim penulis2 As New System.IO.StringWriter
  312.  
  313.                     Dim namaFile As String
  314.  
  315.                     tabelBayangan.TableName = "tabelBayangan"
  316.  
  317.                     namaFile = rowBayangan(4)
  318.  
  319.                     tabelBayangan.WriteXml(penulis2, XmlWriteMode.WriteSchema, True)
  320.  
  321.                     tabelBayangan.WriteXml("C:\STEVEN\ProyekVB\Latihan7\Latihan7\Latihan7\bin\Debug\data\data.xml", XmlWriteMode.WriteSchema, True)
  322.  
  323.                     Dim laporan As New XtraReport1
  324.  
  325.                     laporan.ExportToPdf("C:\STEVEN\ProyekVB\Latihan7\Latihan7\Latihan7\bin\Debug\filePDF\" & namaFile & ".pdf")
  326.  
  327.  
  328.  
  329.                 Next rowBayangan
  330.  
  331.  
  332.             Next i
  333.  
  334.         Catch ex As OdbcException
  335.  
  336.             Console.WriteLine(ex.ToString)
  337.  
  338.         End Try
  339.  
  340.         koneksi.Close()
  341.  
  342.         koneksi.Dispose()
  343.  
  344.  
  345.  
  346.  
  347.     End Sub
  348.  
  349.  
  350.  
  351.  
  352.  
  353.     Sub resetIdSlipGaji1()
  354.  
  355.         Dim koneksi As New OdbcConnection("DSN=latihan")
  356.  
  357.         Try
  358.  
  359.             Dim perintah As New OdbcCommand("ALTER TABLE slipgaji1 AUTO_INCREMENT = 1", koneksi)
  360.  
  361.             koneksi.Open()
  362.  
  363.             perintah.ExecuteNonQuery()
  364.  
  365.  
  366.  
  367.         Catch ex As odbcException
  368.  
  369.         End Try
  370.  
  371.         koneksi.Close()
  372.  
  373.         koneksi.Dispose()
  374.  
  375.  
  376.  
  377.     End Sub
  378.  
  379.  
  380.     Sub cetakXmlTabelBayangan()
  381.  
  382.         tabelBayangan.WriteXml("C:\STEVEN\ProyekVB\Latihan7\Latihan7\Latihan7\bin\Debug\data\tabelBayangan.xml", XmlWriteMode.WriteSchema, True)
  383.  
  384.  
  385.     End Sub
  386.  
  387.     Private Sub Form2_Load(sender As Object, e As EventArgs) Handles Me.Load
  388.  
  389.         'Dim tabelBayangan As DataTable = New DataTable("tabelBayangan")
  390.  
  391.         'Dim columnBayangan As DataColumn
  392.  
  393.         'Dim rowBayangan As DataRow
  394.  
  395.  
  396.         kotakKombo()
  397.  
  398.         DateTimePicker1.MinDate = New DateTime(1900, 1, 1)
  399.  
  400.         DateTimePicker1.MaxDate = DateTime.Today
  401.  
  402.         DateTimePicker1.CustomFormat = "MMMM yyyy"
  403.  
  404.         DateTimePicker1.Format = DateTimePickerFormat.Custom
  405.  
  406.         DateTimePicker1.ShowUpDown = True
  407.  
  408.         Label4.Text = ComboBox1.SelectedValue.ToString
  409.  
  410.  
  411.  
  412.         ' Membuat datatabel tabelBayangan  dan kolom-kolomnya seperti di datatabel tabelLaporan
  413.  
  414.  
  415.         ' Membuat kolom nip di datatabel tabelBayangan
  416.        ' rowBayangan(0), columnBayangan(0)
  417.  
  418.         columnBayangan = New DataColumn
  419.  
  420.         columnBayangan.DataType = System.Type.GetType("System.String")
  421.  
  422.         columnBayangan.ColumnName = "nip"
  423.  
  424.         tabelBayangan.Columns.Add(columnBayangan)
  425.  
  426.  
  427.  
  428.         ' Membuat kolom alamatemail di datatabel tabelBayangan
  429.        ' rowBayangan(1), columnBayangan(1)
  430.  
  431.         columnBayangan = New DataColumn
  432.  
  433.         columnBayangan.DataType = System.Type.GetType("System.String")
  434.  
  435.         columnBayangan.ColumnName = "alamatemail"
  436.  
  437.         tabelBayangan.Columns.Add(columnBayangan)
  438.  
  439.  
  440.  
  441.         ' Membuat kolom KODE_BAG di datatabel tabelBayangan
  442.        ' rowBayangan(2), columnBayangan(2)
  443.  
  444.         columnBayangan = New DataColumn
  445.  
  446.         columnBayangan.DataType = System.Type.GetType("System.String")
  447.  
  448.         columnBayangan.ColumnName = "KODE_BAG"
  449.  
  450.         tabelBayangan.Columns.Add(columnBayangan)
  451.  
  452.  
  453.  
  454.         ' Membuat kolom TGL di datatabel tabelBayangan
  455.        ' rowBayangan(3), columnBayangan(3)
  456.  
  457.         columnBayangan = New DataColumn
  458.  
  459.         columnBayangan.DataType = System.Type.GetType("System.String")
  460.  
  461.         columnBayangan.ColumnName = "TGL"
  462.  
  463.         tabelBayangan.Columns.Add(columnBayangan)
  464.  
  465.  
  466.  
  467.         ' Membuat kolom nama di datatabel tabelBayangan
  468.        ' rowBayangan(4), columnBayangan(4)
  469.  
  470.         columnBayangan = New DataColumn
  471.  
  472.         columnBayangan.DataType = System.Type.GetType("System.String")
  473.  
  474.         columnBayangan.ColumnName = "nama"
  475.  
  476.         tabelBayangan.Columns.Add(columnBayangan)
  477.  
  478.  
  479.  
  480.         ' Membuat kolom NAMA_BAG di datatabel tabelBayangan
  481.        ' rowBayangan(5), columnBayangan(5)
  482.  
  483.         columnBayangan = New DataColumn
  484.  
  485.         columnBayangan.DataType = System.Type.GetType("System.String")
  486.  
  487.         columnBayangan.ColumnName = "NAMA_BAG"
  488.  
  489.         tabelBayangan.Columns.Add(columnBayangan)
  490.  
  491.  
  492.  
  493.         ' Membuat kolom idslipgaji1 di datatabel tabelBayangan
  494.        ' rowBayangan(6), columnBayangan(6)
  495.  
  496.         columnBayangan = New DataColumn
  497.  
  498.         columnBayangan.DataType = System.Type.GetType("System.Int32")
  499.  
  500.         columnBayangan.ColumnName = "idgaji"
  501.  
  502.         tabelBayangan.Columns.Add(columnBayangan)
  503.  
  504.  
  505.         tabelBayangan.AcceptChanges()
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.     End Sub
  515.  
  516.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  517.  
  518.         ' Simpan Data
  519.  
  520.  
  521.  
  522.         hapus()
  523.  
  524.         resetIdSlipGaji1()
  525.  
  526.  
  527.         simpan()
  528.  
  529.         buatLaporan()
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.     End Sub
  537.  
  538.     Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged
  539.  
  540.         Label3.Text = DateTimePicker1.Value.ToString("MMMM yyyy")
  541.  
  542.  
  543.     End Sub
  544.  
  545.     Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
  546.  
  547.         Label4.Text = ComboBox1.SelectedValue.ToString
  548.  
  549.  
  550.     End Sub
  551.  
  552.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  553.  
  554.         cetakXmlTabelBayangan()
  555.  
  556.  
  557.  
  558.     End Sub
  559. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top