BpcSMScriptLibrary 8

From RiskWiki
Jump to: navigation, search

bpcXML Data Transfer Utility Routines

Language: Delphi 7 - 2007


//////////////////////////////////////////////////////////////////////////////////////////
//////// bpcXML Data Transfer Utility Routines. Uses TbpcPublicationManager object.
//////////////////////////////////////////////////////////////////////////////////////////

interface
uses windows, SysUtils, Classes, JvComponent, JvDirectories, Types, DB, ADODB, Psock, NMsmtp, DBGrids, HTTPApp, HTTPProd,
  NMHttp, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP, xmldom, XMLIntf, msxmldom, XMLDoc, {JvBaseDlg,} IdAuthentication, bpcDBBookMarkList,
  LMDCustomComponent, lmdcont, bpcSMScriptLibrary_7;

type
  TbpcsmDSMapperfunc= function( const sDataSetName: string): string of object;
  TbpcSMConfirmOk = Function( var myResult : variant ) : integer of object;
  TbpcSMSTPMode=(bpcSMUpdate,bpcSMReplace,bpcSMDelete);
  TbpcHTTPSuccess =  procedure (Cmd: CmdType) of object;
  TbpcValidfunc = function (sOID, sPID: string): string;
  TbpcGetPSTTableMasterIndex = function ( Sender: TDataSet ) : string;
{
  TGovDupFlags = ( csmHeader, csmQuestionsByRef, csmQuestionsByAct, csmScripts, csmInstances );
  TGovDupFlagsSet = set of TGovDupFlags;
  TGovMaintHTTPSuccess =  procedure (Cmd: CmdType) of object;
  TGovMaintUpdateStatusBar = procedure of object;
  TGovMaintConfirmOk = Function( var myResult : variant ) : integer of object;
  TGovMaintWSLoginDlg = Function( var Username : string; var PassWord : string ) : boolean of object;
  TGovMaintInfoErrorAdvice = procedure( myAdvice : string ) of object;
}

  TbpcPublicationManager = class(TObject)
  private
    funUplinkFail: TbpcHTTPSuccess;
    funUplinkComplete: TbpcHTTPSuccess;
    Activated : boolean;
    funGetTargetDLLModuleName: TSimpleStringFunc;
    function DummyValidateSMAccess(sOID, sPID: string): string;
  public
    Owner : TDataModule;
    ADOConnection1: TADOConnection;
    funDataSetMapperFunc, funOutGoingDataSetMapperFunc : TbpcsmDSMapperfunc;
    funValidateAccess : TbpcValidfunc;
    funGetTableMasterIndex : TbpcGetPSTTableMasterIndex;
    funGetOrgID, funGetPID : TSimpleStringFunc;
    ConfirmOkFunc : TbpcSMConfirmOk;
    PreviewCommsPackets : boolean;
    iniURLDefPublicationSite : string;
    {TargetDLLModuleName,} TargetModuleExt, TargetModuleAction  : string;
    tsDataSetIndexes : TStrings;

    IdHTTP1 : TIdHTTP;
    XMLDocument1 : TXMLDocument;

    constructor create(myOwner : TDataModule;  myADOConnection: TADOConnection; myDataSetMapperFunc, myOutGoingDataSetMapperFunc : TbpcsmDSMapperfunc; myConfirmOkFunc : TbpcSMConfirmOk );
    destructor destroy;

    function GetActive : boolean;
    procedure SetActive( value : boolean );
    function DataSetMapperFunc( const sDataSetName : string ) : string ;
    function OutGoingDataSetMapperFunc( const sDataSetName : string ) : string ;
    // Send the current row or all rows of the sender dataset to the URL (or if URL is ommitted, the iniURLDefPublicationSite)
    // Defaults the destination to ''.
    // bpcBookMarks is an alternative to BookMarks (the latter requiring a grid, while the former does not). If both are set, BookMarks are used.
    function SendToPubServer( indexby : string; singleonly:boolean; sendingDS : TDataSet; publishto : string; BookMarks : TBookmarklist=nil; bpcBookMarks : TbpcBookmarkList=nil ): string; overload;
    // Send the current row or all rows of the sender dataset to the URL (or if URL is ommitted, the iniURLDefPublicationSite)
    // bpcBookMarks is an alternative to BookMarks (the latter requiring a grid, while the former does not). If both are set, BookMarks are used.
    // If Confirmer is assigned, the associated TSurvMaintConfirmOk routine will be called before the XML packet is dispatched.
    function SendToPubServer( confirmer: TbpcSMConfirmOk ;destination, indexby : string; singleonly:boolean; sendastable:boolean; sendermode: TbpcSMSTPMode; DelFilter: string; sendingDS : TDataSet; publishto : string; BookMarks : TBookmarklist=nil; bpcBookMarks : TbpcBookmarkList=nil ) : string; overload;
    // Send the current row or all rows of the sender dataset to the URL (or if URL is ommitted, the iniURLDefPublicationSite)
    // bpcBookMarks is an alternative to BookMarks (the latter requiring a grid, while the former does not). If both are set, BookMarks are used.
    function  SendToPubServer( destination, indexby : string; singleonly:boolean; sendastable:boolean; sendermode: TbpcSMSTPMode; DelFilter: string; sendingDS : TDataSet; publishto : string; BookMarks : TBookmarklist=nil; bpcBookMarks : TbpcBookmarkList=nil ): string; overload;
    function  SendToPubServer( destination, indexby : string; singleonly:boolean; sendastable:boolean; sendingDS : TDataSet; publishto : string; BookMarks : TBookmarklist=nil; bpcBookMarks : TbpcBookmarkList=nil ) : string; overload;
    // Send the all rows of the sending qry (named sourceQryName, or if '' named destination) to the URL (or if URL is ommitted, the iniURLDefPublicationSite)
    function SendToPubServer( destination, indexby : string; singleonly:boolean; sendastable:boolean; sendermode: TbpcSMSTPMode; DelFilter: string; sourceQryName, sendingQry : string; publishto : string ) : string; overload;
    // Send the all rows of the sending qry (named sourceQryName, or if '' named destination) to the URL (or if URL is ommitted, the iniURLDefPublicationSite)
    // If Confirmer is assigned, the associated TGovMaintConfirmOk routine will be called before the XML packet is dispatched.
    function SendToPubServer( confirmer: TbpcSMConfirmOk ;destination, indexby : string; singleonly:boolean; sendastable:boolean;  sendermode: TbpcSMSTPMode; DelFilter: string; sourceQryName, sendingQry : string; publishto : string ) : string; overload;
    // Send the all rows of the sending qry (named sourceQryName, or if '' named destination) to the URL (or if URL is ommitted, the iniURLDefPublicationSite)
    // If Confirmer is assigned, the associated TGovMaintConfirmOk routine will be called before the XML packet is dispatched.
    // Assumes the sendermode (not present in this version) is the Update (ie. NOT replace mode)
    function SendToPubServer( confirmer: TbpcSMConfirmOk ;destination, indexby : string; singleonly:boolean; sendastable:boolean;  sourceQryName, sendingQry : string; publishto : string ) : string; overload;
    procedure GetFromPubServer(indexby, returnindexby : string; singleonly:boolean; sendingDS : TDataSet; publishto : string ; BookMarks : TBookmarklist=nil; bpcBookMarks : TbpcBookmarkList=nil);
    procedure GetSimpleFromPubServer(indexby, returnindexby : string; singleonly:boolean; sendingDS : TDataSet; publishto : string; myParams : Variant );
    // Return the index for the dataset (only some known datasets covered)
    function GetTableMasterIndex( Sender: TDataSet ) : string;
    // Send the current row or all rows of the sender dataset to the URL (or if URL is ommitted, the iniURLDefPublicationSite)
    // The correct index will be found in the DataSetIndexes StringList and matched with the dataset prior to sending.
    procedure IndexedSendToPubServer( SingleOnly: boolean; Sender: TDataSet; URL : string=''; BookMarks : TBookmarklist=nil; bpcBookMarks : TbpcBookmarkList=nil );   Overload;
    // Get the current row or all rows of the sender dataset from the URL (or if URL is ommitted, the iniURLDefPublicationSite)
    // The correct index will be found in the DataSetIndexes StringList and matched with the dataset prior to sending.
    procedure IndexedGetFromPubServer( SingleOnly: boolean; Sender: TDataSet; URL : string=''; BookMarks : TBookmarklist=nil; bpcBookMarks : TbpcBookmarkList=nil);   Overload;
    // Send the current row or all rows of the sender dataset to the URL (or if URL is ommitted, the iniURLDefPublicationSite)
    // The correct index will be found in the provided myTableIndexes StringList and matched with the dataset prior to sending.
    procedure IndexedSendToPubServer(myTableIndexes : TStrings; SingleOnly: boolean; Sender: TDataSet; URL : string=''; BookMarks : TBookmarklist=nil; bpcBookMarks : TbpcBookmarkList=nil);   Overload;
    // Get the current row or all rows of the sender dataset from the URL (or if URL is ommitted, the iniURLDefPublicationSite)
    // The correct index will be found in the provided myTableIndexes StringList and matched with the dataset prior to sending.
    procedure IndexedGetFromPubServer(myTableIndexes : TStrings; SingleOnly: boolean; Sender: TDataSet; URL : string=''; BookMarks : TBookmarklist=nil; bpcBookMarks : TbpcBookmarkList=nil);  Overload;

    property OnGetOrgID : TSimpleStringFunc read funGetOrgID write funGetOrgID;
    property OnGetPID : TSimpleStringFunc read funGetPID write funGetPID;
    property Active : boolean read GetActive write SetActive;
    property EnableCommsPreview : boolean read PreviewCommsPackets write PreviewCommsPackets;
    property PublicationSite : string read iniURLDefPublicationSite write iniURLDefPublicationSite;
    property OnGetTargetDLL : TSimpleStringFunc read funGetTargetDLLModuleName write funGetTargetDLLModuleName;
    property TargetAction : string read TargetModuleAction write TargetModuleAction;
    property TargetExt : string read TargetModuleExt write TargetModuleExt;
    property IdHTTP : TIdHTTP read IdHTTP1 write IdHTTP1;
    property DataSetIndexes : TStrings read tsDataSetIndexes  write tsDataSetIndexes;
    property OnValidateAccess : TbpcValidfunc read funValidateAccess write funValidateAccess;
    property OnConfirmOkFunc : TbpcSMConfirmOk read ConfirmOkFunc write ConfirmOkFunc;
    property OnGetTableMasterIndex : TbpcGetPSTTableMasterIndex read funGetTableMasterIndex write funGetTableMasterIndex;
    property OnOutGoingDataSetMapper : TbpcsmDSMapperfunc read funOutGoingDataSetMapperFunc write funOutGoingDataSetMapperFunc;
    property OnDataSetMapper : TbpcsmDSMapperfunc read funDataSetMapperFunc write funDataSetMapperFunc;
    property OnUpLinkComplete : TbpcHTTPSuccess read funUplinkComplete write funUplinkComplete;
    property OnUpLinkFail : TbpcHTTPSuccess read funUplinkFail write funUplinkFail;
  end;

BackLinks