Esempio n. 1
0
        /// <summary>
        /// Undoes the request.
        /// </summary>
        /// <returns></returns>
        public int UndoRequest()
        {
            if (this.undoRecords == null || this.undoRecords.Count == 0)
            {
                return(-1);
            }

            CRMDatabase database = this.DataStore.DatabaseInstance;

            database.BeginTransaction();
            int ret = 0;

            foreach (UPCRMUndoRecord record in this.undoRecords)
            {
                ret = record.UndoWithTransaction(database);
                if (ret != 0)
                {
                    break;
                }
            }

            if (ret == 0)
            {
                database.Commit();
            }
            else
            {
                database.Rollback();
            }

            return(ret);
        }
Esempio n. 2
0
        /// <summary>
        /// Saves this instance.
        /// </summary>
        /// <returns></returns>
        public int Save()
        {
            if (this.undoRecords.Count == 0)
            {
                return(-1);
            }

            CRMDatabase database = this.DataStore.DatabaseInstance;

            database.BeginTransaction();
            DatabaseStatement statement = new DatabaseStatement(database);

            if (!statement.Prepare("DELETE FROM rollbackinfo WHERE requestnr = ?"))
            {
                return(-1);
            }

            statement.Bind(this.RequestId);
            int ret = statement.Execute();

            if (ret != 0)
            {
                return(ret);
            }

            statement = new DatabaseStatement(database);
            if (!statement.Prepare("INSERT INTO rollbackinfo (requestnr, infoareaid, recordid, rollbackinfo) VALUES (?,?,?,?)"))
            {
                return(-1);
            }

            int recordCount = this.undoRecords.Count;

            for (int i = 0; ret == 0 && i < recordCount; i++)
            {
                UPCRMUndoRecord undoRecord = this.undoRecords[i];
                statement.Reset();
                statement.Bind(1, this.RequestId);
                string infoAreaId   = undoRecord.RecordIdentification.InfoAreaId();
                string recordId     = undoRecord.RecordIdentification.RecordId();
                string rollbackInfo = undoRecord.RollbackInfo;
                if (string.IsNullOrEmpty(infoAreaId) || string.IsNullOrEmpty(recordId) || string.IsNullOrEmpty(rollbackInfo))
                {
                    continue;
                }

                statement.Bind(2, infoAreaId);
                statement.Bind(3, recordId);
                statement.Bind(4, rollbackInfo);
                ret = statement.Execute();
            }

            if (ret == 0)
            {
                database.Commit();
            }
            else
            {
                database.Rollback();
            }

            return(ret);
        }