OnBeforeSaveData(Stub: IVariableStub; Matrix: IMatrix; Var ValueFlag: Integer; Var Cancel: Boolean);
Stub. Data source, to which data is saved.
Matrix. Matrix with saved values.
ValueFlag. Flag that is assigned to changed data in the Matrix matrix.
Cancel. Indicates whether data saving is canceled.
The OnBeforeSaveData method implements the event that occurs before saving data.
The Matrix variable will have source and calculated data. Source data will have the 0 flag of changed values. Calculated data will have the flag that is equal to value of the ValueFlag parameter. ValueFlag will correspond to the value specified in the IMsProblem.ValueFlag or IMsProblemCalculationSettings.ValueFlag property. If required, one can change matrix data and flag in the ValueFlag parameter. The values are saved that have the flag of changed values equal to value of the ValueFlag parameter.
After the data is saved, the OnSaveData event is generated.
If data saving must be canceled, set the Cancel parameter to True or the ValueFlag parameter to 0.
Executing the example requires a time series database with the TSDB identifier. The modeling container that is a child object of the database has a modeling problem with the TSDB_PROBLEM identifier.
Add links to the Cubes, Matrix, Metabase, Ms, Ui system assemblies.
Sub UserProc;
Var
Mb: IMetabase;
Rub: IRubricator;
Problem: IMsProblem;
Calculation: IMsProblemCalculation;
CalcSettings: IMsProblemCalculationSettings;
Begin
Mb := MetabaseClass.Active;
Rub := MB.ItemById("TSDB").Bind As IRubricator;
// Get problem in TSDB modeling container
Problem := Mb.ItemByIdNamespace("TSDB_PROBLEM", Rub.ModelSpace.Key).Edit As IMsProblem;
// Flag that will be assigned to changed data
Problem.ValueFlag := 2;
// Set problem calculation parameters
CalcSettings := Problem.CreateCalculationSettings;
CalcSettings.FactIncluded := True;
CalcSettings.BreakOnError := True;
Calculation := Problem.Calculate(CalcSettings);
// Set event handler
Calculation.Callback := New MCallback.Create;
// Calculate
Calculation.Run;
End Sub UserProc;
Public Class MCallback: ProblemCalculationCallback
Public Sub OnBeforeSaveData(Stub: IVariableStub; Matrix: IMatrix; Var ValueFlag: Integer; Var Cancel: Boolean);
Var
Iter: IMatrixIterator;
Begin
If Not WinApplication.ConfirmationBox("Save data?", Null) Then
Cancel := True;
End If;
Iter := Matrix.CreateIterator;
Iter.Move(IteratorDirection.First);
While Iter.Valid Do
If Iter.ValueFlag <> 0 Then
If Iter.Value < 100 Then
Iter.ValueFlag := ValueFlag + 1;
End If;
End If;
Iter.Move(IteratorDirection.Next);
End While;
// Increase value of flag of changed data that will be saved by 1
ValueFlag := ValueFlag + 1;
End Sub OnBeforeSaveData;
Public Sub OnSaveData(Stub: IVariableStub; Matrix: IMatrix; ValueFlag: Integer; AuditRecordKey: Variant);
Var
Iter: IMatrixIterator;
RecordCount: Integer;
Begin
Iter := Matrix.CreateIterator;
Iter.Move(IteratorDirection.First);
While Iter.Valid Do
If Iter.ValueFlag = ValueFlag Then
RecordCount := RecordCount + 1;
End If;
Iter.Move(IteratorDirection.Next);
End While;
Debug.WriteLine("Data is saved on ValueFlag: " + ValueFlag.ToString + #13 + #10 +
"Number of saved values: " + RecordCount.ToString + #13 + #10 +
"Key of record in access protocol: " + AuditRecordKey);
End Sub OnSaveData;
End Class MCallback;
After executing the example the modeling problem is calculated. The calculated values will have the 2 flag (ValueFlag = 2).
A save request is displayed in the event that traces data saving. If the answer is positive, the 3 flag is set for calculated values less than 100. After this all the values with the 3 flag will be saved into the time series database. After the data is saved, the development environment console displays information about the number of saved values and key of the record in access protocol that corresponds to data saving.
See also: