Forms("加载提示").Open()
'导入应收明细
'获取年月
Dim ny As String
With RibbonTabs("销售管理")("应收明细")
ny = .Items("年月").Text
End With
Dim y1 As String = CInt(Left(ny,4))-1
'生成ysmx临时表
Dim o As new QueryBuilder
o.TableName = "ysmx"
o.C
o.SelectString = "Select DISTINCT 年月 From {应收明细} WHERE Left(年月,4)>= '" & y1 & "'"
o.Build
Dim Book As New XLS.Book(ProjectPath & "应收明细.xls")
If DataTables("ysmx").Find("年月 = '" & ny & "'") IsNot Nothing Then
Forms("加载提示").Close()
messagebox.show("当月数据已导入","提示")
Return
End If
MainTable = Tables("应收明细")
For i As Integer = 0 To Book.Sheets.Count -1
Dim a As String = Book.Sheets(i).Name
If a = ny Then
Dim Sheet As XLS.Sheet = Book.Sheets(i)
Tables("应收明细").StopRedraw()
For r As Integer = 1 To Sheet.Rows.Count - 1
Dim Filter1 As String = ""
For c As Integer = 0 To Sheet.Cols.Count - 1
If c > 0 Then
Filter1 = Filter1 & " And "
End If
If sheet(r,c).Value <> "" AndAlso CurrentTable.DataTable.DataCols(sheet(0,c).Value).IsNumeric Then
Filter1 = Filter1 & sheet(0,c).Value & " = " & sheet(r,c).Value
ElseIf sheet(r,c).Value = "" Then
Filter1 = Filter1 & sheet(0,c).Value & " is null "
Else
Filter1 = Filter1 & sheet(0,c).Value & " = '" & sheet(r,c).Value & "'"
End If
Next
If CurrentTable.DataTable.Find(Filter1) Is Nothing Then
Dim dr As Row = CurrentTable.AddNew()
For c As Integer = 0 To Sheet.Cols.Count - 1
dr(Sheet(0,c).Value) = Sheet(r,c).Value
Next
End If
Next
DataTables("应收明细").ReplaceFor("年月", ny ,"[年月] is null")
'数据格式化
Dim t As Table = Tables("应收明细")
Dim s As String
For Each dc As DataCol In t.DataTable.DataCols
If dc.name <> "年月" AndAlso dc.name <> "单位" AndAlso dc.name <> "ny1" Then
s = "0.00"
t.DataTable.DataCols(dc.Name).SetFormat(s)
End If
Next
For Each dr As DataRow In DataTables("应收明细").DataRows
If dr.IsNull("年月") Then
dr("ny1") = Nothing
Else
dr("ny1") = Cdate(dr("年月"))
End If
Next
DataTables("应收明细").DataCols("警务区").RaiseDataColChanged()
Tables("应收明细").Sort = "年月,单位"
Tables("应收明细").AutoSizeCols()
Tables("应收明细").ListMode = True
DataTables("应收明细").Save()
Tables("应收明细").ResumeRedraw()
Forms("加载提示").Close()
Return
End If
Next
Forms("加载提示").Close()
Messagebox.show("需导入的数据不存在!","提示")