Browse Source

接口程序添加发邮件功能

master
lvzb 4 years ago
parent
commit
6602a4e4ca
  1. 18
      SCP/Properties/PublishProfiles/FolderProfile.pubxml
  2. 7
      UniApiGroup/App.config
  3. 1
      UniApiGroup/CK.SCP.GrupUniApi.csproj
  4. 1
      UniApiGroup/Config/DurationConfig.cs
  5. 179
      UniApiGroup/Controller/MailController.cs
  6. 19
      UniApiGroup/FormMain.Designer.cs
  7. 9
      UniApiGroup/FormMain.cs
  8. 1
      UniApiGroup/IApi.cs
  9. 42
      UniApiGroup/QadOdbcApi.cs

18
SCP/Properties/PublishProfiles/FolderProfile.pubxml

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
此文件由 Web 项目的发布/打包过程使用。可以通过编辑此 MSBuild 文件
自定义此过程的行为。为了解与此相关的更多内容,请访问 https://go.microsoft.com/fwlink/?LinkID=208121。
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<PublishProvider>FileSystem</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>D:\work\JZJHPublish</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
</PropertyGroup>
</Project>

7
UniApiGroup/App.config

@ -4,6 +4,13 @@
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<appSettings>
<add key="MailSender" value="scp@jinhengairbag.com"/>
<add key="MailServer" value="smtp.qiye.aliyun.com"/>
<add key="MailUserName" value="scp@jinhengairbag.com"/>
<add key="MailPassword" value="SCPscp2020"/>
<add key="MailPort" value="25"/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>

1
UniApiGroup/CK.SCP.GrupUniApi.csproj

@ -86,6 +86,7 @@
<Compile Include="CktUniApiButton.Designer.cs">
<DependentUpon>CktUniApiButton.cs</DependentUpon>
</Compile>
<Compile Include="Controller\MailController.cs" />
<Compile Include="Controller\OdbcApiWmsController.cs" />
<Compile Include="UniApiController.cs" />
<Compile Include="Config\ApiType.cs" />

1
UniApiGroup/Config/DurationConfig.cs

@ -4,6 +4,7 @@
{
public int ERP接口发送 { get; set; } = 300;
public int ERP接口接收 { get; set; } = 300;
public int { get; set; } = 30000;
public int CsAntolinMES接口 { get; set; } = 217;
public int CsAntolinJIS搜索客户零件号变更 { get; set; } = 1;
public int CsAntolinJIS接收排序发货单 { get; set; } = 60;

179
UniApiGroup/Controller/MailController.cs

@ -0,0 +1,179 @@
using ChangKeTec.Wms.Models.Wms;
using CK.SCP.Common;
using CK.SCP.Models;
using CK.SCP.Models.AppBoxEntity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace CK.SCP.UniApi.Controller
{
public static class MailController
{
public class MailVend
{
public string Email { get; set; }
public string VendId { get; set; }
}
public static void GetNewCtrlList()
{
AppBoxContext idb = EntitiesFactory.CreateAppBoxInstance();
WmsEntities wmsdb = EntitiesFactory.CreateWmsInstance();
StringBuilder _buffer = new StringBuilder();
_buffer.Append("SELECT b.Email ,a.VenderId as VendId ");
_buffer.Append(" FROM VenderUsers AS a INNER JOIN ");
_buffer.Append(" Users AS b ON a.UserId = b.ID INNER JOIN ");
_buffer.Append(" FactoryUsers AS c ON a.UserId = c.UserID INNER JOIN ");
_buffer.Append(" TA_FACTORY AS d ON c.FACTORY_ID = d.ID INNER JOIN ");
_buffer.Append(" Users AS f ON c.UserID = f.ID INNER JOIN ");
_buffer.Append(" RoleUsers AS g ON a.UserId = g.UserID INNER JOIN ");
_buffer.Append(" Roles AS h ON g.RoleID = h.ID ");
_buffer.AppendFormat(" WHERE(h.Name = '供应商' and b.Enabled=1) ");
var _userList = idb.Database.SqlQuery<MailVend>(_buffer.ToString()).ToList();
var grouplist = _userList.GroupBy(r => r.VendId);
if (_userList != null && _userList.Count > 0)
{
foreach (var itm in grouplist)
{
var maillist = itm.Select(r => r.Email);
string mails = "";
foreach (var mail in maillist)
{
mails += mail + ",";
}
if (mails != "")
{
mails = mails.Substring(0, mails.Length - 1);
}
var stocklist = wmsdb.VIEW_STOCK_VEND.Where(r => r.VendId == itm.Key).ToList();
if (stocklist.Count() == 0)
{
continue;
}
var aaa = ToDataTable(stocklist);
var bb = GetHtmlString(aaa);
MyWebSmtpMail webmail = new MyWebSmtpMail();
webmail.Send(mails, bb, "库存");
Console.WriteLine($"发送邮件:供应商编码为{ itm.Key}");
}
}
}
#region 将list转换为datatable
/// <summary>
/// 将list转换为datatable
/// </summary>
public static DataTable ToDataTable<T>(List<T> items)
{
var tb = new DataTable(typeof(T).Name);
PropertyInfo[] props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo prop in props)
{
Type t = GetCoreType(prop.PropertyType);
tb.Columns.Add(prop.Name, t);
}
foreach (T item in items)
{
var values = new object[props.Length];
for (int i = 0; i < props.Length; i++)
{
values[i] = props[i].GetValue(item, null);
}
tb.Rows.Add(values);
}
return tb;
}
/// <summary>
/// Determine of specified type is nullable
/// </summary>
public static bool IsNullable(Type t)
{
return !t.IsValueType || (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>));
}
/// <summary>
/// Return underlying type if type is Nullable otherwise return the type
/// </summary>
public static Type GetCoreType(Type t)
{
if (t != null && IsNullable(t))
{
if (!t.IsValueType)
{
return t;
}
else
{
return Nullable.GetUnderlyingType(t);
}
}
else
{
return t;
}
}
#endregion
public static string GetHtmlString(DataTable dt)
{
StringBuilder sb = new StringBuilder();
sb.Append("<html><head>");
sb.Append("<title>Excel转换为Table</title>");
sb.Append("<meta http-equiv='content-type' content='text/html; charset=GB2312'> ");
sb.Append("<style type=text/css>");
sb.Append("td{font-size: 9pt;border:solid 1 #000000;}");
sb.Append("table{padding:3 0 3 0;border:solid 1 #000000;margin:0 0 0 0;BORDER-COLLAPSE: collapse;}");
sb.Append("</style>");
sb.Append("</head>");
sb.Append("<body>");
sb.Append("<table cellSpacing='0' cellPadding='0' width ='100%' border='1'>");
sb.Append("<tr valign='middle'>");
sb.Append("<td><b></b></td>");
foreach (DataColumn column in dt.Columns)
{
sb.Append("<td><b><span>" + column.ColumnName + "</span></b></td>");
}
sb.Append("</tr>");
int iColsCount = dt.Columns.Count;
int rowsCount = dt.Rows.Count - 1;
for (int j = 0; j <= rowsCount; j++)
{
sb.Append("<tr>");
sb.Append("<td>" + ((int)(j + 1)).ToString() + "</td>");
for (int k = 0; k <= iColsCount - 1; k++)
{
sb.Append("<td>");
object obj = dt.Rows[j][k];
if (obj == DBNull.Value)
{
obj = "&nbsp;";//如果是NULL则在HTML里面使用一个空格替换之
}
if (obj.ToString() == "")
{
obj = "&nbsp;";
}
string strCellContent = obj.ToString().Trim();
sb.Append("<span>" + strCellContent + "</span>");
sb.Append("</td>");
}
sb.Append("</tr>");
}
sb.Append("</table>");
//点击单元格 输出 行和列
//sb.Append("<script src='https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js'></script>");
//sb.Append("<script type='text/javascript'>");
//sb.Append("$('table tbody').on('click', 'td', function (e) {");
//sb.Append("var row = $(this).parent().prevAll().length-1 ;");
//sb.Append("var column = $(this).prevAll().length-1 ;");
//sb.Append("var str = 'dt.Rows[' + row + '][' + column + '].ToString()';");
//sb.Append("console.log(str);alert(str);");
//sb.Append("});");
//sb.Append("</script>");
sb.Append("</body></html>");
return sb.ToString();
}
}
}

19
UniApiGroup/FormMain.Designer.cs

@ -47,6 +47,7 @@
this.panelEx2 = new DevComponents.DotNetBar.PanelEx();
this.BtnErpPut = new CktUniApiButton();
this.BtnErpGet = new CktUniApiButton();
this.BtnErpMail = new CktUniApiButton();
this.bar1 = new DevComponents.DotNetBar.Bar();
this.labelItem1 = new DevComponents.DotNetBar.LabelItem();
this.txtDomain = new DevComponents.DotNetBar.TextBoxItem();
@ -274,6 +275,7 @@
this.panelEx2.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
this.panelEx2.Controls.Add(this.BtnErpPut);
this.panelEx2.Controls.Add(this.BtnErpGet);
this.panelEx2.Controls.Add(this.BtnErpMail);
this.panelEx2.DisabledBackColor = System.Drawing.Color.Empty;
this.panelEx2.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelEx2.Location = new System.Drawing.Point(0, 0);
@ -289,6 +291,22 @@
this.panelEx2.Style.GradientAngle = 90;
this.panelEx2.TabIndex = 29;
//
// BtnErpMail
//
this.BtnErpMail.Count = 0;
this.BtnErpMail.Dock = System.Windows.Forms.DockStyle.Top;
this.BtnErpMail.EnableManual = true;
this.BtnErpMail.InitCount = 0;
this.BtnErpMail.Location = new System.Drawing.Point(0, 100);
this.BtnErpMail.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.BtnErpMail.Name = "BtnErpMail";
this.BtnErpMail.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.BtnErpMail.Size = new System.Drawing.Size(170, 50);
this.BtnErpMail.SwitchEnabled = false;
this.BtnErpMail.TabIndex = 40;
this.BtnErpMail.Title = "发送邮件";
this.BtnErpMail.RunOnceExecute += new CktUniApiButton.RunOnceHandler(this.BtnErpMail_RunOnceExecute);
//
// BtnErpPut
//
this.BtnErpPut.Count = 0;
@ -423,6 +441,7 @@
private DevComponents.DotNetBar.PanelEx panelEx2;
private CktUniApiButton BtnErpPut;
private CktUniApiButton BtnErpGet;
private CktUniApiButton BtnErpMail;
private DevComponents.DotNetBar.Bar bar1;
private DevComponents.DotNetBar.LabelItem labelItem1;
private DevComponents.DotNetBar.TextBoxItem txtDomain;

9
UniApiGroup/FormMain.cs

@ -62,10 +62,12 @@ namespace CK.SCP.GrupUniApi
// BtnErpGet.Visible = false;
// BtnErpPut.Visible = false;
BtnErpGet.Count = GlobalVar.DurationConfig.ERP接口接收;
BtnErpPut.Count = GlobalVar.DurationConfig.ERP接口发送;
BtnErpPut.Count = GlobalVar.DurationConfig.ERP接口发送;
BtnErpMail.Count = GlobalVar.DurationConfig.;
BtnErpGet.InitCount = GlobalVar.DurationConfig.ERP接口接收;
BtnErpPut.InitCount = GlobalVar.DurationConfig.ERP接口发送;
BtnErpMail.InitCount = GlobalVar.DurationConfig.;
_timer = new Timer { Interval = 1000 };
@ -197,6 +199,9 @@ namespace CK.SCP.GrupUniApi
{
_iApi.Put();
}
private void BtnErpMail_RunOnceExecute()
{
_iApi.Mail();
}
}
}

1
UniApiGroup/IApi.cs

@ -5,5 +5,6 @@
void Get();
void Put();
void Mail();
}
}

42
UniApiGroup/QadOdbcApi.cs

@ -7,6 +7,7 @@ using CK.SCP.Models.UniApiEntity;
using CK.SCP.GrupUniApi.Controller;
using System.Transactions;
using System.Data.Entity.Core;
using CK.SCP.UniApi.Controller;
namespace CK.SCP.GrupUniApi
{
@ -14,7 +15,7 @@ namespace CK.SCP.GrupUniApi
{
private readonly BackgroundWorker _bgwGet = new BackgroundWorker();
private readonly BackgroundWorker _bgwPut = new BackgroundWorker();
private readonly BackgroundWorker _bgwMail = new BackgroundWorker();
public QadOdbcApi()
{
InitBgw();
@ -27,14 +28,19 @@ namespace CK.SCP.GrupUniApi
//回传给QAD
_bgwPut.DoWork += BgwPutDoWork;
_bgwPut.RunWorkerCompleted += BgwPutRunWorkerCompleted;
//发邮件
_bgwMail.DoWork += BgwMailDoWork;
_bgwMail.RunWorkerCompleted += BgwMailRunWorkerCompleted;
}
private void BgwPutRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Console.WriteLine(@"Odbc接口数据发送完成<<<<<<<<<<");
}
private void BgwMailRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Console.WriteLine(@"邮件发送完成<<<<<<<<<<");
}
private void BgwPutDoWork(object sender, DoWorkEventArgs e)
{
var idb = EntitiesFactory.CreateUniApiInstance();
@ -87,7 +93,22 @@ namespace CK.SCP.GrupUniApi
}
}
/// <summary>
/// 邮件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BgwMailDoWork(object sender, DoWorkEventArgs e)
{
try
{
MailController.GetNewCtrlList();
}
catch (Exception ex)
{
Console.WriteLine(string.Format("错误:{0}", ex.InnerException.Message));
}
}
private void BgwGetRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
@ -135,6 +156,19 @@ namespace CK.SCP.GrupUniApi
Console.WriteLine(ex);
}
}
public void Mail()
{
try
{
if (_bgwMail.IsBusy) return;
Console.WriteLine(@"发送邮件>>>>>>>>>>");
_bgwMail.RunWorkerAsync();
}
catch (ScpException ex)
{
Console.WriteLine(ex);
}
}
}
}
Loading…
Cancel
Save