IcsFromERPJob
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.

193 lines
7.4 KiB

2 weeks ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Quartz;
  6. using System.Data;
  7. //using NFine.Data.Extensions;
  8. using System.Configuration;
  9. using ICSSoft.FromERP;
  10. //using ICSSoft.SendMail;
  11. using System.Data.SqlClient;
  12. using System.Net;
  13. using System.Net.Mail;
  14. using System.Security.Cryptography.X509Certificates;
  15. using System.Net.Security;
  16. namespace ICSSoft.FromERP
  17. {
  18. /// <summary>
  19. /// 发送SQE人员复判
  20. /// </summary>
  21. public class AutoSendMail_KBS : IJob
  22. {
  23. private static object key = new object();
  24. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  25. public void Execute(IJobExecutionContext context)
  26. {
  27. try
  28. {
  29. lock (key)
  30. {
  31. log.Info("开始……………………………………………………………………");
  32. Execute();
  33. log.Info("结束……………………………………………………………………");
  34. }
  35. }
  36. catch (Exception ex)
  37. {
  38. log.Error(ex.ToString());
  39. }
  40. }
  41. private void Execute()
  42. {
  43. string erpName = ICSHelper.GetConfigString()["ERPDB"];
  44. string conStr = ICSHelper.GetConnectString();
  45. string Namespace = this.GetType().Namespace;
  46. //string Class = this.GetType().Name;
  47. DataTable dt = ICSHelper.GetOldERPDB(conStr);
  48. foreach (DataRow dr1 in dt.Rows)
  49. {
  50. string WorkPoint = dr1["WorkPointCode"].ToString();
  51. string Class = this.GetType().Name + WorkPoint;
  52. string sql = @"select
  53. a.*
  54. from IcsMatCheckResult a with(nolock)
  55. where 1=1
  56. and a.WorkPoint='KC47'
  57. and a.CheckNo='CR202410290034'
  58. --and a.IsCheckComplete='是'
  59. --and a.AsnCode='DNA08S000072400088'
  60. --and a.InvCode='8S11332'
  61. --and a.InvBatcgNo=''
  62. order by a.Mtime desc
  63. ";
  64. DataTable dtInInfo = ICSHelper.ExecuteTable(conStr, sql);
  65. if (dtInInfo == null || dtInInfo.Rows.Count == 0)
  66. {
  67. return;
  68. }
  69. string MailOpen = ICSHelper.GetConfigString("MailOpen");
  70. if (MailOpen != "true")
  71. {
  72. return;
  73. }
  74. string SendHost = ICSHelper.GetConfigString("SendHost");
  75. string StrSendPort = ICSHelper.GetConfigString("SendPort");
  76. int SendPort = 25;
  77. if (!string.IsNullOrEmpty(StrSendPort))
  78. SendPort = Convert.ToInt32(ICSHelper.GetConfigString("SendPort"));
  79. string SendDisplayName = ICSHelper.GetConfigString("SendDisplayName");
  80. string SendAddress = ICSHelper.GetConfigString("SendAddress");
  81. string SendPassword = ICSHelper.GetConfigString("SendPassword");
  82. string sqls = @" select *
  83. from V_QuerySysEnumItem a
  84. where a.F_EnCode = 'SQESendMail'";
  85. DataTable dts = ICSHelper.ExecuteTable(conStr, sqls);
  86. string Email = string.Empty;
  87. foreach (DataRow drs in dts.Rows)
  88. {
  89. Email += drs["Ext1"].ToString() + ",";
  90. }
  91. foreach (DataRow dr in dtInInfo.Rows)
  92. {
  93. string TOAddress = Email.TrimEnd(',');
  94. string CCAddress = "";
  95. string Subject = "SQE复判提醒";
  96. bool isBodyHtml = true;
  97. //string VenName = dr["VENDORNAME"].ToString();
  98. //string STNO = dr["STNO"].ToString();
  99. string NowDate = DateTime.Now.GetDateTimeFormats('D')[0].ToString();
  100. string body = "SQE复判" + ":";
  101. body += "\r\n";
  102. body += " 您好!有一个来料复判的检验单,单号为:" + dr["CheckNo"].ToString() + " 的检验单已经超过48小时没有复判,请及时处理 !";
  103. body += "\r\n";
  104. body += " 苏州咖博士咖啡系统科技有限公司";
  105. body += "\r\n";
  106. body += " " + NowDate;
  107. //string StrConn = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
  108. SendEmail(conStr, SendHost, SendPort, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, isBodyHtml, body);
  109. }
  110. }
  111. }
  112. public void SendEmail(string ConnectionString, string SendHost, int SendPort, string SendDisplayName, string SendAddress, string SendPassword, string TOAddress, string CCAddress, string Subject, bool IsBodyHtml, string Body)
  113. {
  114. try
  115. {
  116. SmtpClient smtpClient = new SmtpClient
  117. {
  118. //EnableSsl = false,
  119. UseDefaultCredentials = false,
  120. Host = SendHost,
  121. Port = SendPort,
  122. Credentials = new NetworkCredential(SendAddress, SendPassword)
  123. };
  124. MailMessage mailMessage = new MailMessage
  125. {
  126. Subject = Subject,
  127. SubjectEncoding = Encoding.GetEncoding("utf-8"),
  128. BodyEncoding = Encoding.GetEncoding("utf-8"),
  129. From = new MailAddress(SendAddress, SendDisplayName),
  130. IsBodyHtml = IsBodyHtml,
  131. Body = Body
  132. };
  133. string[] array = TOAddress.Split(new char[]
  134. {
  135. ','
  136. });
  137. string[] array2 = array;
  138. for (int i = 0; i < array2.Length; i++)
  139. {
  140. string text = array2[i];
  141. if (!string.IsNullOrEmpty(text))
  142. {
  143. mailMessage.To.Add(text);
  144. }
  145. }
  146. string[] array3 = CCAddress.Split(new char[]
  147. {
  148. ','
  149. });
  150. array2 = array3;
  151. for (int i = 0; i < array2.Length; i++)
  152. {
  153. string text2 = array2[i];
  154. if (!string.IsNullOrEmpty(text2))
  155. {
  156. mailMessage.CC.Add(text2);
  157. }
  158. }
  159. ServicePointManager.ServerCertificateValidationCallback = ((object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) => true);
  160. smtpClient.Send(mailMessage);
  161. //InsertData(ConnectionString, SendHost, SendPort, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, IsBodyHtml, Body, "1", null);
  162. }
  163. catch (Exception ex)
  164. {
  165. //InsertData(ConnectionString, SendHost, SendPort, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, IsBodyHtml, Body, "2", ex.Message);
  166. throw ex;
  167. }
  168. }
  169. }
  170. }