30.12.2010, 10:45 | #23 |
Участник
|
Для поиска удалённых данных, могу подкинуть один джобик.
X++: // Восстанавливает в таблицу <toTable> записи удеалённые из таблицы <fromTable> // !!! имена полей (и желательно их типы :) должны совпадать static void RestoreToTable(TableId fromTableId, TableId toTableId, date fromDate, date toDate, UserId deletedBy = "")//, createdTransactionId _createdTransactionId) { SysDataBaseLog SysDataBaseLog; list datalist; listEnumerator enumerator; container tmp; int i; dictTable toDictTable = new dictTable(toTableId); dictTable fromDictTable = new dictTable(FromTableId); DictField toDictField; DictField fromDictField; FieldId toFieldId; FieldId fromFieldId; int toCntFields; int arrayCount; int arrayIdx; FieldName fromFieldName; FieldName toFieldName; Common Common; SysOperationProgress DialogProgress; int DialogProgress_cntAll; int DialogProgress_cnt = 0; ; DialogProgress = new SysOperationProgress(); DialogProgress.setCaption("Восстановление удалённых записей"); DialogProgress.setTotal(100); select count(RecId) from SysDataBaseLog where SysDataBaseLog.table == fromTableId && SysDataBaseLog.createdDateTime >= datetimeutil::newDateTime(fromDate, 0) && SysDataBaseLog.createdDateTime < datetimeutil::newDateTime(toDate + 1, 0) && (deletedBy == "" || SysDataBaseLog.createdBy == deletedBy) && SysDataBaseLog.LogType == DatabaseLogType::Delete ;// && SysDataBaseLog.createdTransactionId == _createdTransactionId; DialogProgress_cntAll = SysDataBaseLog.RecId; while select SysDataBaseLog where SysDataBaseLog.table == fromTableId && SysDataBaseLog.createdDateTime >= datetimeutil::newDateTime(fromDate, 0) && SysDataBaseLog.createdDateTime < datetimeutil::newDateTime(toDate + 1, 0) && (deletedBy == "" || SysDataBaseLog.createdBy == deletedBy) && SysDataBaseLog.LogType == DatabaseLogType::Delete // && SysDataBaseLog.createdTransactionId == _createdTransactionId { DialogProgress.setText(strfmt ( "Восстановленно записей: %1 из %2", DialogProgress_cnt, DialogProgress_cntAll )); Common = toDictTable.makeRecord(); datalist = SysDataBaseLog.getDataAslist(); enumerator = dataList.getEnumerator(); while (enumerator.moveNext()) { tmp = enumerator.current(); fromFieldId = conpeek(tmp, 1); fromDictField = new dictField(fromDictTable.id(), fromFieldId); fromFieldName = fromDictField.name(); toCntFields = toDictTable.fieldCnt(); for (I = 1; I <= toCntFields; I++) { toDictField = new dictField(toDictTable.id(), toDictTable.fieldCnt2Id(I)); toFieldId = toDictField.id(); arrayCount = toDictField.arraySize(); for (arrayIdx = 1; arrayIdx <= arrayCount; arrayIdx ++) { toFieldId += 65536; toDictField = new dictField(toDictTable.id(), toFieldId); toFieldName = toDictField.name(); if (toFieldName == fromFieldName) { Common.(toDictField.id()) = conpeek(tmp, 2); } } } } toFieldId = toDictTable.fieldName2Id("DeletedBy"); if (toFieldId > 0) Common.(toFieldId) = SysDataBaseLog.createdBy; toFieldId = toDictTable.fieldName2Id("DeletedDateTime"); if (toFieldId > 0) Common.(toFieldId) = SysDataBaseLog.createdDateTime; toFieldId = toDictTable.fieldName2Id("DeletedTransactionId"); if (toFieldId > 0) Common.(toFieldId) = SysDataBaseLog.createdTransactionId; Common.insert(); DialogProgress_cnt++; DialogProgress.setcount(DialogProgress_cnt*100/DialogProgress_cntAll); } } |
|