Browse Source

临时提交

谢翼翔 1 year ago
parent
commit
f7aa72941d

+ 342 - 203
skoda-scada-daq3.0-master/skoda-scada-daq3.0-master/scada_-daq3.0-master/SCADA_DAQ/Customer/Machines/CP1HMachine.cs

@@ -33,6 +33,8 @@ namespace SCADA_DAQ.Customer.Machines
 
         public YaweiStateInfoModel RepairTime = new YaweiStateInfoModel();
 
+        public YaweiStateInfoModel AlarmTime = new YaweiStateInfoModel();
+
         public string WaitNameStateCode { get; set; }
 
         public string OrgID { get; set; }
@@ -99,134 +101,194 @@ namespace SCADA_DAQ.Customer.Machines
                         RepairTime.OnOrgID_Str = "";
                     }
 
+                    if (AlarmTime.OnOrgID_Str != "")
+                    {
+                        Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                        $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{AlarmTime.OnOrgID_Str}'",
+                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - AlarmTime.StateOnTime_Dt)),
+                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - AlarmTime.StateOnTime_Dt).TotalSeconds));
+                        AlarmTime.OnOrgID_Str = "";
+                    }
+
 
                 }
                 else
                 {
                     if (!IsOpenTime)
                     {
-                        if (!AlarmCode)
+                        if (ConnectState == SCADA.Comm.ConnectStates.Connected)
                         {
-                            if (ConnectState == SCADA.Comm.ConnectStates.Connected)
+                            var repairTime = this.GetListenReg("维修时间");
+                            if (repairTime.Value == 1)
                             {
-                                var repairTime = this.GetListenReg("维修时间");
-                                int RepairValueRegFlag = 0;
-                                RepairValueRegFlag = (int)repairTime.Value;
-                                if (repairTime.Value == 1)
-                                {
-                                    RepairValueRegTrue = true;
-                                    RepairTime.OnOrgID_Str = Guid.NewGuid().ToString();
-                                    RepairTime.StateOnTime_Dt = DateTime.Now;
-                                    Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, RepairTime.OnOrgID_Str),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "维修时间"));
+                                RepairValueRegTrue = true;
+                                RepairTime.OnOrgID_Str = Guid.NewGuid().ToString();
+                                RepairTime.StateOnTime_Dt = DateTime.Now;
+                                Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, RepairTime.OnOrgID_Str),
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "维修时间"));
 
-                                }
-                                else if (repairTime.Value == 0)
+                            }
+                            else if (repairTime.Value == 0)
+                            {
+                                if (RepairTime.OnOrgID_Str != "")
                                 {
-                                    if (RepairTime.OnOrgID_Str != "")
-                                    {
-                                        RepairValueRegTrue = false;
-                                        Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                                        $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{RepairTime.OnOrgID_Str}'",
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - RepairTime.StateOnTime_Dt)),
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - RepairTime.StateOnTime_Dt).TotalSeconds));
-                                        RepairTime.OnOrgID_Str = "";
-                                    }
+                                    RepairValueRegTrue = false;
+                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                                    $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{RepairTime.OnOrgID_Str}'",
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - RepairTime.StateOnTime_Dt)),
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - RepairTime.StateOnTime_Dt).TotalSeconds));
+                                    RepairTime.OnOrgID_Str = "";
+                                }
 
 
-                                }
+                            }
 
-                                var runTIme = this.GetListenReg("运行标志位");
-                                if (runTIme.Value == 1 && RepairValueRegTrue != true)
+                            var runTIme = this.GetListenReg("运行标志位");
+                            if (runTIme.Value == 1 && RepairValueRegTrue != true && AlarmCode != true)
+                            {
+                                ProgramStart.OnOrgID_Str = Guid.NewGuid().ToString();
+                                ProgramStart.StateOnTime_Dt = DateTime.Now;
+                                Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, ProgramStart.OnOrgID_Str),
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "运行标志位"));
+                            }
+                            else if (runTIme.Value == 0)
+                            {
+                                if (ProgramStart.OnOrgID_Str != "")
                                 {
-                                    ProgramStart.OnOrgID_Str = Guid.NewGuid().ToString();
-                                    ProgramStart.StateOnTime_Dt = DateTime.Now;
-                                    Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, ProgramStart.OnOrgID_Str),
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "运行标志位"));
+                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                                   $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ProgramStart.OnOrgID_Str}'",
+                                   new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                                   new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ProgramStart.StateOnTime_Dt).TotalSeconds));
+                                    ProgramStart.OnOrgID_Str = "";
+
                                 }
-                                else if (runTIme.Value == 0)
-                                {
-                                    if (ProgramStart.OnOrgID_Str != "")
-                                    {
-                                        Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                                       $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ProgramStart.OnOrgID_Str}'",
-                                       new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
-                                       new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ProgramStart.StateOnTime_Dt).TotalSeconds));
-                                        ProgramStart.OnOrgID_Str = "";
 
-                                    }
 
+                            }
 
+                            var changeMoldTime = this.GetListenReg("换模标志位");
+                            if (changeMoldTime.Value == 0 && RepairValueRegTrue != true && AlarmCode != true)
+                            {
+                                ChangeModel.OnOrgID_Str = Guid.NewGuid().ToString();
+                                ChangeModel.StateOnTime_Dt = DateTime.Now;
+                                Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, ChangeModel.OnOrgID_Str),
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "换模标志位"));
+                            }
+                            else
+                            {
+                                if (ChangeModel.OnOrgID_Str != "")
+                                {
+                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                                  $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ChangeModel.OnOrgID_Str}'",
+                                  new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                                  //new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - ProgramStart.StateOnTime_Dt)),
+                                  new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ChangeModel.StateOnTime_Dt).TotalSeconds));
+                                    ChangeModel.OnOrgID_Str = "";
                                 }
 
-                                var changeMoldTime = this.GetListenReg("换模标志位");
-                                if (changeMoldTime.Value == 0 && RepairValueRegTrue != true)
+                            }
+
+                            var runFlag = this.GetListenReg("运行标志位");
+                            var toolChangeFlag = this.GetListenReg("换模标志位");
+                            var repairFlag = this.GetListenReg("维修时间");
+                            RegInfo reg = runFlag.Value == 1 ? runFlag : toolChangeFlag.Value == 0 ? toolChangeFlag : repairFlag.Value == 1 ? repairFlag : null;
+                            if (reg == null && AlarmCode != true)
+                            {
+                                if (WaitNameStateCode != "停止标志位")
                                 {
-                                    ChangeModel.OnOrgID_Str = Guid.NewGuid().ToString();
-                                    ChangeModel.StateOnTime_Dt = DateTime.Now;
+                                    WaitTime.OnOrgID_Str = Guid.NewGuid().ToString();
+                                    WaitTime.StateOnTime_Dt = DateTime.Now;
                                     Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, ChangeModel.OnOrgID_Str),
+                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, WaitTime.OnOrgID_Str),
                                         new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
                                         new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
-                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "换模标志位"));
+                                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "停止标志位"));
+                                    WaitNameStateCode = "停止标志位";
                                 }
-                                else
+
+                            }
+                            else
+                            {
+                                if (WaitTime.OnOrgID_Str != "")
                                 {
-                                    if (ChangeModel.OnOrgID_Str != "")
-                                    {
-                                        Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                                      $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ChangeModel.OnOrgID_Str}'",
+                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                                      $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{WaitTime.OnOrgID_Str}'",
                                       new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
                                       //new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - ProgramStart.StateOnTime_Dt)),
-                                      new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ChangeModel.StateOnTime_Dt).TotalSeconds));
-                                        ChangeModel.OnOrgID_Str = "";
-                                    }
-
+                                      new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - WaitTime.StateOnTime_Dt).TotalSeconds));
+                                    WaitTime.OnOrgID_Str = "";
+                                    WaitNameStateCode = "";
                                 }
 
-                                var runFlag = this.GetListenReg("运行标志位");
-                                var toolChangeFlag = this.GetListenReg("换模标志位");
-                                var repairFlag = this.GetListenReg("维修时间");
-                                RegInfo reg = runFlag.Value == 1 ? runFlag : toolChangeFlag.Value == 0 ? toolChangeFlag : repairFlag.Value == 1 ? repairFlag : null;
-                                if (reg == null)
-                                {
-                                    if (WaitNameStateCode != "停止标志位")
-                                    {
-                                        WaitTime.OnOrgID_Str = Guid.NewGuid().ToString();
-                                        WaitTime.StateOnTime_Dt = DateTime.Now;
-                                        Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
-                                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, WaitTime.OnOrgID_Str),
-                                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
-                                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
-                                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "停止标志位"));
-                                        WaitNameStateCode = "停止标志位";
-                                    }
+                            }
 
+                            if (AlarmCode == true && RepairValueRegTrue != true)
+                            {
+                                if (WaitTime.OnOrgID_Str != "")
+                                {
+                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                                     $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{WaitTime.OnOrgID_Str}'",
+                                     new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                                   new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - WaitTime.StateOnTime_Dt).TotalSeconds));
+                                    WaitTime.OnOrgID_Str = "";
+                                    WaitNameStateCode = "";
                                 }
-                                else
+                                if (ChangeModel.OnOrgID_Str != "")
                                 {
-                                    if (WaitTime.OnOrgID_Str != "")
-                                    {
-                                        Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                                          $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{WaitTime.OnOrgID_Str}'",
-                                          new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
-                                          //new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - ProgramStart.StateOnTime_Dt)),
-                                          new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - WaitTime.StateOnTime_Dt).TotalSeconds));
-                                        WaitTime.OnOrgID_Str = "";
-                                        WaitNameStateCode = "";
-                                    }
-
+                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                                         $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ChangeModel.OnOrgID_Str}'",
+                                         new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                                         new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ChangeModel.StateOnTime_Dt).TotalSeconds));
+                                    ChangeModel.OnOrgID_Str = "";
                                 }
-
+                                if (ProgramStart.OnOrgID_Str != "")
+                                {
+                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                                    $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ProgramStart.OnOrgID_Str}'",
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ProgramStart.StateOnTime_Dt).TotalSeconds));
+                                    ProgramStart.OnOrgID_Str = "";
+                                }
+                                if (AlarmTime.OnOrgID_Str == "")
+                                {
+                                    AlarmTime.OnOrgID_Str = Guid.NewGuid().ToString();
+                                    AlarmTime.StateOnTime_Dt = DateTime.Now;
+                                    Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, AlarmTime.OnOrgID_Str),
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "故障标志位"));
+                                }
+                           
                             }
                             else
+                            {
+                                if (AlarmTime.OnOrgID_Str != "")
+                                {
+                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                                    $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{AlarmTime.OnOrgID_Str}'",
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - AlarmTime.StateOnTime_Dt)),
+                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - AlarmTime.StateOnTime_Dt).TotalSeconds));
+                                    AlarmTime.OnOrgID_Str = "";
+                                }
+                            }
+
+                        }
+                        else
+                        {
+                            if (WaitNameStateCode != "停止标志位")
                             {
                                 WaitTime.OnOrgID_Str = Guid.NewGuid().ToString();
                                 WaitTime.StateOnTime_Dt = DateTime.Now;
@@ -237,8 +299,17 @@ namespace SCADA_DAQ.Customer.Machines
                                     new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "停止标志位"));
                                 WaitNameStateCode = "停止标志位";
                             }
+                            //WaitTime.OnOrgID_Str = Guid.NewGuid().ToString();
+                            //WaitTime.StateOnTime_Dt = DateTime.Now;
+                            //Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
+                            //    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, WaitTime.OnOrgID_Str),
+                            //    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
+                            //    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
+                            //    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "停止标志位"));
+                            //WaitNameStateCode = "停止标志位";
                         }
 
+
                     }
                 }
 
@@ -246,142 +317,196 @@ namespace SCADA_DAQ.Customer.Machines
         }
         protected override void RegReadValueChanged(object sender, RegReadValueChangedEventArgs e)
         {
+
             AlarmCode = this.BaseDevice.IsAlarmed;
             if (!IsOpenTime)
             {
-                if (!AlarmCode)
+                if (ConnectState == SCADA.Comm.ConnectStates.Connected)
                 {
-                    if (ConnectState == SCADA.Comm.ConnectStates.Connected)
+                    base.RegReadValueChanged(sender, e);
+                    var reg = (RegInfo)sender;
+                    int RepairValueRegFlag = 0;
+                    if (reg.Comment.Variable == "维修时间")
                     {
-                        base.RegReadValueChanged(sender, e);
-                        var reg = (RegInfo)sender;
-                        int RepairValueRegFlag = 0;
-                        if (reg.Comment.Variable == "维修时间")
+
+                        RepairValueRegFlag = (int)reg.Value;
+                        if (reg.Value == 1)
                         {
+                            RepairValueRegTrue = true;
+                            RepairTime.OnOrgID_Str = Guid.NewGuid().ToString();
+                            RepairTime.StateOnTime_Dt = DateTime.Now;
+                            Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, RepairTime.OnOrgID_Str),
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "维修时间"));
 
-                            RepairValueRegFlag = (int)reg.Value;
-                            if (reg.Value == 1)
+                        }
+                        else if (reg.Value == 0)
+                        {
+                            RepairValueRegTrue = false;
+                            if (RepairTime.OnOrgID_Str != "")
                             {
-                                RepairValueRegTrue = true;
-                                RepairTime.OnOrgID_Str = Guid.NewGuid().ToString();
-                                RepairTime.StateOnTime_Dt = DateTime.Now;
-                                Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
-                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, RepairTime.OnOrgID_Str),
-                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
-                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
-                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "维修时间"));
-
+                                Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                               $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{RepairTime.OnOrgID_Str}'",
+                               new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                               new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - RepairTime.StateOnTime_Dt)),
+                               new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - RepairTime.StateOnTime_Dt).TotalSeconds));
+                                RepairTime.OnOrgID_Str = "";
                             }
-                            else if (reg.Value == 0)
-                            {
-                                RepairValueRegTrue = false;
-                                if (RepairTime.OnOrgID_Str != "")
-                                {
-                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                                   $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{RepairTime.OnOrgID_Str}'",
-                                   new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
-                                   new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - RepairTime.StateOnTime_Dt)),
-                                   new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - RepairTime.StateOnTime_Dt).TotalSeconds));
-                                    RepairTime.OnOrgID_Str = "";
-                                }
+                         
+                        }
 
+                    }
 
 
+                    if (reg.Comment.Variable == "运行标志位" && RepairValueRegTrue == false && AlarmCode != true)
+                    {
+
+                        if (reg.Value == 1)
+                        {
+                            ProgramStart.OnOrgID_Str = Guid.NewGuid().ToString();
+                            ProgramStart.StateOnTime_Dt = DateTime.Now;
+                            Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, ProgramStart.OnOrgID_Str),
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "运行标志位"));
+                        }
+                        else if (reg.Value == 0)
+                        {
+                            if (ProgramStart.OnOrgID_Str != "")
+                            {
+                                Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                                $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ProgramStart.OnOrgID_Str}'",
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ProgramStart.StateOnTime_Dt).TotalSeconds));
+                                ProgramStart.OnOrgID_Str = "";
                             }
 
                         }
 
+                    }
 
-                        if (reg.Comment.Variable == "运行标志位" && RepairValueRegTrue == false)
+                    if (reg.Comment.Variable == "换模标志位" && RepairValueRegTrue == false && AlarmCode != true)
+                    {
+                        if (reg.Value == 0)
                         {
-
-                            if (reg.Value == 1)
+                            ChangeModel.OnOrgID_Str = Guid.NewGuid().ToString();
+                            ChangeModel.StateOnTime_Dt = DateTime.Now;
+                            Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, ChangeModel.OnOrgID_Str),
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "换模标志位"));
+                        }
+                        else
+                        {
+                            if (ChangeModel.OnOrgID_Str != "")
                             {
-                                ProgramStart.OnOrgID_Str = Guid.NewGuid().ToString();
-                                ProgramStart.StateOnTime_Dt = DateTime.Now;
-                                Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, ProgramStart.OnOrgID_Str),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "运行标志位"));
+                                Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                         $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ChangeModel.OnOrgID_Str}'",
+                         new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                         //new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - ProgramStart.StateOnTime_Dt)),
+                         new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ChangeModel.StateOnTime_Dt).TotalSeconds));
+                                ChangeModel.OnOrgID_Str = "";
                             }
-                            else if (reg.Value == 0)
-                            {
-                                if (ProgramStart.OnOrgID_Str != "")
-                                {
-                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                                    $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ProgramStart.OnOrgID_Str}'",
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ProgramStart.StateOnTime_Dt).TotalSeconds));
-                                    ProgramStart.OnOrgID_Str = "";
-                                }
 
-                            }
+                        }
+                    }
+                    var runFlag = this.GetListenReg("运行标志位");
+                    var toolChangeFlag = this.GetListenReg("换模标志位");
+                    var repairFlag = this.GetListenReg("维修时间");
+                    reg = runFlag.Value == 1 ? runFlag : toolChangeFlag.Value == 0 ? toolChangeFlag : repairFlag.Value == 1 ? repairFlag : null;
+                    if (reg == null && AlarmCode != true)
+                    {
+                        if (WaitTime.OnOrgID_Str == "" & WaitNameStateCode != "停止标志位")
+                        {
+                            WaitTime.OnOrgID_Str = Guid.NewGuid().ToString();
+                            WaitTime.StateOnTime_Dt = DateTime.Now;
+                            Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, WaitTime.OnOrgID_Str),
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
+                                new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "停止标志位"));
+                            WaitNameStateCode = "停止标志位";
+                        }
 
+                    }
+                    else
+                    {
+                        if (WaitTime.OnOrgID_Str != "")
+                        {
+                            Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                              $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{WaitTime.OnOrgID_Str}'",
+                              new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                              //new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - ProgramStart.StateOnTime_Dt)),
+                              new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - WaitTime.StateOnTime_Dt).TotalSeconds));
+                            WaitTime.OnOrgID_Str = "";
+                            WaitNameStateCode = "";
                         }
 
-                        if (reg.Comment.Variable == "换模标志位" && RepairValueRegTrue == false)
+                    }
+                  
+
+                    if (AlarmCode == true && RepairValueRegTrue != true)
+                    {
+                        if (WaitTime.OnOrgID_Str != "")
                         {
-                            if (reg.Value == 0)
-                            {
-                                ChangeModel.OnOrgID_Str = Guid.NewGuid().ToString();
-                                ChangeModel.StateOnTime_Dt = DateTime.Now;
-                                Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, ChangeModel.OnOrgID_Str),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "换模标志位"));
-                            }
-                            else
-                            {
-                                if (ChangeModel.OnOrgID_Str != "")
-                                {
-                                    Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                             $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ChangeModel.OnOrgID_Str}'",
+                            Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                             $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{WaitTime.OnOrgID_Str}'",
                              new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
-                             //new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - ProgramStart.StateOnTime_Dt)),
-                             new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ChangeModel.StateOnTime_Dt).TotalSeconds));
-                                    ChangeModel.OnOrgID_Str = "";
-                                }
-
-                            }
+                           new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - WaitTime.StateOnTime_Dt).TotalSeconds));
+                            WaitTime.OnOrgID_Str = "";
+                            WaitNameStateCode = "";
                         }
-                        var runFlag = this.GetListenReg("运行标志位");
-                        var toolChangeFlag = this.GetListenReg("换模标志位");
-                        var repairFlag = this.GetListenReg("维修时间");
-                        reg = runFlag.Value == 1 ? runFlag : toolChangeFlag.Value == 0 ? toolChangeFlag : repairFlag.Value == 1 ? repairFlag : null;
-                        if (reg == null)
+                        if (ChangeModel.OnOrgID_Str != "")
                         {
-                            if (WaitNameStateCode != "停止标志位")
-                            {
-                                WaitTime.OnOrgID_Str = Guid.NewGuid().ToString();
-                                WaitTime.StateOnTime_Dt = DateTime.Now;
-                                Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, WaitTime.OnOrgID_Str),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "停止标志位"),
-                                    new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.TagName_Str, "停止标志位"));
-                                WaitNameStateCode = "停止标志位";
-                            }
-
+                            Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                                 $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ChangeModel.OnOrgID_Str}'",
+                                 new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                                 new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ChangeModel.StateOnTime_Dt).TotalSeconds));
+                            ChangeModel.OnOrgID_Str = "";
                         }
-                        else
+                        if (ProgramStart.OnOrgID_Str != "")
                         {
-                            if (WaitTime.OnOrgID_Str != "")
-                            {
-                                Env.SqlDAL.App_Vertiv_MachineInfo.Update(
-                                  $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{WaitTime.OnOrgID_Str}'",
-                                  new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
-                                  //new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - ProgramStart.StateOnTime_Dt)),
-                                  new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - WaitTime.StateOnTime_Dt).TotalSeconds));
-                                WaitTime.OnOrgID_Str = "";
-                                WaitNameStateCode = "";
-                            }
-
+                            Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                            $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{ProgramStart.OnOrgID_Str}'",
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - ProgramStart.StateOnTime_Dt).TotalSeconds));
+                            ProgramStart.OnOrgID_Str = "";
+                        }
+                        if (AlarmTime.OnOrgID_Str == "")
+                        {
+                            AlarmTime.OnOrgID_Str = Guid.NewGuid().ToString();
+                            AlarmTime.StateOnTime_Dt = DateTime.Now;
+                            Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateId_Str, AlarmTime.OnOrgID_Str),
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Device_Str, BaseDevice.DeviceID),
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StartTime_Dt, DateTime.Now),
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "故障标志位"));
                         }
+
+
+                     
                     }
                     else
+                    {
+                        if (AlarmTime.OnOrgID_Str != "")
+                        {
+                            Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                            $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{AlarmTime.OnOrgID_Str}'",
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - AlarmTime.StateOnTime_Dt)),
+                            new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - AlarmTime.StateOnTime_Dt).TotalSeconds));
+                            AlarmTime.OnOrgID_Str = "";
+                        }
+                    }
+                
+                }
+                else
+                {
+                    if (WaitNameStateCode != "停止标志位")
                     {
                         WaitTime.OnOrgID_Str = Guid.NewGuid().ToString();
                         WaitTime.StateOnTime_Dt = DateTime.Now;
@@ -392,10 +517,12 @@ namespace SCADA_DAQ.Customer.Machines
                             new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.StateCode_Str, "停止标志位"));
                         WaitNameStateCode = "停止标志位";
                     }
+                  
                 }
 
-            }
 
+            }
+          
         }
 
 
@@ -405,8 +532,7 @@ namespace SCADA_DAQ.Customer.Machines
             AlarmCode = this.BaseDevice.IsAlarmed;
             if (!IsOpenTime)
             {
-                if (!AlarmCode)
-                {
+                
                     if (ConnectState != SCADA.Comm.ConnectStates.Connected)
                     {
                         PowerOn.OnOrgID_Str = Guid.NewGuid().ToString();
@@ -416,6 +542,9 @@ namespace SCADA_DAQ.Customer.Machines
                             );
                         PowerOn.StateOnTime_Dt = DateTime.Now;
 
+
+                    if (WaitNameStateCode != "停止标志位")
+                    {
                         WaitTime.OnOrgID_Str = Guid.NewGuid().ToString();
                         WaitTime.StateOnTime_Dt = DateTime.Now;
                         Env.SqlDAL.App_Vertiv_MachineInfo.Insert(
@@ -426,6 +555,7 @@ namespace SCADA_DAQ.Customer.Machines
                             new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.TagName_Str, "停止标志位"));
                         WaitNameStateCode = "停止标志位";
                         OrgID = WaitTime.OnOrgID_Str;
+                    }              
                     }
                     else if (ConnectState == SCADA.Comm.ConnectStates.Connected)
                     {
@@ -448,7 +578,7 @@ namespace SCADA_DAQ.Customer.Machines
 
 
                     }
-                }
+                
 
             }
 
@@ -483,8 +613,7 @@ namespace SCADA_DAQ.Customer.Machines
             if (e.ChangeType == DateTimeChangeType.SecondChanged & e.TimeFlag.Second % 15 == 0)
             {
                 AlarmCode = this.BaseDevice.IsAlarmed;
-                if (!AlarmCode)
-                {
+              
                     if (ConnectState != SCADA.Comm.ConnectStates.Connected)
                     {
                         if (WaitTime.OnOrgID_Str != "")
@@ -501,7 +630,7 @@ namespace SCADA_DAQ.Customer.Machines
                         Env.SqlDAL.App_Vertiv_MachineInfo.Update(
                          $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{WaitTime.OnOrgID_Str}'",
                          new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
-                       new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - WaitTime.StateOnTime_Dt).TotalSeconds));
+                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - WaitTime.StateOnTime_Dt).TotalSeconds));
                     }
                     if (ChangeModel.OnOrgID_Str != "")
                     {
@@ -530,7 +659,17 @@ namespace SCADA_DAQ.Customer.Machines
                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - RepairTime.StateOnTime_Dt).TotalSeconds));
 
                     }
-                }
+
+                    if (AlarmTime.OnOrgID_Str != "")
+                    {
+                        Env.SqlDAL.App_Vertiv_MachineInfo.Update(
+                        $"{T_Col_Name.App_Vertiv_MachineInfo.StateId_Str} = '{AlarmTime.OnOrgID_Str}'",
+                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.EndTime_Dt, DateTime.Now),
+                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.Duration_Dt, (DateTime.Now - AlarmTime.StateOnTime_Dt)),
+                        new UpdateItem(T_Col_Name.App_Vertiv_MachineInfo.DurationSec_Int, (DateTime.Now - AlarmTime.StateOnTime_Dt).TotalSeconds));
+
+                    }
+                
             }
         }