.NET · Coding · Task

Aplikasi Pendaftaran Seller Marketplace Berbasis VB.NET + Koneksi Office

Guys~ saya mau membagikan materi seputar coding lagi nih. Kali ini bahasa yang saya gunakan adalah VB.NET diterapkan di dekstop. Saya masih baru belajar VB.NET, walau sebelumnya udah belajar VB 6, bahasanya gak jauh berbeda. Emang pada dasarnya masiing-masing bahasa metodologi utamanya itu sama.

Deskripsi Singkat :

Aplikasi ini membahas pendaftaran seller/penjual di marketplace yang bernama ENI (ceritanya haha). Marketplace sama sepert shop online yang sudah tersebar di dunia maya. Tapi, marketplace lebih menitikkan pasar umum, dimana siapapun bisa berjualan dengan mendaftar lebih dahulu.

Aplikas ini mempunyai fungsi utama lain:

  1. Terkoneksi dengan microsoft word, sistemnya 1 pendaftar mempunyai 1 dokumen word setiap submit.
  2. Terkoneksi dengan microsoft excel, sistemnya 1 pendaftar mempuyai 1 dokumen excel setiap submit.

Design & Frame:

tugas_design_word

Gambar 1. Template Word untuk Aplikasi

tugas_design_excel

Gambar 2. Template Excel untuk Aplikasi

tugas_demo_1

Gambar 3. Demo: Input data Seller baru

tugas_demo_3

Gambar 4. Pesan sukses ketika submit tombol Export Word Excel
(Export data Seller ke word & excel)

tugas_demo_2_word

Gambar 5. Hasil export ke Word

tugas_demo_4_excel

Gambar 6. Hasil export ke Excel

Ada beberapa logic khusus yang saya tambahkan. Ketika nama file sudah ada (diambil dari nama seller yang diisi), di codingan saya membuat sistem menambahkan angka random setelah nama seller yang ada. Formatnya: form_namaSeller_angkaRandom.

Source Code:

Imports Word = Microsoft.Office.Interop.Word
Imports Excel = Microsoft.Office.Interop.Excel

Public Class Form1
    Private Sub FORM_Enter(sender As Object, e As EventArgs) Handles FORM.Enter
        ckArea.Items.Add("Bogor")
        ckArea.Items.Add("DKI Jakarta")
        ckArea.Items.Add("Depok")
        ckArea.Items.Add("Tangerang Selatan")
        ckArea.Items.Add("Subang")
    End Sub

    Private Sub btnExportE_Click(sender As Object, e As EventArgs) Handles btnExportE.Click
        Dim app As New Excel.Application
        Dim file As Excel.Workbook

        Dim str As String
        str = ""
        For i = 0 To ckArea.Items.Count - 1
            Dim Item As Object = ckArea.Items(i)
            If ckArea.GetItemChecked(i) Then
                str &= Item
                str &= ", "
            End If
        Next

        file = app.Workbooks.Open("C:\Users\Eni\Documents\tugas_uts\form_daftar_excel.xlsx")
        app.Range("C3").Value = txtNama.Text
        app.Range("C4").Value = txtEmail.Text
        app.Range("C5").Value = txtPhone.Text
        app.Range("C6").Value = txtBisnis.Text
        app.Range("C7").Value = str
        app.Range("C8").Value = txtAddr.Text

        Dim fileNew As String = "C:\Users\Eni\Documents\tugas_uts\form-excel\form_" + txtNama.Text + ".xlsx"

        If System.IO.File.Exists(fileNew) Then
            Dim rnd As New Random()
            Dim randomNumber As String = rnd.Next(10, 100)
            fileNew = "C:\Users\Eni\Documents\tugas_uts\form-excel\form_" + txtNama.Text + "" + randomNumber + ".xlsx"
        End If

        file.SaveAs(fileNew)
        MsgBox("Success")
        app.Visible = True
    End Sub

    Private Sub btnExportW_Click(sender As Object, e As EventArgs) Handles btnExportW.Click
        Dim app As New Word.Application
        Dim file As Word.Document

        Dim str As String
        str = ""
        For i = 0 To ckArea.Items.Count - 1
            Dim Item As Object = ckArea.Items(i)
            If ckArea.GetItemChecked(i) Then
                str &= Item
                str &= ", "
            End If
        Next

        file = app.Documents.Open("C:\Users\Eni\Documents\tugas_uts\form_daftar_word.doc")
        file.Bookmarks("full_name").Select()
        app.Selection.TypeText(txtNama.Text)
        file.Bookmarks("ttd").Select()
        app.Selection.TypeText(txtNama.Text)
        file.Bookmarks("email").Select()
        app.Selection.TypeText(txtEmail.Text)
        file.Bookmarks("phone").Select()
        app.Selection.TypeText(txtPhone.Text)
        file.Bookmarks("bussiness_type").Select()
        app.Selection.TypeText(txtBisnis.Text)
        file.Bookmarks("service_area").Select()
        app.Selection.TypeText(str)
        file.Bookmarks("address").Select()
        app.Selection.TypeText(txtAddr.Text)

        Dim fileNew As String = "C:\Users\Eni\Documents\tugas_uts\form-word\form_" + txtNama.Text + ".docx"

        If System.IO.File.Exists(fileNew) Then
            Dim rnd As New Random()
            Dim randomNumber As String = rnd.Next(10, 100)
            fileNew = "C:\Users\Eni\Documents\tugas_uts\form-word\form_" + txtNama.Text + "" + randomNumber + ".docx"
        End If

        file.SaveAs(fileNew)
        MsgBox("Success")
        app.Visible = True
    End Sub

    Private Sub btnExportWE_Click(sender As Object, e As EventArgs) Handles btnExportWE.Click
        Dim app_w As New Word.Application
        Dim file_w As Word.Document

        Dim str As String
        str = ""
        For i = 0 To ckArea.Items.Count - 1
            Dim Item As Object = ckArea.Items(i)
            If ckArea.GetItemChecked(i) Then
                str &= Item
                str &= ", "
            End If
        Next

        file_w = app_w.Documents.Open("C:\Users\Eni\Documents\tugas_uts\form_daftar_word.docx")
        file_w.Bookmarks("full_name").Select()
        app_w.Selection.TypeText(txtNama.Text)
        file_w.Bookmarks("ttd").Select()
        app_w.Selection.TypeText(txtNama.Text)
        file_w.Bookmarks("email").Select()
        app_w.Selection.TypeText(txtEmail.Text)
        file_w.Bookmarks("phone").Select()
        app_w.Selection.TypeText(txtPhone.Text)
        file_w.Bookmarks("bussiness_type").Select()
        app_w.Selection.TypeText(txtBisnis.Text)
        file_w.Bookmarks("service_area").Select()
        app_w.Selection.TypeText(str)
        file_w.Bookmarks("address").Select()
        app_w.Selection.TypeText(txtAddr.Text)

        Dim fileNew_w As String = "C:\Users\Eni\Documents\tugas_uts\form-word\form_" + txtNama.Text + ".docx"

        If System.IO.File.Exists(fileNew_w) Then
            Dim rnd As New Random()
            Dim randomNumber As String = rnd.Next(10, 100)
            fileNew_w = "C:\Users\Eni\Documents\tugas_uts\form-word\form_" + txtNama.Text + "" + randomNumber + ".doc"
        End If

        file_w.SaveAs(fileNew_w)
        app_w.Visible = True

        Dim app_e As New Excel.Application
        Dim file_e As Excel.Workbook

        file_e = app_e.Workbooks.Open("C:\Users\Eni\Documents\tugas_uts\form_daftar_excel.xlsx")
        app_e.Range("C3").Value = txtNama.Text
        app_e.Range("C4").Value = txtEmail.Text
        app_e.Range("C5").Value = txtPhone.Text
        app_e.Range("C6").Value = txtBisnis.Text
        app_e.Range("C7").Value = str
        app_e.Range("C8").Value = txtAddr.Text

        Dim fileNew_e As String = "C:\Users\Eni\Documents\tugas_uts\form-excel\form_" + txtNama.Text + ".xlsx"

        If System.IO.File.Exists(fileNew_e) Then
            Dim rnd As New Random()
            Dim randomNumber As String = rnd.Next(10, 100)
            fileNew_e = "C:\Users\Eni\Documents\tugas_uts\form-excel\form_" + txtNama.Text + "" + randomNumber + ".xlsx"
        End If

        file_e.SaveAs(fileNew_e)
        MsgBox("Success")
        app_e.Visible = True
    End Sub

    Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
        txtNama.Text = ""
        txtEmail.Text = ""
        txtPhone.Text = ""
        txtBisnis.Text = ""
        txtAddr.Text = ""
        ckArea.ClearSelected()
        For i As Integer = 0 To ckArea.Items.Count - 1
            ckArea.SetItemChecked(i, False)
        Next
    End Sub
End Class
Iklan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Google

You are commenting using your Google account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s