diff --git a/DB/DB.csproj b/DB/DB.csproj
index f2b613f..6d0326b 100644
--- a/DB/DB.csproj
+++ b/DB/DB.csproj
@@ -113,6 +113,7 @@
+
diff --git a/DB/Entity/UpdateLog.cs b/DB/Entity/UpdateLog.cs
index b32a37c..d4f5e72 100644
--- a/DB/Entity/UpdateLog.cs
+++ b/DB/Entity/UpdateLog.cs
@@ -15,7 +15,7 @@
///
/// 页面的Id
///
- public long FunctionId { get; set; }
+ public string PointName { get; set; }
}
diff --git a/DB/Service/UpdateLogService.cs b/DB/Service/UpdateLogService.cs
new file mode 100644
index 0000000..99b7531
--- /dev/null
+++ b/DB/Service/UpdateLogService.cs
@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.Text.RegularExpressions;
+using System.Windows.Forms.VisualStyles;
+using DB.Dto;
+using DB.Entity;
+
+using Tool;
+
+namespace DB.Service
+{
+ public class UpdateLogService
+ {
+ public bool AddOrUpdateLog(UserDto user,string address,uint value)
+ {
+ UpdateLog log = new UpdateLog
+ {
+ ID = SnowflakeFactory.NewId,
+ PointName = address,
+ CreateDate = DateTime.Now,
+ CreateUserId = user.Id.ToString(),
+ CreateUserName = user.UserName,
+ LastModifyUserId = "",
+ LastModifyUserName = "",
+ LastModifyDate = DateTime.Now
+ };
+
+ using (var dbContext = DbFactory.GetContext)
+ {
+ var firstOrDefault = dbContext.Query()
+ .Where(x=>x.PointName==address)
+ .OrderByDesc(x=>x.ID).FirstOrDefault();
+ if (firstOrDefault != null)
+ {
+ if (firstOrDefault.NewValue != value.ToString())
+ {
+
+ log.OldValue = firstOrDefault.NewValue;
+ log.NewValue = value.ToString();
+ dbContext.Insert(log);
+ }
+ }
+ else
+ {
+
+ log.OldValue = "";
+ log.NewValue = value.ToString();
+ dbContext.Insert(log);
+ }
+
+ }
+
+ return true;
+
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/RfidWeb/FormMain.cs b/RfidWeb/FormMain.cs
index 8a81ef3..18352eb 100644
--- a/RfidWeb/FormMain.cs
+++ b/RfidWeb/FormMain.cs
@@ -17,16 +17,22 @@ using Tool;
using System.Security.Principal;
using DB.Entity;
using DB;
+using System.Threading;
+using DB.Service;
+using NewLife.Caching;
+using Tool.Model;
namespace RfidWeb
{
public partial class FormMain : Form
{
private ILogNet logNet = ILogNetFactory.GetLogNet;
-
+ private ICache cache;
TimerX _timer;
public FormMain()
{
+ cache=Cache.Default;
+
DbInfo.Init(typeof(UserInfo).Assembly);
var rfidSetting = RfidSetting.Current;
@@ -59,6 +65,8 @@ namespace RfidWeb
this.panContent.Controls.Clear();
this.panContent.Controls.Add(new UserMain());
+
+
}
@@ -73,6 +81,36 @@ namespace RfidWeb
label1.Text = dataTime.ToString("yyyy'/'MM'/'dd");
label2.Text = dataTime.ToString("HH:mm:ss");
});
+
+ ThreadPoolX.QueueUserWorkItem(UpdateLog);
+ }
+
+ private UpdateLogService updateLogService = new UpdateLogService();
+
+
+ private void UpdateLog()
+ {
+ if(cache.ContainsKey("UpdateLog")) return;
+
+ cache.Set("UpdateLog", "d", TimeSpan.FromSeconds(10));
+ var plc = PlcConnect.Instance;
+ var userDto = TestFactory.TestUser();
+
+ var strings = HmiPoint.GetValue();
+
+ foreach (var se in strings)
+ {
+ var res = plc.ReadUInt32(se);
+ if (res.IsSuccess)
+ {
+ updateLogService.AddOrUpdateLog(userDto, se, res.Content);
+ }
+ }
+
+
+ cache.Remove("UpdateLog");
+
+
}
private void btnExit_Click(object sender, EventArgs e)
diff --git a/RfidWeb/FromSQl.cs b/RfidWeb/FromSQl.cs
index d14cf32..277ddcb 100644
--- a/RfidWeb/FromSQl.cs
+++ b/RfidWeb/FromSQl.cs
@@ -7,6 +7,7 @@ using System.Windows.Forms;
using Chloe.PostgreSQL.DDL;
using Chloe.RDBMS.DDL;
using Tool;
+using DB.Service;
namespace RfidWeb
{
@@ -145,52 +146,13 @@ namespace RfidWeb
private void ucBtnExt2_BtnClick(object sender, EventArgs e)
{
- var dbContext = DbFactory.GetContext;
- var dic = new Dictionary();
- dic["HMI_button_LP_ON[0].0"] = "右料盘横移电缸";
-
-
- for (int i = 1; i < 31; i++)
- {
- string key = "HMI_button_LP_ON[0]." + i;
- dic[key] = "";
- }
-
- for (int i = 0; i < 31; i++)
- {
- string key = "HMI_button_LP_ON[1]." + i;
- dic[key] = "";
- }
-
-
-
- foreach (var eti in dic)
- {
-
- Point p = new Point()
- {
- ID = GetId,
-
- FromType = "料盘页手动界面",
- DataType = "bool",
- CreateDate = DateTime.Now,
- LastModifyDate = DateTime.Now,
- CreateUserId = "",
- CreateUserName = "",
- LastModifyUserId = "",
- LastModifyUserName = "",
- PointName = eti.Value,
- PointAddress = eti.Key
- };
-
- dbContext.Insert(p);
-
+ DbInfo.Init(typeof(UserInfo).Assembly);
+ UpdateLogService service = new UpdateLogService();
+ service.AddOrUpdateLog(TestFactory.TestUser(), "test", 1);
- }
-
}
}
}
diff --git a/RfidWeb/Program.cs b/RfidWeb/Program.cs
index b70d3e4..fae68c3 100644
--- a/RfidWeb/Program.cs
+++ b/RfidWeb/Program.cs
@@ -19,8 +19,8 @@ namespace RfidWeb
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new FromSQl());
- //Application.Run(new FormMain());
+ //Application.Run(new FromSQl());
+ Application.Run(new FormMain());
}
}
}
diff --git a/RfidWeb/RfidWeb.csproj b/RfidWeb/RfidWeb.csproj
index e00c872..3f5ef9f 100644
--- a/RfidWeb/RfidWeb.csproj
+++ b/RfidWeb/RfidWeb.csproj
@@ -168,6 +168,7 @@
+
FormLogin.cs
diff --git a/RfidWeb/TestFactory.cs b/RfidWeb/TestFactory.cs
new file mode 100644
index 0000000..adde399
--- /dev/null
+++ b/RfidWeb/TestFactory.cs
@@ -0,0 +1,39 @@
+using DB.Dto;
+using DB.Service;
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.VisualBasic.ApplicationServices;
+
+namespace RfidWeb
+{
+ public class TestFactory
+ {
+ public static UserDto dto;
+ public static UserDto TestUser()
+ {
+ if (dto != null)
+ {
+ return dto;
+ }
+ long id = 7254397083167133696;
+ var userInfo = new UserService().Query(id);
+
+
+ UserDto user = new UserDto
+ {
+ Id = userInfo.ID,
+ UserName = userInfo.UserName,
+ RoleId = userInfo.RoleId,
+ RoleName ="管理员",
+ RoleLevel =1
+ };
+ dto = user;
+ return user;
+
+ }
+ }
+}
diff --git a/Tool/Model/HmiPoint.cs b/Tool/Model/HmiPoint.cs
new file mode 100644
index 0000000..1bd4083
--- /dev/null
+++ b/Tool/Model/HmiPoint.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace Tool.Model
+{
+ public class HmiPoint
+ {
+ ///
+ /// DInt 供料电机速度
+ ///
+ public static readonly string feeding_motor_speed = "feeding_motor_speed";
+
+
+ ///
+ /// DInt 层合电机速度
+ ///
+ public static readonly string Laminated_motor_speed = "Laminated_motor_speed";
+
+
+ ///
+ /// DInt 毛毡带电机速度
+ ///
+ public static readonly string Felt_belt_motor_speed = "Felt_belt_motor_speed";
+
+
+ ///
+ /// DInt 收料电机1速度
+ ///
+ public static readonly string Receiving_Electric_motor_speed_1 = "Receiving_Electric_motor_speed_1";
+
+
+ ///
+ /// DInt 收料电机2速度
+ ///
+ public static readonly string Receiving_Electric_motor_speed_2 = "Receiving_Electric_motor_speed_2";
+
+
+
+ public static string[] GetValue()
+ {
+ List ls = new List
+ {
+ feeding_motor_speed,
+ Laminated_motor_speed,
+ Felt_belt_motor_speed,
+ Receiving_Electric_motor_speed_1,
+ Receiving_Electric_motor_speed_2
+ };
+
+ return ls.ToArray();
+ }
+ }
+}
diff --git a/Tool/PlcConnect.cs b/Tool/PlcConnect.cs
index 34c37fb..4242469 100644
--- a/Tool/PlcConnect.cs
+++ b/Tool/PlcConnect.cs
@@ -106,10 +106,10 @@ namespace Tool
public static OperateResult WriteTag(string address, UInt32 num)
{
- OperateResult operate = Instance.WriteTag(address, 0xC4, num.GetBytes());
+ OperateResult result = Instance.WriteTag(address, 0xC4, num.GetBytes());
logNet.WriteInfo("打印日志", $"write 地址[{address}] value:[{num.ToString()}] type:[Tag] result:[{result.ToJsonString()}]");
- return operate;
+ return result;
}
}
diff --git a/Tool/RfidSetting.cs b/Tool/RfidSetting.cs
index 268a37a..833a771 100644
--- a/Tool/RfidSetting.cs
+++ b/Tool/RfidSetting.cs
@@ -16,7 +16,7 @@ namespace Tool
public string Db { get; set; } = "server=127.0.0.1;database=gaosu;uid=postgres;pwd=123456";
- public string PlcIp { get; set; } = "192.168.1.140";
+ public string PlcIp { get; set; } = "192.168.1.180";
public int Port { get; set; }=44818;
diff --git a/Tool/Tool.csproj b/Tool/Tool.csproj
index c54db9f..dc39b2a 100644
--- a/Tool/Tool.csproj
+++ b/Tool/Tool.csproj
@@ -68,6 +68,7 @@
+