3 Commits 67aea48e15 ... 0e7e3d021f

Autor SHA1 Mensagem Data
  zhangliwen 0e7e3d021f 临时 1 ano atrás
  zhangliwen e23d6cd764 更新扫码逻辑,更新工单界面 1 ano atrás
  zhangliwen bbd2d86f97 修复工单bug 1 ano atrás

+ 4 - 7
SCADA_DAQ/Customer/Jobs/SyncRunTime.cs

@@ -69,15 +69,12 @@ namespace SCADA_DAQ.Customer.Jobs
             ProductionLineStateModel tableInfo = null;
             if (Env.SgIDAL.APP_TaiLing_ProductionLineStateRecord != null && Env.SgIDAL.APP_TaiLing_ProductionLineStateRecord.Exist(filterStr))
             {
-                tableInfo = Env.SgIDAL.APP_TaiLing_ProductionLineStateRecord?
-                    .GetData<ProductionLineStateModel>(filterStr)
-                    .OrderBy(t => t.ID).Last();
-            }
-            else
-            {
-                tableInfo = null;
+                tableInfo = Env.SgIDAL.APP_TaiLing_ProductionLineStateRecord
+                    .GetData<ProductionLineStateModel>(filterStr)?
+                    .OrderBy(t => t.ID).LastOrDefault();
             }
 
+
             if (tableInfo == null)
             {
                 Env.SgIDAL.APP_TaiLing_ProductionLineStateRecord?.Insert(

+ 46 - 38
SCADA_DAQ/Customer/Machines/ScannerMachine.cs

@@ -55,6 +55,8 @@ namespace SCADA_DAQ.Customer.Machines
         private static string lastScanCode = "";
         // 上次生产的工单号
         private static string lastOrderId = "";
+        // 上次生产的工单号
+        private static int lastId = -1;
 
         // 扫码队列
         Queue scanQueue = new Queue();
@@ -78,7 +80,8 @@ namespace SCADA_DAQ.Customer.Machines
             //    $"AND WorkShopId_Str='{scanItem.WorkShopId}' AND ProductionLineId_Str='{scanItem.ProductionLineId}'");
 
             Init();
-            if (lastOrderId == "")
+            //if (lastOrderId == "")
+            if (lastId == -1)
                 Log.Warn("上次生产的工单号数据已丢失");
         }
 
@@ -152,7 +155,7 @@ namespace SCADA_DAQ.Customer.Machines
             {
                 Log.Warn($"扫码枪ID无效 —— 当前扫码枪ID为{BaseDevice.DeviceID}");
             }
-            // 插入数据
+            // 持久化数据
             sqliteDAL.APP_TaiLing_ScanRecord.Insert(
                 new UpdateItem(DBNames.T_Col_Name.APP_TaiLing_ScanRecord.ScannerId_Str, BaseDevice.DeviceID),
                 new UpdateItem(DBNames.T_Col_Name.APP_TaiLing_ScanRecord.ScanData_Str, e.ReceiveMsg),
@@ -194,7 +197,8 @@ namespace SCADA_DAQ.Customer.Machines
             }
             else if (BaseDevice.DeviceID == "下料扫码枪")
             {
-                lastOrderId = taskInfoItem.OrderId;
+                //lastOrderId = taskInfoItem.OrderId;
+                lastId = taskInfoItem.ID;
                 CustomerEnv.CurrentTaskInfo.OrderSequence = taskInfoItem.OrderSequence;
                 CustomerEnv.CurrentTaskInfo.OrderId = taskInfoItem.OrderId;
                 CustomerEnv.CurrentTaskInfo.MotorcycleTypeName = taskInfoItem.MotorcycleTypeName;
@@ -435,7 +439,7 @@ namespace SCADA_DAQ.Customer.Machines
                 Log.Debug("空信息");
                 return;
             }
-            if (lastScanCode == scanMsg)  // 重复扫码
+            if (lastScanCode == scanMsg && !IsDev)  // 重复扫码,调试允许重复
             {
                 Log.Debug("重复扫码");
                 return;
@@ -519,24 +523,26 @@ namespace SCADA_DAQ.Customer.Machines
                 return;
             }
 
-            // 更新API缓存
-            //var tableCacheItem = GetTableCacheItem(lastOrderId);
-            
+
             // 更新工单
             // 计数
-            DAL.APP_TaiLing_TaskManagement.Update($"OrderId_Str='{scanItem.OrderId}' AND WorkShopId_Str='{scanItem.WorkShopId}' AND ProductionLineId_Str='{scanItem.ProductionLineId}'",
+            //DAL.APP_TaiLing_TaskManagement.Update($"OrderId_Str='{scanItem.OrderId}' AND WorkShopId_Str='{scanItem.WorkShopId}' AND ProductionLineId_Str='{scanItem.ProductionLineId}'",
+            //    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.CurrentProduction_Int, taskInfo.CurrentProduction + 1));
+            DAL.APP_TaiLing_TaskManagement.Update($"ID={taskInfo.ID}",
                 new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.CurrentProduction_Int, taskInfo.CurrentProduction + 1));
             CustomerEnv.CurrentTaskInfo.CurrentProduction = taskInfo.CurrentProduction + 1;
-            //if (tableCacheItem != null)
-            //{
-            //    tableCacheItem.CurrentProduction++;
-            //}
+
 
             if (taskInfo.CurrentProduction + 1 >= taskInfo.ScheduledProduction)
             {
                 // 结束生产 
                 var dateDiff = (DateTime.Now - taskInfo.WorkStartTime).TotalSeconds.ToInt();  // 时间差/s
-                DAL.APP_TaiLing_TaskManagement.Update($"OrderId_Str='{scanItem.OrderId}' AND WorkShopId_Str='{scanItem.WorkShopId}' AND ProductionLineId_Str='{scanItem.ProductionLineId}'",
+                //DAL.APP_TaiLing_TaskManagement.Update($"OrderId_Str='{scanItem.OrderId}' AND WorkShopId_Str='{scanItem.WorkShopId}' AND ProductionLineId_Str='{scanItem.ProductionLineId}'",
+                //    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.WorkEndTime_Dt, DateTime.Now.Format()),
+                //    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.DurationSec_Int, dateDiff),
+                //    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "已生产")
+                //);
+                DAL.APP_TaiLing_TaskManagement.Update($"ID={taskInfo.ID}",
                     new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.WorkEndTime_Dt, DateTime.Now.Format()),
                     new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.DurationSec_Int, dateDiff),
                     new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "已生产")
@@ -559,25 +565,27 @@ namespace SCADA_DAQ.Customer.Machines
 
 
             // 切换生产工单
-            if (currentOrderId != lastOrderId)
+            //if (currentOrderId != lastOrderId)
+            if (taskInfo.ID != lastId)
             {
                 // 表示该订单已被切换了                
+                //var oldTaskInfo = DAL.APP_TaiLing_TaskManagement.GetData<TaskManagementModel>()?
+                //    .Where(t => t.OrderId == lastOrderId).OrderBy(t => t.ID)
+                //    .Select(t => t.OrderState).LastOrDefault();
                 var oldTaskInfo = DAL.APP_TaiLing_TaskManagement.GetData<TaskManagementModel>()?
-                    .Where(t => t.OrderId == lastOrderId).Select(t => t.OrderState).LastOrDefault();
-                if (oldTaskInfo == null)
-                    return;
+                    .Where(t => t.ID == lastId).Select(t => t.OrderState).LastOrDefault();
+                //if (oldTaskInfo == null)
+                //    return;
                 if (oldTaskInfo == "生产中")
                 {
-                    DAL.APP_TaiLing_TaskManagement.Update($"OrderId_Str='{lastOrderId}' AND WorkShopId_Str='{scanItem.WorkShopId}' AND ProductionLineId_Str='{scanItem.ProductionLineId}'",
+                    //DAL.APP_TaiLing_TaskManagement.Update($"OrderId_Str='{lastOrderId}' AND WorkShopId_Str='{scanItem.WorkShopId}' AND ProductionLineId_Str='{scanItem.ProductionLineId}'",
+                    //    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "待生产"));
+                    DAL.APP_TaiLing_TaskManagement.Update($"ID={lastId}",
                         new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "待生产"));
-                    
-                    //// 更新API缓存
-                    //if (tableCacheItem != null)
-                    //{
-                    //    tableCacheItem.OrderState = "待生产";
-                    //}
+
                 }
-                lastOrderId = currentOrderId;
+                //lastOrderId = currentOrderId;
+                lastId = taskInfo.ID;
                 Log.Debug($"工单已切换为:{lastOrderId}");
             }
         }
@@ -586,19 +594,19 @@ namespace SCADA_DAQ.Customer.Machines
         #endregion
 
 
-        /// <summary>
-        /// 取出缓存表的数据
-        /// </summary>
-        /// <param name="filter"></param>
-        /// <returns></returns>
-        private TaskManagementModel GetTableCacheItem(string filter)
-        {
-            if (CustomerEnv.TaskInfoCache.Count <= 0)
-                return null;
-            var result = CustomerEnv.TaskInfoCache.Where(t => t.OrderId == filter)
-                .OrderBy(t => t.ID).LastOrDefault();
-            return result;
-        }
+        ///// <summary>
+        ///// 取出缓存表的数据
+        ///// </summary>
+        ///// <param name="filter"></param>
+        ///// <returns></returns>
+        //private TaskManagementModel GetTableCacheItem(string filter)
+        //{
+        //    if (CustomerEnv.TaskInfoCache.Count <= 0)
+        //        return null;
+        //    var result = CustomerEnv.TaskInfoCache.Where(t => t.OrderId == filter)
+        //        .OrderBy(t => t.ID).LastOrDefault();
+        //    return result;
+        //}
 
 
 

+ 2 - 0
SCADA_DAQ/Customer/Models/MotorcycleTypeManagement/AddMotorcycleTypeModel.cs

@@ -2,6 +2,7 @@
 using SqlSchema.DBNames;
 using System;
 using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -81,6 +82,7 @@ namespace SCADA_DAQ.Customer.Models.MotorcycleTypeManagement
         /// </summary>
         [AutoViewProperty("车型名称", Icon = "BedSingle")]
         [Column(T_Col_Name.APP_TaiLing_MotorcycleTypeManagement.MotorcycleTypeName_Str)]
+        [Required]   // 必须
         public string CarModelName
         {
             get { return _CarModelName; }

+ 6 - 2
SCADA_DAQ/Customer/Models/ProductionLineManagement/AddProductionLineManagementModel.cs

@@ -2,6 +2,7 @@
 using SqlSchema.DBNames;
 using System;
 using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -14,7 +15,7 @@ namespace SCADA_DAQ.Customer.Models.ProductionLineManagement
     [Table(nameof(SqlSchema.DBModel.APP_TaiLing_ProductionLineManagement))]
     public class AddProductionLineManagementModel : ObservableObject
     {
-        
+
 
         ///// <summary>
         ///// ID
@@ -38,8 +39,9 @@ namespace SCADA_DAQ.Customer.Models.ProductionLineManagement
         /// <summary>
         /// 车间号
         /// </summary>
-        [AutoViewProperty("车间号", Icon = "",IsEnable = true)]
+        [AutoViewProperty("车间号", Icon = "", IsEnable = true)]
         [Column(T_Col_Name.APP_TaiLing_ProductionLineManagement.WorkShopId_Str)]
+        [Required]
         public string WorkShopId
         {
             get { return _WorkShopId; }
@@ -60,6 +62,7 @@ namespace SCADA_DAQ.Customer.Models.ProductionLineManagement
         /// </summary>
         [AutoViewProperty("产线号", Icon = "", IsEnable = true)]
         [Column(T_Col_Name.APP_TaiLing_ProductionLineManagement.ProductionLineId_Str)]
+        [Required]
         public string ProductionLineId
         {
             get { return _ProductionLineId; }
@@ -82,6 +85,7 @@ namespace SCADA_DAQ.Customer.Models.ProductionLineManagement
         /// </summary>
         [AutoViewProperty("产线名称", Icon = "")]
         [Column(T_Col_Name.APP_TaiLing_ProductionLineManagement.ProductionLineName_Str)]
+        [Required]
         public string ProductionLineName
         {
             get { return _ProductionLineName; }

+ 11 - 6
SCADA_DAQ/Customer/Models/TaskManagement/AddTaskModel.cs

@@ -4,10 +4,12 @@ using SCADA_DAQ.Customer.Models.MotorcycleTypeManagement;
 using SqlSchema.DBNames;
 using System;
 using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
+
 namespace SCADA_DAQ.Customer.Models.TaskManagement
 {
     /// <summary>
@@ -20,7 +22,6 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
         /// <summary>
         /// 车间号
         /// </summary>
-        private string _WorkShopId = CustomerEnv.ProductionLineConfigValue.WorkShopId;
         [AutoViewProperty("车间号", Icon = "", IsEnable =false)]
         [Column(T_Col_Name.APP_TaiLing_TaskManagement.WorkShopId_Str)]
         public string WorkShopId
@@ -35,11 +36,11 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
                 }
             }
         }
+        private string _WorkShopId = CustomerEnv.ProductionLineConfigValue.WorkShopId;
 
         /// <summary>
         /// 产线号
         /// </summary>
-        private string _ProductionLineId = CustomerEnv.ProductionLineConfigValue.ProductionLineId;
         [AutoViewProperty("产线号", Icon = "", IsEnable =false)]
         [Column(T_Col_Name.APP_TaiLing_TaskManagement.ProductionLineId_Str)]
         public string ProductionLineId
@@ -54,13 +55,14 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
                 }
             }
         }
+        private string _ProductionLineId = CustomerEnv.ProductionLineConfigValue.ProductionLineId;
 
         /// <summary>
         /// 批次号
         /// </summary>
-        private string _OrderId;
         [AutoViewProperty("批次号", Icon = "")]
         [Column(T_Col_Name.APP_TaiLing_TaskManagement.OrderId_Str)]
+        [Required]   // 必须
         public string OrderId
         {
             get { return _OrderId; }
@@ -73,11 +75,11 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
                 }
             }
         }
+        private string _OrderId;
 
         /// <summary>
         /// 工单日期
         /// </summary>
-        private DateTime _OrderDatetime = DateTime.Now;
         [AutoViewProperty("工单日期", Icon = "")]
         [Column(T_Col_Name.APP_TaiLing_TaskManagement.OrderDatetime_Dt)]
         public DateTime OrderDatetime
@@ -92,11 +94,11 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
                 }
             }
         }
+        private DateTime _OrderDatetime = DateTime.Now;
 
         /// <summary>
         /// 工单顺序
         /// </summary>
-        private int _OrderSequence;
         [AutoViewProperty("工单顺序", Icon = "")]
         [Column(T_Col_Name.APP_TaiLing_TaskManagement.OrderSequence_Int)]
         public int OrderSequence
@@ -111,11 +113,11 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
                 }
             }
         }
+        private int _OrderSequence;
 
         /// <summary>
         /// 计划产量
         /// </summary>
-        private int _ScheduledProduction;
         [AutoViewProperty("计划产量", Icon = "")]
         [Column(T_Col_Name.APP_TaiLing_TaskManagement.ScheduledProduction_Int)]
         public int ScheduledProduction
@@ -130,6 +132,7 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
                 }
             }
         }
+        private int _ScheduledProduction;
 
 
         /// <summary>
@@ -180,6 +183,7 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
             DisplayMemberPath = "MotorcycleTypeName",
             SelectedValuePath = "MotorcycleTypeName")]
         [Column(T_Col_Name.APP_TaiLing_TaskManagement.MotorcycleTypeName_Str)]
+        [Required]   // 必须
         public string MotorcycleTypeName
         {
             get { return _MotorcycleTypeName; }
@@ -202,6 +206,7 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
             Env.SgIDAL.APP_TaiLing_MotorcycleTypeManagement.GetData<MotorcycleTypeModel>();
 
 
+
         /// <summary>
         /// 工单状态
         /// </summary>

+ 79 - 80
SCADA_DAQ/Customer/Models/TaskManagement/TaskManagementModel.cs

@@ -14,7 +14,6 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
     public class TaskManagementModel : ObservableObject
     {
 
-
         /// <summary>
         /// ID
         /// </summary>
@@ -33,49 +32,30 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
         }
         private int _ID;
 
-
         /// <summary>
-        /// 车间号
+        /// 工单日期
         /// </summary>
-        [AutoViewProperty("车间号", Icon = "")]
-        [Column(T_Col_Name.APP_TaiLing_TaskManagement.WorkShopId_Str)]
-        public string WorkShopId
+        [AutoViewProperty("工单日期", Icon = "", IsReadOnly =true)]
+        [Column(T_Col_Name.APP_TaiLing_TaskManagement.OrderDatetime_Dt)]
+        public DateTime OrderDatetime
         {
-            get { return _WorkShopId; }
+            get { return _OrderDatetime; }
             set
             {
-                if (value != _WorkShopId)
+                if (value != _OrderDatetime)
                 {
-                    _WorkShopId = value;
-                    OnPropertyChanged(nameof(WorkShopId));
+                    _OrderDatetime = value;
+                    OnPropertyChanged(nameof(OrderDatetime));
                 }
             }
         }
-        private string _WorkShopId;
+        private DateTime _OrderDatetime;
 
-        /// <summary>
-        /// 产线号
-        /// </summary>
-        [AutoViewProperty("产线号", Icon = "")]
-        [Column(T_Col_Name.APP_TaiLing_TaskManagement.ProductionLineId_Str)]
-        public string ProductionLineId
-        {
-            get { return _ProductionLineId; }
-            set
-            {
-                if (value != _ProductionLineId)
-                {
-                    _ProductionLineId = value;
-                    OnPropertyChanged(nameof(ProductionLineId));
-                }
-            }
-        }
-        private string _ProductionLineId;
 
         /// <summary>
         /// 批次号
         /// </summary>
-        [AutoViewProperty("批次号", Icon = "")]
+        [AutoViewProperty("批次号", Icon = "" ,IsReadOnly = true)]
         [Column(T_Col_Name.APP_TaiLing_TaskManagement.OrderId_Str)]
         public string OrderId
         {
@@ -91,48 +71,50 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
         }
         private string _OrderId;
 
+        
+
         /// <summary>
-        /// 工单日期
+        /// 工单顺序
         /// </summary>
-        [AutoViewProperty("工单日期", Icon = "")]
-        [Column(T_Col_Name.APP_TaiLing_TaskManagement.OrderDatetime_Dt)]
-        public DateTime OrderDatetime
+        [AutoViewProperty("工单顺序", Icon = "", IsReadOnly = true)]
+        [Column(T_Col_Name.APP_TaiLing_TaskManagement.OrderSequence_Int)]
+        public int OrderSequence
         {
-            get { return _OrderDatetime; }
+            get { return _OrderSequence; }
             set
             {
-                if (value != _OrderDatetime)
+                if (value != _OrderSequence)
                 {
-                    _OrderDatetime = value;
-                    OnPropertyChanged(nameof(OrderDatetime));
+                    _OrderSequence = value;
+                    OnPropertyChanged(nameof(OrderSequence));
                 }
             }
         }
-        private DateTime _OrderDatetime;
+        private int _OrderSequence;
 
         /// <summary>
-        /// 工单顺序
+        /// 车型名称
         /// </summary>
-        [AutoViewProperty("工单顺序", Icon = "")]
-        [Column(T_Col_Name.APP_TaiLing_TaskManagement.OrderSequence_Int)]
-        public int OrderSequence
+        [AutoViewProperty("车型名称", Icon = "", IsReadOnly = true)]
+        [Column(T_Col_Name.APP_TaiLing_TaskManagement.MotorcycleTypeName_Str)]
+        public string MotorcycleTypeName
         {
-            get { return _OrderSequence; }
+            get { return _MotorcycleTypeName; }
             set
             {
-                if (value != _OrderSequence)
+                if (value != _MotorcycleTypeName)
                 {
-                    _OrderSequence = value;
-                    OnPropertyChanged(nameof(OrderSequence));
+                    _MotorcycleTypeName = value;
+                    OnPropertyChanged(nameof(MotorcycleTypeName));
                 }
             }
         }
-        private int _OrderSequence;
+        private string _MotorcycleTypeName;
 
         /// <summary>
         /// 计划产量
         /// </summary>
-        [AutoViewProperty("计划产量", Icon = "")]
+        [AutoViewProperty("计划产量", Icon = "", IsReadOnly =false)]
         [Column(T_Col_Name.APP_TaiLing_TaskManagement.ScheduledProduction_Int)]
         public int ScheduledProduction
         {
@@ -167,10 +149,29 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
         }
         private int _CurrentProduction;
 
+        /// <summary>
+        /// 工单状态
+        /// </summary>
+        [AutoViewProperty("工单状态", Icon = "", IsReadOnly = false)]
+        [Column(T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str)]
+        public string OrderState
+        {
+            get { return _OrderState; }
+            set
+            {
+                if (value != _OrderState)
+                {
+                    _OrderState = value;
+                    OnPropertyChanged(nameof(OrderState));
+                }
+            }
+        }
+        private string _OrderState;
+
         /// <summary>
         /// 开始生产时间
         /// </summary>
-        [AutoViewProperty("开始生产时间", Icon = "")]
+        [AutoViewProperty("开始生产时间", Icon = "", IsReadOnly = true)]
         [Column(T_Col_Name.APP_TaiLing_TaskManagement.WorkStartTime_Dt)]
         public DateTime WorkStartTime
         {
@@ -189,7 +190,7 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
         /// <summary>
         /// 结束生产时间
         /// </summary>
-        [AutoViewProperty("结束生产时间", Icon = "")]
+        [AutoViewProperty("结束生产时间", Icon = "", IsReadOnly = true)]
         [Column(T_Col_Name.APP_TaiLing_TaskManagement.WorkEndTime_Dt)]
         public DateTime WorkEndTime
         {
@@ -206,63 +207,61 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
         private DateTime _WorkEndTime;
 
         /// <summary>
-        /// 工单状态
+        /// 生产总时长
         /// </summary>
-        [AutoViewProperty("工单状态", Icon = "")]
-        [Column(T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str)]
-        public string OrderState
+        [AutoViewProperty("生产总时长", Icon = "", IsReadOnly = true)]
+        [Column(T_Col_Name.APP_TaiLing_TaskManagement.DurationSec_Int)]
+        public int DurationSec
         {
-            get { return _OrderState; }
+            get { return _DurationSec; }
             set
             {
-                if (value != _OrderState)
+                if (value != _DurationSec)
                 {
-                    _OrderState = value;
-                    OnPropertyChanged(nameof(OrderState));
+                    _DurationSec = value;
+                    OnPropertyChanged(nameof(DurationSec));
                 }
             }
         }
-        private string _OrderState;
+        private int _DurationSec;
 
         /// <summary>
-        /// 车型名称
+        /// 车间号
         /// </summary>
-        [AutoViewProperty("车型名称", Icon = "")]
-        [Column(T_Col_Name.APP_TaiLing_TaskManagement.MotorcycleTypeName_Str)]
-        public string MotorcycleTypeName
+        [AutoViewProperty("车间号", Icon = "", IsReadOnly = true)]
+        [Column(T_Col_Name.APP_TaiLing_TaskManagement.WorkShopId_Str)]
+        public string WorkShopId
         {
-            get { return _MotorcycleTypeName; }
+            get { return _WorkShopId; }
             set
             {
-                if (value != _MotorcycleTypeName)
+                if (value != _WorkShopId)
                 {
-                    _MotorcycleTypeName = value;
-                    OnPropertyChanged(nameof(MotorcycleTypeName));
+                    _WorkShopId = value;
+                    OnPropertyChanged(nameof(WorkShopId));
                 }
             }
         }
-        private string _MotorcycleTypeName;
+        private string _WorkShopId;
 
         /// <summary>
-        /// 生产总时长
+        /// 产线号
         /// </summary>
-        [AutoViewProperty("生产总时长", Icon = "")]
-        [Column(T_Col_Name.APP_TaiLing_TaskManagement.DurationSec_Int)]
-        public int DurationSec
+        [AutoViewProperty("产线号", Icon = "", IsReadOnly = true)]
+        [Column(T_Col_Name.APP_TaiLing_TaskManagement.ProductionLineId_Str)]
+        public string ProductionLineId
         {
-            get { return _DurationSec; }
+            get { return _ProductionLineId; }
             set
             {
-                if (value != _DurationSec)
+                if (value != _ProductionLineId)
                 {
-                    _DurationSec = value;
-                    OnPropertyChanged(nameof(DurationSec));
+                    _ProductionLineId = value;
+                    OnPropertyChanged(nameof(ProductionLineId));
                 }
             }
         }
-        private int _DurationSec;
-
-
+        private string _ProductionLineId;
 
 
     }

+ 7 - 11
SCADA_DAQ/Customer/UctFrmParameterSet.xaml.cs

@@ -34,17 +34,13 @@ namespace SCADA_DAQ.Customer
         {
             InitializeComponent();
             ToolBar.Visibility=Visibility.Collapsed;
-            //ParameterSettings.Content = new AutoView(CustomerEnv.ProductionLineConfigValue, new string[]
-            //{
-            //    nameof(ParameterSettingsModel.WorkShopId),
-            //    nameof(ParameterSettingsModel.ProductionLineId),
-            //    nameof(ParameterSettingsModel.ProductionLineAdministrator),
-            //    nameof(ParameterSettingsModel.ProductionLineName),
-            //    nameof(ParameterSettingsModel.ProductionLineShortName),
-            //    nameof(ParameterSettingsModel.NumberOfPeople),
-            //    nameof(ParameterSettingsModel.PLCName)
-            //})
-            ParameterSettings.Content = new AutoView(CustomerEnv.ProductionLineConfigValue)
+            ParameterSettings.Content = new AutoView(CustomerEnv.ProductionLineConfigValue, new string[]
+            {
+                nameof(ParameterSettingsModel.WorkShopId),
+                nameof(ParameterSettingsModel.ProductionLineId),
+                nameof(ParameterSettingsModel.PlcName)
+            })
+            //ParameterSettings.Content = new AutoView(CustomerEnv.ProductionLineConfigValue)
             { MaxTitleWidth = 150 };
 
         }

+ 5 - 0
SCADA_DAQ/Customer/UctFrmTaskManagement.xaml

@@ -15,6 +15,11 @@
     <wpfcontrol:QueryFrm x:Name="FrmQuery">
         <wpfcontrol:SmartGrid x:Name="MainGrid" IsAutoUpdate="True" CanUserDeleteRows="{Binding IsAdmin,ElementName=this}" 
                AutoGenerateColumns="True" IsReadOnly="{Binding IsReadOnly,ElementName=this}">
+            <wpfcontrol:SmartGrid.HeaderExControl>
+                <wpfcontrol:IconButton ButtonKind="OkButton" ButtonStyle="Success"
+						Title="完成生产" Margin="11" Cursor="Hand" FontSize="14"
+                        Click="IconButton_Click"/>
+            </wpfcontrol:SmartGrid.HeaderExControl>
         </wpfcontrol:SmartGrid>
     </wpfcontrol:QueryFrm>
 </wpfcontrol:BaseUctFrm>

+ 123 - 2
SCADA_DAQ/Customer/UctFrmTaskManagement.xaml.cs

@@ -1,12 +1,20 @@
-using SCADA.CommonCtrl.WpfControl;
+using Microsoft.DwayneNeed.Numerics;
+using Microsoft.DwayneNeed.Win32.Gdi32;
+using Mysqlx.Crud;
+using Mysqlx.Session;
+using NPOI.SS.Formula.Eval;
+using SCADA.CommonCtrl.WpfControl;
 using SCADA.CommonLib;
 using SCADA.CommonLib.CommonModel;
+using SCADA.CommonLib.Data.DIL;
+using SCADA.CommonLib.Helper;
 using SCADA_DAQ.Customer.Models;
 using SCADA_DAQ.Customer.Models.MotorcycleTypeManagement;
 using SCADA_DAQ.Customer.Models.TaskManagement;
 using SqlSchema.DBNames;
 using System;
 using System.Collections.Generic;
+using System.Data;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -41,9 +49,9 @@ namespace SCADA_DAQ.Customer
             FrmQuery.QueryModel = QueryModel;
             //DAL = Env.DAL;
             DAL = Env.SgIDAL;
-            //MainGrid.IsAutoUpdate = true;  //表格更新时允许更新到数据库
             MainGrid.SourceTable = QueryModel.SourceTable;   //指定绑定更新的表
             MainGrid.DataTableColumnLables = SmartGridHeaderMapping.CreateMapping<TaskManagementModel>();
+
             // 给字段设置下拉选项
             MainGrid.DataTableColumnLables[T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str].OptionItems
                 = new Dictionary<string, string>() { { "待生产", "待生产" }, { "生产中", "生产中" }, { "已生产", "已生产" } };
@@ -55,8 +63,67 @@ namespace SCADA_DAQ.Customer
                 = "MotorcycleTypeName";
             MainGrid.DataTableColumnLables[T_Col_Name.APP_TaiLing_TaskManagement.MotorcycleTypeName_Str].SelectedValuePath
                 = "MotorcycleTypeName";
+
+            //MainGrid.CellEditEnding += MainGrid_CellEditEnding;
+
         }
 
+
+        /// <summary>
+        /// 完成生产
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void IconButton_Click(object sender, RoutedEventArgs e)
+        {
+            var item = MainGrid.CurrentItem as DataRowView;
+            if (item == null) return;
+            var id = Convert.ToInt32(item[T_Col_Name.APP_TaiLing_TaskManagement.ID]?.ToString());
+            var orderId = Convert.ToString(item[T_Col_Name.APP_TaiLing_TaskManagement.OrderId_Str]);
+            var workStartTime = item[T_Col_Name.APP_TaiLing_TaskManagement.WorkStartTime_Dt];
+            var orderDatetime = Convert.ToDateTime(item[T_Col_Name.APP_TaiLing_TaskManagement.OrderDatetime_Dt]);
+            var scheduledProduction = Convert.ToInt32(item[T_Col_Name.APP_TaiLing_TaskManagement.ScheduledProduction_Int]);
+
+            if (MessageBox.Show($"是否确认已完成 {orderId} ?", "提示", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
+                return;
+
+            var res = false;
+            if (workStartTime is DBNull)
+            {
+                var dateDiff = (DateTime.Now - orderDatetime).TotalSeconds.ToInt();  // 时间差/s
+                res = Env.SgIDAL.APP_TaiLing_TaskManagement.Update($"ID={id}",
+                    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.CurrentProduction_Int, scheduledProduction),
+                    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.WorkStartTime_Dt, orderDatetime),
+                    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.WorkEndTime_Dt, DateTime.Now.Format()),
+                    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.DurationSec_Int, dateDiff),
+                    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "已生产"),
+                    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.ModifyTime_Dt, DateTime.Now.Format())
+                );
+            }
+            else
+            {
+                var dateDiff = (DateTime.Now - Convert.ToDateTime(workStartTime)).TotalSeconds.ToInt();  // 时间差/s
+                res = Env.SgIDAL.APP_TaiLing_TaskManagement.Update($"ID={id}",
+                    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.CurrentProduction_Int, scheduledProduction),
+                    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.WorkEndTime_Dt, DateTime.Now.Format()),
+                    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.DurationSec_Int, dateDiff),
+                    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "已生产"),
+                    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.ModifyTime_Dt, DateTime.Now.Format())
+                );
+            }
+
+            if (res)
+            {
+                ((IApp)System.Windows.Application.Current).ShowShortToast("操作成功!", ControlStyle.Success);
+                Query();
+            }
+            else
+            {
+                ((IApp)System.Windows.Application.Current).ShowShortToast("操作失败,请重试!", ControlStyle.Warning);
+            }
+        }
+
+
         private void Schedual_DateTimeChanged(object sender, DateTimeChangedArgs e)
         {
             if (e.ChangeType == DateTimeChangeType.MinuteChanged && e.TimeFlag.Minute % 10 == 0)
@@ -72,6 +139,60 @@ namespace SCADA_DAQ.Customer
                 Query();
             }
         }
+
+        //private void MainGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
+        //{
+        //    string newValue = (e.EditingElement as TextBox).Text;   // 新编辑的值
+        //    var item = (DataRowView)((SmartGrid)sender).CurrentItem;
+        //    //var cell = ((SmartGrid)sender).CurrentCell;
+        //    //var x = cell.Column;
+        //    //var y = cell.Item;
+        //    //var column = ((SmartGrid)sender).CurrentCell.Column.Header;
+
+        //    var orderId = Convert.ToString(item[T_Col_Name.APP_TaiLing_TaskManagement.OrderId_Str]);
+        //    var scheduledProduction = Convert.ToInt32(item[T_Col_Name.APP_TaiLing_TaskManagement.ScheduledProduction_Int]);
+        //    var currentProduction = Convert.ToInt32(item[T_Col_Name.APP_TaiLing_TaskManagement.CurrentProduction_Int]);
+        //    var workStartTime = item[T_Col_Name.APP_TaiLing_TaskManagement.WorkStartTime_Dt];
+        //    var orderDatetime = Convert.ToDateTime(item[T_Col_Name.APP_TaiLing_TaskManagement.OrderDatetime_Dt]);
+        //    var workShopId = CustomerEnv.ProductionLineConfigValue.WorkShopId;
+        //    var productionLineId = CustomerEnv.ProductionLineConfigValue.ProductionLineId;
+
+        //    //if (e.Column.Header.ToString() == "计划产量")
+        //    //    return;
+
+        //    if (e.Column.Header.ToString() == "当前产量")
+        //    {
+        //        currentProduction = Convert.ToInt32(newValue);
+        //    }
+        //    if (scheduledProduction > currentProduction)
+        //        return;
+        //    var taskInfo = Env.SgIDAL.APP_TaiLing_TaskManagement?.GetData<TaskManagementModel>()?
+        //        .Where(t => t.OrderId == orderId && t.WorkShopId == workShopId
+        //             && t.ProductionLineId == productionLineId)
+        //        .OrderBy(t => t.ID).LastOrDefault();
+        //    if (taskInfo == null)
+        //        return;
+
+        //    if (workStartTime is DBNull)
+        //    {
+        //        var dateDiff = (DateTime.Now - orderDatetime).TotalSeconds.ToInt();  // 时间差/s
+        //        Env.SgIDAL.APP_TaiLing_TaskManagement.Update($"OrderId_Str='{orderId}' AND WorkShopId_Str='{workShopId}' AND ProductionLineId_Str='{productionLineId}'",
+        //            new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.WorkStartTime_Dt, orderDatetime),
+        //            new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.WorkEndTime_Dt, DateTime.Now.Format()),
+        //            new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.DurationSec_Int, dateDiff),
+        //            new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "已生产")
+        //        );
+        //    }
+        //    else
+        //    {
+        //        var dateDiff = (DateTime.Now - taskInfo.WorkStartTime).TotalSeconds.ToInt();  // 时间差/s
+        //        Env.SgIDAL.APP_TaiLing_TaskManagement.Update($"OrderId_Str='{orderId}' AND WorkShopId_Str='{workShopId}' AND ProductionLineId_Str='{productionLineId}'",
+        //            new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.WorkEndTime_Dt, DateTime.Now.Format()),
+        //            new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.DurationSec_Int, dateDiff),
+        //            new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str, "已生产")
+        //        );
+        //    }
+        //}
     }
 
 

+ 1 - 0
SCADA_DAQ/SCADA_DAQ.csproj

@@ -221,6 +221,7 @@
       <HintPath>..\Lib\SCADA_DAQ.Plugin.RESTful.dll</HintPath>
       <Private>False</Private>
     </Reference>
+    <Reference Include="System.ComponentModel.DataAnnotations" />
     <Reference Include="System.Data.SQLite">
       <HintPath>..\Lib\System.Data.SQLite.dll</HintPath>
       <Private>False</Private>