Bladeren bron

更新扫码逻辑,更新工单界面

zhangliwen 1 jaar geleden
bovenliggende
commit
e23d6cd764

+ 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 - 2
SCADA_DAQ/Customer/Models/TaskManagement/TaskManagementModel.cs

@@ -114,7 +114,7 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
         /// <summary>
         /// 计划产量
         /// </summary>
-        [AutoViewProperty("计划产量", Icon = "", IsReadOnly =true)]
+        [AutoViewProperty("计划产量", Icon = "", IsReadOnly =false)]
         [Column(T_Col_Name.APP_TaiLing_TaskManagement.ScheduledProduction_Int)]
         public int ScheduledProduction
         {
@@ -152,7 +152,7 @@ namespace SCADA_DAQ.Customer.Models.TaskManagement
         /// <summary>
         /// 工单状态
         /// </summary>
-        [AutoViewProperty("工单状态", Icon = "", IsReadOnly = true)]
+        [AutoViewProperty("工单状态", Icon = "", IsReadOnly = false)]
         [Column(T_Col_Name.APP_TaiLing_TaskManagement.OrderState_Str)]
         public string OrderState
         {

+ 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>

+ 91 - 34
SCADA_DAQ/Customer/UctFrmTaskManagement.xaml.cs

@@ -1,5 +1,7 @@
 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;
@@ -47,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>() { { "待生产", "待生产" }, { "生产中", "生产中" }, { "已生产", "已生产" } };
@@ -62,65 +64,66 @@ namespace SCADA_DAQ.Customer
             MainGrid.DataTableColumnLables[T_Col_Name.APP_TaiLing_TaskManagement.MotorcycleTypeName_Str].SelectedValuePath
                 = "MotorcycleTypeName";
 
+            //MainGrid.CellEditEnding += MainGrid_CellEditEnding;
 
-            MainGrid.CellEditEnding += MainGrid_CellEditEnding;
         }
 
-        private void MainGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
+
+        /// <summary>
+        /// 完成生产
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void IconButton_Click(object sender, RoutedEventArgs 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 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 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;
+            var scheduledProduction = Convert.ToInt32(item[T_Col_Name.APP_TaiLing_TaskManagement.ScheduledProduction_Int]);
 
-            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)
+            if (MessageBox.Show($"是否确认已完成 {orderId} ?", "提示", MessageBoxButton.OKCancel) != MessageBoxResult.OK)
                 return;
 
+            var res = false;
             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}'",
+                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.OrderState_Str, "已生产"),
+                    new UpdateItem(T_Col_Name.APP_TaiLing_TaskManagement.ModifyTime_Dt, DateTime.Now.Format())
                 );
             }
             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}'",
+                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.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)
@@ -136,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, "已生产")
+        //        );
+        //    }
+        //}
     }