// SD01 - Inteface de cliente - Comunicação // funcao - ZFXI_SD01C //[RfcServerFunction(Name = "ZFXI_SD01C")] public static void StfcInterfaceCliente(RfcServerContext context, IRfcFunction function) { // // CLIENTE // // Exibe no console a interface que será executada Console.WriteLine("Received function call {0} from system {1}.", function.Metadata.Name, context.SystemAttributes.SystemID); // Implementa repositorio antes do Foreach para evitar duplicações ClienteRepository clienteRepository = new ClienteRepository(); // Implementa repositorio antes do Foreach para evitar duplicações Cliente cliente = new Cliente(); // Flag da interface que de Limpar tabela de dados Char deletar = function.GetChar("I_REFRESH"); // exibe se o mesmo foi flegado Console.WriteLine(deletar); // Se estiver espaco em branco na variavel, não limpa a tabela da interface. if (deletar != ' ') { // Apaga todos os registros da tabela pro_fornecedor IList<Cliente> fromDB = clienteRepository.ObterTodos(); foreach (Cliente dados in fromDB) { clienteRepository.Excluir(dados); } } // ZTBSD056 - ZTBXI_101 IRfcTable it_cliente = function.GetTable("IT_CLIENTE"); // Implementa Repositorio Rfc de resposta RfcRepository rep = context.Repository; // RETORNO RfcStructureMetadata bapiret2 = rep.GetStructureMetadata("BAPIRET2"); IRfcStructure linha_retorno = bapiret2.CreateStructure(); int v_cont = 0; foreach (IRfcStructure row in it_cliente) { cliente.id_cliente = row.GetString("KUNNR"); cliente.nome = row.GetString("NAME1"); cliente.cpf = row.GetString("STCD2"); cliente.cnpj = row.GetString("STCD1"); cliente.nr_ie_cli = row.GetString("STCD3"); cliente.cep = row.GetString("POST_CODE"); cliente.endereco = row.GetString("STREET"); cliente.numero = row.GetString("HOUSE_NUM1"); cliente.complemento = row.GetString("HOUSE_NUM2"); cliente.municipio = row.GetString("CITY1"); cliente.bairro = row.GetString("CITY2"); cliente.uf = row.GetString("UF"); cliente.pais = row.GetString("COUNTRY"); cliente.tel_res = row.GetString("TELF1"); cliente.tel_cel = row.GetString("TELF2"); cliente.fax = row.GetString("TELFX"); cliente.email = row.GetString("EMAIL"); // Pacote cliente.pacote = row.GetString("PACOTE"); // Data Cricao string v_data_Cricao = row.GetString("ERDAT"); cliente.data_criacao = Convert.ToDateTime(v_data_Cricao); // Hora de Criacao cliente.hora_criacao = row.GetString("ERZET"); try { v_cont = v_cont + 1; if (deletar == ' ') { IList<Cliente> fromDB = clienteRepository.ObterTodosComCampo("id_cliente", cliente.id_cliente); foreach (Cliente dados in fromDB) { clienteRepository.Excluir(dados); } } } catch (Exception ex) { // Em caso de erro retorna o erro Console.Write("entrou no exception"); IRfcTable retorno = function.GetTable("IT_RETURN"); linha_retorno.SetValue("TYPE", "E"); linha_retorno.SetValue("MESSAGE", ex.Message); linha_retorno.SetValue("MESSAGE", "Erro ao inserir o Cliente: " + cliente.nome + " - Id: " + cliente.id_cliente); retorno.Insert(linha_retorno); } clienteRepository.Salvar(cliente); String PACOTE = row.GetString("PACOTE"); String ERDAT = row.GetString("ERDAT"); String ERZET = row.GetString("ERZET"); } IRfcTable retornoSucesso = function.GetTable("IT_RETURN"); linha_retorno.SetValue("TYPE", "S"); linha_retorno.SetValue("MESSAGE", "Registros com Sucesso: " + v_cont); retornoSucesso.Insert(linha_retorno); // FIM CLIENTE // // CLIENTE VENDAS // // Implementa repositorio antes do Foreach para evitar duplicações ClienteVendasRepository clienteVendasRepository = new ClienteVendasRepository(); // Implementa repositorio antes do Foreach para evitar duplicações ClienteVendas clienteVendas = new ClienteVendas(); // ZTBSD056 - ZTBXI_101 IRfcTable it_cliente_vendas = function.GetTable("IT_CLIENTE_AV"); // Implementa Repositorio Rfc de resposta RfcRepository repVendas = context.Repository; // RETORNO RfcStructureMetadata bapiret2Vendas = repVendas.GetStructureMetadata("BAPIRET2"); IRfcStructure linha_retorno_vendas = bapiret2Vendas.CreateStructure(); int v_cont_vendas = 0; foreach (IRfcStructure row in it_cliente_vendas) { clienteVendas.id_cliente = row.GetString("KUNNR"); clienteVendas.org_vendas = row.GetString("VKORG"); clienteVendas.can_dist = row.GetString("VTWEG"); clienteVendas.can_dist = row.GetString("VTWEG"); clienteVendas.set_ativ = row.GetString("SPART"); clienteVendas.set_ativ = row.GetString("SPART"); clienteVendas.grupo_cli = row.GetString("KDGRP"); clienteVendas.id_fornecedor = row.GetString("LIFNR"); // Pacote clienteVendas.pacote = row.GetString("PACOTE"); // Data Cricao string v_data_Cricao = row.GetString("ERDAT"); clienteVendas.data_criacao = Convert.ToDateTime(v_data_Cricao); // Hora de Criacao clienteVendas.hora_criacao = row.GetString("ERZET"); try { //v_cont_vendas = v_cont_vendas + 1; //if (deletar == ' ') //{ IList<ClienteVendas> fromDB = clienteVendasRepository.PesquisaClienteVendas("id_cliente", clienteVendas.id_cliente, "org_vendas", clienteVendas.org_vendas); foreach (ClienteVendas dados in fromDB) { clienteVendasRepository.Excluir(dados); } //} } catch (Exception ex) { // Em caso de erro retorna o erro Console.Write("entrou no exception"); IRfcTable retorno = function.GetTable("IT_RETURN"); linha_retorno_vendas.SetValue("TYPE", "E"); linha_retorno_vendas.SetValue("MESSAGE", ex.Message); linha_retorno_vendas.SetValue("MESSAGE", "Erro ao inserir o Cliente: " + cliente.nome + " - Id: " + cliente.id_cliente); retorno.Insert(linha_retorno_vendas); } clienteVendasRepository.Salvar(clienteVendas); String PACOTE = row.GetString("PACOTE"); String ERDAT = row.GetString("ERDAT"); String ERZET = row.GetString("ERZET"); } IRfcTable retornoSucessoVendas = function.GetTable("IT_RETURN"); linha_retorno_vendas.SetValue("TYPE", "S"); linha_retorno_vendas.SetValue("MESSAGE", "Registros com Sucesso Grupo de Vendas: " + v_cont_vendas); retornoSucessoVendas.Insert(linha_retorno_vendas); // FIM CLIENTE VENDAS }