Saturday, October 25, 2014

Manage and control number of active user loggins

Even though client license says it is for 10 users there are some chances more than 10 users can access the system at the same time. I have faced this situation many times and we didn't had a option to control No. of user loggins. 

To achieve and control the number of user loggins I have written a small and silly code segment which check number of active users logged to NAV database and then check it with the actual users allowed. Then next user will not allowed to access the system if the number of allowed users are exceeded with the current level.

Here goes the code,

 OBJECT Table 79 Company Information  
 {  
  OBJECT-PROPERTIES  
  {  
   Date=14-10-25;  
   Time=[ 3:29:45 PM];  
   Modified=Yes;  
   Version List=NAVW16.00;  
  }  
  PROPERTIES  
  {  
   CaptionML=ENU=Company Information;  
  }  
  FIELDS  
  {  
   { 1  ;  ;Primary Key     ;Code10    ;CaptionML=ENU=Primary Key }  
   { 2  ;  ;Name        ;Text50    ;CaptionML=ENU=Name }  
   { 3  ;  ;Name 2       ;Text50    ;CaptionML=ENU=Name 2 }  
   { 4  ;  ;Address       ;Text50    ;CaptionML=ENU=Address }  
   { 5  ;  ;Address 2      ;Text50    ;CaptionML=ENU=Address 2 }  
   { 6  ;  ;City        ;Text30    ;OnValidate=BEGIN  
                                 PostCode.ValidateCity(City,"Post Code");  
                                END;  
                           OnLookup=BEGIN  
                                PostCode.LookUpCity(City,"Post Code",TRUE);  
                               END;  
                           CaptionML=ENU=City }  
   { 7  ;  ;Phone No.      ;Text30    ;ExtendedDatatype=Phone No.;  
                           CaptionML=ENU=Phone No. }  
   { 8  ;  ;Phone No. 2     ;Text30    ;ExtendedDatatype=Phone No.;  
                           CaptionML=ENU=Phone No. 2 }  
   { 9  ;  ;Telex No.      ;Text30    ;CaptionML=ENU=Telex No. }  
   { 10 ;  ;Fax No.       ;Text30    ;CaptionML=ENU=Fax No. }  
   { 11 ;  ;Giro No.      ;Text20    ;CaptionML=ENU=Giro No. }  
   { 12 ;  ;Bank Name      ;Text50    ;CaptionML=ENU=Bank Name }  
   { 13 ;  ;Bank Branch No.   ;Text20    ;CaptionML=ENU=Bank Branch No. }  
   { 14 ;  ;Bank Account No.  ;Text30    ;CaptionML=ENU=Bank Account No. }  
   { 15 ;  ;Payment Routing No. ;Text20    ;CaptionML=ENU=Payment Routing No. }  
   { 17 ;  ;Customs Permit No. ;Text10    ;CaptionML=ENU=Customs Permit No. }  
   { 18 ;  ;Customs Permit Date ;Date     ;CaptionML=ENU=Customs Permit Date }  
   { 19 ;  ;VAT Registration No.;Text20    ;OnValidate=VAR  
                                 VATRegNoFormat@1000 : Record 381;  
                                BEGIN  
                                 VATRegNoFormat.Test("VAT Registration No.","Country/Region Code",'',DATABASE::"Company Information");  
                                END;  
                           CaptionML=ENU=VAT Registration No. }  
   { 20 ;  ;Registration No.  ;Text20    ;CaptionML=ENU=Registration No. }  
   { 21 ;  ;Telex Answer Back  ;Text20    ;CaptionML=ENU=Telex Answer Back }  
   { 22 ;  ;Ship-to Name    ;Text50    ;CaptionML=ENU=Ship-to Name }  
   { 23 ;  ;Ship-to Name 2   ;Text50    ;CaptionML=ENU=Ship-to Name 2 }  
   { 24 ;  ;Ship-to Address   ;Text50    ;CaptionML=ENU=Ship-to Address }  
   { 25 ;  ;Ship-to Address 2  ;Text50    ;CaptionML=ENU=Ship-to Address 2 }  
   { 26 ;  ;Ship-to City    ;Text30    ;OnValidate=BEGIN  
                                 PostCode.ValidateCity("Ship-to City","Ship-to Post Code");  
                                END;  
                           OnLookup=BEGIN  
                                PostCode.LookUpCity("Ship-to City","Ship-to Post Code",TRUE);  
                               END;  
                           CaptionML=ENU=Ship-to City }  
   { 27 ;  ;Ship-to Contact   ;Text50    ;CaptionML=ENU=Ship-to Contact }  
   { 28 ;  ;Location Code    ;Code10    ;TableRelation=Location WHERE (Use As In-Transit=CONST(No));  
                           CaptionML=ENU=Location Code }  
   { 29 ;  ;Picture       ;BLOB     ;CaptionML=ENU=Picture;  
                           SubType=Bitmap }  
   { 30 ;  ;Post Code      ;Code20    ;TableRelation="Post Code";  
                           OnValidate=BEGIN  
                                 PostCode.ValidatePostCode(City,"Post Code");  
                                END;  
                           OnLookup=BEGIN  
                                PostCode.LookUpPostCode(City,"Post Code",TRUE);  
                               END;  
                           ValidateTableRelation=No;  
                           TestTableRelation=No;  
                           CaptionML=ENU=Post Code }  
   { 31 ;  ;County       ;Text30    ;CaptionML=ENU=County }  
   { 32 ;  ;Ship-to Post Code  ;Code20    ;TableRelation="Post Code";  
                           OnValidate=BEGIN  
                                 PostCode.ValidatePostCode("Ship-to City","Ship-to Post Code");  
                                END;  
                           OnLookup=BEGIN  
                                PostCode.LookUpPostCode("Ship-to City","Ship-to Post Code",TRUE);  
                               END;  
                           ValidateTableRelation=No;  
                           TestTableRelation=No;  
                           CaptionML=ENU=Ship-to Post Code }  
   { 33 ;  ;Ship-to County   ;Text30    ;CaptionML=ENU=Ship-to County }  
   { 34 ;  ;E-Mail       ;Text80    ;ExtendedDatatype=E-Mail;  
                           CaptionML=ENU=E-Mail }  
   { 35 ;  ;Home Page      ;Text80    ;ExtendedDatatype=URL;  
                           CaptionML=ENU=Home Page }  
   { 36 ;  ;Country/Region Code ;Code10    ;TableRelation=Country/Region;  
                           CaptionML=ENU=Country/Region Code }  
   { 37 ;  ;Ship-to Country/Region Code;Code10 ;TableRelation=Country/Region;  
                           CaptionML=ENU=Ship-to Country/Region Code }  
   { 38 ;  ;IBAN        ;Code50    ;OnValidate=BEGIN  
                                 CheckIBAN(IBAN);  
                                END;  
                           CaptionML=ENU=IBAN }  
   { 39 ;  ;SWIFT Code     ;Code20    ;CaptionML=ENU=SWIFT Code }  
   { 40 ;  ;Industrial Classification;Text30  ;CaptionML=ENU=Industrial Classification }  
   { 41 ;  ;IC Partner Code   ;Code20    ;CaptionML=ENU=IC Partner Code }  
   { 42 ;  ;IC Inbox Type    ;Option    ;OnValidate=BEGIN  
                                 IF "IC Inbox Type" = "IC Inbox Type"::Database THEN  
                                  "IC Inbox Details" := '';  
                                END;  
                           CaptionML=ENU=IC Inbox Type;  
                           OptionCaptionML=ENU=File Location,Database;  
                           OptionString=File Location,Database }  
   { 43 ;  ;IC Inbox Details  ;Text250    ;OnLookup=VAR  
                                CmDlgMgt@1001 : Codeunit 412;  
                                i@1000 : Integer;  
                                FileName@1002 : Text[1024];  
                               BEGIN  
                                TESTFIELD("IC Partner Code");  
                                CASE "IC Inbox Type" OF  
                                 "IC Inbox Type"::"File Location":  
                                  BEGIN  
                                   IF "IC Inbox Details" = '' THEN BEGIN  
                                    FileName := STRSUBSTNO('%1.xml',"IC Partner Code");  
                                    "IC Inbox Details" := CmDlgMgt.OpenFile(Text001,FileName,4,'*.xml|*.xml',1)  
                                   END ELSE BEGIN  
                                    FileName := "IC Inbox Details" + STRSUBSTNO('\%1.xml',"IC Partner Code");  
                                    "IC Inbox Details" := CmDlgMgt.OpenFile(Text001,FileName,4,'*.xml|*.xml',1);  
                                   END;  
                                   IF STRLEN("IC Inbox Details") > 4 THEN BEGIN  
                                    i := STRLEN("IC Inbox Details") - 4;  
                                    WHILE (i > 1) AND ("IC Inbox Details"[i] <> '\') DO  
                                     i := i - 1;  
                                    IF i > 1 THEN  
                                     "IC Inbox Details" := COPYSTR("IC Inbox Details",1,i - 1);  
                                   END;  
                                  END;  
                                END;  
                               END;  
                           CaptionML=ENU=IC Inbox Details }  
   { 44 ;  ;Abbreviated Name  ;Text4     ;CaptionML=ENU=Abbreviated Name }  
   { 45 ;  ;Show Abbreviated Name;Boolean   ;CaptionML=ENU=Show Abbreviated Name }  
   { 5700;  ;Responsibility Center;Code10    ;TableRelation="Responsibility Center".Code;  
                           ValidateTableRelation=Yes;  
                           CaptionML=ENU=Responsibility Center }  
   { 5791;  ;Check-Avail. Period Calc.;DateFormula;  
                           CaptionML=ENU=Check-Avail. Period Calc. }  
   { 5792;  ;Check-Avail. Time Bucket;Option  ;CaptionML=ENU=Check-Avail. Time Bucket;  
                           OptionCaptionML=ENU=Day,Week,Month,Quarter,Year;  
                           OptionString=Day,Week,Month,Quarter,Year }  
   { 7600;  ;Base Calendar Code ;Code10    ;TableRelation="Base Calendar";  
                           CaptionML=ENU=Base Calendar Code }  
   { 7601;  ;Cal. Convergence Time Frame;DateFormula;  
                           InitValue=1Y;  
                           CaptionML=ENU=Cal. Convergence Time Frame }  
   { 50000; ;Session Available  ;Integer    }  
  }  
  KEYS  
  {  
   {  ;Primary Key               ;Clustered=Yes }  
  }  
  FIELDGROUPS  
  {  
  }  
  CODE  
  {  
   VAR  
    PostCode@1000 : Record 225;  
    Text000@1001 : TextConst 'ENU=The number you entered is not a valid IBAN.';  
    Text001@1002 : TextConst 'ENU=File Location for IC files';  
    Text002@1003 : TextConst 'ENU=Before you can use Online Map, you must fill in the Online Map Setup window.\See Setting Up Online Map in Help.';  
   PROCEDURE CheckIBAN@1(IBANCode@1000 : Code[100]);  
   VAR  
    Modulus97@1001 : Integer;  
    I@1002 : Integer;  
   BEGIN  
    IF IBANCode = '' THEN  
     EXIT;  
    IBANCode := DELCHR(IBANCode);  
    Modulus97 := 97;  
    IF (STRLEN(IBANCode) <= 5) OR (STRLEN(IBANCode) > 34) THEN  
     IBANError;  
    ConvertIBAN(IBANCode);  
    WHILE STRLEN(IBANCode) > 6 DO  
     IBANCode := CalcModulus(COPYSTR(IBANCode,1,6),Modulus97) + COPYSTR(IBANCode,7);  
    EVALUATE(I,IBANCode);  
    IF (I MOD Modulus97) <> 1 THEN  
     IBANError;  
   END;  
   LOCAL PROCEDURE ConvertIBAN@4(VAR IBANCode@1000 : Code[100]);  
   VAR  
    I@1002 : Integer;  
   BEGIN  
    IBANCode := COPYSTR(IBANCode,5) + COPYSTR(IBANCode,1,4);  
    I := 0;  
    WHILE I < STRLEN(IBANCode) DO BEGIN  
     I := I + 1;  
     IF ConvertLetter(IBANCode,COPYSTR(IBANCode,I,1),I) THEN  
      I := 0;  
    END;  
   END;  
   LOCAL PROCEDURE CalcModulus@3(Number@1000 : Code[10];Modulus97@1001 : Integer) : Code[10];  
   VAR  
    I@1002 : Integer;  
   BEGIN  
    EVALUATE(I,Number);  
    I := I MOD Modulus97;  
    IF I = 0 THEN  
     EXIT('');  
    EXIT(FORMAT(I));  
   END;  
   LOCAL PROCEDURE ConvertLetter@5(VAR IBANCode@1000 : Code[100];Letter@1001 : Code[1];LetterPlace@1002 : Integer) : Boolean;  
   VAR  
    Letter2@1003 : Code[2];  
   BEGIN  
    IF (Letter >= 'A') AND (Letter <= 'Z') THEN BEGIN  
     CASE Letter OF  
      'A': Letter2 := '10';  
      'B': Letter2 := '11';  
      'C': Letter2 := '12';  
      'D': Letter2 := '13';  
      'E': Letter2 := '14';  
      'F': Letter2 := '15';  
      'G': Letter2 := '16';  
      'H': Letter2 := '17';  
      'I': Letter2 := '18';  
      'J': Letter2 := '19';  
      'K': Letter2 := '20';  
      'L': Letter2 := '21';  
      'M': Letter2 := '22';  
      'N': Letter2 := '23';  
      'O': Letter2 := '24';  
      'P': Letter2 := '25';  
      'Q': Letter2 := '26';  
      'R': Letter2 := '27';  
      'S': Letter2 := '28';  
      'T': Letter2 := '29';  
      'U': Letter2 := '30';  
      'V': Letter2 := '31';  
      'W': Letter2 := '32';  
      'X': Letter2 := '33';  
      'Y': Letter2 := '34';  
      'Z': Letter2 := '35';  
     END;  
     IF LetterPlace = 1 THEN  
      IBANCode := Letter2 + COPYSTR(IBANCode,2)  
     ELSE BEGIN  
      IF LetterPlace = STRLEN(IBANCode) THEN  
       IBANCode := COPYSTR(IBANCode,1,LetterPlace - 1) + Letter2  
      ELSE  
       IBANCode :=  
        COPYSTR(IBANCode,1,LetterPlace - 1) + Letter2 + COPYSTR(IBANCode,LetterPlace + 1);  
     END;  
     EXIT(TRUE);  
    END;  
    IF (Letter >= '0') AND (Letter <= '9') THEN  
     EXIT(FALSE);  
    IBANError;  
   END;  
   LOCAL PROCEDURE IBANError@12();  
   BEGIN  
    ERROR(Text000);  
   END;  
   PROCEDURE DisplayMap@7();  
   VAR  
    MapPoint@1001 : Record 800;  
    MapMgt@1000 : Codeunit 802;  
   BEGIN  
    IF MapPoint.FIND('-') THEN  
     MapMgt.MakeSelection(DATABASE::"Company Information",GETPOSITION)  
    ELSE MESSAGE(Text002);  
   END;  
   BEGIN  
   END.  
  }  
 }  
 OBJECT Form 1 Company Information  
 {  
  OBJECT-PROPERTIES  
  {  
   Date=14-10-25;  
   Time=[ 3:30:36 PM];  
   Modified=Yes;  
   Version List=NAVW16.00;  
  }  
  PROPERTIES  
  {  
   Width=16170;  
   Height=8140;  
   CaptionML=ENU=Company Information;  
   InsertAllowed=No;  
   DeleteAllowed=No;  
   SourceTable=Table79;  
   OnOpenForm=VAR  
          MapMgt@1000 : Codeunit 802;  
         BEGIN  
          RESET;  
          IF NOT GET THEN BEGIN  
           INIT;  
           INSERT;  
          END;  
          IF NOT MapMgt.TestSetup THEN  
           CurrForm.MapPoint.VISIBLE(FALSE);  
         END;  
  }  
  CONTROLS  
  {  
   { 1  ;TabControl  ;220 ;220 ;15730;6930 ;HorzGlue=Both;  
                          VertGlue=Both;  
                          PageNamesML=ENU=General,Communication,Payments,Shipping, User Session }  
   { 2  ;TextBox   ;3850 ;990 ;5500 ;440 ;ParentControl=1;  
                          InPage=0;  
                          SourceExpr=Name }  
   { 3  ;Label    ;440 ;990 ;3300 ;440 ;ParentControl=2;  
                          InPage=0 }  
   { 4  ;TextBox   ;3850 ;1540 ;5500 ;440 ;ParentControl=1;  
                          InPage=0;  
                          SourceExpr=Address }  
   { 5  ;Label    ;440 ;1540 ;3300 ;440 ;ParentControl=4;  
                          InPage=0 }  
   { 6  ;TextBox   ;3850 ;2090 ;5500 ;440 ;ParentControl=1;  
                          InPage=0;  
                          SourceExpr="Address 2" }  
   { 7  ;Label    ;440 ;2090 ;3300 ;440 ;ParentControl=6;  
                          InPage=0 }  
   { 10 ;TextBox   ;3850 ;3850 ;2750 ;440 ;ParentControl=1;  
                          InPage=0;  
                          SourceExpr="Phone No." }  
   { 11 ;Label    ;440 ;3850 ;3300 ;440 ;ParentControl=10;  
                          InPage=0 }  
   { 14 ;TextBox   ;3850 ;4510 ;2750 ;440 ;ParentControl=1;  
                          InPage=0;  
                          SourceExpr="VAT Registration No." }  
   { 15 ;Label    ;440 ;4510 ;3300 ;440 ;ParentControl=14;  
                          InPage=0 }  
   { 33 ;PictureBox  ;9570 ;990 ;6160 ;3960 ;HorzGlue=Both;  
                          VertGlue=Both;  
                          ParentControl=1;  
                          InPage=0;  
                          SourceExpr=Picture }  
   { 8  ;TextBox   ;6710 ;2640 ;2640 ;440 ;ParentControl=1;  
                          InPage=0;  
                          NextControl=42;  
                          SourceExpr=City }  
   { 34 ;TextBox   ;3850 ;2640 ;2750 ;440 ;ParentControl=1;  
                          InPage=0;  
                          NextControl=8;  
                          SourceExpr="Post Code" }  
   { 46 ;Label    ;440 ;2640 ;3300 ;440 ;ParentControl=34;  
                          CaptionML=ENU=Post Code/City }  
   { 42 ;TextBox   ;3850 ;3190 ;2750 ;440 ;ParentControl=1;  
                          InPage=0;  
                          SourceExpr="Country/Region Code" }  
   { 45 ;Label    ;440 ;3190 ;3300 ;440 ;ParentControl=42 }  
   { 76 ;TextBox   ;3850 ;5170 ;2750 ;440 ;ParentControl=1;  
                          InPage=0;  
                          SourceExpr="Industrial Classification" }  
   { 77 ;Label    ;440 ;5170 ;3300 ;440 ;ParentControl=76 }  
   { 86 ;CommandButton;6710 ;3190 ;440 ;440 ;Name=MapPoint;  
                          ParentControl=1;  
                          InPage=0;  
                          ShowCaption=No;  
                          Bitmap=53;  
                          ToolTipML=ENU=Display Map;  
                          OnPush=BEGIN  
                              DisplayMap;  
                             END;  
                              }  
   { 87 ;TextBox   ;3850 ;5830 ;1320 ;440 ;ParentControl=1;  
                          InPage=0;  
                          SourceExpr="Abbreviated Name" }  
   { 88 ;Label    ;440 ;5830 ;3300 ;440 ;ParentControl=87 }  
   { 89 ;CheckBox   ;3850 ;6380 ;440 ;440 ;ParentControl=1;  
                          InPage=0;  
                          ShowCaption=No;  
                          SourceExpr="Show Abbreviated Name" }  
   { 90 ;Label    ;440 ;6380 ;3300 ;440 ;ParentControl=89 }  
   { 50 ;TextBox   ;3850 ;990 ;2750 ;440 ;ParentControl=1;  
                          InPage=1;  
                          SourceExpr="Phone No." }  
   { 53 ;Label    ;440 ;990 ;3300 ;440 ;ParentControl=50 }  
   { 54 ;TextBox   ;3850 ;1540 ;2750 ;440 ;ParentControl=1;  
                          InPage=1;  
                          SourceExpr="Fax No." }  
   { 55 ;Label    ;440 ;1540 ;3300 ;440 ;ParentControl=54 }  
   { 56 ;TextBox   ;3850 ;2200 ;2750 ;440 ;ParentControl=1;  
                          InPage=1;  
                          SourceExpr="E-Mail" }  
   { 57 ;Label    ;440 ;2200 ;3300 ;440 ;ParentControl=56 }  
   { 58 ;TextBox   ;3850 ;2750 ;2750 ;440 ;ParentControl=1;  
                          InPage=1;  
                          SourceExpr="Home Page" }  
   { 59 ;Label    ;440 ;2750 ;3300 ;440 ;ParentControl=58 }  
   { 9  ;CommandButton;6710 ;2750 ;440 ;440 ;ParentControl=1;  
                          InPage=1;  
                          ShowCaption=No;  
                          Bitmap=20;  
                          ToolTipML=ENU=Hyperlink;  
                          OnPush=BEGIN  
                              TESTFIELD("Home Page");  
                              HYPERLINK("Home Page");  
                             END;  
                              }  
   { 12 ;CommandButton;6710 ;2200 ;440 ;440 ;ParentControl=1;  
                          InPage=1;  
                          ShowCaption=No;  
                          Bitmap=21;  
                          ToolTipML=ENU=New Mail Message;  
                          OnPush=BEGIN  
                              Mail.OpenNewMessage("E-Mail");  
                             END;  
                              }  
   { 78 ;TextBox   ;3850 ;3410 ;2750 ;440 ;ParentControl=1;  
                          InPage=1;  
                          SourceExpr="IC Partner Code" }  
   { 79 ;Label    ;440 ;3410 ;3300 ;440 ;ParentControl=78 }  
   { 80 ;TextBox   ;3850 ;3960 ;2750 ;440 ;ParentControl=1;  
                          InPage=1;  
                          SourceExpr="IC Inbox Type" }  
   { 81 ;Label    ;440 ;3960 ;3300 ;440 ;ParentControl=80 }  
   { 82 ;TextBox   ;3850 ;4510 ;5500 ;440 ;ParentControl=1;  
                          InPage=1;  
                          SourceExpr="IC Inbox Details" }  
   { 83 ;Label    ;440 ;4510 ;3300 ;440 ;ParentControl=82 }  
   { 16 ;TextBox   ;3850 ;990 ;5500 ;440 ;ParentControl=1;  
                          InPage=2;  
                          SourceExpr="Bank Name" }  
   { 17 ;Label    ;440 ;990 ;3300 ;440 ;ParentControl=16 }  
   { 22 ;TextBox   ;3850 ;2640 ;2750 ;440 ;ParentControl=1;  
                          InPage=2;  
                          SourceExpr="Payment Routing No." }  
   { 23 ;Label    ;440 ;2640 ;3300 ;440 ;ParentControl=22 }  
   { 24 ;TextBox   ;3850 ;3300 ;2750 ;440 ;ParentControl=1;  
                          InPage=2;  
                          SourceExpr="Giro No." }  
   { 25 ;Label    ;440 ;3300 ;3300 ;440 ;ParentControl=24 }  
   { 20 ;TextBox   ;3850 ;2090 ;2750 ;440 ;ParentControl=1;  
                          InPage=2;  
                          SourceExpr="Bank Account No." }  
   { 21 ;Label    ;440 ;2090 ;3300 ;440 ;ParentControl=20 }  
   { 18 ;TextBox   ;3850 ;1540 ;2750 ;440 ;ParentControl=1;  
                          InPage=2;  
                          SourceExpr="Bank Branch No." }  
   { 19 ;Label    ;440 ;1540 ;3300 ;440 ;ParentControl=18 }  
   { 72 ;TextBox   ;3850 ;3960 ;2750 ;440 ;ParentControl=1;  
                          InPage=2;  
                          SourceExpr="SWIFT Code" }  
   { 73 ;Label    ;440 ;3960 ;3300 ;440 ;ParentControl=72 }  
   { 74 ;TextBox   ;3850 ;4510 ;5500 ;440 ;ParentControl=1;  
                          InPage=2;  
                          SourceExpr=IBAN }  
   { 75 ;Label    ;440 ;4510 ;3300 ;440 ;ParentControl=74 }  
   { 47 ;TextBox   ;12980;990 ;2750 ;440 ;ParentControl=1;  
                          InPage=3;  
                          SourceExpr="Location Code" }  
   { 48 ;Label    ;9570 ;990 ;3300 ;440 ;ParentControl=47 }  
   { 35 ;TextBox   ;3850 ;990 ;5500 ;440 ;ParentControl=1;  
                          InPage=3;  
                          SourceExpr="Ship-to Name" }  
   { 36 ;Label    ;440 ;990 ;3300 ;440 ;ParentControl=35 }  
   { 37 ;TextBox   ;3850 ;1540 ;5500 ;440 ;ParentControl=1;  
                          InPage=3;  
                          SourceExpr="Ship-to Address" }  
   { 38 ;Label    ;440 ;1540 ;3300 ;440 ;ParentControl=37 }  
   { 39 ;TextBox   ;3850 ;2090 ;5500 ;440 ;ParentControl=1;  
                          InPage=3;  
                          SourceExpr="Ship-to Address 2" }  
   { 40 ;Label    ;440 ;2090 ;3300 ;440 ;ParentControl=39 }  
   { 43 ;TextBox   ;3850 ;3850 ;5500 ;440 ;ParentControl=1;  
                          InPage=3;  
                          SourceExpr="Ship-to Contact" }  
   { 44 ;Label    ;440 ;3850 ;3300 ;440 ;ParentControl=43 }  
   { 49 ;TextBox   ;6710 ;2640 ;2640 ;440 ;ParentControl=1;  
                          InPage=3;  
                          NextControl=60;  
                          SourceExpr="Ship-to City" }  
   { 51 ;TextBox   ;3850 ;2640 ;2750 ;440 ;ParentControl=1;  
                          InPage=3;  
                          NextControl=49;  
                          SourceExpr="Ship-to Post Code" }  
   { 52 ;Label    ;440 ;2640 ;3300 ;440 ;ParentControl=51;  
                          CaptionML=ENU=Ship-to Post Code/City }  
   { 13 ;TextBox   ;12980;1540 ;2750 ;440 ;ParentControl=1;  
                          InPage=3;  
                          SourceExpr="Responsibility Center" }  
   { 41 ;Label    ;9570 ;1540 ;3300 ;440 ;ParentControl=13 }  
   { 60 ;TextBox   ;3850 ;3190 ;2750 ;440 ;ParentControl=1;  
                          InPage=3;  
                          SourceExpr="Ship-to Country/Region Code" }  
   { 61 ;Label    ;440 ;3190 ;3300 ;440 ;ParentControl=60 }  
   { 62 ;TextBox   ;12980;2090 ;2750 ;440 ;ParentControl=1;  
                          InPage=3;  
                          SourceExpr="Check-Avail. Period Calc." }  
   { 63 ;Label    ;9570 ;2090 ;3300 ;440 ;ParentControl=62 }  
   { 64 ;TextBox   ;12980;2640 ;2750 ;440 ;ParentControl=1;  
                          InPage=3;  
                          SourceExpr="Check-Avail. Time Bucket" }  
   { 65 ;Label    ;9570 ;2640 ;3300 ;440 ;ParentControl=64 }  
   { 67 ;TextBox   ;12980;3190 ;2750 ;440 ;ParentControl=1;  
                          InPage=3;  
                          DrillDown=No;  
                          SourceExpr="Base Calendar Code" }  
   { 68 ;Label    ;9570 ;3190 ;3300 ;440 ;ParentControl=67 }  
   { 69 ;TextBox   ;12980;3740 ;1700 ;440 ;Name=Customized Calendar;  
                          Editable=No;  
                          ParentControl=1;  
                          InPage=3;  
                          DrillDown=Yes;  
                          CaptionML=ENU=Customized Calendar;  
                          SourceExpr=CalendarMgmt.CustomizedCalendarExistText(CustomizedCalendar."Source Type"::Company,'','',"Base Calendar Code");  
                          OnDrillDown=BEGIN  
                                 CurrForm.SAVERECORD;  
                                 TESTFIELD("Base Calendar Code");  
                                 CalendarMgmt.ShowCustomizedCalendar(CustomizedCalEntry."Source Type"::Company,'','',"Base Calendar Code");  
                                END;  
                                }  
   { 71 ;Label    ;9790 ;3740 ;3080 ;440 ;ParentControl=69;  
                          InPage=3;  
                          CaptionML=ENU=Customized Calendar }  
   { 84 ;TextBox   ;12980;4290 ;1700 ;440 ;ParentControl=1;  
                          InPage=3;  
                          SourceExpr="Cal. Convergence Time Frame" }  
   { 85 ;Label    ;9570 ;4290 ;3300 ;440 ;ParentControl=84 }  
   { 1000000004;TextBox;3850 ;1320 ;1700 ;440 ;ParentControl=1;  
                          InPage=4;  
                          SourceExpr="Session Available" }  
   { 1000000005;Label ;440 ;1320 ;3300 ;440 ;ParentControl=1000000004 }  
   { 26 ;CommandButton;4070 ;7370 ;2200 ;550 ;HorzGlue=Right;  
                          VertGlue=Bottom;  
                          Default=Yes;  
                          PushAction=LookupOK;  
                          InvalidActionAppearance=Hide }  
   { 27 ;CommandButton;6490 ;7370 ;2200 ;550 ;HorzGlue=Right;  
                          VertGlue=Bottom;  
                          Cancel=Yes;  
                          PushAction=LookupCancel;  
                          InvalidActionAppearance=Hide }  
   { 28 ;MenuButton  ;11330;7370 ;2200 ;550 ;HorzGlue=Right;  
                          VertGlue=Bottom;  
                          CaptionML=ENU=&Picture;  
                          Menu=MENUITEMS  
                          {  
                           { ID=29;  
                            Ellipsis=Yes;  
                            CaptionML=ENU=Import;  
                            OnPush=BEGIN  
                                PictureExists := Picture.HASVALUE;  
                                IF Picture.IMPORT('*.BMP',TRUE) = '' THEN  
                                 EXIT;  
                                IF PictureExists THEN  
                                 IF NOT CONFIRM(Text001,FALSE) THEN  
                                  EXIT;  
                                CurrForm.SAVERECORD;  
                               END;  
                                }  
                           { ID=30;  
                            Ellipsis=Yes;  
                            CaptionML=ENU=E&xport;  
                            OnPush=BEGIN  
                                IF Picture.HASVALUE THEN  
                                 Picture.EXPORT('*.BMP',TRUE);  
                               END;  
                                }  
                           { ID=31;  
                            CaptionML=ENU=Delete;  
                            OnPush=BEGIN  
                                IF Picture.HASVALUE THEN  
                                 IF CONFIRM(Text002,FALSE) THEN BEGIN  
                                  CLEAR(Picture);  
                                  CurrForm.SAVERECORD;  
                                 END;  
                               END;  
                                }  
                          }  
                          }  
   { 32 ;CommandButton;13750;7370 ;2200 ;550 ;HorzGlue=Right;  
                          VertGlue=Bottom;  
                          PushAction=FormHelp }  
   { 66 ;MenuButton  ;8910 ;7370 ;2200 ;550 ;HorzGlue=Right;  
                          VertGlue=Bottom;  
                          CaptionML=ENU=&Company;  
                          Menu=MENUITEMS  
                          {  
                           { ID=70;  
                            PushAction=RunObject;  
                            CaptionML=ENU=Responsibility Centers;  
                            RunObject=Form 5714 }  
                           { ID=91;  
                            MenuItemType=Separator }  
                           { ID=92;  
                            CaptionML=ENU=Online Map;  
                            OnPush=BEGIN  
                                DisplayMap;  
                               END;  
                                }  
                          }  
                          }  
  }  
  CODE  
  {  
   VAR  
    Text001@1000 : TextConst 'ENU=Do you want to replace the existing picture?';  
    Text002@1001 : TextConst 'ENU=Do you want to delete the picture?';  
    CustomizedCalEntry@1007 : Record 7603;  
    CustomizedCalendar@1005 : Record 7602;  
    CalendarMgmt@1004 : Codeunit 7600;  
    Mail@1002 : Codeunit 397;  
    PictureExists@1003 : Boolean;  
   BEGIN  
   END.  
  }  
 }  
 OBJECT Codeunit 50096 Session Management  
 {  
  OBJECT-PROPERTIES  
  {  
   Date=14-08-05;  
   Time=[ 5:06:04 PM];  
   Modified=Yes;  
   Version List=;  
  }  
  PROPERTIES  
  {  
   OnRun=BEGIN  
       //checkSession;  
      END;  
  }  
  CODE  
  {  
   PROCEDURE checkSession@1000000001() loginAllowed : Boolean;  
   VAR  
    recSessions01@1000000000 : Record 2000000009;  
    recSessions02@1000000001 : Record 2000000009;  
    WindowsShell@1000000002 : Automation "{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B} 1.0:{72C24DD5-D70A-438B-8A42-98424B88AFB8}:'Windows Script Host Object Model'.WshShell";  
    recCompany@1000000003 : Record 79;  
    recDatabase@1000000004 : Record 2000000048;  
    dbName@1000000005 : Text[30];  
   BEGIN  
    recDatabase.RESET;  
    recDatabase.SETFILTER(recDatabase."My Database",'%1',TRUE);  
    IF recDatabase.FINDFIRST THEN BEGIN  
      dbName := recDatabase."Database Name";  
    END;  
    loginAllowed := TRUE;  
    recSessions01.RESET;  
    recSessions01.SETFILTER(recSessions01."User ID",'<>%1','sa');  
    recSessions01.SETRANGE(recSessions01."Database Name",'%1',dbName);  
    recCompany.RESET;  
    IF recCompany.FINDFIRST THEN BEGIN  
      IF recSessions01.COUNT > recCompany."Session Available" THEN BEGIN  
       IF CONFIRM ('Available login sessions have been exceeded',FALSE,FALSE) THEN BEGIN  
         CREATE(WindowsShell);  
         WindowsShell.SendKeys('%{F4}');  
         CLEAR(WindowsShell);  
       END ELSE BEGIN  
         CREATE(WindowsShell);  
         WindowsShell.SendKeys('%{F4}');  
         CLEAR(WindowsShell);  
       END;  
      END;  
    END;  
   END;  
   BEGIN  
   END.  
  }  
 }  

Import this codeunit and other objects and then compile. 

Go to company information form and set the number of active users you want to have for your company and then go to Codeunit 01 and then modify it to call the "checkSession" function for every new loggin. Compile and save the code. 

So from next loggin this would work and if the number of set users are exceed with the current active users, then that loggin will not go through and will result in closing the application automatically. 

Setting number of active users in company information table will not do work because then client can change it anytime he want. I think you can figure out a way to avoid that or to modify this code accordingly. 

Thank you and Regards,
Tharanga Chandrasekara


No comments:

Post a Comment