示例#1
0
        //connect
        public Boolean connect()
        {
            bool status = false;

            try
            {
                if (!bcom.getfindDevice())
                {
                    /*bcom.setTypeCom
                     * Set 1 to RS232
                     * Set 2 to IP
                     */
                    bcom.setTypeCom("1");
                    if (bcom.getTypeCom().Equals("1"))
                    {
                        status = findPorts();
                        bcom.setfindDevice(status);
                    }
                }
                else
                {
                    status = true;
                }
            }
            catch (Exception ex)
            {
                MITLog.PrintLn("connect" + ex.Message);
                status = false;
            }

            return(status);
        }
示例#2
0
        //Comando C59 - Print
        public bool SendC59(String voucher)
        {
            if (string.IsNullOrEmpty(Info.Printer) || Info.Printer == ("0"))
            {
                MITLog.PrintLn("Terminal sin impresora");
                return(false);
            }

            String Cmd = "";

            //Set logo
            voucher = voucher.Replace("@cnb Santander", "@logo1 @br");
            voucher = voucher.Replace("@cnb American Express", "@logo2 @br");
            voucher = voucher.Replace("@cnb HSBC", "@logo7 @br");
            voucher = voucher.Replace("@cnb IXE", "@logo11 @br");
            voucher = voucher.Replace("@cnb MULTIVA", "@logo15 @br");
            voucher = voucher.Replace("@cnb SCOTIA BANK", "@logo16 @br");
            voucher = voucher.Replace("@cnb logo_cpagos", "@logo3 @br");
            voucher = voucher.Replace("@cnn ver_app", "@cnn " + Info.dll_version);

            //if (!agregaSalto)
            //    voucher = voucher + "@br @br @br ";

            Cmd = "C59"
                  + "A" + voucher;
            //Timeout to wait response...
            bcom.setTimeOut(30);
            return(BuildCMD(Cmd));
        }
示例#3
0
        //Find device port.
        private bool findPorts()
        {
            bool status = false;

            try
            {
                String[] ports = RS232.findPorts();
                bcom.setBaudRate(19200);
                for (int count = 0; count < ports.Length; count++)
                {
                    bcom.setCom(ports[count]);
                    Info.COM = ports[count];
                    if (SendC56())
                    {
                        status = true;
                        break;
                    }
                    else
                    {
                        bcom.setCom("");
                        Info.COM = "";
                    }
                }
            }
            catch (Exception ex)
            {
                MITLog.PrintLn("findPorts" + ex.Message);
                status = false;
            }

            return(status);
        }
示例#4
0
        public String SendWSSoap(String url, String data, String Action, String Method)
        {
            try
            {
                String soapxml    = "";
                String soapResult = "";
                //data = data.Replace("<", "#");

                soapxml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                          + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\""
                          + " xmlns:q0=\"" + Action + "\""
                          + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
                          + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
                          + "<soapenv:Body>"
                          + "<q0:" + Method + ">"
                          + data
                          + "</q0:" + Method + ">"
                          + "</soapenv:Body>"
                          + "</soapenv:Envelope>";

                MITLog.PrintLn("soapxml:" + soapxml);
                // Create a request using a URL that can receive a post.
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.Headers.Add("SOAPAction", Action);
                //User Agent
                // Create POST data and convert it to a byte array.
                String postData  = soapxml;
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
                // Set the ContentType property of the WebRequest.
                request.ContentType = "text/xml;charset=\"utf-8\"";
                request.Accept      = "text/xml";
                request.Method      = "POST";

                XmlDocument soapEnvelopeXml = new XmlDocument();
                soapEnvelopeXml.LoadXml(soapxml);

                using (Stream stream = request.GetRequestStream())
                {
                    soapEnvelopeXml.Save(stream);
                }

                using (WebResponse response = request.GetResponse()) // Error occurs here
                {
                    using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                    {
                        soapResult = rd.ReadToEnd();
                        soapResult = soapResult.Replace("&lt;", "<");
                    }
                }
                MITLog.PrintLn("Soap Result:" + soapResult);
                return(soapResult);
            }
            catch (WebException ex)
            {
                MITLog.PrintLn("SendWS Exception: " + ex.ToString());
                TRINP.DsError = ex.Response.ToString().ToString();
                return("");
            }
        }
示例#5
0
        public String SendWS(String url, String data)
        {
            try
            {
                MITLog.PrintLn("URL:" + url);
                MITLog.PrintLn("Request:" + data);

                // Create a request using a URL that can receive a post.
                WebRequest request = WebRequest.Create(url);

                //User Agent
                ((HttpWebRequest)request).UserAgent = "pcpay";
                // Set the Method property of the request to POST.
                request.Method = "POST";
                // Create POST data and convert it to a byte array.
                String postData  = data;
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
                // Set the ContentType property of the WebRequest.
                request.ContentType = "application/x-www-form-urlencoded";
                // Set the ContentLength property of the WebRequest.
                request.ContentLength = byteArray.Length;
                // Get the request stream.
                Stream dataStream = request.GetRequestStream();
                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);
                // Close the Stream object.
                dataStream.Close();
                // Get the response.
                WebResponse response = request.GetResponse();
                // Display the status.
                //Console.WriteLine(((HttpWebResponse)response).StatusDescription);
                // Get the stream containing content returned by the server.
                dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                String responseFromServer = reader.ReadToEnd();
                // Display the content.
                //Console.WriteLine(responseFromServer);
                // Clean up the streams.
                reader.Close();
                dataStream.Close();
                response.Close();
                MITLog.PrintLn("Response SendWS:" + responseFromServer);


                if (responseFromServer.Contains("<?xml version"))
                {
                    responseFromServer = utilidadesMIT.ValidaCadena(responseFromServer);
                }

                return(responseFromServer);
            }catch (WebException ex)
            {
                MITLog.PrintLn("SendWS Exception: " + ex.ToString());
                return("");
            }
        }
示例#6
0
        //Processing Cancel
        private void ProcessingCancel()
        {
            String RecBuffer = bcom.getRecBuf();

            MITLog.PrintLn("ProcessingCancel");
            String aux = RecBuffer.Substring(4, 6);

            if (RecBuffer.Substring(4, 6).Equals("PXVA00"))
            {
                MITLog.PrintLn("ProcessingCancel 1");
                TRRSP.xml           = xmlErrores.xmlPinPadError10;
                TRINP.chkPp_CdError = "10";
            }

            //Stop wait for pinpad.
            bcom.setTimeOut(0);
        }
        private void cmboxTipoMoneda_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (cmboxTipoMoneda.SelectedIndex != 0 && !txtMontoConvertir.Text.Equals("") && !txtMontoConvertir.Text.Equals("."))
                {
                    double.TryParse(txtMontoConvertir.Text, out monto);
                    double.TryParse(lstActualMoneda[cmboxTipoMoneda.SelectedIndex].ToString(), out aux);
                    tipoCambio           = monto * aux;
                    lblMonedaCambio.Text = cmboxTipoMoneda.Text.Substring(0, 3);

                    if (lblMonedaCambio.Text.ToUpper().Equals("JPY"))
                    {
                        lblResultado.Text = tipoCambio.ToString("##########");
                    }
                    else
                    {
                        lblResultado.Text = tipoCambio.ToString("##########.00");
                    }
                }

                if (cmboxTipoMoneda.SelectedIndex != 0 && !txtMontoConvertir.Text.Equals(""))
                {
                    double.TryParse(lstActualMoneda[cmboxTipoMoneda.SelectedIndex].ToString(), out aux);
                    tipoCambio     = 1 / aux;
                    lblTipCam.Text = tipoCambio.ToString("##########.00");
                }

                if (cmboxTipoMoneda.SelectedIndex == 0)
                {
                    txtMontoConvertir.Text = "";
                    lblResultado.Text      = "";
                    lblTipCam.Text         = "";
                    lblMonedaCambio.Text   = "";
                }
            }
            catch (Exception ex)
            {
                MITLog.PrintLn("cmboxTipoMoneda_SelectedIndexChanged:-- " + ex.Message);
            }
        }
示例#8
0
        //Send Port RS232.
        private bool SendRS232()
        {
            bool ReadStatus = false;

            bcom.setCommContinue(false);
            try
            {
                //bcom.setTimeOut(0);
                if (!RS232.IsOpen())
                {
                    RS232.SetConfig(bcom.getCom(), bcom.getBaudRate());
                }

                if (RS232.OpenPort())
                {
                    RS232.WritePort();
                    if (bcom.getCommContinue())
                    {
                        RS232.ReadPort();
                    }
                }
                else
                {
                    bcom.setfindDevice(false);
                    return(false);
                }
                RS232.ClosePort();

                if (bcom.getstatusRead())
                {
                    ReadStatus = true;
                }
            }
            catch (Exception ex)
            {
                MITLog.PrintLn("SendMsg:" + ex.Message);
                return(false);
            }
            return(ReadStatus);
        }
示例#9
0
        //Build command structure
        private Boolean BuildCMD(String Cmd)
        {
            int    lenSend, lencmd;
            String slen       = "";
            int    countBytes = 0;

            byte[] buffer = new byte[bcom.getBufSize()];
            System.Text.ASCIIEncoding buffStr = new System.Text.ASCIIEncoding();
            SendMsg send = new SendMsg();

            lenSend = Cmd.Length;

            buffer[countBytes] = bcom.getSTX();
            countBytes++;

            if (Cmd.Trim().Equals("VXVCANCEL"))
            {
                lencmd = 12;
            }
            else
            {
                lencmd = lenSend;
            }
            slen = lencmd.ToString();
            slen = slen.PadLeft(3);
            slen = slen.Replace(" ", "0");
            System.Buffer.BlockCopy(Encoding.ASCII.GetBytes(slen), 0, buffer, countBytes, 3);
            countBytes += 3;
            System.Buffer.BlockCopy(Encoding.ASCII.GetBytes(Cmd), 0, buffer, countBytes, lenSend);
            countBytes        += lenSend;
            buffer[countBytes] = bcom.getETX();
            countBytes++;
            buffer[countBytes] = calculateLRC(buffer, countBytes);
            countBytes++;

            MITLog.PrintLn(buffStr.GetString(buffer).Substring(0, countBytes));
            return(send._SendMsg(buffer, countBytes));
        }
        private void frmDownloadCarga_Shown(object sender, EventArgs e)
        {
            try
            {
                this.Refresh();

                //utilidadesMIT.DownloadFile(URLDownload + Path, PathDestino);

                //this.Close();

                //System.Timers.Timer aTimer;
                //aTimer = new System.Timers.Timer();
                ////aTimer.Interval = 2000;
                //aTimer.Elapsed += OnTimedEvent;
                //aTimer.AutoReset = false;
                //aTimer.Enabled = true;

                //aTimer.Start();
                ////this.Close();


                Thread oThread = new Thread(new ThreadStart(descargaFile));
                oThread.Start();
                while (oThread.IsAlive)
                {
                    this.Refresh();
                }
                ;

                oThread.Abort();
                oThread.Join();
                this.Close();
            }
            catch (Exception ex)
            {
                MITLog.PrintLn(ex.Message);
            }
        }
        private void dbgGetCboAfiliaciones(ComboBox cboContenedor, string catAfis)
        {
            try
            {
                string[] afil;

                cboContenedor.Items.Clear();
                cboContenedor.Items.Add("-- Seleccione Afiliación --");

                afil = catAfis.Split('|');

                for (int i = 0; i < afil.Length; i++)
                {
                    cboContenedor.Items.Add(afil[i]);
                }

                cboContenedor.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                MITLog.PrintLn("dbgGetCboAfiliaciones:--- " + ex.Message);
            }
        }
        private void frmActualizando_Shown(object sender, EventArgs e)
        {
            try
            {
                label1.Text = "Actualizando terminal... \r\n ¡Se recomienda no interrumpir!";
                this.Refresh();

                Process myProcess = new Process();
                myProcess.StartInfo.FileName        = filePath + fileName;
                myProcess.StartInfo.CreateNoWindow  = true;
                myProcess.StartInfo.UseShellExecute = false;
                myProcess.EnableRaisingEvents       = true;
                myProcess.Exited += new EventHandler(myProcess_Exited);
                myProcess.Start();


                while (!eventHandled)
                {
                    this.Refresh();
                }

                TypeUsuario.isUpdate = true;
                this.Close();
            }
            catch (Exception ex)
            {
                if (utilidadesMIT.ExisteCarpeta(Info.PathExe + "\\Load"))
                {
                    Directory.Delete(Info.PathExe + "\\Load", true);
                }

                MITLog.PrintLn(ex.Message);
                MessageBox.Show("No se pudo completar el proceso de actualización." + "\r\n" + "Es necesario ejecutar el programa con permisos de administrador", "Centro de Pagos - Actualización firmware", MessageBoxButtons.OK, MessageBoxIcon.Information);
                TypeUsuario.isUpdate = false;
                this.Close();
            }
        }
示例#13
0
        //GET
        public string HTTP_GET(string Url, string Data)
        {
            string     Out = String.Empty;
            WebRequest req = WebRequest.Create(Url + (string.IsNullOrEmpty(Data) ? "" : "?" + Data));

            try
            {
                //non cache
                HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
                req.CachePolicy = noCachePolicy;

                WebResponse resp = req.GetResponse();
                using (Stream stream = resp.GetResponseStream())
                {
                    using (StreamReader sr = new StreamReader(stream))
                    {
                        Out = sr.ReadToEnd();
                        sr.Close();
                    }
                }
            }
            catch (ArgumentException ex)
            {
                Out = string.Format("HTTP_ERROR :: The second HttpWebRequest object has raised an Argument Exception as 'Connection' Property is set to 'Close' :: {0}", ex.Message);
            }
            catch (WebException ex)
            {
                Out = string.Format("HTTP_ERROR :: WebException raised! :: {0}", ex.Message);
            }
            catch (Exception ex)
            {
                Out = string.Format("HTTP_ERROR :: Exception raised! :: {0}", ex.Message);
            }
            MITLog.PrintLn("Response GET:" + Out);
            return(Out);
        }
示例#14
0
        //Process PinPad Message Response.
        public bool ProcesaRsp()
        {
            String cmdType = "";

            byte[] bcmd = new byte[3];
            String cmd;
            //String CMD = "";
            int     LenCmd        = 0;
            int     LenBuff       = 0;
            Boolean continueparse = true;

            cmd     = bcom.getRecBuf();
            LenBuff = cmd.Length;
            MITLog.PrintLn(cmd.Substring(0, bcom.getLenRecBuf()));

            do
            {
                //Find STX
                if (cmd.Length > 0)
                {
                    if (cmd.Substring(0, 1).Equals(bcom.getsSTX()))
                    {
                        LenCmd = Int32.Parse(cmd.Substring(1, 3));

                        if (cmd.Substring(4, 3).Equals("P61"))
                        {
                            bcom.setRecBuf(cmd.Substring(0, LenCmd + 6));
                            bcom.setLenRecBuf(LenCmd + 6);
                            //LenCmd = LenCmd - 1;
                            ProcessingP61();
                            return(true);
                        }

                        //Find ETX
                        if (cmd.Substring(LenCmd + 4, 1).Equals(bcom.getsETX()))
                        {
                            //Set Command to process
                            bcom.setRecBuf(cmd.Substring(0, LenCmd + 6));
                            bcom.setLenRecBuf(LenCmd + 6);
                            //Check LRC Value
                            if (CheckLRC())
                            {
                                //Get number command.
                                cmdType = cmd.Substring(4, 3);

                                if (cmdType.Substring(0, 1).Equals("E"))
                                {
                                    if (!ProcessingError())
                                    {
                                        return(false);
                                    }
                                }
                                else
                                {
                                    //About
                                    if (cmdType.Equals("P56") || cmdType.Equals(bcom.getNull() + "56"))
                                    {
                                        ProcessingP56();
                                    }
                                    //Printer
                                    else if (cmdType.Equals("P59"))
                                    {
                                        ProcessingP59();
                                    }
                                    //Cipher Card
                                    else if (cmdType.Equals("P62"))
                                    {
                                        ProcessingP62();
                                    }
                                    //Transaction Process
                                    else if (cmdType.Equals("P71") || cmdType.Equals("P93"))
                                    {
                                        ProcessingEMV();
                                    }
                                    //Display information
                                    else if (cmdType.Equals("P81"))
                                    {
                                        ProcessingP81();
                                    }
                                    //Parametros EMV
                                    else if (cmdType.Equals("P83"))
                                    {
                                        ProcessingP83();
                                    }
                                    //End EMV config
                                    else if (cmdType.Equals("P87"))
                                    {
                                        ProcessingP87();
                                    }
                                    //Dukpt Initialization.
                                    else if (cmdType.Equals("P91"))
                                    {
                                        ProcessingP91();
                                    }
                                    //IPEK Set
                                    else if (cmdType.Equals("P92"))
                                    {
                                        ProcessingP92();
                                    }
                                    //Cancel
                                    else if (cmdType.Equals("PXV"))
                                    {
                                        ProcessingCancel();
                                    }
                                    //Firma en pinPad
                                    else if (cmdType.Equals("P61"))
                                    {
                                        ProcessingP61();
                                    }
                                    //Parametros EMV
                                    else if (cmdType.Equals("P50"))
                                    {
                                        ProcessingP50();
                                    }
                                    //Carga Pinpad
                                    else if (cmdType.Equals("P84"))
                                    {
                                        ProcessingP84();
                                    }
                                    else
                                    {
                                        //Command not found.
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                return(false);
                            }
                            //Is there more information
                            if ((LenCmd + 6) < LenBuff)
                            {
                                cmd = cmd.Substring((LenCmd + 6), (LenBuff - (LenCmd + 6)));
                                //is it an invalid command?
                                if (cmd.Substring(0, 1).Equals(bcom.getNull()))
                                {
                                    cmd = "";
                                }
                                LenBuff = cmd.Length;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            } while (continueparse);

            return(true);
        }
示例#15
0
        //Processing Errors
        private bool ProcessingError()
        {
            String RecBuffer = bcom.getRecBuf();
            String cmdType   = RecBuffer.Substring(4, 3);
            String rspType   = RecBuffer.Substring(7, 3);

            MITLog.PrintLn("ProcessingError");

            //Stop wait for pinpad.
            bcom.setTimeOut(0);

            if (cmdType.Trim().Equals("E62"))
            {
                TRINP.pinpadrsp = "CANCELADO";
                return(false);
            }

            if (cmdType.Trim().Equals("E71") && rspType.Trim().Equals("A10"))
            {
                Cancel("1");
                TRRSP.xml           = xmlErrores.xmlPinPadError10;
                TRINP.chkPp_CdError = "10";
                return(false);
            }

            if (rspType.Trim().Equals("A01"))
            {
                TRRSP.xml           = xmlErrores.xmlPinPadError01;
                TRINP.chkPp_CdError = "01";
                return(false);
            }
            else if (rspType.Trim().Equals("A02"))
            {
                TRRSP.xml           = xmlErrores.xmlPinPadError02;
                TRINP.chkPp_CdError = "02";
                return(false);
            }
            else if (rspType.Trim().Equals("A03"))
            {
                TRRSP.xml           = xmlErrores.xmlPinPadError03;
                TRINP.chkPp_CdError = "03";
                return(false);
            }
            else if (rspType.Trim().Equals("A04"))
            {
                TRRSP.xml           = xmlErrores.xmlPinPadError04;
                TRINP.chkPp_CdError = "04";
                return(false);
            }
            else if (rspType.Trim().Equals("A10"))
            {
                TRRSP.xml           = xmlErrores.xmlPinPadError10;
                TRINP.chkPp_CdError = "10";
                return(false);
            }
            else if (rspType.Trim().Equals("A11"))
            {
                TRRSP.xml           = xmlErrores.xmlPinPadError11;
                TRINP.chkPp_CdError = "11";
                return(false);
            }
            else if (rspType.Trim().Equals("A12"))
            {
                TRRSP.xml           = xmlErrores.xmlPinPadError12;
                TRINP.chkPp_CdError = "12";
                return(false);
            }
            else if (rspType.Trim().Equals("A13"))
            {
                TRRSP.xml           = xmlErrores.xmlPinPadError13;
                TRINP.chkPp_CdError = "13";
                return(false);
            }
            else if (rspType.Trim().Equals("A14"))
            {
                TRRSP.xml           = xmlErrores.xmlPinPadError14;
                TRINP.chkPp_CdError = "14";
                return(false);
            }
            else if (rspType.Trim().Equals("A15"))
            {
                TRRSP.xml           = xmlErrores.xmlPinPadError15;
                TRINP.chkPp_CdError = "15";
                return(false);
            }
            else if (rspType.Trim().Equals("A16"))
            {
                TRRSP.xml           = xmlErrores.xmlPinPadError16;
                TRINP.chkPp_CdError = "16";
                return(false);
            }
            else if (rspType.Trim().Equals("A17"))
            {
                TRRSP.xml           = xmlErrores.xmlPinPadError17;
                TRINP.chkPp_CdError = "17";
                return(false);
            }
            else if (rspType.Trim().Equals("A21"))
            {
                TRRSP.xml           = xmlErrores.xmlPinPadError21;
                TRINP.chkPp_CdError = "21";
                return(false);
            }
            else if (rspType.Trim().Equals("A22"))
            {
                TRRSP.xml           = xmlErrores.xmlPinPadError22;
                TRINP.chkPp_CdError = "22";
                return(false);
            }

            //pendiente
            //validar errores de pinpad
            TRINP.chkPp_CdError  = "";
            TRINP.chkPp_XmlError = "";
            return(true);
        }
 public bool dbgSetReader()
 {
     MITLog.PrintLn("*** dbgSetReader(), Deprecated!!! -> No need to call...");
     return(true);
 }