From 8b476f9f22cbd0f9c1391ae8d5b8a0ead852ecf8 Mon Sep 17 00:00:00 2001 From: Shaobin Date: Thu, 19 Sep 2024 16:42:05 +0800 Subject: [PATCH] no message --- ...POSendMailUIFormWebPartCodeBehindExtend.cs | 248 +++++++++++------- 1 file changed, 150 insertions(+), 98 deletions(-) diff --git a/UICode/CustPOSendMailUI/WebPart/CustPOSendMailUIFormWebPartCodeBehindExtend.cs b/UICode/CustPOSendMailUI/WebPart/CustPOSendMailUIFormWebPartCodeBehindExtend.cs index 7944872..4c9efeb 100644 --- a/UICode/CustPOSendMailUI/WebPart/CustPOSendMailUIFormWebPartCodeBehindExtend.cs +++ b/UICode/CustPOSendMailUI/WebPart/CustPOSendMailUIFormWebPartCodeBehindExtend.cs @@ -45,78 +45,78 @@ namespace UFIDA.U9.Cust.WC.CustPOSendMailUI #region Custome eventBind string filePath = " C:\\U8NetPrintResult\\Guest"; - string filePathD = " D:\\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) + 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 = dt.Rows[0][0].ToString(); - this.DataCollect(); - this.DataBind(); + this.MailText53.Text = dt.Rows[0][0].ToString(); + 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; + DropDownList_Notices_TextChanged_DefaultImpl(sender, e); + } - if (records == null || records.Count == 0) - { - throw new Exception("请先勾选发件人"); - } - string MailAddress = string.Empty; + //OnSend273_Click... + private void OnSend273_Click_Extend(object sender, EventArgs e) + { + //调用模版提供的默认实现.--默认实现可能会调用相应的Action. + IUIRecordCollection records = this.Model.CustPOSendMailPerson.SelectRecords; - if (records.Count > 0) - { - foreach (var item in records) - { - string RcvPerson = string.Empty; - string Telephone = string.Empty; + if (records == null || records.Count == 0) + { + throw new Exception("请先勾选发件人"); + } + string MailAddress = 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("邮箱地址为空"); - } + 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); + SendMail(MailAddress); - OnSend273_Click_DefaultImpl(sender,e); - } + + OnSend273_Click_DefaultImpl(sender, e); + } private void SendMail(string TOAddress) @@ -215,13 +215,14 @@ namespace UFIDA.U9.Cust.WC.CustPOSendMailUI SmtpClient client = new SmtpClient(); client.Host = SendHost;//SMTP服务器地址 - //client.EnableSsl = true; + 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 @@ -238,14 +239,43 @@ namespace UFIDA.U9.Cust.WC.CustPOSendMailUI 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 = this.MailText53.Text; + 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 = @" @@ -274,7 +304,17 @@ namespace UFIDA.U9.Cust.WC.CustPOSendMailUI } i++; } + mailMessage += string.Format(@" + + + + ", "采购员邮箱:" + PurMail); + mailMessage += string.Format(@" + + + + ", "采购经理邮箱:yu.zhou@panawincn.com"); mailMessage += @"
{0}
{0}
"; @@ -287,16 +327,21 @@ namespace UFIDA.U9.Cust.WC.CustPOSendMailUI client.Port = Convert.ToInt32(SendPort);// 25; } - + message.Attachments.Add(new Attachment(__NewFile)); // 发送附件 - - client.Send(message);//发送邮件 + 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); @@ -304,17 +349,8 @@ namespace UFIDA.U9.Cust.WC.CustPOSendMailUI throw new Exception(ex.ToString()); } - finally - { - message.Dispose(); - } - - File.Delete(fileName); - File.Delete(_NewFile); - File.Delete(__NewFile); - this.CloseDialog(); } } @@ -351,13 +387,13 @@ namespace UFIDA.U9.Cust.WC.CustPOSendMailUI } //OnClose141_Click... - private void OnClose141_Click_Extend(object sender, EventArgs e) - { - //调用模版提供的默认实现.--默认实现可能会调用相应的Action. - - - OnClose141_Click_DefaultImpl(sender,e); - } + private void OnClose141_Click_Extend(object sender, EventArgs e) + { + //调用模版提供的默认实现.--默认实现可能会调用相应的Action. + + + OnClose141_Click_DefaultImpl(sender, e); + } string OrgID = string.Empty; @@ -369,7 +405,7 @@ namespace UFIDA.U9.Cust.WC.CustPOSendMailUI #region 自定义数据初始化加载和数据收集 private void OnLoadData_Extend(object sender) - { + { DropDownList_Notices.Items.Clear(); string _SelSQL = @"SELECT PrintTemplateTypeName FROM Cust_PrintTemplateText"; @@ -377,7 +413,7 @@ namespace UFIDA.U9.Cust.WC.CustPOSendMailUI 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) + if (_dt.Rows.Count < 1) { throw new Exception("配置表Cust_PrintTemplateText中不存在对应信息,请先维护"); } @@ -385,10 +421,10 @@ namespace UFIDA.U9.Cust.WC.CustPOSendMailUI { this.DropDownList_Notices.Items.Add("" + item["PrintTemplateTypeName"].ToString() + ""); } - + DropDownList_Notices.SelectedIndex = 0; - + OrgID = CurrentState["OrgID"].ToString(); SupplierName = CurrentState["SupplierName"].ToString(); SupplierCode = CurrentState["SupplierCode"].ToString(); @@ -433,51 +469,67 @@ namespace UFIDA.U9.Cust.WC.CustPOSendMailUI throw new Exception("配置表Cust_PrintTemplateText中不存在对应信息,请先维护"); } + _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() + "'"; + _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 = dt.Rows[0][0].ToString(); + this.MailText53.Text = dt.Rows[0][0].ToString() + "\r\n" + "采购员邮箱:" + PurMail + + "\r\n" + "采购经理邮箱:yu.zhou@panawincn.com"; this.DataCollect(); this.DataBind(); } - private void OnDataCollect_Extend(object sender) - { - OnDataCollect_DefaultImpl(sender); - } - #endregion + private void OnDataCollect_Extend(object sender) + { + OnDataCollect_DefaultImpl(sender); + } + #endregion #region 自己扩展 Extended Event handler - public void AfterOnLoad() - { + public void AfterOnLoad() + { - } + } public void AfterCreateChildControls() { - + } - + public void AfterEventBind() { } - - public void BeforeUIModelBinding() - { - } + public void BeforeUIModelBinding() + { + + } - public void AfterUIModelBinding() - { + public void AfterUIModelBinding() + { - } + } #endregion - + #endregion - + } } \ No newline at end of file