操作和显示到DataGrid中的数据重复数据删除阵列 [英] Manipulate and Dedupe Array of data for display into DataGrid

查看:128
本文介绍了操作和显示到DataGrid中的数据重复数据删除阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把他们带到遵循以下格式我的VB程序的.Net数据数组。

 订购号|描述|颜色|大小|总数量|在线订购日期|预期D.D.
2273448 | NOK不透明膝盖高|黑色| X | 001 | 2013年2月12日| 2013年5月12日
2231428 | UX XR WARM大腿袜| NAVY | ONE SIZE | 001 | 2013年2月12日| 2013年5月12日
2231428 | NHS SOFTHOLD套牢|黑色| X | 001 | 2013年2月12日| 2013年5月12日
2265640 | KX XR WARM TIGHTS |黑色| XXL | 001 | 2013年2月12日| 2013年5月12日
2273448 | NOK不透明膝盖高|黑色| X | 001 | 2013年2月12日| 2013年5月12日
2231428 | NHS SOFTHOLD套牢|黑色| X | 001 | 2013年2月12日| 2013年5月12日
2231428 | NHS SOFTHOLD套牢|自然科学| X | 001 | 2013年2月12日| 2013年5月12日
2267461 | WF-01触发器|黑色| 13 | 001 | 2013年2月12日| 2013年5月12日
2231428 | NHS SOFTHOLD套牢|自然科学| X | 001 | 2013年2月12日| 2013年5月12日
2273007 | CR棉袜子富|黑色| 4-7 | 001 | 2013年2月12日| 2013年6月12日
2273127 | TH热袜子| MOSS | 6-11 | 001 | 2013年2月12日| 2013年6月12日

这是我无法控制的一个pre-管道格式的文本文件。

我试图把这个数据到一个VB的DataGrid,但我做之前,我想重复数据删除的价值,同时计数他们,这样我就可以只显示相关的数据,没有重复的行,所以该程序用户然后可以选择所有相关行的行和工作(即减少人为错误的可能性。

预期输出到DataGrid,基于上述情况,会是这样...

 订单号|在订单行|订购日期|预产期
2273448 | 2 | 2013年2月12日| 2013年5月12日
2231428 | 5 | 2013年2月12日| 2013年5月12日
2265640 | 1 | 2013年2月12日| 2013年5月12日
2267461 | 1 | 2013年2月12日| 2013年5月12日
2273007 | 1 | 2013年2月12日| 2013年6月12日
2273127 | 1 | 2013年2月12日| 2013年6月12日

下面的形式code是打开文件和检索的数据的一部分...

 昏暗JDW_Row作为字符串
昏暗的JDW_RowValues​​()作为字符串流程JDW订单文件到DataGrid中        昏暗JDW_Reader作为IO.StreamReader =新IO.StreamReader(File.OpenRead(完整路径),System.Text.Encoding.Default)        跳过标题
        JDW_Reader.ReadLine()        开始读文件内容
        做,直到JDW_Reader.EndOfStream            读取记录,并分割成田            JDW_Row = JDW_Reader.ReadLine()
            JDW_RowValues​​ =斯普利特(JDW_Row,|)        循环

我得到了JDW_RowValues​​的每一个成员,我要问我已经见过你'通过写入到一个数组和递增相关的计数器或数组值如果再次遭遇,但我不知道$的C $℃的VB .NET。

任何人都可以建议最好的方法是什么?


解决方案

 类OrderItem的
    公共属性OrderNo作为字符串???
    公共属性产品数量为整数
    公共属性订购日期为DATETIME
    公共属性ExpectedDate为DATETIME    亚新(newOrderNo)
       OrderNo = newOrderNo
    结束小组
 末级 朋友colOrderItems作为新词典(串,OrderItem的) '...伪在循环增加 昏暗的项目作为OrderItem的 做,直到JDW_Reader.EndOfStream
     如果colOrderItems.ContainsKey(newOrderIDRead)然后
         增量生化的
         colOrderItems(newOrderIDRead).Quantity + = newQuanReadValue     其他
        添加一个新的
        项目=新OrderItem的(newOrderIDRead)
        item.Quantity = newQuanReadValue
         ...
         colOrderItems.Add(newOrderIDRead,项)
     万一
 循环

字典有助于剔除重复的,因为只有一个值(订单ID)的关键是允许的,而且很容易找到现有的。 A 列表(OrderItem的的)也将工作,但它并没有本质上保持了易受骗的人(这也部分取决于欺骗的定义)。

I have an array of data brought into my VB .Net program that follows the following format.

Order No.|Description|Colour|Size|Total Qty.|Order Date|Expected D.D.
2273448|NOK OPAQUE KNEE HIGH |BLACK |X |001 |02/12/2013 |05/12/2013
2231428|UX XR WARM HOLD UPS |NAVY |ONE SIZE |001 |02/12/2013 |05/12/2013
2231428|NHS SOFTHOLD HOLD-UP |BLACK |X |001 |02/12/2013 |05/12/2013
2265640|KX XR WARM TIGHTS |BLACK |XXL |001 |02/12/2013 |05/12/2013
2273448|NOK OPAQUE KNEE HIGH |BLACK |X |001 |02/12/2013 |05/12/2013
2231428|NHS SOFTHOLD HOLD-UP |BLACK |X |001 |02/12/2013 |05/12/2013
2231428|NHS SOFTHOLD HOLD-UP |NATURAL |X |001 |02/12/2013 |05/12/2013
2267461|WF-01 FLIP FLOP |BLACK |13 |001 |02/12/2013 |05/12/2013
2231428|NHS SOFTHOLD HOLD-UP |NATURAL |X |001 |02/12/2013 |05/12/2013
2273007|CR COTTON-RICH SOCK |BLACK |4-7 |001 |02/12/2013 |06/12/2013
2273127|TH THERMAL SOCK |MOSS |6-11 |001 |02/12/2013 |06/12/2013

This is a pre-formatted piped text file that I have no control over.

I am trying to bring this data into a VB DataGrid, but before I do, I want to de-dupe the values, whilst counting them, so I can display only pertinent data, without duplicate rows, so that the program user can then select the rows and work on all the associated rows (i.e. reducing the potential for human error.

The expected output to the DataGrid, based on the above, would be something like...

Order No | Lines on Order | Order Date | Expected Date
2273448  |2               |02/12/2013  |05/12/2013
2231428  |5               |02/12/2013  |05/12/2013
2265640  |1               |02/12/2013  |05/12/2013
2267461  |1               |02/12/2013  |05/12/2013
2273007  |1               |02/12/2013  |06/12/2013
2273127  |1               |02/12/2013  |06/12/2013

Here is the portion of the form code that is opening the file and retrieving the data...

Dim JDW_Row As String
Dim JDW_RowValues() As String

' Process JDW Order File into DataGrid

        Dim JDW_Reader As IO.StreamReader = New IO.StreamReader(File.OpenRead(FullPath), System.Text.Encoding.Default)

        ' Skip Header
        JDW_Reader.ReadLine()

        ' Start reading file contents
        Do Until JDW_Reader.EndOfStream

            ' read a record and split into fields

            JDW_Row = JDW_Reader.ReadLine()
            JDW_RowValues = Split(JDW_Row, "|")

        Loop

I get that for each member of JDW_RowValues, I need to ask 'have I seen you before' by writing it to an array and incrementing an associated counter or array value if its encountered again but I'm not sure of the code in VB .NET.

Can anyone suggest the best method?

解决方案

 Class OrderItem
    Public Property OrderNo As String  ' ???
    Public Property Quantity As Integer 
    Public Property OrderDate As DateTime
    Public Property ExpectedDate As DateTime

    Sub New(newOrderNo)
       OrderNo = newOrderNo
    End Sub
 End Class

 Friend colOrderItems as New Dictionary(Of String, OrderItem)

 ' ... pseudo for adding in the loop

 Dim item as OrderItem

 Do Until JDW_Reader.EndOfStream
     If colOrderItems.ContainsKey(newOrderIDRead) Then
         ' increment quatity
         colOrderItems(newOrderIDRead).Quantity += newQuanReadValue

     Else
        ' add a new one
        item = New OrderItem(newOrderIDRead)
        item.Quantity = newQuanReadValue
         ...
         colOrderItems.Add(newOrderIDRead, item)
     End If
 Loop 

The dictionary helps weed out duplicates because only one key of that value (OrderID) is allowed, and it is easy to find existing ones. A List(of OrderItem) would also work, but it does not inherently keep out dupes (which also partly depends on the definition of a dupe).

这篇关于操作和显示到DataGrid中的数据重复数据删除阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆