派纳发送邮件功能
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.

546 lines
22 KiB

9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
6 months ago
6 months ago
9 months ago
5 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
8 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
6 months ago
9 months ago
6 months ago
9 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
9 months ago
6 months ago
6 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
6 months ago
9 months ago
  1. using System;
  2. using System.Text;
  3. using System.Collections;
  4. using System.Xml;
  5. using System.Data;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Resources;
  10. using System.Reflection;
  11. using System.Globalization;
  12. using System.Threading;
  13. using Telerik.WebControls;
  14. using UFSoft.UBF.UI.WebControls;
  15. using UFSoft.UBF.UI.Controls;
  16. using UFSoft.UBF.Util.Log;
  17. using UFSoft.UBF.Util.Globalization;
  18. using UFSoft.UBF.UI.IView;
  19. using UFSoft.UBF.UI.Engine;
  20. using UFSoft.UBF.UI.MD.Runtime;
  21. using UFSoft.UBF.UI.ActionProcess;
  22. using UFSoft.UBF.UI.WebControls.ClientCallBack;
  23. using UFSoft.UBF.Analysis.MD.Report.Service;
  24. using UFSoft.UBF.Analysis.Interface.MD.Report.Service;
  25. using UFSoft.UBF.Analysis.Interface.MD.Report.Model;
  26. using System.IO;
  27. using System.Net.Mail;
  28. using UFSoft.UBF.PRN.Control;
  29. using UFSoft.UBF.Report.Tools;
  30. using CusSupplierContactBP;
  31. using System.Collections.Generic;
  32. /***********************************************************************************************
  33. * Form ID:
  34. * UIFactory Auto Generator
  35. ***********************************************************************************************/
  36. namespace UFIDA.U9.Cust.WC.CustPOSendMailUI
  37. {
  38. public partial class CustPOSendMailUIFormWebPart
  39. {
  40. #region Custome eventBind
  41. string filePath = " C:\\U8NetPrintResult\\Guest";
  42. string filePathD = " E:\\U8NetPrintResult\\Guest";
  43. string PurMail = "";
  44. //DropDownList_Notices_TextChanged...
  45. private void DropDownList_Notices_TextChanged_Extend(object sender, EventArgs e)
  46. {
  47. //调用模版提供的默认实现.--默认实现可能会调用相应的Action.
  48. Action.OnSend(sender, new UIActionEventArgs());
  49. //string SelSQL = @"SELECT PrintTemplateText FROM Cust_PrintTemplateText WHERE PrintTemplateTypeName='" + this.DropDownList_Notices.Text + "'";
  50. //DataSet SelSQLDs = new DataSet();
  51. //UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), SelSQL.ToString(), null, out SelSQLDs);
  52. //DataTable dt = new DataTable();
  53. //dt = SelSQLDs.Tables[0];
  54. //if (dt.Rows.Count < 1)
  55. //{
  56. // throw new Exception("配置表Cust_PrintTemplateText中不存在对应信息,请先维护");
  57. //}
  58. 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."
  59. + "\r\n" + "Best Regards" + "\r\n" + "The information contained in this message is confidential and may be " +
  60. "legally privileged. The message is intended solely for the addressee(s). " +
  61. "If you are not the intended recipient, you are hereby notified that any use,dissemination " +
  62. "or reproduction is strictly prohibited and may be unlawful. If you are not the intended recipient, " +
  63. "please contact the sender by return e-mail and destroy all copies of the original message.";
  64. this.DataCollect();
  65. this.DataBind();
  66. DropDownList_Notices_TextChanged_DefaultImpl(sender, e);
  67. }
  68. //OnSend273_Click...
  69. private void OnSend273_Click_Extend(object sender, EventArgs e)
  70. {
  71. //调用模版提供的默认实现.--默认实现可能会调用相应的Action.
  72. IUIRecordCollection records = this.Model.CustPOSendMailPerson.SelectRecords;
  73. if (records == null || records.Count == 0)
  74. {
  75. throw new Exception("请先勾选发件人");
  76. }
  77. string MailAddress = string.Empty;
  78. if (records.Count > 0)
  79. {
  80. foreach (var item in records)
  81. {
  82. string RcvPerson = string.Empty;
  83. string Telephone = string.Empty;
  84. RcvPerson = item["RcvPerson"].ToString();
  85. Telephone = item["Telephone"].ToString();
  86. if (string.IsNullOrWhiteSpace(item["MailAddress"].ToString()))
  87. {
  88. throw new Exception("邮箱地址为空");
  89. }
  90. MailAddress += item["MailAddress"].ToString() + ";";
  91. if (string.IsNullOrWhiteSpace(MailAddress))
  92. {
  93. throw new Exception("邮箱地址为空");
  94. }
  95. }
  96. }
  97. SendMail(MailAddress);
  98. OnSend273_Click_DefaultImpl(sender, e);
  99. }
  100. private void SendMail(string TOAddress)
  101. {
  102. string printTemplateID = this.PrintTemplates278.Value.ToString();
  103. this.DataCollect();
  104. this.DataBind();
  105. if (string.IsNullOrWhiteSpace(this.PrintTemplates278.Value.ToString()))
  106. {
  107. throw new Exception("请选择模板");
  108. }
  109. string connectionString = UFSoft.UAP.Report.Base.DBConnectionHelper.GetConnectionString();
  110. string cultrueName = UFSoft.UBF.Util.Context.PlatformContext.Current.Culture;
  111. ReportMDService service = ReportMDService.GetInstance(connectionString, cultrueName);
  112. IReportMDReader reader = service.GetReader();
  113. IReportTemplate reportTemplate = reader.GetReportTemplateByID(printTemplateID);
  114. UFSoft.UBF.Report.Entity.Report report = (UFSoft.UBF.Report.Entity.Report)reportTemplate.Content;
  115. reader.Dispose();
  116. DataSet ds = new DataSet();
  117. string fileName = OutPutFile(report, ds, printTemplateID);
  118. string _NewFile = string.Empty;
  119. string __NewFile = string.Empty;
  120. ArrayList list = new ArrayList();
  121. //读取指定目录的文件
  122. if (!Directory.Exists(filePath))
  123. {
  124. Directory.CreateDirectory(filePath);
  125. }
  126. else
  127. {
  128. DirectoryInfo dirIfo = new DirectoryInfo(filePath);
  129. FileInfo[] files = dirIfo.GetFiles();
  130. for (int k = files.Length - 1; k >= 0; k--)
  131. {
  132. if (fileName == files[k].FullName)
  133. {
  134. list.Add(files[k].FullName);
  135. _NewFile = filePath + "\\" + "采购订单" + CurrentState["POCode"].ToString() + "" + ".pdf";
  136. __NewFile = filePathD + "\\" + "采购订单" + CurrentState["POCode"].ToString() + "" + ".pdf";
  137. File.Delete(_NewFile);
  138. File.Move(files[k].FullName, _NewFile);
  139. File.Move(_NewFile, __NewFile);
  140. }
  141. }
  142. }
  143. string MailBoxConfigurationSQL = @"SELECT SendHost,SendPort,SendDisplayName,SendAddress,SendPassword,TOAddress,
  144. CCAddress,Subject,IsBodyHtml FROM [Cust_MailBoxConfiguration ]";
  145. DataSet MailBoxConfigurationDs = new DataSet();
  146. UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), MailBoxConfigurationSQL.ToString(), null, out MailBoxConfigurationDs);
  147. DataTable MailBoxConfigurationDT = new DataTable();
  148. if (MailBoxConfigurationDs != null && MailBoxConfigurationDs.Tables.Count > 0 && MailBoxConfigurationDs.Tables[0].Rows.Count > 0)
  149. {
  150. MailBoxConfigurationDT = MailBoxConfigurationDs.Tables[0];
  151. }
  152. string SendHost = string.Empty;
  153. int SendPort = 0;
  154. string SendAddress = string.Empty; ;
  155. string SendPassword = string.Empty; ;
  156. string CCAddress = string.Empty; ;
  157. foreach (DataRow item in MailBoxConfigurationDT.Rows)
  158. {
  159. SendHost = item["SendHost"].ToString();
  160. if (!string.IsNullOrWhiteSpace(item["SendPort"].ToString()))
  161. {
  162. SendPort = Int32.Parse(item["SendPort"].ToString());
  163. }
  164. SendAddress = item["SendAddress"].ToString();
  165. SendPassword = item["SendPassword"].ToString();
  166. CCAddress = item["CCAddress"].ToString();
  167. }
  168. string[] mailNames = TOAddress.Split(';');
  169. for (int i = 0; i < list.Count; i++)
  170. {
  171. SmtpClient client = new SmtpClient();
  172. client.Host = SendHost;//SMTP服务器地址
  173. client.EnableSsl = true;
  174. client.UseDefaultCredentials = false;
  175. //发件人邮箱账号
  176. client.Credentials = new System.Net.NetworkCredential(SendAddress, SendPassword);
  177. MailAddress from = new MailAddress(SendAddress, SendPassword); //邮件的发件人
  178. MailMessage message = new MailMessage();
  179. try
  180. {
  181. foreach (var MailItem in mailNames)
  182. {
  183. if (!string.IsNullOrWhiteSpace(MailItem))
  184. {
  185. message.To.Add(MailItem);//收件人地址
  186. }
  187. }
  188. if (!string.IsNullOrWhiteSpace(CCAddress))
  189. {
  190. message.CC.Add(CCAddress);//抄送人邮箱
  191. }
  192. //string SelSQL = @"SELECT top 1 PrintTemplateText FROM Cust_PrintTemplateText ";
  193. //DataSet SelSQLDs = new DataSet();
  194. //UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), SelSQL.ToString(), null, out SelSQLDs);
  195. //DataTable dt = new DataTable();
  196. //dt = SelSQLDs.Tables[0];
  197. //if (dt.Rows.Count < 1)
  198. //{
  199. // throw new Exception("配置表Cust_PrintTemplateText中不存在对应信息,请先维护");
  200. //}
  201. message.From = new MailAddress(SendAddress);//发件人邮箱
  202. message.Subject = this.MailTitle86.Text;//邮件标题
  203. message.SubjectEncoding = Encoding.UTF8;//标题格式为UTF8
  204. //string _Body = dt.Rows[0][0].ToString();
  205. //string[] strArray = _Body.Split(new char[1] { ' ' });
  206. string _SelSQL = @"select c.DefaultEmail from PM_PurchaseOrder a
  207. left join CBO_Operators b on a.PurOper = b.ID
  208. left join Base_Contact c on b.Contact = c.ID
  209. where a.DocNo ='" + CurrentState["POCode"].ToString() + "' and a.Org='" + CurrentState["OrgID"].ToString() + "'";
  210. DataSet _SelSQLDs = new DataSet();
  211. UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), _SelSQL.ToString(), null, out _SelSQLDs);
  212. DataTable dtPur = new DataTable();
  213. dtPur = _SelSQLDs.Tables[0];
  214. if (dtPur.Rows.Count == 0)
  215. {
  216. throw new Exception("采购员未维护邮箱");
  217. }
  218. string PurMail = dtPur.Rows[0]["DefaultEmail"].ToString();//采购员收件邮箱
  219. string mailMessage = @"<html>
  220. <body>
  221. <table style='width: 100%; table-layout: fixed; font-size: 16px;' border: 0px cellspacing='4' >
  222. <tbody> ";
  223. int k = 0;
  224. mailMessage += string.Format(@"
  225. <tr>
  226. <td >{0}</td>
  227. </tr>
  228. ", "Dear Supplier:");
  229. mailMessage += string.Format(@"
  230. <tr>
  231. <td >{0}</td>
  232. </tr>
  233. ", "Please refer to the New PO, Confirm it within today and feedback the delivery date within 2 Days,Thanks.");
  234. mailMessage += string.Format(@"
  235. <tr>
  236. <td >{0}</td>
  237. </tr>
  238. ", "Best Regards");
  239. mailMessage += string.Format(@"
  240. <tr>
  241. <td >{0}</td>
  242. </tr>
  243. ", "The information contained in this message is confidential and may be legally privileged. " +
  244. "The message is intended solely for the addressee(s). If you are not the intended recipient," +
  245. " you are hereby notified that any use, dissemination or reproduction is strictly prohibited" +
  246. " and may be unlawful. If you are not the intended recipient, please contact the sender " +
  247. "by return e-mail and destroy all copies of the original message.");
  248. mailMessage += @" </table></body></html>";
  249. if (!string.IsNullOrEmpty(PurMail))
  250. {
  251. message.CC.Add(PurMail);//采购员抄送人邮箱
  252. }
  253. message.CC.Add("yu.zhou@panawincn.com");//采购经理抄送人邮箱
  254. message.Body = mailMessage;// mailContent;//邮件内容
  255. message.BodyEncoding = Encoding.UTF8;//内容格式为UTF8
  256. message.IsBodyHtml = true;//是否是HTML邮件
  257. message.Priority = MailPriority.Normal;//邮件优先级
  258. if (SendPort > 0)
  259. {
  260. client.Port = Convert.ToInt32(SendPort);// 25;
  261. }
  262. message.Attachments.Add(new Attachment(__NewFile)); // 发送附件
  263. client.Send(message);//发送邮件
  264. message.Dispose();
  265. File.Delete(fileName);
  266. File.Delete(_NewFile);
  267. File.Delete(__NewFile);
  268. this.CloseDialog();
  269. }
  270. catch (Exception ex)
  271. {
  272. message.Dispose();
  273. File.Delete(fileName);
  274. File.Delete(_NewFile);
  275. File.Delete(__NewFile);
  276. throw new Exception(ex.ToString());
  277. }
  278. }
  279. }
  280. private string OutPutFile(UFSoft.UBF.Report.Entity.Report template, DataSet data, string printTemplateID)
  281. {
  282. string sql = string.Empty;
  283. string SelSQL = @"SELECT a.PrintTemplateSQL FROM Cust_PrintTemplate a WHERE a.PrintTemplateID='" + printTemplateID + "'";
  284. DataSet SelSQLDs = new DataSet();
  285. UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), SelSQL.ToString(), null, out SelSQLDs);
  286. DataTable dt = new DataTable();
  287. if (SelSQLDs != null && SelSQLDs.Tables.Count > 0 && SelSQLDs.Tables[0].Rows.Count > 0)
  288. {
  289. dt = SelSQLDs.Tables[0];
  290. }
  291. sql = dt.Rows[0][0].ToString();
  292. sql = string.Format(sql, CurrentState["POCode"].ToString(), CurrentState["OrgID"].ToString());
  293. DataSet SelDs = new DataSet();
  294. UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql.ToString(), null, out SelDs);
  295. data = SelDs;
  296. PrintService printService = new PrintService();
  297. PrintCreater printCreater = new PrintCreater();
  298. printService.LoadXmlFormatFromString(printCreater.CreateReport(template).InnerXml);
  299. printService.LoadPrintData(data);
  300. printService.ConvertStart();
  301. string[] resultFilesName = printService.GetResultFilesName();
  302. return printService.PhysicalFilePrefix + resultFilesName[0];
  303. }
  304. //OnClose141_Click...
  305. private void OnClose141_Click_Extend(object sender, EventArgs e)
  306. {
  307. //调用模版提供的默认实现.--默认实现可能会调用相应的Action.
  308. OnClose141_Click_DefaultImpl(sender, e);
  309. }
  310. string OrgID = string.Empty;
  311. string SupplierName = string.Empty;
  312. string SupplierCode = string.Empty;
  313. string POCode = string.Empty;
  314. List<OperationResultContent> list = new List<OperationResultContent>();
  315. #region 自定义数据初始化加载和数据收集
  316. private void OnLoadData_Extend(object sender)
  317. {
  318. DropDownList_Notices.Items.Clear();
  319. //string _SelSQL = @"SELECT PrintTemplateTypeName FROM Cust_PrintTemplateText";
  320. //DataSet _SelSQLDs = new DataSet();
  321. //UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), _SelSQL.ToString(), null, out _SelSQLDs);
  322. //DataTable _dt = new DataTable();
  323. //_dt = _SelSQLDs.Tables[0];
  324. //if (_dt.Rows.Count < 1)
  325. //{
  326. // throw new Exception("配置表Cust_PrintTemplateText中不存在对应信息,请先维护");
  327. //}
  328. //foreach (DataRow item in _dt.Rows)
  329. //{
  330. // this.DropDownList_Notices.Items.Add("" + item["PrintTemplateTypeName"].ToString() + "");
  331. //}
  332. this.DropDownList_Notices.Items.Add("发送模板");
  333. DropDownList_Notices.SelectedIndex = 0;
  334. OrgID = CurrentState["OrgID"].ToString();
  335. SupplierName = CurrentState["SupplierName"].ToString();
  336. SupplierCode = CurrentState["SupplierCode"].ToString();
  337. POCode = CurrentState["POCode"].ToString();
  338. this.Model.CustPOSendMailPerson.Clear();
  339. CusSupplierContactBP.CusSelSupplierContactBP pro = new CusSupplierContactBP.CusSelSupplierContactBP();
  340. pro.OrgID = OrgID;
  341. pro.SupplierNo = SupplierCode;
  342. pro.PODocNo = POCode;
  343. list = new List<OperationResultContent>();
  344. list = pro.Do();
  345. if (list != null && list.Count > 0)
  346. {
  347. foreach (var item in list)
  348. {
  349. //IUIRecordCollection records = this.Model.CustPOSendMailPerson.SelectRecords;
  350. CustPOSendMailPersonRecord dataRwcord = this.Model.CustPOSendMailPerson.AddNewUIRecord();
  351. if (!string.IsNullOrWhiteSpace(item.SupplierContentName))
  352. {
  353. dataRwcord.RcvPerson = item.SupplierContentName;
  354. dataRwcord.Telephone = item.Telephoto;
  355. dataRwcord.MailAddress = item.Mail;
  356. dataRwcord.IsSelected = true;
  357. }
  358. }
  359. }
  360. OnLoadData_DefaultImpl(sender);
  361. string MaileTile = string.Empty;
  362. MaileTile = "采购订单 " + POCode + ","+ "供应商:" + SupplierName;
  363. //string SelSQL = @"SELECT top 1 PrintTemplateText FROM Cust_PrintTemplateText ";
  364. //DataSet SelSQLDs = new DataSet();
  365. //UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), SelSQL.ToString(), null, out SelSQLDs);
  366. //DataTable dt = new DataTable();
  367. //dt = SelSQLDs.Tables[0];
  368. //if (dt.Rows.Count < 1)
  369. //{
  370. // throw new Exception("配置表Cust_PrintTemplateText中不存在对应信息,请先维护");
  371. //}
  372. string _SelSQL = @"select c.DefaultEmail from PM_PurchaseOrder a
  373. left join CBO_Operators b on a.PurOper = b.ID
  374. left join Base_Contact c on b.Contact = c.ID
  375. where a.DocNo ='" + CurrentState["POCode"].ToString() + "' and a.Org='" + CurrentState["OrgID"].ToString() + "'";
  376. DataSet _SelSQLDs = new DataSet();
  377. UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), _SelSQL.ToString(), null, out _SelSQLDs);
  378. DataTable dtPur = new DataTable();
  379. dtPur = _SelSQLDs.Tables[0];
  380. if (dtPur.Rows.Count == 0)
  381. {
  382. throw new Exception("采购员未维护邮箱");
  383. }
  384. string PurMail = dtPur.Rows[0]["DefaultEmail"].ToString();//采购员收件邮箱
  385. this.MailTitle86.Text = MaileTile;
  386. 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."
  387. + "\r\n" + "Best Regards" + "\r\n" + "The information contained in this message is confidential and may be " +
  388. "legally privileged. The message is intended solely for the addressee(s). " +
  389. "If you are not the intended recipient, you are hereby notified that any use,dissemination " +
  390. "or reproduction is strictly prohibited and may be unlawful. If you are not the intended recipient, " +
  391. "please contact the sender by return e-mail and destroy all copies of the original message.";
  392. this.DataCollect();
  393. this.DataBind();
  394. }
  395. private void OnDataCollect_Extend(object sender)
  396. {
  397. OnDataCollect_DefaultImpl(sender);
  398. }
  399. #endregion
  400. #region 自己扩展 Extended Event handler
  401. public void AfterOnLoad()
  402. {
  403. }
  404. public void AfterCreateChildControls()
  405. {
  406. }
  407. public void AfterEventBind()
  408. {
  409. }
  410. public void BeforeUIModelBinding()
  411. {
  412. }
  413. public void AfterUIModelBinding()
  414. {
  415. }
  416. #endregion
  417. #endregion
  418. }
  419. }