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

543 lines
22 KiB

11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
8 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
11 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
8 months ago
8 months ago
8 months ago
11 months ago
8 months ago
8 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 months ago
8 months ago
11 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. message.CC.Add(PurMail);//采购员抄送人邮箱
  250. message.CC.Add("yu.zhou@panawincn.com");//采购经理抄送人邮箱
  251. message.Body = mailMessage;// mailContent;//邮件内容
  252. message.BodyEncoding = Encoding.UTF8;//内容格式为UTF8
  253. message.IsBodyHtml = true;//是否是HTML邮件
  254. message.Priority = MailPriority.Normal;//邮件优先级
  255. if (SendPort > 0)
  256. {
  257. client.Port = Convert.ToInt32(SendPort);// 25;
  258. }
  259. message.Attachments.Add(new Attachment(__NewFile)); // 发送附件
  260. client.Send(message);//发送邮件
  261. message.Dispose();
  262. File.Delete(fileName);
  263. File.Delete(_NewFile);
  264. File.Delete(__NewFile);
  265. this.CloseDialog();
  266. }
  267. catch (Exception ex)
  268. {
  269. message.Dispose();
  270. File.Delete(fileName);
  271. File.Delete(_NewFile);
  272. File.Delete(__NewFile);
  273. throw new Exception(ex.ToString());
  274. }
  275. }
  276. }
  277. private string OutPutFile(UFSoft.UBF.Report.Entity.Report template, DataSet data, string printTemplateID)
  278. {
  279. string sql = string.Empty;
  280. string SelSQL = @"SELECT a.PrintTemplateSQL FROM Cust_PrintTemplate a WHERE a.PrintTemplateID='" + printTemplateID + "'";
  281. DataSet SelSQLDs = new DataSet();
  282. UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), SelSQL.ToString(), null, out SelSQLDs);
  283. DataTable dt = new DataTable();
  284. if (SelSQLDs != null && SelSQLDs.Tables.Count > 0 && SelSQLDs.Tables[0].Rows.Count > 0)
  285. {
  286. dt = SelSQLDs.Tables[0];
  287. }
  288. sql = dt.Rows[0][0].ToString();
  289. sql = string.Format(sql, CurrentState["POCode"].ToString(), CurrentState["OrgID"].ToString());
  290. DataSet SelDs = new DataSet();
  291. UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), sql.ToString(), null, out SelDs);
  292. data = SelDs;
  293. PrintService printService = new PrintService();
  294. PrintCreater printCreater = new PrintCreater();
  295. printService.LoadXmlFormatFromString(printCreater.CreateReport(template).InnerXml);
  296. printService.LoadPrintData(data);
  297. printService.ConvertStart();
  298. string[] resultFilesName = printService.GetResultFilesName();
  299. return printService.PhysicalFilePrefix + resultFilesName[0];
  300. }
  301. //OnClose141_Click...
  302. private void OnClose141_Click_Extend(object sender, EventArgs e)
  303. {
  304. //调用模版提供的默认实现.--默认实现可能会调用相应的Action.
  305. OnClose141_Click_DefaultImpl(sender, e);
  306. }
  307. string OrgID = string.Empty;
  308. string SupplierName = string.Empty;
  309. string SupplierCode = string.Empty;
  310. string POCode = string.Empty;
  311. List<OperationResultContent> list = new List<OperationResultContent>();
  312. #region 自定义数据初始化加载和数据收集
  313. private void OnLoadData_Extend(object sender)
  314. {
  315. DropDownList_Notices.Items.Clear();
  316. //string _SelSQL = @"SELECT PrintTemplateTypeName FROM Cust_PrintTemplateText";
  317. //DataSet _SelSQLDs = new DataSet();
  318. //UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), _SelSQL.ToString(), null, out _SelSQLDs);
  319. //DataTable _dt = new DataTable();
  320. //_dt = _SelSQLDs.Tables[0];
  321. //if (_dt.Rows.Count < 1)
  322. //{
  323. // throw new Exception("配置表Cust_PrintTemplateText中不存在对应信息,请先维护");
  324. //}
  325. //foreach (DataRow item in _dt.Rows)
  326. //{
  327. // this.DropDownList_Notices.Items.Add("" + item["PrintTemplateTypeName"].ToString() + "");
  328. //}
  329. this.DropDownList_Notices.Items.Add("发送模板");
  330. DropDownList_Notices.SelectedIndex = 0;
  331. OrgID = CurrentState["OrgID"].ToString();
  332. SupplierName = CurrentState["SupplierName"].ToString();
  333. SupplierCode = CurrentState["SupplierCode"].ToString();
  334. POCode = CurrentState["POCode"].ToString();
  335. this.Model.CustPOSendMailPerson.Clear();
  336. CusSupplierContactBP.CusSelSupplierContactBP pro = new CusSupplierContactBP.CusSelSupplierContactBP();
  337. pro.OrgID = OrgID;
  338. pro.SupplierNo = SupplierCode;
  339. pro.PODocNo = POCode;
  340. list = new List<OperationResultContent>();
  341. list = pro.Do();
  342. if (list != null && list.Count > 0)
  343. {
  344. foreach (var item in list)
  345. {
  346. //IUIRecordCollection records = this.Model.CustPOSendMailPerson.SelectRecords;
  347. CustPOSendMailPersonRecord dataRwcord = this.Model.CustPOSendMailPerson.AddNewUIRecord();
  348. if (!string.IsNullOrWhiteSpace(item.SupplierContentName))
  349. {
  350. dataRwcord.RcvPerson = item.SupplierContentName;
  351. dataRwcord.Telephone = item.Telephoto;
  352. dataRwcord.MailAddress = item.Mail;
  353. dataRwcord.IsSelected = true;
  354. }
  355. }
  356. }
  357. OnLoadData_DefaultImpl(sender);
  358. string MaileTile = string.Empty;
  359. MaileTile = "采购订单 " + POCode + "已经审批,"+ "供应商:" + SupplierName;
  360. //string SelSQL = @"SELECT top 1 PrintTemplateText FROM Cust_PrintTemplateText ";
  361. //DataSet SelSQLDs = new DataSet();
  362. //UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), SelSQL.ToString(), null, out SelSQLDs);
  363. //DataTable dt = new DataTable();
  364. //dt = SelSQLDs.Tables[0];
  365. //if (dt.Rows.Count < 1)
  366. //{
  367. // throw new Exception("配置表Cust_PrintTemplateText中不存在对应信息,请先维护");
  368. //}
  369. string _SelSQL = @"select c.DefaultEmail from PM_PurchaseOrder a
  370. left join CBO_Operators b on a.PurOper = b.ID
  371. left join Base_Contact c on b.Contact = c.ID
  372. where a.DocNo ='" + CurrentState["POCode"].ToString() + "' and a.Org='" + CurrentState["OrgID"].ToString() + "'";
  373. DataSet _SelSQLDs = new DataSet();
  374. UFSoft.UBF.Util.DataAccess.DataAccessor.RunSQL(UFSoft.UBF.Util.DataAccess.DataAccessor.GetConn(), _SelSQL.ToString(), null, out _SelSQLDs);
  375. DataTable dtPur = new DataTable();
  376. dtPur = _SelSQLDs.Tables[0];
  377. if (dtPur.Rows.Count == 0)
  378. {
  379. throw new Exception("采购员未维护邮箱");
  380. }
  381. string PurMail = dtPur.Rows[0]["DefaultEmail"].ToString();//采购员收件邮箱
  382. this.MailTitle86.Text = MaileTile;
  383. 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."
  384. + "\r\n" + "Best Regards" + "\r\n" + "The information contained in this message is confidential and may be " +
  385. "legally privileged. The message is intended solely for the addressee(s). " +
  386. "If you are not the intended recipient, you are hereby notified that any use,dissemination " +
  387. "or reproduction is strictly prohibited and may be unlawful. If you are not the intended recipient, " +
  388. "please contact the sender by return e-mail and destroy all copies of the original message.";
  389. this.DataCollect();
  390. this.DataBind();
  391. }
  392. private void OnDataCollect_Extend(object sender)
  393. {
  394. OnDataCollect_DefaultImpl(sender);
  395. }
  396. #endregion
  397. #region 自己扩展 Extended Event handler
  398. public void AfterOnLoad()
  399. {
  400. }
  401. public void AfterCreateChildControls()
  402. {
  403. }
  404. public void AfterEventBind()
  405. {
  406. }
  407. public void BeforeUIModelBinding()
  408. {
  409. }
  410. public void AfterUIModelBinding()
  411. {
  412. }
  413. #endregion
  414. #endregion
  415. }
  416. }