Ir para conteúdo
  • Cadastre-se

Mario -

Membros
  • Total de ítens

    5
  • Registro em

  • Última visita

Community Answers

  1. Mario -'s post in Imprimir N Titulos was marked as the answer   
    Conforme já expliquei sou novo nas Lib ACBr mas estou gostando muito, portanto gostaria de postar aqui a forma que fiz para N Titulos usando as Classes.
    O codigo abaixo se alguém achar bom, por favor pode otimizar.
    Parabéns a equipe ACBr.
        Dim Boleto As New ACBrLib.Boleto.ACBrBoleto
        Dim Titulo As New ACBrLib.Boleto.Titulo
        Dim Titulos As New List(Of ACBrLib.Boleto.Titulo)
        
        Dim N As Int32 = 1
        Boleto.LimparLista()
        Call DataRowObject(drConta, Boleto.Config.Banco, "Banco.") 'DataColumn.name=Prefixo+Property.Name, caso seja necessário
        Call DataRowObject(drConta, Boleto.Config.Cedente, "Conta.")
        Call DataRowObject(drConta, Boleto.Config.Cedente, "Cedente.")
        For Each dr As DataRow In tbCompromisso.Rows
            Titulo = New ACBrLib.Boleto.Titulo
            Titulo.NossoNumero = N.ToString("0000000000")
            Call DataRowObject(dr, Titulo, "Titulo.")
            Call DataRowObject(dr, Titulo.Sacado, "Sacado.")
            Call DataRowObject(dr, Titulo.Sacado.Avalista, "Sacado.Avalista.")
            Titulos.Add(Titulo)
        Next
        Boleto.IncluirTitulos(Titulos.ToArray())
        Boleto.Imprimir()
        
        
        'Função para popular os Types
        
            Private Shared Sub DataRowObject(dr As DataRow, sender As Object, Optional ByVal Prefixo As String = "")
            'ler propriedades - obter valor em datarow.column - atribuir valor a propriedade
            Dim T As Type = sender.GetType()
            Dim value As Object, Col As String, obj As Object
            For Each P In T.GetProperties(BindingFlags.Public Or BindingFlags.Instance Or BindingFlags.NonPublic)
                Select Case True
                    Case dr.Table.Columns(Prefixo & P.Name) IsNot Nothing
                        Col = Prefixo & P.Name
                    Case dr.Table.Columns(P.Name) IsNot Nothing
                        Col = P.Name
                    Case Else : Continue For
                End Select
                If String.IsNullOrEmpty(dr(Col).ToString) Then Continue For
                value = P.GetValue(sender)
                Select Case P.PropertyType()
                    Case GetType(Integer)
                        Integer.TryParse(dr(Col), value)
                    Case GetType(Boolean)
                        value = CBool(Integer.TryParse(dr(Col), value))
                    Case GetType(String)
                        value = dr(Col).ToString
                    Case GetType(System.Decimal), GetType(System.Double)
                        Decimal.TryParse(dr(Col), NumberStyles.Number, NumberFormatInfo, value)
                    Case GetType(System.DateTime)
                        DateTime.TryParseExact(dr(Col), {"dd/MM/yyyy"}, Nothing, DateTimeStyles.AssumeLocal, value)
                    Case Else
                        Select Case True
                            Case P.PropertyType.BaseType Is (GetType(System.Enum))
                                Integer.TryParse(dr(Col), value)
                            Case P.PropertyType.FullName.Contains("System.DateTime") 'este case é devido não saber ainda como pegar classe Nullable-datetime
                                DateTime.TryParseExact(dr(Col), {"dd/MM/yyyy"}, Nothing, DateTimeStyles.AssumeLocal, value)
                            Case P.PropertyType.FullName.Contains("System.Decimal") 'este case é devido não saber ainda como pegar classe Nullable-datetime
                                Decimal.TryParse(dr(Col), NumberStyles.Number, NumberFormatInfo, value)
                            Case Else
                                value = New Generic.List(Of String) From {dr(Col).ToString}
                                Continue For
                        End Select
                End Select
                P.SetValue(sender, value)
            Next
        End Sub
        
     
    A liguagem utilizada VB.NET VS 2019
     
  2. Mario -'s post in Classe Boleto.Config.Cedente x .Ini was marked as the answer   
    Resolvido...favor fechar...
     
               Dim ListBoleto As New List(Of String) From {"[Cedente]", "LayOutBol=" & drBancoConta("Cedente.LayOutBol").ToString}
                
                Dim StrConta As String = DrObjectString(drBancoConta, Boleto.Config.Cedente, "Conta.")
                
                'Abaixo fiz a troca das propriedades em não conformidade de nomes entre Classe e Cedente.ini, o que poderia ser evitado.
                ListBoleto.Add(StrConta.Replace("AgenciaDigito", "DigitoAgencia").Replace("ContaDigito", "DigitoConta"))
     
    'Aqui um trecho da function que trata Classe Cedende e o datarow(que todas as colunas tem a Property.name
           Private Shared Function DrObjectString(dr As DataRow, sender As Object, Optional ByVal Prefixo As String = "", Optional ByVal UseCol As Boolean = False) As String
                'Ler properties da Classes - Obtem valor Datarow - Converte Tipo - Atribui a StringBuild
                'DataRow.Columns.name = Property.name
                Dim T As Type = sender.GetType()
                Dim Props As PropertyInfo() = T.GetProperties()
                Dim value As Object, Col As String
                Dim StrRet As New System.Text.StringBuilder("", 60)
                For Each P As PropertyInfo In Props
                    ...Trata P x datarow and datacolumn
                Next
                StrRet.Append(IIf(UseCol, Col, P.Name) & "=" & value.ToString)
     
    PS-: Se deixarem compatíveis Classe.Property.Name x File.ini seria uma baita ajuda para criação de function de produtividade.
    Grato.
     
              
     
     
     
  3. Mario -'s post in Adicionar N Titulos was marked as the answer   
    Acabei de descobrir...não populei toda a estrutura da Classe Titulo....agora incluiu com Zero erro...
    Obrigado...e de como encerrado..
     
×
×
  • Criar Novo...

Informação Importante

Colocamos cookies em seu dispositivo para ajudar a tornar este site melhor. Você pode ajustar suas configurações de cookies, caso contrário, assumiremos que você está bem para continuar.