刘彬 10 小時之前
父節點
當前提交
64364cd675

+ 22 - 8
LocalhostMES/Controller/MesController.cs

@@ -67,7 +67,7 @@ namespace LocalhostMES.Controller
 
                     return Ok(response);
                 }
-                else 
+                else
                 {
                     var errorResponse = new ErrorResponse
                     {
@@ -146,7 +146,7 @@ namespace LocalhostMES.Controller
                 }
                 var workOrder = DatabaseHelper.SelectWorkOrderInfo(request.WorkOrderNo);
                 // 验证工单是否存在
-                if ( workOrder.Count==0 )
+                if ( workOrder.Count == 0 )
                 {
                     return BadRequest($"工单 {request.WorkOrderNo} 不存在");
                 }
@@ -261,6 +261,8 @@ namespace LocalhostMES.Controller
         {
             try
             {
+
+
                 // 验证请求头
                 if ( !ValidateHeaders() )
                 {
@@ -294,12 +296,24 @@ namespace LocalhostMES.Controller
                             Employee = request.Employee ?? "",
                             ScanType = request.ScanTpye
                         };
-
-                       DatabaseHelper .InsertBindRecord(bindRecord);
+                        if ( DatabaseHelper.GetProductProductionRecords(request.Sn) != 0 )
+                        {
+                            var response = new ApiResponse<bool>
+                            {
+                                Code = "200",
+                                Success = true,
+                                Msg = "已存在记录",
+                                MsgTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                                TraceId = Guid.NewGuid().ToString("N").Substring(0, 24),
+                                Data = false
+                            };
+                            return Ok(response);
+                        }
+                        DatabaseHelper.InsertBindRecord(bindRecord);
                     }
                 }
 
-                var response = new ApiResponse<bool>
+                var okresponse = new ApiResponse<bool>
                 {
                     Code = "200",
                     Success = true,
@@ -309,7 +323,7 @@ namespace LocalhostMES.Controller
                     Data = true
                 };
 
-                return Ok(response);
+                return Ok(okresponse);
             }
             catch ( Exception ex )
             {
@@ -526,9 +540,9 @@ namespace LocalhostMES.Controller
                     return "未知";
             }
 
-            #endregion
-        }
 
+        }
+        #endregion
 
     }
 }

+ 9 - 1
LocalhostMES/Core/LogHelper.cs

@@ -4,6 +4,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows.Forms;
 
 namespace LocalhostMES.Core
 {
@@ -15,12 +16,19 @@ namespace LocalhostMES.Core
         public static readonly ILog logwarn = LogManager.GetLogger("logwarn");
         public static readonly ILog logfatal = LogManager.GetLogger("logfatal");
         public static readonly ILog logDynamic = LogManager.GetLogger("logDynamic");
+
+
+        public delegate void LogChangHandler(string msg);
+
+        public static LogChangHandler logChangHandler;
+
         public static void WriteLogInfo(string info)
         {
             if ( loginfo.IsInfoEnabled )
             {
-                loginfo.Info(info);
 
+                loginfo.Info(info);
+                logChangHandler?.Invoke(info);
             }
         }
 

+ 32 - 19
LocalhostMES/DataBase/DatabaseHelper.cs

@@ -1,4 +1,5 @@
-using LocalhostMES.Models;
+using LocalhostMES.Core;
+using LocalhostMES.Models;
 using SqlSugar;
 using System;
 using System.Collections.Generic;
@@ -15,7 +16,7 @@ namespace LocalhostMES.DataBase
         public static SqlSugarScope Db = new SqlSugarScope(new ConnectionConfig()
         {
             //192.168.1.100
-            ConnectionString = "Database=LingPaoProject; Data Source=Localhost; Port=3306;User Id=root; Password=root;Charset=utf8;TreatTinyAsBoolean=false;",//连接符字串
+            ConnectionString = "Database=LingPaoProject; Data Source=192.168.1.26; Port=3306;User Id=root; Password=root;Charset=utf8;TreatTinyAsBoolean=false;",//连接符字串
             DbType = SqlSugar.DbType.MySql,//数据库类型
             IsAutoCloseConnection = true //不设成true要手动close
         },
@@ -36,7 +37,21 @@ namespace LocalhostMES.DataBase
             Db.CodeFirst.InitTables<SnInfo>();
             Db.CodeFirst.InitTables<BindRecord>();
             Db.CodeFirst.InitTables<ProcessRecord>();
-            
+
+        }
+
+        public static int GetProductProductionRecords(string sn)
+        {
+            try
+            {
+                return Db.Queryable<ProductionToStation>().Where(it => it.SN == sn).ToList().Count;
+            }
+            catch ( Exception ex )
+            {
+                LogHelper.WriteLogError("获取一条产品的生产记录至数据库时出错!", ex);
+
+            }
+            return 0;
         }
         public static List<WorkOrderInfo> SelectWorkOrderInfo(string workOrderNo = null)
         {
@@ -47,24 +62,23 @@ namespace LocalhostMES.DataBase
             else
             {
                 return Db.Queryable<WorkOrderInfo>().ToList();
-                
-            }  
+            }
         }
-        
-        public static bool InsertWorkOrderInfo(WorkOrderInfo info) 
+
+        public static bool InsertWorkOrderInfo(WorkOrderInfo info)
         {
 
-           if( Db.Storageable(info).ExecuteCommand() == 1 )
+            if ( Db.Storageable(info).ExecuteCommand() == 1 )
             {
                 return true;
             }
-           return false;
+            return false;
         }
 
         public static bool UpdateWorkOrderInfo(WorkOrderInfo info)
         {
 
-            if ( Db.Updateable(info).Where(it=>it.WorkOrderNo==info.WorkOrderNo) .ExecuteCommand() == 1 )
+            if ( Db.Updateable(info).Where(it => it.WorkOrderNo == info.WorkOrderNo).ExecuteCommand() == 1 )
             {
                 return true;
             }
@@ -80,7 +94,7 @@ namespace LocalhostMES.DataBase
             }
             return false;
         }
-        public static List<SnInfo> SelectSnInfo(string workOrderNo = null, bool needused = false,bool isused=false)
+        public static List<SnInfo> SelectSnInfo(string workOrderNo = null, bool needused = false, bool isused = false)
         {
             if ( workOrderNo != null )
             {
@@ -88,7 +102,7 @@ namespace LocalhostMES.DataBase
                 {
                     return Db.Queryable<SnInfo>().Where(it => it.WorkOrderNo == workOrderNo && it.IsUsed == isused).ToList();
                 }
-                else 
+                else
                 {
                     return Db.Queryable<SnInfo>().Where(it => it.WorkOrderNo == workOrderNo).ToList();
                 }
@@ -96,7 +110,6 @@ namespace LocalhostMES.DataBase
             else
             {
                 return Db.Queryable<SnInfo>().ToList();
-
             }
         }
         public static bool InsertSnInfo(SnInfo info)
@@ -171,7 +184,7 @@ namespace LocalhostMES.DataBase
             return false;
         }
 
-        public static bool DeleteBindRecord(string sn=null)
+        public static bool DeleteBindRecord(string sn = null)
         {
             if ( sn != null )
             {
@@ -180,9 +193,9 @@ namespace LocalhostMES.DataBase
                     return true;
                 }
             }
-            else 
+            else
             {
-                if ( Db.Deleteable<BindRecord>().ExecuteCommand()!=0)
+                if ( Db.Deleteable<BindRecord>().ExecuteCommand() != 0 )
                 {
                     return true;
                 }
@@ -200,7 +213,7 @@ namespace LocalhostMES.DataBase
                 query = query.Where(it => it.Sn == Sn);
             }
 
-           
+
 
             if ( !string.IsNullOrWhiteSpace(StationCode) )
             {
@@ -230,7 +243,7 @@ namespace LocalhostMES.DataBase
             return false;
         }
 
-        public static bool DeleteProcessRecord(string sn=null)
+        public static bool DeleteProcessRecord(string sn = null)
         {
 
             if ( Db.Deleteable<ProcessRecord>().Where(it => it.Sn == sn).ExecuteCommand() == 1 )
@@ -239,7 +252,7 @@ namespace LocalhostMES.DataBase
             }
             return false;
         }
-        
+
 
     }
 }

+ 40 - 0
LocalhostMES/Enums/FormulaPartType.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace LocalhostMES.Enums
+{
+    /// <summary>
+    /// 配方站的类型
+    /// </summary>
+    public enum FormulaPartType
+    {
+        /// <summary>
+        /// OP10配方
+        /// </summary>
+        OP10Formula = 0,
+
+        /// <summary>
+        /// OP2030配方
+        /// </summary>
+        OP203040Formula = 1,
+
+        /// <summary>
+        /// OP4050配方
+        /// </summary>
+        OP506070Formula = 2,
+
+
+        /// <summary>
+        /// OP80配方
+        /// </summary>
+        OP80Formula = 3,
+
+        /// <summary>
+        /// OP90配方
+        /// </summary>
+        OP90Formula = 4,
+    }
+}

+ 1 - 0
LocalhostMES/LocalhostMES.csproj

@@ -406,6 +406,7 @@
     <Compile Include="Core\LogHelper.cs" />
     <Compile Include="Core\TrayIconManager.cs" />
     <Compile Include="DataBase\DatabaseHelper.cs" />
+    <Compile Include="Enums\FormulaPartType.cs" />
     <Compile Include="Enums\StationType.cs" />
     <Compile Include="Models\MesModel.cs" />
     <Compile Include="ViewModels\MainViewModel.cs" />

+ 51 - 1
LocalhostMES/Models/MesModel.cs

@@ -1,4 +1,6 @@
-using System;
+using LocalhostMES.Enums;
+using Prism.Mvvm;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -205,4 +207,52 @@ namespace LocalhostMES.Models
         public string Equipment { get; set; }
     }
     #endregion
+
+
+    #region
+    /// <summary>
+    /// 生产数据
+    /// </summary>
+    public class ProductionToStation : BindableBase
+    {
+
+        private Guid _id = Guid.NewGuid();
+        private string _SN;
+        private string _PartNum;
+        private DateTime _CreateTime;
+
+        private string _FormulaName;
+
+        private FormulaPartType _formulaPart;
+
+        private string _Result;
+
+        private List<ResultInfo> _resultContent = new List<ResultInfo>();
+
+        public Guid Id { get => _id; set { SetProperty(ref _id, value); } }
+        public DateTime CreateTime { get => _CreateTime; set { SetProperty(ref _CreateTime, value); } }
+        public string FormulaName { get => _FormulaName; set { SetProperty(ref _FormulaName, value); } }
+        public FormulaPartType FormulaPart { get => _formulaPart; set { SetProperty(ref _formulaPart, value); } }
+        public string Result { get => _Result; set { SetProperty(ref _Result, value); } }
+
+        [SqlSugar.SugarColumn(IsJson = true, ColumnDataType = "nvarchar(2000)")]//必填
+        public List<ResultInfo> ResultContent { get => _resultContent; set { SetProperty(ref _resultContent, value); } }
+
+        public string SN { get => _SN; set { SetProperty(ref _SN, value); } }
+        public string PartNum { get => _PartNum; set { SetProperty(ref _PartNum, value); } }
+    }
+
+
+    public class ResultInfo : BindableBase
+    {
+
+        private string resultName;
+        private string resultValue;
+        private string result;
+
+        public string ResultName { get => resultName; set { SetProperty(ref resultName, value); } }
+        public string ResultValue { get => resultValue; set { SetProperty(ref resultValue, value); } }
+        public string Result { get => result; set { SetProperty(ref result, value); } }
+    }
+    #endregion
 }

+ 2 - 0
LocalhostMES/Properties/AssemblyInfo.cs

@@ -53,3 +53,5 @@ using System.Windows;
 // [assembly: AssemblyVersion("1.0.*")]
 [assembly: AssemblyVersion("1.0.0.0")]
 [assembly: AssemblyFileVersion("1.0.0.0")]
+// 在程序启动时确保log4net配置已加载
+[assembly: log4net.Config.XmlConfigurator(Watch = true)]

+ 4 - 0
LocalhostMES/ViewModels/MainViewModel.cs

@@ -16,6 +16,7 @@ using Prism.Mvvm;
 using Prism.Commands;
 using System.Collections.ObjectModel;
 using System.Drawing;
+using LocalhostMES.Core;
 
 namespace LocalhostMES.ViewModels
 {
@@ -122,6 +123,7 @@ namespace LocalhostMES.ViewModels
 
 
 
+      
         private DelegateCommand _RefreshWorkOrdersCommand;
         public DelegateCommand RefreshWorkOrdersCommand =>
             _RefreshWorkOrdersCommand ?? ( _RefreshWorkOrdersCommand = new DelegateCommand(RefreshWorkOrders) );
@@ -173,6 +175,8 @@ namespace LocalhostMES.ViewModels
             _webApiService = new WebApiService(5000);
             // 初始化数据
             InitializeDataGrids();
+
+            LogHelper.logChangHandler += AddLog;
         }
 
         private void ExecuteLoadedCommand()