Form S_153FC: Email Demonstration C

LANSA

Form S_153FC: Email Demonstration C
Name: S_153FC

Description: The following RDMLX form demonstrates various aspects of email integration and the use of resuable part S_153RML.
FUNCTION OPTIONS(*DIRECT);
BEGIN_COM FORMPOSITION(ScreenCenter) HEIGHT(100) WIDTH(596);
;
DEFINE_COM CLASS(#STD_TEXTL.Visual) NAME(#SEND_TO) CAPTION('Send to Email Address') DISPLAYPOSITION(1) LABELTYPE(Caption) LEFT(8) MARGINLEFT(120) PARENT(#COM_OWNER) TABPOSITION(1) TOP(16) WIDTH(465);
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#BTN_SEND) BUTTONDEFAULT(True) CAPTION('Send Email ') DISPLAYPOSITION(2) ENABLED(False) LEFT(496) PARENT(#COM_OWNER) TABPOSITION(2) TOP(12);
DEFINE_COM CLASS(#PRIM_STBR) NAME(#STBR_1) DISPLAYPOSITION(3) HEIGHT(22) LEFT(0) MESSAGEPOSITION(1) PARENT(#COM_OWNER) TABPOSITION(5) TABSTOP(False) TOP(51) WIDTH(588);
DEFINE_COM CLASS(#PRIM_PGBR) NAME(#PROGBAR) DISPLAYPOSITION(1) HEIGHT(16) LEFT(364) MAXIMUMVALUE(5) MINIMUMVALUE(0) PARENT(#STBR_1) TABPOSITION(1) TABSTOP(False) TOP(4) VALUE(0) VISUALSTYLE(#VS_GROUP) WIDTH(207);
;
DEFINE_COM CLASS(#S_152RHT) NAME(#HTML) DISPLAYPOSITION(5) PARENT(#COM_OWNER) TABPOSITION(4) VISIBLE(False);
DEFINE_COM CLASS(#S_153RML) NAME(#MAIL) DISPLAYPOSITION(4) LEFT(0) PARENT(#COM_OWNER) TABPOSITION(3) VISIBLE(False);
;
Define #HTMOutFil Type(*char) Length(100) ;
Define #XLSOutFil RefFld(#HTMOutFil);
Define #BRetCode Type(*Char) Length(2);
Define #RowCount RefFld(#Std_Num);
Def_List #EmpList (#EmpNo #GiveName #SurName #DeptDesc #SecDesc #Salary) Type(*Working) Entrys(9999);
Def_Cond *Recipient '#Send_To.Value *ne *blanks';
;
* ============================================================;
* Form Initialization;
* ============================================================;
;
EVTROUTINE handling(#com_owner.Initialize);
;
* Set / Initialize fields and components;
;
Set #Com_Owner Caption(*Component_Desc);
Set #ProgBar Value(0);
Use TConcat (*Temp_Dir *Component '.htm') (#HTMOutFil);
Use TConcat (*Temp_Dir *Component '.xls') (#XLSOutFil);
;
* Restore details of last email address used ;
;
Change #Send_To *Remembered_Value_For_User;
Set #Btn_Send Enabled(*Recipient);
;
* Fill up the employee working list with the required details;
;
Select (#EmpNo #GiveName #SurName #Deptment #Section #Salary) From_File(PslMst);
Fetch (#DeptDesc) From_File(DepTab) With_Key(#Deptment) Keep_Last(50);
Fetch (#SecDesc) From_File(SecTab) With_Key(#Deptment #Section) Keep_Last(50);
Add_Entry To_List(#EmpList);
EndSelect ;
;
ENDROUTINE ;
;
* ============================================================;
* Handle send email request;
* ============================================================;
;
EvtRoutine Handling(#BTN_SEND.Click);
;
* Define the HTML output table;
;
Set #ProgBar Value(1);
;
Invoke #HTML.DefineTable WithName(Emp) Order(1) CellPad(4);
Invoke #HTML.DefineTableCell InTable(Emp) WithName(A) Order(1) ColHdg1('Employee') ColHdg2('Number');
Invoke #HTML.DefineTableCell InTable(Emp) WithName(B) Order(2) ColHdg1('First Name');
Invoke #HTML.DefineTableCell InTable(Emp) WithName(C) Order(3) ColHdg1('Second Name');
Invoke #HTML.DefineTableCell InTable(Emp) WithName(D) Order(4) ColHdg1('Department');
Invoke #HTML.DefineTableCell InTable(Emp) WithName(E) Order(5) ColHdg1('Section');
Invoke #HTML.DefineTableCell InTable(Emp) WithName(F) Order(6) ColHdg1('Current') ColHdg2('Salary');
;
* Fill the HTML output table cells with the employee details;
;
Set #ProgBar Value(2);
;
Change #RowCount 0;
;
SelectList #EmpList;
Change #RowCount '#RowCount + 1';
;
Invoke #HTML.SetTableCell InTable(Emp) withName(A) Rownum(#RowCount) Type(alpha) AlphaValue(#EmpNo);
Invoke #HTML.SetTableCell InTable(Emp) withName(B) Rownum(#RowCount) Type(alpha) AlphaValue(#GiveName);
Invoke #HTML.SetTableCell InTable(Emp) withName(C) Rownum(#RowCount) Type(alpha) AlphaValue(#SurName);
Invoke #HTML.SetTableCell InTable(Emp) withName(D) Rownum(#RowCount) Type(alpha) AlphaValue(#DeptDesc);
Invoke #HTML.SetTableCell InTable(Emp) withName(E) Rownum(#RowCount) Type(alpha) AlphaValue(#SecDesc);
Invoke #HTML.SetTableCell InTable(Emp) withName(F) Rownum(#RowCount) Type(numeric) NumValue(#Salary) Decimals(2);
;
EndSelect ;
;
* Save the HTML output table;
;
Set #ProgBar Value(3);
;
Invoke #HTML.Save InFile(#HTMOutFil);
;
* Close the HTML component as we have finished with it ;
;
Invoke #HTML.Close;
;
* Save the list in an XLS format as well. This can be done directly from the list.;
;
Set #ProgBar Value(4);
;
Use Transform_List (#EmpList #XLSOutFil B) (#BRetCode);
;
* Insert the email recipient ;
;
Set #ProgBar Value(5);
;
Invoke #Mail.InsertRecipient EMailAddress(#Send_To) ;
;
* Set the mail subject;
;
Set #Mail Subject('Latest Head Count and Salary Details');
;
* Insert the email body text ;
;
Invoke #Mail.InsertItem Order(10) TextValue('Hello,') ;
;
Invoke #Mail.InsertItem Order(20) TextValue('Attached to this email are the current head count and salary details.') ;
;
Invoke #Mail.InsertItem Order(30) TextValue('The attachments have been sent in HTML format and MS Excel format.') ;
;
Invoke #Mail.InsertItem Order(40) TextValue('Simply double click on the attachment to work with the details.');
;
Invoke #Mail.InsertItem Order(50) TextValue('Best Regards,') ;
;
Invoke #Mail.InsertItem Order(60) TextValue(*User) ;
;
* Insert the attachment files;
;
Invoke #Mail.InsertAttachment FileName(#XLSOutFil);
;
Invoke #Mail.InsertAttachment FileName(#HTMOutFil);
;
* Send the mail ;
;
Invoke #Mail.Send;
;
* Close the mail component (which clears all data inside it);
;
Invoke #Mail.Close;
;
* Finished;
;
Set #ProgBar Value(0);
Message 'Mail has been sent';
;
EndRoutine ;
;
* ============================================================;
* Put up a message box if an unexpected error is detected;
* ============================================================;
;
EvtRoutine Handling(#Mail.MailErrorDetected) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS);
Use Message_Box_Show (ok ok error *component 'Unexpected error when sending email.');
Set #ProgBar Value(0);
Message 'Mail was NOT sent';
EndRoutine ;
;
* =========================================================================;
* Only enable the send email button when there is something in the address;
* =========================================================================;
;
EVTROUTINE HANDLING(#Send_To.Changed) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS);
Set #Btn_Send Enabled(*Recipient);
ENDROUTINE ;
;
;
END_COM ;