コード例 #1
0
    public void Log(ISO8583 isoRegistro)
    {
        // somente no disco!

        var dados = " ISO8583-DETALHES DO REGISTRO \r\n         ======================================================== \r\n         Registro Iso : codigo       =" + isoRegistro.codigo + "\r\n         Bits preenchidos :          =" + isoRegistro.relacaoBits + "\r\n         bit( 3  ) - Codigo Proc.    =" + isoRegistro.codProcessamento + "\r\n         bit( 4  ) - valor           =" + isoRegistro.valor + "\r\n         bit( 7  ) - datahora        =" + isoRegistro.datetime + "\r\n         bit( 11 ) - NSU Origem      =" + isoRegistro.nsuOrigem + "\r\n         bit( 13 ) - data            =" + isoRegistro.Date + "\r\n         bit( 22 ) - modo captura    =" + isoRegistro.bit22 + "\r\n         bit( 35 ) - trilha          =" + isoRegistro.trilha2 + "\r\n         bit( 37 ) - nsu alternativo =" + isoRegistro.nsu + "\r\n         bit( 39 ) - codResposta     =" + isoRegistro.codResposta + "\r\n         bit( 41 ) - terminal        =" + isoRegistro.terminal + "\r\n         bit( 42 ) - codigoLoja      =" + isoRegistro.codLoja + "\r\n         bit( 49 ) - codigo moeda    =" + isoRegistro.bit49 + "\r\n         bit( 52 ) - Senha           =" + isoRegistro.senha + "\r\n         bit( 62 ) - Dados transacao =" + isoRegistro.bit62 + "\r\n         bit( 63 ) - Dados transacao =" + isoRegistro.bit63 + "\r\n         bit( 64 ) - Dados transacao =" + isoRegistro.bit64 + "\r\n         bit( 90 ) - dados original  =" + isoRegistro.bit90 + "\r\n         bit( 125 )- NSU original    =" + isoRegistro.bit125 + "\r\n         bit( 127 )- NSU             =" + isoRegistro.bit127 + "\r\n         ======================================================== \r\n";
        var st    = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss:ffff") + " {" + dados + "}";

        sw.WriteLine(st);
    }
コード例 #2
0
        static void Main(string[] args)
        {
            //Sample ISO8583 Message
            var e1 = "0100323C078020E092083110000000000000001027065031000011065032102722090051000000005136639331006860000001D2209601784000000030303031303031313030303030303030303030383638370040000000000000000000000000000000000000000000000000000000000000000000000000000000000608B93B86AE877E8468019870355712639331006860000001D220960178400000005F201150454E414C5645522F44454E4E495320489F1F0A37383430303030303030900070495F24032209305A096393310068600000015F3401008E0A000000000000000002009F0D0590709C98009F0E0520000000009F0F0590709C98009F0702AB005F25031709305F280206089000703C9F080200968C159F02069F03069F1A0295055F2A029A039C019F37048D198A029F02069F03069F1A0295055F2A029A039C019F3704910A5F30020601900000113135303132303030303030";

            string[] parseMessage = ISO8583.ParseMessageEMVUpdate(e1);

            Console.ReadLine();
        }
コード例 #3
0
    private string montaConfirmacaoCE(ISO8583 regIso)
    {
        try
        {
            string codLoja  = regIso.codLoja;
            string terminal = regIso.terminal;

            if (regIso.codLoja == "")
            {
                Log("codLoja vazio!");
                return("");
            }

            if (regIso.codLoja.Length < 4)
            {
                Log("codLoja menor de 4 chars!");
                return("");
            }

            if (regIso.terminal == "")
            {
                Log("terminal vazio!");
                return("");
            }

            if (regIso.terminal.Length < 4)
            {
                Log("terminal menor de 4 chars!");
                return("");
            }

            string s    = terminal.Substring(terminal.Length - 4, 4);
            string str1 = (int.Parse(codLoja.Substring(codLoja.Length - 4, 4)) + int.Parse(s)).ToString("00000000");

            string str2 = "";
            string str3 = regIso.bit127;

            if (regIso.bit62 == "")
            {
                Log("bit62 vazio!");
                return("");
            }

            if (regIso.bit127 == "")
            {
                Log("bit127 vazio!");
                return("");
            }

            if (regIso.bit127.Length < 4)
            {
                Log("bit127 menor de 4 chars!");
                return("");
            }

            if (str3 == "")
            {
                str3 = "000000000";
            }

            int length = regIso.trilha2.Trim().Length;

            string bit62 = regIso.bit62;

            if (regIso.bit62.Trim().Length == 27)
            {
                str2 = regIso.bit62.Trim();
            }
            else if (regIso.bit62.Trim().Length == 37)
            {
                str2 = ("999999" +
                        regIso.bit62.Substring(17, 6) +
                        regIso.bit62.Substring(23, 6) +
                        regIso.bit62.Substring(29, 3)).PadLeft(27, '0');
            }

            // original
            //string registro = "05" + "CE" + "CC" + str1.PadLeft(8, '0') + str2 + str3.Substring(3) + "00000" + str3;

            // ajustado
            string registro = "05CECC1" +
                              codLoja.TrimStart('0').PadLeft(7, '0') +
                              str2 +
                              str3.Substring(3) +
                              "00000" +
                              str3;

            registro = registro.PadRight(200, '*') + str1;

            return(registro);
        }
        catch (System.Exception ex)
        {
            LogFalha("montaConfirmacaoCE exception: " + ex.ToString());
            return("");
        }
    }
コード例 #4
0
        private string montaConfirmacaoCE(ISO8583 regIso)
        {
            Util.LOGENTRADA();

            string codLoja  = regIso.codLoja;
            string terminal = regIso.terminal;

            if (regIso.codLoja == "")
            {
                Util.LOGDADOS("codLoja vazio!");
                return("");
            }

            if (regIso.codLoja.Length < 4)
            {
                Util.LOGDADOS("codLoja menor de 4 chars!");
                return("");
            }

            if (!IsNumeric(regIso.codLoja))
            {
                Util.LOGDADOS("codLoja não numerico!");
                return("");
            }

            if (regIso.terminal == "")
            {
                Util.LOGDADOS("terminal vazio!");
                return("");
            }

            if (regIso.terminal.Length < 4)
            {
                Util.LOGDADOS("terminal menor de 4 chars!");
                return("");
            }

            /*     if (!IsNumeric(regIso.terminal))
             *   {
             *       Util.LOGDADOS("terminal não numerico!");
             *       return "";
             *   }
             */
            string s    = terminal.Substring(terminal.Length - 4, 4);
            string str1 = (int.Parse(codLoja.Substring(codLoja.Length - 4, 4)) + int.Parse(s)).ToString("00000000");

            Util.LOGDADOS("Num terminal atribuido: " + str1);

            string str2 = "";
            string str3 = regIso.bit127;

            if (regIso.bit62 == "")
            {
                Util.LOGDADOS("bit62 vazio!");
                return("");
            }

            if (regIso.bit127 == "")
            {
                Util.LOGDADOS("bit127 vazio!");
                return("");
            }

            if (regIso.bit127.Length < 4)
            {
                Util.LOGDADOS("bit127 menor de 4 chars!");
                return("");
            }

            if (str3 == "")
            {
                str3 = "000000000";
            }

            int length = regIso.trilha2.Trim().Length;

            string bit62 = regIso.bit62;

            if (regIso.bit62.Trim().Length == 27)
            {
                str2 = regIso.bit62.Trim();
            }
            else if (regIso.bit62.Trim().Length == 37)
            {
                str2 = ("999999" +
                        regIso.bit62.Substring(17, 6) +
                        regIso.bit62.Substring(23, 6) +
                        regIso.bit62.Substring(29, 3)).PadLeft(27, '0');
            }

            // original
            //string registro = "05" + "CE" + "CC" + str1.PadLeft(8, '0') + str2 + str3.Substring(3) + "00000" + str3;

            // ajustado
            string registro = "05CECC1" +
                              codLoja.TrimStart('0').PadLeft(7, '0') +
                              str2 +
                              str3.Substring(3) +
                              "00000" +
                              str3;

            registro = registro.PadRight(200, '*') + str1;

            Util.LOGSAIDA(registro);

            return(registro);
        }
コード例 #5
0
        private string montaDesfazimento(ISO8583 regIso)
        {
            try
            {
                Util.LOGENTRADA();

                string codLoja  = regIso.codLoja;
                string terminal = regIso.terminal;

                if (regIso.codLoja == "")
                {
                    Util.LOGDADOS("codLoja vazio!");
                    return("");
                }

                if (regIso.codLoja.Length < 4)
                {
                    Util.LOGDADOS("codLoja menor de 4 chars!");
                    return("");
                }

                if (!IsNumeric(regIso.codLoja))
                {
                    Util.LOGDADOS("codLoja não numerico!");
                    return("");
                }

                if (regIso.terminal == "")
                {
                    Util.LOGDADOS("terminal vazio!");
                    return("");
                }

                if (regIso.terminal.Length < 4)
                {
                    Util.LOGDADOS("terminal menor de 4 chars!");
                    return("");
                }

                /*          if (!IsNumeric(regIso.terminal))
                 *        {
                 *            Util.LOGDADOS("terminal não numerico!");
                 *            return "";
                 *        }
                 */
                string s   = terminal.Substring(terminal.Length - 4, 4);
                string str = (int.Parse(codLoja.Substring(codLoja.Length - 4, 4)) + int.Parse(s)).ToString("00000000");

                Util.LOGDADOS("Num terminal atribuido: " + str);

                // original
                //string registro = "05" + "CE" + "DF" + str.PadLeft(8, '0') + "0".PadLeft(43, '0') + regIso.valor.PadLeft(12, '0');

                // ajustado
                string registro = "05CEDF1" + codLoja.TrimStart('0').PadLeft(7, '0') + "0".PadLeft(43, '0') + regIso.valor.PadLeft(12, '0');
                registro = registro.PadRight(200, '*') + str + regIso.nsuOrigem.TrimStart('0').PadLeft(8, '0');

                Util.LOGSAIDA(registro);
                return(registro);
            }
            catch (System.Exception ex)
            {
                Util.LOGSAIDA(ex.ToString());
                return("");
            }
        }
コード例 #6
0
        private string montaVendaCE(ISO8583 regIso)
        {
            try
            {
                Util.LOGENTRADA();
                string codLoja = regIso.codLoja;
                Util.LOGDADOS("CodEstabelecimento: " + codLoja);
                string terminal = regIso.terminal;
                Util.LOGDADOS("codigo Terminal : " + terminal);

                if (regIso.codLoja == "")
                {
                    Util.LOGDADOS("codLoja vazio!");
                    return("");
                }

                if (regIso.codLoja.Length < 4)
                {
                    Util.LOGDADOS("codLoja menor de 4 chars!");
                    return("");
                }

                if (!IsNumeric(regIso.codLoja))
                {
                    Util.LOGDADOS("codLoja não numerico!");
                    return("");
                }

                if (regIso.terminal == "")
                {
                    Util.LOGDADOS("terminal vazio!");
                    return("");
                }

                if (regIso.terminal.Length < 4)
                {
                    Util.LOGDADOS("terminal menor de 4 chars!");
                    return("");
                }

                /*         if (!IsNumeric(regIso.terminal))
                 *       {
                 *           Util.LOGDADOS("terminal não numerico!");
                 *           return "";
                 *       }
                 */
                string s = terminal.Substring(terminal.Length - 4, 4);

                string str = (int.Parse(codLoja.Substring(codLoja.Length - 4, 4)) +
                              int.Parse(s)).ToString("00000000");

                Util.LOGDADOS("Num terminal atribuido: " + str);

                // original

                /*string registro = "05" + "CE" + "CE" + str.PadLeft(8, '0') +
                 *        (regIso.trilha2.Trim().Length != 0 ? (regIso.trilha2.Trim().Length != 27 ?
                 *        ("999999" + regIso.trilha2.Substring(17, 6) +
                 *        regIso.trilha2.Substring(23, 6) +
                 *        regIso.trilha2.Substring(29, 3)).PadLeft(27, '0') :
                 *        regIso.trilha2.Trim()) : "999999999999999999999999999") + regIso.senha.PadLeft(16, '0') +
                 *        regIso.valor.PadLeft(12, '0') + "01" +
                 *        regIso.valor.PadLeft(12, '0');
                 */

                // ajustado
                string registro = "05CECE1" + codLoja.TrimStart('0').PadLeft(7, '0') +
                                  (regIso.trilha2.Trim().Length != 0 ? (regIso.trilha2.Trim().Length != 27 ?
                                                                        ("999999" + regIso.trilha2.Substring(17, 6) +
                                                                         regIso.trilha2.Substring(23, 6) +
                                                                         regIso.trilha2.Substring(29, 3)).PadLeft(27, '0') :
                                                                        regIso.trilha2.Trim()) : "999999999999999999999999999") + regIso.senha.PadLeft(16, '0') +
                                  regIso.valor.PadLeft(12, '0') + "01" +
                                  regIso.valor.PadLeft(12, '0');

                registro = registro.PadRight(200, '*') + str + regIso.nsuOrigem;

                Util.LOGSAIDA(registro);
                return(registro);
            }
            catch (System.Exception ex)
            {
                Util.LOGSAIDA(ex.ToString());
                return("");
            }
        }
コード例 #7
0
    private string montaCNET_VendaCE(ISO8583 regIso)
    {
        try
        {
            string codLoja = regIso.codLoja;

            Log("CodEstabelecimento: " + codLoja);

            string terminal = regIso.terminal;

            Log("codigo Terminal : " + terminal);

            if (regIso.codLoja == "")
            {
                Log("codLoja vazio!");
                return("");
            }

            if (regIso.codLoja.Length < 4)
            {
                Log("codLoja menor de 4 chars!");
                return("");
            }

            if (regIso.terminal == "")
            {
                Log("terminal vazio!");
                return("");
            }

            if (regIso.terminal.Length < 4)
            {
                Log("terminal menor de 4 chars!");
                return("");
            }

            string s = terminal.Substring(terminal.Length - 4, 4);

            string str = (int.Parse(codLoja.Substring(codLoja.Length - 4, 4)) +
                          int.Parse(s)).ToString("00000000");

            // original

            /*string registro = "05" + "CE" + "CE" + str.PadLeft(8, '0') +
             *          (regIso.trilha2.Trim().Length != 0 ? (regIso.trilha2.Trim().Length != 27 ?
             *          ("999999" + regIso.trilha2.Substring(17, 6) +
             *          regIso.trilha2.Substring(23, 6) +
             *          regIso.trilha2.Substring(29, 3)).PadLeft(27, '0') :
             *          regIso.trilha2.Trim()) : "999999999999999999999999999") + regIso.senha.PadLeft(16, '0') +
             *          regIso.valor.PadLeft(12, '0') + "01" +
             *          regIso.valor.PadLeft(12, '0');
             */

            // ajustado
            string registro = "05CECE1" + codLoja.TrimStart('0').PadLeft(7, '0') +
                              (regIso.trilha2.Trim().Length != 0 ? (regIso.trilha2.Trim().Length != 27 ?
                                                                    ("999999" + regIso.trilha2.Substring(17, 6) +
                                                                     regIso.trilha2.Substring(23, 6) +
                                                                     regIso.trilha2.Substring(29, 3)).PadLeft(27, '0') :
                                                                    regIso.trilha2.Trim()) : "999999999999999999999999999") + regIso.senha.PadLeft(16, '0') +
                              regIso.valor.PadLeft(12, '0') + "01" +
                              regIso.valor.PadLeft(12, '0');

            registro = registro.PadRight(200, '*') + str + regIso.nsuOrigem;

            return(registro);
        }
        catch (System.Exception ex)
        {
            LogFalha("montaCNET_VendaCE exception: " + ex.ToString());
            return("");
        }
    }
コード例 #8
0
    private string montaCNET_VendaCEparcelada(ref ISO8583 regIso)
    {
        try
        {
            string codLoja  = regIso.codLoja;
            string terminal = regIso.terminal;

            if (regIso.codLoja == "")
            {
                Log("codLoja vazio!");
                return("");
            }

            if (regIso.codLoja.Length < 4)
            {
                Log("codLoja menor de 4 chars!");
                return("");
            }

            if (regIso.terminal == "")
            {
                Log("terminal vazio!");
                return("");
            }

            if (regIso.terminal.Length < 4)
            {
                Log("terminal menor de 4 chars!");
                return("");
            }

            string s    = terminal.Substring(terminal.Length - 4, 4);
            string str1 = (int.Parse(codLoja.Substring(codLoja.Length - 4, 4)) + int.Parse(s)).ToString("00000000");

            // original
            //string str2 = "05" + "CE" + "CE" + str1 + (regIso.trilha2.Trim().Length != 27 ? ("999999" + regIso.trilha2.Substring(17, 6) + regIso.trilha2.Substring(23, 6) + regIso.trilha2.Substring(29, 3)).PadLeft(27, '0') : regIso.trilha2.Trim()) + regIso.senha.PadLeft(16, '0') + regIso.valor.PadLeft(12, '0');

            if (regIso.trilha2 == "")
            {
                Log("trilha vazia!");
                return("");
            }

            // ajustado
            string str2 = "05CECE1" + codLoja.TrimStart('0').PadLeft(7, '0') +
                          (regIso.trilha2.Trim().Length != 27 ? ("999999" + regIso.trilha2.Substring(17, 6) +
                                                                 regIso.trilha2.Substring(23, 6) + regIso.trilha2.Substring(29, 3)).PadLeft(27, '0') :
                           regIso.trilha2.Trim()) + regIso.senha.PadLeft(16, '0') + regIso.valor.PadLeft(12, '0');

            //                             1         2
            //                   012345678901234567890123456789
            //bit(35) - trilha = 826766001401000650011651018

            if (regIso.bit62 == "")
            {
                Log("BIT 62 vazio!");
                return("");
            }

            if (regIso.bit62.Length < 2)
            {
                Log("BIT 62 vazio!");
                return("");
            }

            if (regIso.bit62.Substring(0, 2) == "00")
            {
                return("");
            }

            int    num1 = int.Parse(regIso.valor);
            int    num2 = int.Parse(regIso.bit62.Substring(0, 2));
            int    num3 = num1 / num2;
            int    num4 = num2 * num3;
            int    num5 = num1 - num4;
            int    num6 = num3 + num5;
            string str3 = num2.ToString("00");
            for (int index = 0; index < num2; ++index)
            {
                str3 = index != 0 ? str3 + num3.ToString("000000000000") : str3 + num6.ToString("000000000000");
            }
            string registro = str2 + str3;

            // ajustado
            registro = registro.PadRight(200, '*') + str1 + regIso.nsuOrigem;

            regIso.bit62 = str3;

            return(registro);
        }
        catch (System.Exception ex)
        {
            LogFalha(ex.ToString());
            return("");
        }
    }
コード例 #9
0
    private void ProcessDataReceived()
    {
        bool bFinaliza = false;

        try
        {
            var dadosRecebidos = msgReceived.ToString();

            if (dadosRecebidos == null)
            {
                dadosRecebidos = "";
            }

            if (dadosRecebidos.ToUpper() == "PING")
            {
                enviaDadosREDE("PONG");

                networkStream.Close();
                ClientSocket.Close();
                ContinueProcess = false;
                sw.Close();

                return;
            }

            if (dadosRecebidos.Length > 3)
            {
                dadosRecebidos = dadosRecebidos.Substring(2);
            }
            else
            {
                return;
            }

            msgReceived.Clear();

            if (dadosRecebidos.Length == 0)
            {
                // desprezar
            }
            else if (dadosRecebidos.Length <= 20 && dadosRecebidos.Length > 4)
            {
                Log("Registro recebido tamanho invalido! [1] (" + dadosRecebidos.Length + ")");
            }
            else if (dadosRecebidos.Length < 4)
            {
                Log("Registro recebido tamanho invalido! [2] (" + dadosRecebidos.Length + ")");
            }
            else
            {
                Log("Dados recebidos: length " + dadosRecebidos.Length + "<");
                Log("Dados recebidos: >" + dadosRecebidos + "<");

                var isoCode = dadosRecebidos.Substring(0, 4);

                Log("isoCode " + isoCode);

                if (isoCode != "0200" && isoCode != "0202" && isoCode != "0400" && isoCode != "0420")
                {
                    Log("Código de processamento inválido!");
                }
                else
                {
                    Log("Dados recebidos: >" + dadosRecebidos + "<");

                    var regIso = new ISO8583(dadosRecebidos);

                    Log(regIso);

                    if (regIso.erro)
                    {
                        Log("Registro ISO com erro! " + regIso.strErro);
                    }
                    else
                    {
                        var isoCodProc = regIso.codProcessamento;

                        if (isoCode == "0200" && (isoCodProc == "002000" || isoCodProc == "002800"))
                        {
                            #region - code -

                            using (var tcpClient = new TcpClient(localHost, 2000))
                            {
                                // montagem

                                string registroCNET = !(regIso.codProcessamento == "002000") ?
                                                      montaCNET_VendaCEparcelada(ref regIso) :
                                                      montaCNET_VendaCE(regIso);

                                if (registroCNET.Length < 20)
                                {
                                    #region - code -

                                    LogFalha(isoCode + " montaCNET_Venda ERRO ");

                                    //06

                                    var Iso210 = new ISO8583
                                    {
                                        codResposta      = "06",
                                        nsuOrigem        = regIso.nsuOrigem,
                                        codProcessamento = regIso.codProcessamento,
                                        codigo           = "0210",
                                        valor            = regIso.valor,
                                        terminal         = regIso.terminal,
                                        codLoja          = regIso.codLoja
                                    };

                                    string str4, str5, str6;

                                    if (regIso.trilha2.Trim().Length == 0)
                                    {
                                        str4 = "999999999999999999999999999";
                                        str5 = "999999";
                                        str6 = "999999";
                                    }
                                    else if (regIso.trilha2.Trim().Length == 27)
                                    {
                                        str4 = regIso.trilha2.Trim();
                                        str5 = regIso.trilha2.Trim().Substring(6, 6);
                                        str6 = regIso.trilha2.Trim().Substring(12, 6);
                                    }
                                    else
                                    {
                                        str5 = regIso.trilha2.Substring(17, 6);
                                        str6 = regIso.trilha2.Substring(23, 6);
                                        str4 = ("999999" + str5 + str6 + regIso.trilha2.Substring(29, 3)).PadLeft(27, '0');
                                    }

                                    Log(Iso210);

                                    #endregion

                                    // --------------------------------
                                    // envia 210 EXPRESS
                                    // --------------------------------

                                    enviaDadosEXPRESS(Iso210.registro);
                                }
                                else
                                {
                                    // --------------------------------
                                    // processamento no cnet server VENDA
                                    // --------------------------------

                                    var dadosRecCNET_200 = enviaRecebeDadosCNET(tcpClient, registroCNET);

                                    // --------------------------------
                                    // cria 210 EXPRESS
                                    // --------------------------------

                                    #region - code -

                                    var Iso210 = new ISO8583
                                    {
                                        codigo           = "0210",
                                        codResposta      = dadosRecCNET_200.Substring(2, 2),
                                        bit127           = "000" + dadosRecCNET_200.Substring(7, 6),
                                        nsuOrigem        = regIso.nsuOrigem,
                                        codProcessamento = regIso.codProcessamento,
                                        valor            = regIso.valor,
                                        terminal         = regIso.terminal,
                                        codLoja          = regIso.codLoja
                                    };

                                    if (regIso.codProcessamento != "002000")
                                    {
                                        Iso210.bit63 = regIso.bit62;
                                    }

                                    string str4, str5, str6;

                                    if (regIso.trilha2.Trim().Length == 0)
                                    {
                                        str4 = "999999999999999999999999999";
                                        str5 = "999999";
                                        str6 = "999999";
                                    }
                                    else if (regIso.trilha2.Trim().Length == 27)
                                    {
                                        str4 = regIso.trilha2.Trim();
                                        str5 = regIso.trilha2.Trim().Substring(6, 6);
                                        str6 = regIso.trilha2.Trim().Substring(12, 6);
                                    }
                                    else
                                    {
                                        str5 = regIso.trilha2.Substring(17, 6);
                                        str6 = regIso.trilha2.Substring(23, 6);
                                        str4 = ("999999" + str5 + str6 + regIso.trilha2.Substring(29, 3)).PadLeft(27, '0');
                                    }

                                    Iso210.bit62 = !(dadosRecCNET_200.Substring(2, 2) == "00") ?
                                                   dadosRecCNET_200.Substring(73, 20) :
                                                   str5 + str6 + str4.Substring(18, 3) + dadosRecCNET_200.Substring(27, 40);

                                    Log(Iso210);

                                    #endregion

                                    // --------------------------------
                                    // envia 210 EXPRESS
                                    // --------------------------------

                                    enviaDadosEXPRESS(Iso210.registro);
                                }
                            }

                            #endregion

                            bFinaliza = false; // continua depois via 202
                        }
                        else if (isoCode == "0202")
                        {
                            #region - code -

                            using (var tcpClient = new TcpClient(localHost, 2000))
                            {
                                var strRegIso = montaConfirmacaoCE(regIso);

                                if (strRegIso == null)
                                {
                                    LogFalha(isoCode + " montaDesfazimento / montaCancelamento nulo");
                                }
                                else if (strRegIso.Length < 20)
                                {
                                    LogFalha(isoCode + " montaDesfazimento / montaCancelamento tamanho inválido");
                                }
                                else
                                {
                                    // --------------------------------
                                    // processamento no cnet server CONF
                                    // --------------------------------

                                    enviaDadosCNET(tcpClient, montaConfirmacaoCE(regIso));
                                }
                            }

                            #endregion

                            bFinaliza = true;
                        }
                        else if (isoCode == "0400" || isoCode == "0420")
                        {
                            string codigoIso = "", strRegIso = "";

                            // montagem

                            if (isoCode == "0400")
                            {
                                codigoIso = "0410";
                                strRegIso = montaCancelamento(regIso, "012345678901234567890123456");
                            }
                            else if (isoCode == "0420")
                            {
                                codigoIso = "0430";
                                strRegIso = montaDesfazimento(regIso, novo: true);
                            }

                            Log("codigoIso " + codigoIso);

                            if (strRegIso.Length < 20)
                            {
                                LogFalha(isoCode + " montaDesfazimento / montaCancelamento ERRO");

                                if (codigoIso == "0402")
                                {
                                    #region - cancelamento -

                                    var isoRegistro = new ISO8583
                                    {
                                        codResposta      = "06",
                                        codigo           = codigoIso,
                                        codProcessamento = regIso.codProcessamento,
                                        codLoja          = regIso.codLoja,
                                        terminal         = regIso.terminal,
                                        nsuOrigem        = regIso.nsuOrigem,
                                    };

                                    Log(isoRegistro);

                                    enviaDadosEXPRESS(isoRegistro.registro);

                                    #endregion
                                }
                                else
                                {
                                    #region - desfazimento -

                                    var Iso430 = new ISO8583
                                    {
                                        codigo      = codigoIso,
                                        codResposta = "06",
                                        nsuOrigem   = regIso.nsuOrigem,
                                        valor       = regIso.valor,
                                        terminal    = regIso.terminal,
                                        codLoja     = regIso.codLoja,
                                        bit62       = regIso.nsuOrigem.PadLeft(6, '0') + regIso.valor.PadLeft(12, '0')
                                    };

                                    Log(Iso430);

                                    #endregion

                                    // --------------------------------
                                    // envia 210 EXPRESS
                                    // --------------------------------

                                    enviaDadosEXPRESS(Iso430.registro);
                                }
                            }
                            else
                            {
                                using (var tcpClient = new TcpClient(localHost, 2000))
                                {
                                    // --------------------------------
                                    // processamento no cnet server DESFAZ
                                    // --------------------------------

                                    string dadosRec400 = enviaRecebeDadosCNET(tcpClient, strRegIso), codResp = "00";

                                    if (codigoIso == "0410")
                                    {
                                        #region - cancelamento -

                                        if (dadosRec400 == "")
                                        {
                                            Log(isoCode + "Recebeu ISO vazio");
                                        }
                                        else if (dadosRec400.Length < 27)
                                        {
                                            Log(isoCode + "Recebeu ISO tamanho incorreto");
                                        }
                                        else
                                        {
                                            dadosRec400 = dadosRec400.PadRight(200, ' ');

                                            var isoRegistro = new ISO8583
                                            {
                                                codigo           = codigoIso,
                                                codProcessamento = regIso.codProcessamento,
                                                codLoja          = regIso.codLoja,
                                                terminal         = regIso.terminal,
                                                codResposta      = dadosRec400.Substring(2, 2),
                                                bit127           = "000" + dadosRec400.Substring(21, 6),
                                                nsuOrigem        = regIso.nsuOrigem,
                                            };

                                            Log("Montagem Bit 62");

                                            isoRegistro.bit62 = !(dadosRec400.Substring(0, 4) == "0400") ?
                                                                dadosRec400.Substring(7, 6) + regIso.valor :
                                                                regIso.bit125.Substring(3, 6) + regIso.valor;

                                            Log(isoRegistro);

                                            enviaDadosEXPRESS(isoRegistro.registro);
                                        }

                                        #endregion
                                    }
                                    else
                                    {
                                        Log("Desfaz DESABILITADO");

                                        //#region - desfazimento -

                                        //if (!dadosRec400.Contains("S"))
                                        //{
                                        //    using (var tcpClientRetry = new TcpClient(localHost, 2000))
                                        //    {
                                        //        strRegIso = montaDesfazimento(regIso, novo: false);
                                        //        dadosRec400 = enviaRecebeDadosCNET(tcpClientRetry, strRegIso);

                                        //        if (!dadosRec400.Contains("S"))
                                        //            codResp = "06";
                                        //    }
                                        //}

                                        //#region - monta 430 -

                                        //var Iso430 = new ISO8583
                                        //{
                                        //    codigo = "430",
                                        //    nsuOrigem = regIso.nsuOrigem,
                                        //    codResposta = codResp,
                                        //    valor = regIso.valor,
                                        //    terminal = regIso.terminal,
                                        //    codLoja = regIso.codLoja,
                                        //    bit62 = regIso.nsuOrigem.PadLeft(6,'0') + regIso.valor.PadLeft(12,'0')
                                        //};

                                        //Log(Iso430);

                                        //#endregion

                                        //// --------------------------------
                                        //// envia 210 EXPRESS
                                        //// --------------------------------

                                        //enviaDadosEXPRESS(Iso430.registro);

                                        //#endregion
                                    }
                                }
                            }

                            bFinaliza = true;
                        }
                        else
                        {
                            bFinaliza = true;
                        }
                    }
                }
            }
        }
        catch (SocketException ex)
        {
            LogFalha("ProcessDataReceived SocketException " + ex.ToString());
            bFinaliza = true;
        }
        catch (SystemException ex)
        {
            LogFalha("ProcessDataReceived SystemException " + ex.ToString());
            bFinaliza = true;
        }
        catch (Exception ex)
        {
            LogFalha("ProcessDataReceived Exception " + ex.ToString());
            bFinaliza = true;
        }

        if (bFinaliza)
        {
            //  Log("========= ProcessDataReceived FINALIZADO ====================");

            networkStream.Close();
            ClientSocket.Close();
            ContinueProcess = false;
            sw.Close();
        }
    }
コード例 #10
0
 public void logISO(ref ISO8583 isoRegistro)
 {
     Util.LOGDADOS(" ISO8583-DETALHES DO REGISTRO \r\n         ======================================================== \r\n         Registro Iso : codigo       =" + isoRegistro.codigo + "\r\n         Bits preenchidos :          =" + isoRegistro.relacaoBits + "\r\n         bit( 3  ) - Codigo Proc.    =" + isoRegistro.codProcessamento + "\r\n         bit( 4  ) - valor           =" + isoRegistro.valor + "\r\n         bit( 7  ) - datahora        =" + isoRegistro.datetime + "\r\n         bit( 11 ) - NSU Origem      =" + isoRegistro.nsuOrigem + "\r\n         bit( 13 ) - data            =" + isoRegistro.Date + "\r\n         bit( 22 ) - modo captura    =" + isoRegistro.bit22 + "\r\n         bit( 35 ) - trilha          =" + isoRegistro.trilha2 + "\r\n         bit( 37 ) - nsu alternativo =" + isoRegistro.nsu + "\r\n         bit( 39 ) - codResposta     =" + isoRegistro.codResposta + "\r\n         bit( 41 ) - terminal        =" + isoRegistro.terminal + "\r\n         bit( 42 ) - codigoLoja      =" + isoRegistro.codLoja + "\r\n         bit( 49 ) - codigo moeda    =" + isoRegistro.bit49 + "\r\n         bit( 52 ) - Senha           =" + isoRegistro.senha + "\r\n         bit( 62 ) - Dados transacao =" + isoRegistro.bit62 + "\r\n         bit( 63 ) - Dados transacao =" + isoRegistro.bit63 + "\r\n         bit( 64 ) - Dados transacao =" + isoRegistro.bit64 + "\r\n         bit( 90 ) - dados original  =" + isoRegistro.bit90 + "\r\n         bit( 125 )- NSU original    =" + isoRegistro.bit125 + "\r\n         bit( 127 )- NSU             =" + isoRegistro.bit127 + "\r\n         ======================================================== \r\n");
 }
コード例 #11
0
        public void RecebeRespondeTransacao()
        {
            Util.LOGDADOS("RecebeRespondeTransacao START");

            while (true)
            {
                using (TcpClient client = server.AcceptTcpClient())
                {
                    try
                    {
                        if (GlobalVar.finalizar)
                        {
                            break;
                        }

                        string dadosRecebidos = esperaDadosEXPRESS(client);

                        #region - code -

                        if (dadosRecebidos != null)
                        {
                            if (dadosRecebidos.Length == 0)
                            {
                                Util.LOGCHECK("Encerrada Conexão");
                            }
                            else if (dadosRecebidos.Length <= 20)
                            {
                                GlobalVar.frmPrincipal.AtualizaTela("Registro recebido invalido");
                                Util.LOGCHECK("Registro recebido invalido - muito pequeno");
                                Util.LOGDADOS(dadosRecebidos);
                            }
                            else
                            {
                                Util.LOGDADOS("pacote válido " + dadosRecebidos);

                                if (dadosRecebidos.Substring(0, 4) != "0200" &&
                                    dadosRecebidos.Substring(0, 4) != "0202" &&
                                    dadosRecebidos.Substring(0, 4) != "0400" &&
                                    dadosRecebidos.Substring(0, 4) != "0420")
                                {
                                    GlobalVar.frmPrincipal.AtualizaTela("Registro recebido não formato ISO8583 esperado  - Ignorado");
                                    Util.LOGCHECK("Registro recebido não formato ISO8583 esperado - Ignorado");
                                    Util.LOGDADOS(dadosRecebidos);
                                }
                                else
                                {
                                    ISO8583 regIso = new ISO8583(dadosRecebidos);

                                    logISO(ref regIso);

                                    if (regIso.erro)
                                    {
                                        GlobalVar.frmPrincipal.AtualizaTela("Registro ISO com erro");
                                        Util.LOGCHECK("Registro ISO com erro");
                                    }
                                    else
                                    {
                                        GlobalVar.frmPrincipal.AtualizaTela("Registro ISO Recebido! " + dadosRecebidos.Substring(0, 4));
                                        GlobalVar.frmPrincipal.AtualizaTela("Loja: " + regIso.codLoja.TrimStart('0') + " terminal: " + regIso.terminal);

                                        ISO8583 isoRegistro;

                                        if (dadosRecebidos.Substring(0, 4) == "0200" &&
                                            (regIso.codProcessamento == "002000" ||
                                             regIso.codProcessamento == "002800"))
                                        {
                                            #region - 200 e 202 -

                                            string registro1 = !(regIso.codProcessamento == "002000") ?
                                                               montaVendaCEparcelada(ref regIso) :
                                                               montaVendaCE(regIso);

                                            if (registro1 == "")
                                            {
                                                Util.LOGCHECK("Falhas na desmontagem da iso enviada pelo SITEF");
                                            }
                                            else
                                            {
                                                using (Socket s = connectSocketCNET(GlobalVar.SocketIPCE, int.Parse(GlobalVar.SocketPortCE)))
                                                {
                                                    if (s == null)
                                                    {
                                                        Util.LOGCHECK("Conexao com Servidor FALHOU");
                                                    }
                                                    else
                                                    {
                                                        socketEnviaCNET(s, registro1);

                                                        string dadosSocket = socketRecebeCNET(s);

                                                        Util.LOGCHECK("dadosSocket 0200: >" + dadosSocket + "<");

                                                        if (string.IsNullOrEmpty(dadosSocket))
                                                        {
                                                            Util.LOGCHECK("Recebeu ISO vazio");
                                                        }
                                                        else if (dadosSocket.Length <= 20)
                                                        {
                                                            Util.LOGCHECK(" 200 e 202 Recebeu ISO tamanho incorreto");
                                                        }
                                                        else
                                                        {
                                                            dadosSocket = dadosSocket.PadRight(200, ' ');

                                                            isoRegistro = new ISO8583();

                                                            isoRegistro.codResposta = dadosSocket.Substring(2, 2);
                                                            if (regIso.codProcessamento != "002000")
                                                            {
                                                                isoRegistro.bit63 = regIso.bit62;
                                                            }
                                                            isoRegistro.bit127           = "000" + dadosSocket.Substring(7, 6);
                                                            isoRegistro.nsuOrigem        = regIso.nsuOrigem;
                                                            isoRegistro.codProcessamento = regIso.codProcessamento;
                                                            isoRegistro.codigo           = "0210";
                                                            isoRegistro.valor            = regIso.valor;
                                                            isoRegistro.codResposta      = dadosSocket.Substring(2, 2);
                                                            isoRegistro.terminal         = regIso.terminal;
                                                            isoRegistro.codLoja          = regIso.codLoja;
                                                            string str4;
                                                            string str5;
                                                            string str6;
                                                            if (regIso.trilha2.Trim().Length == 0)
                                                            {
                                                                str4 = "999999999999999999999999999";
                                                                str5 = "999999";
                                                                str6 = "999999";
                                                            }
                                                            else if (regIso.trilha2.Trim().Length == 27)
                                                            {
                                                                str4 = regIso.trilha2.Trim();
                                                                str5 = regIso.trilha2.Trim().Substring(6, 6);
                                                                str6 = regIso.trilha2.Trim().Substring(12, 6);
                                                            }
                                                            else
                                                            {
                                                                str5 = regIso.trilha2.Substring(17, 6);
                                                                str6 = regIso.trilha2.Substring(23, 6);
                                                                str4 = ("999999" + str5 + str6 + regIso.trilha2.Substring(29, 3)).PadLeft(27, '0');
                                                            }

                                                            isoRegistro.bit62 = !(dadosSocket.Substring(2, 2) == "00") ?
                                                                                dadosSocket.Substring(73, 20) :
                                                                                str5 + str6 + str4.Substring(18, 3) + dadosSocket.Substring(27, 40);

                                                            string registro2 = isoRegistro.registro;

                                                            logISO(ref isoRegistro);
                                                            enviaDadosEXPRESS(registro2, client);

                                                            dadosRecebidos = esperaDadosEXPRESS(client);

                                                            if (dadosRecebidos.Substring(0, 4) == "0202")
                                                            {
                                                                #region - 202 -

                                                                GlobalVar.frmPrincipal.AtualizaTela("Registro ISO Recebido - Confirmacao ");

                                                                string registro = montaConfirmacaoCE(regIso);

                                                                if (string.IsNullOrEmpty(registro))
                                                                {
                                                                    Util.LOGCHECK("Falha na desmontagem!");
                                                                }
                                                                else
                                                                {
                                                                    socketEnviaCNET(s, registro);
                                                                }

                                                                #endregion
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                            #endregion
                                        }
                                        else if (dadosRecebidos.Substring(0, 4) == "0202")
                                        {
                                            #region - 202 -

                                            GlobalVar.frmPrincipal.AtualizaTela("Registro ISO Recebido - Confirmacao ");

                                            string registro = montaConfirmacaoCE(regIso);

                                            if (string.IsNullOrEmpty(registro))
                                            {
                                                Util.LOGCHECK("Falha na desmontagem!");
                                            }
                                            else
                                            {
                                                using (Socket s = connectSocketCNET(GlobalVar.SocketIPCE, int.Parse(GlobalVar.SocketPortCE)))
                                                {
                                                    if (s == null)
                                                    {
                                                        Util.LOGCHECK("Conexao com Servidor FALHOU");
                                                    }
                                                    else
                                                    {
                                                        socketEnviaCNET(s, registro);
                                                    }
                                                }
                                            }

                                            #endregion
                                        }
                                        else if (dadosRecebidos.Substring(0, 4) == "0400" ||
                                                 dadosRecebidos.Substring(0, 4) == "0420")
                                        {
                                            #region - 400 || 420 -

                                            string codigoIso, strRegIso;

                                            if (dadosRecebidos.Substring(0, 4) == "0400")
                                            {
                                                codigoIso = "0410";
                                                strRegIso = montaCancelamento(regIso, "012345678901234567890123456");
                                            }
                                            else
                                            {
                                                codigoIso = "0430";
                                                strRegIso = montaDesfazimento(regIso);
                                            }

                                            if (string.IsNullOrEmpty(strRegIso))
                                            {
                                                Util.LOGCHECK("Falha na desmontagem!");
                                            }
                                            else if (strRegIso.Length < 20)
                                            {
                                                Util.LOGCHECK("Falha na desmontagem! 2");
                                            }
                                            else
                                            {
                                                using (Socket s = connectSocketCNET(GlobalVar.SocketIPCE, int.Parse(GlobalVar.SocketPortCE)))
                                                {
                                                    if (s == null)
                                                    {
                                                        Util.LOGCHECK("Conexao com Servidor CNET FALHOU");
                                                    }
                                                    else
                                                    {
                                                        socketEnviaCNET(s, strRegIso);
                                                        string dadosRec400 = socketRecebeCNET(s);

                                                        Util.LOGCHECK("dadosRecebidos 0400: >" + dadosRec400 + "<");

                                                        if (dadosRec400 == "")
                                                        {
                                                            Util.LOGCHECK("Recebeu ISO vazio");
                                                        }
                                                        else if (dadosRec400.Length < 27)
                                                        {
                                                            Util.LOGCHECK("Recebeu ISO tamanho incorreto");
                                                        }
                                                        else
                                                        {
                                                            dadosRec400 = dadosRec400.PadRight(200, ' ');

                                                            isoRegistro                  = new ISO8583();
                                                            isoRegistro.codResposta      = dadosRec400.Substring(2, 2);
                                                            isoRegistro.bit127           = "000" + dadosRec400.Substring(21, 6);
                                                            isoRegistro.nsuOrigem        = regIso.nsuOrigem;
                                                            isoRegistro.codProcessamento = regIso.codProcessamento;
                                                            isoRegistro.codigo           = codigoIso;
                                                            isoRegistro.codLoja          = regIso.codLoja;
                                                            isoRegistro.terminal         = regIso.terminal;

                                                            Util.LOGCHECK("Montagem Bit 62");

                                                            isoRegistro.bit62 = !(dadosRec400.Substring(0, 4) == "0400") ? dadosRec400.Substring(7, 6) + regIso.valor : regIso.bit125.Substring(3, 6) + regIso.valor;

                                                            string registro2 = isoRegistro.registro;

                                                            Util.LOGDADOS("RESPOSTA ISO = " + registro2);

                                                            logISO(ref isoRegistro);
                                                            enviaDadosEXPRESS(registro2, client);
                                                        }
                                                    }
                                                }
                                            }

                                            #endregion
                                        }
                                    }
                                }
                            }
                        }

                        #endregion
                    }
                    catch (SocketException ex)
                    {
                        Util.LOGDADOS("RecebeRespondeTransacao *ERR " + ex.Message);
                    }
                    catch (Exception ex)
                    {
                        Util.LOGDADOS("RecebeRespondeTransacao *ERR " + ex.ToString());
                    }
                }
            }

            Util.LOGDADOS("*ERR - CAINDO FORA!");
        }
コード例 #12
0
    private string montaDesfazimento(ISO8583 regIso, bool novo)
    {
        try
        {
            string codLoja  = regIso.codLoja;
            string terminal = regIso.terminal;

            if (regIso.codLoja == "")
            {
                Log("codLoja vazio!");
                return("");
            }

            if (regIso.codLoja.Length < 4)
            {
                Log("codLoja menor de 4 chars!");
                return("");
            }

            if (regIso.terminal == "")
            {
                Log("terminal vazio!");
                return("");
            }

            if (regIso.terminal.Length < 4)
            {
                Log("terminal menor de 4 chars!");
                return("");
            }

            string s   = terminal.Substring(terminal.Length - 4, 4);
            string str = (int.Parse(codLoja.Substring(codLoja.Length - 4, 4)) + int.Parse(s)).ToString("00000000");

            // original
            //string registro = "05" + "CE" + "DF" + str.PadLeft(8, '0') + "0".PadLeft(43, '0') + regIso.valor.PadLeft(12, '0');

            // ajustado
            string registro = "05CEDF";

            if (novo)
            {
                registro += "1" + codLoja.TrimStart('0').PadLeft(7, '0') + "0".PadLeft(43, '0') + regIso.valor.PadLeft(12, '0');
            }
            else
            {
                registro += "0" + str.PadLeft(8, '0') + "0".PadLeft(43, '0') + regIso.valor.PadLeft(12, '0');
            }

            registro = registro.PadRight(200, '*') + str + regIso.nsuOrigem.TrimStart('0').PadLeft(8, '0');

            Log(registro);

            return(registro);
        }
        catch (System.Exception ex)
        {
            LogFalha("montaDesfazimento exception: " + ex.ToString());
            return("");
        }
    }
コード例 #13
0
    private string montaCancelamento(ISO8583 regIso, string trilha)
    {
        try
        {
            string codLoja  = regIso.codLoja;
            string terminal = regIso.terminal;

            if (regIso.codLoja == "")
            {
                Log("codLoja vazio!");
                return("");
            }

            if (regIso.codLoja.Length < 4)
            {
                Log("codLoja menor de 4 chars!");
                return("");
            }

            if (regIso.terminal == "")
            {
                Log("terminal vazio!");
                return("");
            }

            if (regIso.terminal.Length < 4)
            {
                Log("terminal menor de 4 chars!");
                return("");
            }

            string s   = terminal.Substring(terminal.Length - 4, 4);
            string str = (int.Parse(codLoja.Substring(codLoja.Length - 4, 4)) + int.Parse(s)).ToString("00000000");

            // original
            //string registro = "05" + "CE" + "CA" + str.PadLeft(8, '0') + trilha + regIso.bit125.Substring(3) + "00000" + regIso.bit125;

            if (regIso.bit125 == "")
            {
                Log("bit125 vazio!");
                return("");
            }

            if (regIso.bit125.Length < 4)
            {
                Log("bit125 menor de 4 chars!");
                return("");
            }

            // ajustado
            string registro = "05CECA1" +
                              codLoja.TrimStart('0').PadLeft(7, '0') +
                              trilha +
                              regIso.bit125.Substring(3) +
                              "00000" + regIso.bit125;

            registro = registro.PadRight(200, '*') + str;

            Log(registro);

            return(registro);
        }
        catch (System.Exception ex)
        {
            LogFalha("montaCancelamento exception: " + ex.ToString());
            return("");
        }
    }
コード例 #14
0
ファイル: RedisMQServices.cs プロジェクト: 51103220/mVisa
 public object Post(ISO8583 request)
 {
     return(new ISO8583Response {
         MsgResult = "Message returned from MQ"
     });
 }
コード例 #15
0
        public void RecebeRespondeTransacao()
        {
            Util.LOGENTRADA();
            Util.LOGCHECK("Esperando Conexões....");
            ++GlobalVar.numThreads;
            TcpClient     client = new TcpClient();
            NetworkStream stream = (NetworkStream)null;

            this.esperaConectar(ref client, ref stream);
            if (!GlobalVar.finalizar)
            {
                this.workThread2[GlobalVar.numThreads] = new Thread(new ThreadStart(this.RecebeRespondeTransacao));
                this.workThread2[GlobalVar.numThreads].Start();
            }
            bool flag = true;

            do
            {
                if (GlobalVar.finalizar)
                {
                    flag = false;
                }
                string str1 = this.esperaDados(ref client, ref stream);
                if (!GlobalVar.finalizar)
                {
                    if (str1 != null)
                    {
                        if (str1.StartsWith("?"))
                        {
                            str1 = str1.Substring(2);
                        }

                        if (str1.Length == 0)
                        {
                            Util.LOGCHECK("Encerrada Conexão");
                        }
                        else if (str1.Length < 20)
                        {
                            GlobalVar.frmPrincipal.AtualizaTela("Registro recebido invalido");
                            Util.LOGCHECK("Registro recebido invalido - muito pequeno");
                            Util.LOGDADOS(str1);
                        }
                        else if (str1.Substring(0, 4) != "0200" && str1.Substring(0, 4) != "0202" && str1.Substring(0, 4) != "0400" && str1.Substring(0, 4) != "0420")
                        {
                            GlobalVar.frmPrincipal.AtualizaTela("Registro recebido não formato ISO8583 esperado  - Ignorado");
                            Util.LOGCHECK("Registro recebido não formato ISO8583 esperado - Ignorado");
                            Util.LOGDADOS(str1);
                        }
                        else
                        {
                            ISO8583 regIso = new ISO8583(str1);
                            this.logISO(ref regIso);
                            if (regIso.erro)
                            {
                                GlobalVar.frmPrincipal.AtualizaTela("Registro ISO com erro");
                                Util.LOGCHECK("Registro ISO com erro");
                            }
                            else
                            {
                                frmMain  frmPrincipal = GlobalVar.frmPrincipal;
                                object[] objArray1    = new object[6];
                                objArray1[0] = (object)"Registro ISO Recebido: ";
                                object[] objArray2 = objArray1;
                                int      index1    = 1;
                                DateTime now       = DateTime.Now;
                                // ISSUE: variable of a boxed type
                                var hour = (ValueType)now.Hour;
                                objArray2[index1] = (object)hour;
                                objArray1[2]      = (object)":";
                                object[] objArray3 = objArray1;
                                int      index2    = 3;
                                now = DateTime.Now;
                                // ISSUE: variable of a boxed type
                                var minute = (ValueType)now.Minute;
                                objArray3[index2] = (object)minute;
                                objArray1[4]      = (object)":";
                                object[] objArray4 = objArray1;
                                int      index3    = 5;
                                now = DateTime.Now;
                                // ISSUE: variable of a boxed type
                                var second = (ValueType)now.Second;
                                objArray4[index3] = (object)second;
                                string t = string.Concat(objArray1);
                                frmPrincipal.AtualizaTela(t);
                                GlobalVar.frmPrincipal.AtualizaTela("Empresa: " + regIso.codLoja + " terminal: " + regIso.terminal + " tipo: " + str1.Substring(0, 4));
                                string  str2;
                                ISO8583 isoRegistro;
                                if (str1.Substring(0, 4) == "0200" && (regIso.codProcessamento == "002000" || regIso.codProcessamento == "002800"))
                                {
                                    #region - 0200 -

                                    str2 = "";
                                    string registro1 = !(regIso.codProcessamento == "002000") ? this.montaVendaCEparcelada(ref regIso) : this.montaVendaCE(regIso);
                                    Socket s         = SocketConvey.connectSocket(GlobalVar.SocketIPCE, int.Parse(GlobalVar.SocketPortCE));
                                    if (s == null)
                                    {
                                        Util.LOGCHECK("Conexao com Servidor FALHOU");
                                        Util.LOGSAIDA();
                                        return;
                                    }
                                    this.socketEnvia(s, registro1);
                                    string str3 = this.socketRecebe(s);
                                    isoRegistro             = new ISO8583();
                                    isoRegistro.codResposta = str3.Substring(2, 2);
                                    if (regIso.codProcessamento != "002000")
                                    {
                                        isoRegistro.bit63 = regIso.bit62;
                                    }
                                    isoRegistro.bit127           = "000" + str3.Substring(7, 6);
                                    isoRegistro.nsuOrigem        = regIso.nsuOrigem;
                                    isoRegistro.codProcessamento = regIso.codProcessamento;
                                    isoRegistro.codigo           = "0210";
                                    isoRegistro.valor            = regIso.valor;
                                    isoRegistro.codResposta      = str3.Substring(2, 2);
                                    isoRegistro.terminal         = regIso.terminal;
                                    isoRegistro.codLoja          = regIso.codLoja;
                                    string str4;
                                    string str5;
                                    string str6;
                                    if (regIso.trilha2.Trim().Length == 0)
                                    {
                                        str4 = "999999999999999999999999999";
                                        str5 = "999999";
                                        str6 = "999999";
                                    }
                                    else if (regIso.trilha2.Trim().Length == 27)
                                    {
                                        str4 = regIso.trilha2.Trim();
                                        str5 = regIso.trilha2.Trim().Substring(6, 6);
                                        str6 = regIso.trilha2.Trim().Substring(12, 6);
                                    }
                                    else
                                    {
                                        str5 = regIso.trilha2.Substring(17, 6);
                                        str6 = regIso.trilha2.Substring(23, 6);
                                        str4 = ("999999" + str5 + str6 + regIso.trilha2.Substring(29, 3)).PadLeft(27, '0');
                                    }
                                    isoRegistro.bit62 = !(str3.Substring(2, 2) == "00") ? str3.Substring(73, 20) : str5 + str6 + str4.Substring(18, 3) + str3.Substring(27, 40);
                                    string registro2 = isoRegistro.registro;
                                    this.logISO(ref isoRegistro);
                                    this.enviaDados(registro2, stream);

                                    #endregion
                                }
                                else if (str1.Substring(0, 4) == "0202")
                                {
                                    #region - 0202 -

                                    GlobalVar.frmPrincipal.AtualizaTela("Registro ISO Recebido - Confirmacao ");
                                    string registro = this.montaConfirmacaoCE(regIso);
                                    Socket s        = SocketConvey.connectSocket(GlobalVar.SocketIPCE, int.Parse(GlobalVar.SocketPortCE));
                                    if (s == null)
                                    {
                                        Util.LOGCHECK("Conexao com Servidor FALHOU");
                                        Util.LOGSAIDA();
                                    }
                                    else
                                    {
                                        this.socketEnvia(s, registro);
                                    }

                                    #endregion
                                }
                                else if (str1.Substring(0, 4) == "0400" || str1.Substring(0, 4) == "0420")
                                {
                                    #region - 0400 -

                                    str2 = "";
                                    string str3;
                                    string registro1;
                                    if (str1.Substring(0, 4) == "0400")
                                    {
                                        str3      = "0410";
                                        registro1 = this.montaCancelamento(regIso, "012345678901234567890123456");
                                    }
                                    else
                                    {
                                        str3      = "0430";
                                        registro1 = this.montaDesfazimento(regIso);
                                    }
                                    Socket s = SocketConvey.connectSocket(GlobalVar.SocketIPCE, int.Parse(GlobalVar.SocketPortCE));
                                    if (s == null)
                                    {
                                        Util.LOGCHECK("Conexao com Servidor FALHOU");
                                        Util.LOGSAIDA();
                                        return;
                                    }
                                    this.socketEnvia(s, registro1);
                                    string str4 = this.socketRecebe(s);
                                    isoRegistro                  = new ISO8583();
                                    isoRegistro.codResposta      = str4.Substring(2, 2);
                                    isoRegistro.bit127           = "000" + str4.Substring(21, 6);
                                    isoRegistro.nsuOrigem        = regIso.nsuOrigem;
                                    isoRegistro.codProcessamento = regIso.codProcessamento;
                                    isoRegistro.codigo           = str3;
                                    isoRegistro.codLoja          = regIso.codLoja;
                                    isoRegistro.terminal         = regIso.terminal;
                                    isoRegistro.bit62            = !(str1.Substring(0, 4) == "0400") ? str4.Substring(7, 6) + regIso.valor : regIso.bit125.Substring(3, 6) + regIso.valor;
                                    string registro2 = isoRegistro.registro;
                                    Util.LOGDADOS("RESPOSTA ISO = " + registro2);
                                    this.logISO(ref isoRegistro);
                                    this.enviaDados(registro2, stream);

                                    #endregion
                                }
                            }
                        }
                    }
                }
                else
                {
                    goto label_6;
                }
            }while (flag);
            goto label_40;
label_6:
            return;

label_40:
            this.closeCliente(client);
            Util.LOGSAIDA();
        }