派纳发送邮件功能
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

544 lines
22 KiB

using System;
using System.Text;
using System.Collections;
using System.Xml;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Resources;
using System.Reflection;
using System.Globalization;
using System.Threading;
using Telerik.WebControls;
using UFSoft.UBF.UI.WebControls;
using UFSoft.UBF.UI.Controls;
using UFSoft.UBF.Util.Log;
using UFSoft.UBF.Util.Globalization;
using UFSoft.UBF.UI.IView;
using UFSoft.UBF.UI.Engine;
using UFSoft.UBF.UI.MD.Runtime;
using UFSoft.UBF.UI.ActionProcess;
using UFSoft.UBF.UI.WebControls.ClientCallBack;
using UFSoft.UBF.Analysis.MD.Report.Service;
using UFSoft.UBF.Analysis.Interface.MD.Report.Service;
using UFSoft.UBF.Analysis.Interface.MD.Report.Model;
using System.IO;
using System.Net.Mail;
using UFSoft.UBF.PRN.Control;
using UFSoft.UBF.Report.Tools;
using CusSupplierContactBP;
using System.Collections.Generic;
/***********************************************************************************************
* Form ID:
* UIFactory Auto Generator
***********************************************************************************************/
namespace UFIDA.U9.Cust.WC.CustPOSendMailUI
{
public partial class CustPOSendMailUIFormWebPart
{
#region Custome eventBind
string filePath = " C:\\U8NetPrintResult\\Guest";
string filePathD = " E:\\U8NetPrintResult\\Guest";
string PurMail = "";
//DropDownList_Notices_TextChanged...
private void DropDownList_Notices_TextChanged_Extend(object sender, EventArgs e)
{
//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
Action.OnSend(sender, new UIActionEventArgs());
//string SelSQL = @"SELECT PrintTemplateText FROM Cust_PrintTemplateText WHERE PrintTemplateTypeName='" + this.DropDownList_Notices.Text + "'";
//DataSet SelSQLDs = new DataSet();
//UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), SelSQL.ToString(), null, out SelSQLDs);
//DataTable dt = new DataTable();
//dt = SelSQLDs.Tables[0];
//if (dt.Rows.Count < 1)
//{
// throw new Exception("配置表Cust_PrintTemplateText中不存在对应信息,请先维护");
//}
this.MailText53.Text = "Dear Supplier:" + "\r\n" + "Please refer to the New PO, Confirm it within today and feedback the delivery date within 2 Days,Thanks."
+ "\r\n" + "Best Regards" + "\r\n" + "The information contained in this message is confidential and may be " +
"legally privileged. The message is intended solely for the addressee(s). " +
"If you are not the intended recipient, you are hereby notified that any use,dissemination " +
"or reproduction is strictly prohibited and may be unlawful. If you are not the intended recipient, " +
"please contact the sender by return e-mail and destroy all copies of the original message.";
this.DataCollect();
this.DataBind();
DropDownList_Notices_TextChanged_DefaultImpl(sender, e);
}
//OnSend273_Click...
private void OnSend273_Click_Extend(object sender, EventArgs e)
{
//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
IUIRecordCollection records = this.Model.CustPOSendMailPerson.SelectRecords;
if (records == null || records.Count == 0)
{
throw new Exception("请先勾选发件人");
}
string MailAddress = string.Empty;
if (records.Count > 0)
{
foreach (var item in records)
{
string RcvPerson = string.Empty;
string Telephone = string.Empty;
RcvPerson = item["RcvPerson"].ToString();
Telephone = item["Telephone"].ToString();
if (string.IsNullOrWhiteSpace(item["MailAddress"].ToString()))
{
throw new Exception("邮箱地址为空");
}
MailAddress += item["MailAddress"].ToString() + ";";
if (string.IsNullOrWhiteSpace(MailAddress))
{
throw new Exception("邮箱地址为空");
}
}
}
SendMail(MailAddress);
OnSend273_Click_DefaultImpl(sender, e);
}
private void SendMail(string TOAddress)
{
string printTemplateID = this.PrintTemplates278.Value.ToString();
this.DataCollect();
this.DataBind();
if (string.IsNullOrWhiteSpace(this.PrintTemplates278.Value.ToString()))
{
throw new Exception("请选择模板");
}
string connectionString = UFSoft.UAP.Report.Base.DBConnectionHelper.GetConnectionString();
string cultrueName = UFSoft.UBF.Util.Context.PlatformContext.Current.Culture;
ReportMDService service = ReportMDService.GetInstance(connectionString, cultrueName);
IReportMDReader reader = service.GetReader();
IReportTemplate reportTemplate = reader.GetReportTemplateByID(printTemplateID);
UFSoft.UBF.Report.Entity.Report report = (UFSoft.UBF.Report.Entity.Report)reportTemplate.Content;
reader.Dispose();
DataSet ds = new DataSet();
string fileName = OutPutFile(report, ds, printTemplateID);
string _NewFile = string.Empty;
string __NewFile = string.Empty;
ArrayList list = new ArrayList();
//读取指定目录的文件
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
else
{
DirectoryInfo dirIfo = new DirectoryInfo(filePath);
FileInfo[] files = dirIfo.GetFiles();
for (int k = files.Length - 1; k >= 0; k--)
{
if (fileName == files[k].FullName)
{
list.Add(files[k].FullName);
_NewFile = filePath + "\\" + "采购订单" + CurrentState["POCode"].ToString() + "" + ".pdf";
__NewFile = filePathD + "\\" + "采购订单" + CurrentState["POCode"].ToString() + "" + ".pdf";
File.Delete(_NewFile);
File.Move(files[k].FullName, _NewFile);
File.Move(_NewFile, __NewFile);
}
}
}
string MailBoxConfigurationSQL = @"SELECT SendHost,SendPort,SendDisplayName,SendAddress,SendPassword,TOAddress,
CCAddress,Subject,IsBodyHtml FROM [Cust_MailBoxConfiguration ]";
DataSet MailBoxConfigurationDs = new DataSet();
UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), MailBoxConfigurationSQL.ToString(), null, out MailBoxConfigurationDs);
DataTable MailBoxConfigurationDT = new DataTable();
if (MailBoxConfigurationDs != null && MailBoxConfigurationDs.Tables.Count > 0 && MailBoxConfigurationDs.Tables[0].Rows.Count > 0)
{
MailBoxConfigurationDT = MailBoxConfigurationDs.Tables[0];
}
string SendHost = string.Empty;
int SendPort = 0;
string SendAddress = string.Empty; ;
string SendPassword = string.Empty; ;
string CCAddress = string.Empty; ;
foreach (DataRow item in MailBoxConfigurationDT.Rows)
{
SendHost = item["SendHost"].ToString();
if (!string.IsNullOrWhiteSpace(item["SendPort"].ToString()))
{
SendPort = Int32.Parse(item["SendPort"].ToString());
}
SendAddress = item["SendAddress"].ToString();
SendPassword = item["SendPassword"].ToString();
CCAddress = item["CCAddress"].ToString();
}
string[] mailNames = TOAddress.Split(';');
for (int i = 0; i < list.Count; i++)
{
SmtpClient client = new SmtpClient();
client.Host = SendHost;//SMTP服务器地址
client.EnableSsl = true;
client.UseDefaultCredentials = false;
//发件人邮箱账号
client.Credentials = new System.Net.NetworkCredential(SendAddress, SendPassword);
MailAddress from = new MailAddress(SendAddress, SendPassword); //邮件的发件人
MailMessage message = new MailMessage();
try
{
foreach (var MailItem in mailNames)
{
if (!string.IsNullOrWhiteSpace(MailItem))
{
message.To.Add(MailItem);//收件人地址
}
}
if (!string.IsNullOrWhiteSpace(CCAddress))
{
message.CC.Add(CCAddress);//抄送人邮箱
}
//string SelSQL = @"SELECT top 1 PrintTemplateText FROM Cust_PrintTemplateText ";
//DataSet SelSQLDs = new DataSet();
//UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), SelSQL.ToString(), null, out SelSQLDs);
//DataTable dt = new DataTable();
//dt = SelSQLDs.Tables[0];
//if (dt.Rows.Count < 1)
//{
// throw new Exception("配置表Cust_PrintTemplateText中不存在对应信息,请先维护");
//}
message.From = new MailAddress(SendAddress);//发件人邮箱
message.Subject = this.MailTitle86.Text;//邮件标题
message.SubjectEncoding = Encoding.UTF8;//标题格式为UTF8
//string _Body = dt.Rows[0][0].ToString();
//string[] strArray = _Body.Split(new char[1] { ' ' });
string _SelSQL = @"select c.DefaultEmail from PM_PurchaseOrder a
left join CBO_Operators b on a.PurOper = b.ID
left join Base_Contact c on b.Contact = c.ID
where a.DocNo ='" + CurrentState["POCode"].ToString() + "' and a.Org='" + CurrentState["OrgID"].ToString() + "'";
DataSet _SelSQLDs = new DataSet();
UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), _SelSQL.ToString(), null, out _SelSQLDs);
DataTable dtPur = new DataTable();
dtPur = _SelSQLDs.Tables[0];
if (dtPur.Rows.Count == 0)
{
throw new Exception("采购员未维护邮箱");
}
string PurMail = dtPur.Rows[0]["DefaultEmail"].ToString();//采购员收件邮箱
string mailMessage = @"<html>
<body>
<table style='width: 100%; table-layout: fixed; font-size: 16px;' border: 0px cellspacing='4' >
<tbody> ";
int k = 0;
mailMessage += string.Format(@"
<tr>
<td >{0}</td>
</tr>
", "Dear Supplier:");
mailMessage += string.Format(@"
<tr>
<td >{0}</td>
</tr>
", "Please refer to the New PO, Confirm it within today and feedback the delivery date within 2 Days,Thanks.");
mailMessage += string.Format(@"
<tr>
<td >{0}</td>
</tr>
", "Best Regards");
mailMessage += string.Format(@"
<tr>
<td >{0}</td>
</tr>
", "The information contained in this message is confidential and may be legally privileged. " +
"The message is intended solely for the addressee(s). If you are not the intended recipient," +
" you are hereby notified that any use, dissemination or reproduction is strictly prohibited" +
" and may be unlawful. If you are not the intended recipient, please contact the sender " +
"by return e-mail and destroy all copies of the original message.");
mailMessage += @" </table></body></html>";
message.CC.Add(PurMail);//采购员抄送人邮箱
message.CC.Add("yu.zhou@panawincn.com");//采购经理抄送人邮箱
message.Body = mailMessage;// mailContent;//邮件内容
message.BodyEncoding = Encoding.UTF8;//内容格式为UTF8
message.IsBodyHtml = true;//是否是HTML邮件
message.Priority = MailPriority.Normal;//邮件优先级
if (SendPort > 0)
{
client.Port = Convert.ToInt32(SendPort);// 25;
}
message.Attachments.Add(new Attachment(__NewFile)); // 发送附件
client.Send(message);//发送邮件
message.Dispose();
File.Delete(fileName);
File.Delete(_NewFile);
File.Delete(__NewFile);
this.CloseDialog();
}
catch (Exception ex)
{
message.Dispose();
File.Delete(fileName);
File.Delete(_NewFile);
File.Delete(__NewFile);
throw new Exception(ex.ToString());
}
}
}
private string OutPutFile(UFSoft.UBF.Report.Entity.Report template, DataSet data, string printTemplateID)
{
string sql = string.Empty;
string SelSQL = @"SELECT a.PrintTemplateSQL FROM Cust_PrintTemplate a WHERE a.PrintTemplateID='" + printTemplateID + "'";
DataSet SelSQLDs = new DataSet();
UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), SelSQL.ToString(), null, out SelSQLDs);
DataTable dt = new DataTable();
if (SelSQLDs != null && SelSQLDs.Tables.Count > 0 && SelSQLDs.Tables[0].Rows.Count > 0)
{
dt = SelSQLDs.Tables[0];
}
sql = dt.Rows[0][0].ToString();
sql = string.Format(sql, CurrentState["POCode"].ToString(), CurrentState["OrgID"].ToString());
DataSet SelDs = new DataSet();
UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql.ToString(), null, out SelDs);
data = SelDs;
PrintService printService = new PrintService();
PrintCreater printCreater = new PrintCreater();
printService.LoadXmlFormatFromString(printCreater.CreateReport(template).InnerXml);
printService.LoadPrintData(data);
printService.ConvertStart();
string[] resultFilesName = printService.GetResultFilesName();
return printService.PhysicalFilePrefix + resultFilesName[0];
}
//OnClose141_Click...
private void OnClose141_Click_Extend(object sender, EventArgs e)
{
//调用模版提供的默认实现.--默认实现可能会调用相应的Action.
OnClose141_Click_DefaultImpl(sender, e);
}
string OrgID = string.Empty;
string SupplierName = string.Empty;
string SupplierCode = string.Empty;
string POCode = string.Empty;
List<OperationResultContent> list = new List<OperationResultContent>();
#region 自定义数据初始化加载和数据收集
private void OnLoadData_Extend(object sender)
{
DropDownList_Notices.Items.Clear();
//string _SelSQL = @"SELECT PrintTemplateTypeName FROM Cust_PrintTemplateText";
//DataSet _SelSQLDs = new DataSet();
//UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), _SelSQL.ToString(), null, out _SelSQLDs);
//DataTable _dt = new DataTable();
//_dt = _SelSQLDs.Tables[0];
//if (_dt.Rows.Count < 1)
//{
// throw new Exception("配置表Cust_PrintTemplateText中不存在对应信息,请先维护");
//}
//foreach (DataRow item in _dt.Rows)
//{
// this.DropDownList_Notices.Items.Add("" + item["PrintTemplateTypeName"].ToString() + "");
//}
this.DropDownList_Notices.Items.Add("发送模板");
DropDownList_Notices.SelectedIndex = 0;
OrgID = CurrentState["OrgID"].ToString();
SupplierName = CurrentState["SupplierName"].ToString();
SupplierCode = CurrentState["SupplierCode"].ToString();
POCode = CurrentState["POCode"].ToString();
this.Model.CustPOSendMailPerson.Clear();
CusSupplierContactBP.CusSelSupplierContactBP pro = new CusSupplierContactBP.CusSelSupplierContactBP();
pro.OrgID = OrgID;
pro.SupplierNo = SupplierCode;
pro.PODocNo = POCode;
list = new List<OperationResultContent>();
list = pro.Do();
if (list != null && list.Count > 0)
{
foreach (var item in list)
{
//IUIRecordCollection records = this.Model.CustPOSendMailPerson.SelectRecords;
CustPOSendMailPersonRecord dataRwcord = this.Model.CustPOSendMailPerson.AddNewUIRecord();
if (!string.IsNullOrWhiteSpace(item.SupplierContentName))
{
dataRwcord.RcvPerson = item.SupplierContentName;
dataRwcord.Telephone = item.Telephoto;
dataRwcord.MailAddress = item.Mail;
dataRwcord.IsSelected = true;
}
}
}
OnLoadData_DefaultImpl(sender);
string MaileTile = string.Empty;
MaileTile = "采购订单 " + POCode + ","+ "供应商:" + SupplierName;
//string SelSQL = @"SELECT top 1 PrintTemplateText FROM Cust_PrintTemplateText ";
//DataSet SelSQLDs = new DataSet();
//UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), SelSQL.ToString(), null, out SelSQLDs);
//DataTable dt = new DataTable();
//dt = SelSQLDs.Tables[0];
//if (dt.Rows.Count < 1)
//{
// throw new Exception("配置表Cust_PrintTemplateText中不存在对应信息,请先维护");
//}
string _SelSQL = @"select c.DefaultEmail from PM_PurchaseOrder a
left join CBO_Operators b on a.PurOper = b.ID
left join Base_Contact c on b.Contact = c.ID
where a.DocNo ='" + CurrentState["POCode"].ToString() + "' and a.Org='" + CurrentState["OrgID"].ToString() + "'";
DataSet _SelSQLDs = new DataSet();
UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), _SelSQL.ToString(), null, out _SelSQLDs);
DataTable dtPur = new DataTable();
dtPur = _SelSQLDs.Tables[0];
if (dtPur.Rows.Count == 0)
{
throw new Exception("采购员未维护邮箱");
}
string PurMail = dtPur.Rows[0]["DefaultEmail"].ToString();//采购员收件邮箱
this.MailTitle86.Text = MaileTile;
this.MailText53.Text = "Dear Supplier:" + "\r\n" + "Please refer to the New PO, Confirm it within today and feedback the delivery date within 2 Days,Thanks."
+ "\r\n" + "Best Regards" + "\r\n" + "The information contained in this message is confidential and may be " +
"legally privileged. The message is intended solely for the addressee(s). " +
"If you are not the intended recipient, you are hereby notified that any use,dissemination " +
"or reproduction is strictly prohibited and may be unlawful. If you are not the intended recipient, " +
"please contact the sender by return e-mail and destroy all copies of the original message.";
this.DataCollect();
this.DataBind();
}
private void OnDataCollect_Extend(object sender)
{
OnDataCollect_DefaultImpl(sender);
}
#endregion
#region 自己扩展 Extended Event handler
public void AfterOnLoad()
{
}
public void AfterCreateChildControls()
{
}
public void AfterEventBind()
{
}
public void BeforeUIModelBinding()
{
}
public void AfterUIModelBinding()
{
}
#endregion
#endregion
}
}