Пример #1
0
        /// <summary>
        /// Adds the record.
        /// </summary>
        /// <param name="record">The record.</param>
        /// <returns></returns>
        public UPCRMUndoRecord AddRecord(UPCRMRecord record)
        {
            UPCRMUndoRecord undoRecord = this.undoRecordDictionary.ValueOrDefault(record.RecordIdentification);

            if (undoRecord == null)
            {
                undoRecord = new UPCRMUndoRecord(record, this);
                if (this.undoRecordDictionary == null)
                {
                    this.undoRecordDictionary = new Dictionary <string, UPCRMUndoRecord> {
                        { undoRecord.RecordIdentification, undoRecord }
                    };
                    this.undoRecords = new List <UPCRMUndoRecord> {
                        undoRecord
                    };
                }
                else
                {
                    this.undoRecordDictionary[undoRecord.RecordIdentification] = undoRecord;
                    this.undoRecords.Add(undoRecord);
                }
            }
            else
            {
                undoRecord.ApplyChangesFromRecord(record);
            }

            return(undoRecord);
        }
Пример #2
0
        /// <summary>
        /// Checks the after cache save.
        /// </summary>
        /// <returns></returns>
        public int CheckAfterCacheSave()
        {
            CRMDatabase database = this.DataStore.DatabaseInstance;
            int         ret      = 0;
            int         count    = this.undoRecords.Count;

            for (int i = 0; ret == 0 && i < count; i++)
            {
                UPCRMUndoRecord undoRecord = this.undoRecords[i];
                ret = undoRecord.CheckAfterCacheSave(database);
            }

            return(ret);
        }
Пример #3
0
        /// <summary>
        /// Adds the record identification rollback information.
        /// </summary>
        /// <param name="recordIdentification">The record identification.</param>
        /// <param name="rollbackInfo">The rollback information.</param>
        /// <returns></returns>
        public UPCRMUndoRecord AddRecordIdentificationRollbackInfo(string recordIdentification, string rollbackInfo)
        {
            UPCRMUndoRecord undoRecord = new UPCRMUndoRecord(recordIdentification, rollbackInfo.JsonDictionaryFromString(), this);

            if (this.undoRecordDictionary == null)
            {
                this.undoRecordDictionary = new Dictionary <string, UPCRMUndoRecord> {
                    { undoRecord.RecordIdentification, undoRecord }
                };
                this.undoRecords = new List <UPCRMUndoRecord> {
                    undoRecord
                };
            }
            else
            {
                this.undoRecordDictionary.SetObjectForKey(undoRecord, undoRecord.RecordIdentification);
                this.undoRecords.Add(undoRecord);
            }

            return(undoRecord);
        }
Пример #4
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);
        }