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
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
Post a Comment