Skip to main content

Skip Rows In Uploading .xls Files

Private Sub DATA_TOBE_SAVE()

        OfdBUKAFILE.Filter = "*.xlsx|*.xlsx|All files(*.*)|*.*"
        If OfdBUKAFILE.ShowDialog = Windows.Forms.DialogResult.OK Then
            Try
                Conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & _
                     "Data Source='" & OfdBUKAFILE.FileName & "';Extended Properties=Excel 12.0;")
                DA = New OleDbDataAdapter("SELECT * FROM [FIXED_ORDER_MONTHLY$]", Conn)

                DTTemp = New DataTable
                Conn.Open()
                DA.Fill(DTTemp)

                'Skip Datatable Rows.. ini skip 2 baris...
                Dim BarisBaru As IEnumerable(Of DataRow) = DTTemp.AsEnumerable().Skip(2)
                Dim DT As DataTable = BarisBaru.CopyToDataTable()
                'Skip Datatable Rows.. ini skip 2 baris...

                Dim DT_Check_Upload As New DataTable
                For Each tCol As DataColumn In DT.Columns
                    Dim ColName As String = tCol.ColumnName
                    If Microsoft.VisualBasic.Left(ColName, 1) <> "F" Then
                        DT_Check_Upload.Columns.Add(ColName, Type.GetType("System.String"))
                    End If
                Next

                Dim DT_Duplicate As New DataTable
                For Each tCol As DataColumn In DT.Columns
                    Dim ColName As String = tCol.ColumnName
                    If Microsoft.VisualBasic.Left(ColName, 1) <> "F" Then
                        DT_Duplicate.Columns.Add(ColName, Type.GetType("System.String"))
                    End If
                Next

                For TT As Integer = 0 To DT.Rows.Count - 1
                    If TT = 0 Then
                        DT_Check_Upload.Rows.Add(DT.Rows(TT)("SECTION"),
                                                 DT.Rows(TT)("MONTH"),
                                                 DT.Rows(TT)("YEAR"),
                                                 DT.Rows(TT)("PLANT"),
                                                 DT.Rows(TT)("COUPON_QTY"),
                                                 DT.Rows(TT)("ANNOTATION"))

                    ElseIf TT > 0 Then
                        Dim R As Integer = TT - 1
                        For G As Integer = R To DT_Check_Upload.Rows.Count - 1
                            Dim tmpCHECK = DT.Select("SECTION = '" & DT_Check_Upload.Rows(G)("SECTION") & "' " & _
                                                     "AND MONTH = '" & DT_Check_Upload.Rows(G)("MONTH") & "' " & _
                                                     "AND YEAR = '" & DT_Check_Upload.Rows(G)("YEAR") & "' " & _
                                                     "AND PLANT = '" & DT_Check_Upload.Rows(G)("PLANT") & "' " & _
                                                     "AND COUPON_QTY = '" & DT_Check_Upload.Rows(G)("COUPON_QTY") & "' " & _
                                                     "AND ANNOTATION = '" & DT_Check_Upload.Rows(G)("ANNOTATION") & "' ")

                            If tmpCHECK.Length > 1 Then
                                DT_Duplicate.Rows.Add(tmpCHECK(0)("SECTION"),
                                                 tmpCHECK(0)("MONTH"),
                                                 tmpCHECK(0)("YEAR"),
                                                 tmpCHECK(0)("PLANT"),
                                                 tmpCHECK(0)("COUPON_QTY"),
                                                 tmpCHECK(0)("ANNOTATION"))

                            ElseIf tmpCHECK.Length <= 1 Then
                                DT_Check_Upload.Rows.Add(DT.Rows(TT)("SECTION"),
                                              DT.Rows(TT)("MONTH"),
                                              DT.Rows(TT)("YEAR"),
                                              DT.Rows(TT)("PLANT"),
                                              DT.Rows(TT)("COUPON_QTY"),
                                              DT.Rows(TT)("ANNOTATION"))

                            End If
                        Next G
                    End If
                Next TT

                If DT_Duplicate.Rows.Count > 0 Then
                    DgvDATA.DataSource = DT_Duplicate
                    Dim Hasil As DialogResult = _
                        MsgBox("Some data on your uploaded list cannot be processed" & vbCrLf & _
                        "Please remove as mentioned items from your list" & vbCrLf & _
                        "Application will saved checked item to remove in .xlsx file",
                        MsgBoxStyle.YesNo, Me.Text)

                    If Hasil = DialogResult.Yes Then
                        ExportToExcelFromGridview()

                    Else
                        Exit Sub

                    End If

                ElseIf DT_Duplicate.Rows.Count = 0 Then
                    LvDATA.Columns.Clear()
                    LvDATA.Items.Clear()
                    LvDATA.View = View.Details
                    LvDATA.GridLines = True
                    LvDATA.FullRowSelect = True

                    For Each tCol As DataColumn In DT_Check_Upload.Columns
                        Dim ColName As String = tCol.ColumnName
                        If Microsoft.VisualBasic.Left(ColName, 1) <> "F" Then
                            LvDATA.Columns.Add(ColName, 90, HorizontalAlignment.Left)
                        End If
                    Next

                    Try
                        Dim myRow As DataRow
                        For Each myRow In DT_Check_Upload.Rows
                            LvDATA.Items.Add(myRow.Item(0))
                            For myCol As Integer = 1 To DT_Check_Upload.Columns.Count - 1
                                LvDATA.Items(LvDATA.Items.Count - 1).SubItems.Add(CStr(IIf(myRow.Item(myCol) _
                                IsNot DBNull.Value, myRow.Item(myCol), "")))
                            Next
                        Next

                    Catch ex As Exception
                        MsgBox("you have trouble with your uploaded data file list" & vbCrLf & vbCrLf & _
                                "To solve it, please check your data carefully or block next " & _
                                "row from the last row until end of excel rows" & vbCrLf & _
                                "Then delete those all rows ")

                        LblMESSAGE.Visible = False
                        LvDATA.Items.Clear()

                        MsgBox(ex.ToString)
                        Exit Sub

                    End Try

                    LvDATA.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize)
                    Conn.Close()

                    LblMESSAGE.Text = "Uploaded " & LvDATA.Items.Count & " Rows Data"
                    LblMESSAGE.Visible = True
                    LblMESSAGE.Text = "Please Wait While Saving Data !!!!"

                    SAVE_DATA_UPLOAD()
                    MsgBox("Data has been saved properly", MsgBoxStyle.Information, "TEENSYS")

                End If

            Catch ex As Exception
                MsgBox("You're Uploading Incorrect Template !!")
                MsgBox(ex.ToString)
                PgBAR.Visible = False

            End Try

        ElseIf OfdBUKAFILE.ShowDialog = Windows.Forms.DialogResult.Cancel Then
            Exit Sub

        End If

    End Sub

Comments

Popular posts from this blog

CheckBox dalam DataGridView VB.Net

Pada saat membuat aplikasi (VB.Net) untuk materi skripsi, terbesit bagaimana cara baru untuk memberikan hak akses user secara dinamis pada sistem. setelah dicoba dengan tanya-tanya. akhirnya bisa mendapatkan cara itu... wah sesuatu banget dah.... inti dari posting ini hanya pada barisan kode berikut : Private Sub BtnSIMPAN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSIMPAN.Click         Dim Y As String = Mid(CmbUSER.Text, 1, 7)         Dim iROW As Integer         Dim AKSES As String         For iROW = 0 To DGVSample.Rows.Count - 1             'AksesBox = Nama CheckBox yang ada di DatagridView             If DGVSample.Rows(iROW).Cells("AksesBox").Value Then                 AKSES = "1"             Else                 AKSES = "0"             End If             'Class Proses DML (Simpan Data)             xSIMPAN.SIMPAN_AKSES(Y, DGVSample.Rows(iROW).Cells(1).Value, AKSES)         N

LDAP In VB.Net

hey there friends,  here is this i would like to share another simple code in developing an application in VB.Net by now i would like to share how the way to use a LDAP (Lightweight Directory Access Protocol). at the time i need to develop a system which needs to use login user using domain user (ex: peoplename@company.co.id) no longer using user level in database. it is so confused to me to make it real at the time, because i never make it before. but this is the way how i make it happened. just make a simple form as below : next level : add another reference in your visual studio project (System.DirectoryService.dll) next : make a new class Imports System Imports System.Text Imports System.Collections Imports System.Security.Principal Imports System.DirectoryServices Public Class LDAPControlClass     Private NamaDomain As String = "company.co.id"     Private MemberOf As New List(Of String)     Public Function LoginLDAP(ByVal Username