Browse Source

no message

master
yangtm 1 month ago
parent
commit
b7fba02ac9
  1. 11
      ICSSoft.FromERP/ICSSoft.FromERP/ICSInventorySql.cs
  2. 7
      ICSSoft.FromERP/ICSSoft.FromERP/ICSSendEmail.cs
  3. 17
      ICSSoft.FromERP/ICSSoft.FromERP/ICSSoft.FromERP.csproj
  4. 282
      ICSSoft.FromERP/ICSSoft.FromERP/ICSWHSendMail.cs
  5. 25
      ICSSoft.FromERP/ICSSoft.FromERP/NpoiMemoryStream.cs
  6. BIN
      ICSSoft.FromERP/Root/Aspose.Cells.dll
  7. BIN
      ICSSoft.FromERP/Root/ICSSoft.Frame.Data.Entity.dll
  8. BIN
      ICSSoft.FromERP/Root/NPOI.OOXML.dll
  9. BIN
      ICSSoft.FromERP/Root/NPOI.OpenXml4Net.dll
  10. BIN
      ICSSoft.FromERP/Root/NPOI.OpenXmlFormats.dll
  11. BIN
      ICSSoft.FromERP/Root/NPOI.dll

11
ICSSoft.FromERP/ICSSoft.FromERP/ICSInventorySql.cs

@ -7,6 +7,7 @@ using Quartz;
using System.Data;
using ICSSoft.Frame.Data.Entity;
using ICSSoft.Base.Config.AppConfig;
using Newtonsoft.Json;
namespace ICSSoft.FromERP
{
@ -38,6 +39,7 @@ namespace ICSSoft.FromERP
{
try
{
log.Info("开始……………………………………………………………………");
string conStr = ICSHelper.GetConnectString();
string WHCode = ICSHelper.GetConfigString()["WHCode"];
//string[] WHCodeList= ICSHelper.GetConfigString()["WHCode"].Split(',');
@ -46,7 +48,6 @@ namespace ICSSoft.FromERP
try
{
foreach (DataRow dr in dt.Rows)
//foreach(string WHCode in WHCodeList)
{
string sql = "";
int Count = 0;
@ -74,6 +75,7 @@ namespace ICSSoft.FromERP
SAPGetINVZS.ZWMS_SK_MARAResponse result = new SAPGetINVZS.ZWMS_SK_MARAResponse();
client.Timeout = 600000;
result = client.CallZWMS_SK_MARA(Info);
//log.Info(JsonConvert.SerializeObject(result));
foreach (SAPGetINVZS.ZWMS_MARA item in result.T_MARA)
{
TotalCount++;
@ -92,9 +94,9 @@ namespace ICSSoft.FromERP
,InvIQC,InvFQC,EffectiveEnable,EffectiveDays,BatchEnable,LotEnable,PrintEnable
,MUSER,MUSERName,MTIME,WorkPoint,DrawingNo,Version)
values
('" + AppConfig.GetGuid() + "','" + item.MATNR.TrimStart('0') + "','" + item.MAKTX.Replace('\'','"') + "','" + item.DESCR.Replace('\'', '"') + @"'
('" + AppConfig.GetGuid() + "','" + item.MATNR.TrimStart('0') + "','" + item.MAKTX.Replace('\'', '"') + "','" + item.DESCR.Replace('\'', '"') + @"'
,'" + item.MEINS + "','" + item.MATKL + "','" + item.EXTWG + "','" + item.NTGEW + "','" + item.MTART + @"'
,0,0,0,0,0,0,0
,0,0,0,0,0,1,0
,'JOB','JOB','" + DateTime.Now + "','" + item.WERKS + "','" + item.TEST1 + "','" + item.TEST2 + @"')
END";
@ -122,9 +124,12 @@ namespace ICSSoft.FromERP
sql = "";
}
}
if (!string.IsNullOrWhiteSpace(sql))
{
ICSHelper.ExecuteDate(conStr, sql);
}
}
}
catch (Exception ex)
{
log.Error(ex.ToString());

7
ICSSoft.FromERP/ICSSoft.FromERP/ICSSendEmail.cs

@ -176,7 +176,12 @@ namespace ICSSoft.FromERP
{
try
{
string text = "INSERT INTO ICSSendMail(ID, SendHost, SendPort, SendDisplayName, SendAddress, \r\n SendPassword, TOAddress, CCAddress, Subject, IsBodyHtml, \r\n Body, Retry, Status, Message, MUSER, MUSERName, CreatTIME, ModifyTIME)\r\n VALUES(NEWID(),'{0}','{1}','{2}','{3}',\r\n '{4}','{5}','{6}','{7}','{8}',\r\n '{9}','0','{10}','{11}','','',GETDATE(),GETDATE())";
string text = @"INSERT INTO ICSSendMail(ID, SendHost, SendPort, SendDisplayName, SendAddress,
SendPassword, TOAddress, CCAddress, Subject, IsBodyHtml,
Body, Retry, Status, Message, MUSER, MUSERName, CreatTIME, ModifyTIME)
VALUES(NEWID(),'{0}','{1}','{2}','{3}',
'{4}','{5}','{6}','{7}','{8}',
'{9}','0','{10}','{11}','','',GETDATE(),GETDATE())";
text = string.Format(text, new object[]
{
SendHost,

17
ICSSoft.FromERP/ICSSoft.FromERP/ICSSoft.FromERP.csproj

@ -42,6 +42,9 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Aspose.Cells">
<HintPath>..\Root\Aspose.Cells.dll</HintPath>
</Reference>
<Reference Include="ICSSoft.Base.Config.AppConfig, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Debug\ICSSoft.Base.Config.AppConfig.dll</HintPath>
@ -55,6 +58,18 @@
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\50-job\Scheduler_4.0\Scheduler\JOB\Newtonsoft.Json.DLL</HintPath>
</Reference>
<Reference Include="NPOI">
<HintPath>..\Root\NPOI.dll</HintPath>
</Reference>
<Reference Include="NPOI.OOXML">
<HintPath>..\Root\NPOI.OOXML.dll</HintPath>
</Reference>
<Reference Include="NPOI.OpenXml4Net">
<HintPath>..\Root\NPOI.OpenXml4Net.dll</HintPath>
</Reference>
<Reference Include="NPOI.OpenXmlFormats">
<HintPath>..\Root\NPOI.OpenXmlFormats.dll</HintPath>
</Reference>
<Reference Include="Quartz">
<HintPath>..\..\..\50-job\Scheduler_4.0\Scheduler\JOB\Quartz.dll</HintPath>
</Reference>
@ -115,6 +130,8 @@
<Compile Include="ICSSendEmail.cs" />
<Compile Include="ICSWarehouse.cs" />
<Compile Include="ICSWareHouseLotInfoDoc.cs" />
<Compile Include="ICSWHSendMail.cs" />
<Compile Include="NpoiMemoryStream.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ICSInventory.cs" />
<Compile Include="ICSMo.cs" />

282
ICSSoft.FromERP/ICSSoft.FromERP/ICSWHSendMail.cs

@ -0,0 +1,282 @@
using Aspose.Cells;
using NPOI.SS.UserModel;
using Quartz;
using System;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace ICSSoft.FromERP
{
/// <summary>
/// 库存清单发送邮件
/// </summary>
public class ICSWHSendMail : IJob
{
private static object key = new object();
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public void Execute(IJobExecutionContext context)
{
try
{
lock (key)
{
log.Info("开始……………………………………………………………………");
Execute();
log.Info("结束……………………………………………………………………");
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
public void Execute()
{
log.Info("发送邮件开始……………………………………………………………………");
string sql = "";
try
{
string conStr = ICSHelper.GetConnectString();
string Namespace = this.GetType().Namespace;
string Class = this.GetType().Name;
string host = ICSHelper.GetConfigString()["Host"];//邮件服务器
string port = ICSHelper.GetConfigString()["Port"];//端口 默认25
string send = ICSHelper.GetConfigString()["SendDisplayName"];//发件人显示名称
string sendAccount = ICSHelper.GetConfigString()["SendAccount"];//发送邮箱账号
string sendPassWord = ICSHelper.GetConfigString()["SendPassWord"];//发送邮箱密码
string to = ICSHelper.GetConfigString()["ToAddress"].ToString();//接受邮箱地址
string cc = ICSHelper.GetConfigString()["CC"].ToString();//抄送邮箱地址
#region sql
sql = @"
SELECT DISTINCT c.ID,bb.oldlotno LotNO,b.INVCode ,b.INVNAME,b.INVPARSETYPE,b.INVSTD,b.INVMODELCODE InvType
,ISNULL(c.BatchNO, a.VenderLotNO) BatchNO, 1 rowNo
,ISNULL(c.ProductionDate, a.PRODUCTDATE) ProductionDate,ISNULL(c.ExpiryDate , DATEADD(DAY, b.INVShelfLife, a.PRODUCTDATE))ExpiryDate
FROM ICSDataCollectINVUP aa with(nolock)
inner JOIN #lotTable1 bb ON aa.mainlotno=bb.LOTNO2
INNER JOIN ICSITEMLot a with(nolock) ON aa.SubLotNo=a.LotNo
LEFT JOIN ICSINVENTORY b with(nolock) ON a.ItemCODE=b.invcode
LEFT JOIN ICSIsolationWareHouseLine c with(nolock) ON b.invcode=c.INVCode and bb.oldlotno=c.lotno
WHERE b.INVMODELCODE IS NOT NULL AND bb.oldlotno IN (SELECT * FROM #TABLE3)
) a order by rowNo
DROP TABLE #TABLE1
DROP TABLE #TABLE2
DROP TABLE #TABLE3
DROP TABLE #lotTable1";
#endregion
sql = string.Format(sql);
DataTable dt = new DataTable();// ICSHelper.GetDataTable(conStr, sql);
string html = @"<html><body>
<table border = 1 cellspacing = 0 cellpadding = 5><tbody>
<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr> ";
for (int i = 0; i < dt.Rows.Count; i++)
{
html += string.Format(@"<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td></tr> "
, dt.Rows[i]["LotNO"].ToString(), dt.Rows[i]["INVCode"].ToString(), dt.Rows[i]["INVNAME"].ToString(), dt.Rows[i]["INVPARSETYPE"].ToString()
, dt.Rows[i]["LotQty"].ToString(), dt.Rows[i]["ReceiveDate"].ToString(), dt.Rows[i]["ExpiryDate"].ToString(), dt.Rows[i]["StorageName"].ToString());
}
html += "</tbody></table><br/>";
string Subject = "产品/材料过期提醒";
sql = string.Format(@"INSERT INTO ICSSendMail
VALUES (newid(), '{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', NULL, 'job', 'job', getdate(), NULL);"
, host, port, send, sendAccount, sendPassWord, to, cc, Subject, 1, html, 0, 0);
ICSHelper.ExecuteDate(conStr, sql);
try
{
string Files = System.IO.Directory.GetCurrentDirectory() + @"\邮件\";
string File = ZLFExcel(dt, Files);
SendEmail(host, Convert.ToInt32(port), "", sendAccount, sendPassWord, to, cc, Subject, true, html, File);
}
catch (Exception ex)
{
throw ex;
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
log.Error(sql);
}
log.Info("发送邮件结束……………………………………………………………………");
}
#region 发邮件
public static void SendEmail(string SendHost, int SendPort, string SendDisplayName, string SendAddress, string SendPassword, string TOAddress, string CCAddress, string Subject, bool IsBodyHtml, string Body, string File)
{
try
{
SmtpClient smtpClient = new SmtpClient
{
//EnableSsl = false,
UseDefaultCredentials = false,
Host = SendHost,
Port = SendPort,
Credentials = new NetworkCredential(SendAddress, SendPassword)
};
MailMessage mailMessage = new MailMessage
{
Subject = Subject,
SubjectEncoding = Encoding.GetEncoding("utf-8"),
BodyEncoding = Encoding.GetEncoding("utf-8"),
From = new MailAddress(SendAddress, SendDisplayName),
IsBodyHtml = IsBodyHtml,
Body = Body
};
string SUpFile = File;
Attachment data = new Attachment(SUpFile, MediaTypeNames.Application.Octet);
//附件资料
System.Net.Mime.ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(SUpFile);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(SUpFile);
disposition.ReadDate = System.IO.File.GetLastAccessTime(SUpFile);
//加入邮件附件
mailMessage.Attachments.Add(data);
string[] array = TOAddress.Split(new char[]
{
','
});
string[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
string text = array2[i];
if (!string.IsNullOrEmpty(text))
{
mailMessage.To.Add(text);
}
}
string[] array3 = CCAddress.Split(new char[]
{
','
});
array2 = array3;
for (int i = 0; i < array2.Length; i++)
{
string text2 = array2[i];
if (!string.IsNullOrEmpty(text2))
{
mailMessage.CC.Add(text2);
}
}
ServicePointManager.ServerCertificateValidationCallback = ((object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) => true);
smtpClient.Send(mailMessage);
}
catch (Exception ex)
{
throw;
}
}
#endregion
public string ZLFExcel(DataTable dt1, string Files)
{
string TempletFileName = System.IO.Directory.GetCurrentDirectory() + @"\邮件\产品or材料过期提醒.xls";
IWorkbook workbook = null;
using (FileStream fs = System.IO.File.Open(TempletFileName, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite))
{
//把xls文件读入workbook变量里,之后就可以关闭了
workbook = WorkbookFactory.Create(fs);
fs.Close();
}
ISheet sheet = workbook.GetSheetAt(0);
ICellStyle cellStyle = workbook.CreateCellStyle();
//设置单元格上下左右边框线
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
//文字水平和垂直对齐方式
cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
ICell Cell = null;
IRow row = null;//创建行
int start = 1;//从第2行开始写入数据
//var line = db.SAL_AccountStatementLine.GetList(x => x.AccountStatement == ID).ToList();
int index = 1;
decimal CostMoney = 0;
for (int i = 0; i < dt1.Rows.Count; i++)
{
row = sheet.CreateRow(start);
for (int j = 0; j < 8; j++)
{
Cell = row.CreateCell(j);
Cell.CellStyle = cellStyle;
if (j == 0)
Cell.SetCellValue(dt1.Rows[i]["LotNO"].ToString());
else if (j == 1)
Cell.SetCellValue(dt1.Rows[i]["INVCode"].ToString());
else if (j == 2)
Cell.SetCellValue(dt1.Rows[i]["INVNAME"].ToString());
else if (j == 3)
Cell.SetCellValue(dt1.Rows[i]["INVPARSETYPE"].ToString());
else if (j == 4)
Cell.SetCellValue(dt1.Rows[i]["LotQty"].ToString());
else if (j == 5)
Cell.SetCellValue(dt1.Rows[i]["ReceiveDate"].ToString());
else if (j == 6)
Cell.SetCellValue(dt1.Rows[i]["ExpiryDate"].ToString());
else if (j == 7)
Cell.SetCellValue(dt1.Rows[i]["StorageName"].ToString());
}
start++;
index++;
string where = string.Format(" LotNO = '{0}' ", dt1.Rows[i]["LotNO"].ToString());
}
IFont font = workbook.CreateFont();
font.IsBold = false;
font.FontHeightInPoints = 16;
string fileName = "产品or材料过期提醒" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";
string excelPath = System.IO.Directory.GetCurrentDirectory() + @"\邮件\" + fileName;
//string pdf2 = DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
//string pdf = HttpContext.Current.Server.MapPath("/File/" + pdf2);
//保存
using (NpoiMemoryStream ms = new NpoiMemoryStream())
{
using (FileStream fs = new FileStream(excelPath, FileMode.Create, FileAccess.Write))
{
ms.AllowClose = false;
workbook.Write(ms);
ms.Flush();
ms.Seek(0, SeekOrigin.Begin);
ms.AllowClose = true;
byte[] datas = ms.ToArray();
fs.Write(datas, 0, datas.Length);
fs.Flush();
}
}
Workbook workbooks = new Workbook(excelPath);
return excelPath;
}
}
}

25
ICSSoft.FromERP/ICSSoft.FromERP/NpoiMemoryStream.cs

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ICSSoft.FromERP
{
public class NpoiMemoryStream : MemoryStream
{
public NpoiMemoryStream()
{
AllowClose = true;
}
public bool AllowClose { get; set; }
public override void Close()
{
if (AllowClose)
base.Close();
}
}
}

BIN
ICSSoft.FromERP/Root/Aspose.Cells.dll

Binary file not shown.

BIN
ICSSoft.FromERP/Root/ICSSoft.Frame.Data.Entity.dll

Binary file not shown.

BIN
ICSSoft.FromERP/Root/NPOI.OOXML.dll

Binary file not shown.

BIN
ICSSoft.FromERP/Root/NPOI.OpenXml4Net.dll

Binary file not shown.

BIN
ICSSoft.FromERP/Root/NPOI.OpenXmlFormats.dll

Binary file not shown.

BIN
ICSSoft.FromERP/Root/NPOI.dll

Binary file not shown.
Loading…
Cancel
Save