private void NumOrden_GotFocus(object sender, RoutedEventArgs e)
 {
     if (TypeUsuario.Id_Company == "0059" && NumOrden.IsEnabled)
     {
         TypeUsuario.strRefReaDig = "BA";
         Importe.Focus();
         frmReaderDigest frm = new frmReaderDigest();
         frm.Show();
     }
 }
 private void NumMesero_GotFocus(object sender, RoutedEventArgs e)
 {
     if (TypeUsuario.Id_Company == "0059" && NumOrden.IsEnabled)
     {
         TypeUsuario.strRefReaDig = "MA";
         Importe.Focus();
         frmReaderDigest reader = new frmReaderDigest();
         reader.ShowDialog();
         NumOrden.Text = Globales.referenciaAux;
     }
 }
        private void CmdLeer_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(NumOrden.Text))
            {
                Globales.MessageBoxMit("Ingresa Referencia");
                NumOrden.Focus();
                return;
            }
            if (string.IsNullOrWhiteSpace(NumCuarto.Text))
            {
                Globales.MessageBoxMit("Ingresa Cuarto");
                NumCuarto.Focus();
                return;
            }
            if (string.IsNullOrWhiteSpace(Importe.Text))
            {
                Globales.MessageBoxMit("Ingresa Importe");
                Importe.Focus();
                return;
            }

            realizaOp();
        }
        private void realizaOp()
        {
            if (string.IsNullOrWhiteSpace(NumOrden.Text))
            {
                Globales.MessageBoxMit("Introduzca" + TypeUsuario.reference);
                NumOrden.Focus();
                return;
            }
            else if (string.IsNullOrWhiteSpace(NumMesero.Text))
            {
                Globales.MessageBoxMit("Introduzca el Número de Mesero.");
                NumMesero.Focus();
                return;
            }
            else if (string.IsNullOrWhiteSpace(NumTurno.Text))
            {
                Globales.MessageBoxMit("Introduzca el Turno");
                NumTurno.Focus();
                return;
            }
            else if (string.IsNullOrWhiteSpace(Importe.Text))
            {
                Globales.MessageBoxMit("Introduzca el importe.");
                Importe.Focus();
                return;
            }
            else if ((Utils.Mid(Globales.GetDataXml("facileasing", TypeUsuario.CadenaXML), 1, 1) == "1") && (Globales.GetDataXml("tarjeta", Globales.cpHTTP_sResult) != NumTdc.Text))
            {
                Globales.MessageBoxMit("La Tarjeta Deslizada no corresponde con el Servicio a cobrar");
            }
            else
            if (TypeUsuario.Id_Company == "0059")
            {
                if (NumOrden.Text.Length != 28)
                {
                    Globales.MessageBoxMit("El no. de REFERENCIA debe ser de 28 posiciones");
                    NumOrden.Focus();
                    return;
                }
            }

            if (!Globales.isNumeric(Importe.Text))
            {
                Globales.MessageBoxMit("El importe debe ser numérico.");
                Importe.Focus();
                return;
            }
            CmdLeer.IsEnabled   = false;
            cboBanco.IsEnabled  = false;
            FormaPago.IsEnabled = false;
            NumOrden.IsEnabled  = false;
            Importe.IsEnabled   = false;
            NumMesero.IsEnabled = false;
            NumTurno.IsEnabled  = false;

            Globales.cpIntegraEMV.dbgSetUrl(Globales.URL_3GATE);
            //   // 'Prepara PinPad y DLL, para EMV
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
            Globales.cpIntegraEMV.dbgStartTxEMV(Importe.Text);
            CmdLeer.IsEnabled    = false;
            Mouse.OverrideCursor = null;
            if (string.IsNullOrWhiteSpace(Globales.cpIntegraEMV.chkPp_CdError()) && !string.IsNullOrWhiteSpace(Globales.cpIntegraEMV.chkCc_Number()))
            {
                //       // 'Extrae Datos de la tarjeta
                NumTdc.Text = Globales.cpIntegraEMV.chkCc_Number();
                NomTdc.Text = Globales.cpIntegraEMV.chkCc_Name();

                this.mes  = Globales.cpIntegraEMV.chkCc_ExpMonth();
                this.anio = Globales.cpIntegraEMV.chkCc_ExpYear();

                this.TFECHAVENC.Text   = string.Format("{0}/{1}", this.mes, this.anio);
                Globales.merchantBanda = Globales.cpIntegraEMV.dbgGetMerchantBanda("9");

                if (Globales.merchantBanda != "00000")
                {
                    Globales.isAmex = Globales.cpIntegraEMV.dbgGetisAmex();
                    this.formaPago();
                    CmdLeer.Visibility   = Visibility.Hidden;
                    CmdEnviar.IsEnabled  = true;
                    CmdEnviar.Visibility = Visibility.Visible;

                    if (!Globales.cpIntegraEMV.dbgTxMonitor())
                    {
                        Globales.MessageBoxMitError(Globales.cpIntegraEMV.getRspDsError());

                        CmdLeer.Visibility   = Visibility.Visible;
                        CmdLeer.IsEnabled    = true;
                        CmdEnviar.IsEnabled  = false;
                        CmdEnviar.Visibility = Visibility.Hidden;
                        FormaPago.Visibility = Visibility.Hidden;
                        //  Label(6).Visibility = Visibility.Hidden;
                        NumTdc.Text          = "";
                        NomTdc.Text          = "";
                        this.TFECHAVENC.Text = string.Empty;


                        this.mes  = string.Empty;
                        this.anio = string.Empty;
                    }
                }
                else
                {
                    Globales.MessageBoxMitError(Globales.cpIntegraEMV.getRspDsError());
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(Globales.cpIntegraEMV.chkPp_CdError()))
                {
                    Globales.MessageBoxMitError("Error en leer la tarjeta...");
                }
                CmdLeer.IsEnabled = true;
            }
        }
        private void CmdEnviar_Click(object sender, RoutedEventArgs e)
        {
            Globales.strNombreFP = NOMBRE_GENERAL + ".cmdEnviar_Click()";
            string mensaje = string.Empty;

            CmdEnviar.IsEnabled = false;
            FormaPago.IsEnabled = false;

            if (string.IsNullOrWhiteSpace(NumTdc.Text) || string.IsNullOrWhiteSpace(this.mes) || string.IsNullOrWhiteSpace(this.anio))
            {
                Globales.MessageBoxMit("Deslice la tarjeta bancaria");
                CmdEnviar.IsEnabled = true;
                return;
            }
            else if (string.IsNullOrWhiteSpace(NumOrden.Text))
            {
                Globales.MessageBoxMit("Introduzca" + TypeUsuario.reference + "");
                NumOrden.Focus();
                CmdEnviar.IsEnabled = true;
                return;
            }
            else if (string.IsNullOrWhiteSpace(NumMesero.Text))
            {
                Globales.MessageBoxMit("Introduzca el Número de Mesero.");
                NumMesero.Focus();
                CmdEnviar.IsEnabled = true;
                return;
            }
            else if (string.IsNullOrWhiteSpace(NumTurno.Text))
            {
                Globales.MessageBoxMit("Introduzca el Turno.");
                NumTurno.Focus();
                CmdEnviar.IsEnabled = true;
                return;
            }
            else if (string.IsNullOrWhiteSpace(Importe.Text))
            {
                Globales.MessageBoxMit("Introduzca el Turno.");
                Importe.Focus();
                CmdEnviar.IsEnabled = true;
                return;
            }
            else if (Utils.Mid(Globales.GetDataXml("facileasing", TypeUsuario.CadenaXML), 1, 1) == "1" && (Globales.GetDataXml("tarjeta", Globales.cpHTTP_sResult) != NumTdc.Text))
            {
                Globales.MessageBoxMit("La Tarjeta Deslizada no corresponde con el Servicio a cobrar");
                CmdEnviar.IsEnabled = true;
                return;
            }
            else
            if (TypeUsuario.Id_Company == "0059")
            {
                if (NumOrden.Text.Length != 28)
                {
                    Globales.MessageBoxMit("El no. de REFERENCIA debe ser de 28 posiciones");
                    NumOrden.Focus();
                    CmdEnviar.IsEnabled = true;
                    return;
                }
            }


            // 'EMV FULL
            string strTypeC        = string.Empty;
            string strCadEncriptar = string.Empty;

            Voucher = string.Empty;


            if (Globales.isAmex)
            {
                strTypeC = "AMEX";
            }
            else
            {
                strTypeC = "V/MC";
            }

            // 'Se agrega validación para no permitir enviar la transacción sin contar con merchant
            if (string.IsNullOrWhiteSpace(Globales.merchantBanda))
            {
                Globales.MessageBoxMit("No hay planes de pago para esta tarjeta, por favor cambie la tarjeta.");
                CmdEnviar.IsEnabled = true;
                return;
            }

            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
            string moneda = lblMoneda.Content.ToString();

            Globales.cpIntegraEMV.dbgSetCurrencyType(moneda);
            Globales.cpIntegraEMV.sndPreventaEMV(TypeUsuario.usu, TypeUsuario.Pass, "", TypeUsuario.Id_Company, TypeUsuario.Id_Branch,
                                                 TypeUsuario.country, strTypeC, Globales.merchantBanda, NumOrden.Text,
                                                 "9", moneda, NumMesero.Text, NumTurno.Text, Globales.csvAmexenBanda);
            Mouse.OverrideCursor = null;
            //frmPlanPagos.merchant = ""
            //frmPlanPagos.TipoTarjeta = ""
            //frmPlanPagos.Bin = ""
            Globales.csvAmexenBanda = "";
            string temporal = Globales.cpIntegraEMV.getRspXML();

            string aux = Globales.cpIntegraEMV.getRspDsResponse();

            aux = aux.ToLower();
            switch (aux)
            {
            case "approved":
                cboBanco.IsEnabled  = false;
                FormaPago.IsEnabled = false;
                NumOrden.IsEnabled  = false;
                Importe.IsEnabled   = false;
                NumMesero.IsEnabled = false;
                NumTurno.IsEnabled  = false;
                mensaje             = Globales.cpIntegraEMV.getRspAuth();
                if (TypeUsuario.Id_Company == Globales.EMPREF && TypeUsuario.Id_Branch == Globales.EMPREF2)
                {
                    frmReferencia refe = new frmReferencia();
                    refe.ShowDialog();
                    if (!refe.cancelar)
                    {
                        Globales.cpIntegraEMV.sndReimpresion(TypeUsuario.usu, TypeUsuario.Pass, TypeUsuario.Id_Company, TypeUsuario.Id_Branch, TypeUsuario.country, Globales.cpIntegraEMV.getRspOperationNumber());
                        Mouse.OverrideCursor = null;
                    }
                }
                Globales.MessageBoxMitApproved(mensaje);

                TypeUsuario.strVoucherCoP = Globales.cpIntegraEMV.getRspVoucher();
                CmdNuevo.Visibility       = Visibility.Visible;
                CmdEnviar.Visibility      = Visibility.Hidden;
                cmdVoucher.IsEnabled      = true;

                this.BENVIAMAIL.Visibility = TypeUsuario.enviaCorreo ? Visibility.Visible : Visibility.Hidden;
                this.BENVIAMAIL.Tag        = this.NomTdc.Text;

                Voucher = Globales.cpIntegraEMV.getRspVoucher();

                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                Globales.PrintOptions(Voucher, Globales.cpIntegraEMV.getRspOperationNumber());
                Mouse.OverrideCursor = null;
                break;

            case "denied":
                //label4.Text = "La transacción ha finalizado, si deseas hacer otra transacción haz  clic en el botón Otro Cobro.";
                if (Utils.Mid(Globales.GetDataXml("facileasing", TypeUsuario.CadenaXML), 1, 1) == "1")
                {
                    Globales.cpHTTP_Clear();
                    Globales.cpHTTP_sURL_cpCUCT = TypeUsuario.Url;
                    strCadEncriptar             = "&op=facileasingcobrorechazada" +
                                                  "&nueconomico=" + strNoEconomico +
                                                  "&nuservicio=" + strNoServicio +
                                                  "&nuproveedor=" + strProveedor +
                                                  "&transaccion=" + Globales.cpIntegraEMV.getRspOperationNumber() +
                                                  "&importe=" + Importe +
                                                  "&numtdc=" + Utils.Mid(NumTdc.Text, 13, 4) +
                                                  "&auth=" + "" +
                                                  "&response=" + Globales.cpIntegraEMV.getRspCdResponse();
                    Globales.cpHTTP_cadena1 = "enc=" + Globales.encryptString(strCadEncriptar, Globales.KEY_RC4, true);
                    if (Globales.cpHTTP_SendcpCUCT())
                    {
                    }
                }
                Globales.cpHTTP_cadena1 = "enc=" + Globales.encryptString(strCadEncriptar, Globales.KEY_RC4, true);
                mensaje = Globales.msjRech + " " + Globales.cpIntegraEMV.getRspCdResponse() + " " + Globales.cpIntegraEMV.getRspFriendlyResponse();
                Globales.MessageBoxMitDenied(mensaje);
                CmdNuevo.Visibility  = Visibility.Visible;
                CmdEnviar.Visibility = Visibility.Hidden;
                break;

            case "error":
                if (Globales.EMVLector == "1" && (TypeUsuario.strTipoLector == "3" || TypeUsuario.strTipoLector == "4"))
                {
                    CmdLeer.Visibility   = Visibility.Visible;
                    CmdLeer.IsEnabled    = true;
                    CmdEnviar.IsEnabled  = false;
                    CmdEnviar.Visibility = Visibility.Hidden;
                    cboBanco.IsEnabled   = true;
                    FormaPago.IsEnabled  = true;
                    Importe.IsEnabled    = true;
                    NumOrden.IsEnabled   = true;
                    NumMesero.IsEnabled  = true;
                    NumTurno.IsEnabled   = true;
                    NumTdc.Text          = "";
                    TFECHAVENC.Text      = "";
                    NomTdc.Text          = "";
                }
                else
                {
                    CmdEnviar.Visibility = Visibility.Visible;
                    CmdEnviar.IsEnabled  = true;
                }
                mensaje = Globales.cpIntegraEMV.getRspDsError();
                Globales.MessageBoxMitError(mensaje);
                if (mensaje.Contains("La transaccion ya fue aprobada"))
                {
                    CmdNuevo.Visibility  = Visibility.Visible;
                    CmdLeer.Visibility   = Visibility.Hidden;
                    cboBanco.IsEnabled   = false;
                    FormaPago.IsEnabled  = false;
                    NumOrden.IsEnabled   = false;
                    Importe.IsEnabled    = false;
                    NumMesero.IsEnabled  = false;
                    NumTurno.IsEnabled   = false;
                    CmdEnviar.Visibility = Visibility.Hidden;
                    CmdEnviar.IsEnabled  = false;
                }
                else
                {
                    CmdNuevo.Visibility = Visibility.Hidden;
                }
                Globales.cpIntegraEMV.dbgCancelOperation();
                break;

            default:
                //label4.Text = "La transacción ha finalizado, si deseas intentar nuevamente haz  clic en el botón Activar Lector.";
                if (Globales.EMVLector == "1" && (TypeUsuario.strTipoLector == "3" || TypeUsuario.strTipoLector == "4"))
                {
                    CmdEnviar.IsEnabled = false;
                    CmdLeer.Visibility  = Visibility.Visible;
                    CmdLeer.IsEnabled   = true;
                    cboBanco.IsEnabled  = true;
                    FormaPago.IsEnabled = true;
                    Importe.IsEnabled   = true;
                    NumOrden.IsEnabled  = true;
                    NumMesero.IsEnabled = true;
                    NumTurno.IsEnabled  = true;
                }
                else
                {
                    CmdEnviar.Visibility = Visibility.Visible;
                    CmdEnviar.IsEnabled  = true;
                }
                mensaje = "Error de conexión, verifique su reporte.";
                Globales.MessageBoxMitError(mensaje);
                CmdNuevo.Visibility = Visibility.Hidden;


                break;
            }
            Mouse.OverrideCursor = null;
        }
        private void realizaOp()
        {
            if (string.IsNullOrWhiteSpace(NumOrden.Text))
            {
                Globales.MessageBoxMit("Introduzca" + TypeUsuario.reference + ".");
                NumOrden.Focus();
            }
            else if (string.IsNullOrWhiteSpace(Importe.Text))
            {
                Globales.MessageBoxMit("Introduzca el importe.");
                Importe.Focus();
            }
            else if (string.IsNullOrWhiteSpace(NumCuarto.Text))
            {
                Globales.MessageBoxMit("Introduzca el Dato Adicional.");
                NumCuarto.Focus();
            }
            else if (TypeUsuario.Id_Company == "0059")
            {
                if (NumOrden.Text.Length != 28)
                {
                    Globales.MessageBoxMit("El no. de REFERENCIA debe ser de 28 posiciones");
                    NumOrden.Focus();
                    return;
                }
            }
            if (!Globales.IsNumeric(Importe.Text))
            {
                Globales.MessageBoxMit("El importe debe ser numérico." + Globales.NOMBRE_APP);
                Importe.Focus();

                return;
            }
            CmdLeer.IsEnabled    = false;
            FormaPago.IsEnabled  = false;
            NumOrden.IsEnabled   = false;
            Importe.IsEnabled    = false;
            NumCuarto.IsEnabled  = false;
            StatusCmd            = false;
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
            Globales.cpIntegraEMV.dbgSetUrl(Globales.URL_3GATE);
            Globales.cpIntegraEMV.dbgStartTxEMV(Importe.Text);
            CmdLeer.IsEnabled = false;
            if (string.IsNullOrWhiteSpace(Globales.cpIntegraEMV.chkPp_CdError()) && !string.IsNullOrWhiteSpace(Globales.cpIntegraEMV.chkCc_Number()))
            {
                NumTdc.Text   = Globales.cpIntegraEMV.chkCc_Number();
                NomTdc.Text   = Globales.cpIntegraEMV.chkCc_Name();
                numeroTarjeta = NomTdc.Text;


                this._mes              = Globales.cpIntegraEMV.chkCc_ExpMonth();
                this._anio             = Globales.cpIntegraEMV.chkCc_ExpYear();
                this.TFECHA.Text       = string.Format("{0}/{1}", this._mes, this._anio);
                Globales.merchantBanda = Globales.cpIntegraEMV.dbgGetMerchantBanda("9");
                if (Globales.merchantBanda != "00000")
                {
                    Globales.isAmex = Globales.cpIntegraEMV.dbgGetisAmex();
                    FormaPago_Click();
                    CmdLeer.Visibility   = Visibility.Hidden;
                    CmdEnviar.IsEnabled  = true;
                    CmdEnviar.Visibility = Visibility.Visible;

                    if (!Globales.cpIntegraEMV.dbgTxMonitor())
                    {
                        Globales.MessageBoxMit(Globales.cpIntegraEMV.getRspDsError());
                        CmdLeer.Visibility   = Visibility.Visible;
                        CmdLeer.IsEnabled    = true;
                        CmdEnviar.IsEnabled  = false;
                        CmdEnviar.Visibility = Visibility.Hidden;
                        FormaPago.Visibility = Visibility.Hidden;
                        NumTdc.Text          = "";
                        NomTdc.Text          = "";

                        this._anio       = string.Empty;
                        this._mes        = string.Empty;
                        this.TFECHA.Text = string.Empty;

                        StatusCmd = true;
                    }
                }
                else
                {
                    Globales.MessageBoxMit(Globales.cpIntegraEMV.getRspDsError());
                    CmdNuevo_Click();
                }
            }
            Mouse.OverrideCursor = null;
        }
        private void CmdEnviar_Click(object sender, RoutedEventArgs e)
        {
            Globales.strNombreFP = NOMBRE_GENERAL + ".cmdEnviar_Click()";
            CmdEnviar.IsEnabled  = false;
            if (string.IsNullOrWhiteSpace(NumTdc.Text) || string.IsNullOrWhiteSpace(this._mes) || string.IsNullOrWhiteSpace(this._anio))
            {
                Globales.MessageBoxMit("Deslice la tarjeta bancaria.");
                CmdEnviar.IsEnabled = true;
            }
            else if (string.IsNullOrWhiteSpace(NumOrden.Text))
            {
                Globales.MessageBoxMit("Introduzca " + TypeUsuario.reference + ".");
                NumOrden.Focus();
                CmdEnviar.IsEnabled = true;
            }
            else if (string.IsNullOrWhiteSpace(NumCuarto.Text))
            {
                Globales.MessageBoxMit("Introduzca el Dato Adicional. ");
                NumCuarto.Focus();
                CmdEnviar.IsEnabled = true;
            }
            else if (string.IsNullOrWhiteSpace(Importe.Text))
            {
                Globales.MessageBoxMit("Introduzca el importe.");
                Importe.Focus();
                CmdEnviar.IsEnabled = true;
            }
            else if ((Utils.Mid(Globales.GetDataXml("facileasing", TypeUsuario.CadenaXML), 1, 1) == "1") && (Globales.GetDataXml("tarjeta", Globales.cpHTTP_sResult) != NumTdc.Text))
            {
                Globales.MessageBoxMit("La Tarjeta Deslizada no corresponde con el Servicio a cobrar");
                CmdEnviar.IsEnabled = true;
            }

            else if (TypeUsuario.Id_Company == "0059")
            {
                if (NumOrden.Text.Length != 28)
                {
                    Globales.MessageBoxMit("El no. de REFERENCIA debe ser de 28 posiciones");
                    NumOrden.Focus();
                    CmdEnviar.IsEnabled = true;
                    return;
                }
            }

            if (!Globales.IsNumeric(Importe.Text))
            {
                Globales.MessageBoxMit("El importe debe ser numérico.");
                Importe.Focus();
                CmdEnviar.IsEnabled = true;
                return;
            }
            if (string.IsNullOrWhiteSpace(Globales.merchantBanda))
            {
                Globales.MessageBoxMit("No hay planes de pago para esta tarjeta, por favor cambie la tarjeta.");
                CmdLeer.Visibility   = Visibility.Visible;
                CmdLeer.IsEnabled    = true;
                CmdEnviar.IsEnabled  = false;
                CmdEnviar.Visibility = Visibility.Hidden;
                CmdNuevo.Visibility  = Visibility.Hidden;
                CmdNuevo.IsEnabled   = false;
                Importe.IsEnabled    = true;
                NumOrden.IsEnabled   = true;
                NumCuarto.IsEnabled  = true;
                NumOrden.IsEnabled   = true;
                Importe.IsEnabled    = true;
                StatusCmd            = true;
                NumTdc.Text          = "";
                this.TFECHA.Text     = string.Empty;
                NomTdc.Text          = "";
                Globales.cpIntegraEMV.dbgCancelOperation();
                return;
            }
            string strTypeC        = string.Empty;
            string strCadEncriptar = string.Empty;

            Voucher = string.Empty;

            if (Globales.isAmex)
            {
                strTypeC = "AMEX";
            }
            else
            {
                strTypeC = "V/MC";
            }


            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
            Globales.cpIntegraEMV.dbgSetCurrencyType(lblMoneda.Content.ToString());
            Globales.cpIntegraEMV.sndCheckInEMV(TypeUsuario.usu, TypeUsuario.Pass, "", TypeUsuario.Id_Company, TypeUsuario.Id_Branch,
                                                TypeUsuario.country, strTypeC, Globales.merchantBanda, NumOrden.Text,
                                                "9", lblMoneda.Content.ToString(), NumCuarto.Text, Globales.csvAmexenBanda);
            Globales.csvAmexenBanda = "";
            string mensaje = string.Empty;
            string caso    = Globales.cpIntegraEMV.getRspDsResponse();

            Mouse.OverrideCursor = null;
            switch (caso)
            {
            case "approved":    //'Transacción Aprobada
                NumOrden.IsEnabled  = false;
                Importe.IsEnabled   = false;
                NumCuarto.IsEnabled = false;
                mensaje             = Globales.cpIntegraEMV.getRspAuth();
                if (TypeUsuario.Id_Company == Globales.EMPREF && TypeUsuario.Id_Branch == Globales.EMPREF2)
                {
                    frmReferencia refe = new frmReferencia();
                    refe.ShowDialog();
                    if (!refe.cancelar)
                    {
                        Globales.cpIntegraEMV.sndReimpresion(TypeUsuario.usu, TypeUsuario.Pass, TypeUsuario.Id_Company, TypeUsuario.Id_Branch, TypeUsuario.country, Globales.cpIntegraEMV.getRspOperationNumber());
                        Mouse.OverrideCursor = null;
                    }
                }
                Globales.MessageBoxMitApproved(mensaje);
                TypeUsuario.strVoucherCoP  = Globales.cpIntegraEMV.getRspVoucher().Trim();
                CmdNuevo.Visibility        = Visibility.Visible;
                CmdEnviar.Visibility       = Visibility.Hidden;
                this.BENVIAMAIL.Visibility = TypeUsuario.enviaCorreo ? Visibility.Visible : Visibility.Hidden;
                this.BENVIAMAIL.Tag        = this.NomTdc.Text;
                //'************************************************************************************************
                //        ''********************************** FIRMA EN PANEL *********************************************
                //        'VALIDACIONES PARA LA FIRMA EN PANEL
                string textoAgua = string.Empty;
                textoAgua  = "Folio: " + Globales.cpIntegraEMV.getRspOperationNumber() + System.Environment.NewLine;
                textoAgua += "Auth: " + Globales.cpIntegraEMV.getRspAuth() + System.Environment.NewLine;
                textoAgua += "Importe: " + Globales.cpIntegraEMV.getTx_Amount() + System.Environment.NewLine;
                textoAgua += "Fecha: " + Globales.cpIntegraEMV.getRspDate() + System.Environment.NewLine;
                textoAgua += "Merchant: " + Globales.cpIntegraEMV.getRspDsMerchant() + System.Environment.NewLine;
                textoAgua += " " + System.Environment.NewLine;
                textoAgua += "___________________" + System.Environment.NewLine;
                textoAgua += "FIRMA DIGITALIZADA:" + System.Environment.NewLine;
                //'************************************************************************************************
                //'valida si la tarjeta es Chip and Pin
                bool   IsChipAndPin = false; bool esQPS = false;
                string cadenaHexFirma = string.Empty;
                int    tipoVta        = 1;
                //'valida si es chip and pin
                if (Globales.cpIntegraEMV.chkCc_IsPin() == "01")
                {
                    IsChipAndPin = true;
                }

                //'************************************************************************************************
                //'valida si la venta es QPS
                if (Globales.cpIntegraEMV.getRspVoucher().Contains("@cnn Autorizado sin Firma ") && tipoVta == 1 && !IsChipAndPin)
                {
                    esQPS = true;
                }

                //'************************************************************************************************
                // 'Si la PinPad no soporta Firma en Panel y no es touch, sigue el flujo normal de PcPay
                if (!Globales.cpIntegraEMV.EsTouch() && !Globales.cpIntegraEMV.getRspSoportaFirmaPanel())
                {
                    goto GoImpresion;
                }

                //'************************************************************************************************
                //'Si la PinPad Soporta Firma en Panel y no es touch,
                if (!Globales.cpIntegraEMV.EsTouch() && Globales.cpIntegraEMV.getRspSoportaFirmaPanel())
                {
                    //'Llama a la función de obtener la firma en Panel
                    cadenaHexFirma = Globales.cpIntegraEMV.sndObtieneFirmaPanel(false, textoAgua, Globales.cpIntegraEMV.getRspVoucher(),
                                                                                IsChipAndPin, Globales.cpIntegraEMV.chkPp_Trademark(), (short)tipoVta, esQPS);

                    if (!cadenaHexFirma.Contains("Error"))
                    {
                        // 'Llama a la funcion de Guardar la firma
                        Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                        if (Globales.cpIntegraEMV.sndGuardaFirmaPanel(cadenaHexFirma, Program.ipFirmaPanel, Globales.cpIntegraEMV.getRspOperationNumber(), Globales.cpIntegraEMV.chkPp_Serial()))
                        {
                            imgEmailFirmaPanel.Visibility = Visibility.Visible;
                        }
                        Mouse.OverrideCursor = null;
                    }
                    else
                    {
                        Globales.MessageBoxMit("No se pudo obtener la imagen del PinPad" + "\n" + cadenaHexFirma);
                    }

                    goto GoImpresion;
                }



                //'************************************************************************************************
                //'SI EL DISPOSITIVO TIENE CAPACIDAD TOUCH
                if (Globales.cpIntegraEMV.EsTouch())
                {
                    if (TypeUsuario.UtilizarCapacidadTouch && TypeUsuario.EnviarVoucherMail)
                    {
                        Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                        if (!Globales.ObtieneFirmaPanel(Program.ipFirmaPanel, textoAgua, (short)tipoVta, IsChipAndPin, esQPS))
                        {
                            goto GoImpresion;
                        }
                        else
                        {
                            goto finaliza;
                        }
                        Mouse.OverrideCursor = null;
                    }


                    if (TypeUsuario.UtilizarCapacidadTouch && !TypeUsuario.EnviarVoucherMail)
                    {
                        // 'Llama a la función de obtener la firma en Panel
                        cadenaHexFirma = Globales.cpIntegraEMV.sndObtieneFirmaPanel(true, textoAgua,
                                                                                    Globales.cpIntegraEMV.getRspVoucher(), IsChipAndPin, Globales.cpIntegraEMV.chkPp_Trademark(), (short)tipoVta, esQPS);

                        if (!cadenaHexFirma.Contains("Error"))
                        {
                            // 'Llama a la funcion de Guardar la firma
                            if (Globales.cpIntegraEMV.sndGuardaFirmaPanel(cadenaHexFirma, Program.ipFirmaPanel, Globales.cpIntegraEMV.getRspOperationNumber(), Globales.cpIntegraEMV.chkPp_Serial()))
                            {
                                imgEmailFirmaPanel.Visibility = Visibility.Visible;
                            }
                        }
                        else
                        {
                            Globales.MessageBoxMit("No se pudo obtener la imagen del PinPad" + "\n" + cadenaHexFirma);
                        }

                        goto GoImpresion;
                    }


                    if (!TypeUsuario.UtilizarCapacidadTouch && !TypeUsuario.EnviarVoucherMail)
                    {
                        if (Globales.cpIntegraEMV.getRspSoportaFirmaPanel())
                        {
                            //'Llama a la función de obtener la firma en Panel
                            cadenaHexFirma = Globales.cpIntegraEMV.sndObtieneFirmaPanel(false, textoAgua,
                                                                                        Globales.cpIntegraEMV.getRspVoucher(), IsChipAndPin, Globales.cpIntegraEMV.chkPp_Trademark(), (short)tipoVta, esQPS);

                            if (!cadenaHexFirma.Contains("Error"))
                            {
                                //'Llama a la funcion de Guardar la firma
                                if (Globales.cpIntegraEMV.sndGuardaFirmaPanel(cadenaHexFirma, Program.ipFirmaPanel, Globales.cpIntegraEMV.getRspOperationNumber(), Globales.cpIntegraEMV.chkPp_Serial()))
                                {
                                    imgEmailFirmaPanel.Visibility = Visibility.Visible;
                                }
                            }
                            else
                            {
                                Globales.MessageBoxMit("No se pudo obtener la imagen del PinPad" + "\n" + cadenaHexFirma);
                            }
                        }

                        goto GoImpresion;
                    }
                }
                if (imgEmailFirmaPanel.Visibility == Visibility.Hidden)
                {
                    BENVIAMAIL.Visibility = (TypeUsuario.enviaCorreo) ? Visibility.Visible : Visibility.Hidden;
                }
GoImpresion:
                Voucher = Globales.cpIntegraEMV.getRspVoucher();
                CmdVoucher.IsEnabled = true;
                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                Globales.PrintOptions(Voucher, Globales.cpIntegraEMV.getRspOperationNumber());    //, Impresora
                Mouse.OverrideCursor = null;

finaliza:
                break;

            case "denied":
                if (Utils.Mid(Globales.GetDataXml("facileasing", TypeUsuario.CadenaXML), 1, 1) == "1")
                {
                    Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                    Globales.cpHTTP_Clear();
                    Globales.cpHTTP_sURL_cpCUCT = TypeUsuario.Url;
                    strCadEncriptar             = "&op=facileasingcobrorechazada" +
                                                  "&nueconomico=" + strNoEconomico +
                                                  "&nuservicio=" + strNoServicio +
                                                  "&nuproveedor=" + strProveedor +
                                                  "&transaccion=" + Globales.cpIntegraEMV.getRspOperationNumber() +
                                                  "&importe=" + Importe +
                                                  "&numtdc=" + Utils.Mid(NumTdc.Text, 13, 4) +
                                                  "&auth=" + "" +
                                                  "&response=" + Globales.cpIntegraEMV.getRspCdResponse();
                    Globales.cpHTTP_cadena1 = "enc=" + Globales.encryptString(strCadEncriptar, Globales.KEY_RC4, true);
                    if (Globales.cpHTTP_SendcpCUCT())
                    {
                    }
                    Mouse.OverrideCursor = null;
                }
                Globales.cpHTTP_cadena1 = "enc=" + Globales.encryptString(strCadEncriptar, Globales.KEY_RC4, true);
                mensaje = Globales.msjRech + "\n" + Globales.cpIntegraEMV.getRspCdResponse() + " " + Globales.cpIntegraEMV.getRspFriendlyResponse();
                Globales.MessageBoxMitDenied(mensaje);
                CmdNuevo.Visibility  = Visibility.Visible;
                CmdEnviar.Visibility = Visibility.Hidden;
                break;

            case "error":
                CmdLeer.Visibility   = Visibility.Hidden;
                CmdLeer.IsEnabled    = false;
                CmdEnviar.IsEnabled  = false;
                CmdEnviar.Visibility = Visibility.Hidden;
                mensaje = Globales.cpIntegraEMV.getRspDsError();
                Globales.MessageBoxMitError(mensaje);
                CmdNuevo.Visibility = Visibility.Visible;
                break;

            default:
                if (Globales.EMVLector == "1" && (TypeUsuario.strTipoLector == "3" || TypeUsuario.strTipoLector == "4"))
                {
                    CmdEnviar.IsEnabled = false;
                    CmdLeer.Visibility  = Visibility.Visible;
                    CmdLeer.IsEnabled   = true;
                }
                else
                {
                    CmdEnviar.Visibility = Visibility.Visible;
                }
                mensaje = "Error de conexión, verifique su reporte.";
                Globales.MessageBoxMitError(mensaje);
                CmdNuevo.Visibility = Visibility.Hidden;
                break;
            }
            Mouse.OverrideCursor = null;
        }
Example #8
0
        private void Procesar(object sender, RoutedEventArgs e)
        {
            if (txtNumOper.Text.Trim().Length != 9)
            {
                //Globales.MessageBoxMit("El número de operación debe ser de 9 digitos.");
                Globales.MessageBoxMit("El número de operación debe ser de 9 digitos.");
                txtNumOper.Focus();
                return;
            }
            else if (txtNumAut.Text.Trim().Length != 6)
            {
                //Globales.MessageBoxMit("El número de autorización debe ser de 6 digitos.");
                Globales.MessageBoxMit("El número de autorización debe ser de 6 digitos.");
                txtNumAut.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(txtNumOper.Text) || txtNumOper.Text.Length != 9)
            {
                Globales.MessageBoxMit("Introduzca el número de operación.");
                txtNumOper.Focus();
            }
            else if (string.IsNullOrWhiteSpace(txtNumAut.Text))
            {
                Globales.MessageBoxMit("Introduzca el número de autorizacion");
                txtNumAut.Focus();
            }
            else if (string.IsNullOrWhiteSpace(Importe.Text))
            {
                Globales.MessageBoxMit("Introduzca el importe");
                Importe.Focus();
            }
            else
            {
                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                cmdEnviar.IsEnabled  = false;
                Globales.cpIntegracion_Clear();
                Globales.sURL_cpINTEGRA = Globales.URL_DLL_CANC;
                Globales.cpIntegraEMV.dbgSetUrl(Globales.URL_3GATE);
                Globales.cpIntegraEMV.sndCancelacion(TypeUsuario.usu,
                                                     TypeUsuario.Pass, "", TypeUsuario.Id_Company, TypeUsuario.Id_Branch,
                                                     TypeUsuario.country, Importe.Text, txtNumOper.Text, txtNumAut.Text);
                Globales.cpIntegracion_sResult = Globales.cpIntegraEMV.getRspXML();

                string strCadEncriptar = "";
                string mensaje         = string.Empty;
                Mouse.OverrideCursor = null;
                switch (Globales.GetDataXml("response", Globales.cpIntegracion_sResult))
                {
                case "approved":
                    txtNumOper.IsEnabled = false;
                    txtNumAut.IsEnabled  = false;
                    Importe.IsEnabled    = false;

                    mensaje = Globales.GetDataXml("auth", Globales.cpIntegracion_sResult);
                    //FIRMA EN PANEL

                    //texto de marca de agu


                    Globales.MessageBoxMitApproved(mensaje, true);
                    #region firma en panel
                    string textoAgua = string.Empty;
                    textoAgua += "Folio:" + Globales.cpIntegraEMV.getRspOperationNumber() + "\n";
                    textoAgua += "Auth:" + Globales.cpIntegraEMV.getRspAuth() + "\n";
                    textoAgua += "Importe:" + Globales.cpIntegraEMV.getTx_Amount() + "\n";
                    textoAgua += "Fecha" + Globales.cpIntegraEMV.getRspDate() + "\n";
                    textoAgua += "Merchant" + Globales.cpIntegraEMV.getRspDsMerchant() + "\n";
                    textoAgua += " \n";
                    textoAgua += "_______________________\n";
                    textoAgua += "FIRMA DIGITALIZADA:\n";

                    bool   isChipAndPind, esQPS;
                    string cadenaHexFirma = string.Empty;
                    int    tipoVta;
                    esQPS         = false;
                    tipoVta       = 1;
                    isChipAndPind = false;
                    //Valida si el chip and pind

                    if (Globales.cpIntegraEMV.chkCc_IsPin() == "01")
                    {
                        isChipAndPind = true;
                    }
                    if (Globales.cpIntegraEMV.getRspVoucher().Contains("@cnn Autorizado sin Firma ") && tipoVta == 1 && !isChipAndPind)
                    {
                        esQPS = true;
                    }


                    //Si pinpad soporta firma en panel y no es touch
                    if (!Globales.cpIntegraEMV.EsTouch() && Globales.cpIntegraEMV.getRspSoportaFirmaPanel())
                    {
                        cadenaHexFirma = Globales.cpIntegraEMV.sndObtieneFirmaPanel(false, textoAgua, Globales.cpIntegraEMV.getRspVoucher(), isChipAndPind, Globales.cpIntegraEMV.chkPp_Trademark(), tipoVta, esQPS);


                        if (!cadenaHexFirma.Contains("Error"))
                        {
                            if (Globales.cpIntegraEMV.sndGuardaFirmaPanel(cadenaHexFirma, Globales.ipFirmaPanel, Globales.cpIntegraEMV.getRspOperationNumber(), Globales.cpIntegraEMV.chkPp_Serial()))
                            {
                                imgEmail.Visibility = Visibility.Visible;
                            }
                        }
                        else
                        {
                            Globales.MessageBoxMit("No se pudo obtener la imagen del PinPad.");
                        }
                        goto GoImpresion;
                    }
                    //Sí el dispositivo tiene capacidad touch...


                    if (Globales.cpIntegraEMV.EsTouch())
                    {
                        if (TypeUsuario.UtilizarCapacidadTouch && TypeUsuario.EnviarVoucherMail)
                        {
                            if (!Globales.ObtieneFirmaPanel(Globales.ipFirmaPanel, textoAgua, tipoVta, isChipAndPind, esQPS))
                            {
                                goto GoImpresion;
                            }
                            else
                            {
                                goto finaliza;
                            }
                        }

                        if (TypeUsuario.UtilizarCapacidadTouch && TypeUsuario.EnviarVoucherMail)
                        {
                            //Llama a la función de obtener la firma en panel
                            cadenaHexFirma = Globales.cpIntegraEMV.sndObtieneFirmaPanel(true, textoAgua, Globales.cpIntegraEMV.getRspVoucher(), isChipAndPind, Globales.cpIntegraEMV.chkPp_Trademark(), tipoVta, esQPS);
                            if (!cadenaHexFirma.Contains("Error"))
                            {
                                if (Globales.cpIntegraEMV.sndGuardaFirmaPanel(cadenaHexFirma, Globales.ipFirmaPanel, Globales.cpIntegraEMV.getRspOperationNumber(), Globales.cpIntegraEMV.chkPp_Serial()))
                                {
                                    imgEmail.Visibility = Visibility.Visible;
                                }
                            }
                            else
                            {
                                Globales.MessageBoxMit("No se pudo obtener la imagen del pinpad");
                            }
                            goto GoImpresion;
                        }

                        if (!TypeUsuario.UtilizarCapacidadTouch && !TypeUsuario.EnviarVoucherMail)
                        {
                            if (Globales.cpIntegraEMV.getRspSoportaFirmaPanel())
                            {
                                cadenaHexFirma = Globales.cpIntegraEMV.sndObtieneFirmaPanel(false, textoAgua, Globales.cpIntegraEMV.getRspVoucher(), isChipAndPind, Globales.cpIntegraEMV.chkPp_Trademark(), tipoVta, esQPS);
                                if (!cadenaHexFirma.Contains("Error"))
                                {
                                    if (Globales.cpIntegraEMV.sndGuardaFirmaPanel(cadenaHexFirma, Globales.ipFirmaPanel, Globales.cpIntegraEMV.getRspOperationNumber(), Globales.cpIntegraEMV.chkPp_Serial()))
                                    {
                                        imgEmail.Visibility = Visibility.Visible;
                                    }
                                }
                                else
                                {
                                    Globales.MessageBoxMit("No s pudo obtener la imagen del PinPad\n" + cadenaHexFirma);
                                }
                            }
                            goto GoImpresion;
                        }
                    }    //Fin de si eres Touch

                    #endregion
GoImpresion:
                    Mouse.OverrideCursor      = System.Windows.Input.Cursors.Wait;
                    TypeUsuario.strVoucherCoP = Globales.GetDataXml("voucher", Globales.cpIntegracion_sResult);
                    switch (TypeUsuario.TipoImpresora)
                    {
                    case "1":
                        if (Globales.VoucherHtml(Globales.GetDataXml("foliocpagos", Globales.cpIntegracion_sResult),
                                                 TypeUsuario.Id_Company, TypeUsuario.Id_Branch, "impvouch", "false"))
                        {
                            TypeUsuario.strVoucher = Globales.cpHTTP_sResult;
                            Globales.Imprimir_HTML(TypeUsuario.strVoucher);
                        }
                        cmdVoucher.IsEnabled = true;
                        cmdNuevo.IsEnabled   = true;
                        break;

                    case "4":
                        if (Globales.VoucherHtml(Globales.GetDataXml("foliocpagos", Globales.cpIntegracion_sResult),
                                                 TypeUsuario.Id_Company, TypeUsuario.Id_Branch, "impvouch", "false"))
                        {
                            TypeUsuario.strVoucher = Globales.VoucherHtml1(Globales.cpHTTP_sResult);
                            Globales.Imprimir_HTML(TypeUsuario.strVoucher);
                        }
                        cmdVoucher.IsEnabled = true;
                        cmdNuevo.IsEnabled   = true;
                        break;

                    case "3":
                        Globales.imprimirEpson();
                        break;

                    case "6":
                        Globales.PrintOptions(TypeUsuario.strVoucherCoP);
                        cmdVoucher.IsEnabled = true;
                        cmdNuevo.IsEnabled   = true;

                        break;

                    default:
                        break;
                    }

finaliza:
                    cmdNuevo.Visibility  = Visibility.Visible;
                    cmdEnviar.Visibility = Visibility.Visible;
                    Mouse.OverrideCursor = null;
                    break;

                case "denied":
                    txtNumOper.Visibility = Visibility.Visible;
                    txtNumAut.IsEnabled   = false;
                    Importe.IsEnabled     = false;

                    mensaje = Globales.GetDataXml("cd_response", Globales.cpIntegracion_sResult);
                    Globales.MessageBoxMitDenied("Cancelación denegada\n" + mensaje);
                    cmdNuevo.Visibility  = Visibility.Visible;
                    cmdEnviar.Visibility = Visibility.Hidden;
                    break;

                case "error":

                    mensaje = Globales.GetDataXml("nb_error", Globales.cpIntegracion_sResult);
                    Globales.MessageBoxMitError(mensaje);
                    cmdNuevo.Visibility  = Visibility.Hidden;
                    cmdEnviar.Visibility = Visibility.Visible;
                    break;

                default:
                    mensaje = "Verifique su conexión de internet.";
                    this.setMensaje("none", mensaje);

                    cmdNuevo.Visibility  = Visibility.Hidden;
                    cmdEnviar.Visibility = Visibility.Visible;
                    Globales.MessageBoxMitError(mensaje);
                    break;
                }
                cmdEnviar.IsEnabled  = true;
                Mouse.OverrideCursor = null;
            }
        }
        private void CmdEnviar_Click(object sender, RoutedEventArgs e)
        {
            Globales.strNombreFP = NOMBRE_GENERAL + ".CmdEnviar_Click()";

            string mensaje = string.Empty;

            if (string.IsNullOrWhiteSpace(Importe.Text))
            {
                Globales.MessageBoxMit("Introduzca el importe.");
                Importe.Focus();
            }
            else
            {
                lblimportecheckin.Content = lblimportecheckin.Content.ToString().Replace(",", "");
                string importe = lblimportecheckin.Content.ToString();
                importe = importe.Replace("$", "");
                importe = importe.Trim();

                if (Convert.ToDouble(Importe.Text) > Convert.ToDouble(importe))
                {
                    double ImporteRA;
                    ImporteRA = Convert.ToDouble(Importe.Text) - Convert.ToDouble(lblimportecheckin.Content.ToString().Replace("$", "").Trim());

                    Globales.cpIntegracion_Clear();
                    Globales.cpIntegracion_sURL_cpINTEGRA = Globales.URL_DLL_RA;
                    CmdEnviar.IsEnabled = false;

                    Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                    Globales.cpIntegraEMV.dbgSetUrl(Globales.URL_3GATE);
                    Globales.cpIntegraEMV.sndReautorizacionMOTO(TypeUsuario.usu,
                                                                TypeUsuario.Pass,
                                                                "",
                                                                TypeUsuario.Id_Company,
                                                                TypeUsuario.Id_Branch,
                                                                TypeUsuario.country,
                                                                ImporteRA.ToString(),
                                                                lblOperacion);
                    Globales.cpIntegracion_sResult = Globales.cpIntegraEMV.getRspXML();
                    Mouse.OverrideCursor           = null;
                    string caso = Globales.GetDataXml("response", Globales.cpIntegracion_sResult).ToLower();
                    switch (caso)
                    {
                    case "approved":
                        goto DoCheckout;
                        break;

                    default:

                        Globales.MessageBoxMit("No es posible realizar el checkout");
                        CmdEnviar.IsEnabled  = true;
                        CmdEnviar.Visibility = Visibility.Visible;
                        return;

                        break;
                    }
                }
                else
                {
                    goto DoCheckout;
                }

DoCheckout:
                CmdEnviar.IsEnabled = false;

                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                string strTypeC = string.Empty;
                Globales.cpIntegracion_Clear();

                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                Globales.cpIntegraEMV.dbgSetUrl(Globales.URL_3GATE);
                Globales.cpIntegraEMV.sndCheckOutMOTO(TypeUsuario.usu,
                                                      TypeUsuario.Pass,
                                                      "",
                                                      TypeUsuario.Id_Company,
                                                      TypeUsuario.Id_Branch,
                                                      TypeUsuario.country,
                                                      Importe.Text,
                                                      this.lblOperacion);
                Globales.cpIntegracion_sResult = Globales.cpIntegraEMV.getRspXML();

                Mouse.OverrideCursor = null;
                string strCadEncriptar = string.Empty;

                string case2 = Globales.GetDataXml("response", Globales.cpIntegracion_sResult).ToLower();

                switch (case2)
                {
                case "approved":
                    Importe.IsEnabled = false;
                    mensaje           = Globales.GetDataXml("auth", Globales.cpIntegracion_sResult);
                    Globales.MessageBoxMitApproved(mensaje);
                    TypeUsuario.strVoucherCoP = (Globales.GetDataXml("voucher", Globales.cpIntegracion_sResult)).Trim();
                    TypeUsuario.strVoucherCoP = (Globales.GetDataXml("voucher", Globales.cpIntegracion_sResult)).Trim();


                    //'************************************************************************************************
                    //''********************************** FIRMA EN PANEL *********************************************
                    //'VALIDACIONES PARA LA FIRMA EN PANEL

                    //'Texto de marca de agua ceriroji
                    string textoAgua = string.Empty;
                    textoAgua  = "Folio: " + Globales.cpIntegraEMV.getRspOperationNumber() + "\n";
                    textoAgua += "Auth: " + Globales.cpIntegraEMV.getRspAuth() + "\n";
                    textoAgua += "Importe: " + Globales.cpIntegraEMV.getTx_Amount() + "\n";
                    textoAgua += "Fecha: " + Globales.cpIntegraEMV.getRspDate() + "\n";
                    textoAgua += "Merchant: " + Globales.cpIntegraEMV.getRspDsMerchant() + "\n";
                    textoAgua += " " + "\n";
                    textoAgua += "___________________" + "\n";
                    textoAgua += "FIRMA DIGITALIZADA:" + "\n";


                    //'************************************************************************************************
                    //'valida si la tarjeta es Chip and Pin
                    bool   IsChipAndPin, esQPS;
                    string cadenaHexFirma = string.Empty;
                    int    tipoVta;
                    IsChipAndPin = false;
                    esQPS        = false;
                    tipoVta      = 1;

                    //'valida si es chip and pin
                    if (Globales.cpIntegraEMV.chkCc_IsPin() == "01")
                    {
                        IsChipAndPin = true;
                    }

                    //'************************************************************************************************
                    //'valida si la venta es QPS
                    if (Globales.cpIntegraEMV.getRspVoucher().Contains("@cnn Autorizado sin Firma ") && tipoVta == 1 && !IsChipAndPin)
                    {
                        esQPS = true;
                    }

                    //'************************************************************************************************
                    //'Si la PinPad no soporta Firma en Panel y no es touch, sigue el flujo normal de PcPay
                    if (!Globales.cpIntegraEMV.EsTouch() && !Globales.cpIntegraEMV.getRspSoportaFirmaPanel())
                    {
                        goto GoImpresion;
                    }

                    //'************************************************************************************************
                    //'Si la PinPad Soporta Firma en Panel y no es touch,
                    if (!Globales.cpIntegraEMV.EsTouch() && Globales.cpIntegraEMV.getRspSoportaFirmaPanel())
                    {
                        // 'Llama a la función de obtener la firma en Panel
                        cadenaHexFirma = Globales.cpIntegraEMV.sndObtieneFirmaPanel(false, textoAgua, Globales.cpIntegraEMV.getRspVoucher(),
                                                                                    IsChipAndPin, Globales.cpIntegraEMV.chkPp_Trademark(), (short)tipoVta, esQPS);

                        if (!cadenaHexFirma.Contains("Error"))
                        {
                            //'Llama a la funcion de Guardar la firma
                            if (Globales.cpIntegraEMV.sndGuardaFirmaPanel(cadenaHexFirma, Program.ipFirmaPanel, Globales.cpIntegraEMV.getRspOperationNumber(), Globales.cpIntegraEMV.chkPp_Serial()))
                            {
                                imgEmailFirmaPanel.Visibility = Visibility.Visible;
                            }
                        }
                        else
                        {
                            Globales.MessageBoxMit("No se pudo obtener la imagen del PinPad");
                        }
                        goto GoImpresion;
                    }

                    //'************************************************************************************************
                    //'SI EL DISPOSITIVO TIENE CAPACIDAD TOUCH
                    if (Globales.cpIntegraEMV.EsTouch())
                    {
                        if (TypeUsuario.UtilizarCapacidadTouch && TypeUsuario.EnviarVoucherMail)
                        {
                            if (!Globales.ObtieneFirmaPanel(Program.ipFirmaPanel, textoAgua, (short)tipoVta, IsChipAndPin, esQPS))
                            {
                                goto GoImpresion;
                            }
                            else
                            {
                                cmdVoucher.Visibility = Visibility.Visible;
                                cmdVoucher.IsEnabled  = false;
                                CmdEnviar.Visibility  = Visibility.Hidden;

                                goto finaliza;
                            }
                        }
                    }


                    if (TypeUsuario.UtilizarCapacidadTouch && !TypeUsuario.EnviarVoucherMail)
                    {
                        //   'Llama a la función de obtener la firma en Panel
                        cadenaHexFirma = Globales.cpIntegraEMV.sndObtieneFirmaPanel(true, textoAgua,
                                                                                    Globales.cpIntegraEMV.getRspVoucher(), IsChipAndPin, Globales.cpIntegraEMV.chkPp_Trademark(), (short)tipoVta, esQPS);

                        if (!cadenaHexFirma.Contains("Error"))
                        {
                            // 'Llama a la funcion de Guardar la firma
                            if (Globales.cpIntegraEMV.sndGuardaFirmaPanel(cadenaHexFirma, Program.ipFirmaPanel, Globales.cpIntegraEMV.getRspOperationNumber(), Globales.cpIntegraEMV.chkPp_Serial()))
                            {
                                imgEmailFirmaPanel.Visibility = Visibility.Visible;
                            }
                            else
                            {
                                Globales.MessageBoxMit("No se pudo obtener la imagen del PinPad" + "\n" + cadenaHexFirma);
                            }

                            goto GoImpresion;
                        }
                    }
                    if (!TypeUsuario.UtilizarCapacidadTouch && !TypeUsuario.EnviarVoucherMail)
                    {
                        if (Globales.cpIntegraEMV.getRspSoportaFirmaPanel())
                        {
                            //  'Llama a la función de obtener la firma en Panel
                            cadenaHexFirma = Globales.cpIntegraEMV.sndObtieneFirmaPanel(false, textoAgua,
                                                                                        Globales.cpIntegraEMV.getRspVoucher(), IsChipAndPin, Globales.cpIntegraEMV.chkPp_Trademark(), (short)tipoVta, esQPS);
                            if (!cadenaHexFirma.Contains("Error"))
                            {
                                // 'Llama a la funcion de Guardar la firma
                                if (Globales.cpIntegraEMV.sndGuardaFirmaPanel(cadenaHexFirma, Program.ipFirmaPanel, Globales.cpIntegraEMV.getRspOperationNumber(), Globales.cpIntegraEMV.chkPp_Serial()))
                                {
                                    imgEmailFirmaPanel.Visibility = Visibility.Visible;
                                }
                                else
                                {
                                    Globales.MessageBoxMit("No se pudo obtener la imagen del PinPad" + "\n" + cadenaHexFirma);
                                }
                            }
                            goto GoImpresion;
                        }
                    }

                    //    '************************************************************************************************************
GoImpresion:

                    //  Select Case Mid(TypeUsuario.TipoImpresora, 1, 1)
                    cmdVoucher.IsEnabled = true;
                    CmdEnviar.Visibility = Visibility.Hidden;
                    escogerImpresora();

                    if (TypeUsuario.IsAQ)
                    {
                        //VerificaVoucher
                    }

                    CmdEnviar.Visibility  = Visibility.Hidden;
                    cmdVoucher.Visibility = Visibility.Visible;

finaliza:
                    //    'fin del case

                    //   '''*******************************FACTURA ELECTRONICA*********************************
                    Globales.cpIntegracion_sResult = Globales.cpIntegracion_sResult.Replace("<amount/>", "<amount>" + Importe.Text + "</amount>");
                    if (Globales.FacturaE == "1")
                    {
                        if (Globales.MessageConfirm("¿Desea factura electrónica?"))
                        {
                            frmPreguntaFactura fpf = new frmPreguntaFactura();
                            fpf.abrirFrmAhora = abrir;
                            fpf.cerraPage     = cierra;
                            abrir(fpf);
                        }
                        else
                        {
                            Globales.XMLFacturaE = "";
                        }
                    }
                    break;
                //    ''''***********************************************************************************



                case "denied":
                    Importe.IsEnabled = false;
                    mensaje           = " msjRech" + "\n" + Globales.GetDataXml("cd_response", Globales.cpIntegracion_sResult) + " " + Globales.GetDataXml("friendly_response", Globales.cpIntegracion_sResult);
                    Globales.MessageBoxMitDenied(mensaje);
                    CmdEnviar.Visibility = Visibility.Hidden;
                    break;

                case "error":
                    mensaje = Globales.GetDataXml("nb_error", Globales.cpIntegracion_sResult);
                    Globales.MessageBoxMitError(mensaje);
                    CmdEnviar.Visibility = Visibility.Visible;
                    break;

                default:
                    mensaje = "Verifique su conexión de Internet.";
                    Globales.MessageBoxMitError(mensaje);
                    CmdEnviar.Visibility = Visibility.Visible;
                    Mouse.OverrideCursor = null;
                    CmdEnviar.IsEnabled  = true;
                    break;
                }
            }
        }
        private void CmdLeer_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (vacio(TxtReferencia.Text))
                {
                    System.Windows.Forms.MessageBox.Show("Introduzca una referencia para la activación MITarjeta.", Globales.NOMBRE_APP, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
                    TxtReferencia.Focus();
                    //Exit Sub
                    return;
                }
                if (vacio(Importe.Text))
                {
                    System.Windows.Forms.MessageBox.Show("Introduzca el importe MITarjeta.", Globales.NOMBRE_APP, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
                    Importe.Focus();
                    //Exit Sub
                    return;
                }

                //FormaPago.Enabled = False
                //cboBanco.Enabled = False
                Importe.IsEnabled       = false;
                TxtReferencia.IsEnabled = false;

                CmdLeer.IsEnabled = false;
                //CmdEnviar.Default = True

                NumTdc.Text = "";
                NomTdc.Text = "";
                Mes.Text    = "";
                Anio.Text   = "";

                //SetMensaje "Inserta el chip o desliza tarjeta y Espera un momento..." & vbNewLine & "Sigue las instrucciones del lector", &HD28106, LblTInfo
                //    Globales.SetMensaje();
                LblTInfo.Text       = "Inserta el chip o desliza tarjeta y Espera un momento..." + Environment.NewLine + "Sigue las instrucciones del lector";
                LblTInfo.Foreground = Brushes.Blue;


                if (Globales.CpCobro3G.dbgActivaLector())
                {
                    if (vacio(Globales.CpCobro3G.chkCc_Number()))
                    {
                        NumTdc.Text = Globales.CpCobro3G.chkCc_Number();
                        NomTdc.Text = Globales.CpCobro3G.chkCc_Name();
                        Mes.Text    = Globales.CpCobro3G.chkCc_ExpMonth();
                        Anio.Text   = Globales.CpCobro3G.chkCc_ExpYear();

                        if (Globales.GetDataXml("csvamexenbanda", TypeUsuario.CadenaXML) == "1" /*&& Globales.CpCobro.chkCc_Number.Length == 15*/)
                        {
                            //frmCsvAMEX.Show vbModal
                        }
                        //MousePointer = vbNormal
                        cmdActual(CmdEnviar);
                        CmdEnviar.Focus();
                    }
                }
                else
                {
                    //if (!vacio(Globales.CpCobro3G.chkPp_DsError()))
                    //{

                    //    System.Windows.Forms.MessageBox.Show(Globales.CpCobro3G.chkPp_DsError, Globales.NOMBRE_APP, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
                    //    cmdActual(CmdLeer);
                    //    // MousePointer = vbNormal
                    //}
                }
                Globales.cpIntegraEMV.dbgSetTrxData(TypeUsuario.usu, TypeUsuario.Pass, "", TypeUsuario.Id_Company, TypeUsuario.Id_Branch, TypeUsuario.country);
            }
            catch
            {
            }
        }