Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
-
- Public Class Form1
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- If InputFileDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
- inputFile.Text = InputFileDialog.FileName
- otputFileName.Text = IO.Path.GetFileNameWithoutExtension(inputFile.Text) & "_no_dublicates"
- outputSaveDir.Text = IO.Path.GetDirectoryName(inputFile.Text)
- End If
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
- outputSaveDir.Text = FolderBrowserDialog1.SelectedPath
- End If
- End Sub
- Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
- Using csvReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(inputFile.Text, System.Text.Encoding.GetEncoding(1251))
- csvReader.TextFieldType = FileIO.FieldType.Delimited
- csvReader.SetDelimiters(";")
- csvReader.TrimWhiteSpace = True
- Dim currentRow As String()
- Dim brands As Dictionary(Of String, List(Of Integer)) = New Dictionary(Of String, List(Of Integer))
- Dim articles As Dictionary(Of String, List(Of Integer)) = New Dictionary(Of String, List(Of Integer))
- ' Словник з елмементами які мають однаковий артикул і виробника
- ' Структура:
- ' Ідентифікатор який складається з виробника і артикула, номер рядка в файлі, ціна
- ' id -> {
- ' 25687 -> 1325.2,
- ' 35978 -> 1525.0
- '}
- Dim duplicates As Dictionary(Of String, Dictionary(Of Integer, Double)) = New Dictionary(Of String, Dictionary(Of Integer, Double))
- Dim brand As String = ""
- Dim article As String
- While Not csvReader.EndOfData
- Try
- currentRow = csvReader.ReadFields()
- brand = currentRow(2)
- article = currentRow(1)
- ' For some reason real data starts from 3rd row. 2nd line is header
- ' Рядок №2 - заголовок
- If csvReader.LineNumber < 3 Then
- Continue While
- End If
- Dim brands_line_numbers As New List(Of Integer)
- If brands.TryGetValue(brand, brands_line_numbers) Then
- brands_line_numbers.Add(csvReader.LineNumber)
- Else
- Dim nac As New List(Of Integer)
- nac.Add(csvReader.LineNumber)
- brands.Add(brand, nac)
- End If
- Dim articles_line_numbers As New List(Of Integer)
- If articles.TryGetValue(article, articles_line_numbers) Then
- articles_line_numbers.Add(csvReader.LineNumber)
- Else
- Dim aac As New List(Of Integer)
- aac.Add(csvReader.LineNumber)
- articles.Add(article, aac)
- End If
- Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
- MsgBox("Line " & ex.Message & " is invalid. Skipping")
- End Try
- End While
- Dim pair As KeyValuePair(Of String, List(Of Integer))
- Dim pair2 As KeyValuePair(Of String, List(Of Integer))
- ' Виробники
- For Each pair In brands
- ' Артикули
- For Each pair2 In articles
- 'Dim iintersection = pair.Value.Intersect(pair2.Value)
- ' Перетин множин артикули і виробники
- Dim intersection = Enumerable.ToList(pair.Value.Intersect(pair2.Value))
- ' Якщо перетин містить лише один елемент, значить це номер рядка в якому розташована поточна зв'язка виробник + артикул
- If intersection.Count > 1 Then
- Dim output As New System.Text.StringBuilder
- For Each number As Integer In intersection
- Console.WriteLine("bebe {0}", number)
- output.AppendLine(number)
- Dim tmpDict As Dictionary(Of Integer, Double) = New Dictionary(Of Integer, Double)
- ' ціни
- tmpDict.Item(number) = 0.0
- ' ідентифікатор який складається з артикула і назви виробника
- duplicates.Item(pair.Key & pair2.Key) = tmpDict
- Next
- Console.WriteLine("******")
- Console.WriteLine("Intersaction is")
- Console.Write(output)
- Console.WriteLine("******")
- End If
- Next
- Next
- End Using
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement