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

534 lines
20 KiB

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