'CSV2 Öffnen ##############################################################
Private Sub csv2_Click(sender As Object, e As EventArgs) Handles csv2.Click
Dim file_open_ebay As New OpenFileDialog
file_open_ebay.Filter = "csv-dateien|*.csv"
file_open_ebay.AddExtension = True
If file_open_ebay.ShowDialog = DialogResult.OK Then
'CSV-Files lesen
ds.Tables.Add(LoadCSV(file_open_ebay.FileName))
If Not ds.Tables.Count = 2 Then
MessageBox.Show("Eine Datei konnte nicht gelesen werden")
Exit Sub
End If
'Datarelation
'Dim dr As New DataRelation("Artikel", ds.Tables(0).Columns(
' "SP_2"), ds.Tables(1).Columns("SP_13"), False)
Dim field As String = "asasdasd H0 weqwewqe 345"
'bei Faller den zweiten Abschnitt als Art.Nr. verwenden
Dim startindex As Integer = 0, positionbehind As Integer = -1
Dim numberpart As String
Do
numberpart = FindFirstNumber(field, startindex, , _
positionbehind)
startindex = positionbehind
Loop While startindex > 0 And numberpart = "0"
'Neue Spalten erstellen und Zeilen mit dem Teilstring (=Nummer)
' füllen
Dim columnwithnumber1 As String = CreateNumberColumn(DirectCast( _
ds.Tables(0), cDataTableCSV), "SP_2")
Dim columnwithnumber2 As String = CreateNumberColumn(DirectCast( _
ds.Tables(1), cDataTableCSV), "SP_13")
'Datarelation
Dim dr As New DataRelation("Artikel", ds.Tables(0).Columns( _
columnwithnumber1), ds.Tables(1).Columns(columnwithnumber2), _
False)
ds.Relations.Add(dr)
'Spalten in Ausgabedatei erstellen
dtout = New cDataTableCSV
dtout.Columns.Add("SP_0") : dtout.Columns.Add("SP_1")
dtout.Columns.Add("SP_2") : dtout.Columns.Add("SP_3")
dtout.Columns.Add("SP_4")
dtout.Rows.Add({"Action", "ItemID", "EndCode"})
Try
'Schleife über csv1-Zeilen (=Parent)
For Each prow As DataRow In ds.Tables(0).Rows
'Suchkriterium in csv1 nur Artikel die als Stückzahl 0
' haben.
If DirectCast(prow("SP_4"), String) = "0" Then
'per Relation zugeordnete Childrow in csv2
For Each crow As DataRow In prow.GetChildRows(dr)
'Ausgabedatensatz aufbauen
Dim orow As DataRow = dtout.NewRow
orow("SP_0") = "End"
orow("SP_1") = crow("SP_0")
orow("SP_2") = "NotAvailable"
orow("SP_3") = crow("SP_13") 'Titel
orow("SP_4") = prow("SP_4") 'Anzahl der Artikel
dtout.Rows.Add(orow)
Next crow
End If
Next prow
Catch ex As Exception
MessageBox.Show("Abbruch - Fehler: " & ex.Message)
Exit Sub
End Try
DataGridView3.DataSource = dtout
DataGridView3.Columns(0).Width = 383
DataGridView3.Columns(1).Width = 383
DataGridView3.Columns(2).Width = 383
DataGridView3.Columns(3).Width = 383
DataGridView3.Columns(4).Width = 383
End If
End Sub
'Speichern Funktion
' ##############################################################
Private Sub csv_safe_Click(sender As Object, e As EventArgs) Handles _
csv_safe.Click
ProgressBar2.Value = 0
Label10.Text = "0 %"
SaveFileDialog2.Filter = "Artikel (*.csv)|*.csv"
If SaveFileDialog2.ShowDialog() = DialogResult.OK Then
Timer3.Start()
End If
End Sub
Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles _
Timer3.Tick
ProgressBar2.Increment(1)
If ProgressBar2.Value = 100 Then
Timer3.Stop()
If Not dtout.SaveFile(SaveFileDialog2.FileName, ";"c) Then
MessageBox.Show("Fehler beim Schreiben der Datei")
Else
MessageBox.Show _
(dtout.Rows.Count.ToString & " Artikel sind zu löschen")
End If
Else
ProgressBar2.Value = ProgressBar2.Value + 1
End If
Label10.Text = ProgressBar2.Value & (" %")
End Sub Hier noch ein Bild von der Form:
Da ist bestimmt einiges noch zu verbessern |