2 Commits 8dd01cbc11 ... 619c2bdfc4

Author SHA1 Message Date
  谢翼翔 619c2bdfc4 代码完善 1 year ago
  谢翼翔 8386f313a7 临时提交 1 year ago

+ 40 - 40
skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Machines/FXMachine.cs

@@ -53,7 +53,7 @@ namespace SCADA_DAQ.Customer.Machines
                 }
                 else
                 {
-                    if (IsOpenTime == false)
+                    if (!IsOpenTime)
                     {
                         if (ConnectState == SCADA.Comm.ConnectStates.Connected)
                         {
@@ -62,10 +62,6 @@ namespace SCADA_DAQ.Customer.Machines
                             var toolChangeFlag = this.GetListenReg("换模标志位");
                             var repairFlag = this.GetListenReg("维修时间");
                             RegInfo reg = runFlag.Value == 1 ? runFlag : stopFlag.Value == 1 ? stopFlag : toolChangeFlag.Value == 1 ? toolChangeFlag : repairFlag.Value == 1 ? repairFlag : null;
-                            if (reg == null)
-                            {
-
-                            }
                             InsertStateRecord(reg);
 
                         }
@@ -96,56 +92,60 @@ namespace SCADA_DAQ.Customer.Machines
 
         private void Schedual_DateTimeChanged(object sender, SCADA.CommonLib.DateTimeChangedArgs e)
         {
-            if (e.ChangeType == DateTimeChangeType.DayChanged)
+            if (!IsOpenTime)
             {
-                if (BaseDevice.ConnectState == SCADA.Comm.ConnectStates.Connected)
+                if (e.ChangeType == DateTimeChangeType.DayChanged)
                 {
-                    var runFlag = this.GetListenReg("运行标志位");
-                    var stopFlag = this.GetListenReg("停止标志位");
-                    var toolChangeFlag = this.GetListenReg("换模标志位");
-                    var repairFlag = this.GetListenReg("维修时间");
-                    if (runFlag != null && stopFlag != null && toolChangeFlag != null && repairFlag != null)
+                    if (BaseDevice.ConnectState == SCADA.Comm.ConnectStates.Connected)
                     {
-                        RegInfo reg = runFlag.Value == 1 ? runFlag : stopFlag.Value == 1 ? stopFlag : toolChangeFlag.Value == 1 ? toolChangeFlag : repairFlag.Value == 1 ? repairFlag : null;
-
-                        if (reg != null)
+                        var runFlag = this.GetListenReg("运行标志位");
+                        var stopFlag = this.GetListenReg("停止标志位");
+                        var toolChangeFlag = this.GetListenReg("换模标志位");
+                        var repairFlag = this.GetListenReg("维修时间");
+                        if (runFlag != null && stopFlag != null && toolChangeFlag != null && repairFlag != null)
                         {
-                            if (machineStateResumeModels.Count > 0)
+                            RegInfo reg = runFlag.Value == 1 ? runFlag : stopFlag.Value == 1 ? stopFlag : toolChangeFlag.Value == 1 ? toolChangeFlag : repairFlag.Value == 1 ? repairFlag : null;
+
+                            if (reg != null)
                             {
-                                if (machineStateResumeModels[0].TagName == reg.Comment.Variable)
+                                if (machineStateResumeModels.Count > 0)
                                 {
-                                    machineStateResumeModels[0].EndTime = DateTime.Parse(DateTime.Now.Format());
-                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                                        $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{machineStateResumeModels[0].StateId}'",
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now.Format()),
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, machineStateResumeModels[0].EndTime - machineStateResumeModels[0].StartTime),
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (machineStateResumeModels[0].EndTime - machineStateResumeModels[0].StartTime).TotalSeconds)
-                                        );
+                                    if (machineStateResumeModels[0].TagName == reg.Comment.Variable)
+                                    {
+                                        machineStateResumeModels[0].EndTime = DateTime.Parse(DateTime.Now.Format());
+                                        Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                                            $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{machineStateResumeModels[0].StateId}'",
+                                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now.Format()),
+                                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, machineStateResumeModels[0].EndTime - machineStateResumeModels[0].StartTime),
+                                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (machineStateResumeModels[0].EndTime - machineStateResumeModels[0].StartTime).TotalSeconds)
+                                            );
 
+                                    }
+                                    machineStateResumeModels.Clear();
                                 }
-                                machineStateResumeModels.Clear();
+                                InsertStateRecord(reg);
                             }
-                            InsertStateRecord(reg);
-                        }
 
+                        }
                     }
-                }
 
-            }
-            if (e.ChangeType == DateTimeChangeType.MinuteChanged)
-            {
-                if (machineStateResumeModels.Count > 0)
-                {
-                    machineStateResumeModels[0].EndTime = DateTime.Parse(DateTime.Now.Format());
-                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                        $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{machineStateResumeModels[0].StateId}'",
-                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now.Format()),
-                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, machineStateResumeModels[0].EndTime - machineStateResumeModels[0].StartTime),
-                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (machineStateResumeModels[0].EndTime - machineStateResumeModels[0].StartTime).TotalSeconds)
-                        );
                 }
+                if (e.ChangeType == DateTimeChangeType.MinuteChanged)
+                {
+                    if (machineStateResumeModels.Count > 0)
+                    {
+                        machineStateResumeModels[0].EndTime = DateTime.Parse(DateTime.Now.Format());
+                        Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                            $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{machineStateResumeModels[0].StateId}'",
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now.Format()),
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, machineStateResumeModels[0].EndTime - machineStateResumeModels[0].StartTime),
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (machineStateResumeModels[0].EndTime - machineStateResumeModels[0].StartTime).TotalSeconds)
+                            );
+                    }
 
+                }
             }
+            
         }
 
         protected override void RegReadValueChanged(object sender, RegReadValueChangedEventArgs e)

+ 15 - 0
skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Models/DistinctTimePiece/TimePiece.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SCADA_DAQ.Customer.Models.DistinctTimePiece
+{
+    public class TimePiece
+    {
+        public TimeSpan StartTime { get; set; }
+
+        public TimeSpan EndTime { get; set; }
+    }
+}

+ 89 - 0
skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Models/DistinctTimePiece/TimeTotalHelper.cs

@@ -0,0 +1,89 @@
+using SCADA.CommonLib;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SCADA_DAQ.Customer.Models.DistinctTimePiece
+{
+    public class TimeTotalHelper:ObservableObject
+    {
+        public static List<TimePiece> DistinctTime(List<TimePiece> timePieces)
+        {
+            var result = new List<TimePiece>();
+
+            if (timePieces?.Count != null)
+            {
+                var ascTime = timePieces.OrderBy(t => t.StartTime).ToList();
+                result.Add(ascTime.First());
+                for (global::System.Int32 i = 0; i < ascTime.Count - 1; i++)
+                {
+                    if (ascTime[i + 1].StartTime <= ascTime[i].EndTime)
+                    {
+                        if (ascTime[i + 1].EndTime > ascTime[i].EndTime)
+                        {
+                            result.Last().EndTime = ascTime[i + 1].EndTime;
+                        }
+                    }
+                    else
+                    {
+                        result.Add(ascTime[i + 1]);
+                    }
+                }
+
+            }
+
+            return result;
+        }
+
+        public static TimeSpan DistinctPlanStopTime(List<TimePiece> timePieces, List<TimePiece> planStops)
+        {
+            var result = new TimeSpan();
+            var isInclude = false;
+            if (timePieces?.Count != null && planStops?.Count != null)
+            {
+                if (timePieces.Count > 0)
+                {
+
+                    for (int i = 0; i < timePieces.Count; i++)
+                    {
+                        isInclude = false;
+                        if (planStops.Count > 0)
+                        {
+                            for (int j = 0; j < planStops.Count; j++)
+                            {
+                                if ((timePieces[i].StartTime > planStops[j].StartTime && timePieces[i].StartTime < planStops[j].EndTime) ||
+                                        (timePieces[i].EndTime > planStops[j].StartTime && timePieces[i].EndTime < planStops[j].EndTime) ||
+                                            (timePieces[i].StartTime < planStops[j].StartTime && timePieces[i].EndTime > planStops[j].EndTime) ||
+                                                (timePieces[i].StartTime > planStops[j].StartTime && timePieces[i].EndTime < planStops[j].EndTime))
+                                {
+                                    if (timePieces[i].StartTime < planStops[j].StartTime)
+                                    {
+                                        result = result + (planStops[j].StartTime - timePieces[i].StartTime);
+                                    }
+                                    if (timePieces[i].EndTime > planStops[j].EndTime)
+                                    {
+                                        result = result + (timePieces[i].EndTime - planStops[j].EndTime);
+                                    }
+                                    isInclude = true;
+                                }
+
+                            }
+                            if (!isInclude)
+                            {
+                                result = result + (timePieces[i].EndTime - timePieces[i].StartTime);
+                            }
+                        }
+                        else
+                        {
+                            result = result + (timePieces[i].EndTime - timePieces[i].StartTime);
+                        }
+                    }
+
+                }
+            }
+            return result;
+        }
+    }
+}

+ 10 - 10
skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/UctFrmKanbanForPressBrakeEquipment.xaml.cs

@@ -155,11 +155,11 @@ namespace SCADA_DAQ.Customer
             //var baiChaoStopTime = totalTimeOfDay - baiChaoRunTime - baiChaoMoldTime - DevicScheduleStop("百超折弯机")
             //    - DevicMainTableTime("百超折弯机").TotalSeconds - DeviceTimeValue("百超折弯机", "维修时间") + DeviceStateCodeStopBetweenTime("百超折弯机", "维修时间");//百超折弯机折弯机等待时间
 
-            var firstYaWeiStopTime = DeviceTimeValue("1号YaWei折弯机", "停止标志位");//1号YaWei折弯机等待时间
-            var sencondYaWeiStopTime = DeviceTimeValue("2号YaWei折弯机", "停止标志位");//2号YaWei折弯机等待时间
-            var thirdYaWweiStopTime = DeviceTimeValue("3号YaWei折弯机", "停止标志位"); //3号YaWei折弯机等待时间
-            var pbcYaWweiStopTime = DeviceTimeValue("亚威PBC折弯机", "停止标志位");//亚威PBC折弯机等待时间
-            var baiChaoStopTime = DeviceTimeValue("百超折弯机", "停止标志位");//百超折弯机折弯机等待时间
+            var firstYaWeiStopTime = DeviceTimeValue("1号YaWei折弯机", "停止标志位")- DevicMainTableTime("亚威一号折弯机").TotalSeconds;//1号YaWei折弯机等待时间
+            var sencondYaWeiStopTime = DeviceTimeValue("2号YaWei折弯机", "停止标志位") - DevicMainTableTime("亚威二号折弯机").TotalSeconds;//2号YaWei折弯机等待时间
+            var thirdYaWweiStopTime = DeviceTimeValue("3号YaWei折弯机", "停止标志位") - DevicMainTableTime("亚威三号折弯机").TotalSeconds; //3号YaWei折弯机等待时间
+            var pbcYaWweiStopTime = DeviceTimeValue("亚威PBC折弯机", "停止标志位") - DevicMainTableTime("亚威PBC折弯机").TotalSeconds;//亚威PBC折弯机等待时间
+            var baiChaoStopTime = DeviceTimeValue("百超折弯机", "停止标志位") - DevicMainTableTime("百超折弯机").TotalSeconds;//百超折弯机折弯机等待时间
 
             var firstYaWeiRunTimeSpan = TimeSpan.FromSeconds(Math.Round(firstYaWeiRunTime)).ToString();
             var firstYaWeiStopTimeSpan = TimeSpan.FromSeconds(Math.Round(firstYaWeiStopTime)).ToString();
@@ -432,11 +432,11 @@ namespace SCADA_DAQ.Customer
                     //    - DevicMainTableTime("亚威PBC折弯机").TotalSeconds - DeviceTimeValue("亚威PBC折弯机", "维修时间") + DeviceStateCodeStopBetweenTime("亚威PBC折弯机", "维修时间");//亚威PBC折弯机等待时间
                     //var baiChaoStopTime = totalTimeOfDay - baiChaoRunTime - baiChaoMoldTime - DevicScheduleStop("百超折弯机")
                     //    - DevicMainTableTime("百超折弯机").TotalSeconds - DeviceTimeValue("百超折弯机", "维修时间") + DeviceStateCodeStopBetweenTime("百超折弯机", "维修时间");//百超折弯机折弯机等待时间
-                    var firstYaWeiStopTime = DeviceTimeValue("1号YaWei折弯机", "停止标志位");//1号YaWei折弯机等待时间
-                    var sencondYaWeiStopTime = DeviceTimeValue("2号YaWei折弯机", "停止标志位");//2号YaWei折弯机等待时间
-                    var thirdYaWweiStopTime = DeviceTimeValue("3号YaWei折弯机", "停止标志位"); //3号YaWei折弯机等待时间
-                    var pbcYaWweiStopTime = DeviceTimeValue("亚威PBC折弯机", "停止标志位");//亚威PBC折弯机等待时间
-                    var baiChaoStopTime = DeviceTimeValue("百超折弯机", "停止标志位");//百超折弯机折弯机等待时间
+                    var firstYaWeiStopTime = DeviceTimeValue("1号YaWei折弯机", "停止标志位") - DevicMainTableTime("亚威一号折弯机").TotalSeconds;//1号YaWei折弯机等待时间
+                    var sencondYaWeiStopTime = DeviceTimeValue("2号YaWei折弯机", "停止标志位") - DevicMainTableTime("亚威二号折弯机").TotalSeconds;//2号YaWei折弯机等待时间
+                    var thirdYaWweiStopTime = DeviceTimeValue("3号YaWei折弯机", "停止标志位") - DevicMainTableTime("亚威三号折弯机").TotalSeconds; //3号YaWei折弯机等待时间
+                    var pbcYaWweiStopTime = DeviceTimeValue("亚威PBC折弯机", "停止标志位") - DevicMainTableTime("亚威PBC折弯机").TotalSeconds;//亚威PBC折弯机等待时间
+                    var baiChaoStopTime = DeviceTimeValue("百超折弯机", "停止标志位") - DevicMainTableTime("百超折弯机").TotalSeconds;//百超折弯机折弯机等待时间
 
                     var firstYaWeiRunTimeSpan = TimeSpan.FromSeconds(Math.Round(firstYaWeiRunTime)).ToString();
                     var firstYaWeiStopTimeSpan = TimeSpan.FromSeconds(Math.Round(firstYaWeiStopTime)).ToString();

+ 74 - 103
skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/UctFrmPunchingMachineEquipmentKanban.xaml.cs

@@ -9,6 +9,7 @@ using SCADA.SECS;
 using SCADA_DAQ.Customer.Models;
 using SCADA_DAQ.Customer.Models.AlarmTime;
 using SCADA_DAQ.Customer.Models.DeviceInfoTime;
+using SCADA_DAQ.Customer.Models.DistinctTimePiece;
 using SCADA_DAQ.Customer.Models.ScheduleStop;
 using SqlSchema.DBNames;
 using System;
@@ -50,9 +51,7 @@ namespace SCADA_DAQ.Customer
             GetRepairTime();
             GetScheduleStopTime();
             GetDeviceAlarmTime();
-            GetHighDeviceWaitTime();
-            GetDeviceScheduleStopBetweenTime();
-            GetDeviceAlarmScheduleStopBetweenTime();
+            GetDeviceStopTime();
             Env.Schedual.DateTimeChanged += Schedual_DateTimeChanged;
             ToolBar.Visibility = Visibility.Collapsed;
             Image_Title.Source = SCADA.CommonCtrl.WpfHelper.VisualHelper.ImageToImageSource(@"Icon\VertivBck.png");
@@ -103,12 +102,11 @@ namespace SCADA_DAQ.Customer
             //var highmachineStopTime = totalTimeOfDay - highmachineRunTime - highmachineMoldTime - DevicScheduleStop("高机母线冲剪机") - highmachineArlamDouble
             //     + DeviceScheduleStopBetweenTime("高机母线冲剪机") + DeviceAlarmScheduleStopBetweenTime("高机母线冲剪机");//高机母线冲剪机等待时间
             //var highmachineStopTimeSpan = TimeSpan.FromSeconds(Math.Round(highmachineStopTime)).ToString();
-
-
-            var kimFangyuanStopTime = DeviceTimeValue("金方圆数控母线冲孔机", "停止标志位");//金方圆数控母线冲孔机等待时间
+            var kimFangyuanStopTime = DeviceTimeValue("金方圆数控母线冲孔机", "停止标志位") - DevicMainTableTime("金方圆铜排冲剪机").TotalSeconds;//金方圆数控母线冲孔机等待时间
             var kimFangyuanStopTimeSpan = TimeSpan.FromSeconds(Math.Round(kimFangyuanStopTime)).ToString();
 
-            var highmachineStopTime = DeviceTimeValue("高机母线冲剪机", "停止标志位");//高机母线冲剪机等待时间
+
+            var highmachineStopTime = DeviceTimeValue("高机母线冲剪机", "停止标志位") - DevicMainTableTime("高机铜排冲剪机").TotalSeconds;//高机母线冲剪机等待时间
             var highmachineStopTimeSpan = TimeSpan.FromSeconds(Math.Round(highmachineStopTime)).ToString();
 
             var kimFangyuanTimeValue = new double[] { kimFangyuanRunTime, kimFangyuanStopTime, kimFangyuanArlamDouble, kimFangyuanMoldTime };
@@ -150,7 +148,7 @@ namespace SCADA_DAQ.Customer
             //var classesEndTimeSpan = Env.Schedual.CurrentClasses.EndTime.ToString();
             //var classesStartTime = Convert.ToDateTime(classesStartTimeSpan);
             //var classesEndTime = Convert.ToDateTime(classesEndTimeSpan);
-         
+
             var classesStartTime = Convert.ToDateTime(DateTime.Now.ToString("00:00:00"));
             var classesEndTime = Convert.ToDateTime(DateTime.Now.ToString("23:59:59"));
             //获取当天所有设备信息
@@ -237,114 +235,87 @@ namespace SCADA_DAQ.Customer
         }
 
 
-        public List<DeviceAlarmInformationModel> deviceAlarmTime { get; set; }
+        public List<AlarmColumModel> deviceAlarmTime { get; set; }
+
+        public List<AlarmColumModel> DistinctDeviceAlarmTime { get; set; }
         public void GetDeviceAlarmTime()//获取设备一天报警信息
         {
             var classesStartTime = Convert.ToDateTime(DateTime.Now.ToString("00:00:00"));
             var classesEndTime = Convert.ToDateTime(DateTime.Now.ToString("23:59:59"));
-            deviceAlarmTime = DAL.Base_AlarmLog.GetData<DeviceAlarmInformationModel>()?.Where(t => t.CreateTime >= classesStartTime & t.CreateTime <= classesEndTime).ToList();
-        }
+            deviceAlarmTime = DAL.Base_AlarmLog.GetData<AlarmColumModel>()?.Where(t => t.CreateTime >= classesStartTime & t.CreateTime <= classesEndTime).ToList();
 
-        public double DeviceAlarmTime(string deviceName)
-        {
-            var deviceAlarm = deviceAlarmTime.ToLookup(t => t.Device)[deviceName].Sum(t => t.Duration);//获取设备报警时间
-            return Convert.ToDouble(deviceAlarm);
+            var classesYesterdayStartTime = Convert.ToDateTime(DateTime.Now.AddDays(-1).Date);
+            var classesDayEndTime = Convert.ToDateTime(DateTime.Now);
+            DistinctDeviceAlarmTime = DAL.Base_AlarmLog.GetData<AlarmColumModel>()?.Where(t => t.StartTime >= classesYesterdayStartTime & t.EndTime <= classesDayEndTime).ToList();
 
         }
+        public List<DeviceScheduleStopModel> deviceStopTime { get; set; }
 
-        public List<DeviceWorkTimeModel> highDeviceWaitTime { get; set; }//高机设备一天通电时间的信息
-        public void GetHighDeviceWaitTime()
+        public void GetDeviceStopTime()//获取计划停止时间
         {
-            var classesStartTime = Convert.ToDateTime(DateTime.Now.ToString("00:00:00"));
-            var classesEndTime = Convert.ToDateTime(DateTime.Now.ToString("23:59:59"));
-            highDeviceWaitTime = DAL.App_Vertiv_WorkTime.GetData<DeviceWorkTimeModel>()?.Where(t => t.TurnOnTime >= classesStartTime & t.TurnOnTime <= classesEndTime).ToList();
+             deviceStopTime = DAL.App_Vertiv_DeviceScheduleStop.GetData<DeviceScheduleStopModel>();
         }
 
-        public double HighDeviceWaitTime(string deviceName)//高机一天通电的时长
-        {
-
-            var highDeviceWait = highDeviceWaitTime.ToLookup(t => t.DeviceName)[deviceName].Sum(t => t.DurationSec);//获取高机设备等待时间
-            return highDeviceWait;
-        }
-
-
-        public List<MachineInfoModel> DeviceMachineInformation { get; set; }
-
-        public List<DeviceScheduleStopModel> DeviceScheduleStopInformation { get; set; }
-
-        public int DeviceScheduleStopBetWeenTime { get; set; }
-
-        public List<int> DeviceScheduleStopBetweenTimeList { get; set; }
-
-        public int IntValue { get; set; }
-        public void GetDeviceScheduleStopBetweenTime()
-        {
-            DeviceScheduleStopInformation = Env.SqlDAL.App_Vertiv_DeviceScheduleStop.GetData<DeviceScheduleStopModel>();
-            DeviceMachineInformation = Env.SqlDAL.App_Vertiv_MachineInfo.GetData<MachineInfoModel>();
-        }
-        public double DeviceScheduleStopBetweenTime(string deviceName)
+        public double DeviceAlarmTime(string deviceName)
         {
-            IntValue = 0;
-            List<int> DeviceValue = new List<int>();
-            var deviceScheduleStop = DeviceScheduleStopInformation.ToLookup(t => t.Device)[deviceName];
-            foreach (var item in deviceScheduleStop)
+            var timeStopTime = deviceStopTime.ToLookup(t => t.Device)[deviceName];
+            var timeStopPieces = new List<TimePiece>();
+            if (timeStopTime.Count() != 0)
             {
-              
-                var classesStartTime = Convert.ToDateTime(DateTime.Now.ToString(item.StartTime.ToString()));
-                var classesEndTime = Convert.ToDateTime(DateTime.Now.ToString(item.EndTime.ToString()));
-                var deviceBetweenTime = DeviceMachineInformation.ToLookup(t => t.Device)[deviceName]?.Where(t => t.CreateTime >= classesStartTime & t.CreateTime <= classesEndTime);
-                DeviceScheduleStopBetWeenTime = deviceBetweenTime.Sum(t => t.DurationSec);
-                DeviceValue.Add(DeviceScheduleStopBetWeenTime);
+                foreach (var item in timeStopTime)
+                {
+                    timeStopPieces.Add(new TimePiece
+                    {
+                        StartTime = Convert.ToDateTime(item.StartTime.ToString()).TimeOfDay,
+                        EndTime = Convert.ToDateTime(item.EndTime.ToString()).TimeOfDay
+                    });
+                }
             }
+                    
+            var informationValue = deviceAlarmTime?.ToLookup(t => t.Device_Str)[deviceName];
+            var deviceValueInformation = DistinctDeviceAlarmTime.ToLookup(t => t.Device_Str)[deviceName];
 
-            DeviceScheduleStopBetweenTimeList = DeviceValue;
-            for (int i = 0; i < DeviceScheduleStopBetweenTimeList.Count; i++)
+            var timePieces = new List<TimePiece>();
+            if (deviceValueInformation.Count() != 0)
             {
-                IntValue = DeviceScheduleStopBetweenTimeList[i] + IntValue;
-            }
-            return IntValue;
-        }
-
-
-        public List<AlarmColumModel> DeviceAlarmMachineInformation { get; set; }
-
-        public List<DeviceScheduleStopModel> DeviceAlarmScheduleStopInformation { get; set; }
-        public int DeviceAlarmInt { get; set; }
-
+                foreach (var item in deviceValueInformation)
+                {
+                    timePieces.Add(new TimePiece
+                    {
+                        StartTime = Convert.ToDateTime(DateTime.Now.ToString("00:00:00")).TimeOfDay,
+                        EndTime = item.EndTime.TimeOfDay
+                    });
+                }
 
-        public int DeviceAlarmIntValue { get; set; }
+            }
+            if (informationValue.Count() != 0)
+            {
+                foreach (var item in informationValue)
+                {
+                    timePieces.Add(new TimePiece
+                    {
+                        StartTime = item.StartTime.TimeOfDay,
+                        EndTime = item.EndTime.TimeOfDay
+                    });
+                }
+            }
+            else
+            {
+                timePieces = new List<TimePiece>() {
 
+                      new TimePiece{StartTime =TimeSpan.FromSeconds(DateTime.Now.ToOADate()) ,
+                          EndTime = TimeSpan.FromSeconds(DateTime.Now.ToOADate())},
+                     };
+            }
 
-        public List<int> DeviceAlarmIntList { get; set; }
-        public void GetDeviceAlarmScheduleStopBetweenTime()
-        {
-            DeviceAlarmScheduleStopInformation = Env.SqlDAL.App_Vertiv_DeviceScheduleStop.GetData<DeviceScheduleStopModel>();
+            var total = TimeTotalHelper.DistinctPlanStopTime(TimeTotalHelper.DistinctTime(timePieces), timeStopPieces);
+            var doubletotal = total.TotalSeconds;
+            return doubletotal;
 
-            DeviceAlarmMachineInformation = Env.SqlDAL.Base_AlarmLog.GetData<AlarmColumModel>();
         }
 
 
-        public double DeviceAlarmScheduleStopBetweenTime(string deviceName)
-        {
-            DeviceAlarmIntValue = 0;
-            List<int> DeviceValue = new List<int>();
-            var deviceScheduleStop = DeviceAlarmScheduleStopInformation.ToLookup(t => t.Device)[deviceName];
-            foreach (var item in deviceScheduleStop)
-            {
-                var classesStartTime = Convert.ToDateTime(DateTime.Now.ToString(item.StartTime.ToString()));
-                var classesEndTime = Convert.ToDateTime(DateTime.Now.ToString(item.EndTime.ToString()));
-                var deviceBetweenTime = DeviceAlarmMachineInformation.ToLookup(t => t.Device_Str)[deviceName]?.Where(t => t.CreateTime >= classesStartTime & t.CreateTime <= classesEndTime);
-                DeviceAlarmInt = deviceBetweenTime.Sum(t => t.DurationSec);
-                DeviceValue.Add(DeviceAlarmInt);
-            }
-
-            DeviceAlarmIntList = DeviceValue;
-            for (int i = 0; i < DeviceAlarmIntList.Count; i++)
-            {
-                DeviceAlarmIntValue = DeviceAlarmIntList[i] + DeviceAlarmIntValue;
-            }
-            return DeviceAlarmIntValue;
-        }
+     
         private void Schedual_DateTimeChanged(object sender, SCADA.CommonLib.DateTimeChangedArgs e)
         {
 
@@ -358,10 +329,8 @@ namespace SCADA_DAQ.Customer
                     GetRepairTime();
                     GetScheduleStopTime();
                     GetDeviceAlarmTime();
-                    GetHighDeviceWaitTime();
-                    GetDeviceScheduleStopBetweenTime();
-                    GetDeviceAlarmScheduleStopBetweenTime();
-                    var kimFangyuanRepairTime = "倒计时" + DeviceRepairTime("金方圆铜排冲剪机").ToString() + "天";//金方圆铜排冲剪机设备保养信息
+                    GetDeviceStopTime();
+                     var kimFangyuanRepairTime = "倒计时" + DeviceRepairTime("金方圆铜排冲剪机").ToString() + "天";//金方圆铜排冲剪机设备保养信息
                     var highmachineRepairTime = "倒计时" + DeviceRepairTime("高机铜排冲剪机").ToString() + "天";//高机铜排冲剪机设备保养信息
                     var kimFangyuanArlamTimeSpanString = Convert.ToString(DevicMainTableTime("金方圆铜排冲剪机")
                         + TimeSpan.FromSeconds(DeviceTimeValue("金方圆数控母线冲孔机", "维修时间")) + TimeSpan.FromSeconds(DeviceAlarmTime("金方圆数控母线冲孔机")));//获取金方圆铜排冲剪机设备维修时间
@@ -388,19 +357,21 @@ namespace SCADA_DAQ.Customer
 
 
                     double totalTimeOfDay = TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")).TotalSeconds;
-
-                    var kimFangyuanStopTime = DeviceTimeValue("金方圆数控母线冲孔机", "停止标志位");//金方圆数控母线冲孔机等待时间
+                    
+                    var kimFangyuanStopTime = DeviceTimeValue("金方圆数控母线冲孔机", "停止标志位")- DevicMainTableTime("金方圆铜排冲剪机").TotalSeconds;//金方圆数控母线冲孔机等待时间
                     var kimFangyuanStopTimeSpan = TimeSpan.FromSeconds(Math.Round(kimFangyuanStopTime)).ToString();
 
 
-                    //var highmachineStopTime = totalTimeOfDay - highmachineRunTime - highmachineMoldTime - DeviceTimeValue("高机母线冲剪机", "计划停止时间") - highmachineArlamDouble
-                    //+ DeviceScheduleStopBetweenTime("高机母线冲剪机") + DeviceAlarmScheduleStopBetweenTime("高机母线冲剪机");//高机母线冲剪机等待时间
-                    //var highmachineStopTimeSpan = TimeSpan.FromSeconds(Math.Round(highmachineStopTime)).ToString();
-                    var highmachineStopTime = DeviceTimeValue("高机母线冲剪机", "停止标志位");//高机母线冲剪机等待时间
+                    var highmachineStopTime = DeviceTimeValue("高机母线冲剪机", "停止标志位")- DevicMainTableTime("高机铜排冲剪机").TotalSeconds;//高机母线冲剪机等待时间
                     var highmachineStopTimeSpan = TimeSpan.FromSeconds(Math.Round(highmachineStopTime)).ToString();
 
                     var kimFangyuanTimeValue = new double[] { kimFangyuanRunTime, kimFangyuanStopTime, kimFangyuanArlamDouble, kimFangyuanMoldTime };
                     var highmachineTimeValue = new double[] { highmachineRunTime, highmachineStopTime, highmachineArlamDouble, highmachineMoldTime };
+
+                    //var highmachineStopTime = totalTimeOfDay - highmachineRunTime - highmachineMoldTime - DeviceTimeValue("高机母线冲剪机", "计划停止时间") - highmachineArlamDouble
+                    //+ DeviceScheduleStopBetweenTime("高机母线冲剪机") + DeviceAlarmScheduleStopBetweenTime("高机母线冲剪机");//高机母线冲剪机等待时间
+                    //var highmachineStopTimeSpan = TimeSpan.FromSeconds(Math.Round(highmachineStopTime)).ToString();
+
                     //TimeResult[0] = $"{timespanOne.Hours.ToString("00")}时 {timespanOne.Minutes.ToString("00")}分 {timespanOne.Seconds.ToString("00")}秒";
                     //countdown[0] = "倒计时" + $"{timefinalResult}" + "天";
                     //var waitTime = $"{waitTimeResult.Hours.ToString("00")}时 {waitTimeResult.Minutes.ToString("00")}分 {Convert.ToInt32(waitTimeResult.Seconds).ToString("00")}秒";

+ 3 - 14
skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/UctFrmRunHistory.xaml

@@ -6,22 +6,11 @@
       xmlns:local="clr-namespace:SCADA_DAQ.Customer" xmlns:uct="clr-namespace:SCADA_DAQ.Customer.Views.Uct" xmlns:dashboard="clr-namespace:SCADA_DAQ.Customer.Views.Dashboard"
       mc:Ignorable="d" 
      x:Name="this"
-      Background="LightBlue"
-      d:DesignHeight="1080" d:DesignWidth="1920"
+         d:DesignHeight="1080" d:DesignWidth="1920"
       Title="UctFrmRunHistory">
     <Grid >
-        <Grid.RowDefinitions>
-            <RowDefinition Height="60"/>
-            <RowDefinition/>
-        </Grid.RowDefinitions>
-        <Image x:Name="Image_Title" Grid.RowSpan="3"  Stretch="Fill"/>
-        <TextBlock x:Name="LocalTime" Foreground="White" FontSize="20" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,10,10,0" FontWeight="Bold"/>
-        <TextBlock Text="设备运行信息" FontSize="28" HorizontalAlignment="Center" VerticalAlignment="Top" Foreground="LightBlue"  FontWeight="Bold" />
-        <!--<uct:UctAllDeviceInformation Margin="0,50,0,0" Grid.Row="1"/>-->
-        <!--<DatePicker  x:Name="uu" Width="100" Height="120" FontSize="30" />-->
-        <!--<wpfcontrol:DateSelecter x:Name="Time" Title="时间计划表" />
-        <ContentControl x:Name="MaintainTime"/>-->
-        <uct:UctDeviceInformationControlsThird x:Name="PunchingMachineEquipmentKanbanOne" Text="高机冲孔机设备运行状况" Grid.Row="1"  />
+  
+   
     </Grid>
 
 </wpfcontrol:BaseUctFrm>

+ 139 - 111
skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/UctFrmRunHistory.xaml.cs

@@ -4,8 +4,10 @@ using NPOI.SS.Formula.Eval;
 using NPOI.SS.Formula.Functions;
 using SCADA.CommonCtrl.WpfControl;
 using SCADA.CommonLib.Data.DIL.Sqlite;
+using SCADA.CommonLib.Helper;
 using SCADA_DAQ.Customer.Models.AlarmTime;
 using SCADA_DAQ.Customer.Models.DeviceInfoTime;
+using SCADA_DAQ.Customer.Models.DistinctTimePiece;
 using SCADA_DAQ.Customer.Models.ScheduleStop;
 using SqlSchema.DBNames;
 using System;
@@ -21,6 +23,7 @@ using System.Windows.Documents;
 using System.Windows.Forms;
 using System.Windows.Input;
 using System.Windows.Media;
+using System.Windows.Media.Animation;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
@@ -33,145 +36,170 @@ namespace SCADA_DAQ.Customer
     /// </summary>
     [UctMenu("设备运行界面", Icon = "看板")]
 
+
     public partial class UctFrmRunHistory : BaseUctFrm
     {
         private static SqlSchema.DIL.DILDB DAL = Env.SqlDAL;
         //private static DIL.DILDB sqliteDAL = Env.DAL;
+
         public UctFrmRunHistory()
         {
             InitializeComponent();
-            GetDeviceScheduleStopBetweenTime();
-            GetDeviceAlarmScheduleStopBetweenTime();
-
-            PunchingMachineEquipmentKanbanOne.DeviceNameOne.Value = TimeSpan.FromSeconds(Math.Round(DeviceScheduleStopBetweenTime("1号YaWei折弯机"))).ToString();
-            PunchingMachineEquipmentKanbanOne.DeviceNameTwo.Value = TimeSpan.FromSeconds(Math.Round(DeviceAlarmScheduleStopBetweenTime("西门子840D数冲"))).ToString();
             
-            Env.Schedual.DateTimeChanged += Schedual_DateTimeChanged;
-            var AA= DeviceStateCodeStopBetweenTime("1号YaWei折弯机", "换模标志位");
-            var BB = DeviceStateCodeStopBetweenTime("1号YaWei折弯机", "运行标志位");
-            var CC = DeviceStateCodeStopBetweenTime("1号YaWei折弯机", "维修时间");
-        }
-
-        private void Schedual_DateTimeChanged(object sender, SCADA.CommonLib.DateTimeChangedArgs e)
-        {
-            if (e.ChangeType == SCADA.CommonLib.DateTimeChangeType.SecondChanged && e.TimeFlag.Second % 5 == 0)
+            var timeListAdd = new List<List<TimePiece>>();
+            var timeStopTime = DAL.App_Vertiv_DeviceScheduleStop.GetData<DeviceScheduleStopModel>().ToLookup(t => t.Device)["高机母线冲剪机"];
+            var timeStopPieces = new List<TimePiece>();
+            if (timeStopTime.Count() != 0)
             {
-                GetDeviceScheduleStopBetweenTime();
-                GetDeviceAlarmScheduleStopBetweenTime();
-                PunchingMachineEquipmentKanbanOne.DeviceNameOne.Value = TimeSpan.FromSeconds(Math.Round(DeviceScheduleStopBetweenTime("1号YaWei折弯机"))).ToString();
-                PunchingMachineEquipmentKanbanOne.DeviceNameTwo.Value = TimeSpan.FromSeconds(Math.Round(DeviceAlarmScheduleStopBetweenTime("西门子840D数冲"))).ToString();
+                foreach (var item in timeStopTime)
+                {
+                    timeStopPieces.Add(new TimePiece
+                    {
+                        StartTime = Convert.ToDateTime(item.StartTime.ToString()).TimeOfDay,
+                        EndTime = Convert.ToDateTime(item.EndTime.ToString()).TimeOfDay
+                    });
+                }
             }
-        }
-
-        public List<MachineInfoModel> DeviceMachineInformation { get; set; }
 
-        public List<DeviceScheduleStopModel> DeviceScheduleStopInformation { get; set; }
+            var classesStartTime = Convert.ToDateTime(DateTime.Now.ToString("00:00:00"));
+            var classesEndTime = Convert.ToDateTime(DateTime.Now.ToString("23:59:59"));
+            var informationValue = Env.SqlDAL.Base_AlarmLog.GetData<AlarmColumModel>()?.Where(t => t.CreateTime >= classesStartTime & t.CreateTime <= classesEndTime).ToLookup(t => t.Device_Str)["高机母线冲剪机"];
 
-        public int DeviceStateCodeScheduleStopBetWeenTime { get; set; }
 
-        public List<int> DeviceStateCodeScheduleStopBetweenTimeList { get; set; }
+            var classesYesterdayStartTime = Convert.ToDateTime(DateTime.Now.AddDays(-1).Date);
+            var classesDayEndTime = Convert.ToDateTime(DateTime.Now);
+            var deviceValueInformation = Env.SqlDAL.Base_AlarmLog.GetData<AlarmColumModel>()?.Where(t => t.StartTime >= classesYesterdayStartTime & t.EndTime <= classesDayEndTime).ToLookup(t => t.Device_Str)["高机母线冲剪机"];
 
-        public int DeviceStateCodeIntValue { get; set; }
-        public void GetDeviceScheduleStopBetweenTime()
-        {
-            DeviceScheduleStopInformation = Env.SqlDAL.App_Vertiv_DeviceScheduleStop.GetData<DeviceScheduleStopModel>();
-            DeviceMachineInformation = Env.SqlDAL.App_Vertiv_MachineInfo.GetData<MachineInfoModel>();
-        }
-        public double DeviceStateCodeStopBetweenTime(string deviceName, string deviceStateCode)
-        {
-            DeviceStateCodeIntValue = 0;
-            List<int> DeviceValue = new List<int>();
-            var deviceScheduleStop = DeviceScheduleStopInformation.ToLookup(t => t.Device)[deviceName];
-            foreach (var item in deviceScheduleStop)
+            var timePieces = new List<TimePiece>();
+            if (deviceValueInformation.Count() !=0)
             {
-                var classesStartTime = Convert.ToDateTime(DateTime.Now.ToString(item.StartTime.ToString()));
-                var classesEndTime = Convert.ToDateTime(DateTime.Now.ToString(item.EndTime.ToString()));
-                var deviceBetweenTime = DeviceMachineInformation.ToLookup(t => t.Device)[deviceName].ToLookup(t => t.StateCode)[deviceStateCode]?
-                .Where(t => t.CreateTime >= classesStartTime & t.CreateTime <= classesEndTime);
-                DeviceStateCodeScheduleStopBetWeenTime = deviceBetweenTime.Sum(t => t.DurationSec);
-                DeviceValue.Add(DeviceStateCodeScheduleStopBetWeenTime);
-            }
+                foreach (var item in deviceValueInformation)
+                {
+                    timePieces.Add(new TimePiece
+                    {
+                        StartTime = Convert.ToDateTime(DateTime.Now.ToString("00:00:00")).TimeOfDay,
+                        EndTime = item.EndTime.TimeOfDay
+                    });
+                }
 
-            DeviceStateCodeScheduleStopBetweenTimeList = DeviceValue;
-            for (int i = 0; i < DeviceStateCodeScheduleStopBetweenTimeList.Count; i++)
-            {
-                DeviceStateCodeIntValue = DeviceStateCodeScheduleStopBetweenTimeList[i] + DeviceStateCodeIntValue;
             }
-            return DeviceStateCodeIntValue;
-        }
-
-
-        public int DeviceScheduleStopBetWeenTime { get; set; }
-
-        public List<int> DeviceScheduleStopBetweenTimeList { get; set; }
-
-        public int IntValue { get; set; }
-        public double DeviceScheduleStopBetweenTime(string deviceName)
-        {
-            IntValue = 0;
-            List<int> DeviceValue = new List<int>();
-            var deviceScheduleStop = DeviceScheduleStopInformation.ToLookup(t => t.Device)[deviceName];
-            foreach (var item in deviceScheduleStop)
+            if (informationValue.Count() != 0)
             {
-
-                var classesStartTime = Convert.ToDateTime(DateTime.Now.ToString(item.StartTime.ToString()));
-                var classesEndTime = Convert.ToDateTime(DateTime.Now.ToString(item.EndTime.ToString()));
-                var deviceBetweenTime = DeviceMachineInformation.ToLookup(t => t.Device)[deviceName]?.Where(t => t.CreateTime >= classesStartTime & t.CreateTime <= classesEndTime);
-                DeviceScheduleStopBetWeenTime = deviceBetweenTime.Sum(t => t.DurationSec);
-                DeviceValue.Add(DeviceScheduleStopBetWeenTime);
+                foreach (var item in informationValue)
+                {
+                    timePieces.Add(new TimePiece
+                    {
+                        StartTime = item.StartTime.TimeOfDay,
+                        EndTime = item.EndTime.TimeOfDay
+                    });
+                }
             }
-
-            DeviceScheduleStopBetweenTimeList = DeviceValue;
-            
-            for (int i = 0; i < DeviceScheduleStopBetweenTimeList.Count; i++)
+            else
             {
-                IntValue = DeviceScheduleStopBetweenTimeList[i] + IntValue;
-            }
-            return IntValue;
-        }
-
-      
-        public List<AlarmColumModel> DeviceAlarmMachineInformation { get; set; }
-
-        public List<DeviceScheduleStopModel> DeviceAlarmScheduleStopInformation { get; set; }
-        public int DeviceAlarmInt { get; set; }
+                timePieces = new List<TimePiece>() {
 
+                      new TimePiece{StartTime =TimeSpan.FromSeconds(DateTime.Now.ToOADate()) ,
+                          EndTime = TimeSpan.FromSeconds(DateTime.Now.ToOADate())},
+                     };
+            }
+        
 
-        public int DeviceAlarmIntValue { get; set; }
-       
+            var total = TimeTotalHelper.DistinctPlanStopTime(TimeTotalHelper.DistinctTime(timePieces), timeStopPieces);
 
-        public List<int> DeviceAlarmIntList { get; set; }
-        public void GetDeviceAlarmScheduleStopBetweenTime()
-        {
-            DeviceAlarmScheduleStopInformation = Env.SqlDAL.App_Vertiv_DeviceScheduleStop.GetData<DeviceScheduleStopModel>();
 
-            DeviceAlarmMachineInformation = Env.SqlDAL.Base_AlarmLog.GetData<AlarmColumModel>();
         }
 
+    }
 
-        public double DeviceAlarmScheduleStopBetweenTime(string deviceName)
-        {
-            
-            List<int> DeviceValue = new List<int>();
-            var deviceScheduleStop = DeviceAlarmScheduleStopInformation.ToLookup(t => t.Device)[deviceName];
-            foreach (var item in deviceScheduleStop)
-            {
-                var classesStartTime = Convert.ToDateTime(DateTime.Now.ToString(item.StartTime.ToString()));
-                var classesEndTime = Convert.ToDateTime(DateTime.Now.ToString(item.EndTime.ToString()));
-                var deviceBetweenTime = DeviceAlarmMachineInformation.ToLookup(t => t.Device_Str)[deviceName]?.Where(t => t.CreateTime >= classesStartTime & t.CreateTime <= classesEndTime);
-                DeviceAlarmInt = deviceBetweenTime.Sum(t => t.DurationSec);
-                DeviceValue.Add(DeviceAlarmInt);
-            }
-
-            DeviceAlarmIntList = DeviceValue;
-            for (int i = 0; i < DeviceAlarmIntList.Count; i++)
-            {
-                DeviceAlarmIntValue = DeviceAlarmIntList[i] + DeviceAlarmIntValue;
-            }
-            return DeviceAlarmIntValue;
-        }
+        //class TimePiece
+        //{
+        //    public TimeSpan StartTime { get; set; }
+
+        //    public TimeSpan EndTime { get; set; }
+        //}
+
+        //class TimeTotalHelper
+        //{
+        //    public static List<TimePiece> DistinctTime(List<TimePiece> timePieces)
+        //    {
+        //        var result = new List<TimePiece>();
+
+        //        if (timePieces?.Count != null)
+        //        {
+        //            var ascTime = timePieces.OrderBy(t => t.StartTime).ToList();
+        //            result.Add(ascTime.First());
+        //            for (global::System.Int32 i = 0; i < ascTime.Count - 1; i++)
+        //            {
+        //                if (ascTime[i + 1].StartTime <= ascTime[i].EndTime)
+        //                {
+        //                    if (ascTime[i + 1].EndTime > ascTime[i].EndTime)
+        //                    {
+        //                        result.Last().EndTime = ascTime[i + 1].EndTime;
+        //                    }
+        //                }
+        //                else
+        //                {
+        //                    result.Add(ascTime[i + 1]);
+        //                }
+        //            }
+
+        //        }
+
+        //        return result;
+        //    }
+
+        //    public static TimeSpan DistinctPlanStopTime(List<TimePiece> timePieces, List<TimePiece> planStops)
+        //    {
+        //        var result = new TimeSpan();
+        //        var isInclude = false;
+        //        if (timePieces?.Count != null && planStops?.Count != null)
+        //        {
+        //            if (timePieces.Count > 0)
+        //            {
+
+        //                for (int i = 0; i < timePieces.Count; i++)
+        //                {
+        //                    isInclude = false;
+        //                    if (planStops.Count > 0)
+        //                    {
+        //                        for (int j = 0; j < planStops.Count; j++)
+        //                        {
+        //                            if ((timePieces[i].StartTime > planStops[j].StartTime && timePieces[i].StartTime < planStops[j].EndTime) ||
+        //                                    (timePieces[i].EndTime > planStops[j].StartTime && timePieces[i].EndTime < planStops[j].EndTime) ||
+        //                                        (timePieces[i].StartTime < planStops[j].StartTime && timePieces[i].EndTime > planStops[j].EndTime) ||
+        //                                            (timePieces[i].StartTime > planStops[j].StartTime && timePieces[i].EndTime < planStops[j].EndTime))
+        //                            {
+        //                                if (timePieces[i].StartTime < planStops[j].StartTime)
+        //                                {
+        //                                    result = result + (planStops[j].StartTime - timePieces[i].StartTime);
+        //                                }
+        //                                if (timePieces[i].EndTime > planStops[j].EndTime)
+        //                                {
+        //                                    result = result + (timePieces[i].EndTime - planStops[j].EndTime);
+        //                                }
+        //                                isInclude = true;
+        //                            }
+
+        //                        }
+        //                        if (!isInclude)
+        //                        {
+        //                            result = result + (timePieces[i].EndTime - timePieces[i].StartTime);
+        //                        }
+        //                    }
+        //                    else
+        //                    {
+        //                        result = result + (timePieces[i].EndTime - timePieces[i].StartTime);
+        //                    }
+        //                }
+
+        //            }
+        //        }
+        //        return result;
+        //    }
+        //}
 
     }
-}
+
+
 
 

+ 77 - 30
skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Views/Dashboard/LaserAndDigitalPunchingEquipmentWidget.xaml.cs

@@ -7,6 +7,7 @@ using SCADA.SECS;
 using SCADA_DAQ.Customer.Models;
 using SCADA_DAQ.Customer.Models.AlarmTime;
 using SCADA_DAQ.Customer.Models.DeviceInfoTime;
+using SCADA_DAQ.Customer.Models.DistinctTimePiece;
 using SCADA_DAQ.Customer.Models.ScheduleStop;
 using SqlSchema.DBNames;
 using System;
@@ -54,6 +55,7 @@ namespace SCADA_DAQ.Customer.Views.Dashboard
             GetHighDeviceWorkTime();
             GetDeviceScheduleStopBetweenTime();
             GetDeviceAlarmScheduleStopBetweenTime();
+            GetDeviceStopTime();
             var laserRepairTime = "倒计时" + DeviceRepairTime("激光机").ToString() + "天";//激光机设备保养信息
             var siemensRepairTime = "倒计时" + DeviceRepairTime("西门子840D数冲").ToString() + "天";//西门子设备保养信息
             var behwifRepairTime = "倒计时" + DeviceRepairTime("倍福数冲机").ToString() + "天";//倍福数冲设备保养信息
@@ -90,9 +92,9 @@ namespace SCADA_DAQ.Customer.Views.Dashboard
 
             //double totalTimeOfDay = TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")).TotalSeconds;
 
-            var laserStopTime = DeviceTimeValue("激光机", "停止标志位");//激光机等待时间
-            var siemensStopTime = AllDeviceWorkTime("西门子840D数冲");//西门子等待时间
-            var behwiftStopTime = DeviceTimeValue("倍福数冲机", "停止标志位");//倍福数冲等待时间
+            var laserStopTime = DeviceTimeValue("激光机", "停止标志位") - DevicMainTableTime("激光机").TotalSeconds;//激光机等待时间
+            var siemensStopTime = AllDeviceWorkTime("西门子840D数冲") - DevicMainTableTime("西门子840D数冲").TotalSeconds;//西门子等待时间
+            var behwiftStopTime = DeviceTimeValue("倍福数冲机", "停止标志位") - DevicMainTableTime("倍福数冲机").TotalSeconds;//倍福数冲等待时间
             //var laserStopTime = totalTimeOfDay - laserRunTime - DevicScheduleStop("激光机") - laserArlamDouble
             //     + DeviceScheduleStopBetweenTime("激光机") + DeviceAlarmScheduleStopBetweenTime("激光机");//激光机等待时间
             //var siemensStopTime = totalTimeOfDay - siemensRunTime - siemensMoldTime - DevicScheduleStop("西门子840D数冲") - siemensArlamDouble
@@ -273,18 +275,80 @@ namespace SCADA_DAQ.Customer.Views.Dashboard
             return Convert.ToDouble(scheduleStopTimeValue.TotalSeconds);
         }
 
-        public List<DeviceAlarmInformationModel> deviceAlarmTime { get; set; }
+        public List<AlarmColumModel> deviceAlarmTime { get; set; }
+
+        public List<AlarmColumModel> DistinctDeviceAlarmTime { get; set; }
         public void GetDeviceAlarmTime()//获取设备一天报警信息
         {
             var classesStartTime = Convert.ToDateTime(DateTime.Now.ToString("00:00:00"));
             var classesEndTime = Convert.ToDateTime(DateTime.Now.ToString("23:59:59"));
-            deviceAlarmTime = DAL.Base_AlarmLog.GetData<DeviceAlarmInformationModel>()?.Where(t => t.CreateTime >= classesStartTime & t.CreateTime <= classesEndTime).ToList();
+            deviceAlarmTime = DAL.Base_AlarmLog.GetData<AlarmColumModel>()?.Where(t => t.CreateTime >= classesStartTime & t.CreateTime <= classesEndTime).ToList();
+
+            var classesYesterdayStartTime = Convert.ToDateTime(DateTime.Now.AddDays(-1).Date);
+            var classesDayEndTime = Convert.ToDateTime(DateTime.Now);
+            DistinctDeviceAlarmTime = DAL.Base_AlarmLog.GetData<AlarmColumModel>()?.Where(t => t.StartTime >= classesYesterdayStartTime & t.EndTime <= classesDayEndTime).ToList();
+        }
+        public List<DeviceScheduleStopModel> deviceStopTime { get; set; }
+
+        public void GetDeviceStopTime()//获取计划停止时间
+        {
+            deviceStopTime = DAL.App_Vertiv_DeviceScheduleStop.GetData<DeviceScheduleStopModel>();
         }
 
         public double DeviceAlarmTime(string deviceName)
         {
-            var deviceAlarm = deviceAlarmTime.ToLookup(t => t.Device)[deviceName].Sum(t => t.Duration);//获取设备报警时间
-            return Convert.ToDouble(deviceAlarm);
+            var timeStopTime = deviceStopTime.ToLookup(t => t.Device)[deviceName];
+            var timeStopPieces = new List<TimePiece>();
+            if (timeStopTime.Count() != 0)
+            {
+                foreach (var item in timeStopTime)
+                {
+                    timeStopPieces.Add(new TimePiece
+                    {
+                        StartTime = Convert.ToDateTime(item.StartTime.ToString()).TimeOfDay,
+                        EndTime = Convert.ToDateTime(item.EndTime.ToString()).TimeOfDay
+                    });
+                }
+            }
+
+            var informationValue = deviceAlarmTime?.ToLookup(t => t.Device_Str)[deviceName];
+            var deviceValueInformation = DistinctDeviceAlarmTime.ToLookup(t => t.Device_Str)[deviceName];
+            var timePieces = new List<TimePiece>();
+            if (deviceValueInformation.Count() != 0)
+            {
+                foreach (var item in deviceValueInformation)
+                {
+                    timePieces.Add(new TimePiece
+                    {
+                        StartTime = Convert.ToDateTime(DateTime.Now.ToString("00:00:00")).TimeOfDay,
+                        EndTime = item.EndTime.TimeOfDay
+                    });
+                }
+
+            }
+            if (informationValue.Count() != 0)
+            {
+                foreach (var item in informationValue)
+                {
+                    timePieces.Add(new TimePiece
+                    {
+                        StartTime = item.StartTime.TimeOfDay,
+                        EndTime = item.EndTime.TimeOfDay
+                    });
+                }
+            }
+            else
+            {
+                timePieces = new List<TimePiece>() {
+
+                      new TimePiece{StartTime =TimeSpan.FromSeconds(DateTime.Now.ToOADate()) ,
+                          EndTime = TimeSpan.FromSeconds(DateTime.Now.ToOADate())},
+                     };
+            }
+
+            var total = TimeTotalHelper.DistinctPlanStopTime(TimeTotalHelper.DistinctTime(timePieces), timeStopPieces);
+            var doubletotal = total.TotalSeconds;
+            return doubletotal;
 
         }
 
@@ -397,25 +461,8 @@ namespace SCADA_DAQ.Customer.Views.Dashboard
                     GetHighDeviceWorkTime();
                     GetDeviceScheduleStopBetweenTime();
                     GetDeviceAlarmScheduleStopBetweenTime();
-                    //var laserTimeMaintenanceTable = DevicMainTableTime("激光机");//获取激光机设备维修时间
-                    //var laserTimeMaintenanceTableString = DevicMainTableTime("激光机").ToString();//获取激光机设备维修时间
-                    //var siemensTimeMaintenanceTable = DevicMainTableTime("西门子840D数冲");//获取西门子840D数冲设备维修时间
-                    //var siemensTimeMaintenanceTableString = DevicMainTableTime("西门子840D数冲").ToString();//获取西门子840D数冲设备维修时间
-                    //var behwifTimeMaintenanceTable = DevicMainTableTime("倍福数冲");//获取倍福数冲设备维修时间
-                    //var behwifTimeMaintenanceTableString = DevicMainTableTime("倍福数冲").ToString();//获取倍福数冲设备维修时间
-
-                    //var laserArlamTime = laserTimeMaintenanceTable.TotalSeconds * 0.2;//激光机设备报警时间单位秒
-                    //var laserArlamTimeSpan = TimeSpan.FromSeconds(laserArlamTime).ToString();
-                    //var laserArlamDouble = Convert.ToDouble(laserArlamTime);
-
-                    //var siemensArlamTime = siemensTimeMaintenanceTable.TotalSeconds * 0.2;//西门子设备报警时间单位秒
-                    //var siemensArlamTimeSpan = TimeSpan.FromSeconds(siemensArlamTime).ToString();
-                    //var siemensArlamDouble = Convert.ToDouble(siemensArlamTime);
-
-                    //var behwiftArlamTime = behwifTimeMaintenanceTable.TotalSeconds * 0.2;//倍福数冲设备报警时间单位秒
-                    //var behwiftArlamTimeSpan = TimeSpan.FromSeconds(behwiftArlamTime).ToString();
-                    //var bewiftArlamDouble = Convert.ToDouble(behwiftArlamTime);
-
+                    GetDeviceStopTime();
+            
                     var laserRepairTime = "倒计时" + DeviceRepairTime("激光机").ToString() + "天";//激光机设备保养信息
                     var siemensRepairTime = "倒计时" + DeviceRepairTime("西门子840D数冲").ToString() + "天";//西门子设备保养信息
                     var behwifRepairTime = "倒计时" + DeviceRepairTime("倍福数冲机").ToString() + "天";//倍福数冲设备保养信息
@@ -452,10 +499,10 @@ namespace SCADA_DAQ.Customer.Views.Dashboard
 
                     double totalTimeOfDay = TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")).TotalSeconds;
 
-     
-                    var laserStopTime = DeviceTimeValue("激光机", "停止标志位");//激光机等待时间
-                    var siemensStopTime = AllDeviceWorkTime("西门子840D数冲");//西门子等待时间
-                    var behwiftStopTime = DeviceTimeValue("倍福数冲机", "停止标志位");//倍福数冲等待时间
+
+                    var laserStopTime = DeviceTimeValue("激光机", "停止标志位") - DevicMainTableTime("激光机").TotalSeconds;//激光机等待时间
+                    var siemensStopTime = AllDeviceWorkTime("西门子840D数冲") - DevicMainTableTime("西门子840D数冲").TotalSeconds;//西门子等待时间
+                    var behwiftStopTime = DeviceTimeValue("倍福数冲机", "停止标志位") - DevicMainTableTime("倍福数冲机").TotalSeconds;//倍福数冲等待时间
 
 
                     var laserStopTimeSpan = TimeSpan.FromSeconds(Math.Round(laserStopTime)).ToString();

+ 10 - 11
skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Views/Dashboard/YaweiPressBrakeOneWidget.xaml.cs

@@ -79,12 +79,11 @@ namespace SCADA_DAQ.Customer.Views.Dashboard
             var baiChaoRunTime = DeviceTimeValue("百超折弯机", "运行标志位");//百超折弯机运行时间
             var baiChaoMoldTime = DeviceTimeValue("百超折弯机", "换模标志位");//百超折弯机换模时间
 
-
-            var firstYaWeiStopTime = DeviceTimeValue("1号YaWei折弯机", "停止标志位");//1号YaWei折弯机等待时间
-            var sencondYaWeiStopTime = DeviceTimeValue("2号YaWei折弯机", "停止标志位");//2号YaWei折弯机等待时间
-            var thirdYaWweiStopTime = DeviceTimeValue("3号YaWei折弯机", "停止标志位"); //3号YaWei折弯机等待时间
-            var pbcYaWweiStopTime = DeviceTimeValue("亚威PBC折弯机", "停止标志位");//亚威PBC折弯机等待时间
-            var baiChaoStopTime = DeviceTimeValue("百超折弯机", "停止标志位");//百超折弯机折弯机等待时间
+            var firstYaWeiStopTime = DeviceTimeValue("1号YaWei折弯机", "停止标志位") - DevicMainTableTime("亚威一号折弯机").TotalSeconds;//1号YaWei折弯机等待时间
+            var sencondYaWeiStopTime = DeviceTimeValue("2号YaWei折弯机", "停止标志位") - DevicMainTableTime("亚威二号折弯机").TotalSeconds;//2号YaWei折弯机等待时间
+            var thirdYaWweiStopTime = DeviceTimeValue("3号YaWei折弯机", "停止标志位") - DevicMainTableTime("亚威三号折弯机").TotalSeconds; //3号YaWei折弯机等待时间
+            var pbcYaWweiStopTime = DeviceTimeValue("亚威PBC折弯机", "停止标志位") - DevicMainTableTime("亚威PBC折弯机").TotalSeconds;//亚威PBC折弯机等待时间
+            var baiChaoStopTime = DeviceTimeValue("百超折弯机", "停止标志位") - DevicMainTableTime("百超折弯机").TotalSeconds;//百超折弯机折弯机等待时间
 
             //double totalTimeOfDay = TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")).TotalSeconds;
             //var firstYaWeiStopTime = totalTimeOfDay - firstYaWeiRunTime - firstYaWeiMoldTime - DevicScheduleStop("1号YaWei折弯机")
@@ -321,11 +320,11 @@ namespace SCADA_DAQ.Customer.Views.Dashboard
                     var pbcYaWweiTimeMaintenanceTable = DevicMainTableTime("亚威PBC折弯机").TotalSeconds + DeviceTimeValue("亚威PBC折弯机", "维修时间");
                     var baiChaoTimeMaintenanceTable = DevicMainTableTime("百超折弯机").TotalSeconds + DeviceTimeValue("百超折弯机", "维修时间");
 
-                    var firstYaWeiStopTime = DeviceTimeValue("1号YaWei折弯机", "停止标志位");//1号YaWei折弯机等待时间
-                    var sencondYaWeiStopTime = DeviceTimeValue("2号YaWei折弯机", "停止标志位");//2号YaWei折弯机等待时间
-                    var thirdYaWweiStopTime = DeviceTimeValue("3号YaWei折弯机", "停止标志位"); //3号YaWei折弯机等待时间
-                    var pbcYaWweiStopTime = DeviceTimeValue("亚威PBC折弯机", "停止标志位");//亚威PBC折弯机等待时间
-                    var baiChaoStopTime = DeviceTimeValue("百超折弯机", "停止标志位");//百超折弯机折弯机等待时间
+                    var firstYaWeiStopTime = DeviceTimeValue("1号YaWei折弯机", "停止标志位") - DevicMainTableTime("亚威一号折弯机").TotalSeconds;//1号YaWei折弯机等待时间
+                    var sencondYaWeiStopTime = DeviceTimeValue("2号YaWei折弯机", "停止标志位") - DevicMainTableTime("亚威二号折弯机").TotalSeconds;//2号YaWei折弯机等待时间
+                    var thirdYaWweiStopTime = DeviceTimeValue("3号YaWei折弯机", "停止标志位") - DevicMainTableTime("亚威三号折弯机").TotalSeconds; //3号YaWei折弯机等待时间
+                    var pbcYaWweiStopTime = DeviceTimeValue("亚威PBC折弯机", "停止标志位") - DevicMainTableTime("亚威PBC折弯机").TotalSeconds;//亚威PBC折弯机等待时间
+                    var baiChaoStopTime = DeviceTimeValue("百超折弯机", "停止标志位") - DevicMainTableTime("百超折弯机").TotalSeconds;//百超折弯机折弯机等待时间
 
                     var firstYaWeiValueTime = new double[] { firstYaWeiRunTime, firstYaWeiStopTime, firstYaWeiTimeMaintenanceTable, firstYaWeiMoldTime };
                     var sencondYaWeiValueTime = new double[] { sencondYaWeiRunTime, sencondYaWeiStopTime, secondYaWeiTimeMaintenanceTable, sencondYaWeiMoldTime };