示例#1
0
        /// <summary>
        /// Find if one (or more) operations are associated for the vehicle, date and group.
        /// If an operation is found, but in other group, the method checks if the PDM of the operation found belongs
        /// to an amplied zone containing the associated group and the PDM. If the amplied zone is found, the operation
        /// is considered valid.
        /// </summary>
        /// <param name="maxTime">If retval is FindOperationsResult.OK, the parameter is filled with the max of OPE_ENDDATE of all operations</param>
        /// <returns>true if one or more operations were found</returns>
        public FindOperationsResults FindOperations(out DateTime maxTime)
        {
            // 1. Get all operations for the current vehicleID and date.
            maxTime = DateTime.MinValue;
            CmpOperationsDB cmp = new CmpOperationsDB();
            DataTable       dt  = cmp.GetData(null, "OPE_INIDATE <= @OPERATIONS.OPE_INIDATE@ AND OPE_ENDDATE >= @OPERATIONS.OPE_ENDDATE@ AND OPE_VEHICLEID = @OPERATIONS.OPE_VEHICLEID@",       //ORDER BY OPE_ENDDATE DESC
                                              new object[] { _date, _date, _vehicle });

            if (dt.Rows.Count == 0)
            {
                return(FindOperationsResults.NotFoundAnyOperation);                                                     // No operations found...
            }
            // Select the operations on the same group
            DataRow[] currentGroupOperations = dt.Select("OPE_GRP_ID=" + _grpid, "OPE_ENDDATE DESC");
            if (currentGroupOperations.Length > 0)
            {
                maxTime = Convert.ToDateTime(currentGroupOperations[0]["OPE_ENDDATE"]);
                return(FindOperationsResults.OK);
            }
            else
            {
                FindOperationsResults bRet = FindOperationsResults.OK;
                // Not found operations for the SAME group... let's check PDM of all operations for the vehicle...
                DateTime maxOpeDate = DateTime.MinValue;
                foreach (DataRow dr in dt.Rows)
                {
                    // Check if operation is in the current group or in another group but inside the same amplied zone
                    int opePdm = Convert.ToInt32(dr["OPE_UNI_ID"]);
                    if (CheckForAmpliedZone(opePdm) != -1)
                    {
                        // operation is good
                        // NOTE: When we find the first operation that is in the amplied group, we could finish (because
                        // we have the operations sorted by OPE_ENDDATE).
                        // But we will continue, because we could find a 2nd operation in INVALID zone... in that case the car
                        // must be fined.
                        DateTime opeEnd = Convert.ToDateTime(dr["OPE_ENDDATE"]);
                        if (opeEnd > maxOpeDate)
                        {
                            maxOpeDate = opeEnd;
                        }
                    }
                    else
                    {
                        // Vehicle MUST be fined
                        bRet = FindOperationsResults.OperationOnInvalidZone;
                        break;
                    }
                }
                if (bRet == FindOperationsResults.OK)
                {
                    maxTime = maxOpeDate;
                }
                return(bRet);
            }
        }
        /// <summary>
        /// Computes the minimum MP.
        /// Foreach group in the table of groups:
        ///		Get all operations of the group (for article and vehicle passed)
        ///		Sums all OPE_DURATION times
        ///		Set CalculoMP of the group to the value MP - Sum(OPE_DURATION)
        /// The dtConstraints DataTable is modified (CalculoMP field is set).
        /// </summary>
        /// <param name="dtConstraints">DataTable of constraints (obtained with CmpConstraints::GetConstraints())</param>
        /// <param name="artid">ID of the article (use -1 for NULL)</param>
        /// <param name="vehid">ID of the vehicle (cannot be NULL)</param>
        /// <param name="pInDate">DateTime of the new intended operation (OPE_INIDATE or OPE_MOVDATE if passed in the message).</param>
        public void CalculateMP(DataTable dtConstraints, DateTime pInDate, int artid, string vehid)
        {
            CmpOperationsDB cmp = new CmpOperationsDB();

            _treeGroups.EvalHandler = new OTS.Framework.Collections.UnorderedTree.EvalItem(TreeItemToId);
            foreach (DataRow drGroup in dtConstraints.Rows)
            {
                // Can use Agrupación, we don't have GROUP_TYPEs at that step
                // (were all removed in FilterConstraintsTable)
                int group = Convert.ToInt32(drGroup["Agrupacion"]);
                UnorderedTree.TreeItem titem = _treeGroups.FindItem(new UnorderedTree.FindItemDelegate(FindItemById), drGroup);
                // Get an arraylist with the IDs of all descendants of the current group.
                ArrayList groupChilds = titem.MapcarDescendants();
                // Get all operations.
                int      mp    = drGroup["MP"] != DBNull.Value ? Convert.ToInt32(drGroup["MP"]) : 0;
                DateTime opend = pInDate;
                if (mp > 0)
                {
                    opend = opend.Subtract(new TimeSpan(0, mp, 0));
                }
                DataTable dtOperations = cmp.GetData(null, "OPE_ENDDATE > @OPERATIONS.OPE_ENDDATE@ AND OPE_ART_ID = @OPERATIONS.OPE_ART_ID@ AND OPE_VEHICLEID = @OPERATIONS.OPE_VEHICLEID@",
                                                     "OPE_ENDDATE DESC", new object[] { opend, artid != -1 ? (object)artid : (object)DBNull.Value, vehid });
                // Iterates throught the operations DataTable. We will exit when we found an OPERATION that:
                //	a) Were not related to the group we are processing (group variable)
                //	b) AND were not related to any of the group_childs of the group...
                int sumOpeDuration = 0;
                foreach (DataRow drOperation in dtOperations.Rows)
                {
                    int opeGroup = Convert.ToInt32(drOperation["OPE_GRP_ID"]);
                    // Check if opeGroup (group of the operation) is the group we are processing (group) or any
                    // descendant of the group we are processing..
                    if (!groupChilds.Contains(opeGroup))
                    {
                        break;                                                                  // finish the iteration over operations table
                    }
                    sumOpeDuration += Convert.ToInt32(drOperation["OPE_DURATION"]);
                }
                // At that point we have the sumOpeDuration for the current group, so store it in the CalculoMP row
                drGroup["CalculoMP"] = mp - sumOpeDuration;
            }
            // Now we have "CalculoMP" computed by all operations.
            _treeGroups.EvalHandler = null;
        }
        /// <summary>
        /// Validates the TR (tiempo de reentrada) constraints for a given table of constraints and groups
        /// That method is called after get the constraints (CmpConstraints::GetConstraints) and
        /// after filtering the constraints obtained (CmpConstraints::FilterConstraintsTable)
        /// </summary>
        /// <param name="dtConstraints">DataTable with constraints and groups (not groups_types) to process.</param>
        /// <param name="pInDate">DateTime when te operation was done (usually MOV_OPDATE of M01 message)</param>
        /// <param name="artid">ID of the ARTICLE (-1 for NULL)</param>
        /// <param name="vehicleid">ID of the VEHICLE (CANNOT be null)</param>
        /// <param name="operationId">OUT parameter with value of DATE of previous Operation (only used if return code is PreviousDate)</param>
        /// <returns>A ValidateTRReturnCodes specifying the result of validation (non valid, ok with previous date, ok)</returns>
        public ValidateTRReturnCodes ValidateTR(DataTable dtConstraints, DateTime pInDate,
                                                int artid, string vehicleid, out int operationId)
        {
            //previousDate = DateTime.MinValue;
            operationId = -1;
            CmpOperationsDB cmp = new CmpOperationsDB();

            foreach (DataRow group in dtConstraints.Rows)
            {
                int       tr    = group["TR"] != DBNull.Value ? Convert.ToInt32(group["TR"]) : 0;
                int       tc    = group["TC"] != DBNull.Value ? Convert.ToInt32(group["TC"]) : 0;
                DateTime  opend = pInDate.Subtract(new TimeSpan(0, tr, 0));
                DataTable dtOperations;
                if (artid != -1)
                {
                    dtOperations = cmp.GetAllData(null, "OPE_ENDDATE >= @OPERATIONS.OPE_ENDDATE@ "
                                                  + "AND OPE_VEHICLEID = @OPERATIONS.OPE_VEHICLEID@ "
                                                  + "AND OPE_ART_ID = @OPERATIONS.OPE_ART_ID@",
                                                  "OPE_ENDDATE DESC", new object[] { opend, vehicleid, artid });
                }
                else
                {
                    dtOperations = cmp.GetAllData(null, "OPE_ENDDATE >= @OPERATIONS.OPE_ENDDATE@ "
                                                  + "AND OPE_VEHICLEID = @OPERATIONS.OPE_VEHICLEID@",
                                                  "OPE_ENDDATE DESC", new object[] { opend, vehicleid });
                }
                if (dtOperations.Rows.Count > 0)
                {
                    // Ok.. At that point we have:
                    //		ALL operations of the current vehicle and current article for ALL zones in the TR period of time.
                    //		We must filter that table for having only the operations for the CURRENT zone and ALL HIS CHILDS.
                    //		The rest of operations are discarded at that point (but, of course, we could find them again when
                    //		processing another zone
                    UnorderedTree.TreeItem titem = _treeGroups.FindItem(new UnorderedTree.FindItemDelegate(FindItemById), group);
                    // Delete from dtOperations table ALL operations that are not associated by titem or any childs of titem.
                    FilterOperationsTableByGroup(dtOperations, titem);
                }
                if (dtOperations.Rows.Count > 0)
                {
//					return ValidateTRReturnCodes.OperationNonValid;
                    // At that point we have only the operations related with the current group (or any of his childs).
                    DataRow  operation = dtOperations.Rows[0];
                    DateTime opendtc   = Convert.ToDateTime(operation["OPE_ENDDATE"]).AddMinutes(tc);
                    if (pInDate > opendtc)
                    {
                        // Operation not valid. At the first non-valid operation we return
                        return(ValidateTRReturnCodes.OperationNonValid);
                    }
                    else                     // An ampliation of previous operation is possible
                    {
                        // Find the group of the current operation
                        int currentGroup = -1;
                        foreach (object o in _lstGroups)
                        {
                            CmpStatus.StatusTreeItem item = (CmpStatus.StatusTreeItem)((UnorderedTree.TreeItem)o).Data;
                            if (item.IsUnit)
                            {
                                continue;
                            }
                            else if (item.IsGroup)
                            {
                                currentGroup = item.Id;
                                break;
                            }
                        }

                        // Let's check if the groups are the same.
                        // If not, exit as an extension is not possible.
                        int operationGroup = Convert.ToInt32(operation["OPE_GRP_ID"]);
                        if (currentGroup != operationGroup)
                        {
                            return(ValidateTRReturnCodes.OperationNonValid);
                        }

                        operationId = Convert.ToInt32(operation["OPE_ID"]);
                        return(ValidateTRReturnCodes.Extension);
                        /////////////////////////////////////////////////////////
                        //int groupid = Convert.ToInt32 (group["Agrupacion"]);
                        //if (opeid == groupid && Convert.ToBoolean (group["PagoTC"]))
                        //{
                        //	// An ampliation is allowed.
                        //	previousDate = Convert.ToDateTime (operation["OPE_ENDDATE"]);
                        //	return ValidateTRReturnCodes.PreviousDate;
                        //}
                    }
                }
            }
            return(ValidateTRReturnCodes.OnlyOk);
        }
        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));
            }
        }
示例#5
0
        /// <summary>
        /// Obtains all the operations related to a parking in one register.
        /// So, if "id" is a parking, searches also for its extensions
        /// And if "id" itself is an extension, looks for its base parking and afterwards its extensions
        /// </summary>
        /// <param name="id">The parking to look for</param>
        /// <returns>A single row with the summarized data</returns>
        public DataTable GetSummarizedParking(int id)
        {
            CmpOperationsDB odb = new CmpOperationsDB();
            DataTable       dt  = odb.GetAllData(null, "OPE_ID = @OPERATIONS.OPE_ID@ OR OPE_OPE_ID = @OPERATIONS.OPE_OPE_ID@",
                                                 new object[] { id, id });

            if (dt.Rows.Count == 0)
            {
                return(null);
            }
            else if (dt.Rows.Count == 1)             // Is it a parking?
            {
                if (Convert.ToInt32(dt.Rows[0]["OPE_DOPE_ID"]) == OPERATIONS_DEF_EXTENSION)
                {
                    int original = Convert.ToInt32(dt.Rows[0]["OPE_OPE_ID"]);
                    dt = odb.GetAllData(null, "OPE_ID = @OPERATIONS.OPE_ID@ OR OPE_OPE_ID = @OPERATIONS.OPE_OPE_ID@",
                                        new object[] { original, original });
                }
                else if (Convert.ToInt32(dt.Rows[0]["OPE_DOPE_ID"]) != OPERATIONS_DEF_PARKING)
                {
                    return(null);
                }
            }
            // Now just summarize the data
            foreach (DataRow row in dt.Rows)
            {
                if (Convert.ToInt32(row["OPE_ID"]) != Convert.ToInt32(dt.Rows[0]["OPE_ID"]))
                {
                    // MOVDATE
                    if (dt.Rows[0]["OPE_MOVDATE"] == DBNull.Value)
                    {
                        dt.Rows[0]["OPE_MOVDATE"] = row["OPE_MOVDATE"];
                    }
                    else if (row["OPE_MOVDATE"] != DBNull.Value)
                    {
                        dt.Rows[0]["OPE_MOVDATE"] =
                            MaxDateTime(Convert.ToDateTime(row["OPE_MOVDATE"]),
                                        Convert.ToDateTime(dt.Rows[0]["OPE_MOVDATE"]));
                    }

                    // INIDATE
                    if (dt.Rows[0]["OPE_INIDATE"] == DBNull.Value)
                    {
                        dt.Rows[0]["OPE_INIDATE"] = row["OPE_INIDATE"];
                    }
                    else if (row["OPE_INIDATE"] != DBNull.Value)
                    {
                        dt.Rows[0]["OPE_INIDATE"] =
                            MinDateTime(Convert.ToDateTime(row["OPE_INIDATE"]),
                                        Convert.ToDateTime(dt.Rows[0]["OPE_INIDATE"]));
                    }

                    // ENDDATE
                    if (dt.Rows[0]["OPE_ENDDATE"] == DBNull.Value)
                    {
                        dt.Rows[0]["OPE_ENDDATE"] = row["OPE_ENDDATE"];
                    }
                    else if (row["OPE_ENDDATE"] != DBNull.Value)
                    {
                        dt.Rows[0]["OPE_ENDDATE"] =
                            MaxDateTime(Convert.ToDateTime(row["OPE_ENDDATE"]),
                                        Convert.ToDateTime(dt.Rows[0]["OPE_ENDDATE"]));
                    }

                    // DURATION
                    if (dt.Rows[0]["OPE_DURATION"] == DBNull.Value)
                    {
                        dt.Rows[0]["OPE_DURATION"] = row["OPE_DURATION"];
                    }
                    else if (row["OPE_DURATION"] != DBNull.Value)
                    {
                        dt.Rows[0]["OPE_DURATION"] =
                            Convert.ToInt32(row["OPE_DURATION"])
                            + Convert.ToInt32(dt.Rows[0]["OPE_DURATION"]);
                    }

                    // VALUE
                    if (dt.Rows[0]["OPE_VALUE"] == DBNull.Value)
                    {
                        dt.Rows[0]["OPE_VALUE"] = row["OPE_VALUE"];
                    }
                    else if (row["OPE_VALUE"] != DBNull.Value)
                    {
                        dt.Rows[0]["OPE_VALUE"] =
                            Convert.ToDouble(row["OPE_VALUE"])
                            + Convert.ToDouble(dt.Rows[0]["OPE_VALUE"]);
                    }

                    row.Delete();
                }
            }
            // Leave only the first row and return
            //while (dt.Rows.Count > 2)
            //{
            //	dt.Rows[1].Delete();
            //}
            return(dt);
        }