From 6602a4e4ca4c863858812d9406fd1f7ca9d101aa Mon Sep 17 00:00:00 2001 From: lvzb <35200379@qq.com> Date: Thu, 22 Oct 2020 14:34:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=A8=8B=E5=BA=8F=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=8F=91=E9=82=AE=E4=BB=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PublishProfiles/FolderProfile.pubxml | 18 ++ UniApiGroup/App.config | 7 + UniApiGroup/CK.SCP.GrupUniApi.csproj | 1 + UniApiGroup/Config/DurationConfig.cs | 1 + UniApiGroup/Controller/MailController.cs | 179 ++++++++++++++++++ UniApiGroup/FormMain.Designer.cs | 19 ++ UniApiGroup/FormMain.cs | 9 +- UniApiGroup/IApi.cs | 1 + UniApiGroup/QadOdbcApi.cs | 42 +++- 9 files changed, 271 insertions(+), 6 deletions(-) create mode 100644 SCP/Properties/PublishProfiles/FolderProfile.pubxml create mode 100644 UniApiGroup/Controller/MailController.cs diff --git a/SCP/Properties/PublishProfiles/FolderProfile.pubxml b/SCP/Properties/PublishProfiles/FolderProfile.pubxml new file mode 100644 index 0000000..bb3d089 --- /dev/null +++ b/SCP/Properties/PublishProfiles/FolderProfile.pubxml @@ -0,0 +1,18 @@ + + + + + FileSystem + FileSystem + Release + Any CPU + + True + False + D:\work\JZJHPublish + False + + \ No newline at end of file diff --git a/UniApiGroup/App.config b/UniApiGroup/App.config index 286b0f3..796219c 100644 --- a/UniApiGroup/App.config +++ b/UniApiGroup/App.config @@ -4,6 +4,13 @@
+ + + + + + + diff --git a/UniApiGroup/CK.SCP.GrupUniApi.csproj b/UniApiGroup/CK.SCP.GrupUniApi.csproj index 88237f5..dde5b76 100644 --- a/UniApiGroup/CK.SCP.GrupUniApi.csproj +++ b/UniApiGroup/CK.SCP.GrupUniApi.csproj @@ -86,6 +86,7 @@ CktUniApiButton.cs + diff --git a/UniApiGroup/Config/DurationConfig.cs b/UniApiGroup/Config/DurationConfig.cs index 1ae049f..c90f27d 100644 --- a/UniApiGroup/Config/DurationConfig.cs +++ b/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; diff --git a/UniApiGroup/Controller/MailController.cs b/UniApiGroup/Controller/MailController.cs new file mode 100644 index 0000000..d0f516d --- /dev/null +++ b/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(_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 + /// + /// 将list转换为datatable + /// + public static DataTable ToDataTable(List 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; + } + /// + /// Determine of specified type is nullable + /// + public static bool IsNullable(Type t) + { + return !t.IsValueType || (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>)); + } + /// + /// Return underlying type if type is Nullable otherwise return the type + /// + 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(""); + sb.Append("Excel转换为Table"); + sb.Append(" "); + sb.Append(""); + sb.Append(""); + sb.Append(""); + sb.Append(""); + sb.Append(""); + sb.Append(""); + foreach (DataColumn column in dt.Columns) + { + sb.Append(""); + } + sb.Append(""); + int iColsCount = dt.Columns.Count; + int rowsCount = dt.Rows.Count - 1; + for (int j = 0; j <= rowsCount; j++) + { + sb.Append(""); + sb.Append(""); + for (int k = 0; k <= iColsCount - 1; k++) + { + sb.Append(""); + } + sb.Append(""); + } + sb.Append("
" + column.ColumnName + "
" + ((int)(j + 1)).ToString() + ""); + object obj = dt.Rows[j][k]; + if (obj == DBNull.Value) + { + obj = " ";//如果是NULL则在HTML里面使用一个空格替换之 + } + if (obj.ToString() == "") + { + obj = " "; + } + string strCellContent = obj.ToString().Trim(); + sb.Append("" + strCellContent + ""); + sb.Append("
"); + + //点击单元格 输出 行和列 + //sb.Append(""); + //sb.Append(""); + + sb.Append(""); + return sb.ToString(); + } + } +} diff --git a/UniApiGroup/FormMain.Designer.cs b/UniApiGroup/FormMain.Designer.cs index 9b83d2b..cf8b4ff 100644 --- a/UniApiGroup/FormMain.Designer.cs +++ b/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; diff --git a/UniApiGroup/FormMain.cs b/UniApiGroup/FormMain.cs index 3a976d8..32398e2 100644 --- a/UniApiGroup/FormMain.cs +++ b/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(); + } } } diff --git a/UniApiGroup/IApi.cs b/UniApiGroup/IApi.cs index 3816f31..ab58101 100644 --- a/UniApiGroup/IApi.cs +++ b/UniApiGroup/IApi.cs @@ -5,5 +5,6 @@ void Get(); void Put(); + void Mail(); } } \ No newline at end of file diff --git a/UniApiGroup/QadOdbcApi.cs b/UniApiGroup/QadOdbcApi.cs index 34d4dd8..c11b649 100644 --- a/UniApiGroup/QadOdbcApi.cs +++ b/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 } } - + /// + /// 邮件 + /// + /// + /// + 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); + } + } } } \ No newline at end of file