Which database are you logged into?

In a conference like Direcionts EMEA, I noticed again how interested people can be in sometimes such a simple solution. In our company, we implement every installation with a default set of tools (enhancements). One of these tools is a very simple and little something called "Database Info"-form.

The goal is to differentiate what kind of database you logged in: Test Database, a Test Company, a Development Database, ... . Actually, you just want a visual difference between two environments. In the old days (version 3.X and less), we had a menu, which we could give a certain color, caption or whatever. Now, we don't have a form that pops up, so no form we can modify. I present to you a little solution that might be able to help you with this, and the end result looks like this:

The red area, just right from the menu suite, is the "solution" I'm talking about - in case it was not clear Wink. To accomplish the main idea, there are only three things you have to do:

  • Create a form with these properties:
    • Borderstyle: None
    • CaptionBar: None
    • Mimizable: No
    • Maximizable: No
    • Sizeable: No
    • Editable: No
    • Xpos: 0
    • Ypos: 0
  • You put some descriptions on the form with captions.
  • In CodeUnit 1 in Trigger "CompanyOpen" you call the form like:

    IF GUIALLOWED THEN FORM.RUN(FORM::"Database Info");

That's basically all. Easy, isn't it?

But let's make it somewhat more useful and generic. Let's put some info on the form, work with colors and make that configurable ... So that the result is somewhat more like above:

  • Create a setup table with these fields:
    • Primary Key (Code)
    • Show Database info Form (Boolean): use this field to be able to switch off the use of the form.
    • Title (Text): Will be shown on the form.
    • Color (Option): The color of the form to make it even more "visible". I have chosen to make it simple. Just a fixed number of colors with an option field. You could make this with a color picker, but hey, we're not creating a business critical form here, are we Wink?
  • Modify codeunit 1, change your already added code to:

    CLEAR(recDatabaseInfoSetup);
      IF recDatabaseInfoSetup.GET THEN
        IF recDatabaseInfoSetup."Show Database Info Form" THEN
          IF GUIALLOWED THEN
            FORM.RUN(FORM::"Database Info");

  • Modify the form like this:

    The main idea is to "generate" the form when we are opening it. We'll set the colors, fill in the fields, make the form the right size and put it in it's place. Actually, the design on the form might even look like this (it doesn't matter):

    • To make the colors work:
      • For all colors in your option field, create a shape and put it somewhere on your form. Also, give a name to your shapes (preferably the color names to make the code more readable);
      • Create a function "SetBackColor" and call it "OnOpenForm".
      • This is what your function "SetBackColor" could look like;

        SetBackColor()

        //FIXED WIDTH AND HEIGHT. I CHOSE THESE VALUES:
        lintFormWidth := 10960;
        lintFormHeight := 4647;    

        //RESET SHAPE VALUES
        CurrForm.Blue.VISIBLE:=FALSE;
        CurrForm.Red.VISIBLE:=FALSE;
        //...
        //YOU CAN ADD THE REST OF THE COLORS IN THE SAME WAY

        //MOVE SHAPES
        CASE recDatabaseInfoSetup.Color OF
          recDatabaseInfoSetup.Color::Red:
           
        BEGIN
             
        CurrForm.Red.VISIBLE:=TRUE; 
             
        CurrForm.Red.XPOS := 0; 
             
        CurrForm.Red.YPOS := 0; 
             
        CurrForm.Red.WIDTH := lintFormWidth; 
             
        CurrForm.Red.HEIGHT := lintFormHeight; 
            
        END;
         
        recDatabaseInfoSetup.Color::Blue: 
            
        BEGIN 
             
        CurrForm.Blue.VISIBLE:=TRUE; 
             
        CurrForm.Blue.XPOS := 0; 
             
        CurrForm.Blue.YPOS := 0; 
             
        CurrForm.Blue.WIDTH := lintFormWidth; 
             
        CurrForm.Blue.HEIGHT := lintFormHeight; 
            
        END; 
            
        //...
            
        //YOU CAN ADD THE REST OF THE COLORS IN THE SAME WAY   
        END;

        //RESIZE FORM
        CurrForm.WIDTH := lintFormWidth;
        CurrForm.HEIGHT := lintFormHeight;

        It all comes down on resizing the form and resizing shapes.

  • I've put the following fields on the form as "useful info":
    • Title: This is a text that you can fill in in the Setup. I suppose you know how to put it in the form Wink.
    • Company: this is the COMPANYNAME statement (Duh...)
    • License Info: To get the license info, you can use the following code

      //recLicense (Record of the table "License Information")
      recLicense.SETRANGE("Line No.",5,6);
      IF recLicense.FIND('-') THEN
       
      REPEAT
         
      IF recLicense.Text <> '' THEN
           
      txtlicense[recLicense."Line No."] :=
              COPYSTR(recLicense.Text, 27, STRLEN(recLicense.Text)-26);
       
      UNTIL recLicense.NEXT = 0;

      With txtlicense[5] and txtLicenseDevil you can find your license information.

    • Number of Sessions: You could be using following code to make it work for SQL and Native databases:

      CLEAR(lrecSession);
      IF lrecSession.RECORDLEVELLOCKING THEN
       
      lrecSession.SETFILTER("Application Name",'@*NAV*');
      intSessionCount := lrecSession.COUNT;

    • User and Database information: You can get this info from the Session Table as well, with this code:

      lrecSession.SETRANGE("My Session", TRUE);
      IF lrecSession.FINDFIRST THEN BEGIN
       
      txtUserID := lrecSession."User ID";
       
      txtDatabaseName := lrecSession."Database Name";
      END
      ELSE BEGIN
       
      txtUserID := '';
        txtDatabaseName := '';
      END;

      This way, you also get the full login (with domain) when logged in with Windows Authentication ... Which I prefer.

Voilà, that's all. Not really "hocus pocus". Just simple and effective.

Hope you like it.

Enjoy!

Comment List
Related
Recommended