Exemplo n.º 1
0
        /// <summary>
        /// Inserts a new register in the FINES table, and if everything is successful sends an ACK_PROCESSED
        /// </summary>
        /// <returns>Message to send back to the sender</returns>
        public System.Collections.Specialized.StringCollection Process()
        {
            StringCollection res        = null;
            OracleConnection oraDBConn  = null;
            OracleCommand    oraCmd     = null;
            ILogger          logger     = null;
            bool             bExistFine = false;
            bool             bRet       = false;

            try
            {
                Database d = OPS.Components.Data.DatabaseFactory.GetDatabase();
                logger = DatabaseFactory.Logger;
                System.Data.IDbConnection DBCon = d.GetNewConnection();
                oraDBConn = (OracleConnection)DBCon;
                oraDBConn.Open();

                if (oraDBConn.State == System.Data.ConnectionState.Open)
                {
                    if (logger != null)
                    {
                        if (ExistFine(oraDBConn, ref bExistFine, logger))
                        {
                            if (bExistFine)
                            {
                                bRet = UpdateFine(oraDBConn, lista_campos, lista_valores, logger);
                                if (!bRet)
                                {
                                    if (logger != null)
                                    {
                                        logger.AddLog("[Msg53:Process]: Error: Updating Fine", LoggerSeverities.Error);
                                    }
                                    res = ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS);
                                }
                            }
                            else
                            {
                                bRet = InsertFine(oraDBConn, lista_campos, lista_valores, logger);
                                if (!bRet)
                                {
                                    if (logger != null)
                                    {
                                        logger.AddLog("[Msg53:Process]: Error: Inserting Fine", LoggerSeverities.Error);
                                    }
                                    res = ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS);
                                }
                            }

                            if (bRet)
                            {
                                CFineManager oFineManager = new CFineManager();
                                oFineManager.SetLogger(logger);
                                oFineManager.SetDBConnection(oraDBConn);
                                oFineManager.SetFineStatus(iFine);
                                res = ReturnAck(AckMessage.AckTypes.ACK_PROCESSED);
                            }
                        }
                        else
                        {
                            if (logger != null)
                            {
                                logger.AddLog("[Msg53:Process]: Error finding if fine exists", LoggerSeverities.Error);
                            }
                            res = ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (logger != null)
                {
                    logger.AddLog("[Msg53:Process]: Error: " + e.Message, LoggerSeverities.Error);
                }
                res = ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS);
            }
            finally
            {
                if (oraCmd != null)
                {
                    oraCmd.Dispose();
                    oraCmd = null;
                }


                if (oraDBConn != null)
                {
                    oraDBConn.Close();
                    oraDBConn.Dispose();
                    oraDBConn = null;
                }
            }

            return(res);
        }
Exemplo n.º 2
0
        public System.Collections.Specialized.StringCollection Process()
        {
            //***** Parameters needed for FINES
            //id is not necessary
            //defId is FINE_TYPE_PAYMENT
            //number is the "fineNumber" parameter (optional)
            string vehicleId    = null;
            string model        = null;
            string manufacturer = null;
            string colour       = null;
            int    groupId      = -1;
            int    streetId     = -1;
            int    streetNumber = -1;
            //date is the "date" parameter
            string comments = null;
            int    userId   = -1;

            //unitId is the "unitId" parameter
            //payed is TRUE
            //int paymentDefId = -1; // Could be calculated through the "paymentDefDescShort" parameter, but is not used
            //sent is not necessary
            //extrasent is not necessary

            //***** Parameters needed for OPERATIONS (see also parameters for FINES)
            //quantity is the "quantity" parameter

            try
            {
                Console.WriteLine("M04.cs:Proccess - Inicio del procesado del M04");
                ILogger        logger = null;
                IDbTransaction tran   = null;
                logger = DatabaseFactory.Logger;
                if (logger != null)
                {
                    logger.AddLog("[Msg04:Process]", LoggerSeverities.Debug);
                }

                // this._paymentDefId == OPERATIONS_BILLREADER_REFUNDRECEIPT !!!!!!!!!!!!!!!! chapuza momentanea
                if (_operType == OPERATIONS_BILLREADER_REFUNDRECEIPT || this._paymentDefId == OPERATIONS_BILLREADER_REFUNDRECEIPT)
                {
                    CmpBillReaderRefundsFineDB cmp = new CmpBillReaderRefundsFineDB();
                    if (cmp.Insert(_unitId, _date, Convert.ToInt32(_quantity), _fineNumber, _lfineDef) < 0)
                    {
                        if (logger != null)
                        {
                            logger.AddLog("[Msg04:Process]:ERROR ON INSERT", LoggerSeverities.Debug);
                        }
                        return(ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS));
                    }
                    else
                    {
                        if (logger != null)
                        {
                            logger.AddLog("[Msg04:Process]: RESULT OK", LoggerSeverities.Debug);
                        }
                        return(ReturnAck(AckMessage.AckTypes.ACK_PROCESSED));
                    }
                }
                else
                {
                    int iBinFormat = -1;
                    if (_binType == -1)
                    {
                        CmpParametersDB cmpParam     = new CmpParametersDB();
                        string          strBinFormat = cmpParam.GetParameter("P_BIN_FORMAT");
                        if (strBinFormat != "")
                        {
                            iBinFormat = Convert.ToInt32(strBinFormat);
                        }
                    }
                    else
                    {
                        iBinFormat = _binType;
                    }

                    if (!Msg07.ListaNegra(logger, _szCCNumber, iBinFormat))
                    {
                        // Step 1: Search for an existing fine
                        DataTable  dt  = null;
                        CmpFinesDB fdb = new CmpFinesDB();
                        if (_fineNumber != null)
                        {
                            string sql = "SELECT * "
                                         + "FROM FINES "
                                         + "INNER JOIN FINES_DEF ON FINES.FIN_DFIN_ID = FINES_DEF.DFIN_ID "
                                         + "WHERE FIN_NUMBER = @FINES.FIN_NUMBER@ "
                                         + "AND DFIN_COD_ID = @FINES_DEF.DFIN_COD_ID@";
                            dt = fdb.GetData(sql, new object[] { _fineNumber, FINES_DEF_CODES_FINE });
                            if (dt.Rows.Count > 0)
                            {
                                vehicleId    = (dt.Rows[0]["FIN_VEHICLEID"] == DBNull.Value ? null : (string)dt.Rows[0]["FIN_VEHICLEID"]);
                                model        = (dt.Rows[0]["FIN_MODEL"] == DBNull.Value ? null : (string)dt.Rows[0]["FIN_MODEL"]);
                                manufacturer = (dt.Rows[0]["FIN_MANUFACTURER"] == DBNull.Value ? null : (string)dt.Rows[0]["FIN_MANUFACTURER"]);
                                colour       = (dt.Rows[0]["FIN_COLOUR"] == DBNull.Value ? null : (string)dt.Rows[0]["FIN_COLOUR"]);
                                groupId      = (dt.Rows[0]["FIN_GRP_ID"] == DBNull.Value ? -1 : Convert.ToInt32(dt.Rows[0]["FIN_GRP_ID"]));
                                streetId     = (dt.Rows[0]["FIN_STR_ID"] == DBNull.Value ? -1 : Convert.ToInt32(dt.Rows[0]["FIN_STR_ID"]));
                                streetNumber = (dt.Rows[0]["FIN_STRNUMBER"] == DBNull.Value ? -1 : Convert.ToInt32(dt.Rows[0]["FIN_STRNUMBER"]));
                                comments     = (dt.Rows[0]["FIN_COMMENTS"] == DBNull.Value ? null : (string)dt.Rows[0]["FIN_COMMENTS"]);
                                userId       = (dt.Rows[0]["FIN_USR_ID"] == DBNull.Value ? -1 : Convert.ToInt32(dt.Rows[0]["FIN_USR_ID"]));
                                //quantity = Convert.ToDouble(dt.Rows[0]["DFIN_VALUE"]);
                            }
                            else
                            {
                                CmpFinesHisDB fhdb = new CmpFinesHisDB();
                                sql = "SELECT * "
                                      + "FROM FINES_HIS "
                                      + "INNER JOIN FINES_DEF ON FINES_HIS.HFIN_DFIN_ID = FINES_DEF.DFIN_ID "
                                      + "WHERE HFIN_NUMBER = @FINES_HIS.HFIN_NUMBER@ "
                                      + "AND DFIN_COD_ID = @FINES_DEF.DFIN_COD_ID@";
                                dt = fhdb.GetData(sql, new object[] { _fineNumber, FINES_DEF_CODES_FINE });
                                if (dt.Rows.Count > 0)
                                {
                                    vehicleId    = (dt.Rows[0]["HFIN_VEHICLEID"] == DBNull.Value ? null : (string)dt.Rows[0]["HFIN_VEHICLEID"]);
                                    model        = (dt.Rows[0]["HFIN_MODEL"] == DBNull.Value ? null : (string)dt.Rows[0]["HFIN_MODEL"]);
                                    manufacturer = (dt.Rows[0]["HFIN_MANUFACTURER"] == DBNull.Value ? null : (string)dt.Rows[0]["HFIN_MANUFACTURER"]);
                                    colour       = (dt.Rows[0]["HFIN_COLOUR"] == DBNull.Value ? null : (string)dt.Rows[0]["HFIN_COLOUR"]);
                                    groupId      = (dt.Rows[0]["HFIN_GRP_ID"] == DBNull.Value ? -1 : Convert.ToInt32(dt.Rows[0]["HFIN_GRP_ID"]));
                                    streetId     = (dt.Rows[0]["HFIN_STR_ID"] == DBNull.Value ? -1 : Convert.ToInt32(dt.Rows[0]["HFIN_STR_ID"]));
                                    streetNumber = (dt.Rows[0]["HFIN_STRNUMBER"] == DBNull.Value ? -1 : Convert.ToInt32(dt.Rows[0]["HFIN_STRNUMBER"]));
                                    comments     = (dt.Rows[0]["HFIN_COMMENTS"] == DBNull.Value ? null : (string)dt.Rows[0]["HFIN_COMMENTS"]);
                                    userId       = (dt.Rows[0]["HFIN_USR_ID"] == DBNull.Value ? -1 : Convert.ToInt32(dt.Rows[0]["HFIN_USR_ID"]));
                                    //quantity = Convert.ToDouble(dt.Rows[0]["DFIN_VALUE"]);
                                }
                            }
                        }
                        //				else
                        //				{
                        //					// Quantity can be calculated based on _fineDefId parameter
                        //					CmpFinesDefDB fddb = new CmpFinesDefDB();
                        //					DataTable fddt = fddb.GetData(null, "DFIN_DESCSHORT = @FINES_DEF.DFIN_DESCSHORT@",
                        //						new object[] {_fineDefDescShort});
                        //					if (fddt.Rows.Count > 0)
                        //						quantity = (double)fddt.Rows[0]["DFIN_VALUE"];
                        //				}
                        if (groupId == -1)
                        {
                            // Get the physical groups tree and store it in parentsList
                            CmpGroupsChildsDB gcdb = new CmpGroupsChildsDB();
                            groupId = gcdb.GetFirstPhysicalParent(_unitId);
                        }

                        // Step 2: Insert the payed register in the FINES table

                        // ESTO NO FUNCIONA Y LO SE, LO SE ... falta la adecuación a la nueva tabla FINES

                        /*
                         * CFE - 020705 - Elimino inserción en fines de pagos llegados por m4
                         * fdb.InsertFine(FINES_DEF_PAYMENT,  vehicleId, model, manufacturer,
                         *      colour, groupId, groupId, streetId, streetNumber, _date, comments, userId, _unitId, _paymentDefId,-1,-1);
                         */

                        // Step 3: Insert the register in the OPERATIONS table
                        CmpOperationsDB odb             = new CmpOperationsDB();
                        int             nNewOperationID = 0;


                        /// Returns 0 = 0K, -1 = ERR, 1 = OPERACION YA EXISTENTE
                        int nInsOperRdo = odb.InsertOperation(OPERATIONS_DEF_PAYMENT, _operationId, -1, groupId,
                                                              _unitId, _paymentDefId, _date, DateTime.MinValue, DateTime.MinValue, -1, _quantity, vehicleId, -1, _mobileUserId, -1,
                                                              _dChipCardCredit, _ulChipCardId, (_fineNumber == null ? -1 : Convert.ToDouble(_fineNumber)),
                                                              _lfineDef, -1, -1, _onlineMessage, _ticketNumber, ref nNewOperationID, out tran);

                        // Smartcode implementation
                        if (_fineNumber.Length <= 10)
                        {
                            if ((nInsOperRdo == 0) && (_fineNumber != null))
                            {
                                CFineManager oFineManager = new CFineManager();
                                oFineManager.SetLogger(logger);
                                oFineManager.SetDBTransaction(tran);
                                oFineManager.SetFineStatus(int.Parse(_fineNumber));
                            }
                        }
                        else
                        {
                            string sFineCode = "";
                            for (int i = 0; i < 10; i++)
                            {
                                string sByte  = _fineNumber.Substring(i * 2, 2);
                                int    nValue = Convert.ToInt32(sByte);
                                char   cByte  = (char)nValue;
                                sFineCode += cByte.ToString();
                            }
                            CFineManager oFineManager = new CFineManager();
                            oFineManager.SetLogger(logger);
                            oFineManager.SetDBTransaction(tran);
                            oFineManager.UpdateOperationFineNumber(nNewOperationID, sFineCode);
                        }

                        if (nInsOperRdo == 0)
                        {
                            if (!UpdateCloudData(nNewOperationID, tran))
                            {
                                RollbackTrans(tran);
                                return(ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS));
                            }

                            OPS.Components.Data.CmpCreditCardDB cmpCreditCard = null;
                            cmpCreditCard = new OPS.Components.Data.CmpCreditCardDB();

                            if (cmpCreditCard == null)
                            {
                                RollbackTrans(tran);
                                return(ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS));
                            }

                            try
                            {
                                if (_szCCNumber != "")
                                {
                                    if (logger != null)
                                    {
                                        logger.AddLog("[Msg04:Process]: Operation WITH CARD Id", LoggerSeverities.Debug);
                                    }


                                    CmpCreditCardsTransactionsDB cmpCreditCardsTransactionsDB = new CmpCreditCardsTransactionsDB();

                                    if (_szCCNumber == "CCZ_OPERATIONID")
                                    {
                                        //szCCName contiene el número de transacción
                                        //nNewOperationID
                                        OracleConnection oraDBConn = null;
                                        OracleCommand    oraCmd    = null;


                                        Database d = OPS.Components.Data.DatabaseFactory.GetDatabase();
                                        logger    = DatabaseFactory.Logger;
                                        oraDBConn = (OracleConnection)tran.Connection;


                                        //
                                        string state     = String.Empty;
                                        string selectMFT = "select mft_status from mifare_transaction where MFT_UNI_TRANS_ID = " + _szCCName;
                                        selectMFT += " and MFT_UNI_ID = " + _unitId;

                                        if (oraDBConn.State == System.Data.ConnectionState.Open)
                                        {
                                            oraCmd             = new OracleCommand();
                                            oraCmd.Connection  = (OracleConnection)oraDBConn;
                                            oraCmd.CommandText = selectMFT;
                                            oraCmd.Transaction = (OracleTransaction)tran;

                                            OracleDataReader rd = oraCmd.ExecuteReader();

                                            while (rd.Read())
                                            {
                                                int i = rd.GetOrdinal("MFT_STATUS");
                                                state = (rd.GetInt32(rd.GetOrdinal("MFT_STATUS"))).ToString();
                                            }
                                        }
                                        else
                                        {
                                            RollbackTrans(tran);
                                            return(ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS));
                                        }

                                        if (state == "20")
                                        {
                                            string updateMFT = "update mifare_transaction ";
                                            updateMFT += "set mft_status = 30, mft_ope_id = " + nNewOperationID.ToString();
                                            updateMFT += "  where MFT_UNI_TRANS_ID= " + _szCCName + " and MFT_UNI_ID = " + _unitId;

                                            if (oraDBConn.State == System.Data.ConnectionState.Open)
                                            {
                                                oraCmd             = new OracleCommand();
                                                oraCmd.Connection  = (OracleConnection)oraDBConn;
                                                oraCmd.CommandText = updateMFT;
                                                oraCmd.Transaction = (OracleTransaction)tran;
                                                int numRowsAffected = oraCmd.ExecuteNonQuery();

                                                if (numRowsAffected == 0)
                                                {
                                                    RollbackTrans(tran);
                                                    ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS);
                                                    return(ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS));
                                                }
                                            }
                                            else
                                            {
                                                RollbackTrans(tran);
                                                return(ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS));
                                            }
                                        }
                                        else
                                        {
                                            RollbackTrans(tran);
                                            return(ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS));
                                        }
                                    }
                                    else if (iBinFormat == Msg07.DEF_BIN_FORMAT_EMV_TAS && _szCCNumber == "TRANSACTION_ID")
                                    {
                                        int iTransId = -1;
                                        if (cmpCreditCardsTransactionsDB.InsertCommitTrans(tran, _szCCName, _date, nNewOperationID, Convert.ToInt32(_quantity), _unitId, _fineNumber, out iTransId) < 0)
                                        {
                                            RollbackTrans(tran);
                                            if (logger != null)
                                            {
                                                logger.AddLog("[Msg02:Process]:ERROR ON INSERT", LoggerSeverities.Debug);
                                            }
                                            return(ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS));
                                        }
                                        else
                                        {
                                            if (logger != null)
                                            {
                                                logger.AddLog("[Msg02:Process]: RESULT OK", LoggerSeverities.Debug);
                                            }
                                        }
                                    }
                                    else if (iBinFormat == Msg07.DEF_BIN_FORMAT_EMV_TAS && _szCCNumber != "TRANSACTION_ID")
                                    {
                                        RollbackTrans(tran);
                                        if (logger != null)
                                        {
                                            logger.AddLog("[Msg02:Process]:TRANSACTION ID IS NOT ATTACHED", LoggerSeverities.Debug);
                                        }
                                        return(ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS));
                                    }
                                    else
                                    {
                                        _nStatus = STATUS_INSERT;
                                        if (cmpCreditCard.Insert(tran, nNewOperationID, _szCCNumber, _szCCName, _dtExpirDate, _nStatus, _szCCCodServ, _szCCDiscData) < 0)
                                        {
                                            RollbackTrans(tran);
                                            if (logger != null)
                                            {
                                                logger.AddLog("[Msg04:Process]:ERROR ON INSERT", LoggerSeverities.Debug);
                                            }
                                            return(ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS));
                                        }
                                        else
                                        {
                                            if (logger != null)
                                            {
                                                logger.AddLog("[Msg04:Process]: RESULT OK", LoggerSeverities.Debug);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    if (logger != null)
                                    {
                                        logger.AddLog("[Msg04:Process]: Operation WITHOUT CARD Id", LoggerSeverities.Debug);
                                    }
                                }
                            }
                            catch (Exception exc)
                            {
                                RollbackTrans(tran);
                                if (logger != null)
                                {
                                    logger.AddLog("[Msg04:Process]" + exc.Message, LoggerSeverities.Debug);
                                }
                                return(ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS));;
                            }
                        }
                        else if (nInsOperRdo == 1)
                        {
                            //RollbackTrans(tran);
                            if (logger != null)
                            {
                                logger.AddLog("[Msg04:Process]: Operation already exists in DB", LoggerSeverities.Debug);
                            }
                            return(ReturnAck(AckMessage.AckTypes.ACK_PROCESSED));
                        }
                        else
                        {
                            RollbackTrans(tran);
                            return(ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS));
                        }
                    }
                    else
                    {
                        if (!InsertFraudMsgs(logger))
                        {
                            return(ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS));
                        }
                    }
                }

                CommitTrans(tran);
                // Finished.
                return(ReturnAck(AckMessage.AckTypes.ACK_PROCESSED));
            }
            catch (Exception)
            {
                return(ReturnNack(NackMessage.NackTypes.NACK_ERROR_BECS));
            }
        }