Filling the &[DEPARTMENT] and &[NAME] Values for Marking Stamp

The marking stamp can use the &[DEPARTMENT] and &[NAME] substitutions which can be filled in only from application code on creating connection to repository.

To set substitution values, use the ICredentials.PersonDepartment and ICredentials.PersonName properties available only in Fore .NET.

The ICredentials.PersonDepartment property corresponds to the &[DEPARTMENT] substitution, the ICredentials.PersonName property corresponds to the &[NAME] substitution.

See below the example of setting values for the &[DEPARTMENT] and &[NAME] substitutions in the marking stamp. Marking stamp will be displayed whatever mandatory access or access by security levels is applied for the report. To provide a correct example work, the MSServer (DBMS - Microsoft SQL Server 2008) requires the PPRepository repository. A regular report with the REPORT identifier is created in repository.

To execute the example follow the steps:

  1. Create the .NET assembly with the NET form in it.

  2. Add links to the Drawing, ForeSystem, Report system assemblies. Import those assemblies from the Prognoz.Platform.Interop system assembly:

Imports Prognoz.Platform.Interop.Report;
Imports Prognoz.Platform.Interop.Drawing;

Imports Prognoz.Platform.Interop.ForeSystem;

  1. Place on the form:

  1. Create the Test public class in the Program module of the .NET assembly:

Public Class Test
    
    Public Function getMB(name: string; depart: string; Login: string; Password: string;): IMetabase;
    Var mb : IMetabase;
        factory : MetabaseManagerFactoryClass;
        manager : IMetabaseManager;
        def : IMetabaseDefinition;
        defs : IMetabaseDefinitions;
        package : StandardSecurityPackage;
        creds : ICredentials;
        pcreds: IPasswordCredentials;
        // Create object to work with repository description
        factory := New MetabaseManagerFactoryClass.Create();
        manager := factory.Active;
        
// Create a standard security package
        package := New StandardSecurityPackage.Create();
        
// Get collection of repository descriptions
        defs := manager.Definitions;
        
// Add a new description of connection with repository
        def := defs.Add();
        
// Set connection parameters with repository
        def.Name := "Test_connect";
        def.SecurityPackage := package.Id;
        def.Authentication := AuthenticationMode.amPassword;
        def.DeferredLoading := 
False;
        def.DriverId := 
"MSSQL2008";
        ld := def.LogonData;
        ld.ParamValue[
"SERVER"] := 
"ms2008a";
        ld.ParamValue[
"DATABASE"] := "pprepository";
        
// Create credentials with the specified authentication type
        creds := package.CreateCredentials(AuthenticationMode.amPassword);
        
// Set login and password to login the repository
        pcreds := creds As IPasswordCredentials;
        pcreds.UserName := Login;
        pcreds.Password := Password;
        
// Determine the user name which will be displayed to the stamp
        creds.PersonName := name;
        
// Determine department which will be displayed in the stamp
        creds.PersonDepartment := depart;
        
// Connection to repository according to defined parameters
        mb := def.Open(creds, ApplicationMode.amWin, LocaleCodeID.lcidRussian);
        Return mb;
    End Function getMB;
    
End Class Test;

  1. Create handler for the button:

Private Sub button1_Click(sender: System.Object; e: System.EventArgs);
Var
    MB, MB_new : IMetabase;
    Obj: Test=New Test();
    User, Department, Login, Password : String;
    rep : IPrxReport;
    doc : IGxDocument;
    Security : IMetabaseSecurity;       
Begin
    MB := Self.Metabase;
    Security:= MB.Security;
    // Set stamp use regardless of settings
    Security.Policy.AlwaysPrintDocumentLabel := True;
    // Apply selected policy settings
    Security.Apply();
    // Determine user name for marking stamp
    User := "Ivanov Ivan";
    // Determine department for marking stamp
    Department := "HR";
    // Login 
    Login := textBox1.Text;
    // Password
    Password := textBox2.Text;
    // Call the getMB method of the Test custom class
    MB_new := Obj.getMB(User,Department,Login,Password) As IMetabase;
    // Get report for which marking stamp is applied
    Rep := MB_new.ItemById["REPORT"].Open(NullAs IPrxReport;
    doc := rep As IGxDocument;
    // Open document for preview before print to see marking stamp 
    documentPrinterNet1.Document := doc;
    documentPrinterNet1.DocumentPrinterUi.PrintPreview(0New IWin32WindowForeAdapter(Self), True);
End Sub button1_Click;

  1. Launch form for execution, input credentials of the user to connect to repository and click the OK button.

As a result the report is opened for preview, marking stamp with filled values for the &[DEPARTMENT] and &[NAME] substitutions:

See also:

Examples | IMetabaseLinkBase | Marking Stamp