Form VL_SAM098: Using MS Word to Batch Documents and HTML Pages

LANSA

Form VL_SAM098: Using MS Word to Batch Documents and HTML Pages
* ===================================================================
*
* Component : VL_SAM098
* Type : Form
* Ancestor : PRIM_FORM
*
* Description : Using MS Word to Batch Documents and HTML pages
* The following RDMLX form is used to demonstrate how MS Word can be used
* from Visual LANSA applications.
*
* Disclaimer : The following material is supplied as sample material
* only. No warranty concerning this material or its use
* in any way whatsoever is expressed or implied.
*
* ===================================================================

FUNCTION OPTIONS(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Caption('MS Word - Batched Letter Examples') Formposition(ScreenCenter) Height(542) Layoutmanager(#ATLM_1) Left(568) Top(179) Width(326)
Define_Com Class(#PRIM_ATLM) Name(#ATLM_1)
Define_Com Class(#PRIM_ATLI) Name(#ATLI_1) Attachment(Left) Marginbottom(3) Marginleft(3) Marginright(3) Margintop(3) Parent(#ATLM_1)
Define_Com Class(#PRIM_LTVW) Name(#LTVW_1) Displayposition(4) Height(337) Left(0) Parent(#COM_OWNER) Tabposition(3) Top(53) Width(318)
Define_Com Class(#PRIM_ATLI) Name(#ATLI_2) Attachment(Center) Manage(#LTVW_1) Marginbottom(5) Margintop(5) Parent(#ATLM_1)
Define_Com Class(#PRIM_LVCL) Name(#LVCL_1) Caption('Number') Captiontype(Caption) Displayposition(1) Parent(#LTVW_1) Source(#EMPNO) Width(18)
Define_Com Class(#PRIM_LVCL) Name(#LVCL_2) Displayposition(2) Parent(#LTVW_1) Source(#GIVENAME) Width(40)
Define_Com Class(#PRIM_LVCL) Name(#LVCL_3) Displayposition(3) Parent(#LTVW_1) Source(#SURNAME) Width(20) Widthtype(Remainder)
Define_Com Class(#VL_SAM092) Name(#MSWORD) Displayposition(5) Left(16) Parent(#COM_OWNER) Tabstop(False) Top(8) Visible(False)
Define_Com Class(#STD_TEXT.Visual) Name(#WRITERNAM) Caption('Letters are to be signed by ') Displayposition(3) Height(19) Labeltype(Caption) Marginleft(128) Parent(#COM_OWNER) Tabposition(4) Top(29) Width(318)
Define_Com Class(#PRIM_ATLI) Name(#ATLI_3) Attachment(Top) Manage(#WRITERNAM) Margintop(5) Parent(#ATLM_1)
Define_Com Class(#PRIM_GPBX) Name(#GPBX_1) Caption('Batch MS Word Options') Displayposition(1) Height(93) Left(0) Parent(#COM_OWNER) Tabposition(5) Tabstop(False) Top(395) Width(318)
Define_Com Class(#PRIM_ATLI) Name(#ATLI_4) Attachment(Bottom) Manage(#GPBX_1) Marginbottom(5) Parent(#ATLM_1)
Define_Com Class(#PRIM_PHBN) Name(#RDBN_1) Caption('Print Salary Letters for Selected Employee(s)') Displayposition(2) Enabled(False) Left(13) Parent(#GPBX_1) Tabposition(1) Top(23) Width(297)
Define_Com Class(#PRIM_PHBN) Name(#RDBN_2) Caption('Create and Show a "Web Site" for Selected Employees') Displayposition(1) Enabled(False) Left(13) Parent(#GPBX_1) Tabposition(2) Top(55) Width(297)
Define_Com Class(#PRIM_ATLI) Name(#ATLI_5) Attachment(Bottom) Parent(#ATLM_1)
Define_Com Class(#STD_NUM.Visual) Name(#SHOWCOUNT) Caption('Total Selected Employees') Displayposition(2) Height(19) Labeltype(Caption) Marginleft(128) Parent(#COM_OWNER) Readonly(True) Tabposition(2) Top(5) Width(318)
Define_Com Class(#PRIM_ATLI) Name(#ATLI_6) Attachment(Top) Manage(#SHOWCOUNT) Margintop(5) Parent(#ATLM_1)
Define_Com Class(#PRIM_PGBR) Name(#BAR) Displayposition(6) Height(22) Left(0) Parent(#COM_OWNER) Tabposition(6) Top(493) Value(1) Visible(False) Width(318)
Define_Com Class(#PRIM_ATLI) Name(#ATLI_7) Attachment(Bottom) Manage(#BAR) Parent(#ATLM_1)

Define #SelEmpNo RefFld(#EmpNo)
Define #SelCount Reffld(#Std_Num)
Define #HtmFilNam *char 20
Def_List #Selected (#SelEmpNo #HtmFilNam #FullName) Type(*Working) Entrys(9999) Counter(#SelCount)
Def_Cond *Selected '#SelCount > 0'
Define #xx_count *dec 15 0
Define #xx_name *char 20
Define #FullDate *Char 20
Define #OSRc Reffld(#Std_Num)
Define #HomePage *char 50 Default('EmployeeHome.htm')
Def_list name(#skills) fields(#skilcode #SkilDesc #dateacqr #grade #comment #dateacq #gradedes) type(*working) Entrys(9999)

EVTROUTINE handling(#com_owner.Initialize)
Use Convertdate (*Datec a q) (#FullDate)
Select (#EmpNo #GiveName #SurName) From_File(PslMst)
Add_entry #LtVw_1
EndSelect
Set #WriterNam Value('John and Mary Doe')
ENDROUTINE

EVTROUTINE HANDLING(#Com_Owner.Closing)
Invoke #MSWord.CloseAllDoc Option(Discard)
Invoke #MSWord.CloseWord
ENDROUTINE

EVTROUTINE HANDLING(#LTVW_1.ItemGotSelection) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)
Loc_Entry #Selected where('#SelEmpNo = #Empno')
If_status Is_Not(*okay)
Change #SelEmpNo #EmpNo
Add_Entry #Selected
Endif
Set (#RdBn_1 #RdBn_2) Enabled(*Selected)
Set #ShowCount Value(#SelCount)
ENDROUTINE

EVTROUTINE HANDLING(#LTVW_1.ItemLostSelection) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)
Loc_Entry #Selected where('#SelEmpNo = #Empno')
If_status Is(*okay)
Dlt_Entry *Current #Selected
Endif
Set (#RdBn_1 #RdBn_2) Enabled(*Selected)
Set #ShowCount Value(#SelCount)
ENDROUTINE

EVTROUTINE HANDLING(#RDBN_1.Click)
Change #XX_Count 0
Set #Bar Value(0) MaximumValue(#SelCount) Visible(True)
* Get word started if not already running
Invoke #MSWord.OpenWord
Invoke #MSWord.MinimIzeForm
SelectList #Selected
Change #XX_Count '#XX_Count + 1'
Set #Bar Value(#XX_Count)
Fetch *all From_File(PslMst) With_Key(#SelEmpNo)
Use BConcat (#GiveName #SurName) (#FullName)
Invoke #MsWord.NewDoc Template(VL_SAM095)
Invoke #MsWord.InsertValues FromFields('writernam, mnthsal, salary, fulldate, fullname, address1, address2, address3, postcode, givename')
Invoke #MSWord.PrintDoc
Invoke #MSWord.CloseDoc Option(Discard)
EndSelect
Set #Bar Value(0) Visible(False)
ENDROUTINE

EVTROUTINE HANDLING(#RDBN_2.Click)
Change #XX_Count 0
Set #Bar Value(0) MaximumValue(#SelCount) Visible(True)
* Get Word started if not already running
Invoke #MSWord.OpenWord
Invoke #MSWord.MinimIzeForm
* Build the Employee Page(s)
SelectList #Selected
Change #XX_Count '#XX_Count + 1'
Set #Bar Value(#XX_Count)
Fetch *all From_File(PslMst) With_Key(#SelEmpNo)
Use BConcat (#GiveName #SurName) (#FullName)
Use TConcat (#Empno '.htm') (#HtmFilNam)
Clr_List #Skills
Select *all From_File(PslSkl) with_Key(#Empno)
Fetch #SkilDesc from_File(SklTab) With_Key(#SkilCode) Keep_Last(50)
Add_Entry #Skills
EndSelect
Invoke #MsWord.NewDoc Template(VL_SAM099)
Invoke #MsWord.InsertValues FromFields('writernam, fulldate, hl=homepage, fullname, address1, address2, address3, postcode,phonehme,phonebus')
Invoke #MsWord.InsertTable FromList(Skills) FromFields('Skilcode, skildesc,grade,comment ')
Invoke #MSWord.SaveDoc WithName(#HtmFilNam) InFormat(HTML)
Invoke #MSWord.CloseDoc Option(Discard)
Upd_Entry #Selected
EndSelect
* Now build the base directory page
Invoke #MsWord.NewDoc Template(VL_SAM100)
Invoke #MsWord.InsertValues FromFields('writernam, fulldate')
Invoke #MsWord.InsertTable FromList(Selected) FromFields('FullName, SelEmpNo, hl=HtmFilNam ')
Invoke #MSWord.SaveDoc WithName(#HomePage) InFormat(HTML)
Invoke #MSWord.CloseDoc Option(Discard)
Use System_Command (H #MSWord.LastFileSaved) (#OsRc)
Set #Bar Value(0) Visible(False)
ENDROUTINE

END_COM