Gustavo.Vicente 12 Posted September 29, 2020 Report Share Posted September 29, 2020 Bom dia, Gostaria de saber se alguém já criou algum método em C# que faça a leitura dos arquivos de retorno (.INI) dos métodos da ACBrLib, se sim poderia dar um help de como fizeram isso, pois preciso ler o retorno da NFE_Enviar e estou tendo algumas dificuldades para isso. Link to post Share on other sites
antonio.carlos 65 Posted September 29, 2020 Report Share Posted September 29, 2020 @Gustavo.Vicente chegou estudar e testar nosso demo NFE em C# ? Pois no demo demostra como pegar o retorno das funções da lib 1 Link to post Share on other sites
Gustavo.Vicente 12 Posted September 29, 2020 Author Report Share Posted September 29, 2020 Olá Antonio Carlos, sim estou com o Demo em C# para entender o funcionamento de todos os métodos, porém ele não lê nenhum retorno, ele apenas paga o resultado e apresenta em um textbox na tela, mas na realidade seria necessário ler o retorno validar o que ocorreu e ai programar a ação do sistema. Exemplo: Msg=Nota(s) não confirmadas: 8->532-Rejeicao: Total do ICMS difere do somatorio dos itens Esse foi o retorno no INI de uma NFCe que não foi aprovado, preciso ler que ele não obteve sucesso e informar ao usuário, parar o fluxo do sistema para que seja tomada alguma ação a respeito e mostra a msg, então não server apenas pegar o retorno inteiro e apresentar na tela como é feito no exemplo, par ao exemplo isso está perfeito pois executamos cada método de forma manual e individual, porém para o sistema de produção ele tem que saber ler o que ocorreu e que caminho tomar. Por isso a necessidade de ler o INI. Link to post Share on other sites
Fundadores Daniel Simoes 8,703 Posted September 29, 2020 Fundadores Report Share Posted September 29, 2020 Em C# não existe uma classe para leitura e tratamento de INIs ? Uma outra opção, seria configurar a ACBrLib, para usar JSON https://acbr.sourceforge.io/ACBrLib/Geral.html 1 Daniel Simões de Almeida O melhor TEF, é com o Projeto ACBr - Clique e Conheça Ajude o Projeto ACBr crescer - Assine o SAC (15) 2105-0750 (15)99790-2976. Link to post Share on other sites
Juliomar Marchetti 3,845 Posted September 29, 2020 Report Share Posted September 29, 2020 Não existe. tu tem que criar a função. por incrível que pareça Daniel Juliomar Marchetti Ajude o Projeto ACBr crescer - Assine o SAC skype: juliomar telegram: juliomar http://www.juliomarmarchetti.com.br Projeto ACBr - A maior comunidade Open Source de Automação Comercial do Brasil Link to post Share on other sites
Fundadores Daniel Simoes 8,703 Posted September 29, 2020 Fundadores Report Share Posted September 29, 2020 Eita... mas foi a própria Microsoft que criou o formato INI https://pt.wikipedia.org/wiki/INI_(formato_de_arquivo) Daniel Simões de Almeida O melhor TEF, é com o Projeto ACBr - Clique e Conheça Ajude o Projeto ACBr crescer - Assine o SAC (15) 2105-0750 (15)99790-2976. Link to post Share on other sites
Gustavo.Vicente 12 Posted September 29, 2020 Author Report Share Posted September 29, 2020 Prezado, já resolvi. Obrigado. public class IniFiles { private readonly string filePath; private int capacity = 512; [DllImport("kernel32", CharSet = CharSet.Unicode)] private static extern int GetPrivateProfileString(string section, string key, string defaultValue, StringBuilder value, int size, string filePath); [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] static extern int GetPrivateProfileString(string section, string key, string defaultValue, [In, Out] char[] value, int size, string filePath); [DllImport("kernel32.dll", CharSet = CharSet.Auto)] private static extern int GetPrivateProfileSection(string section, IntPtr keyValue, int size, string filePath); [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool WritePrivateProfileString(string section, string key, string value, string filePath); public IniFiles(string Path) { filePath = Path; } public string ReadValue(string section, string key, string defaultValue = "") { var value = new StringBuilder(capacity); GetPrivateProfileString(section, key, defaultValue, value, value.Capacity, filePath); return value.ToString(); } public string[] ReadSections() { // first line will not recognize if ini file is saved in UTF-8 with BOM while (true) { char[] chars = new char[capacity]; int size = GetPrivateProfileString(null, null, "", chars, capacity, filePath); if (size == 0) { return null; } if (size < capacity - 2) { string result = new String(chars, 0, size); string[] sections = result.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); return sections; } capacity = capacity * 2; } } public string[] ReadKeys(string section) { // first line will not recognize if ini file is saved in UTF-8 with BOM while (true) { char[] chars = new char[capacity]; int size = GetPrivateProfileString(section, null, "", chars, capacity, filePath); if (size == 0) { return null; } if (size < capacity - 2) { string result = new String(chars, 0, size); string[] keys = result.Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries); return keys; } capacity = capacity * 2; } } public string[] ReadKeyValuePairs(string section) { while (true) { IntPtr returnedString = Marshal.AllocCoTaskMem(capacity * sizeof(char)); int size = GetPrivateProfileSection(section, returnedString, capacity, filePath); if (size == 0) { Marshal.FreeCoTaskMem(returnedString); return null; } if (size < capacity - 2) { string result = Marshal.PtrToStringAuto(returnedString, size - 1); Marshal.FreeCoTaskMem(returnedString); string[] keyValuePairs = result.Split('\0'); return keyValuePairs; } Marshal.FreeCoTaskMem(returnedString); capacity = capacity * 2; } } public bool WriteValue(string section, string key, string value) { bool result = WritePrivateProfileString(section, key, value, filePath); return result; } public bool DeleteSection(string section) { bool result = WritePrivateProfileString(section, null, null, filePath); return result; } public bool DeleteKey(string section, string key) { bool result = WritePrivateProfileString(section, key, null, filePath); return result; } } Fonte: https://www.webtips.com.br/Home/Detail/73#:~:text=NET %2F C %23%2C mas não,pela Platform Invoke (PInvoke). Link to post Share on other sites
Solution Juliomar Marchetti 3,845 Posted September 29, 2020 Solution Report Share Posted September 29, 2020 http://www.codigoexpresso.com.br/Home/Postagem/24 Juliomar Marchetti Ajude o Projeto ACBr crescer - Assine o SAC skype: juliomar telegram: juliomar http://www.juliomarmarchetti.com.br Projeto ACBr - A maior comunidade Open Source de Automação Comercial do Brasil Link to post Share on other sites
antonio.carlos 65 Posted September 29, 2020 Report Share Posted September 29, 2020 Obrigado por reportar. Fechando. Para novas dúvidas, criar um novo tópico. Link to post Share on other sites
Recommended Posts