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 = @"
{0} |
{0} |
{0} |
{0} |