0

我在确定如何删除使用 FileHelpers 时出现的错误以及选项严格打开时遇到了一些问题。

我初始化了 MasterDetails 类

Private _res As MasterDetails()

调用 MasterDetailEngine 的函数

Private Function ReadCsvFile(ByVal fileName As String, ByVal tipodoc As String) As Boolean
engine = New MasterDetailEngine(GetType(CabecDocVgr), GetType(LinhasDocVgr), CommonSelector.MasterIfContains,
                                            "@")
            _res = engine.ReadFile(strStartPath)
Return true
End Function

这是大师的课程:

<DelimitedRecord(";")>
Public NotInheritable Class CabecDocVgr
    Public TipoLinha As String
    Public Doc As String
    Public Entidade As String
    Public DataDoc As String
    Public RefDoc As String
End Class

这一个,对于细节:

<DelimitedRecord(";")> _
Public NotInheritable Class LinhasDocVgr
    Public Tipolinha As String
    Public Artigo As String
    Public Armazem As String
    Public Localizacao As String
    Public Lote As String
    Public Qtd As Integer
    Public UniMedida As String
    Public DataValidade As String
End Class

每个主/明细将创建一个带有标题和相关行的新文档。

当我调用 Master 或 Details 类的成员时,我可以举一个出现错误的示例:

Private Function TransformaDocF(ByVal tipoDoc As String) As Boolean

    For numdoc As Integer = 0 To _res.Length - 1

        Dim documentosOrigem(0) As Object
        Dim docOrigem As New GcpBEDocumentoCompra
        Dim docDestino As New GcpBEDocumentoCompra

        Dim query As String = String.Format("SELECT TOP 1 NumDoc FROM cabecdoc WHERE RefDocOrig='{0}'",
                                            _res(numdoc).Master.doc)

        Dim lista As New StdBELista()   
        lista = Motor.Consulta(query)

        If Not lista.Vazia Then
            If Not lista.NoInicio And Not lista.NoFim Then
                Dim numeroDoc As Integer = CInt(lista.Valor("NumDoc"))
                'bExecuta = True
            End If
        End If

        docOrigem = Motor.Comercial.Compras.Edita("000", "VGR", "2013", _res(numdoc).Master.doc)
        documentosOrigem(0) = docOrigem

        docDestino.TipoEntidade = "F"
        docDestino.Serie = "2013"
        docDestino.Entidade = docOrigem.Entidade.TrimStart(CChar("0"))
        'DocDestino.DataDoc = "01-01-2013"
        docDestino.Tipodoc = "VFA"
        docDestino.RefDocOrig = _res(numdoc).Master.refDoc

        Try
            If docOrigem.Linhas.NumItens > 0 Then
                For numlinha As Integer = 0 To _res(numdoc).Details.Length - 1
                    If docOrigem.Linhas(numlinha + 1).Artigo = _res(numdoc).Details(numlinha).Artigo Then
                        docOrigem.Linhas(numlinha + 1).Quantidade = docOrigem.Linhas(numlinha + 1).QuantSatisfeita +
                                                                    _res(numdoc).Details(numlinha).Qtd
                    End If
                Next
            End If
            Motor.Comercial.Vendas.TransformaDocumentoEX2(documentosOrigem, CType(docDestino, GcpBEDocumentoVenda), True)
            Return True
        Catch ex As Exception

            MessageBox.Show(ex.Message)
            Return False
        End Try

    Next
    Return True
End Function

例如,调用_res(numdoc).Master.refDoc给了我错误:“ Option Strict On 不允许后期绑定”

关于我需要修改什么以便错误消失的任何想法?

谢谢

4

1 回答 1

1

尝试使用泛型。我不太擅长 VB.NET,但我认为它应该看起来像这样:

'declare _res as an array of MasterDetails<CabecDocVgr, LinhasDocVgr>
Dim _res As MasterDetails(Of CabecDocVgr, LinhasDocVgr)()

'instantiate the generic version of the FileHelpers engine
Dim engine = New MasterDetailEngine(Of CabecDocVgr, LinhasDocVgr)(CommonSelector.MasterIfContains, "@")

'should not cause 'late binding error' since the results are strongly typed
_res = engine.ReadFile("")
于 2013-12-18T13:04:17.540 回答