Dim dz1 As New Dictionary(Of DataRow, DataRow)
Dim dz2 As New Dictionary(Of DataRow, DataRow)
Dim dz3 As New Dictionary(Of DataRow, DataRow)
Dim dznull As New List(Of DataRow)
For Each dr As DataRow In DataTables("净进货核算差额调整").DataRows
If dr("店铺性质") = "正价店" Then
If dr("新季节属性") = "当季新款" Then
Dim pr As DataRow
Dim filter As String
filter = "货品年份 = '" & dr("款式年份") & "' And 货品季节 = '" & dr("款式季度") & "' And 仓店编号 = '" & dr("仓店编号") & "' and 退货截止日期 is not null"
pr = DataTables("客户当季货品退货核算标准").Find(filter)
If pr IsNot Nothing Then
If (pr("退货截止年份") = N1 And pr("退货截止月份") <= y1) Or pr("退货截止年份") < N1 Then
dz1.Add(dr, pr)
Else
dznull.Add(dr)
End If
Else
dznull.Add(dr)
End If
ElseIf dr("新季节属性") = "往年旧款" Then
Dim pr1 As DataRow
Dim filter1 As String
filter1 = "款式季度 = '" & dr("款式季度") & "' And 仓店编号 = '" & dr("仓店编号") & "' and ((年份= '" & dr("年份") & "' and 月份>= " & dr("月份") & ") or 年份> '" & dr("年份") & "') and 退货完成标记='完成退货' and 新季节属性='当季新款'"
pr1 = DataTables("净进货核算差额调整").Find(filter1)
If pr1 IsNot Nothing Then
dz2.Add(dr, pr1)
Else
dznull.Add(dr)
End If
End If
ElseIf dr("店铺性质") = "非正价店" Then
Dim pr2 As DataRow
Dim filter2 As String
filter2 = "款式季度 = '" & dr("款式季度") & "' And 品牌名称 = '" & dr("品牌名称") & "' and ((调整退市年份= '" & dr("年份") & "' and 调整退市月份>= " & dr("月份") & ") or 调整退市年份> '" & dr("年份") & "')"
pr2 = DataTables("商品上市退市时间档案").Find(filter2, "调整退货日期")
If pr2 IsNot Nothing Then
If (pr2("调整退市年份") = N1 And pr2("调整退市月份") <= y1) Or pr2("调整退市年份") < N1 Then
dz3.Add(dr, pr2)
Else
dznull.Add(dr)
End If
Else
dznull.Add(dr)
End If
Else
dznull.Add(dr)
End If
Next
For Each dr As DataRow In dz1.Keys
dr("退货完成标记") = "完成退货"
dr("核算年份") = dz1(dr)("退货截止年份")
dr("核算月份") = dz1(dr)("退货截止月份")
Next
For Each dr As DataRow In dz2.Keys
dr("退货完成标记") = "完成退货"
dr("核算年份") = dz2(dr)("核算年份")
dr("核算月份") = dz2(dr)("核算月份")
Next
For Each dr As DataRow In dz3.Keys
dr("退货完成标记") = "完成退货"
dr("核算年份") = dz3(dr)("调整退市年份")
dr("核算月份") = dz3(dr)("调整退市月份")
Next
For Each dr As DataRow In dznull
dr("退货完成标记") = "未完成退货"
dr("核算年份") = Nothing
dr("核算月份") = Nothing
Next