So this is what I have right now that is producing the following compile errors
Error: CS0103 - line 505 (2511) - The name ‘edvAutoAttachPOHeader’ does not exist in the current context
Warning: CS0467 - line 518 (2524) - Ambiguity between method ‘Microsoft.Office.Interop.Outlook._Inspector.Activate()’ and non-method ‘Microsoft.Office.Interop.Outlook.InspectorEvents_10_Event.Activate’. Using method group
extern alias Erp_Adapters_PO;
extern alias Erp_Adapters_PartRevSearch;
extern alias Erp_Contracts_BO_Vendor;
extern alias Erp_Contracts_BO_Part;
extern alias Erp_Contracts_BO_Company;
extern alias Erp_Contracts_BO_VendorPPSearch;
extern alias Erp_Contracts_BO_VendCntSearch;
extern alias Erp_Contracts_BO_PO;
extern alias Erp_Contracts_BO_MiscShip;
extern alias Erp_Contracts_BO_Receipt;
extern alias Erp_Contracts_BO_JobEntry;
extern alias Erp_Contracts_BO_JobMtlSearch;
extern alias Erp_Contracts_BO_PartRevSearch;
extern alias Erp_Contracts_BO_Plant;
extern alias Ice_Contracts_BO_ReportMonitor;
extern alias Erp_Contracts_Rpt_POForm;
extern alias Erp_Adapters_UserFile;
extern alias Ice_Contracts_BO_UserFile;
extern alias Microsoft_ReportViewer_WebForms;
extern alias Microsoft_Office_Interop_Outlook;
extern alias Microsoft_ReportViewer_WinForms;
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using Erp.BO;
using Ice.BO;
using Ice.Lib.Broadcast;
using System.Reflection;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using Ice.Core;
using Ice.Lib.Report;
using Ice.Contracts;
using System.IO;
using Epicor.ServiceModel;
using Epicor.ServiceModel.Channels;
using System.Diagnostics;
using Ice.Lib.Broadcast;
using Outlook = Microsoft.Office.Interop.Outlook;
using Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution;
using System.Windows.Forms;
private void epiButtonC1_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **
EpiDataView edvPOHeader = (EpiDataView)oTrans.EpiDataViews["POHeader"];
int PONUM;
string Approved;
string Requestor;
string Supplier;
string CurrentCompany;
// check if there is data loaded into the form. if not return from method.
if ( (bool)edvPOHeader.HasRow == false )
{
MessageBox.Show("There is no data present to email");
return;
}
// Get data from the form
Approved = (string)edvPOHeader.dataView[edvPOHeader.Row]["ApprovalStatus"];
PONUM = (int)edvPOHeader.dataView[edvPOHeader.Row]["PONum"];
Requestor = (string)edvPOHeader.dataView[edvPOHeader.Row]["BuyerID"];
Supplier = (string)edvPOHeader.dataView[edvPOHeader.Row]["VendorVendorID"];
CurrentCompany = (string)edvPOHeader.dataView[edvPOHeader.Row]["Company"];
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 = txtEmail.Text; //Supplier email address is in this Textbox.
if (PPemailAddress == "")
{
MessageBox.Show("No Email address. Add address to Supplier Purchase Point");
return; // bailout - no email address...
}
Erp.Proxy.Rpt.POFormImpl Form = WCFServiceSupport.CreateImpl<Erp.Proxy.Rpt.POFormImpl>((Ice.Core.Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Erp.Contracts.POFormSvcContract>.UriPath);
// Make the report from the PO data
Erp.Rpt.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;
switch (CurrentCompany)
{
case "A":
POFormDS.POFormParam[0].ReportStyleNum = 3001;
break;
case "B":
POFormDS.POFormParam[0].ReportStyleNum = 3002;
break;
default:
POFormDS.POFormParam[0].ReportStyleNum = 3003;
break;
}
Guid workstationid = Guid.NewGuid(); // Put a GUID in the workstationId to allow searching for the report later.
POFormDS.POFormParam[0].WorkstationID = String.Format("{0}",workstationid); // Using a GUID as the WorkstationID so it is easy to reteive this report
POFormDS.POFormParam[0].DateFormat = "dd/MM/yy";
POFormDS.POFormParam[0].ArchiveCode = 1;
POFormDS.POFormParam[0].AutoAction = "SSRSGenerate";
MessageBox.Show("Submit to System Agent ...");
Form.SubmitToAgent(POFormDS, "SystemTaskAgent", 0, 0, "Erp.UIRtp.POForm"); //Submit the report to be generate by the system agent.
// 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 SSRS report.
Ice.Proxy.BO.ReportMonitorImpl RM = WCFServiceSupport.CreateImpl<Ice.Proxy.BO.ReportMonitorImpl>((Ice.Core.Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.ReportMonitorSvcContract>.UriPath);
int timer=0;
bool morepages;
SysRptLstListDataSet RptList;
RptList = RM.GetList(@"WorkStationID ='"+workstationid+"'", 0, 0, out morepages);
while (RptList.SysRptLstList.Count == 0 ) // setup a loop to look for when the report has been generated.
{
System.Threading.Thread.Sleep(500);
timer = timer + 1;
if (timer > 120)
{
MessageBox.Show("Attempts to generate a PO pdf has timed-out. Please try again, and if that does not work, contact ERP Support");
return;
}
RptList = RM.GetList(@"WorkStationID ='"+workstationid+"'", 0, 0, out morepages);
}
string tableguid;
tableguid = RptList.SysRptLstList[0].FileName.Replace("REPORT DATABASE: ","");
// make a pdf of the PO from the report
string FileName = String.Format(@"C:\Epicor\ERP10.2Client\ExcoClient\PrintReports\{0}.pdf", PONUM);
string reportStyle;
switch (CurrentCompany)
{
case "A":
reportStyle = "/Reports/CustomReports/PurchaseOrderForm/POForm_5.27.21";
break;
case "B":
reportStyle = "/Reports/CustomReports/PurchaseOrderForm/POForm_5.27.21";
break;
default:
reportStyle = "/Reports/CustomReports/PurchaseOrderForm/POForm_9-22-20";
break;
}
GenerateReportPDF("xxxx/ReportServer/ReportExecution2005.asmx",reportStyle,tableguid,FileName);
MessageBox.Show("Print Job Has been submitted - This will take approx. 10 seconds.");
// create email message
try
{
//MessageBox.Show("Attaching to email...");
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 = PONUM.ToString() + " Purchase Order" ;
switch (CurrentCompany)
{
case "A":
oMsg.HTMLBody = "Put your default text here in html format" + Signature;
break;
case "B":
oMsg.HTMLBody = "Put your default text here in html format" + Signature;
break;
default:
oMsg.HTMLBody = "Put your default text here in html format" + Signature;
break;
}
// Set up the recipients for the email
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(PPemailAddress);
oRecip.Resolve();
// Find the requestors email and add that
if (Requestor != "")
{
Ice.Proxy.BO.UserFileImpl userBO = WCFServiceSupport.CreateImpl<Ice.Proxy.BO.UserFileImpl>((Ice.Core.Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.UserFileSvcContract>.UriPath);
try
{
UserFileDataSet user = userBO.GetByID(Requestor);
oRecip = oRecips.Add(user.UserFile[0].EMailAddress);
oRecip.Resolve();
}
catch
{
MessageBox.Show("Could not add requestors email address to email, user " + Requestor + " not found in Epicor.");
}
}
// Attach pdf of PO, terms, and any other attachments to PO.
oMsg.Attachments.Add(FileName,Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
oMsg.Attachments.Add(@"\\<SERVER>\Shared\Purchasing\Purchase Order Terms and Conditions.pdf",Outlook.OlAttachmentType.olByValue, Type.Missing,Type.Missing);
var FolderId = Guid.NewGuid().ToString("N").ToUpper();
var TempPath = Path.Combine(Path.GetTempPath(), FolderId);
if (!Directory.Exists(TempPath))
{
Directory.CreateDirectory(TempPath);
}
foreach (DataRowView row in edvAutoAttachPOHeader.dataView)
{
var AttachPath = row["FileName"].ToString();
var AttachFileName = Path.GetFileName(AttachPath);
var AttachNewPath = Path.Combine(TempPath, AttachFileName);
var AttachDesc = row["DrawDesc"].ToString();
File.Copy(AttachPath, AttachNewPath);
if (File.Exists(AttachNewPath))
{
oMsg.Attachments.Add(AttachNewPath, 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("PO Email was attempted but failed. Please try again. If that doesn't work, please contact ERP Support");
}
}
else
MessageBox.Show("PO must be approved before it can be sent out");
}
private void GenerateReportPDF(String ServerURL, String report, String tableguid, String PDFfilename)
{
// setup report variables
string deviceInfo = null;
string extension = String.Empty;
string mimeType = String.Empty;
string encoding = String.Empty;
Warning[] warnings = null;
string[] streamIDs = null;
string historyId = null;
// Create a Report Execution object
Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution.ReportExecutionService rsExec = new ReportExecutionService();
rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
rsExec.Url = "http://EXCO-ERP10-SQL.excoeng.com/ReportServer";
// Load the report
rsExec.LoadReport(report, historyId);
// pass parameters
rsExec.SetExecutionParameters(
new ParameterValue[] { new ParameterValue() { Name = "TableGuid", Value = tableguid } }, null);
// get pdf of report
Byte[] results = rsExec.Render("PDF", deviceInfo,
out extension, out encoding,
out mimeType, out warnings, out streamIDs);
File.WriteAllBytes(PDFfilename, results);
}
}