Create PDF of PO report then email

Jose,
I did see the MSDN information on creating an administrative template using a public folder on the Exchange server.  There are registry settings to alter where Outlook looks for security settings that.  We don’t have a test Exchange environment and I am loathed to attempt changing anything there. Funnily we have similar functionality in our current version of Clientele (7.1) which works, but that is what we are attempting to move off.  I did notice a couple of posts about using different approaches to opening a new Mailmailitem which is supposed to work, I gave them a quick attempt but did not get far. Sticking with what works for the moment and just have the users put up with clicking yes until they get their update of Outlook 2007 installed.
 
Cheers
Simon Hall
Greetings all,

I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.

I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong....

I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it...


Here is the code.....

private void epiButtonC1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **
EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
int PONUM;
string Approved;


// check if there is data loaded into the form. if not return from method.
if ( (bool)edvPOHeader.HasRow == false )
{
MessageBox.Show("No Data to email ...");
return;
}

// Get data from the form
Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];

if (Approved == "A")
{
// check the supplier has an email address in Purchase Point.
// grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
string PPemailAddress;

PPemailAddress = epiTextBoxC3.Text;
if (PPemailAddress == "")
{
MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
return; // bailout - no email address...
}


// Make the report from the PO data
POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
POFormDataSet POFormDS;

POFormDS = Form.GetNewParameters();
POFormDS.POFormParam[0].PONum = PONUM;
POFormDS.POFormParam[0].ReportStyleNum = 1001;
Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.

// Need to wait for report to be generated before continuing...
System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues....

// make the crystal report
ReportDocument repDoc = new ReportDocument();
repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm_TMT.rpt"); //get report definition....Once this is working should lookup the report location.

// get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
// we want, we can then use the sysrowID to get the report data to put into the crystal report.
ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
ReportMonitorDataSet RMds;
bool morepages;
ReportDataDataSet reportDS;

RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.

MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing

reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.



repDoc.SetDataSource(reportDS);
repDoc.Refresh();
MessageBox.Show("finished creating report");

// make a pdf of the PO from the report
string FileName = @"\\XXXX\EpicorData\test.pdf";
ExportOptions CrExportOptions ;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = FileName;
CrExportOptions = repDoc.ExportOptions;

CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@
MessageBox.Show("finished saving report as pdf");

// create email message
try
{
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector MsgInspector = oMsg.GetInspector;
string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();
oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. Â <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p>Â </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;

Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// Change the recipient in the next line if necessary.
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);
oRecip.Resolve();

// Attach pdf of PO, terms, and any other attachments to PO.
oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);

MsgInspector.Activate(); // shows the new email message as topmost window.

//Clean up
oRecips = null;
oRecip = null;
oMsg = null;
oApp = null;
}
catch (Exception Ex)
{
MessageBox.Show("Tried to email PO but failed");
}
}
else
MessageBox.Show("PO must be approved before it can be sent out");


}
There is a great product called PDF-Explode (PDF-Explode.com) that does all of that at a reasonable price.

Dave Thomas

--- In vantage@yahoogroups.com, "brettmanners" <bmanners@...> wrote:
>
> Greetings all,
>
> I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.
>
> I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong....
>
> I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it...
>
>
> Here is the code.....
>
> private void epiButtonC1_Click(object sender, System.EventArgs args)
> {
> // ** Place Event Handling Code Here **
> EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
> int PONUM;
> string Approved;
>
>
> // check if there is data loaded into the form. if not return from method.
> if ( (bool)edvPOHeader.HasRow == false )
> {
> MessageBox.Show("No Data to email ...");
> return;
> }
>
> // Get data from the form
> Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
> PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];
>
> if (Approved == "A")
> {
> // check the supplier has an email address in Purchase Point.
> // grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
> string PPemailAddress;
>
> PPemailAddress = epiTextBoxC3.Text;
> if (PPemailAddress == "")
> {
> MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
> return; // bailout - no email address...
> }
>
>
> // Make the report from the PO data
> POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
> POFormDataSet POFormDS;
>
> POFormDS = Form.GetNewParameters();
> POFormDS.POFormParam[0].PONum = PONUM;
> POFormDS.POFormParam[0].ReportStyleNum = 1001;
> Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.
>
> // Need to wait for report to be generated before continuing...
> System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues....
>
> // make the crystal report
> ReportDocument repDoc = new ReportDocument();
> repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm_TMT.rpt"); //get report definition....Once this is working should lookup the report location.
>
> // get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
> // we want, we can then use the sysrowID to get the report data to put into the crystal report.
> ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
> ReportMonitorDataSet RMds;
> bool morepages;
> ReportDataDataSet reportDS;
>
> RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.
>
> MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing
>
> reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.
>
>
>
> repDoc.SetDataSource(reportDS);
> repDoc.Refresh();
> MessageBox.Show("finished creating report");
>
> // make a pdf of the PO from the report
> string FileName = @"\\XXXX\EpicorData\test.pdf";
> ExportOptions CrExportOptions ;
> DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
> PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
> CrDiskFileDestinationOptions.DiskFileName = FileName;
> CrExportOptions = repDoc.ExportOptions;
>
> CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
> CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
> CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
> CrExportOptions.FormatOptions = CrFormatTypeOptions;
> repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@
> MessageBox.Show("finished saving report as pdf");
>
> // create email message
> try
> {
> Outlook.Application oApp = new Outlook.Application();
> Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
> Outlook.Inspector MsgInspector = oMsg.GetInspector;
> string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
> oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();
> oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. Â <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p>Â </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;
>
> Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
> // Change the recipient in the next line if necessary.
> Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);
> oRecip.Resolve();
>
> // Attach pdf of PO, terms, and any other attachments to PO.
> oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
> oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
>
> MsgInspector.Activate(); // shows the new email message as topmost window.
>
> //Clean up
> oRecips = null;
> oRecip = null;
> oMsg = null;
> oApp = null;
> }
> catch (Exception Ex)
> {
> MessageBox.Show("Tried to email PO but failed");
> }
> }
> else
> MessageBox.Show("PO must be approved before it can be sent out");
>
>
> }
>
If you do get it to work like this please let me know as i would be very interested in this as well. Right now i am using APM. There is a checkbox that you can use in the newest version of APM which allows you to name your pdf file with one of the properties that you have selected. but i don't like that the email is automatically sent and that it is hard to verify who it went to and if it actually went out to the suppliers at all.

Thanks,
Bobby

--- In vantage@yahoogroups.com, "brettmanners" <bmanners@...> wrote:
>
> Greetings all,
>
> I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.
>
> I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong....
>
> I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it...
>
>
> Here is the code.....
>
> private void epiButtonC1_Click(object sender, System.EventArgs args)
> {
> // ** Place Event Handling Code Here **
> EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
> int PONUM;
> string Approved;
>
>
> // check if there is data loaded into the form. if not return from method.
> if ( (bool)edvPOHeader.HasRow == false )
> {
> MessageBox.Show("No Data to email ...");
> return;
> }
>
> // Get data from the form
> Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
> PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];
>
> if (Approved == "A")
> {
> // check the supplier has an email address in Purchase Point.
> // grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
> string PPemailAddress;
>
> PPemailAddress = epiTextBoxC3.Text;
> if (PPemailAddress == "")
> {
> MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
> return; // bailout - no email address...
> }
>
>
> // Make the report from the PO data
> POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
> POFormDataSet POFormDS;
>
> POFormDS = Form.GetNewParameters();
> POFormDS.POFormParam[0].PONum = PONUM;
> POFormDS.POFormParam[0].ReportStyleNum = 1001;
> Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.
>
> // Need to wait for report to be generated before continuing...
> System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues....
>
> // make the crystal report
> ReportDocument repDoc = new ReportDocument();
> repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm_TMT.rpt"); //get report definition....Once this is working should lookup the report location.
>
> // get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
> // we want, we can then use the sysrowID to get the report data to put into the crystal report.
> ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
> ReportMonitorDataSet RMds;
> bool morepages;
> ReportDataDataSet reportDS;
>
> RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.
>
> MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing
>
> reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.
>
>
>
> repDoc.SetDataSource(reportDS);
> repDoc.Refresh();
> MessageBox.Show("finished creating report");
>
> // make a pdf of the PO from the report
> string FileName = @"\\XXXX\EpicorData\test.pdf";
> ExportOptions CrExportOptions ;
> DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
> PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
> CrDiskFileDestinationOptions.DiskFileName = FileName;
> CrExportOptions = repDoc.ExportOptions;
>
> CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
> CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
> CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
> CrExportOptions.FormatOptions = CrFormatTypeOptions;
> repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@
> MessageBox.Show("finished saving report as pdf");
>
> // create email message
> try
> {
> Outlook.Application oApp = new Outlook.Application();
> Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
> Outlook.Inspector MsgInspector = oMsg.GetInspector;
> string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
> oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();
> oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. Â <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p>Â </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;
>
> Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
> // Change the recipient in the next line if necessary.
> Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);
> oRecip.Resolve();
>
> // Attach pdf of PO, terms, and any other attachments to PO.
> oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
> oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
>
> MsgInspector.Activate(); // shows the new email message as topmost window.
>
> //Clean up
> oRecips = null;
> oRecip = null;
> oMsg = null;
> oApp = null;
> }
> catch (Exception Ex)
> {
> MessageBox.Show("Tried to email PO but failed");
> }
> }
> else
> MessageBox.Show("PO must be approved before it can be sent out");
>
>
> }
>
Hey, where is the checkbox you mention that will allow you to name your PDF with one of the properties in APM?

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of ralmon64
Sent: Tuesday, May 28, 2013 5:48 AM
To: vantage@yahoogroups.com
Subject: [Vantage] Re: Create PDF of PO report then email



If you do get it to work like this please let me know as i would be very interested in this as well. Right now i am using APM. There is a checkbox that you can use in the newest version of APM which allows you to name your pdf file with one of the properties that you have selected. but i don't like that the email is automatically sent and that it is hard to verify who it went to and if it actually went out to the suppliers at all.

Thanks,
Bobby

--- In vantage@yahoogroups.com<mailto:vantage%40yahoogroups.com>, "brettmanners" <bmanners@...<mailto:bmanners@...>> wrote:
>
> Greetings all,
>
> I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.
>
> I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong....
>
> I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it...
>
>
> Here is the code.....
>
> private void epiButtonC1_Click(object sender, System.EventArgs args)
> {
> // ** Place Event Handling Code Here **
> EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
> int PONUM;
> string Approved;
>
>
> // check if there is data loaded into the form. if not return from method.
> if ( (bool)edvPOHeader.HasRow == false )
> {
> MessageBox.Show("No Data to email ...");
> return;
> }
>
> // Get data from the form
> Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
> PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];
>
> if (Approved == "A")
> {
> // check the supplier has an email address in Purchase Point.
> // grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
> string PPemailAddress;
>
> PPemailAddress = epiTextBoxC3.Text;
> if (PPemailAddress == "")
> {
> MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
> return; // bailout - no email address...
> }
>
>
> // Make the report from the PO data
> POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
> POFormDataSet POFormDS;
>
> POFormDS = Form.GetNewParameters();
> POFormDS.POFormParam[0].PONum = PONUM;
> POFormDS.POFormParam[0].ReportStyleNum = 1001;
> Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.
>
> // Need to wait for report to be generated before continuing...
> System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues....
>
> // make the crystal report
> ReportDocument repDoc = new ReportDocument();
> repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm_TMT.rpt<file:///\\XXXX\Epicor905\Server\reports\CustomReports\POForm_TMT.rpt>"); //get report definition....Once this is working should lookup the report location.
>
> // get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
> // we want, we can then use the sysrowID to get the report data to put into the crystal report.
> ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
> ReportMonitorDataSet RMds;
> bool morepages;
> ReportDataDataSet reportDS;
>
> RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.
>
> MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing
>
> reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.
>
>
>
> repDoc.SetDataSource(reportDS);
> repDoc.Refresh();
> MessageBox.Show("finished creating report");
>
> // make a pdf of the PO from the report
> string FileName = @"\\XXXX\EpicorData\test.pdf<file:///\\XXXX\EpicorData\test.pdf>";
> ExportOptions CrExportOptions ;
> DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
> PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
> CrDiskFileDestinationOptions.DiskFileName = FileName;
> CrExportOptions = repDoc.ExportOptions;
>
> CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
> CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
> CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
> CrExportOptions.FormatOptions = CrFormatTypeOptions;
> repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@
> MessageBox.Show("finished saving report as pdf");
>
> // create email message
> try
> {
> Outlook.Application oApp = new Outlook.Application();
> Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
> Outlook.Inspector MsgInspector = oMsg.GetInspector;
> string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
> oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();
> oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;
>
> Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
> // Change the recipient in the next line if necessary.
> Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);
> oRecip.Resolve();
>
> // Attach pdf of PO, terms, and any other attachments to PO.
> oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf<file:///\\XXXX\Engineering\Temp\Purchase%20Order%20Terms%20and%20Conditions.pdf>",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
> oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt<file:///\\XXXX\EpicorData\test.rpt>",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
>
> MsgInspector.Activate(); // shows the new email message as topmost window.
>
> //Clean up
> oRecips = null;
> oRecip = null;
> oMsg = null;
> oApp = null;
> }
> catch (Exception Ex)
> {
> MessageBox.Show("Tried to email PO but failed");
> }
> }
> else
> MessageBox.Show("PO must be approved before it can be sent out");
>
>
> }
>



[Non-text portions of this message have been removed]
Brett -

Try this for your Crystal portion:


Calvin Dekker
[cid:image001.jpg@01CE5B94.54FC4770]<http://www.codabears.com/>
(630) 672-7688 x1484

*Solutions for Epicor users.

"No trees were harmed during the sending of this message, however a large number of electrons were terribly inconvenienced."

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of brettmanners
Sent: Sunday, May 26, 2013 8:25 PM
To: vantage@yahoogroups.com
Subject: [Vantage] Create PDF of PO report then email



Greetings all,

I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.

I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong....

I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it...

Here is the code.....

private void epiButtonC1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **
EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
int PONUM;
string Approved;

// check if there is data loaded into the form. if not return from method.
if ( (bool)edvPOHeader.HasRow == false )
{
MessageBox.Show("No Data to email ...");
return;
}

// Get data from the form
Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];

if (Approved == "A")
{
// check the supplier has an email address in Purchase Point.
// grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
string PPemailAddress;

PPemailAddress = epiTextBoxC3.Text;
if (PPemailAddress == "")
{
MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
return; // bailout - no email address...
}

// Make the report from the PO data
POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
POFormDataSet POFormDS;

POFormDS = Form.GetNewParameters();
POFormDS.POFormParam[0].PONum = PONUM;
POFormDS.POFormParam[0].ReportStyleNum = 1001;
Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.

// Need to wait for report to be generated before continuing...
System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues....

// make the crystal report
ReportDocument repDoc = new ReportDocument();
repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm_TMT.rpt<file:///\\XXXX\Epicor905\Server\reports\CustomReports\POForm_TMT.rpt>"); //get report definition....Once this is working should lookup the report location.

// get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
// we want, we can then use the sysrowID to get the report data to put into the crystal report.
ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
ReportMonitorDataSet RMds;
bool morepages;
ReportDataDataSet reportDS;

RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.

MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing

reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.



repDoc.SetDataSource(reportDS);
repDoc.Refresh();
MessageBox.Show("finished creating report");

// make a pdf of the PO from the report
string FileName = @"\\XXXX\EpicorData\test.pdf<file:///\\XXXX\EpicorData\test.pdf>";
ExportOptions CrExportOptions ;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = FileName;
CrExportOptions = repDoc.ExportOptions;

CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@
MessageBox.Show("finished saving report as pdf");

// create email message
try
{
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector MsgInspector = oMsg.GetInspector;
string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();
oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;

Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// Change the recipient in the next line if necessary.
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);
oRecip.Resolve();

// Attach pdf of PO, terms, and any other attachments to PO.
oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf<file:///\\XXXX\Engineering\Temp\Purchase%20Order%20Terms%20and%20Conditions.pdf>",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt<file:///\\XXXX\EpicorData\test.rpt>",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);

MsgInspector.Activate(); // shows the new email message as topmost window.

//Clean up
oRecips = null;
oRecip = null;
oMsg = null;
oApp = null;
}
catch (Exception Ex)
{
MessageBox.Show("Tried to email PO but failed");
}
}
else
MessageBox.Show("PO must be approved before it can be sent out");

}



[Non-text portions of this message have been removed]
Brett -

Probably helps more if I try attaching the code to the message too. :)

String myRpt = "";
String rpt = "";
String myPDFName = String.Format("PO-{0}-{1:yyyyMMdd-HHmmssff}.pdf", PONum, System.DateTime.Now);
String myPDF = String.Format("{0}{1}", RptPath, myPDFName);
String RptPath = "\\epicordata\reports\MyPOs\<file:///\\epicordata\reports\MyPOs\>";
String AppPath = "\\Epicor905\";
DataSet rptData = new DataSet;
rptData.ReadXml(FileName);
IF (File.Exists(myPDF)) {
File.Delete(myPDF);
}
ReportDocument myCrystal = New CrystalDecisions.CrystalReports.Engine.ReportDocument;
String myReport = AppPath + myRpt;
myCrystal.Load(myReport);
myCrystal.SetDataSource(rptData);
myCrystal.Refresh();
myCrystal.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, myPDF);


Calvin Dekker
[cid:image001.jpg@01CE5B95.56B350D0]<http://www.codabears.com/>
(630) 672-7688 x1484

*Solutions for Epicor users.

"No trees were harmed during the sending of this message, however a large number of electrons were terribly inconvenienced."

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of brettmanners
Sent: Sunday, May 26, 2013 8:25 PM
To: vantage@yahoogroups.com
Subject: [Vantage] Create PDF of PO report then email



Greetings all,

I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.

I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong....

I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it...

Here is the code.....

private void epiButtonC1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **
EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
int PONUM;
string Approved;

// check if there is data loaded into the form. if not return from method.
if ( (bool)edvPOHeader.HasRow == false )
{
MessageBox.Show("No Data to email ...");
return;
}

// Get data from the form
Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];

if (Approved == "A")
{
// check the supplier has an email address in Purchase Point.
// grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
string PPemailAddress;

PPemailAddress = epiTextBoxC3.Text;
if (PPemailAddress == "")
{
MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
return; // bailout - no email address...
}

// Make the report from the PO data
POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
POFormDataSet POFormDS;

POFormDS = Form.GetNewParameters();
POFormDS.POFormParam[0].PONum = PONUM;
POFormDS.POFormParam[0].ReportStyleNum = 1001;
Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.

// Need to wait for report to be generated before continuing...
System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues....

// make the crystal report
ReportDocument repDoc = new ReportDocument();
repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm_TMT.rpt"); //get report definition....Once this is working should lookup the report location.

// get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
// we want, we can then use the sysrowID to get the report data to put into the crystal report.
ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
ReportMonitorDataSet RMds;
bool morepages;
ReportDataDataSet reportDS;

RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.

MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing

reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.



repDoc.SetDataSource(reportDS);
repDoc.Refresh();
MessageBox.Show("finished creating report");

// make a pdf of the PO from the report
string FileName = @"\\XXXX\EpicorData\test.pdf";
ExportOptions CrExportOptions ;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = FileName;
CrExportOptions = repDoc.ExportOptions;

CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@
MessageBox.Show("finished saving report as pdf");

// create email message
try
{
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector MsgInspector = oMsg.GetInspector;
string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();
oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;

Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// Change the recipient in the next line if necessary.
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);
oRecip.Resolve();

// Attach pdf of PO, terms, and any other attachments to PO.
oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);

MsgInspector.Activate(); // shows the new email message as topmost window.

//Clean up
oRecips = null;
oRecip = null;
oMsg = null;
oApp = null;
}
catch (Exception Ex)
{
MessageBox.Show("Tried to email PO but failed");
}
}
else
MessageBox.Show("PO must be approved before it can be sent out");

}



[Non-text portions of this message have been removed]
Under Routing Lists, Open one of them.

Click the Routing List Groups tab.

Click Edit.

On the window that opens is a section called Output. You can select to use the keyfield of the document type for the name. When I selected it for our packing slips they come out like....

14722.00_165_0_146T0.pdf

The first set of numbers being the packing slip number.

--- In vantage@yahoogroups.com, Karen Schoenung <kschoenung@...> wrote:
>
> Hey, where is the checkbox you mention that will allow you to name your PDF with one of the properties in APM?
>
> From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of ralmon64
> Sent: Tuesday, May 28, 2013 5:48 AM
> To: vantage@yahoogroups.com
> Subject: [Vantage] Re: Create PDF of PO report then email
>
>
>
> If you do get it to work like this please let me know as i would be very interested in this as well. Right now i am using APM. There is a checkbox that you can use in the newest version of APM which allows you to name your pdf file with one of the properties that you have selected. but i don't like that the email is automatically sent and that it is hard to verify who it went to and if it actually went out to the suppliers at all.
>
> Thanks,
> Bobby
>
> --- In vantage@yahoogroups.com<mailto:vantage%40yahoogroups.com>, "brettmanners" <bmanners@<mailto:bmanners@>> wrote:
> >
> > Greetings all,
> >
> > I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.
> >
> > I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong....
> >
> > I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it...
> >
> >
> > Here is the code.....
> >
> > private void epiButtonC1_Click(object sender, System.EventArgs args)
> > {
> > // ** Place Event Handling Code Here **
> > EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
> > int PONUM;
> > string Approved;
> >
> >
> > // check if there is data loaded into the form. if not return from method.
> > if ( (bool)edvPOHeader.HasRow == false )
> > {
> > MessageBox.Show("No Data to email ...");
> > return;
> > }
> >
> > // Get data from the form
> > Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
> > PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];
> >
> > if (Approved == "A")
> > {
> > // check the supplier has an email address in Purchase Point.
> > // grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
> > string PPemailAddress;
> >
> > PPemailAddress = epiTextBoxC3.Text;
> > if (PPemailAddress == "")
> > {
> > MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
> > return; // bailout - no email address...
> > }
> >
> >
> > // Make the report from the PO data
> > POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
> > POFormDataSet POFormDS;
> >
> > POFormDS = Form.GetNewParameters();
> > POFormDS.POFormParam[0].PONum = PONUM;
> > POFormDS.POFormParam[0].ReportStyleNum = 1001;
> > Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.
> >
> > // Need to wait for report to be generated before continuing...
> > System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues....
> >
> > // make the crystal report
> > ReportDocument repDoc = new ReportDocument();
> > repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm_TMT.rpt<file:///\\XXXX\Epicor905\Server\reports\CustomReports\POForm_TMT.rpt>"); //get report definition....Once this is working should lookup the report location.
> >
> > // get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
> > // we want, we can then use the sysrowID to get the report data to put into the crystal report.
> > ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
> > ReportMonitorDataSet RMds;
> > bool morepages;
> > ReportDataDataSet reportDS;
> >
> > RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.
> >
> > MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing
> >
> > reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.
> >
> >
> >
> > repDoc.SetDataSource(reportDS);
> > repDoc.Refresh();
> > MessageBox.Show("finished creating report");
> >
> > // make a pdf of the PO from the report
> > string FileName = @"\\XXXX\EpicorData\test.pdf<file:///\\XXXX\EpicorData\test.pdf>";
> > ExportOptions CrExportOptions ;
> > DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
> > PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
> > CrDiskFileDestinationOptions.DiskFileName = FileName;
> > CrExportOptions = repDoc.ExportOptions;
> >
> > CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
> > CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
> > CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
> > CrExportOptions.FormatOptions = CrFormatTypeOptions;
> > repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@
> > MessageBox.Show("finished saving report as pdf");
> >
> > // create email message
> > try
> > {
> > Outlook.Application oApp = new Outlook.Application();
> > Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
> > Outlook.Inspector MsgInspector = oMsg.GetInspector;
> > string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
> > oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();
> > oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;
> >
> > Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
> > // Change the recipient in the next line if necessary.
> > Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);
> > oRecip.Resolve();
> >
> > // Attach pdf of PO, terms, and any other attachments to PO.
> > oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf<file:///\\XXXX\Engineering\Temp\Purchase%20Order%20Terms%20and%20Conditions.pdf>",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
> > oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt<file:///\\XXXX\EpicorData\test.rpt>",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
> >
> > MsgInspector.Activate(); // shows the new email message as topmost window.
> >
> > //Clean up
> > oRecips = null;
> > oRecip = null;
> > oMsg = null;
> > oApp = null;
> > }
> > catch (Exception Ex)
> > {
> > MessageBox.Show("Tried to email PO but failed");
> > }
> > }
> > else
> > MessageBox.Show("PO must be approved before it can be sent out");
> >
> >
> > }
> >
>
>
>
> [Non-text portions of this message have been removed]
>
Thank you.

Also for this to work, you need to set the Key Property Checkbox

Document Type
Properties
Edit
Select the Field you want.

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of justincalbraze
Sent: Tuesday, May 28, 2013 10:04 AM
To: vantage@yahoogroups.com
Subject: [Vantage] Re: Create PDF of PO report then email



Under Routing Lists, Open one of them.

Click the Routing List Groups tab.

Click Edit.

On the window that opens is a section called Output. You can select to use the keyfield of the document type for the name. When I selected it for our packing slips they come out like....

14722.00_165_0_146T0.pdf

The first set of numbers being the packing slip number.

--- In vantage@yahoogroups.com<mailto:vantage%40yahoogroups.com>, Karen Schoenung <kschoenung@...<mailto:kschoenung@...>> wrote:
>
> Hey, where is the checkbox you mention that will allow you to name your PDF with one of the properties in APM?
>
> From: vantage@yahoogroups.com<mailto:vantage%40yahoogroups.com> [mailto:vantage@yahoogroups.com<mailto:vantage%40yahoogroups.com>] On Behalf Of ralmon64
> Sent: Tuesday, May 28, 2013 5:48 AM
> To: vantage@yahoogroups.com<mailto:vantage%40yahoogroups.com>
> Subject: [Vantage] Re: Create PDF of PO report then email
>
>
>
> If you do get it to work like this please let me know as i would be very interested in this as well. Right now i am using APM. There is a checkbox that you can use in the newest version of APM which allows you to name your pdf file with one of the properties that you have selected. but i don't like that the email is automatically sent and that it is hard to verify who it went to and if it actually went out to the suppliers at all.
>
> Thanks,
> Bobby
>
> --- In vantage@yahoogroups.com<mailto:vantage%40yahoogroups.com><mailto:vantage%40yahoogroups.com>, "brettmanners" <bmanners@<mailto:bmanners@>> wrote:
> >
> > Greetings all,
> >
> > I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.
> >
> > I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong....
> >
> > I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it...
> >
> >
> > Here is the code.....
> >
> > private void epiButtonC1_Click(object sender, System.EventArgs args)
> > {
> > // ** Place Event Handling Code Here **
> > EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
> > int PONUM;
> > string Approved;
> >
> >
> > // check if there is data loaded into the form. if not return from method.
> > if ( (bool)edvPOHeader.HasRow == false )
> > {
> > MessageBox.Show("No Data to email ...");
> > return;
> > }
> >
> > // Get data from the form
> > Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
> > PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];
> >
> > if (Approved == "A")
> > {
> > // check the supplier has an email address in Purchase Point.
> > // grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
> > string PPemailAddress;
> >
> > PPemailAddress = epiTextBoxC3.Text;
> > if (PPemailAddress == "")
> > {
> > MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
> > return; // bailout - no email address...
> > }
> >
> >
> > // Make the report from the PO data
> > POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
> > POFormDataSet POFormDS;
> >
> > POFormDS = Form.GetNewParameters();
> > POFormDS.POFormParam[0].PONum = PONUM;
> > POFormDS.POFormParam[0].ReportStyleNum = 1001;
> > Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.
> >
> > // Need to wait for report to be generated before continuing...
> > System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues....
> >
> > // make the crystal report
> > ReportDocument repDoc = new ReportDocument();
> > repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm_TMT.rpt<file:///<file:///\\>\\XXXX\Epicor905\Server\reports\CustomReports\POForm_TMT.rpt>"); //get report definition....Once this is working should lookup the report location.
> >
> > // get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
> > // we want, we can then use the sysrowID to get the report data to put into the crystal report.
> > ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
> > ReportMonitorDataSet RMds;
> > bool morepages;
> > ReportDataDataSet reportDS;
> >
> > RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.
> >
> > MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing
> >
> > reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.
> >
> >
> >
> > repDoc.SetDataSource(reportDS);
> > repDoc.Refresh();
> > MessageBox.Show("finished creating report");
> >
> > // make a pdf of the PO from the report
> > string FileName = @"\\XXXX\EpicorData\test.pdf<file:///<file:///\\>\\XXXX\EpicorData\test.pdf>";
> > ExportOptions CrExportOptions ;
> > DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
> > PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
> > CrDiskFileDestinationOptions.DiskFileName = FileName;
> > CrExportOptions = repDoc.ExportOptions;
> >
> > CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
> > CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
> > CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
> > CrExportOptions.FormatOptions = CrFormatTypeOptions;
> > repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@
> > MessageBox.Show("finished saving report as pdf");
> >
> > // create email message
> > try
> > {
> > Outlook.Application oApp = new Outlook.Application();
> > Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
> > Outlook.Inspector MsgInspector = oMsg.GetInspector;
> > string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
> > oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();
> > oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. <o:p></o:p></span></p><p cla ss=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;
> >
> > Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
> > // Change the recipient in the next line if necessary.
> > Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);
> > oRecip.Resolve();
> >
> > // Attach pdf of PO, terms, and any other attachments to PO.
> > oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf<file:///<file:///\\>\\XXXX\Engineering\Temp\Purchase%20Order%20Terms%20and%20Conditions.pdf>",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
> > oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt<file:///<file:///\\>\\XXXX\EpicorData\test.rpt>",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
> >
> > MsgInspector.Activate(); // shows the new email message as topmost window.
> >
> > //Clean up
> > oRecips = null;
> > oRecip = null;
> > oMsg = null;
> > oApp = null;
> > }
> > catch (Exception Ex)
> > {
> > MessageBox.Show("Tried to email PO but failed");
> > }
> > }
> > else
> > MessageBox.Show("PO must be approved before it can be sent out");
> >
> >
> > }
> >
>
>
>
> [Non-text portions of this message have been removed]
>



[Non-text portions of this message have been removed]
Thanks for the help everyone.

I am trying to get Calvin's suggestion to work as that will put all the customisation in one place. I am still having trouble though...

I am a bit confused about these lines:
> String myPDFName = String.Format("PO-{0}-{1:yyyyMMdd-HHmmssff}.pdf", PONum, System.DateTime.Now);
> String myPDF = String.Format("{0}{1}", RptPath, myPDFName);
> String RptPath = "\\epicordata\reports\MyPOs\<file:///\\epicordata\reports\MyPOs\>";

it looks like RptPath is used before it has been declared? and I don't understand the "<file:///\\" part?


Calvin can you post the rest of the code?

Thanks Brett


--- In vantage@yahoogroups.com, Calvin Dekker <calvind@...> wrote:
>
> Brett -
>
> Probably helps more if I try attaching the code to the message too. :)
>
> String myRpt = "";
> String rpt = "";
> String myPDFName = String.Format("PO-{0}-{1:yyyyMMdd-HHmmssff}.pdf", PONum, System.DateTime.Now);
> String myPDF = String.Format("{0}{1}", RptPath, myPDFName);
> String RptPath = "\\epicordata\reports\MyPOs\<file:///\\epicordata\reports\MyPOs\>";
> String AppPath = "\\Epicor905\";
> DataSet rptData = new DataSet;
> rptData.ReadXml(FileName);
> IF (File.Exists(myPDF)) {
> File.Delete(myPDF);
> }
> ReportDocument myCrystal = New CrystalDecisions.CrystalReports.Engine.ReportDocument;
> String myReport = AppPath + myRpt;
> myCrystal.Load(myReport);
> myCrystal.SetDataSource(rptData);
> myCrystal.Refresh();
> myCrystal.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, myPDF);
>
>
> Calvin Dekker
> [cid:image001.jpg@...]<http://www.codabears.com/>
> (630) 672-7688 x1484
>
> *Solutions for Epicor users.
>
> "No trees were harmed during the sending of this message, however a large number of electrons were terribly inconvenienced."
>
> From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of brettmanners
> Sent: Sunday, May 26, 2013 8:25 PM
> To: vantage@yahoogroups.com
> Subject: [Vantage] Create PDF of PO report then email
>
>
>
> Greetings all,
>
> I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.
>
> I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong....
>
> I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it...
>
> Here is the code.....
>
> private void epiButtonC1_Click(object sender, System.EventArgs args)
> {
> // ** Place Event Handling Code Here **
> EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
> int PONUM;
> string Approved;
>
> // check if there is data loaded into the form. if not return from method.
> if ( (bool)edvPOHeader.HasRow == false )
> {
> MessageBox.Show("No Data to email ...");
> return;
> }
>
> // Get data from the form
> Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
> PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];
>
> if (Approved == "A")
> {
> // check the supplier has an email address in Purchase Point.
> // grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
> string PPemailAddress;
>
> PPemailAddress = epiTextBoxC3.Text;
> if (PPemailAddress == "")
> {
> MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
> return; // bailout - no email address...
> }
>
> // Make the report from the PO data
> POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
> POFormDataSet POFormDS;
>
> POFormDS = Form.GetNewParameters();
> POFormDS.POFormParam[0].PONum = PONUM;
> POFormDS.POFormParam[0].ReportStyleNum = 1001;
> Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.
>
> // Need to wait for report to be generated before continuing...
> System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues....
>
> // make the crystal report
> ReportDocument repDoc = new ReportDocument();
> repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm_TMT.rpt"); //get report definition....Once this is working should lookup the report location.
>
> // get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
> // we want, we can then use the sysrowID to get the report data to put into the crystal report.
> ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
> ReportMonitorDataSet RMds;
> bool morepages;
> ReportDataDataSet reportDS;
>
> RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.
>
> MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing
>
> reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.
>
>
>
> repDoc.SetDataSource(reportDS);
> repDoc.Refresh();
> MessageBox.Show("finished creating report");
>
> // make a pdf of the PO from the report
> string FileName = @"\\XXXX\EpicorData\test.pdf";
> ExportOptions CrExportOptions ;
> DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
> PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
> CrDiskFileDestinationOptions.DiskFileName = FileName;
> CrExportOptions = repDoc.ExportOptions;
>
> CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
> CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
> CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
> CrExportOptions.FormatOptions = CrFormatTypeOptions;
> repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@
> MessageBox.Show("finished saving report as pdf");
>
> // create email message
> try
> {
> Outlook.Application oApp = new Outlook.Application();
> Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
> Outlook.Inspector MsgInspector = oMsg.GetInspector;
> string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
> oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();
> oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;
>
> Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
> // Change the recipient in the next line if necessary.
> Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);
> oRecip.Resolve();
>
> // Attach pdf of PO, terms, and any other attachments to PO.
> oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
> oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
>
> MsgInspector.Activate(); // shows the new email message as topmost window.
>
> //Clean up
> oRecips = null;
> oRecip = null;
> oMsg = null;
> oApp = null;
> }
> catch (Exception Ex)
> {
> MessageBox.Show("Tried to email PO but failed");
> }
> }
> else
> MessageBox.Show("PO must be approved before it can be sent out");
>
> }
>
>
>
> [Non-text portions of this message have been removed]
>
I managed to get this working with some help from out VAR. In the end we had to rebuild the PO report in crystal as the dataset I was getting from Epicor didn't match what the report was expecting for some reason.

Here is the code:


// **************************************************
// Custom code for POEntryForm
// Created: 15/02/2013 9:50:29 AM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Epicor.Mfg.BO;
using Epicor.Mfg.UI;
using Epicor.Mfg.UI.Adapters;
using Epicor.Mfg.UI.Customization;
using Epicor.Mfg.UI.ExtendedProps;
using Epicor.Mfg.UI.FormFunctions;
using Epicor.Mfg.UI.FrameWork;
using Epicor.Mfg.UI.Searches;

using Outlook = Microsoft.Office.Interop.Outlook;
using Epicor.Mfg.Rpt;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Epicor.Mfg.Core;
using System.IO;


public class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **

// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **

public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization

// End Wizard Added Variable Initialization

// Begin Wizard Added Custom Method Calls

this.epiButtonC1.Click += new System.EventHandler(this.epiButtonC1_Click);
// End Wizard Added Custom Method Calls
}

public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal

this.epiButtonC1.Click -= new System.EventHandler(this.epiButtonC1_Click);
// End Wizard Added Object Disposal

// Begin Custom Code Disposal

// End Custom Code Disposal
}

private void epiButtonC1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **

// This customisation requires 3 .dll files for the email automation to work. These files must exsist in the client
// folder on the client machine before the customistaion can load.
// The files are:
// - Microsoft.Office.Interop.Outlook.dll
// - CrystalDeceisions.Shared.dll
// - CrystalDecsicions.CrystalReports.Engine.dll


EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
int PONUM;
string Approved;


// check if there is data loaded into the form. if not return from method.
if ( (bool)edvPOHeader.HasRow == false )
{
MessageBox.Show("No Data to email ...");
return;
}

// Get data from the form
Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];

if (Approved == "A")
{
// check the supplier has an email address in Purchase Point.
// grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
string PPemailAddress;

PPemailAddress = epiTextBoxC3.Text;
if (PPemailAddress == "")
{
MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
return; // bailout - no email address...
}

// Make the report from the PO data
POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
POFormDataSet POFormDS;

POFormDS = Form.GetNewParameters();

// set the PO number and report style and submit the form to the system agent.
POFormDS.POFormParam[0].PONum = PONUM;
POFormDS.POFormParam[0].ReportStyleNum = 1001;
POFormDS.POFormParam[0].WorkstationID = String.Format("{0}",PONUM); // Using the PO number as the WorkstationID so it is easy to reteive this report
Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.

// make the crystal report
ReportDocument repDoc = new ReportDocument();
repDoc.Load(@"\\#####\Epicor905\Server\reports\CustomReports\POForm.rpt"); //get report definition....Once this is working should lookup the report location.

// get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
// we want, we can then use the sysrowID to get the report data to put into the crystal report.
ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
ReportMonitorDataSet RMds;
bool morepages;
ReportDataDataSet reportDS = new ReportDataDataSet();

// setup a loop to look for when the report has been generated.
int timer=0;
RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='"+PONUM+"'", 0, 0, out morepages);
while (RMds.SysRptLst.Count == 0 );
{
RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='"+PONUM+"'", 0, 0, out morepages);
System.Threading.Thread.Sleep(1000);
timer = timer + 1;
if (timer > 30)
{
MessageBox.Show("Well, I have been trying to make a pdf of the PO for a while now and I just can't do it....I give up!");
return;
}
}

string sFilePath;
sFilePath = RMds.SysRptLst[0].FileName.ToString();
reportDS.ReadXml(sFilePath , System.Data.XmlReadMode.Auto);
reportDS.WriteXml(sFilePath, System.Data.XmlWriteMode.WriteSchema);

repDoc.SetDataSource(reportDS);
repDoc.Refresh();

// make a pdf of the PO from the report
string FileName = String.Format(@"\\###\EpicorData\{0}.pdf", PONUM);
ExportOptions CrExportOptions ;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = FileName;
CrExportOptions = repDoc.ExportOptions;

CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
repDoc.Export();


// create email message
try
{
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector MsgInspector = oMsg.GetInspector;
string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** TMT PO number " + PONUM.ToString();
oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. Â <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p>Â </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;

Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// Change the recipient in the next line if necessary.
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);
oRecip.Resolve();

// Attach pdf of PO, terms, and any other attachments to PO.
oMsg.Attachments.Add(@"\\####\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
oMsg.Attachments.Add(FileName,Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);

MsgInspector.Activate(); // shows the new email message as topmost window.

//Clean up
oRecips = null;
oRecip = null;
oMsg = null;
oApp = null;
File.Delete(FileName);
}
catch (Exception Ex)
{
MessageBox.Show("Tried to email PO but failed.....Really, I did try, I dont know what went wrong...better call the system admin");
}
}
else
MessageBox.Show("PO must be approved before it can be sent out");

}

}







--- In vantage@yahoogroups.com, "brettmanners" <bmanners@...> wrote:
>
> Greetings all,
>
> I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.
>
> I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong....
>
> I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it...
>
>
> Here is the code.....
>
> private void epiButtonC1_Click(object sender, System.EventArgs args)
> {
> // ** Place Event Handling Code Here **
> EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
> int PONUM;
> string Approved;
>
>
> // check if there is data loaded into the form. if not return from method.
> if ( (bool)edvPOHeader.HasRow == false )
> {
> MessageBox.Show("No Data to email ...");
> return;
> }
>
> // Get data from the form
> Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
> PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];
>
> if (Approved == "A")
> {
> // check the supplier has an email address in Purchase Point.
> // grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
> string PPemailAddress;
>
> PPemailAddress = epiTextBoxC3.Text;
> if (PPemailAddress == "")
> {
> MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
> return; // bailout - no email address...
> }
>
>
> // Make the report from the PO data
> POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
> POFormDataSet POFormDS;
>
> POFormDS = Form.GetNewParameters();
> POFormDS.POFormParam[0].PONum = PONUM;
> POFormDS.POFormParam[0].ReportStyleNum = 1001;
> Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.
>
> // Need to wait for report to be generated before continuing...
> System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues....
>
> // make the crystal report
> ReportDocument repDoc = new ReportDocument();
> repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm.rpt"); //get report definition....Once this is working should lookup the report location.
>
> // get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
> // we want, we can then use the sysrowID to get the report data to put into the crystal report.
> ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
> ReportMonitorDataSet RMds;
> bool morepages;
> ReportDataDataSet reportDS;
>
> RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.
>
> MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing
>
> reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.
>
>
>
> repDoc.SetDataSource(reportDS);
> repDoc.Refresh();
> MessageBox.Show("finished creating report");
>
> // make a pdf of the PO from the report
> string FileName = @"\\XXXX\EpicorData\test.pdf";
> ExportOptions CrExportOptions ;
> DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
> PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
> CrDiskFileDestinationOptions.DiskFileName = FileName;
> CrExportOptions = repDoc.ExportOptions;
>
> CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
> CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
> CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
> CrExportOptions.FormatOptions = CrFormatTypeOptions;
> repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@
> MessageBox.Show("finished saving report as pdf");
>
> // create email message
> try
> {
> Outlook.Application oApp = new Outlook.Application();
> Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
> Outlook.Inspector MsgInspector = oMsg.GetInspector;
> string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
> oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();
> oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. Â <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p>Â </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;
>
> Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
> // Change the recipient in the next line if necessary.
> Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);
> oRecip.Resolve();
>
> // Attach pdf of PO, terms, and any other attachments to PO.
> oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
> oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
>
> MsgInspector.Activate(); // shows the new email message as topmost window.
>
> //Clean up
> oRecips = null;
> oRecip = null;
> oMsg = null;
> oApp = null;
> }
> catch (Exception Ex)
> {
> MessageBox.Show("Tried to email PO but failed");
> }
> }
> else
> MessageBox.Show("PO must be approved before it can be sent out");
>
>
> }
>

Ok, been trying to get this to work for a while now and I can't find the DLL files. I have run searches on my computer and tried to browse to different paths, the only thing i can find are MSIL with these names, and i can't copy these.  So what is the best way move the DLL file into the client folder. 


Thanks,
Bobby



---In vantage@yahoogroups.com, <brett.manners@...> wrote:

I managed to get this working with some help from out VAR. In the end we had to rebuild the PO report in crystal as the dataset I was getting from Epicor didn't match what the report was expecting for some reason.

Here is the code:


// **************************************************
// Custom code for POEntryForm
// Created: 15/02/2013 9:50:29 AM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Epicor.Mfg.BO;
using Epicor.Mfg.UI;
using Epicor.Mfg.UI.Adapters;
using Epicor.Mfg.UI.Customization;
using Epicor.Mfg.UI.ExtendedProps;
using Epicor.Mfg.UI.FormFunctions;
using Epicor.Mfg.UI.FrameWork;
using Epicor.Mfg.UI.Searches;

using Outlook = Microsoft.Office.Interop.Outlook;
using Epicor.Mfg.Rpt;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Epicor.Mfg.Core;
using System.IO;


public class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **

// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **

public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization

// End Wizard Added Variable Initialization

// Begin Wizard Added Custom Method Calls

this.epiButtonC1.Click += new System.EventHandler(this.epiButtonC1_Click);
// End Wizard Added Custom Method Calls
}

public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal

this.epiButtonC1.Click -= new System.EventHandler(this.epiButtonC1_Click);
// End Wizard Added Object Disposal

// Begin Custom Code Disposal

// End Custom Code Disposal
}

private void epiButtonC1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **

// This customisation requires 3 .dll files for the email automation to work. These files must exsist in the client
// folder on the client machine before the customistaion can load.
// The files are:
// - Microsoft.Office.Interop.Outlook.dll
// - CrystalDeceisions.Shared.dll
// - CrystalDecsicions.CrystalReports.Engine.dll


EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
int PONUM;
string Approved;


// check if there is data loaded into the form. if not return from method.
if ( (bool)edvPOHeader.HasRow == false )
{
MessageBox.Show("No Data to email ...");
return;
}

// Get data from the form
Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];

if (Approved == "A")
{
// check the supplier has an email address in Purchase Point.
// grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
string PPemailAddress;

PPemailAddress = epiTextBoxC3.Text;
if (PPemailAddress == "")
{
MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
return; // bailout - no email address...
}

// Make the report from the PO data
POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
POFormDataSet POFormDS;

POFormDS = Form.GetNewParameters();

// set the PO number and report style and submit the form to the system agent.
POFormDS.POFormParam[0].PONum = PONUM;
POFormDS.POFormParam[0].ReportStyleNum = 1001;
POFormDS.POFormParam[0].WorkstationID = String.Format("{0}",PONUM); // Using the PO number as the WorkstationID so it is easy to reteive this report
Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.

// make the crystal report
ReportDocument repDoc = new ReportDocument();
repDoc.Load(@"\\#####\Epicor905\Server\reports\CustomReports\POForm.rpt"); //get report definition....Once this is working should lookup the report location.

// get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
// we want, we can then use the sysrowID to get the report data to put into the crystal report.
ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
ReportMonitorDataSet RMds;
bool morepages;
ReportDataDataSet reportDS = new ReportDataDataSet();

// setup a loop to look for when the report has been generated.
int timer=0;
RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='"+PONUM+"'", 0, 0, out morepages);
while (RMds.SysRptLst.Count == 0 );
{
RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='"+PONUM+"'", 0, 0, out morepages);
System.Threading.Thread.Sleep(1000);
timer = timer + 1;
if (timer > 30)
{
MessageBox.Show("Well, I have been trying to make a pdf of the PO for a while now and I just can't do it....I give up!");
return;
}
}

string sFilePath;
sFilePath = RMds.SysRptLst[0].FileName.ToString();
reportDS.ReadXml(sFilePath , System.Data.XmlReadMode.Auto);
reportDS.WriteXml(sFilePath, System.Data.XmlWriteMode.WriteSchema);

repDoc.SetDataSource(reportDS);
repDoc.Refresh();

// make a pdf of the PO from the report
string FileName = String.Format(@"\\###\EpicorData\{0}.pdf", PONUM);
ExportOptions CrExportOptions ;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = FileName;
CrExportOptions = repDoc.ExportOptions;

CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
repDoc.Export();


// create email message
try
{
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector MsgInspector = oMsg.GetInspector;
string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** TMT PO number " + PONUM.ToString();
oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order.  <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;

Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// Change the recipient in the next line if necessary.
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);
oRecip.Resolve();

// Attach pdf of PO, terms, and any other attachments to PO.
oMsg.Attachments.Add(@"\\####\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
oMsg.Attachments.Add(FileName,Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);

MsgInspector.Activate(); // shows the new email message as topmost window.

//Clean up
oRecips = null;
oRecip = null;
oMsg = null;
oApp = null;
File.Delete(FileName);
}
catch (Exception Ex)
{
MessageBox.Show("Tried to email PO but failed.....Really, I did try, I dont know what went wrong...better call the system admin");
}
}
else
MessageBox.Show("PO must be approved before it can be sent out");

}

}







--- In vantage@yahoogroups.com, "brettmanners" <bmanners@...> wrote:
>
> Greetings all,
>
> I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.
>
> I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong....
>
> I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it...
>
>
> Here is the code.....
>
> private void epiButtonC1_Click(object sender, System.EventArgs args)
> {
> // ** Place Event Handling Code Here **
> EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
> int PONUM;
> string Approved;
>
>
> // check if there is data loaded into the form. if not return from method.
> if ( (bool)edvPOHeader.HasRow == false )
> {
> MessageBox.Show("No Data to email ...");
> return;
> }
>
> // Get data from the form
> Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
> PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];
>
> if (Approved == "A")
> {
> // check the supplier has an email address in Purchase Point.
> // grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
> string PPemailAddress;
>
> PPemailAddress = epiTextBoxC3.Text;
> if (PPemailAddress == "")
> {
> MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
> return; // bailout - no email address...
> }
>
>
> // Make the report from the PO data
> POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
> POFormDataSet POFormDS;
>
> POFormDS = Form.GetNewParameters();
> POFormDS.POFormParam[0].PONum = PONUM;
> POFormDS.POFormParam[0].ReportStyleNum = 1001;
> Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.
>
> // Need to wait for report to be generated before continuing...
> System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues....
>
> // make the crystal report
> ReportDocument repDoc = new ReportDocument();
> repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm.rpt"); //get report definition....Once this is working should lookup the report location.
>
> // get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
> // we want, we can then use the sysrowID to get the report data to put into the crystal report.
> ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
> ReportMonitorDataSet RMds;
> bool morepages;
> ReportDataDataSet reportDS;
>
> RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.
>
> MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing
>
> reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.
>
>
>
> repDoc.SetDataSource(reportDS);
> repDoc.Refresh();
> MessageBox.Show("finished creating report");
>
> // make a pdf of the PO from the report
> string FileName = @"\\XXXX\EpicorData\test.pdf";
> ExportOptions CrExportOptions ;
> DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
> PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
> CrDiskFileDestinationOptions.DiskFileName = FileName;
> CrExportOptions = repDoc.ExportOptions;
>
> CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
> CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
> CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
> CrExportOptions.FormatOptions = CrFormatTypeOptions;
> repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@
> MessageBox.Show("finished saving report as pdf");
>
> // create email message
> try
> {
> Outlook.Application oApp = new Outlook.Application();
> Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
> Outlook.Inspector MsgInspector = oMsg.GetInspector;
> string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
> oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();
> oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order.  <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;
>
> Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
> // Change the recipient in the next line if necessary.
> Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);
> oRecip.Resolve();
>
> // Attach pdf of PO, terms, and any other attachments to PO.
> oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
> oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
>
> MsgInspector.Activate(); // shows the new email message as topmost window.
>
> //Clean up
> oRecips = null;
> oRecip = null;
> oMsg = null;
> oApp = null;
> }
> catch (Exception Ex)
> {
> MessageBox.Show("Tried to email PO but failed");
> }
> }
> else
> MessageBox.Show("PO must be approved before it can be sent out");
>
>
> }
>
So I just went through this same problem with Databse Logon and I fixed it as follows


Open the Report in Crystal Developer, -> Load in a NEW XML file (rencelty printed) -> Refresh the Data Source (in my case it said the DB was out of date and fixed a field or two for me)

Save the File

TADA it all works, maybe this will work for you. I was doing the same thing exporting from Cyrstal using code.



Jose C Gomez
Software Engineer


T: 904.469.1524 mobile
E: jose@...
http://www.josecgomez.com

     Â


Quis custodiet ipsos custodes?


On Mon, Sep 30, 2013 at 12:40 PM, <ralmon@...> wrote:

Â
<div>
  
  
  <p></p><p>Ok, been trying to get this to work for a while now and I can&#39;t find the DLL files. I have run searches on my computer and tried to browse to different paths, the only thing i can find are MSIL with these names, and i can&#39;t copy these.  So what is the best way move the DLL file into the client folder. </p>


Thanks,
Bobby



---In vantage@yahoogroups.com, <brett.manners@...> wrote:

I managed to get this working with some help from out VAR. In the end we had to rebuild the PO report in crystal as the dataset I was getting from Epicor didn't match what the report was expecting for some reason.

Here is the code:


// **************************************************
// Custom code for POEntryForm
// Created: 15/02/2013 9:50:29 AM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Epicor.Mfg.BO;
using Epicor.Mfg.UI;
using Epicor.Mfg.UI.Adapters;
using Epicor.Mfg.UI.Customization;
using Epicor.Mfg.UI.ExtendedProps;
using Epicor.Mfg.UI.FormFunctions;
using Epicor.Mfg.UI.FrameWork;
using Epicor.Mfg.UI.Searches;

using Outlook = Microsoft.Office.Interop.Outlook;
using Epicor.Mfg.Rpt;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Epicor.Mfg.Core;
using System.IO;


public class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **

// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **

public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization

// End Wizard Added Variable Initialization

// Begin Wizard Added Custom Method Calls

this.epiButtonC1.Click += new System.EventHandler(this.epiButtonC1_Click);
// End Wizard Added Custom Method Calls
}

public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal

this.epiButtonC1.Click -= new System.EventHandler(this.epiButtonC1_Click);
// End Wizard Added Object Disposal

// Begin Custom Code Disposal

// End Custom Code Disposal
}

private void epiButtonC1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **

// This customisation requires 3 .dll files for the email automation to work. These files must exsist in the client
// folder on the client machine before the customistaion can load.
// The files are:
// - Microsoft.Office.Interop.Outlook.dll
// - CrystalDeceisions.Shared.dll
// - CrystalDecsicions.CrystalReports.Engine.dll


EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
int PONUM;
string Approved;


// check if there is data loaded into the form. if not return from method.
if ( (bool)edvPOHeader.HasRow == false )
{
MessageBox.Show("No Data to email ...");
return;
}

// Get data from the form
Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];

if (Approved == "A")
{
// check the supplier has an email address in Purchase Point.
// grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
string PPemailAddress;

PPemailAddress = epiTextBoxC3.Text;
if (PPemailAddress == "")
{
MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
return; // bailout - no email address...
}

// Make the report from the PO data
POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
POFormDataSet POFormDS;

POFormDS = Form.GetNewParameters();

// set the PO number and report style and submit the form to the system agent.
POFormDS.POFormParam[0].PONum = PONUM;
POFormDS.POFormParam[0].ReportStyleNum = 1001;
POFormDS.POFormParam[0].WorkstationID = String.Format("{0}",PONUM); // Using the PO number as the WorkstationID so it is easy to reteive this report
Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.

// make the crystal report
ReportDocument repDoc = new ReportDocument();
repDoc.Load(@"\\#####\Epicor905\Server\reports\CustomReports\POForm.rpt"); //get report definition....Once this is working should lookup the report location.

// get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
// we want, we can then use the sysrowID to get the report data to put into the crystal report.
ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
ReportMonitorDataSet RMds;
bool morepages;
ReportDataDataSet reportDS = new ReportDataDataSet();

// setup a loop to look for when the report has been generated.
int timer=0;
RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='"+PONUM+"'", 0, 0, out morepages);
while (RMds.SysRptLst.Count == 0 );
{
RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='"+PONUM+"'", 0, 0, out morepages);
System.Threading.Thread.Sleep(1000);
timer = timer + 1;
if (timer > 30)
{
MessageBox.Show("Well, I have been trying to make a pdf of the PO for a while now and I just can't do it....I give up!");
return;
}
}

string sFilePath;
sFilePath = RMds.SysRptLst[0].FileName.ToString();
reportDS.ReadXml(sFilePath , System.Data.XmlReadMode.Auto);
reportDS.WriteXml(sFilePath, System.Data.XmlWriteMode.WriteSchema);

repDoc.SetDataSource(reportDS);
repDoc.Refresh();

// make a pdf of the PO from the report
string FileName = String.Format(@"\\###\EpicorData\{0}.pdf", PONUM);
ExportOptions CrExportOptions ;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = FileName;
CrExportOptions = repDoc.ExportOptions;

CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
repDoc.Export();


// create email message
try
{
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector MsgInspector = oMsg.GetInspector;
string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** TMT PO number " + PONUM.ToString();
oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. Â <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p>Â </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;
				<br>
				Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;<br>
				// Change the recipient in the next line if necessary.<br>
				Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);<br>
				oRecip.Resolve();<br>
				<br>
				// Attach pdf of PO, terms, and any other attachments to PO.<br>
				oMsg.Attachments.Add(@&quot;&#92;&#92;####&#92;Purchase Order Terms and Conditions.pdf&quot;,Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);<br>
				oMsg.Attachments.Add(FileName,Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);<br>
				<br>
				MsgInspector.Activate();   // shows the new email message as topmost window.<br>
				<br>
				//Clean up<br>
				oRecips = null;<br>
				oRecip = null;<br>
				oMsg = null;<br>
				oApp = null;<br>
				File.Delete(FileName);<br>
				}<br>
			catch (Exception Ex)<br>
				{<br>
				MessageBox.Show(&quot;Tried to email PO but failed.....Really, I did try, I dont know what went wrong...better call the system admin&quot;);<br>
				}<br>
		}<br>
	else<br>
		MessageBox.Show(&quot;PO must be approved before it can be sent out&quot;);<br>

}

}







--- In vantage@yahoogroups.com, "brettmanners" <bmanners@...> wrote:
>
> Greetings all,
>
> I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.

>

> I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong…

>

> I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it…

>

>

> Here is the code…

>

> private void epiButtonC1_Click(object sender, System.EventArgs args)

> {

> // ** Place Event Handling Code Here

> EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];

> int PONUM;

> string Approved;

>

>

> // check if there is data loaded into the form. if not return from method.

> if ( (bool)edvPOHeader.HasRow == false )

> {

> MessageBox.Show("No Data to email …");

> return;

> }

>

> // Get data from the form

> Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];

> PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];

>

> if (Approved == "A")

> {

> // check the supplier has an email address in Purchase Point.

> // grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there…

> string PPemailAddress;

>

> PPemailAddress = epiTextBoxC3.Text;

> if (PPemailAddress == "")

> {

> MessageBox.Show("No Email address. Add address to Supplier Purchase Point");

> return; // bailout - no email address…

> }

>

>

> // Make the report from the PO data

> POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);

> POFormDataSet POFormDS;

>

> POFormDS = Form.GetNewParameters();

> POFormDS.POFormParam[0].PONum = PONUM;

> POFormDS.POFormParam[0].ReportStyleNum = 1001;

> Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.

>

> // Need to wait for report to be generated before continuing…

> System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues…

>

> // make the crystal report

> ReportDocument repDoc = new ReportDocument();

> repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm.rpt"); //get report definition…Once this is working should lookup the report location.

>

> // get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report

> // we want, we can then use the sysrowID to get the report data to put into the crystal report.

> ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);

> ReportMonitorDataSet RMds;

> bool morepages;

> ReportDataDataSet reportDS;

>

> RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.

>

> MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing

>

> reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.

>

>

>

> repDoc.SetDataSource(reportDS);

> repDoc.Refresh();

> MessageBox.Show("finished creating report");

>

> // make a pdf of the PO from the report

> string FileName = @"\\XXXX\EpicorData\test.pdf";

> ExportOptions CrExportOptions ;

> DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();

> PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();

> CrDiskFileDestinationOptions.DiskFileName = FileName;

> CrExportOptions = repDoc.ExportOptions;

>

> CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

> CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

> CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;

> CrExportOptions.FormatOptions = CrFormatTypeOptions;

> repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@

> MessageBox.Show("finished saving report as pdf");

>

> // create email message

> try

> {

> Outlook.Application oApp = new Outlook.Application();

> Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

> Outlook.Inspector MsgInspector = oMsg.GetInspector;

> string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.

> oMsg.Subject = "
** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();

> oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. Â <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p>Â </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;

>

> Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;

> // Change the recipient in the next line if necessary.

> Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);

> oRecip.Resolve();

>

> // Attach pdf of PO, terms, and any other attachments to PO.

> oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);

> oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);

>

> MsgInspector.Activate(); // shows the new email message as topmost window.

>

> //Clean up

> oRecips = null;

> oRecip = null;

> oMsg = null;

> oApp = null;

> }

> catch (Exception Ex)

> {

> MessageBox.Show("Tried to email PO but failed");

> }

> }

> else

> MessageBox.Show("PO must be approved before it can be sent out");

>

>

> }

>


</div>
 


<div style="color:#fff;min-height:0;"></div>

I'm not having a logon issue yet...I receive the following errors when I post into the Script editor and change all the database locations to our DB name. I have put the 3 DLL files into the client folder on my machine. 

Error: CS0234 - line 20 (20) - The type or namespace name 'Rpt' does not exist in the namespace 'Epicor.Mfg' (are you missing an assembly reference?)

 Error: CS0246 - line 21 (21) - The type or namespace name 'CrystalDecisions' could not be found (are you missing a using directive or an assembly reference?)

 Error: CS0246 - line 22 (22) - The type or namespace name 'CrystalDecisions' could not be found (are you missing a using directive or an assembly reference?)

 Error: CS0234 - line 19 (19) - The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)



What am i doing wrong??


---In vantage@yahoogroups.com, <jose@...> wrote:

So I just went through this same problem with Databse Logon and I fixed it as follows


Open the Report in Crystal Developer, -> Load in a NEW XML file (rencelty printed) -> Refresh the Data Source (in my case it said the DB was out of date and fixed a field or two for me)

Save the File

TADA it all works, maybe this will work for you. I was doing the same thing exporting from Cyrstal using code.



Jose C Gomez
Software Engineer


T: 904.469.1524 mobile


Quis custodiet ipsos custodes?


On Mon, Sep 30, 2013 at 12:40 PM, <ralmon@...> wrote:

 
<div>
  
  
  <p>Ok, been trying to get this to work for a while now and I can&#39;t find the DLL files. I have run searches on my computer and tried to browse to different paths, the only thing i can find are MSIL with these names, and i can&#39;t copy these. &nbsp;So what is the best way move the DLL file into the client folder.&nbsp;</p>


Thanks,
Bobby



---In vantage@yahoogroups.com, <brett.manners@...> wrote:

I managed to get this working with some help from out VAR. In the end we had to rebuild the PO report in crystal as the dataset I was getting from Epicor didn't match what the report was expecting for some reason.

Here is the code:


// **************************************************
// Custom code for POEntryForm
// Created: 15/02/2013 9:50:29 AM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Epicor.Mfg.BO;
using Epicor.Mfg.UI;
using Epicor.Mfg.UI.Adapters;
using Epicor.Mfg.UI.Customization;
using Epicor.Mfg.UI.ExtendedProps;
using Epicor.Mfg.UI.FormFunctions;
using Epicor.Mfg.UI.FrameWork;
using Epicor.Mfg.UI.Searches;

using Outlook = Microsoft.Office.Interop.Outlook;
using Epicor.Mfg.Rpt;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Epicor.Mfg.Core;
using System.IO;


public class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **

// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **

public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization

// End Wizard Added Variable Initialization

// Begin Wizard Added Custom Method Calls

this.epiButtonC1.Click += new System.EventHandler(this.epiButtonC1_Click);
// End Wizard Added Custom Method Calls
}

public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal

this.epiButtonC1.Click -= new System.EventHandler(this.epiButtonC1_Click);
// End Wizard Added Object Disposal

// Begin Custom Code Disposal

// End Custom Code Disposal
}

private void epiButtonC1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **

// This customisation requires 3 .dll files for the email automation to work. These files must exsist in the client
// folder on the client machine before the customistaion can load.
// The files are:
// - Microsoft.Office.Interop.Outlook.dll
// - CrystalDeceisions.Shared.dll
// - CrystalDecsicions.CrystalReports.Engine.dll


EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
int PONUM;
string Approved;


// check if there is data loaded into the form. if not return from method.
if ( (bool)edvPOHeader.HasRow == false )
{
MessageBox.Show("No Data to email ...");
return;
}

// Get data from the form
Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];

if (Approved == "A")
{
// check the supplier has an email address in Purchase Point.
// grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
string PPemailAddress;

PPemailAddress = epiTextBoxC3.Text;
if (PPemailAddress == "")
{
MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
return; // bailout - no email address...
}

// Make the report from the PO data
POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
POFormDataSet POFormDS;

POFormDS = Form.GetNewParameters();

// set the PO number and report style and submit the form to the system agent.
POFormDS.POFormParam[0].PONum = PONUM;
POFormDS.POFormParam[0].ReportStyleNum = 1001;
POFormDS.POFormParam[0].WorkstationID = String.Format("{0}",PONUM); // Using the PO number as the WorkstationID so it is easy to reteive this report
Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.

// make the crystal report
ReportDocument repDoc = new ReportDocument();
repDoc.Load(@"\\#####\Epicor905\Server\reports\CustomReports\POForm.rpt"); //get report definition....Once this is working should lookup the report location.

// get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
// we want, we can then use the sysrowID to get the report data to put into the crystal report.
ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
ReportMonitorDataSet RMds;
bool morepages;
ReportDataDataSet reportDS = new ReportDataDataSet();

// setup a loop to look for when the report has been generated.
int timer=0;
RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='"+PONUM+"'", 0, 0, out morepages);
while (RMds.SysRptLst.Count == 0 );
{
RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='"+PONUM+"'", 0, 0, out morepages);
System.Threading.Thread.Sleep(1000);
timer = timer + 1;
if (timer > 30)
{
MessageBox.Show("Well, I have been trying to make a pdf of the PO for a while now and I just can't do it....I give up!");
return;
}
}

string sFilePath;
sFilePath = RMds.SysRptLst[0].FileName.ToString();
reportDS.ReadXml(sFilePath , System.Data.XmlReadMode.Auto);
reportDS.WriteXml(sFilePath, System.Data.XmlWriteMode.WriteSchema);

repDoc.SetDataSource(reportDS);
repDoc.Refresh();

// make a pdf of the PO from the report
string FileName = String.Format(@"\\###\EpicorData\{0}.pdf", PONUM);
ExportOptions CrExportOptions ;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = FileName;
CrExportOptions = repDoc.ExportOptions;

CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
repDoc.Export();


// create email message
try
{
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector MsgInspector = oMsg.GetInspector;
string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** TMT PO number " + PONUM.ToString();
oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order.  <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;
				<br>
				Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;<br>
				// Change the recipient in the next line if necessary.<br>
				Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);<br>
				oRecip.Resolve();<br>
				<br>
				// Attach pdf of PO, terms, and any other attachments to PO.<br>
				oMsg.Attachments.Add(@&quot;&#92;&#92;####&#92;Purchase Order Terms and Conditions.pdf&quot;,Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);<br>
				oMsg.Attachments.Add(FileName,Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);<br>
				<br>
				MsgInspector.Activate();   // shows the new email message as topmost window.<br>
				<br>
				//Clean up<br>
				oRecips = null;<br>
				oRecip = null;<br>
				oMsg = null;<br>
				oApp = null;<br>
				File.Delete(FileName);<br>
				}<br>
			catch (Exception Ex)<br>
				{<br>
				MessageBox.Show(&quot;Tried to email PO but failed.....Really, I did try, I dont know what went wrong...better call the system admin&quot;);<br>
				}<br>
		}<br>
	else<br>
		MessageBox.Show(&quot;PO must be approved before it can be sent out&quot;);<br>

}

}







--- In vantage@yahoogroups.com, "brettmanners" <bmanners@...> wrote:
>
> Greetings all,
>
> I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.

>

> I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong…

>

> I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it…

>

>

> Here is the code…

>

> private void epiButtonC1_Click(object sender, System.EventArgs args)

> {

> // ** Place Event Handling Code Here

> EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];

> int PONUM;

> string Approved;

>

>

> // check if there is data loaded into the form. if not return from method.

> if ( (bool)edvPOHeader.HasRow == false )

> {

> MessageBox.Show("No Data to email …");

> return;

> }

>

> // Get data from the form

> Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];

> PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];

>

> if (Approved == "A")

> {

> // check the supplier has an email address in Purchase Point.

> // grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there…

> string PPemailAddress;

>

> PPemailAddress = epiTextBoxC3.Text;

> if (PPemailAddress == "")

> {

> MessageBox.Show("No Email address. Add address to Supplier Purchase Point");

> return; // bailout - no email address…

> }

>

>

> // Make the report from the PO data

> POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);

> POFormDataSet POFormDS;

>

> POFormDS = Form.GetNewParameters();

> POFormDS.POFormParam[0].PONum = PONUM;

> POFormDS.POFormParam[0].ReportStyleNum = 1001;

> Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.

>

> // Need to wait for report to be generated before continuing…

> System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues…

>

> // make the crystal report

> ReportDocument repDoc = new ReportDocument();

> repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm.rpt"); //get report definition…Once this is working should lookup the report location.

>

> // get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report

> // we want, we can then use the sysrowID to get the report data to put into the crystal report.

> ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);

> ReportMonitorDataSet RMds;

> bool morepages;

> ReportDataDataSet reportDS;

>

> RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.

>

> MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing

>

> reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.

>

>

>

> repDoc.SetDataSource(reportDS);

> repDoc.Refresh();

> MessageBox.Show("finished creating report");

>

> // make a pdf of the PO from the report

> string FileName = @"\\XXXX\EpicorData\test.pdf";

> ExportOptions CrExportOptions ;

> DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();

> PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();

> CrDiskFileDestinationOptions.DiskFileName = FileName;

> CrExportOptions = repDoc.ExportOptions;

>

> CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

> CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

> CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;

> CrExportOptions.FormatOptions = CrFormatTypeOptions;

> repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@

> MessageBox.Show("finished saving report as pdf");

>

> // create email message

> try

> {

> Outlook.Application oApp = new Outlook.Application();

> Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

> Outlook.Inspector MsgInspector = oMsg.GetInspector;

> string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.

> oMsg.Subject = "
** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();

> oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order.  <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;

>

> Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;

> // Change the recipient in the next line if necessary.

> Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);

> oRecip.Resolve();

>

> // Attach pdf of PO, terms, and any other attachments to PO.

> oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);

> oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);

>

> MsgInspector.Activate(); // shows the new email message as topmost window.

>

> //Clean up

> oRecips = null;

> oRecip = null;

> oMsg = null;

> oApp = null;

> }

> catch (Exception Ex)

> {

> MessageBox.Show("Tried to email PO but failed");

> }

> }

> else

> MessageBox.Show("PO must be approved before it can be sent out");

>

>

> }

>


</div>
 


<div style="color:#fff;min-height:0;"></div>



Jose C Gomez
Software Engineer


T: 904.469.1524 mobile
E: jose@...
http://www.josecgomez.com

     Â


Quis custodiet ipsos custodes?


On Tue, Oct 1, 2013 at 12:27 PM, <ralmon@...> wrote:

Â
<div>
  
  
  <p></p><p>I&#39;m not having a logon issue yet...I receive the following errors when I post into the Script editor and change all the database locations to our DB name. I have put the 3 DLL files into the client folder on my machine. </p>

Error: CS0234 - line 20 (20) - The type or namespace name 'Rpt' does not exist in the namespace 'Epicor.Mfg' (are you missing an assembly reference?)

 Error: CS0246 - line 21 (21) - The type or namespace name 'CrystalDecisions' could not be found (are you missing a using directive or an assembly reference?)

 Error: CS0246 - line 22 (22) - The type or namespace name 'CrystalDecisions' could not be found (are you missing a using directive or an assembly reference?)

 Error: CS0234 - line 19 (19) - The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)



What am i doing wrong??


---In vantage@yahoogroups.com, <jose@...> wrote:

So I just went through this same problem with Databse Logon and I fixed it as follows


Open the Report in Crystal Developer, -> Load in a NEW XML file (rencelty printed) -> Refresh the Data Source (in my case it said the DB was out of date and fixed a field or two for me)

Save the File

TADA it all works, maybe this will work for you. I was doing the same thing exporting from Cyrstal using code.



Jose C Gomez
Software Engineer


T: 904.469.1524 mobile
E: jose@...
http://www.josecgomez.com

     Â


Quis custodiet ipsos custodes?


On Mon, Sep 30, 2013 at 12:40 PM, <ralmon@...> wrote:

Â
<div>
  
  
  <p>Ok, been trying to get this to work for a while now and I can&#39;t find the DLL files. I have run searches on my computer and tried to browse to different paths, the only thing i can find are MSIL with these names, and i can&#39;t copy these.  So what is the best way move the DLL file into the client folder. </p>


Thanks,
Bobby



---In vantage@yahoogroups.com, <brett.manners@...> wrote:

I managed to get this working with some help from out VAR. In the end we had to rebuild the PO report in crystal as the dataset I was getting from Epicor didn't match what the report was expecting for some reason.

Here is the code:


// **************************************************
// Custom code for POEntryForm
// Created: 15/02/2013 9:50:29 AM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Epicor.Mfg.BO;
using Epicor.Mfg.UI;
using Epicor.Mfg.UI.Adapters;
using Epicor.Mfg.UI.Customization;
using Epicor.Mfg.UI.ExtendedProps;
using Epicor.Mfg.UI.FormFunctions;
using Epicor.Mfg.UI.FrameWork;
using Epicor.Mfg.UI.Searches;

using Outlook = Microsoft.Office.Interop.Outlook;
using Epicor.Mfg.Rpt;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Epicor.Mfg.Core;
using System.IO;


public class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **

// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **

public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization

// End Wizard Added Variable Initialization

// Begin Wizard Added Custom Method Calls

this.epiButtonC1.Click += new System.EventHandler(this.epiButtonC1_Click);
// End Wizard Added Custom Method Calls
}

public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal

this.epiButtonC1.Click -= new System.EventHandler(this.epiButtonC1_Click);
// End Wizard Added Object Disposal

// Begin Custom Code Disposal

// End Custom Code Disposal
}

private void epiButtonC1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **

// This customisation requires 3 .dll files for the email automation to work. These files must exsist in the client
// folder on the client machine before the customistaion can load.
// The files are:
// - Microsoft.Office.Interop.Outlook.dll
// - CrystalDeceisions.Shared.dll
// - CrystalDecsicions.CrystalReports.Engine.dll


EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
int PONUM;
string Approved;


// check if there is data loaded into the form. if not return from method.
if ( (bool)edvPOHeader.HasRow == false )
{
MessageBox.Show("No Data to email ...");
return;
}

// Get data from the form
Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];

if (Approved == "A")
{
// check the supplier has an email address in Purchase Point.
// grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
string PPemailAddress;

PPemailAddress = epiTextBoxC3.Text;
if (PPemailAddress == "")
{
MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
return; // bailout - no email address...
}

// Make the report from the PO data
POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
POFormDataSet POFormDS;

POFormDS = Form.GetNewParameters();

// set the PO number and report style and submit the form to the system agent.
POFormDS.POFormParam[0].PONum = PONUM;
POFormDS.POFormParam[0].ReportStyleNum = 1001;
POFormDS.POFormParam[0].WorkstationID = String.Format("{0}",PONUM); // Using the PO number as the WorkstationID so it is easy to reteive this report
Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.

// make the crystal report
ReportDocument repDoc = new ReportDocument();
repDoc.Load(@"\\#####\Epicor905\Server\reports\CustomReports\POForm.rpt"); //get report definition....Once this is working should lookup the report location.

// get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
// we want, we can then use the sysrowID to get the report data to put into the crystal report.
ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
ReportMonitorDataSet RMds;
bool morepages;
ReportDataDataSet reportDS = new ReportDataDataSet();

// setup a loop to look for when the report has been generated.
int timer=0;
RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='"+PONUM+"'", 0, 0, out morepages);
while (RMds.SysRptLst.Count == 0 );
{
RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='"+PONUM+"'", 0, 0, out morepages);
System.Threading.Thread.Sleep(1000);
timer = timer + 1;
if (timer > 30)
{
MessageBox.Show("Well, I have been trying to make a pdf of the PO for a while now and I just can't do it....I give up!");
return;
}
}

string sFilePath;
sFilePath = RMds.SysRptLst[0].FileName.ToString();
reportDS.ReadXml(sFilePath , System.Data.XmlReadMode.Auto);
reportDS.WriteXml(sFilePath, System.Data.XmlWriteMode.WriteSchema);

repDoc.SetDataSource(reportDS);
repDoc.Refresh();

// make a pdf of the PO from the report
string FileName = String.Format(@"\\###\EpicorData\{0}.pdf", PONUM);
ExportOptions CrExportOptions ;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = FileName;
CrExportOptions = repDoc.ExportOptions;

CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
repDoc.Export();


// create email message
try
{
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector MsgInspector = oMsg.GetInspector;
string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** TMT PO number " + PONUM.ToString();
oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. Â <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p>Â </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;
				<br>
				Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;<br>
				// Change the recipient in the next line if necessary.<br>
				Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);<br>
				oRecip.Resolve();<br>
				<br>
				// Attach pdf of PO, terms, and any other attachments to PO.<br>
				oMsg.Attachments.Add(@&quot;&#92;&#92;####&#92;Purchase Order Terms and Conditions.pdf&quot;,Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);<br>
				oMsg.Attachments.Add(FileName,Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);<br>
				<br>
				MsgInspector.Activate();   // shows the new email message as topmost window.<br>
				<br>
				//Clean up<br>
				oRecips = null;<br>
				oRecip = null;<br>
				oMsg = null;<br>
				oApp = null;<br>
				File.Delete(FileName);<br>
				}<br>
			catch (Exception Ex)<br>
				{<br>
				MessageBox.Show(&quot;Tried to email PO but failed.....Really, I did try, I dont know what went wrong...better call the system admin&quot;);<br>
				}<br>
		}<br>
	else<br>
		MessageBox.Show(&quot;PO must be approved before it can be sent out&quot;);<br>

}

}







--- In vantage@yahoogroups.com, "brettmanners" <bmanners@...> wrote:
>
> Greetings all,
>
> I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.

>

> I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong…

>

> I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it…

>

>

> Here is the code…

>

> private void epiButtonC1_Click(object sender, System.EventArgs args)

> {

> // ** Place Event Handling Code Here

> EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];

> int PONUM;

> string Approved;

>

>

> // check if there is data loaded into the form. if not return from method.

> if ( (bool)edvPOHeader.HasRow == false )

> {

> MessageBox.Show("No Data to email …");

> return;

> }

>

> // Get data from the form

> Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];

> PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];

>

> if (Approved == "A")

> {

> // check the supplier has an email address in Purchase Point.

> // grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there…

> string PPemailAddress;

>

> PPemailAddress = epiTextBoxC3.Text;

> if (PPemailAddress == "")

> {

> MessageBox.Show("No Email address. Add address to Supplier Purchase Point");

> return; // bailout - no email address…

> }

>

>

> // Make the report from the PO data

> POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);

> POFormDataSet POFormDS;

>

> POFormDS = Form.GetNewParameters();

> POFormDS.POFormParam[0].PONum = PONUM;

> POFormDS.POFormParam[0].ReportStyleNum = 1001;

> Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.

>

> // Need to wait for report to be generated before continuing…

> System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues…

>

> // make the crystal report

> ReportDocument repDoc = new ReportDocument();

> repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm.rpt"); //get report definition…Once this is working should lookup the report location.

>

> // get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report

> // we want, we can then use the sysrowID to get the report data to put into the crystal report.

> ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);

> ReportMonitorDataSet RMds;

> bool morepages;

> ReportDataDataSet reportDS;

>

> RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.

>

> MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing

>

> reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.

>

>

>

> repDoc.SetDataSource(reportDS);

> repDoc.Refresh();

> MessageBox.Show("finished creating report");

>

> // make a pdf of the PO from the report

> string FileName = @"\\XXXX\EpicorData\test.pdf";

> ExportOptions CrExportOptions ;

> DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();

> PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();

> CrDiskFileDestinationOptions.DiskFileName = FileName;

> CrExportOptions = repDoc.ExportOptions;

>

> CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

> CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

> CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;

> CrExportOptions.FormatOptions = CrFormatTypeOptions;

> repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@

> MessageBox.Show("finished saving report as pdf");

>

> // create email message

> try

> {

> Outlook.Application oApp = new Outlook.Application();

> Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

> Outlook.Inspector MsgInspector = oMsg.GetInspector;

> string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.

> oMsg.Subject = "
** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();

> oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. Â <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p>Â </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;

>

> Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;

> // Change the recipient in the next line if necessary.

> Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);

> oRecip.Resolve();

>

> // Attach pdf of PO, terms, and any other attachments to PO.

> oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);

> oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);

>

> MsgInspector.Activate(); // shows the new email message as topmost window.

>

> //Clean up

> oRecips = null;

> oRecip = null;

> oMsg = null;

> oApp = null;

> }

> catch (Exception Ex)

> {

> MessageBox.Show("Tried to email PO but failed");

> }

> }

> else

> MessageBox.Show("PO must be approved before it can be sent out");

>

>

> }

>


</div>
 


<div style="color:#fff;"></div>

</div>
 


<div style="color:#fff;min-height:0;"></div>

 Hi,

I've been following this thread and our requirement is similar, but to close a Case then email a call closure acknowledgement to the client who raised the case in the first place. I have got is all working, Filesystem watcher.  It works ok.  The one question I have is that a majority of our users are on Outlook 2003 (don't ask).  We get the security warning about another program is attempting to access your address book.  You don't get the option to permanently disable the warning!  This error message does not occur if you have Outlook 2007.


I have seen a few solutions from using Outlook redemption. Resource Kit Security templates or an Outlook Addin to manage.  I am wondering if anyone else has struck this and how they rectified it?  I proposing to get our Outlook 2003 clients upgraded, a bit of a sledgehammer approach, but it does get us closer to a more standardized operating environment.


Any feedback appreciated.


Simon Hall




---In vantage@yahoogroups.com, <jose@...> wrote:



Jose C Gomez
Software Engineer


T: 904.469.1524 mobile


Quis custodiet ipsos custodes?


On Tue, Oct 1, 2013 at 12:27 PM, <ralmon@...> wrote:

 
<div>
  
  
  <p>I&#39;m not having a logon issue yet...I receive the following errors when I post into the Script editor and change all the database locations to our DB name. I have put the 3 DLL files into the client folder on my machine.&nbsp;</p>

Error: CS0234 - line 20 (20) - The type or namespace name 'Rpt' does not exist in the namespace 'Epicor.Mfg' (are you missing an assembly reference?)

 Error: CS0246 - line 21 (21) - The type or namespace name 'CrystalDecisions' could not be found (are you missing a using directive or an assembly reference?)

 Error: CS0246 - line 22 (22) - The type or namespace name 'CrystalDecisions' could not be found (are you missing a using directive or an assembly reference?)

 Error: CS0234 - line 19 (19) - The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)



What am i doing wrong??


---In vantage@yahoogroups.com, <jose@...> wrote:

So I just went through this same problem with Databse Logon and I fixed it as follows


Open the Report in Crystal Developer, -> Load in a NEW XML file (rencelty printed) -> Refresh the Data Source (in my case it said the DB was out of date and fixed a field or two for me)

Save the File

TADA it all works, maybe this will work for you. I was doing the same thing exporting from Cyrstal using code.



Jose C Gomez
Software Engineer


T: 904.469.1524 mobile


Quis custodiet ipsos custodes?


On Mon, Sep 30, 2013 at 12:40 PM, <ralmon@...> wrote:

 
<div>
  
  
  <p>Ok, been trying to get this to work for a while now and I can&#39;t find the DLL files. I have run searches on my computer and tried to browse to different paths, the only thing i can find are MSIL with these names, and i can&#39;t copy these. &nbsp;So what is the best way move the DLL file into the client folder.&nbsp;</p>


Thanks,
Bobby



---In vantage@yahoogroups.com, <brett.manners@...> wrote:

I managed to get this working with some help from out VAR. In the end we had to rebuild the PO report in crystal as the dataset I was getting from Epicor didn't match what the report was expecting for some reason.

Here is the code:


// **************************************************
// Custom code for POEntryForm
// Created: 15/02/2013 9:50:29 AM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Epicor.Mfg.BO;
using Epicor.Mfg.UI;
using Epicor.Mfg.UI.Adapters;
using Epicor.Mfg.UI.Customization;
using Epicor.Mfg.UI.ExtendedProps;
using Epicor.Mfg.UI.FormFunctions;
using Epicor.Mfg.UI.FrameWork;
using Epicor.Mfg.UI.Searches;

using Outlook = Microsoft.Office.Interop.Outlook;
using Epicor.Mfg.Rpt;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Epicor.Mfg.Core;
using System.IO;


public class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **

// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **

public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization

// End Wizard Added Variable Initialization

// Begin Wizard Added Custom Method Calls

this.epiButtonC1.Click += new System.EventHandler(this.epiButtonC1_Click);
// End Wizard Added Custom Method Calls
}

public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal

this.epiButtonC1.Click -= new System.EventHandler(this.epiButtonC1_Click);
// End Wizard Added Object Disposal

// Begin Custom Code Disposal

// End Custom Code Disposal
}

private void epiButtonC1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **

// This customisation requires 3 .dll files for the email automation to work. These files must exsist in the client
// folder on the client machine before the customistaion can load.
// The files are:
// - Microsoft.Office.Interop.Outlook.dll
// - CrystalDeceisions.Shared.dll
// - CrystalDecsicions.CrystalReports.Engine.dll


EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
int PONUM;
string Approved;


// check if there is data loaded into the form. if not return from method.
if ( (bool)edvPOHeader.HasRow == false )
{
MessageBox.Show("No Data to email ...");
return;
}

// Get data from the form
Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];

if (Approved == "A")
{
// check the supplier has an email address in Purchase Point.
// grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
string PPemailAddress;

PPemailAddress = epiTextBoxC3.Text;
if (PPemailAddress == "")
{
MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
return; // bailout - no email address...
}

// Make the report from the PO data
POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
POFormDataSet POFormDS;

POFormDS = Form.GetNewParameters();

// set the PO number and report style and submit the form to the system agent.
POFormDS.POFormParam[0].PONum = PONUM;
POFormDS.POFormParam[0].ReportStyleNum = 1001;
POFormDS.POFormParam[0].WorkstationID = String.Format("{0}",PONUM); // Using the PO number as the WorkstationID so it is easy to reteive this report
Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.

// make the crystal report
ReportDocument repDoc = new ReportDocument();
repDoc.Load(@"\\#####\Epicor905\Server\reports\CustomReports\POForm.rpt"); //get report definition....Once this is working should lookup the report location.

// get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
// we want, we can then use the sysrowID to get the report data to put into the crystal report.
ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
ReportMonitorDataSet RMds;
bool morepages;
ReportDataDataSet reportDS = new ReportDataDataSet();

// setup a loop to look for when the report has been generated.
int timer=0;
RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='"+PONUM+"'", 0, 0, out morepages);
while (RMds.SysRptLst.Count == 0 );
{
RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='"+PONUM+"'", 0, 0, out morepages);
System.Threading.Thread.Sleep(1000);
timer = timer + 1;
if (timer > 30)
{
MessageBox.Show("Well, I have been trying to make a pdf of the PO for a while now and I just can't do it....I give up!");
return;
}
}

string sFilePath;
sFilePath = RMds.SysRptLst[0].FileName.ToString();
reportDS.ReadXml(sFilePath , System.Data.XmlReadMode.Auto);
reportDS.WriteXml(sFilePath, System.Data.XmlWriteMode.WriteSchema);

repDoc.SetDataSource(reportDS);
repDoc.Refresh();

// make a pdf of the PO from the report
string FileName = String.Format(@"\\###\EpicorData\{0}.pdf", PONUM);
ExportOptions CrExportOptions ;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = FileName;
CrExportOptions = repDoc.ExportOptions;

CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
repDoc.Export();


// create email message
try
{
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector MsgInspector = oMsg.GetInspector;
string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** TMT PO number " + PONUM.ToString();
oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order.  <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;
				<br>
				Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;<br>
				// Change the recipient in the next line if necessary.<br>
				Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);<br>
				oRecip.Resolve();<br>
				<br>
				// Attach pdf of PO, terms, and any other attachments to PO.<br>
				oMsg.Attachments.Add(@&quot;&#92;&#92;####&#92;Purchase Order Terms and Conditions.pdf&quot;,Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);<br>
				oMsg.Attachments.Add(FileName,Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);<br>
				<br>
				MsgInspector.Activate();   // shows the new email message as topmost window.<br>
				<br>
				//Clean up<br>
				oRecips = null;<br>
				oRecip = null;<br>
				oMsg = null;<br>
				oApp = null;<br>
				File.Delete(FileName);<br>
				}<br>
			catch (Exception Ex)<br>
				{<br>
				MessageBox.Show(&quot;Tried to email PO but failed.....Really, I did try, I dont know what went wrong...better call the system admin&quot;);<br>
				}<br>
		}<br>
	else<br>
		MessageBox.Show(&quot;PO must be approved before it can be sent out&quot;);<br>

}

}







--- In vantage@yahoogroups.com, "brettmanners" <bmanners@...> wrote:
>
> Greetings all,
>
> I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.

>

> I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong…

>

> I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it…

>

>

> Here is the code…

>

> private void epiButtonC1_Click(object sender, System.EventArgs args)

> {

> // ** Place Event Handling Code Here

> EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];

> int PONUM;

> string Approved;

>

>

> // check if there is data loaded into the form. if not return from method.

> if ( (bool)edvPOHeader.HasRow == false )

> {

> MessageBox.Show("No Data to email …");

> return;

> }

>

> // Get data from the form

> Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];

> PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];

>

> if (Approved == "A")

> {

> // check the supplier has an email address in Purchase Point.

> // grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there…

> string PPemailAddress;

>

> PPemailAddress = epiTextBoxC3.Text;

> if (PPemailAddress == "")

> {

> MessageBox.Show("No Email address. Add address to Supplier Purchase Point");

> return; // bailout - no email address…

> }

>

>

> // Make the report from the PO data

> POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);

> POFormDataSet POFormDS;

>

> POFormDS = Form.GetNewParameters();

> POFormDS.POFormParam[0].PONum = PONUM;

> POFormDS.POFormParam[0].ReportStyleNum = 1001;

> Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.

>

> // Need to wait for report to be generated before continuing…

> System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues…

>

> // make the crystal report

> ReportDocument repDoc = new ReportDocument();

> repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm.rpt"); //get report definition…Once this is working should lookup the report location.

>

> // get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report

> // we want, we can then use the sysrowID to get the report data to put into the crystal report.

> ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);

> ReportMonitorDataSet RMds;

> bool morepages;

> ReportDataDataSet reportDS;

>

> RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.

>

> MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing

>

> reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.

>

>

>

> repDoc.SetDataSource(reportDS);

> repDoc.Refresh();

> MessageBox.Show("finished creating report");

>

> // make a pdf of the PO from the report

> string FileName = @"\\XXXX\EpicorData\test.pdf";

> ExportOptions CrExportOptions ;

> DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();

> PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();

> CrDiskFileDestinationOptions.DiskFileName = FileName;

> CrExportOptions = repDoc.ExportOptions;

>

> CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

> CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

> CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;

> CrExportOptions.FormatOptions = CrFormatTypeOptions;

> repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@

> MessageBox.Show("finished saving report as pdf");

>

> // create email message

> try

> {

> Outlook.Application oApp = new Outlook.Application();

> Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

> Outlook.Inspector MsgInspector = oMsg.GetInspector;

> string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.

> oMsg.Subject = "
** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();

> oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order.  <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;

>

> Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;

> // Change the recipient in the next line if necessary.

> Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);

> oRecip.Resolve();

>

> // Attach pdf of PO, terms, and any other attachments to PO.

> oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);

> oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);

>

> MsgInspector.Activate(); // shows the new email message as topmost window.

>

> //Clean up

> oRecips = null;

> oRecip = null;

> oMsg = null;

> oApp = null;

> }

> catch (Exception Ex)

> {

> MessageBox.Show("Tried to email PO but failed");

> }

> }

> else

> MessageBox.Show("PO must be approved before it can be sent out");

>

>

> }

>


</div>
 


<div style="color:#fff;"></div>

</div>
 


<div style="color:#fff;min-height:0;"></div>

I think a long time ago I ran  into this and there was a fix in the registry I'll poke around to see if I can find it.


Jose C Gomez
Software Engineer


T: 904.469.1524 mobile
E: jose@...
http://www.josecgomez.com

     Â


Quis custodiet ipsos custodes?


On Thu, Nov 21, 2013 at 8:31 AM, <s1mhall@...> wrote:

Â
<div>
  
  
  <p></p><p> Hi,</p><p>I&#39;ve been following this thread and our requirement is similar, but to close a Case then email a call closure acknowledgement to the client who raised the case in the first place. I have got is all working, Filesystem watcher.  It works ok.  The one question I have is that a majority of our users are on Outlook 2003 (don&#39;t ask).  We get the security warning about another program is attempting to access your address book.  You don&#39;t get the option to permanently disable the warning!  This error message does not occur if you have Outlook 2007.<br>


I have seen a few solutions from using Outlook redemption. Resource Kit Security templates or an Outlook Addin to manage. I am wondering if anyone else has struck this and how they rectified it? I proposing to get our Outlook 2003 clients upgraded, a bit of a sledgehammer approach, but it does get us closer to a more standardized operating environment.


Any feedback appreciated.


Simon Hall




—In vantage@yahoogroups.com, <jose@…> wrote:




Jose C Gomez
Software Engineer


T: 904.469.1524 mobile
E: jose@...
http://www.josecgomez.com

     Â


Quis custodiet ipsos custodes?


On Tue, Oct 1, 2013 at 12:27 PM, <ralmon@...> wrote:

Â
<div>
  
  
  <p>I&#39;m not having a logon issue yet...I receive the following errors when I post into the Script editor and change all the database locations to our DB name. I have put the 3 DLL files into the client folder on my machine. </p>

Error: CS0234 - line 20 (20) - The type or namespace name 'Rpt' does not exist in the namespace 'Epicor.Mfg' (are you missing an assembly reference?)

 Error: CS0246 - line 21 (21) - The type or namespace name 'CrystalDecisions' could not be found (are you missing a using directive or an assembly reference?)

 Error: CS0246 - line 22 (22) - The type or namespace name 'CrystalDecisions' could not be found (are you missing a using directive or an assembly reference?)

 Error: CS0234 - line 19 (19) - The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)



What am i doing wrong??


---In vantage@yahoogroups.com, <jose@...> wrote:

So I just went through this same problem with Databse Logon and I fixed it as follows


Open the Report in Crystal Developer, -> Load in a NEW XML file (rencelty printed) -> Refresh the Data Source (in my case it said the DB was out of date and fixed a field or two for me)

Save the File

TADA it all works, maybe this will work for you. I was doing the same thing exporting from Cyrstal using code.



Jose C Gomez
Software Engineer


T: 904.469.1524 mobile
E: jose@...
http://www.josecgomez.com

     Â


Quis custodiet ipsos custodes?


On Mon, Sep 30, 2013 at 12:40 PM, <ralmon@...> wrote:

Â
<div>
  
  
  <p>Ok, been trying to get this to work for a while now and I can&#39;t find the DLL files. I have run searches on my computer and tried to browse to different paths, the only thing i can find are MSIL with these names, and i can&#39;t copy these.  So what is the best way move the DLL file into the client folder. </p>


Thanks,
Bobby



---In vantage@yahoogroups.com, <brett.manners@...> wrote:

I managed to get this working with some help from out VAR. In the end we had to rebuild the PO report in crystal as the dataset I was getting from Epicor didn't match what the report was expecting for some reason.

Here is the code:


// **************************************************
// Custom code for POEntryForm
// Created: 15/02/2013 9:50:29 AM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Epicor.Mfg.BO;
using Epicor.Mfg.UI;
using Epicor.Mfg.UI.Adapters;
using Epicor.Mfg.UI.Customization;
using Epicor.Mfg.UI.ExtendedProps;
using Epicor.Mfg.UI.FormFunctions;
using Epicor.Mfg.UI.FrameWork;
using Epicor.Mfg.UI.Searches;

using Outlook = Microsoft.Office.Interop.Outlook;
using Epicor.Mfg.Rpt;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using Epicor.Mfg.Core;
using System.IO;


public class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **

// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **

public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization

// End Wizard Added Variable Initialization

// Begin Wizard Added Custom Method Calls

this.epiButtonC1.Click += new System.EventHandler(this.epiButtonC1_Click);
// End Wizard Added Custom Method Calls
}

public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal

this.epiButtonC1.Click -= new System.EventHandler(this.epiButtonC1_Click);
// End Wizard Added Object Disposal

// Begin Custom Code Disposal

// End Custom Code Disposal
}

private void epiButtonC1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **

// This customisation requires 3 .dll files for the email automation to work. These files must exsist in the client
// folder on the client machine before the customistaion can load.
// The files are:
// - Microsoft.Office.Interop.Outlook.dll
// - CrystalDeceisions.Shared.dll
// - CrystalDecsicions.CrystalReports.Engine.dll


EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
int PONUM;
string Approved;


// check if there is data loaded into the form. if not return from method.
if ( (bool)edvPOHeader.HasRow == false )
{
MessageBox.Show("No Data to email ...");
return;
}

// Get data from the form
Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];

if (Approved == "A")
{
// check the supplier has an email address in Purchase Point.
// grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there.....
string PPemailAddress;

PPemailAddress = epiTextBoxC3.Text;
if (PPemailAddress == "")
{
MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
return; // bailout - no email address...
}

// Make the report from the PO data
POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);
POFormDataSet POFormDS;

POFormDS = Form.GetNewParameters();

// set the PO number and report style and submit the form to the system agent.
POFormDS.POFormParam[0].PONum = PONUM;
POFormDS.POFormParam[0].ReportStyleNum = 1001;
POFormDS.POFormParam[0].WorkstationID = String.Format("{0}",PONUM); // Using the PO number as the WorkstationID so it is easy to reteive this report
Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.

// make the crystal report
ReportDocument repDoc = new ReportDocument();
repDoc.Load(@"\\#####\Epicor905\Server\reports\CustomReports\POForm.rpt"); //get report definition....Once this is working should lookup the report location.

// get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report
// we want, we can then use the sysrowID to get the report data to put into the crystal report.
ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);
ReportMonitorDataSet RMds;
bool morepages;
ReportDataDataSet reportDS = new ReportDataDataSet();

// setup a loop to look for when the report has been generated.
int timer=0;
RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='"+PONUM+"'", 0, 0, out morepages);
while (RMds.SysRptLst.Count == 0 );
{
RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='"+PONUM+"'", 0, 0, out morepages);
System.Threading.Thread.Sleep(1000);
timer = timer + 1;
if (timer > 30)
{
MessageBox.Show("Well, I have been trying to make a pdf of the PO for a while now and I just can't do it....I give up!");
return;
}
}

string sFilePath;
sFilePath = RMds.SysRptLst[0].FileName.ToString();
reportDS.ReadXml(sFilePath , System.Data.XmlReadMode.Auto);
reportDS.WriteXml(sFilePath, System.Data.XmlWriteMode.WriteSchema);

repDoc.SetDataSource(reportDS);
repDoc.Refresh();

// make a pdf of the PO from the report
string FileName = String.Format(@"\\###\EpicorData\{0}.pdf", PONUM);
ExportOptions CrExportOptions ;
DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptions.DiskFileName = FileName;
CrExportOptions = repDoc.ExportOptions;

CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
CrExportOptions.FormatOptions = CrFormatTypeOptions;
repDoc.Export();


// create email message
try
{
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector MsgInspector = oMsg.GetInspector;
string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.
oMsg.Subject = "**** TESTING ERP SYSTEM PLEASE IGNORE **** TMT PO number " + PONUM.ToString();
oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. Â <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p>Â </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;
				<br>
				Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;<br>
				// Change the recipient in the next line if necessary.<br>
				Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);<br>
				oRecip.Resolve();<br>
				<br>
				// Attach pdf of PO, terms, and any other attachments to PO.<br>
				oMsg.Attachments.Add(@&quot;&#92;&#92;####&#92;Purchase Order Terms and Conditions.pdf&quot;,Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);<br>
				oMsg.Attachments.Add(FileName,Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);<br>
				<br>
				MsgInspector.Activate();   // shows the new email message as topmost window.<br>
				<br>
				//Clean up<br>
				oRecips = null;<br>
				oRecip = null;<br>
				oMsg = null;<br>
				oApp = null;<br>
				File.Delete(FileName);<br>
				}<br>
			catch (Exception Ex)<br>
				{<br>
				MessageBox.Show(&quot;Tried to email PO but failed.....Really, I did try, I dont know what went wrong...better call the system admin&quot;);<br>
				}<br>
		}<br>
	else<br>
		MessageBox.Show(&quot;PO must be approved before it can be sent out&quot;);<br>

}

}







--- In vantage@yahoogroups.com, "brettmanners" <bmanners@...> wrote:
>
> Greetings all,
>
> I need some help making a customisation to create a pdf of a PO, then open an email message with that PDF attached and leave it open for the user to check before they press the send button. I am having a lot of trouble getting the PO saved as pdf. When I try to export the report from a Cystal ReportDocument it sends an exception saying the database logon failed.

>

> I have followed the trace of doing this manually and read up on previous posts here: http://tech.groups.yahoo.com/group/vantage/message/100387 but I cant figure out what I am doing wrong…

>

> I also looked at using APM to generate the pdf but APM wont let me name the file it creates so I can't go fetch it…

>

>

> Here is the code…

>

> private void epiButtonC1_Click(object sender, System.EventArgs args)

> {

> // ** Place Event Handling Code Here

> EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];

> int PONUM;

> string Approved;

>

>

> // check if there is data loaded into the form. if not return from method.

> if ( (bool)edvPOHeader.HasRow == false )

> {

> MessageBox.Show("No Data to email …");

> return;

> }

>

> // Get data from the form

> Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];

> PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];

>

> if (Approved == "A")

> {

> // check the supplier has an email address in Purchase Point.

> // grab the email address textbox (this textbox is a customisation) so we can check and get the address if it is there…

> string PPemailAddress;

>

> PPemailAddress = epiTextBoxC3.Text;

> if (PPemailAddress == "")

> {

> MessageBox.Show("No Email address. Add address to Supplier Purchase Point");

> return; // bailout - no email address…

> }

>

>

> // Make the report from the PO data

> POForm Form = new POForm(((Session)oTrans.Session).ConnectionPool);

> POFormDataSet POFormDS;

>

> POFormDS = Form.GetNewParameters();

> POFormDS.POFormParam[0].PONum = PONUM;

> POFormDS.POFormParam[0].ReportStyleNum = 1001;

> Form.SubmitToAgent(POFormDS, "SystemAgent", 0, 0, "Epicor.Mfg.UIRtp.POForm"); //Submit the report to be generate by the system agent.

>

> // Need to wait for report to be generated before continuing…

> System.Threading.Thread.Sleep(30000); // not the best method but I have bigger issues…

>

> // make the crystal report

> ReportDocument repDoc = new ReportDocument();

> repDoc.Load(@"\\XXXX\Epicor905\Server\reports\CustomReports\POForm.rpt"); //get report definition…Once this is working should lookup the report location.

>

> // get report data. Make a ReportMonitor, use it to get a reportmonitor dataset. The reportmonitor dataset will have the sysrowID of the report

> // we want, we can then use the sysrowID to get the report data to put into the crystal report.

> ReportMonitor RM = new ReportMonitor(((Session)oTrans.Session).ConnectionPool);

> ReportMonitorDataSet RMds;

> bool morepages;

> ReportDataDataSet reportDS;

>

> RMds = RM.GetRowsKeepIdleTime(@"WorkStationID ='ENG01 1'", 0, 0, out morepages); // this gets all reports from my workstation which during testing have all been the same PO.

>

> MessageBox.Show("Report SysrowID is " + RMds.SysRptLst[0].SysRowID); // for testing

>

> reportDS = RM.GetReportData(RMds.SysRptLst[0].SysRowID); // get the report data using the sysrowID of the first report from the Reportmonitor dataset.

>

>

>

> repDoc.SetDataSource(reportDS);

> repDoc.Refresh();

> MessageBox.Show("finished creating report");

>

> // make a pdf of the PO from the report

> string FileName = @"\\XXXX\EpicorData\test.pdf";

> ExportOptions CrExportOptions ;

> DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();

> PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();

> CrDiskFileDestinationOptions.DiskFileName = FileName;

> CrExportOptions = repDoc.ExportOptions;

>

> CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

> CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

> CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;

> CrExportOptions.FormatOptions = CrFormatTypeOptions;

> repDoc.Export(); // ********************** ERROR OCCURS ON THIS LINE. DB LOGIN FAILED???#$@$#@

> MessageBox.Show("finished saving report as pdf");

>

> // create email message

> try

> {

> Outlook.Application oApp = new Outlook.Application();

> Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

> Outlook.Inspector MsgInspector = oMsg.GetInspector;

> string Signature = oMsg.HTMLBody; //capture signature for appending to custom message later.

> oMsg.Subject = "
** TESTING ERP SYSTEM PLEASE IGNORE **** PO number " + PONUM.ToString();

> oMsg.HTMLBody = "<body lang=EN-AU ><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please see attached purchase order, and Total Marine Technology Purchase Order Terms and Conditions.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Please let me know if there are any problems.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'><o:p>Â </o:p></span></p><p class=MsoNormal><span style='color:red;mso-fareast-language:EN-AU'>Kindly acknowledge receipt of this Purchase Order. Â <o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p>Â </o:p></span></p><div><p class=MsoNormal><span style='color:#1F497D;mso-fareast-language:EN-AU'>Kind Regards,<o:p>" + Signature;

>

> Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;

> // Change the recipient in the next line if necessary.

> Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);

> oRecip.Resolve();

>

> // Attach pdf of PO, terms, and any other attachments to PO.

> oMsg.Attachments.Add(@"\\XXXX\Engineering\Temp\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);

> oMsg.Attachments.Add(@"\\XXXX\EpicorData\test.rpt",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);

>

> MsgInspector.Activate(); // shows the new email message as topmost window.

>

> //Clean up

> oRecips = null;

> oRecip = null;

> oMsg = null;

> oApp = null;

> }

> catch (Exception Ex)

> {

> MessageBox.Show("Tried to email PO but failed");

> }

> }

> else

> MessageBox.Show("PO must be approved before it can be sent out");

>

>

> }

>


</div>
 


<div style="color:#fff;"></div>

</div>
 


<div style="color:#fff;"></div>

</div>
 


<div style="color:#fff;min-height:0;"></div>