diff --git a/CapMachine.Core/CapMachine.Core.csproj b/CapMachine.Core/CapMachine.Core.csproj index 3971803..572049e 100644 --- a/CapMachine.Core/CapMachine.Core.csproj +++ b/CapMachine.Core/CapMachine.Core.csproj @@ -8,7 +8,7 @@ true - + diff --git a/CapMachine.Core/ConfigHelper.cs b/CapMachine.Core/ConfigHelper.cs new file mode 100644 index 0000000..a361eaa --- /dev/null +++ b/CapMachine.Core/ConfigHelper.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CapMachine.Core +{ + public class ConfigHelper + { + Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); + /// + /// 根据Key取Value值 + /// + /// + public static string GetValue(string key) + { + return ConfigurationManager.AppSettings[key].ToString().Trim(); + } + + /// + /// 根据Key修改Value + /// + /// 要修改的Key + /// 要修改为的值 + public static void SetValue(string key, string value) + { + //ConfigurationManager.AppSettings.Set(key, value); + //cfa.AppSettings.Settings[key].Value = value; + //cfa.Save(); + + Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); + configuration.AppSettings.Settings[key].Value = value; + configuration.Save(); + ConfigurationManager.RefreshSection("appSettings"); + } + + /// + /// 添加新的Key ,Value键值对 + /// + /// Key + /// Value + public static void Add(string key, string value) + { + ConfigurationManager.AppSettings.Add(key, value); + } + + /// + /// 根据Key删除项 + /// + /// Key + public static void Remove(string key) + { + ConfigurationManager.AppSettings.Remove(key); + } + + } +} diff --git a/CapMachine.Core/DeepCopyHelper.cs b/CapMachine.Core/DeepCopyHelper.cs new file mode 100644 index 0000000..4adcd0a --- /dev/null +++ b/CapMachine.Core/DeepCopyHelper.cs @@ -0,0 +1,277 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using System.Runtime.Serialization.Formatters.Binary; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Serialization; + +namespace CapMachine.Core +{ + public class DeepCopyHelper + { + // 用一个字典来存放每个对象的反射次数来避免反射代码的循环递归 + static readonly Dictionary TypereflectionCountDic = new Dictionary(); + //static object _deepCopyDemoClasstypeRef = null; + // 利用反射实现深拷贝 + public static T DeepCopyWithReflection(T obj) + { + Type type = obj.GetType(); + // 如果是字符串或值类型则直接返回 + if (obj is string || type.IsValueType) return obj; + if (type.IsArray) + { + if (type.FullName != null) + { + Type elementType = Type.GetType(type.FullName.Replace("[]", string.Empty)); + var array = obj as Array; + if (array != null) + { + Array copied = Array.CreateInstance(elementType ?? throw new InvalidOperationException(), array.Length); + for (int i = 0; i < array.Length; i++) + { + copied.SetValue(DeepCopyWithReflection(array.GetValue(i)), i); + } + return (T)Convert.ChangeType(copied, obj.GetType()); + } + } + } + + object retval = Activator.CreateInstance(obj.GetType()); + + PropertyInfo[] properties = obj.GetType().GetProperties( + BindingFlags.Public | BindingFlags.NonPublic + | BindingFlags.Instance | BindingFlags.Static); + foreach (var property in properties) + { + var propertyValue = property.GetValue(obj, null); + if (propertyValue == null) + continue; + property.SetValue(retval, DeepCopyWithReflection(propertyValue), null); + } + return (T)retval; + } + + + + public static T DeepCopyWithReflection_Second(T obj) + { + Type type = obj.GetType(); + + // 如果是字符串或值类型则直接返回 + if (obj is string || type.IsValueType) return obj; + if (type.IsArray) + { + if (type.FullName != null) + { + Type elementType = Type.GetType(type.FullName.Replace("[]", string.Empty)); + var array = obj as Array; + if (array != null) + { + Array copied = Array.CreateInstance(elementType ?? throw new InvalidOperationException(), array.Length); + for (int i = 0; i < array.Length; i++) + { + copied.SetValue(DeepCopyWithReflection_Second(array.GetValue(i)), i); + } + return (T)Convert.ChangeType(copied, obj.GetType()); + } + } + } + + // 对于类类型开始记录对象反射的次数 + int reflectionCount = Add(TypereflectionCountDic, obj.GetType()); + if (reflectionCount > 1) + return obj; + + object retval = Activator.CreateInstance(obj.GetType()); + + PropertyInfo[] properties = obj.GetType().GetProperties( + BindingFlags.Public | BindingFlags.NonPublic + | BindingFlags.Instance | BindingFlags.Static); + foreach (var property in properties) + { + var propertyValue = property.GetValue(obj, null); + if (propertyValue == null) + continue; + property.SetValue(retval, DeepCopyWithReflection_Second(propertyValue), null); + } + return (T)retval; + } + + + + //public static T DeepCopyWithReflection_Third(T obj) + //{ + // Type type = obj.GetType(); + // // 如果是字符串或值类型则直接返回 + // if (obj is string || type.IsValueType) return obj; + // if (type.IsArray) + // { + // Type elementType = Type.GetType(type.FullName.Replace("[]", string.Empty)); + // var array = obj as Array; + // Array copied = Array.CreateInstance(elementType, array.Length); + // for (int i = 0; i < array.Length; i++) + // { + // copied.SetValue(DeepCopyWithReflection_Second(array.GetValue(i)), i); + // } + // return (T) Convert.ChangeType(copied, obj.GetType()); + // } + // int reflectionCount = Add(typereflectionCountDic, obj.GetType()); + // if (reflectionCount > 1 && obj.GetType() == typeof(DeepCopyDemoClass)) + // return (T) DeepCopyDemoClasstypeRef; // 返回deepCopyClassB对象 + // object retval = Activator.CreateInstance(obj.GetType()); + // if (retval.GetType() == typeof(DeepCopyDemoClass)) + // DeepCopyDemoClasstypeRef = retval; // 保存一开始创建的DeepCopyDemoClass对象 + // PropertyInfo[] properties = obj.GetType().GetProperties( + // BindingFlags.Public | BindingFlags.NonPublic + // | BindingFlags.Instance | BindingFlags.Static); + // foreach (var property in properties) + // { + // var propertyValue = property.GetValue(obj, null); + // if (propertyValue == null) + // continue; + // property.SetValue(retval, DeepCopyWithReflection_Third(propertyValue), null); + // } + // return (T) retval; + //} + + //private static T SetArrayObject(T arrayObj) + //{ + // Type elementType = Type.GetType(arrayObj.GetType().FullName.Replace("[]", string.Empty)); + // var array = arrayObj as Array; + // Array copied = Array.CreateInstance(elementType, array.Length); + // for (int i = 0; i < array.Length; i++) + // { + // copied.SetValue(DeepCopyWithReflection_Third(array.GetValue(i)), i); + // } + // return (T) Convert.ChangeType(copied, arrayObj.GetType()); + //} + + private static int Add(Dictionary dict, Type key) + { + if (key == typeof(string) || key.IsValueType) return 0; + if (!dict.ContainsKey(key)) + { + dict.Add(key, 1); + return dict[key]; + } + dict[key] += 1; + return dict[key]; + } + + // 利用XML序列化和反序列化实现 + public static T DeepCopyWithXmlSerializer(T obj) + { + object retval; + using (MemoryStream ms = new MemoryStream()) + { + XmlSerializer xml = new XmlSerializer(typeof(T)); + xml.Serialize(ms, obj); + ms.Seek(0, SeekOrigin.Begin); + retval = xml.Deserialize(ms); + ms.Close(); + } + return (T)retval; + } + + // 利用二进制序列化和反序列实现(亲测有用) + public static T DeepCopyWithBinarySerialize(T obj) + { + object retval; + using (MemoryStream ms = new MemoryStream()) + { + BinaryFormatter bf = new BinaryFormatter(); + // 序列化成流 + bf.Serialize(ms, obj); + ms.Seek(0, SeekOrigin.Begin); + // 反序列化成对象 + retval = bf.Deserialize(ms); + ms.Close(); + } + return (T)retval; + } + + // 利用DataContractSerializer序列化和反序列化实现 + //public static T DeepCopy(T obj) + //{ + // object retval; + // using (MemoryStream ms = new MemoryStream()) + // { + // DataContractSerializer ser = new DataContractSerializer(typeof(T)); + // ser.WriteObject(ms, obj); + // ms.Seek(0, SeekOrigin.Begin); + // retval = ser.ReadObject(ms); + // ms.Close(); + // } + // return (T) retval; + //} + // 表达式树实现 + // .... + public static class TransExpV2 + { + private static readonly Func cache = GetFunc(); + private static Func GetFunc() + { + ParameterExpression parameterExpression = Expression.Parameter(typeof(TIn), "p"); + List memberBindingList = new List(); + + foreach (var item in typeof(TOut).GetProperties()) + { + if (!item.CanWrite) + continue; + + MemberExpression property = + Expression.Property(parameterExpression, typeof(TIn).GetProperty(item.Name)); + + MemberBinding memberBinding = Expression.Bind(item, property); + memberBindingList.Add(memberBinding); + } + MemberInitExpression memberInitExpression = + Expression.MemberInit(Expression.New(typeof(TOut)), memberBindingList.ToArray()); + + Expression> lambda = Expression.Lambda>(memberInitExpression, + new ParameterExpression[] { parameterExpression }); + return lambda.Compile(); + } + + public static TOut Trans(TIn tIn) + { + return cache(tIn); + } + } + } + + //public static class TransExpV2 + //{ + + // private static readonly Func cache = GetFunc(); + // private static Func GetFunc() + // { + // ParameterExpression parameterExpression = Expression.Parameter(typeof(TIn), "p"); + // List memberBindingList = new List(); + + // foreach (var item in typeof(TOut).GetProperties()) + // { + // if (!item.CanWrite) continue; + // MemberExpression property = Expression.Property(parameterExpression, typeof(TIn).GetProperty(item.Name)); + // MemberBinding memberBinding = Expression.Bind(item, property); + // memberBindingList.Add(memberBinding); + // } + + // MemberInitExpression memberInitExpression = Expression.MemberInit(Expression.New(typeof(TOut)), memberBindingList.ToArray()); + // Expression> lambda = Expression.Lambda>(memberInitExpression, new ParameterExpression[] { parameterExpression }); + + // return lambda.Compile(); + // } + + // public static TOut Trans(TIn tIn) + // { + // return cache(tIn); + // } + + //} + +} diff --git a/CapMachine.Model/CapMachine.Model.csproj b/CapMachine.Model/CapMachine.Model.csproj index c61bce4..1851f75 100644 --- a/CapMachine.Model/CapMachine.Model.csproj +++ b/CapMachine.Model/CapMachine.Model.csproj @@ -6,6 +6,6 @@ enable - + diff --git a/CapMachine.Model/MeterConfig/MeterCom.cs b/CapMachine.Model/MeterConfig/MeterCom.cs new file mode 100644 index 0000000..3628724 --- /dev/null +++ b/CapMachine.Model/MeterConfig/MeterCom.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CapMachine.Model.MeterConfig +{ + /// + /// 公共部分 + /// + public class MeterCom + { + /// + /// 程序步骤序号 + /// + public int StepNo { get; set; } + + /// + /// 开始值 + /// + public double StartValue { get; set; } + + /// + /// 结束值 + /// + public double EndValue { get; set; } + + /// + /// 维持时间 + /// + public int KeepTime { get; set; } + + /// + /// 配置值类型 + /// + public ConfigValueType ValueType { get; set; } + + /// + /// 常值 + /// 在ValueType为常值时会使用 + /// + public double Constant { get; set; } + } +} diff --git a/CapMachine.Model/MeterConfig/MeterCond1Temp.cs b/CapMachine.Model/MeterConfig/MeterCond1Temp.cs index 27d1e18..4dbc97c 100644 --- a/CapMachine.Model/MeterConfig/MeterCond1Temp.cs +++ b/CapMachine.Model/MeterConfig/MeterCond1Temp.cs @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterCondPress.cs b/CapMachine.Model/MeterConfig/MeterCond2Press.cs similarity index 93% rename from CapMachine.Model/MeterConfig/MeterCondPress.cs rename to CapMachine.Model/MeterConfig/MeterCond2Press.cs index 0248e1f..ec37fa8 100644 --- a/CapMachine.Model/MeterConfig/MeterCondPress.cs +++ b/CapMachine.Model/MeterConfig/MeterCond2Press.cs @@ -10,8 +10,8 @@ namespace CapMachine.Model /// /// COND2压力 表设置 /// - [Table(Name = "MeterCondPress")] - public class MeterCondPress + [Table(Name = "MeterCond2Press")] + public class MeterCond2Press { /// /// 主键 @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterCond2Temp.cs b/CapMachine.Model/MeterConfig/MeterCond2Temp.cs index 869d470..ad638e9 100644 --- a/CapMachine.Model/MeterConfig/MeterCond2Temp.cs +++ b/CapMachine.Model/MeterConfig/MeterCond2Temp.cs @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterEVAPExpTemp.cs b/CapMachine.Model/MeterConfig/MeterEVAPExpTemp.cs index 46383b0..0439494 100644 --- a/CapMachine.Model/MeterConfig/MeterEVAPExpTemp.cs +++ b/CapMachine.Model/MeterConfig/MeterEVAPExpTemp.cs @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterTestBoxRH.cs b/CapMachine.Model/MeterConfig/MeterEnvRH.cs similarity index 93% rename from CapMachine.Model/MeterConfig/MeterTestBoxRH.cs rename to CapMachine.Model/MeterConfig/MeterEnvRH.cs index 358f04f..a0621fe 100644 --- a/CapMachine.Model/MeterConfig/MeterTestBoxRH.cs +++ b/CapMachine.Model/MeterConfig/MeterEnvRH.cs @@ -10,8 +10,8 @@ namespace CapMachine.Model /// /// 试验箱湿度 表设置 /// - [Table(Name = "MeterTestBoxRH")] - public class MeterTestBoxRH + [Table(Name = "MeterEnvRH")] + public class MeterEnvRH { /// /// 主键 @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterTestBoxTemp.cs b/CapMachine.Model/MeterConfig/MeterEnvTemp.cs similarity index 93% rename from CapMachine.Model/MeterConfig/MeterTestBoxTemp.cs rename to CapMachine.Model/MeterConfig/MeterEnvTemp.cs index 4a15bcc..a988b0a 100644 --- a/CapMachine.Model/MeterConfig/MeterTestBoxTemp.cs +++ b/CapMachine.Model/MeterConfig/MeterEnvTemp.cs @@ -10,8 +10,8 @@ namespace CapMachine.Model /// /// 试验箱温度 表设置 /// - [Table(Name = "MeterTestBoxTemp")] - public class MeterTestBoxTemp + [Table(Name = "MeterEnvTemp")] + public class MeterEnvTemp { /// /// 主键 @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterExPress.cs b/CapMachine.Model/MeterConfig/MeterExPress.cs index b278787..8b3a16f 100644 --- a/CapMachine.Model/MeterConfig/MeterExPress.cs +++ b/CapMachine.Model/MeterConfig/MeterExPress.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace CapMachine.Model { /// - /// 排气压力设置 + /// 排气压力 设置 /// [Table(Name = "MeterExPress")] public class MeterExPress @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterHVVol.cs b/CapMachine.Model/MeterConfig/MeterHVVol.cs index b123d1e..0e920e1 100644 --- a/CapMachine.Model/MeterConfig/MeterHVVol.cs +++ b/CapMachine.Model/MeterConfig/MeterHVVol.cs @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterInhPress.cs b/CapMachine.Model/MeterConfig/MeterInhPress.cs index 8d98cb2..47f8053 100644 --- a/CapMachine.Model/MeterConfig/MeterInhPress.cs +++ b/CapMachine.Model/MeterConfig/MeterInhPress.cs @@ -36,7 +36,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterInhTemp.cs b/CapMachine.Model/MeterConfig/MeterInhTemp.cs index 316a9d3..1a513df 100644 --- a/CapMachine.Model/MeterConfig/MeterInhTemp.cs +++ b/CapMachine.Model/MeterConfig/MeterInhTemp.cs @@ -36,7 +36,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterLVVol.cs b/CapMachine.Model/MeterConfig/MeterLVVol.cs index 19eb742..904ebf9 100644 --- a/CapMachine.Model/MeterConfig/MeterLVVol.cs +++ b/CapMachine.Model/MeterConfig/MeterLVVol.cs @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterLoPress.cs b/CapMachine.Model/MeterConfig/MeterLubePress.cs similarity index 93% rename from CapMachine.Model/MeterConfig/MeterLoPress.cs rename to CapMachine.Model/MeterConfig/MeterLubePress.cs index 1f7eb3b..cf7b13c 100644 --- a/CapMachine.Model/MeterConfig/MeterLoPress.cs +++ b/CapMachine.Model/MeterConfig/MeterLubePress.cs @@ -10,8 +10,8 @@ namespace CapMachine.Model /// /// 润滑油压力 设置 /// - [Table(Name = "MeterLoPress")] - public class MeterLoPress + [Table(Name = "MeterLubePress")] + public class MeterLubePress { /// /// 主键 @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterOCR.cs b/CapMachine.Model/MeterConfig/MeterOCR.cs index bf44daf..ae09d1e 100644 --- a/CapMachine.Model/MeterConfig/MeterOCR.cs +++ b/CapMachine.Model/MeterConfig/MeterOCR.cs @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterOS1Temp.cs b/CapMachine.Model/MeterConfig/MeterOS1Temp.cs index b767e9a..06677c8 100644 --- a/CapMachine.Model/MeterConfig/MeterOS1Temp.cs +++ b/CapMachine.Model/MeterConfig/MeterOS1Temp.cs @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterOS2Temp.cs b/CapMachine.Model/MeterConfig/MeterOS2Temp.cs index e9f01b7..18b60b0 100644 --- a/CapMachine.Model/MeterConfig/MeterOS2Temp.cs +++ b/CapMachine.Model/MeterConfig/MeterOS2Temp.cs @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterPTCEntTemp.cs b/CapMachine.Model/MeterConfig/MeterPTCEntTemp.cs index 242e871..372496b 100644 --- a/CapMachine.Model/MeterConfig/MeterPTCEntTemp.cs +++ b/CapMachine.Model/MeterConfig/MeterPTCEntTemp.cs @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterPTCFlow.cs b/CapMachine.Model/MeterConfig/MeterPTCFlow.cs index 4f765fc..1e45881 100644 --- a/CapMachine.Model/MeterConfig/MeterPTCFlow.cs +++ b/CapMachine.Model/MeterConfig/MeterPTCFlow.cs @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterPTCPw.cs b/CapMachine.Model/MeterConfig/MeterPTCPw.cs index e215c8f..04eb459 100644 --- a/CapMachine.Model/MeterConfig/MeterPTCPw.cs +++ b/CapMachine.Model/MeterConfig/MeterPTCPw.cs @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 diff --git a/CapMachine.Model/MeterConfig/MeterPd.cs b/CapMachine.Model/MeterConfig/MeterPd.cs deleted file mode 100644 index 7930ee8..0000000 --- a/CapMachine.Model/MeterConfig/MeterPd.cs +++ /dev/null @@ -1,70 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CapMachine.Model -{ - /// - /// Pd表设置 - /// - [Table(Name = "MeterPd")] - public class MeterPd - { - /// - /// 主键 - /// - [Column(IsPrimary = true, IsIdentity = true)] - public long Id { get; set; } - - /// - /// 程序步骤序号 - /// - [Column(Name = "StepNo")] - public int StepNo { get; set; } - - /// - /// 开始值 - /// - [Column(Name = "StartValue")] - public double StartValue { get; set; } - - /// - /// 结束值 - /// - [Column(Name = "EndValue")] - public double EndValue { get; set; } - - /// - /// 维持时间 - /// - [Column(Name = "KeepTime")] - public double KeepTime { get; set; } - - /// - /// 配置值类型 - /// - [Column(MapType = typeof(int))] - public ConfigValueType ValueType { get; set; } - - /// - /// 常值 - /// 在ValueType为常值时会使用 - /// - [Column(Name = "Constant")] - public double Constant { get; set; } - - - [Column(ServerTime = DateTimeKind.Local, CanUpdate = false)] - public DateTime CreateTime { get; set; } - - /// - /// ///////////////////////////////////////////导航属性/////////////////////////////////////////////////////// - /// - - public long ProStepId { get; set; } - public ProStep? ProStep { get; set; } - } -} diff --git a/CapMachine.Model/MeterConfig/MeterPs.cs b/CapMachine.Model/MeterConfig/MeterPs.cs deleted file mode 100644 index b6f1cdf..0000000 --- a/CapMachine.Model/MeterConfig/MeterPs.cs +++ /dev/null @@ -1,70 +0,0 @@ -using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CapMachine.Model -{ - /// - /// Ps表设置 - /// - [Table(Name = "MeterPs")] - public class MeterPs - { - /// - /// 主键 - /// - [Column(IsPrimary = true, IsIdentity = true)] - public long Id { get; set; } - - /// - /// 程序步骤序号 - /// - [Column(Name = "StepNo")] - public int StepNo { get; set; } - - /// - /// 开始值 - /// - [Column(Name = "StartValue")] - public double StartValue { get; set; } - - /// - /// 结束值 - /// - [Column(Name = "EndValue")] - public double EndValue { get; set; } - - /// - /// 维持时间 - /// - [Column(Name = "KeepTime")] - public double KeepTime { get; set; } - - /// - /// 配置值类型 - /// - [Column(MapType = typeof(int))] - public ConfigValueType ValueType { get; set; } - - /// - /// 常值 - /// 在ValueType为常值时会使用 - /// - [Column(Name = "Constant")] - public double Constant { get; set; } - - - [Column(ServerTime = DateTimeKind.Local, CanUpdate = false)] - public DateTime CreateTime { get; set; } - - /// - /// ///////////////////////////////////////////导航属性/////////////////////////////////////////////////////// - /// - - public long ProStepId { get; set; } - public ProStep? ProStep { get; set; } - } -} diff --git a/CapMachine.Model/MeterConfig/MeterSpeed.cs b/CapMachine.Model/MeterConfig/MeterSpeed.cs index 8d6a941..a4eeb37 100644 --- a/CapMachine.Model/MeterConfig/MeterSpeed.cs +++ b/CapMachine.Model/MeterConfig/MeterSpeed.cs @@ -41,7 +41,7 @@ namespace CapMachine.Model /// 维持时间 /// [Column(Name = "KeepTime")] - public double KeepTime { get; set; } + public int KeepTime { get; set; } /// /// 配置值类型 @@ -56,7 +56,54 @@ namespace CapMachine.Model [Column(Name = "Constant")] public double Constant { get; set; } - + /// + /// ///////////////////////////////////////////跟随速度小步骤的常量数据/////////////////////////////////////////////////////// + /// + + + /// + /// 输出锁定(0/1) + /// 跟随速度步骤的常值数据 + /// + [Column(Name = "OutLock")] + public bool OutLock { get; set; } + + /// + ///参数编号(1~16) + /// 跟随速度步骤的常值数据 + /// + [Column(Name = "ParNo")] + public int ParNo { get; set; } + + /// + ///EV(1~4) + /// 跟随速度步骤的常值数据 + /// + [Column(Name = "Ev")] + public int Ev { get; set; } + + // + /// 压缩机使能(0/1) + /// 跟随速度步骤的常值数据 + /// + [Column(Name = "CapEnable")] + public bool CapEnable { get; set; } + + // + /// 吸排气阀(0/1) + /// 跟随速度步骤的常值数据 + /// + [Column(Name = "InhExhValve")] + public bool InhExhValve { get; set; } + + // + /// 加热器使能(0/1) + /// 跟随速度步骤的常值数据 + /// + [Column(Name = "HeatEnable")] + public bool HeatEnable { get; set; } + + [Column(ServerTime = DateTimeKind.Local, CanUpdate = false)] public DateTime CreateTime { get; set; } diff --git a/CapMachine.Model/PLCParsModel/PlcBlockData.cs b/CapMachine.Model/PLCParsModel/PlcBlockData.cs new file mode 100644 index 0000000..7576e88 --- /dev/null +++ b/CapMachine.Model/PLCParsModel/PlcBlockData.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CapMachine.Model +{ + public class PlcBlockData + { + /// + /// 开始地址 + /// + public string? StartAddress { get; set; } + + /// + /// 值集合 + /// + public short[]? ArrValue { get; set; } + } +} diff --git a/CapMachine.Model/PLCParsModel/PlcMeterStepCell.cs b/CapMachine.Model/PLCParsModel/PlcMeterStepCell.cs new file mode 100644 index 0000000..ed5b35e --- /dev/null +++ b/CapMachine.Model/PLCParsModel/PlcMeterStepCell.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CapMachine.Model +{ + /// + /// 步骤的PLC数据单元 + /// + public class PlcMeterStepCell + { + /// + /// 步骤序号 + /// 从1开始 + /// + public int Step { get; set; } + + /// + /// 时间-分 + /// + public int TimeMin { get; set; } + + /// + /// 时间-秒 + /// + public int TimeSec { get; set; } + + /// + /// 循环 + /// + public int Cycle { get; set; } + + /// + /// 值 + /// + public double? Value { get; set; } + + ///// + ///// 地址 + ///// + //public string? Address { get; set; } + + + /// + /// 值地址 + /// + public string? ValueAddress { get; set; } + + /// + /// 分钟地址 + /// + public string? MinAddress { get; set; } + + /// + /// 秒地址 + /// + public string? SecAddress { get; set; } + + /// + /// 循环地址 + /// + public string? CycleAddress { get; set; } + + } +} diff --git a/CapMachine.Model/PLCParsModel/PlcParsData.cs b/CapMachine.Model/PLCParsModel/PlcParsData.cs new file mode 100644 index 0000000..98f837d --- /dev/null +++ b/CapMachine.Model/PLCParsModel/PlcParsData.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CapMachine.Model +{ + /// + /// PLC 解析信息数据 + /// + public class PlcParsData + { + public PlcParsData() + { + + Steps=new List (); + Unit = ""; + } + + + /// + /// 名称 + /// + public string? Name { get; set; } + + /// + /// Model 名称/英文名称 + /// + public string? EnName { get; set; } + + /// + /// 单位 + /// + public string? Unit { get; set; } + + /// + /// 分辨率 + /// + public int? Ratio { get; set; } + + /// + /// 步骤集合信息 + /// + public List Steps { get; set; } + + /// + /// 值首地址 + /// + public int? ValueStartAddress { get; set; } + + /// + /// 分钟首地址 + /// + public int? MinStartAddress { get; set; } + + /// + /// 秒首地址 + /// + public int? SecStartAddress { get; set; } + + /// + /// 循环首地址 + /// + public int? CycleStartAddress { get; set; } + + } +} diff --git a/CapMachine.Model/ProSegRun.cs b/CapMachine.Model/ProSegRun.cs new file mode 100644 index 0000000..785e0e3 --- /dev/null +++ b/CapMachine.Model/ProSegRun.cs @@ -0,0 +1,36 @@ +using FreeSql.DataAnnotations; + +namespace CapMachine.Model +{ + /// + /// 选中运行的程序名称 + /// + [Table(Name = "ProSegRun")] + public class ProSegRun + { + /// + /// 主键 + /// + [Column(IsPrimary = true, IsIdentity = true)] + public long Id { get; set; } + + /// + /// 运行程序序号 + /// + [Column(Name = "StepNo")] + public int StepNo { get; set; } + + /// + /// 程序名称 + /// 工况名称 + /// + [Column(Name = "Name", IsNullable = false, StringLength = 50)] + public string? Name { get; set; } + + /// + /// ///////////////////////////////////////////导航属性/////////////////////////////////////////////////////// + /// + public long ProgramSegId { get; set; } + public ProgramSeg? ProgramSeg { get; set; } + } +} diff --git a/CapMachine.Model/ProStep.cs b/CapMachine.Model/ProStep.cs index 9f67167..f6823a1 100644 --- a/CapMachine.Model/ProStep.cs +++ b/CapMachine.Model/ProStep.cs @@ -12,7 +12,7 @@ namespace CapMachine.Model /// 步骤 /// [Table(Name = "ProStep")] - public class ProStep + public class ProStep { /// /// 主键 @@ -47,33 +47,35 @@ namespace CapMachine.Model [Column(ServerTime = DateTimeKind.Local, CanUpdate = false)] public DateTime CreateTime { get; set; } + /// + /// 速度内部步骤的循环次数 + /// + [Column(Name = "SpeedCycle")] + public int SpeedCycle { get; set; } /// /// ///////////////////////////////////////////导航属性/////////////////////////////////////////////////////// /// - public ICollection? MeterSpeeds { get; set; } - public ICollection? MeterCond1Temps { get; set; } - public ICollection? MeterCond2Temps { get; set; } - public ICollection? MeterCondPresss { get; set; } - public ICollection? MeterEVAPExpTemps { get; set; } - public ICollection? MeterExPresss { get; set; } - public ICollection? MeterHVVols { get; set; } - public ICollection? MeterInhPresss { get; set; } - public ICollection? MeterInhTemps { get; set; } - public ICollection? MeterLoPresss { get; set; } - public ICollection? MeterLVVols { get; set; } - public ICollection? MeterOCRs { get; set; } - public ICollection? MeterOS1Temps { get; set; } - public ICollection? MeterOS2Temps { get; set; } - public ICollection? MeterPTCEntTemps { get; set; } - public ICollection? MeterPTCFlows { get; set; } - public ICollection? MeterPTCPws { get; set; } - public ICollection? MeterTestBoxRHs { get; set; } - public ICollection? MeterTestBoxTemps { get; set; } - - //public ICollection? MeterPds { get; set; } - //public ICollection? MeterPss { get; set; } + public List? MeterSpeeds { get; set; }=new List(); + public List? MeterCond1Temps { get; set; }=new List(); + public List? MeterCond2Temps { get; set; }= new List(); + public List? MeterCond2Presss { get; set; } = new List(); + public List? MeterEVAPExpTemps { get; set; }=new List(); + public List? MeterExPresss { get; set; }=new List(); + public List? MeterHVVols { get; set; } = new List(); + public List? MeterInhPresss { get; set; } = new List(); + public List? MeterInhTemps { get; set; } = new List(); + public List? MeterLubePresss { get; set; } = new List(); + public List? MeterLVVols { get; set; } = new List(); + public List? MeterOCRs { get; set; }=new List(); + public List? MeterOS1Temps { get; set; }=new List(); + public List? MeterOS2Temps { get; set; }=new List(); + public List? MeterPTCEntTemps { get; set; }=new List(); + public List? MeterPTCFlows { get; set; }=new List(); + public List? MeterPTCPws { get; set; } = new List(); + public List? MeterEnvRHs { get; set; }=new List(); + public List? MeterEnvTemps { get; set; }=new List(); /// /// ///////////////////////////////////////////导航属性/////////////////////////////////////////////////////// diff --git a/CapMachine.Model/ProStepDto.cs b/CapMachine.Model/ProStepDto.cs deleted file mode 100644 index 1d4d04f..0000000 --- a/CapMachine.Model/ProStepDto.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CapMachine.Model -{ - public class ProStepDto - { - /// - /// 主键 - /// - public long Id { get; set; } - - /// - /// 程序步骤序号 - /// - public int StepNo { get; set; } - - /// - /// 程序循环次数 - /// - public int StepRepeat { get; set; } - - /// - /// 压缩机转速信息 - /// - public string? SpeedInfo { get; set; } - - /// - /// PID信息 - /// - public string? PID { get; set; } - - /// - /// PID输出限幅信息 - /// - public string? PIDOutLimit { get; set; } - - /// - /// Ps信息 - /// - public string? Ps { get; set; } - - /// - /// Pd信息 - /// - public string? PdInfo{ get; set; } - } -} diff --git a/CapMachine.Model/ProgramSeg.cs b/CapMachine.Model/ProgramSeg.cs index 8d87e17..94ddd6e 100644 --- a/CapMachine.Model/ProgramSeg.cs +++ b/CapMachine.Model/ProgramSeg.cs @@ -1,6 +1,4 @@ using FreeSql.DataAnnotations; -using System; -using System.Collections.Generic; namespace CapMachine.Model { @@ -23,6 +21,13 @@ namespace CapMachine.Model [Column(Name = "Name", IsNullable = false, StringLength = 50)] public string? Name { get; set; } + /// + /// 程序名称 + /// 分类 + /// + [Column(Name = "Category", IsNullable = true, StringLength = 50)] + public string? Category { get; set; } + /// /// 程序段反复 /// @@ -49,7 +54,7 @@ namespace CapMachine.Model /// ///////////////////////////////////////////导航属性/////////////////////////////////////////////////////// /// - public ICollection? ProSteps { get; set; } + public List? ProSteps { get; set; } } } diff --git a/CapMachine.Model/QuickMeterConfig/QuickMeterStep.cs b/CapMachine.Model/QuickMeterConfig/QuickMeterStep.cs new file mode 100644 index 0000000..9833bd1 --- /dev/null +++ b/CapMachine.Model/QuickMeterConfig/QuickMeterStep.cs @@ -0,0 +1,161 @@ +using FreeSql.DataAnnotations; + +namespace CapMachine.Model.QuickMeterConfig +{ + /// + /// 快速的步骤信息 QuickMeterStep + /// + [Table(Name = "QuickMeterStep")] + public class QuickMeterStep + { + /// + /// 主键 + /// + [Column(IsPrimary = true, IsIdentity = true)] + public long Id { get; set; } + + /// + /// 步骤序号 + /// + [Column(Name = "StepNo")] + public int StepNo { get; set; } + + /// + /// 时间-分钟 + /// + [Column(Name = "TimeMin")] + public int TimeMin { get; set; } + + /// + /// 时间-秒 + /// + [Column(Name = "TimeSec")] + public int TimeSec { get; set; } + + /// + /// 时间-循环 + /// + [Column(Name = "Cycle")] + public int Cycle { get; set; } + + /// + /// 速度 + /// + [Column(Name = "Speed")] + public double Speed { get; set; } + + /// + /// 排气压力 + /// + [Column(Name = "ExPress")] + public double ExPress { get; set; } + + /// + /// 吸气压力 + /// + [Column(Name = "InhPress")] + public double InhPress { get; set; } + + /// + /// 吸气温度 + /// + [Column(Name = "InhTemp")] + public double InhTemp { get; set; } + + /// + /// COND1温度 + /// + [Column(Name = "Cond1Temp")] + public double Cond1Temp { get; set; } + + /// + /// 润滑油压力 + /// + [Column(Name = "LubePress")] + public double LubePress { get; set; } + + /// + /// COND2压力 + /// + [Column(Name = "Cond2Press")] + public double Cond2Press { get; set; } + + /// + /// OCR + /// + [Column(Name = "OCR")] + public double OCR { get; set; } + + /// + /// HV电压 + /// + [Column(Name = "HVVol")] + public double HVVol { get; set; } + + /// + /// LV电压 + /// + [Column(Name = "LVVol")] + public double LVVol { get; set; } + + /// + /// 环境湿度 + /// + [Column(Name = "EnvRH")] + public double EnvRH { get; set; } + + /// + /// 环境温度 + /// + [Column(Name = "EnvTemp")] + public double EnvTemp { get; set; } + + /// + /// OS1温度 + /// + [Column(Name = "OS1Temp")] + public double OS1Temp { get; set; } + + /// + /// OS2温度 + /// + [Column(Name = "OS2Temp")] + public double OS2Temp { get; set; } + + /// + /// PTC入口温度 + /// + [Column(Name = "PTCEntTemp")] + public double PTCEntTemp { get; set; } + + /// + /// PTC流量 + /// + [Column(Name = "PTCFlow")] + public double PTCFlow { get; set; } + + /// + /// PTC功率 + /// + [Column(Name = "PTCPw")] + public double PTCPw { get; set; } + + /// + /// EVAP出口温度 + /// + [Column(Name = "EVAPExpTemp")] + public double EVAPExpTemp { get; set; } + + /// + /// COND2温度 + /// + [Column(Name = "Cond2Temp")] + public double Cond2Temp { get; set; } + + ///// + ///// xxxx + ///// + //[Column(Name = "xxxx")] + //public double xxxx { get; set; } + } +} diff --git a/CapMachine.Shared/Controls/BoolNgConvert.cs b/CapMachine.Shared/Controls/BoolNgConvert.cs new file mode 100644 index 0000000..b44cee3 --- /dev/null +++ b/CapMachine.Shared/Controls/BoolNgConvert.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace CapMachine.Shared.Controls +{ + public class BoolNgConvert : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is bool booleanValue) + { + return !booleanValue; + } + return value; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is bool booleanValue) + { + return !booleanValue; + } + return value; + } + } +} diff --git a/CapMachine.Shared/Controls/MeterConfig.xaml b/CapMachine.Shared/Controls/MeterConfig.xaml index 1773aa8..5817bd5 100644 --- a/CapMachine.Shared/Controls/MeterConfig.xaml +++ b/CapMachine.Shared/Controls/MeterConfig.xaml @@ -8,10 +8,12 @@ xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" x:Name="MeterConfigInstance" - d:DesignHeight="330" - d:DesignWidth="360" + d:DesignHeight="400" + d:DesignWidth="300" mc:Ignorable="d"> + + + + + + + + + + + + + + + + - - - + 常值数据 + + + + public string RtAddressSV; - /// - /// MV值的UI展示名称 - /// - public string RtMVUIControlIndex; + ///// + ///// MV值的UI展示名称 + ///// + //public string RtMVUIControlIndex; - /// - /// PV值的UI展示名称 - /// - public string RtPVUIControlIndex; + ///// + ///// PV值的UI展示名称 + ///// + //public string RtPVUIControlIndex; - /// - /// SV值的UI展示名称 - /// - public string RtSVUIControlIndex; + ///// + ///// SV值的UI展示名称 + ///// + //public string RtSVUIControlIndex; /// /// UI展示名称标题 @@ -180,16 +180,22 @@ namespace CapMachine.Wpf.Models ////////////////////////////////////////////////// #region 仪表整体信息 + /// /// 仪表连接状态 /// public bool LinkState { get; set; } /// - /// 仪表名称 + /// 仪表名称 中文 /// public string MeterName { get; set; } + /// + /// 仪表名称 英文 + /// + public string MeterEnName { get; set; } + /// /// 仪表站号 /// @@ -208,7 +214,7 @@ namespace CapMachine.Wpf.Models /// /// 精度 /// - public Int16 Accuracy { get; set; } + public short Precision { get; set; } /// /// 单位 diff --git a/CapMachine.Wpf/Models/Tag/BaseTag.cs b/CapMachine.Wpf/Models/Tag/BaseTag.cs new file mode 100644 index 0000000..6dfc29e --- /dev/null +++ b/CapMachine.Wpf/Models/Tag/BaseTag.cs @@ -0,0 +1,101 @@ +using HslCommunication; +using ImTools; +using NPOI.SS.Formula.Functions; +using Prism.Mvvm; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static CapMachine.Wpf.Models.ComEnum; + +namespace CapMachine.Wpf.Models.Tag +{ + /// + /// 基础模型 + /// + public abstract class BaseTag : BindableBase + { + /// + /// 实例化函数 + /// + /// + /// + /// + public BaseTag(string name, string enName, string unit, TagType tagType) + { + TagTypeInfo = tagType; + Name = name; + Unit = unit; + EnName = enName; + + } + + /// + /// 名称 中文 + /// + public string Name { get; set; } + + /// + /// 名称 英文 + /// + public string EnName { get; set; } + + + ///// + ///// 实时值 + ///// + public abstract IRegisterValue RtValue { get; set; } + + /////// + /////// 原始值实时值 + /////// + //public abstract OperateResult OperateResultSource { get; set; } // + + /// + /// 标签类型信息 + /// + public TagType TagTypeInfo { get; set; } + + /// + /// 数据类型信息 + /// + public abstract DataType DataTypeInfo { get; set; } + + /// + /// 地址信息 + /// + public string Address { get; set; } + + /// + /// 地址信息 Index + /// + public string Index { get; set; } + + /// + /// 最大值 + /// + public double MaxValue { get; set; } + + /// + /// 最小值 + /// + public double MinValue { get; set; } + + /// + /// 精度 + /// 小数点 + /// + public short Precision { get; set; } + + /// + /// 单位 + /// + public string? Unit { get; set; } + + /// + /// 采样周期 + /// + public int SamplingPeriod { get; set; } + } +} diff --git a/CapMachine.Wpf/Models/Tag/ByteTag.cs b/CapMachine.Wpf/Models/Tag/ByteTag.cs new file mode 100644 index 0000000..d7eb3f1 --- /dev/null +++ b/CapMachine.Wpf/Models/Tag/ByteTag.cs @@ -0,0 +1,77 @@ +using HslCommunication; +using NPOI.SS.Formula.Functions; +using Prism.Mvvm; +using static CapMachine.Wpf.Models.ComEnum; + +namespace CapMachine.Wpf.Models.Tag +{ + /// + /// 字节变量模型 + /// + public class ByteTag /*: BaseTag*/ + { + ///// + ///// 实例化函数 + ///// + ///// + ///// + ///// + ///// + //public ByteTag(string name, string enName, string unit, ComEnum.TagType tagType, T registerValue) : base(name, enName, unit, tagType) + //{ + // //IRegisterValue registerValue = new RegisterValue(); + + // //RtValue = registerValue; + //} + + + + public string Name { get; set; } + //T BaseTag.RtValue { get; set; } + + //private IRegisterValue _RtValue; + ///// + ///// 实时值 + ///// + //public override IRegisterValue RtValue + //{ + // get { return _RtValue; } + // set { _RtValue = value; RaisePropertyChanged(); } + //} + + //public override IRegisterValue RtValue { set => throw new NotImplementedException(); } + + //private OperateResult _OperateResultSource; + ///// + ///// 原始值 + ///// + //public override OperateResult OperateResultSource + //{ + // get { return _OperateResultSource; } + // set + // { + // if (value != _OperateResultSource) + // { + // RtValue = value.Content; + // } + // _OperateResultSource = value; + // } + //} + + //private DataType _DataTypeInfo; + ///// + ///// 数据类型信息 + ///// + //public override DataType DataTypeInfo + //{ + // get { return _DataTypeInfo; } + // set { _DataTypeInfo = value; RaisePropertyChanged(); } + //} + + //public override IRegisterValue RtValue { set => throw new NotImplementedException(); } + + //public override IRegisterValue RtValue => throw new NotImplementedException(); + + + } +} diff --git a/CapMachine.Wpf/Models/Tag/IRegisterValue.cs b/CapMachine.Wpf/Models/Tag/IRegisterValue.cs new file mode 100644 index 0000000..0e4b1e6 --- /dev/null +++ b/CapMachine.Wpf/Models/Tag/IRegisterValue.cs @@ -0,0 +1,15 @@ +using HslCommunication; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CapMachine.Wpf.Models.Tag +{ + public interface IRegisterValue + { + T Value { get; set; } + OperateResult OperateResultSource { get; set; } + } +} diff --git a/CapMachine.Wpf/Models/Tag/ITag.cs b/CapMachine.Wpf/Models/Tag/ITag.cs new file mode 100644 index 0000000..00545ae --- /dev/null +++ b/CapMachine.Wpf/Models/Tag/ITag.cs @@ -0,0 +1,17 @@ +using NPOI.SS.Formula.Functions; +using Prism.Mvvm; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CapMachine.Wpf.Models.Tag +{ + public interface ITag + { + string Name { get; set; } + + T RtValue { get; set; } + } +} diff --git a/CapMachine.Wpf/Models/Tag/RegisterValue.cs b/CapMachine.Wpf/Models/Tag/RegisterValue.cs new file mode 100644 index 0000000..7859dbc --- /dev/null +++ b/CapMachine.Wpf/Models/Tag/RegisterValue.cs @@ -0,0 +1,15 @@ +using HslCommunication; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CapMachine.Wpf.Models.Tag +{ + public class RegisterValue : IRegisterValue + { + public byte Value { get; set; } + public OperateResult? OperateResultSource { get; set; } + } +} diff --git a/CapMachine.Wpf/Models/Tag/RtDataModel.cs b/CapMachine.Wpf/Models/Tag/RtDataModel.cs new file mode 100644 index 0000000..77a4957 --- /dev/null +++ b/CapMachine.Wpf/Models/Tag/RtDataModel.cs @@ -0,0 +1,59 @@ +using HslCommunication; +using static CapMachine.Wpf.Models.ComEnum; + +namespace CapMachine.Wpf.Models.Tag +{ + /// + /// 实时数据模型 + /// + public class RtDataModel : TagInfo + { + /// + /// 实例化函数 + /// + /// + /// + /// + /// + public RtDataModel(string name, string enName, string unit, TagType tagType, bool IsChart) : base(name, enName, unit, tagType) + { + IsChartShow = IsChart; + + } + + /// + /// 分类信息 + /// + public string Category { get; set; } + + /// + /// 通信结果 实时值 + /// + private OperateResult _OperateResultRtValue; + public OperateResult OperateResultRtValue + { + get { return _OperateResultRtValue; } + set { _OperateResultRtValue = value; } + } + + private double _RtValue; + /// + /// 实时值 + /// + public double RtValue + { + get { return _RtValue; } + set { _RtValue = value; RaisePropertyChanged(); } + } + + /// + /// 实时值的地址 + /// + public string RtValueAddress { get; set; } + + /// + /// 是否曲线显示 + /// + public bool IsChartShow { get; set; } + } +} diff --git a/CapMachine.Wpf/Models/Tag/ShortTag.cs b/CapMachine.Wpf/Models/Tag/ShortTag.cs new file mode 100644 index 0000000..c59f52d --- /dev/null +++ b/CapMachine.Wpf/Models/Tag/ShortTag.cs @@ -0,0 +1,55 @@ +using HslCommunication; +using NPOI.SS.Formula.Functions; +using static CapMachine.Wpf.Models.ComEnum; + +namespace CapMachine.Wpf.Models.Tag +{ + ///// + ///// 字变量模型 + ///// + //public class ShortTag: BaseTag + //{ + // public ShortTag(string name, string enName, string unit, ComEnum.TagType tagType) : base(name, enName, unit, tagType) + // { + + // } + + // private short _RtValue; + // /// + // /// 实时值 + // /// + // public override short RtValue + // { + // get { return _RtValue; } + // set { _RtValue = value; RaisePropertyChanged(); } + // } + + // private OperateResult _OperateResultSource; + // /// + // /// 原始值 + // /// + // public override OperateResult OperateResultSource + // { + // get { return _OperateResultSource; } + // set + // { + // if (value != _OperateResultSource) + // { + // RtValue= value.Content; + // } + // _OperateResultSource = value; + // } + // } + + // private DataType _DataTypeInfo; + // /// + // /// 数据类型信息 + // /// + // public override DataType DataTypeInfo + // { + // get { return _DataTypeInfo; } + // set { _DataTypeInfo = value; RaisePropertyChanged(); } + // } + + //} +} diff --git a/CapMachine.Wpf/Models/Tag/TagHelper.cs b/CapMachine.Wpf/Models/Tag/TagHelper.cs new file mode 100644 index 0000000..ed0c5d7 --- /dev/null +++ b/CapMachine.Wpf/Models/Tag/TagHelper.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CapMachine.Wpf.Models.Tag +{ + /// + /// 标签帮助类 + /// + public class TagHelper + { + private void ParseData(List tagInfos) + { + //分组数据 + var GroupData = tagInfos.GroupBy(x => x.DataTypeInfo).ToList(); + foreach (var group in GroupData) + { + var key = group.Key; + var TagListData = group.ToList(); + switch (group.Key) + { + case ComEnum.DataType.Short: + + break; + case ComEnum.DataType.Double: + + break; + case ComEnum.DataType.String: + + break; + case ComEnum.DataType.Byte: + + break; + default: + break; + } + } + } + + + } +} diff --git a/CapMachine.Wpf/Models/Tag/TagInfo.cs b/CapMachine.Wpf/Models/Tag/TagInfo.cs new file mode 100644 index 0000000..0167d5e --- /dev/null +++ b/CapMachine.Wpf/Models/Tag/TagInfo.cs @@ -0,0 +1,93 @@ +using Prism.Mvvm; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static CapMachine.Wpf.Models.ComEnum; + +namespace CapMachine.Wpf.Models.Tag +{ + /// + /// 标签的信息 + /// + public abstract class TagInfo : BindableBase + { + /// + /// 实例化函数 + /// + /// + /// + /// + public TagInfo(string name,string enName, string unit,TagType tagType) + { + TagTypeInfo = tagType; + Name = name; + Unit = unit; + EnName = enName; + + //ListRtDataModel=new List(); + } + + + //public List ListRtDataModel { get; set; } + + /// + /// 名称 中文 + /// + public string Name { get; set; } + + /// + /// 名称 英文 + /// + public string EnName { get; set; } + + /// + /// 标签类型信息 + /// + public TagType TagTypeInfo { get; set; } + + /// + /// 数据类型信息 + /// + public DataType DataTypeInfo { get; set; } + + /// + /// 地址信息 + /// + public string Address { get; set; } + + /// + /// 地址信息 Index + /// + public string Index { get; set; } + + /// + /// 最大值 + /// + public double MaxValue { get; set; } + + /// + /// 最小值 + /// + public double MinValue { get; set; } + + /// + /// 精度 + /// 小数点 + /// + public short Precision { get; set; } + + /// + /// 单位 + /// + public string? Unit { get; set; } + + /// + /// 采样周期 + /// + public int SamplingPeriod { get; set; } + + + } +} diff --git a/CapMachine.Wpf/Models/Tag/TagManager.cs b/CapMachine.Wpf/Models/Tag/TagManager.cs new file mode 100644 index 0000000..354a69b --- /dev/null +++ b/CapMachine.Wpf/Models/Tag/TagManager.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CapMachine.Wpf.Models.Tag +{ + /// + /// 标签管理中心 + /// + public class TagManager + { + public TagManager() + { + + } + + /// + /// 标签集合数据 + /// + public List ListTag = new List(); + + ///// + ///// 增加标签 + ///// + //public void AddTag(BaseTag baseTag) + //{ + // ListTag.Add(baseTag); + //} + + ///// + ///// 增加集合标签 + ///// + ///// + //public void AddRange(List> baseTags) + //{ + // ListTag.AddRange(baseTags); + //} + + } +} diff --git a/CapMachine.Wpf/Models/Tag/VarTag.cs b/CapMachine.Wpf/Models/Tag/VarTag.cs new file mode 100644 index 0000000..bb9f796 --- /dev/null +++ b/CapMachine.Wpf/Models/Tag/VarTag.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static CapMachine.Wpf.Models.ComEnum; + +namespace CapMachine.Wpf.Models.Tag +{ + ///// + ///// 一般的处理方法 + ///// + ///// + //public class VarTag : BaseTag + //{ + // public VarTag(string name, string enName, string unit, ComEnum.TagType tagType) : base(name, enName, unit, tagType) + // { + + // } + + // private object _RtValue; + // /// + // /// 实时值 + // /// + // public override object RtValue + // { + // get { return _RtValue; } + // set { _RtValue = (T)Convert.ChangeType(value, typeof(T)); RaisePropertyChanged(); } + // } + + + // private DataType _DataTypeInfo; + // /// + // /// 数据类型信息 + // /// + // public override DataType DataTypeInfo + // { + // get { return _DataTypeInfo; } + // set { _DataTypeInfo = value; RaisePropertyChanged(); } + // } + //} +} diff --git a/CapMachine.Wpf/ProPars/ProParsHelper.cs b/CapMachine.Wpf/ProPars/ProParsHelper.cs new file mode 100644 index 0000000..56a5cb7 --- /dev/null +++ b/CapMachine.Wpf/ProPars/ProParsHelper.cs @@ -0,0 +1,2103 @@ +using CapMachine.Model; +using CapMachine.Model.MeterConfig; +using HslCommunication.Profinet.Siemens; +using SharpDX; +using System.Windows.Controls; + +namespace CapMachine.Wpf.ProPars +{ + /// + /// 程序解析方法 + /// + public class ProParsHelper + { + + /// + /// 获取PLC步骤信息 + /// + /// + /// + public static List GetPlcParsData(List proSteps, int Cycle) + { + //取得的PLC步骤数据,提前预设好 + List ListPlcParsData = new List() + { + new PlcParsData(){ Name="速度",EnName="Speed",Steps=new List(),Ratio=1,Unit="",ValueStartAddress=1006,MinStartAddress=1000,SecStartAddress=1002,CycleStartAddress=1004 }, + new PlcParsData(){ Name="COND1温度 ",EnName="Cond1Temp",Steps=new List(),Ratio=1,Unit="",ValueStartAddress=1014,MinStartAddress=1068,SecStartAddress=1070,CycleStartAddress=1098 }, + new PlcParsData(){ Name="COND2温度",EnName="Cond2Temp",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1034,MinStartAddress=0,SecStartAddress=0,CycleStartAddress=0 }, + new PlcParsData(){ Name="COND2压力",EnName="Cond2Press",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1018,MinStartAddress=1076,SecStartAddress=1078,CycleStartAddress=0 }, + new PlcParsData(){ Name="EVAP出口温度",EnName="EVAPExpTemp",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1036,MinStartAddress=0,SecStartAddress=0,CycleStartAddress=0 }, + new PlcParsData(){ Name="排气压力",EnName="ExPress",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1008,MinStartAddress=1058,SecStartAddress=1058,CycleStartAddress=1092 }, + + new PlcParsData(){ Name="HV电压",EnName="HVVol",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1022,MinStartAddress=1080,SecStartAddress=1082,CycleStartAddress=0 }, + + new PlcParsData(){ Name="吸气压力",EnName="InhPress",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1010,MinStartAddress=1060,SecStartAddress=1062,CycleStartAddress=1094 }, + + new PlcParsData(){ Name="吸气温度",EnName="InhTemp",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1012,MinStartAddress=1064,SecStartAddress=1066,CycleStartAddress=1096 }, + + new PlcParsData(){ Name="润滑油压力",EnName="LubePress",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1016,MinStartAddress=1072,SecStartAddress=1074,CycleStartAddress=0 }, + + new PlcParsData(){ Name="LV电压",EnName="LVVol",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1024,MinStartAddress=0,SecStartAddress=0,CycleStartAddress=0 }, + + new PlcParsData(){ Name="OCR",EnName="OCR",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1020,MinStartAddress=0,SecStartAddress=0,CycleStartAddress=0 }, + + new PlcParsData(){ Name="OS1温度",EnName="OS1Temp",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1030,MinStartAddress=0,SecStartAddress=0,CycleStartAddress=0 }, + new PlcParsData(){ Name="OS2温度",EnName="OS2Temp",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1032,MinStartAddress=0,SecStartAddress=0,CycleStartAddress=0 }, + + new PlcParsData(){ Name="PTC入口温度",EnName="PTCEntTemp",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1054,MinStartAddress=0,SecStartAddress=0,CycleStartAddress=0 }, + new PlcParsData(){ Name="PTC流量",EnName="PTCFlow",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1052,MinStartAddress=0,SecStartAddress=0,CycleStartAddress=0 }, + new PlcParsData(){ Name="PTC功率",EnName="PTCPw",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1050,MinStartAddress=0,SecStartAddress=0,CycleStartAddress=0 }, + + new PlcParsData(){ Name="压缩机环境湿度",EnName="EnvRH",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1028,MinStartAddress=1088,SecStartAddress=1090,CycleStartAddress=0 }, + new PlcParsData(){ Name="压缩机环境温度",EnName="EnvTemp",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=1026,MinStartAddress=1084,SecStartAddress=1086,CycleStartAddress=0 }, + + new PlcParsData(){ Name="输出锁定",EnName="OutLock",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=0,MinStartAddress=0,SecStartAddress=0,CycleStartAddress=0 }, + new PlcParsData(){ Name="参数编号",EnName="ParNo",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=0,MinStartAddress=0,SecStartAddress=0,CycleStartAddress=0 }, + new PlcParsData(){ Name="EV",EnName="Ev",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=0,MinStartAddress=0,SecStartAddress=0,CycleStartAddress=0 }, + new PlcParsData(){ Name="压缩机使能",EnName="CapEnable",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=0,MinStartAddress=0,SecStartAddress=0,CycleStartAddress=0 }, + new PlcParsData(){ Name="吸排气阀",EnName="InhExhValve",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=0,MinStartAddress=0,SecStartAddress=0,CycleStartAddress=0 }, + new PlcParsData(){ Name="加热器使能",EnName="HeatEnable",Steps=new List(),Ratio=1,Unit="" ,ValueStartAddress=0,MinStartAddress=0,SecStartAddress=0,CycleStartAddress=0 }, + + //new PlcParsData(){ Name="加热器功率",EnName="HeatPw",Steps=new List(),Ratio=1,Unit="" }, + //new PlcParsData(){ Name="加热器流量",EnName="HeatFlow",Steps=new List(),Ratio=1,Unit="" }, + //new PlcParsData(){ Name="加热器入口水温",EnName="HeatInWatTemp",Steps=new List(),Ratio=1,Unit="" }, + }; + + for (int i = 0; i < Cycle; i++)//大循环 + { + foreach (ProStep proStep in proSteps)//小循环 + { + //每个步骤里面包含多个参数的设置 + ListPlcParsData = LoadPlcParsData(proStep, ListPlcParsData);//内部循环 + } + } + + //装载地址 VW1000 + ListPlcParsData = LoadPlcCellAddress(ListPlcParsData); + //var datga = LoadPlcBlockAddress(ListPlcParsData, 1000); + + return ListPlcParsData; + } + + + /// + /// 加载数据到PLC + /// + public static void LoadDataToPLC(SiemensS7Net siemensS7NetStance, List plcParsDatas) + { + foreach (var item in plcParsDatas) + { + foreach (var itemStep in item.Steps) + { + if (!string.IsNullOrEmpty(itemStep.ValueAddress)) + { + var Result = siemensS7NetStance.Write(itemStep.ValueAddress, (short)itemStep.Value); + if (!Result.IsSuccess) + { + var data1 = 1; + } + } + if (!string.IsNullOrEmpty(itemStep.MinAddress)) + { + var Result = siemensS7NetStance.Write(itemStep.MinAddress, (short)itemStep.TimeMin); + if (!Result.IsSuccess) + { + var data1 = 1; + } + } + if (!string.IsNullOrEmpty(itemStep.SecAddress)) + { + var Result = siemensS7NetStance.Write(itemStep.SecAddress, (short)itemStep.TimeSec); + if (!Result.IsSuccess) + { + var data1 = 1; + } + } + if (!string.IsNullOrEmpty(itemStep.CycleAddress)) + { + var Result = siemensS7NetStance.Write(itemStep.CycleAddress, (short)itemStep.Cycle); + if (!Result.IsSuccess) + { + var data1 = 1; + } + } + } + } + + var data = 1; + //siemensS7NetStance.Write(); + } + + /// + /// 单步骤程序解析 + /// 单步骤里面包括多个仪表参数的配置信息 + /// + /// + /// + /// + private static List LoadPlcParsData(ProStep proStep, List plcParsDatas) + { + if (proStep != null && proStep.MeterSpeeds != null) + { + //速度 + GetStepsByMeterSpeeds(proStep.MeterSpeeds, plcParsDatas.Find(a => a.EnName == "Speed")!, proStep.SpeedCycle); + //跟速度绑定的数据 + + GetStepsByMeterCond1Temps(proStep.MeterCond1Temps, plcParsDatas.Find(a => a.EnName == "Cond1Temp")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterCond1Temps!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterCond2Temps(proStep.MeterCond2Temps, plcParsDatas.Find(a => a.EnName == "Cond2Temp")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterCond2Temps!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterCond2Presss(proStep.MeterCond2Presss, plcParsDatas.Find(a => a.EnName == "Cond2Press")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterCond2Presss!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterEVAPExpTemps(proStep.MeterEVAPExpTemps, plcParsDatas.Find(a => a.EnName == "EVAPExpTemp")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterEVAPExpTemps!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterExPresss(proStep.MeterExPresss, plcParsDatas.Find(a => a.EnName == "ExPress")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterExPresss!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterHVVols(proStep.MeterHVVols, plcParsDatas.Find(a => a.EnName == "HVVol")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterHVVols!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterInhPresss(proStep.MeterInhPresss, plcParsDatas.Find(a => a.EnName == "InhPress")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterInhPresss!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterInhTemps(proStep.MeterInhTemps, plcParsDatas.Find(a => a.EnName == "InhTemp")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterInhTemps!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterLubePresss(proStep.MeterLubePresss, plcParsDatas.Find(a => a.EnName == "LubePress")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterLubePresss!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterLVVols(proStep.MeterLVVols, plcParsDatas.Find(a => a.EnName == "LVVol")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterLVVols!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterOCRs(proStep.MeterOCRs, plcParsDatas.Find(a => a.EnName == "OCR")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterOCRs!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterOS1Temps(proStep.MeterOS1Temps, plcParsDatas.Find(a => a.EnName == "OS1Temp")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterOS1Temps!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterOS2Temps(proStep.MeterOS2Temps, plcParsDatas.Find(a => a.EnName == "OS2Temp")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterOS2Temps!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterPTCEntTemps(proStep.MeterPTCEntTemps, plcParsDatas.Find(a => a.EnName == "PTCEntTemp")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterPTCEntTemps!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterPTCFlows(proStep.MeterPTCFlows, plcParsDatas.Find(a => a.EnName == "PTCFlow")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterPTCFlows!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterPTCPws(proStep.MeterPTCPws, plcParsDatas.Find(a => a.EnName == "PTCPw")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterPTCPws!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterEnvRHs(proStep.MeterEnvRHs, plcParsDatas.Find(a => a.EnName == "EnvRH")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterEnvRHs!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + GetStepsByMeterEnvTemps(proStep.MeterEnvTemps, plcParsDatas.Find(a => a.EnName == "EnvTemp")!, + GetCycleBySpeed(proStep.MeterSpeeds, proStep.SpeedCycle, proStep.MeterEnvTemps!.Select(p => new MeterCom { Constant = p.Constant, EndValue = p.EndValue, KeepTime = p.KeepTime, StartValue = p.StartValue, StepNo = p.StepNo, ValueType = p.ValueType }).ToList())); + + + return plcParsDatas; + } + return plcParsDatas; + } + + /// + /// 根据速度表时间获取循环的次数 + /// + /// + /// + private static int GetCycleBySpeed(List meterSpeeds, int SpeedCycle, List meterComs) + { + if (meterComs != null && meterComs.Count > 0) + { + if (meterComs.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + if (meterSpeeds != null && meterSpeeds.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var TotalTime = meterSpeeds.Sum(a => a.KeepTime) * SpeedCycle; + var MeterSlopTime = meterComs.Sum(a => a.KeepTime); + if (MeterSlopTime != 0) + { + return TotalTime / MeterSlopTime; + } + else + { + return 0; + } + } + else + { + //速度是常值 + var TotalTime = meterSpeeds.FirstOrDefault()!.KeepTime; + var MeterSlopTime = meterComs.Sum(a => a.KeepTime); + if (MeterSlopTime != 0) + { + return TotalTime / MeterSlopTime; + } + else + { + return 0; + } + } + } + else + { + // meterComs 常值 就一步了,没有循环 + return 0; + } + } + else + { + return 0; + } + + } + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 Speed + /// + /// + /// + private static PlcParsData GetStepsByMeterSpeeds(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterSpeedsOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterSpeedsOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 Cond1Temp + /// + /// + /// + private static PlcParsData GetStepsByMeterCond1Temps(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterCond1TempsOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterCond1TempsOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 Cond2Temp + /// + /// + /// + private static PlcParsData GetStepsByMeterCond2Temps(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterCond2TempsOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterCond2TempsOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 Cond2Press + /// + /// + /// + private static PlcParsData GetStepsByMeterCond2Presss(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterCond2PresssOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterCond2PresssOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 EVAPExpTemp + /// + /// + /// + private static PlcParsData GetStepsByMeterEVAPExpTemps(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterEVAPExpTempsOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterEVAPExpTempsOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 ExPress + /// + /// + /// + private static PlcParsData GetStepsByMeterExPresss(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterExPresssOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterExPresssOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 HVVol + /// + /// + /// + private static PlcParsData GetStepsByMeterHVVols(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterHVVolsOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterHVVolsOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 InhPress + /// + /// + /// + private static PlcParsData GetStepsByMeterInhPresss(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterInhPresssOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterInhPresssOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 InhTemp + /// + /// + /// + private static PlcParsData GetStepsByMeterInhTemps(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterInhTempsOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterInhTempsOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 LubePress + /// + /// + /// + private static PlcParsData GetStepsByMeterLubePresss(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterLubePresssOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterLubePresssOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 LVVol + /// + /// + /// + private static PlcParsData GetStepsByMeterLVVols(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterLVVolsOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterLVVolsOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 OCR + /// + /// + /// + private static PlcParsData GetStepsByMeterOCRs(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterOCRsOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterOCRsOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 OS1Temp + /// + /// + /// + private static PlcParsData GetStepsByMeterOS1Temps(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterOS1TempsOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterOS1TempsOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 OS2Temp + /// + /// + /// + private static PlcParsData GetStepsByMeterOS2Temps(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterOS2TempsOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterOS2TempsOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 PTCEntTemp + /// + /// + /// + private static PlcParsData GetStepsByMeterPTCEntTemps(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterPTCEntTempsOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterPTCEntTempsOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 PTCFlow + /// + /// + /// + private static PlcParsData GetStepsByMeterPTCFlows(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterPTCFlowsOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterPTCFlowsOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 PTCPw + /// + /// + /// + private static PlcParsData GetStepsByMeterPTCPws(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterPTCPwsOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterPTCPwsOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 EnvRH + /// + /// + /// + private static PlcParsData GetStepsByMeterEnvRHs(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterEnvRHsOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterEnvRHsOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + /// + /// 单步(内部多个小步骤)解析 单个仪表参数 + /// 获取 步骤信息 EnvTemp + /// + /// + /// + private static PlcParsData GetStepsByMeterEnvTemps(ICollection? MeterDatas, PlcParsData PLCParsData, int Cycle) + { + if (MeterDatas != null && MeterDatas.Count > 0) + { + if (MeterDatas.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + //排序 + var MeterEnvTempsOrder = MeterDatas.OrderBy(a => a.StepNo).ToList(); + var ListCount = MeterDatas.Count; + var Index = 0; + + foreach (var item in MeterEnvTempsOrder) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = item.EndValue; + plcMeterStepCell.TimeMin = GetKeepTimeMin(item.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(item.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = GetCycleCount(Cycle, Index, ListCount); + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + Index++; + } + + return PLCParsData; + } + else//常值 + { + var Data = MeterDatas.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + if (Data != null) + { + PlcMeterStepCell plcMeterStepCell = new PlcMeterStepCell(); + + plcMeterStepCell.Value = Data.Constant; + plcMeterStepCell.TimeMin = GetKeepTimeMin(Data.KeepTime); + plcMeterStepCell.TimeSec = GetKeepTimeSec(Data.KeepTime); + plcMeterStepCell.Step = GetStep(PLCParsData); + plcMeterStepCell.Cycle = 0; + + //增加步骤信息 + PLCParsData.Steps.Add(plcMeterStepCell); + + return PLCParsData; + } + + return PLCParsData; + } + } + else + { + return PLCParsData; + } + + } + + + + + + + + + + + /// + /// 获取KeepTime分钟信息 + /// + /// + private static int GetKeepTimeMin(int keeptime) + { + return keeptime / 60; + } + + /// + /// 获取KeepTime 秒信息 + /// + /// + private static int GetKeepTimeSec(int keeptime) + { + return keeptime % 60; + } + + + /// + /// 获取步骤信息 + /// + /// + /// + /// + private static int GetStep(PlcParsData plcParsData) + { + if (plcParsData.Steps != null && plcParsData.Steps.Any()) + { + return plcParsData.Steps.Count + 1; + } + else + { + return 1; + } + } + + + + /// + /// 获取Cycle信息 + /// + /// + private static int GetCycleCount(int Cycle, int Index, int ListCount) + { + if (ListCount > 1) + { + //步骤ProStep内部有循环 + if (Index == 0) + { + //循环开始 + return -1; + } + if (ListCount == Index + 1) + { + //循环结束 + return Cycle; + } + //循环中间 + return 0; + } + else + { + //步骤ProStep内部就一个步序,没有循环,则直接返回步骤的Cycle + //单步骤,没有循环 + return 0; + } + } + + /// + /// 加载PLC的地址 + /// 单元分割 + /// + /// + private static List LoadPlcCellAddress(List plcParsDatas) + { + //单步长度 + int StepLengh = 100; + + foreach (var itemMeter in plcParsDatas) + { + //var Stepaddress = StartAddress + Index * StepLengh; + + //循环Index + int Index = 0; + + //循环内部的步骤信息 + foreach (var itemStep in itemMeter.Steps.OrderBy(a => a.Step)) + { + if (itemMeter.ValueStartAddress != 0) + { + var StepValueAddress = itemMeter.ValueStartAddress + Index * StepLengh; + itemStep.ValueAddress = "V" + StepValueAddress; + } + if (itemMeter.MinStartAddress != 0) + { + var StepMinAddress = itemMeter.MinStartAddress + Index * StepLengh; + itemStep.MinAddress = "V" + StepMinAddress; + } + if (itemMeter.SecStartAddress != 0) + { + var StepSecAddress = itemMeter.SecStartAddress + Index * StepLengh; + itemStep.SecAddress = "V" + StepSecAddress; + } + if (itemMeter.CycleStartAddress != 0) + { + var StepCycleAddress = itemMeter.CycleStartAddress + Index * StepLengh; + itemStep.CycleAddress = "V" + StepCycleAddress; + } + + Index++; + } + + } + + return plcParsDatas; + } + + /// + /// 加载PLC块地址信息 + /// + /// + /// + /// + private static List LoadPlcBlockAddress(List plcParsDatas, int start) + { + //开始地址 + int StartAddress = start; + //单步长度 + int StepLengh = 100; + //循环Index + int Index = 0; + //数据集合 + List BlockDatas = new List(); + + foreach (var item in plcParsDatas) + { + var StepAddress = StartAddress + Index * StepLengh; + + //每个步骤封装成一个PlcBlockData + short[] shorts = new short[19];//看有多少个字段 + //shorts[item.Speed!.Index - 1] = (short)item.Speed!.Value!; + //shorts[item.Cond1Temp!.Index - 1] = (short)item.Cond1Temp!.Value!; + //shorts[item.Cond2Temp!.Index - 1] = (short)item.Cond2Temp!.Value!; + //shorts[item.CondPress!.Index - 1] = (short)item.CondPress!.Value!; + //shorts[item.EVAPExpTemp!.Index - 1] = (short)item.EVAPExpTemp!.Value!; + //shorts[item.ExPress!.Index - 1] = (short)item.ExPress!.Value!; + //shorts[item.HVVol!.Index - 1] = (short)item.HVVol!.Value!; + //shorts[item.InhPress!.Index - 1] = (short)item.InhPress!.Value!; + //shorts[item.InhTemp!.Index - 1] = (short)item.InhTemp!.Value!; + //shorts[item.LoPress!.Index - 1] = (short)item.LoPress!.Value!; + //shorts[item.LVVol!.Index - 1] = (short)item.LVVol!.Value!; + //shorts[item.OCR!.Index - 1] = (short)item.OCR!.Value!; + //shorts[item.OS1Temp!.Index - 1] = (short)item.OS1Temp!.Value!; + //shorts[item.OS2Temp!.Index - 1] = (short)item.OS2Temp!.Value!; + //shorts[item.PTCEntTemp!.Index - 1] = (short)item.PTCEntTemp!.Value!; + //shorts[item.PTCFlow!.Index - 1] = (short)item.PTCFlow!.Value!; + //shorts[item.PTCPw!.Index - 1] = (short)item.PTCPw!.Value!; + //shorts[item.TestBoxRH!.Index - 1] = (short)item.TestBoxRH!.Value!; + //shorts[item.TestBoxTemp!.Index - 1] = (short)item.TestBoxTemp!.Value!; + + BlockDatas.Add(new PlcBlockData() + { + StartAddress = "VW" + StepAddress.ToString(), + ArrValue = shorts + }); + + Index++; + } + + return BlockDatas; + } + + /// + /// 根据名称获取Index信息 + /// + /// + public static int GetIndexByName(DataGridColumn dataGridColumn) + { + var headerText = (dataGridColumn.Header as TextBlock).Text; + if (headerText.Contains("COND1温度 ")) + { + return 0; + } + else if (headerText.Contains("COND2温度")) + { + return 1; + } + else if (headerText.Contains("COND2压力")) + { + return 2; + } + else if (headerText.Contains("EVAP出口温度")) + { + return 3; + } + else if (headerText.Contains("排气压力")) + { + return 4; + } + else if (headerText.Contains("HV电压")) + { + return 5; + } + else if (headerText.Contains("吸气压力")) + { + return 6; + } + else if (headerText.Contains("吸气温度")) + { + return 7; + } + else if (headerText.Contains("润滑油压力")) + { + return 8; + } + else if (headerText.Contains("LV电压")) + { + return 9; + } + else if (headerText.Contains("OCR")) + { + return 10; + } + else if (headerText.Contains("OS1温度")) + { + return 11; + } + else if (headerText.Contains("OS2温度")) + { + return 12; + } + else if (headerText.Contains("PTC入口温度")) + { + return 13; + } + else if (headerText.Contains("PTC流量")) + { + return 14; + } + else if (headerText.Contains("PTC功率")) + { + return 15; + } + else if (headerText.Contains("试验箱湿度")) + { + return 16; + } + else if (headerText.Contains("试验箱温度")) + { + return 17; + } + else + { + return 0; + } + } + + + #region 获取数据 + + /// + /// 获取 MeterCellByMeterCond1Temps + /// + /// + private static double GetMeterCellByMeterCond1Temps(ICollection meterCond1Temps, int Index) + { + try + { + if (meterCond1Temps.Count() >= (Index + 1)) + { + return meterCond1Temps.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterCond1Temps.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterCond2Temps + /// + /// + private static double GetMeterCellByMeterCond2Temps(ICollection meterCond2Temps, int Index) + { + try + { + if (meterCond2Temps.Count() >= (Index + 1)) + { + return meterCond2Temps.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterCond2Temps.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterCondPresss + /// + /// + private static double GetMeterCellByMeterCondPresss(ICollection meterCondPresss, int Index) + { + try + { + if (meterCondPresss.Count() >= (Index + 1)) + { + return meterCondPresss.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterCondPresss.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterEVAPExpTemps + /// + /// + private static double GetMeterCellByMeterEVAPExpTemps(ICollection meterEVAPExpTemps, int Index) + { + try + { + if (meterEVAPExpTemps.Count() >= (Index + 1)) + { + return meterEVAPExpTemps.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterEVAPExpTemps.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterExPresss + /// + /// + private static double GetMeterCellByMeterExPresss(ICollection meterExPresss, int Index) + { + try + { + if (meterExPresss.Count() >= (Index + 1)) + { + return meterExPresss.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterExPresss.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterHVVols + /// + /// + private static double GetMeterCellByMeterHVVols(ICollection meterHVVols, int Index) + { + try + { + if (meterHVVols.Count() >= (Index + 1)) + { + return meterHVVols.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterHVVols.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterInhPresss + /// + /// + private static double GetMeterCellByMeterInhPresss(ICollection meterInhPresss, int Index) + { + try + { + if (meterInhPresss.Count() >= (Index + 1)) + { + return meterInhPresss.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterInhPresss.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterInhTemps + /// + /// + private static double GetMeterCellByMeterInhTemps(ICollection meterInhTemps, int Index) + { + try + { + if (meterInhTemps.Count() >= (Index + 1)) + { + return meterInhTemps.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterInhTemps.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterLoPresss + /// + /// + private static double GetMeterCellByMeterLoPresss(ICollection meterLoPresss, int Index) + { + try + { + if (meterLoPresss.Count() >= (Index + 1)) + { + return meterLoPresss.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterLoPresss.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterLVVols + /// + /// + private static double GetMeterCellByMeterLVVols(ICollection meterLVVols, int Index) + { + try + { + if (meterLVVols.Count() >= (Index + 1)) + { + return meterLVVols.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterLVVols.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterOCRs + /// + /// + private static double GetMeterCellByMeterOCRs(ICollection meterOCRs, int Index) + { + try + { + if (meterOCRs.Count() >= (Index + 1)) + { + return meterOCRs.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterOCRs.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterOS1Temps + /// + /// + private static double GetMeterCellByMeterOS1Temps(ICollection meterOS1Temps, int Index) + { + try + { + if (meterOS1Temps.Count() >= (Index + 1)) + { + return meterOS1Temps.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterOS1Temps.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterOS2Temps + /// + /// + private static double GetMeterCellByMeterOS2Temps(ICollection meterOS2Temps, int Index) + { + try + { + if (meterOS2Temps.Count() >= (Index + 1)) + { + return meterOS2Temps.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterOS2Temps.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterPTCEntTemps + /// + /// + private static double GetMeterCellByMeterPTCEntTemps(ICollection meterPTCEntTemps, int Index) + { + try + { + if (meterPTCEntTemps.Count() >= (Index + 1)) + { + return meterPTCEntTemps.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterPTCEntTemps.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterPTCFlows + /// + /// + private static double GetMeterCellByMeterPTCFlows(ICollection meterPTCFlows, int Index) + { + try + { + if (meterPTCFlows.Count() >= (Index + 1)) + { + return meterPTCFlows.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterPTCFlows.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterPTCPws + /// + /// + private static double GetMeterCellByMeterPTCPws(ICollection meterPTCPws, int Index) + { + try + { + if (meterPTCPws.Count() >= (Index + 1)) + { + return meterPTCPws.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterPTCPws.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterTestBoxRHs + /// + /// + private static double GetMeterCellByMeterTestBoxRHs(ICollection meterTestBoxRHs, int Index) + { + try + { + if (meterTestBoxRHs.Count() >= (Index + 1)) + { + return meterTestBoxRHs.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterTestBoxRHs.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + /// + /// 获取 MeterCellByMeterTestBoxTemps + /// + /// + private static double GetMeterCellByMeterTestBoxTemps(ICollection meterTestBoxTemps, int Index) + { + try + { + if (meterTestBoxTemps.Count() >= (Index + 1)) + { + return meterTestBoxTemps.ToList()[Index].EndValue; + } + //找不到的话,则返回第一个值 + return meterTestBoxTemps.FirstOrDefault()!.EndValue; + } + catch (Exception ex) + { + return 0.0; + } + } + + #endregion + + } +} diff --git a/CapMachine.Wpf/Services/MachineRtDataService.cs b/CapMachine.Wpf/Services/MachineRtDataService.cs index fd860c2..af05c1a 100644 --- a/CapMachine.Wpf/Services/MachineRtDataService.cs +++ b/CapMachine.Wpf/Services/MachineRtDataService.cs @@ -1,7 +1,12 @@ using AutoMapper.Internal; +using CapMachine.Core; using CapMachine.Wpf.Models; +using CapMachine.Wpf.Models.Tag; using CapMachine.Wpf.PrismEvent; +using HslCommunication; +using HslCommunication.Profinet.Siemens; using Microsoft.Extensions.Caching.Memory; +using NPOI.SS.Formula.Atp; using Prism.Events; using Prism.Mvvm; using System; @@ -11,6 +16,8 @@ using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows; +using static CapMachine.Wpf.Models.ComEnum; namespace CapMachine.Wpf.Services { @@ -24,16 +31,41 @@ namespace CapMachine.Wpf.Services /// private IEventAggregator _EventAggregator { get; set; } + /// + /// PLCScanTask扫描Task + /// + private static Task PLCScanTask { get; set; } + /// /// ScanTask扫描Task /// - static Task ScanTask { get; set; } + private static Task ScanTask { get; set; } + + /// + /// 西门子连接驱动程序 + /// + public SiemensS7Net SiemensDrive { get; set; } + + /// + /// PLC连接状态 + /// + public bool SiemensS7LinkState { get; set; } /// /// 仪表数据集合 /// public List ListMeterRtData { get; set; } + ///// + ///// Tag数据集合 + ///// + //public List ListRtDataModel { get; set; } + + /// + /// 标签管理中心 + /// + public TagManager TagManger { get; set; } = new TagManager(); + /// /// 扫描线程使能 /// @@ -52,8 +84,6 @@ namespace CapMachine.Wpf.Services { //ConcurrentDictionary keyValuePairs = new ConcurrentDictionary(); - - //Stopwatch stopwatch = new Stopwatch(); ////第一次计时 //stopwatch.Start(); //启动Stopwatch @@ -80,126 +110,266 @@ namespace CapMachine.Wpf.Services //事件服务 _EventAggregator = eventAggregator; + //TagManger.AddTag(new ByteTag("转速", "Speed", "rpm", ComEnum.TagType.Tag)); + + //dynamic dad=10; + + //TagManger.AddRange(new List() + //{ + // new ByteTag("转速","Speed","rpm",ComEnum.TagType.Tag, (byte)10), + // new ShortTag("排气压力","ExPress","BarA",ComEnum.TagType.Tag), + // new ShortTag("吸气压力","InhPress","BarA",ComEnum.TagType.Tag), + // new ShortTag("吸气温度","InhTemp","℃",ComEnum.TagType.Tag), + // new ShortTag("COND1温度","Cond1Temp","℃",ComEnum.TagType.Tag), + // new ShortTag("润滑油压力","LubePress","BarA",ComEnum.TagType.Tag), + // new ShortTag("COND2压力","Cond2Press","BarA",ComEnum.TagType.Tag), + // new ShortTag("OCR","OCR","%",ComEnum.TagType.Tag), + // new ShortTag("HV","HV","V",ComEnum.TagType.Tag), + // new ShortTag("HV","HVCur","A",ComEnum.TagType.Tag), + // new ShortTag("HV","HV","W",ComEnum.TagType.Tag), + // new ShortTag("LV","LV","V",ComEnum.TagType.Tag), + // new ShortTag("LV","LVCur","A",ComEnum.TagType.Tag), + // new ShortTag("环境温度","EnvTemp","℃",ComEnum.TagType.Tag), + // new ShortTag("环境湿度","EnvRH","%",ComEnum.TagType.Tag), + // new ShortTag("OS1温度","OS1Temp","℃",ComEnum.TagType.Tag), + // new ShortTag("OS2温度","OS2Temp","℃",ComEnum.TagType.Tag), + // new ShortTag("COND2温度","Cond2Temp","℃",ComEnum.TagType.Tag), + // new ShortTag("EVAP出口温度","EVAPExpTemp","℃",ComEnum.TagType.Tag), + // new ShortTag("冷媒流量","VRV","L/min",ComEnum.TagType.Tag), + // new ShortTag("润滑油流量","LubeFlow","L/min",ComEnum.TagType.Tag), + // new ShortTag("排气温度","ExTemp","℃",ComEnum.TagType.Tag), + // new ShortTag("膨胀阀前压力","TxvFrPress","BarA",ComEnum.TagType.Tag), + // new ShortTag("膨胀阀前温度","TxvFrTemp","℃",ComEnum.TagType.Tag), + // new ShortTag("EVAP出口压力","EVAPExpPress","BarA",ComEnum.TagType.Tag), + // new ShortTag("腔内压力","IntrplPress","BarA",ComEnum.TagType.Tag), + // new ShortTag("压缩机表面温度","CapSurfTemp","℃",ComEnum.TagType.Tag), + // new ShortTag("PTC流量","PTCFlow","L/min",ComEnum.TagType.Tag), + // new ShortTag("PTC入水温度","PTCEntTemp","℃",ComEnum.TagType.Tag), + // new ShortTag("PTC出水温度","PTCExpTemp","℃",ComEnum.TagType.Tag), + // new ShortTag("通讯Cmp母线电流","ComCapBusCur","A",ComEnum.TagType.Tag), + // new ShortTag("通讯Cmp母线电压","ComCapBusVol","V",ComEnum.TagType.Tag), + // new ShortTag("通讯Cmp逆变器温度","ComCapInvTemp","℃",ComEnum.TagType.Tag), + // new ShortTag("通讯Cmp相电流","ComCapPhCur","A",ComEnum.TagType.Tag), + // new ShortTag("通讯Cmp功率","ComCapPw","W",ComEnum.TagType.Tag), + // new ShortTag("通讯Cmp芯片温度","ComCapChipTemp","℃",ComEnum.TagType.Tag), + // new ShortTag("通讯PTC入水温度","ComPTCEntTemp","℃",ComEnum.TagType.Tag), + // new ShortTag("通讯PTC出水温度","ComPTCExpTemp","℃",ComEnum.TagType.Tag), + // new ShortTag("通讯PTC峰值电流","ComPTCPeakCur","A",ComEnum.TagType.Tag), + // new ShortTag("通讯PTC母线电流","ComPTCBusCur","A",ComEnum.TagType.Tag), + // new ShortTag("通讯PTC膜温","ComPTCFlmTemp","℃",ComEnum.TagType.Tag), + // new ShortTag("通讯PTC模块温度","ComPTCMdTemp","℃",ComEnum.TagType.Tag), + //}); + + + #region ListMeterRtData实例化 //实例化集合 - ListMeterRtData = new List() - { - new MeterRtDataModel(){ - MeterName = "EVA风量", - RtUIControlTitle="EVA风量" + Environment.NewLine + "m³/h", - RtUIControlTitleIndex="Title5", - Station = 1, - RtAddressPV = "101", - RtAddressMV = "105", - RtMVUIControlIndex="MV5", - RtSVUIControlIndex="SV5", - RtPVUIControlIndex="PV5", - MaxValue=500, - MinValue=0, - Accuracy=1, - Unit="m³/h", - MeterEnableStatePLCAddress="V30.3", - }, - new MeterRtDataModel(){//目前是DB表 - MeterName = "中间轴转速",//原来中间轴转速,先全部改为电机转速-开发过程中某个时刻中间轴转速改为电机转速 - RtUIControlTitle="中间轴转速" + Environment.NewLine + "(r/min)", - RtUIControlTitleIndex="Title3", - Station = 2, - RtAddressPV = "101", - RtAddressMV = "105", - RtMVUIControlIndex="MV3", - RtSVUIControlIndex="SV3", - RtPVUIControlIndex="PV3", - MaxValue=4000, - MinValue=0, - Accuracy=0, - Unit="(r/min)", - MeterEnableStatePLCAddress="", - }, - new MeterRtDataModel(){ - MeterName = "加热电力",//加热电力 - RtUIControlTitle="加热电力" + Environment.NewLine + "(KW)", - RtUIControlTitleIndex="Title7", - Station = 3, - RtAddressPV = "101", - RtAddressMV = "105", - RtMVUIControlIndex="MV7", - RtSVUIControlIndex="SV7", - RtPVUIControlIndex="PV7", - MaxValue=30, - MinValue=0, - Accuracy=2, - Unit="(KW)", - MeterEnableStatePLCAddress="V30.4", - }, - new MeterRtDataModel(){ - MeterName = "加湿电力", - RtUIControlTitle="加湿电力" + Environment.NewLine + "(KW)", - RtUIControlTitleIndex="Title8", - Station = 4, - RtAddressPV = "101", - RtAddressMV = "105", - RtMVUIControlIndex="MV8", - RtSVUIControlIndex="SV8", - RtPVUIControlIndex="PV8", - MaxValue=18, - MinValue=0, - Accuracy=2, - Unit="(KW)", - MeterEnableStatePLCAddress="V30.5", - }, - new MeterRtDataModel(){//目前是DB表 - MeterName = "EMPCV电流",//EMPCV电力 - RtUIControlTitle="EMPCV电流" + Environment.NewLine + "(A)", - RtUIControlTitleIndex="Title9", - Station = 5, - RtAddressPV = "101", - RtAddressMV = "105", - RtMVUIControlIndex="MV9", - RtSVUIControlIndex="SV9", - RtPVUIControlIndex="PV9", - MaxValue=1, - MinValue=0, - Accuracy=2, - Unit="(A)", - MeterEnableStatePLCAddress="V30.6", - }, - new MeterRtDataModel(){ - MeterName = "INJ压力", - RtUIControlTitle="INJ压力" + Environment.NewLine + "(MPa)", - RtUIControlTitleIndex="Title10", - Station = 6, - RtAddressPV = "101", - RtAddressMV = "105", - RtMVUIControlIndex="MV10", - RtSVUIControlIndex="SV10", - RtPVUIControlIndex="PV10", - MaxValue=5, - MinValue=0, - Accuracy=3, - Unit="(MPa)", - MeterEnableStatePLCAddress="V30.7", - }, - new MeterRtDataModel(){ - MeterName = "冷媒流量", - RtUIControlTitle="冷媒流量" + Environment.NewLine + "(kg/h)", - RtUIControlTitleIndex="Title11", - Station = 7, - RtAddressPV = "101", - RtAddressMV = "105", - RtMVUIControlIndex="MV11", - RtSVUIControlIndex="SV11", - RtPVUIControlIndex="PV11", - MaxValue=500, - MinValue=0, - Accuracy=1, - Unit="(kg/h)", - MeterEnableStatePLCAddress="V31.0", - }, - }; + //ListMeterRtData = new List() + //{ + // new MeterRtDataModel(){ + // MeterName = "EVA风量", + // RtUIControlTitle="EVA风量" + Environment.NewLine + "m³/h", + // RtUIControlTitleIndex="Title5", + // Station = 1, + // RtAddressPV = "101", + // RtAddressMV = "105", + // RtMVUIControlIndex="MV5", + // RtSVUIControlIndex="SV5", + // RtPVUIControlIndex="PV5", + // MaxValue=500, + // MinValue=0, + // Accuracy=1, + // Unit="m³/h", + // MeterEnableStatePLCAddress="V30.3", + // }, + // new MeterRtDataModel(){//目前是DB表 + // MeterName = "中间轴转速",//原来中间轴转速,先全部改为电机转速-开发过程中某个时刻中间轴转速改为电机转速 + // RtUIControlTitle="中间轴转速" + Environment.NewLine + "(r/min)", + // RtUIControlTitleIndex="Title3", + // Station = 2, + // RtAddressPV = "101", + // RtAddressMV = "105", + // RtMVUIControlIndex="MV3", + // RtSVUIControlIndex="SV3", + // RtPVUIControlIndex="PV3", + // MaxValue=4000, + // MinValue=0, + // Accuracy=0, + // Unit="(r/min)", + // MeterEnableStatePLCAddress="", + // }, + // new MeterRtDataModel(){ + // MeterName = "加热电力",//加热电力 + // RtUIControlTitle="加热电力" + Environment.NewLine + "(KW)", + // RtUIControlTitleIndex="Title7", + // Station = 3, + // RtAddressPV = "101", + // RtAddressMV = "105", + // RtMVUIControlIndex="MV7", + // RtSVUIControlIndex="SV7", + // RtPVUIControlIndex="PV7", + // MaxValue=30, + // MinValue=0, + // Accuracy=2, + // Unit="(KW)", + // MeterEnableStatePLCAddress="V30.4", + // }, + // new MeterRtDataModel(){ + // MeterName = "加湿电力", + // RtUIControlTitle="加湿电力" + Environment.NewLine + "(KW)", + // RtUIControlTitleIndex="Title8", + // Station = 4, + // RtAddressPV = "101", + // RtAddressMV = "105", + // RtMVUIControlIndex="MV8", + // RtSVUIControlIndex="SV8", + // RtPVUIControlIndex="PV8", + // MaxValue=18, + // MinValue=0, + // Accuracy=2, + // Unit="(KW)", + // MeterEnableStatePLCAddress="V30.5", + // }, + // new MeterRtDataModel(){//目前是DB表 + // MeterName = "EMPCV电流",//EMPCV电力 + // RtUIControlTitle="EMPCV电流" + Environment.NewLine + "(A)", + // RtUIControlTitleIndex="Title9", + // Station = 5, + // RtAddressPV = "101", + // RtAddressMV = "105", + // RtMVUIControlIndex="MV9", + // RtSVUIControlIndex="SV9", + // RtPVUIControlIndex="PV9", + // MaxValue=1, + // MinValue=0, + // Accuracy=2, + // Unit="(A)", + // MeterEnableStatePLCAddress="V30.6", + // }, + // new MeterRtDataModel(){ + // MeterName = "INJ压力", + // RtUIControlTitle="INJ压力" + Environment.NewLine + "(MPa)", + // RtUIControlTitleIndex="Title10", + // Station = 6, + // RtAddressPV = "101", + // RtAddressMV = "105", + // RtMVUIControlIndex="MV10", + // RtSVUIControlIndex="SV10", + // RtPVUIControlIndex="PV10", + // MaxValue=5, + // MinValue=0, + // Accuracy=3, + // Unit="(MPa)", + // MeterEnableStatePLCAddress="V30.7", + // }, + // new MeterRtDataModel(){ + // MeterName = "冷媒流量", + // RtUIControlTitle="冷媒流量" + Environment.NewLine + "(kg/h)", + // RtUIControlTitleIndex="Title11", + // Station = 7, + // RtAddressPV = "101", + // RtAddressMV = "105", + // RtMVUIControlIndex="MV11", + // RtSVUIControlIndex="SV11", + // RtPVUIControlIndex="PV11", + // MaxValue=500, + // MinValue=0, + // Accuracy=1, + // Unit="(kg/h)", + // MeterEnableStatePLCAddress="V31.0", + // }, + //}; + + #endregion + + InitialPLCCom(); PubRtDataStart(); } + + /// + /// 初始化PLC通信 + /// + private void InitialPLCCom() + { + var IPInfo = ConfigHelper.GetValue("PLCIP"); + + SiemensDrive = new SiemensS7Net(SiemensPLCS.S200Smart, IPInfo); + // 连接对象 + OperateResult connect = SiemensDrive.ConnectServer(); + if (!connect.IsSuccess)//连接失败 + { + SiemensS7LinkState = false; + Console.WriteLine("connect failed:" + connect.Message); + MessageBox.Show($"PLC连接失败:{IPInfo}"); + return; + } + else//连接成功 + { + SiemensS7LinkState = true; + } + + //扫描线程成功 + RtScanDeviceStart(); + + } + + + /// + /// PLC扫描线程 + /// + private void RtScanDeviceStart() + { + PLCScanTask = Task.Run(async () => + { + while (ThreadEnable) + { + await Task.Delay(50); + + //DiagnosticsTime.Reset(); + //DiagnosticsTime.Start(); + try + { + //RT TODO + //SiemensDrive.Read("VW1", 2); + + foreach (var itemTag in TagManger.ListTag) + { + switch (itemTag.DataTypeInfo) + { + //case DataType.Byte: + // itemTag.OperateResultSource = SiemensDrive.ReadByte(itemTag.Address); + // break; + //case DataType.Short: + // itemTag.OperateResultSource = SiemensDrive.ReadInt16(itemTag.Address); + // break; + //case DataType.String: + // itemTag.OperateResultSource = SiemensDrive.ReadString(itemTag.Address); + // break; + //case DataType.Double: + // itemTag.OperateResultSource = SiemensDrive.ReadDouble(itemTag.Address); + // break; + default: + break; + } + + } + } + catch (Exception ex) + { + //LogService.Info($"时间:{DateTime.Now.ToString()}-【Meter】-{ex.Message}"); + + } + + + //DiagnosticsTime.Stop(); + //ScanRtTimeinfo = $"电表:{DiagnosticsTime.Elapsed.TotalMilliseconds.ToString()}"; + } + }); + } + + + private Random random = new Random(); /// diff --git a/CapMachine.Wpf/ViewModels/ProConfigViewModel.cs b/CapMachine.Wpf/ViewModels/ProConfigViewModel.cs index 561406c..b4a7ff0 100644 --- a/CapMachine.Wpf/ViewModels/ProConfigViewModel.cs +++ b/CapMachine.Wpf/ViewModels/ProConfigViewModel.cs @@ -1,13 +1,21 @@ using CapMachine.Core; using CapMachine.Model; +using CapMachine.Model.MeterConfig; +using CapMachine.Wpf.Dtos; using CapMachine.Wpf.PrismEvent; +using CapMachine.Wpf.ProPars; +using CapMachine.Wpf.Services; using CapMachine.Wpf.Views; +using Force.DeepCloner; +using ImTools; using MaterialDesignThemes.Wpf; +using NPOI.SS.Formula.Functions; using Prism.Commands; using Prism.Events; using Prism.Regions; using Prism.Services.Dialogs; using System.Collections.ObjectModel; +using System.Data; using System.Text; using System.Windows; @@ -15,18 +23,38 @@ namespace CapMachine.Wpf.ViewModels { public class ProConfigViewModel : NavigationViewModel { - public ProConfigViewModel(IDialogService dialogService, IFreeSql freeSql,IEventAggregator eventAggregator, IRegionManager regionManager) + public ProConfigViewModel(IDialogService dialogService, IFreeSql freeSql, IEventAggregator eventAggregator, IRegionManager regionManager, MachineRtDataService machineRtDataService) { //LogService = logService; FreeSql = freeSql; EventAggregator = eventAggregator; RegionManager = regionManager; + this.MachineRtDataService = machineRtDataService; //MachineDataService = machineDataService; DialogService = dialogService; - ListMeterSpeedItems = new ObservableCollection(); - ListMeterPsItems = new ObservableCollection(); + ListSlopMeterSpeedItems = new ObservableCollection(); + //ListMeterPsItems = new ObservableCollection(); + + Cond1TempInit(); + Cond2TempInit(); + Cond2PressInit(); + EVAPExpTempInit(); + ExPressInit(); + HVVolInit(); + InhPressInit(); + InhTempInit(); + LubePressInit(); + LVVolInit(); + OCRInit(); + OS1TempInit(); + OS2TempInit(); + PTCEntTempInit(); + PTCFlowInit(); + PTCPwInit(); + EnvRHInit(); + EnvTempInit(); ListProStepDtoItems = new ObservableCollection(); ListProStep = new List(); @@ -35,10 +63,13 @@ namespace CapMachine.Wpf.ViewModels RefreshProSeg(); //各个单独仪表的初始化 - SelectedMeterSpeed = new MeterSpeed(); - SelectedPs = new MeterPs(); + SelectedSlopMeterSpeed = new MeterSpeed(); + //SelectedPs = new MeterPs(); + + //当前选中的数据 + var CurSelectedData = FreeSql.Select().ToList(); + ProSegRunListViewItems.AddRange(CurSelectedData); - } /// @@ -47,6 +78,7 @@ namespace CapMachine.Wpf.ViewModels public IFreeSql FreeSql { get; } public IEventAggregator EventAggregator { get; } public IRegionManager RegionManager { get; } + private MachineRtDataService MachineRtDataService { get; } /// /// 弹窗服务 @@ -54,260 +86,9 @@ namespace CapMachine.Wpf.ViewModels public IDialogService DialogService { get; } - - #region 速度表操作 - - private ObservableCollection _ListMeterSpeedItems; /// - /// MeterSpeedp数据集合 + /// tEST /// - public ObservableCollection ListMeterSpeedItems - { - get { return _ListMeterSpeedItems; } - set { _ListMeterSpeedItems = value; RaisePropertyChanged(); } - } - - /// - /// MeterSpeed集合数据 - /// - public List ListMeterSpeed { get; set; } - - private MeterSpeed _SelectedMeterSpeed; - /// - /// 当前选中的程序速度 - /// - public MeterSpeed SelectedMeterSpeed - { - get { return _SelectedMeterSpeed; } - set { _SelectedMeterSpeed = value; RaisePropertyChanged(); } - } - - - - - private DelegateCommand _MeterSpeedSelectedChangedCmd; - /// - /// 刷新数据命令 - /// - public DelegateCommand MeterSpeedSelectedChangedCmd - { - set - { - _MeterSpeedSelectedChangedCmd = value; - } - get - { - if (_MeterSpeedSelectedChangedCmd == null) - { - _MeterSpeedSelectedChangedCmd = new DelegateCommand((str) => MeterSpeedSelectedChangedCmdMethod(str)); - } - return _MeterSpeedSelectedChangedCmd; - } - } - - - /// - /// 速度表选中行的执行方法 - /// - /// - /// - private void MeterSpeedSelectedChangedCmdMethod(object par) - { - var SelectedData = par as MeterSpeed; - if (SelectedData != null) - { - SelectedMeterSpeed = SelectedData; - } - - } - - - - private DelegateCommand _ProStepSpeedAddCmd; - /// - /// 新增速度命令 - /// - public DelegateCommand ProStepSpeedAddCmd - { - set - { - _ProStepSpeedAddCmd = value; - } - get - { - if (_ProStepSpeedAddCmd == null) - { - _ProStepSpeedAddCmd = new DelegateCommand(() => ProStepSpeedAddCmdMethod()); - } - return _ProStepSpeedAddCmd; - } - } - - /// - /// 新增速度命令执行方法 - /// - private void ProStepSpeedAddCmdMethod() - { - if (SelectedProStepDto == null) - { - MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); - return; - } - - //当前的速度表集合数据 - var MeterSpeeds = ListMeterSpeedItems.ToList(); - - var MeterSpeedData = new MeterSpeed() - { - StartValue = SelectedMeterSpeed.StartValue, - EndValue = SelectedMeterSpeed.EndValue, - KeepTime = SelectedMeterSpeed.KeepTime, - ProStepId = SelectedProStepDto.Id, - StepNo = AutoGetMeterSpeedStepNo(), - }; - - //增加数据 - var getdata = FreeSql.Insert(MeterSpeedData).ExecuteIdentity(); - - //更新界面数据 - ListProgramSeg = RefreshProSeg(); - RefreshProStepData(); - RefreshMeterSpeed(); - } - - - private DelegateCommand _ProStepSpeedEditCmd; - /// - /// 修改速度命令 - /// - public DelegateCommand ProStepSpeedEditCmd - { - set - { - _ProStepSpeedEditCmd = value; - } - get - { - if (_ProStepSpeedEditCmd == null) - { - _ProStepSpeedEditCmd = new DelegateCommand(() => ProStepSpeedEditCmdMethod()); - } - return _ProStepSpeedEditCmd; - } - } - - /// - /// 新增速度命令执行方法 - /// - private void ProStepSpeedEditCmdMethod() - { - if (SelectedProStepDto == null || SelectedMeterSpeed == null) - { - MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); - return; - } - - FreeSql.Update() - .Set(a => a.StartValue, SelectedMeterSpeed.StartValue) - .Set(a => a.EndValue, SelectedMeterSpeed.EndValue) - .Set(a => a.KeepTime, SelectedMeterSpeed.KeepTime) - .Where(a => a.Id == SelectedMeterSpeed.Id) - .ExecuteAffrows(); - - //更新界面数据 - ListProgramSeg = RefreshProSeg(); - RefreshProStepData(); - RefreshMeterSpeed(); - } - - - private DelegateCommand _ProStepSpeedDeleteCmd; - /// - /// 修改速度命令 - /// - public DelegateCommand ProStepSpeedDeleteCmd - { - set - { - _ProStepSpeedDeleteCmd = value; - } - get - { - if (_ProStepSpeedDeleteCmd == null) - { - _ProStepSpeedDeleteCmd = new DelegateCommand(() => ProStepSpeedDeleteCmdMethod()); - } - return _ProStepSpeedDeleteCmd; - } - } - - /// - /// 删除速度命令执行方法 - /// - private void ProStepSpeedDeleteCmdMethod() - { - if (SelectedProStepDto != null || SelectedMeterSpeed.Id != 0) - { - MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); - if (dialogResult == MessageBoxResult.OK) - { - FreeSql.Delete(SelectedMeterSpeed.Id).ExecuteAffrows(); - - //更新界面数据 - ListProgramSeg = RefreshProSeg(); - RefreshProStepData(); - RefreshMeterSpeed(); - } - - } - else - { - MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); - } - - } - - - - - - - /// - /// 更新速度表信息 - /// - private void RefreshMeterSpeed() - { - ListMeterSpeed = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! - .FirstOrDefault()!.MeterSpeeds!.ToList(); - - ListMeterSpeedItems.Clear(); - - ListMeterSpeedItems = new ObservableCollection(ListMeterSpeed!); - - } - - #endregion - - private DelegateCommand _ProStepPsCmd; - /// - /// 新增PS命令 - /// - public DelegateCommand ProStepPsCmd - { - set - { - _ProStepPsCmd = value; - } - get - { - if (_ProStepPsCmd == null) - { - _ProStepPsCmd = new DelegateCommand(() => ProStepPsCmdCmdMethod()); - } - return _ProStepPsCmd; - } - } - private void ProStepPsCmdCmdMethod() { //var openDrawerCommand = MaterialDesignThemes.Wpf.DrawerHost.OpenDrawerCommand; @@ -315,517 +96,9 @@ namespace CapMachine.Wpf.ViewModels RegionManager.RequestNavigate("ProStepDrawerContentRegion", nameof(ProStepConfigPsView)); //EventAggregator.GetEvent().Publish("Right"); - - - } - - #region Ps表 - - private ObservableCollection _ListMeterPsItems; - /// - /// Meter Ps数据集合 - /// - public ObservableCollection ListMeterPsItems - { - get { return _ListMeterPsItems; } - set { _ListMeterPsItems = value; RaisePropertyChanged(); } - } - - /// - /// MeterSpeed集合数据 - /// - public List ListMeterPs { get; set; } - - - private MeterPs _SelectedPs; - /// - /// 当前选中的程序速度 - /// - public MeterPs SelectedPs - { - get { return _SelectedPs; } - set { _SelectedPs = value; RaisePropertyChanged(); } - } - - private DelegateCommand _MeterPsSelectedChangedCmd; - /// - /// 刷新数据命令 - /// - public DelegateCommand MeterPsSelectedChangedCmd - { - set - { - _MeterPsSelectedChangedCmd = value; - } - get - { - if (_MeterPsSelectedChangedCmd == null) - { - _MeterPsSelectedChangedCmd = new DelegateCommand((str) => MeterPsSelectedChangedCmdMethod(str)); - } - return _MeterPsSelectedChangedCmd; - } - } - - - /// - /// 速度表选中行的执行方法 - /// - /// - /// - private void MeterPsSelectedChangedCmdMethod(object par) - { - var SelectedData = par as MeterPs; - if (SelectedData != null) - { - SelectedPs = SelectedData; - } - } - - private DelegateCommand _ProStepPsAddCmd; - /// - /// 新增PS命令 - /// - public DelegateCommand ProStepPsAddCmd - { - set - { - _ProStepPsAddCmd = value; - } - get - { - if (_ProStepPsAddCmd == null) - { - _ProStepPsAddCmd = new DelegateCommand(() => ProStepPsAddCmdMethod()); - } - return _ProStepPsAddCmd; - } - } - - /// - /// 增加Ps命令执行方法 - /// - private void ProStepPsAddCmdMethod() - { - if (SelectedProStepDto == null) - { - MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); - return; - } - - //当前的速度表集合数据 - var MeterPss = ListMeterPsItems.ToList(); - - var MeterPsData = new MeterPs() - { - StartValue = SelectedPs.StartValue, - EndValue = SelectedPs.EndValue, - KeepTime = SelectedPs.KeepTime, - ProStepId = SelectedProStepDto.Id, - StepNo = AutoGetMeterPsStepNo(), - }; - - //增加数据 - var getdata = FreeSql.Insert(MeterPsData).ExecuteIdentity(); - - //更新界面数据 - ListProgramSeg = RefreshProSeg(); - RefreshProStepData(); - RefreshMeterPs(); - } - - - private DelegateCommand _ProStepPsEditCmd; - /// - /// 新增PS命令 - /// - public DelegateCommand ProStepPsEditCmd - { - set - { - _ProStepPsEditCmd = value; - } - get - { - if (_ProStepPsEditCmd == null) - { - _ProStepPsEditCmd = new DelegateCommand(() => ProStepPsEditCmdMethod()); - } - return _ProStepPsEditCmd; - } - } - - /// - /// 编辑Ps命令执行方法 - /// - private void ProStepPsEditCmdMethod() - { - if (SelectedProStepDto == null || SelectedPs == null) - { - MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); - return; - } - - FreeSql.Update() - .Set(a => a.StartValue, SelectedPs.StartValue) - .Set(a => a.EndValue, SelectedPs.EndValue) - .Set(a => a.KeepTime, SelectedPs.KeepTime) - .Where(a => a.Id == SelectedPs.Id) - .ExecuteAffrows(); - - //更新界面数据 - ListProgramSeg = RefreshProSeg(); - RefreshProStepData(); - RefreshMeterPs(); - } - - private DelegateCommand _ProStepPsDeleteCmd; - /// - /// 新增PS命令 - /// - public DelegateCommand ProStepPsDeleteCmd - { - set - { - _ProStepPsDeleteCmd = value; - } - get - { - if (_ProStepPsDeleteCmd == null) - { - _ProStepPsDeleteCmd = new DelegateCommand(() => ProStepPsDeleteCmdMethod()); - } - return _ProStepPsDeleteCmd; - } - } - - /// - /// 增加Ps命令执行方法 - /// - private void ProStepPsDeleteCmdMethod() - { - if (SelectedProStepDto != null || SelectedPs.Id != 0) - { - MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); - if (dialogResult == MessageBoxResult.OK) - { - FreeSql.Delete(SelectedPs.Id).ExecuteAffrows(); - - //更新界面数据 - ListProgramSeg = RefreshProSeg(); - RefreshProStepData(); - RefreshMeterPs(); - } - - } - else - { - MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); - } - } - - - - /// - /// 更新速度表信息 - /// - private void RefreshMeterPs() - { - ListMeterPs = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! - .FirstOrDefault()!.MeterPss!.ToList(); - - ListMeterPsItems.Clear(); - - ListMeterPsItems = new ObservableCollection(ListMeterPs!); - } - #endregion - - - #region ProStep操作 - - private int _ProStepCycleCount; - /// - /// ProStep 循环次数 - /// - public int ProStepCycleCount - { - get { return _ProStepCycleCount; } - set { _ProStepCycleCount = value; RaisePropertyChanged(); } - } - - - private ProStepDto _SelectedProStepDto; - /// - /// 当前选中的程序步骤 - /// - public ProStepDto SelectedProStepDto - { - get { return _SelectedProStepDto; } - set { _SelectedProStepDto = value; RaisePropertyChanged(); } - } - - - - private ObservableCollection _ListProStepDtoItems; - /// - /// ProStep数据集合 - /// - public ObservableCollection ListProStepDtoItems - { - get { return _ListProStepDtoItems; } - set { _ListProStepDtoItems = value; RaisePropertyChanged(); } - } - - private List _ListProStep; - /// - /// ProStep数据集合 - /// - public List ListProStep - { - get { return _ListProStep; } - set { _ListProStep = value; } - } - - - private string MeterSpeedToString(List data) - { - var strInfo = new StringBuilder(); - var Count = data.Count; - foreach (var item in data) - { - Count--; - strInfo.Append(item.StartValue); - strInfo.Append("-"); - strInfo.Append(item.EndValue); - strInfo.Append("-"); - strInfo.Append(item.KeepTime); - if (Count != 0) - { - strInfo.Append(Environment.NewLine); - } - } - - return strInfo.ToString(); - //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; - - } - - private DelegateCommand _GridSelectionChangedCmd; - /// - /// 刷新数据命令 - /// - public DelegateCommand GridSelectionChangedCmd - { - set - { - _GridSelectionChangedCmd = value; - } - get - { - if (_GridSelectionChangedCmd == null) - { - _GridSelectionChangedCmd = new DelegateCommand((par) => GridSelectionChangedCmdMethod(par)); - } - return _GridSelectionChangedCmd; - } - } - - - private void GridSelectionChangedCmdMethod(object par) - { - //先判断是否是正确的集合数据,防止DataGrid的数据源刷新导致的触发事件 - var Selecteddata = par as ProStepDto; - //SelectedProStepDto = par as ProStepDto; - if (Selecteddata != null) - { - SelectedProStepDto = Selecteddata; - ProStepCycleCount = SelectedProStepDto.StepRepeat; - - ListMeterSpeed = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterSpeeds!.ToList(); - ListMeterPs = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPss!.ToList(); - - ListMeterSpeedItems = new ObservableCollection(ListMeterSpeed); - ListMeterPsItems = new ObservableCollection(ListMeterPs); - } - } - - - - private DelegateCommand _ProStepAddCmd; - /// - /// 新增命令 - /// - public DelegateCommand ProStepAddCmd - { - set - { - _ProStepAddCmd = value; - } - get - { - if (_ProStepAddCmd == null) - { - _ProStepAddCmd = new DelegateCommand(() => ProStepAddCmdMethod()); - } - return _ProStepAddCmd; - } - } - - /// - /// 新增命令执行方法 - /// - private void ProStepAddCmdMethod() - { - //当前的速度表集合数据 - var MeterSpeeds = ListMeterSpeedItems.ToList(); - - var NewData = new ProStep() - { - StepNo = AutoGetProStepNo(), - StepRepeat = ProStepCycleCount, - ProgramSegId = SelectedProgramSeg.Id, - Remark = "", - }; - - var getdata = FreeSql.Insert(NewData).ExecuteIdentity(); - - //var repo = FreeSql.GetRepository(); - //var getdata = repo.Insert(NewData); - - //更新Id - foreach (var item in MeterSpeeds) - { - item.ProStepId = getdata; - } - - NewData.MeterSpeeds = MeterSpeeds; - //repo.SaveMany(NewData, "MeterSpeeds"); - - FreeSql.Insert(MeterSpeeds).ExecuteAffrows(); - - //更新界面数据 - ListProgramSeg = RefreshProSeg(); - RefreshProStepData(); - } - - - - private DelegateCommand _ProStepEditCmd; - /// - /// 编辑命令 - /// - public DelegateCommand ProStepEditCmd - { - set - { - _ProStepEditCmd = value; - } - get - { - if (_ProStepEditCmd == null) - { - _ProStepEditCmd = new DelegateCommand(() => ProStepEditCmdMethod()); - } - return _ProStepEditCmd; - } - } - - /// - /// 编辑命令执行方法 - /// - private void ProStepEditCmdMethod() - { - if (SelectedProStepDto == null) - { - MessageBox.Show("请选择后再进行编辑"); - return; - } - - FreeSql.Update() - .Set(a => a.StepRepeat, ProStepCycleCount) - //.Set(a=>a.StepRepeat, ProStepCycleCount) - .Where(a => a.Id == SelectedProStepDto.Id) - .ExecuteAffrows(); - - //更新界面数据 - ListProgramSeg = RefreshProSeg(); - RefreshProStepData(); - } - - private DelegateCommand _ProStepDeleteCmd; - /// - /// 删除命令 - /// - public DelegateCommand ProStepDeleteCmd - { - set - { - _ProStepDeleteCmd = value; - } - get - { - if (_ProStepDeleteCmd == null) - { - _ProStepDeleteCmd = new DelegateCommand(() => ProStepDeleteCmdMethod()); - } - return _ProStepDeleteCmd; - } - } - - /// - /// 删除命令执行方法 - /// - private void ProStepDeleteCmdMethod() - { - if (SelectedProStepDto == null) - { - MessageBox.Show("请选择后再进行删除"); - return; - } - - MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); - if (dialogResult == MessageBoxResult.OK) - { - FreeSql.Delete() - .Where(a => a.Id == SelectedProStepDto.Id) - .ExecuteAffrows(); - - //更新界面数据 - ListProgramSeg = RefreshProSeg(); - RefreshProStepData(); - } - - } - - - - private void RefreshProStepData() - { - ListProStep = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.ToList(); - ListProStepDtoItems.Clear(); - foreach (var item in ListProStep) - { - ListProStepDtoItems.Add(new ProStepDto() - { - Id = item.Id, - StepNo = item.StepNo, - StepRepeat = item.StepRepeat, - SpeedInfo = MeterSpeedToString(item.MeterSpeeds!.ToList()) - }); - } - } - - #endregion - - - - //private ObservableCollection GetProStep(List data) - //{ - - //} #region ProgramSeg操作 @@ -861,10 +134,10 @@ namespace CapMachine.Wpf.ViewModels //如果不是ProgramSeg则退出,因为刷新数据源的时候,会触发这个选择器 if (data == null) return; - ListProStep = data!.ProSteps!.ToList(); - SelectedProgramSeg = data; + ListProStep = data!.ProSteps!.ToList(); + ListProStepDtoItems.Clear(); foreach (var item in ListProStep) { @@ -873,12 +146,46 @@ namespace CapMachine.Wpf.ViewModels Id = item.Id, StepNo = item.StepNo, StepRepeat = item.StepRepeat, - SpeedInfo = MeterSpeedToString(item.MeterSpeeds!.ToList()) + SpeedCycle = new CycleInfoDto() { Cycle = item.SpeedCycle, IsSlop = CheckIsSlop(item.MeterSpeeds!.Select(p => new MeterCom() { ValueType = p.ValueType, Constant = p.Constant }).ToList()) }, + SpeedInfo = MeterSpeedToString(item.MeterSpeeds!.ToList()), + MeterCond1TempInfo = MeterCond1TempToString(item.MeterCond1Temps!.ToList()), + MeterCond2TempInfo = MeterCond2TempToString(item.MeterCond2Temps!.ToList()), + MeterCond2PressInfo = MeterCond2PressToString(item.MeterCond2Presss!.ToList()), + MeterEVAPExpTempInfo = MeterEVAPExpTempToString(item.MeterEVAPExpTemps!.ToList()), + MeterExPressInfo = MeterExPressToString(item.MeterExPresss!.ToList()), + MeterHVVolInfo = MeterHVVolToString(item.MeterHVVols!.ToList()), + MeterInhPressInfo = MeterInhPressToString(item.MeterInhPresss!.ToList()), + MeterInhTempInfo = MeterInhTempToString(item.MeterInhTemps!.ToList()), + MeterLubePressInfo = MeterLubePressToString(item.MeterLubePresss!.ToList()), + MeterLVVolInfo = MeterLVVolToString(item.MeterLVVols!.ToList()), + MeterOCRInfo = MeterOCRToString(item.MeterOCRs!.ToList()), + MeterOS1TempInfo = MeterOS1TempToString(item.MeterOS1Temps!.ToList()), + MeterOS2TempInfo = MeterOS2TempToString(item.MeterOS2Temps!.ToList()), + MeterPTCEntTempInfo = MeterPTCEntTempToString(item.MeterPTCEntTemps!.ToList()), + MeterPTCFlowInfo = MeterPTCFlowToString(item.MeterPTCFlows!.ToList()), + MeterPTCPwInfo = MeterPTCPwToString(item.MeterPTCPws!.ToList()), + MeterEnvRHInfo = MeterEnvRHToString(item.MeterEnvRHs!.ToList()), + MeterEnvTempInfo = MeterEnvTempToString(item.MeterEnvTemps!.ToList()), + //xxx = MeterSpeedToString(item.xxxs!.ToList()), + //xxx = MeterSpeedToString(item.xxxs!.ToList()), + //xxx = MeterSpeedToString(item.xxxs!.ToList()), + //xxx = MeterSpeedToString(item.xxxs!.ToList()), + //xxx = MeterSpeedToString(item.xxxs!.ToList()), + //xxx = MeterSpeedToString(item.xxxs!.ToList()), + //xxx = MeterSpeedToString(item.xxxs!.ToList()), }); + //【+++】 } + + //新选择ProSeg后,此时还没有选择具体的速度等参数,需要禁用设置,等选择了具体的ProStep后再启用 + SpeedTabControlEnable = false; + OtherParTabControlEnable = false; } + + + private ObservableCollection _ProSegListViewItems; /// /// ProgramSeg 数据集合 @@ -913,17 +220,71 @@ namespace CapMachine.Wpf.ViewModels { ListProgramSeg = FreeSql.Select() .IncludeMany(a => a.ProSteps, - then => then.IncludeMany(b => b.MeterSpeeds).IncludeMany(b => b.MeterPss).IncludeMany(b => b.MeterPds)).ToList(); + then => then.IncludeMany(b => b.MeterSpeeds) + .IncludeMany(b => b.MeterCond1Temps) + .IncludeMany(b => b.MeterCond2Temps) + .IncludeMany(b => b.MeterCond2Presss) + .IncludeMany(b => b.MeterEVAPExpTemps) + .IncludeMany(b => b.MeterExPresss) + .IncludeMany(b => b.MeterHVVols) + .IncludeMany(b => b.MeterInhPresss) + .IncludeMany(b => b.MeterInhTemps) + .IncludeMany(b => b.MeterLubePresss) + .IncludeMany(b => b.MeterLVVols) + .IncludeMany(b => b.MeterOCRs) + .IncludeMany(b => b.MeterOS1Temps) + .IncludeMany(b => b.MeterOS2Temps) + .IncludeMany(b => b.MeterPTCEntTemps) + .IncludeMany(b => b.MeterPTCFlows) + .IncludeMany(b => b.MeterPTCPws) + .IncludeMany(b => b.MeterEnvRHs) + .IncludeMany(b => b.MeterEnvTemps) + //.IncludeMany(b => b.MeterPds) + ).ToList(); - ProSegListViewItems.Clear(); - foreach (var item in ListProgramSeg) - { - ProSegListViewItems.Add(item); - } + //ProSegListViewItems.Clear(); + ProSegListViewItems = new ObservableCollection(ListProgramSeg); + //foreach (var item in ListProgramSeg) + //{ + // ProSegListViewItems.Add(item); + //} return ListProgramSeg; } + /// + /// 根据id找到ProSeg + /// + /// + private ProgramSeg ReFreshProSegById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .IncludeMany(a => a.ProSteps, + then => then.IncludeMany(b => b.MeterSpeeds) + .IncludeMany(b => b.MeterCond1Temps) + .IncludeMany(b => b.MeterCond2Temps) + .IncludeMany(b => b.MeterCond2Presss) + .IncludeMany(b => b.MeterEVAPExpTemps) + .IncludeMany(b => b.MeterExPresss) + .IncludeMany(b => b.MeterHVVols) + .IncludeMany(b => b.MeterInhPresss) + .IncludeMany(b => b.MeterInhTemps) + .IncludeMany(b => b.MeterLubePresss) + .IncludeMany(b => b.MeterLVVols) + .IncludeMany(b => b.MeterOCRs) + .IncludeMany(b => b.MeterOS1Temps) + .IncludeMany(b => b.MeterOS2Temps) + .IncludeMany(b => b.MeterPTCEntTemps) + .IncludeMany(b => b.MeterPTCFlows) + .IncludeMany(b => b.MeterPTCPws) + .IncludeMany(b => b.MeterEnvRHs) + .IncludeMany(b => b.MeterEnvTemps) + //.IncludeMany(b => b.MeterPds) + ).ToList(); + + return Data.FirstOrDefault()!; + } private DelegateCommand _ProAddCmd; /// @@ -966,14 +327,20 @@ namespace CapMachine.Wpf.ViewModels } //开始新增 - var InsertedData = FreeSql.Insert(new ProgramSeg() + var InsertedId = FreeSql.Insert(new ProgramSeg() { Name = ReturnValue, Remark = "", - }).ExecuteAffrows(); + }).ExecuteIdentity(); + + var InertData = ReFreshProSegById(InsertedId); + + //添加新增的数据 + ListProgramSeg.Add(InertData); + ProSegListViewItems.Add(InertData); //获取全部的数据 - RefreshProSeg(); + //RefreshProSeg(); } else if (par.Result == ButtonResult.Cancel) @@ -1037,10 +404,26 @@ namespace CapMachine.Wpf.ViewModels var InsertedData = FreeSql.Update() .Set(a => a.Name, ReturnValue) .Where(a => a.Id == SelectedProgramSeg.Id) - .ExecuteAffrows(); + .ExecuteUpdated(); + + var UpdateData = ReFreshProSegById(InsertedData.FirstOrDefault()!.Id); + + //ListProgramSeg.Find(a => a.Id == SelectedProgramSeg.Id).Name = InsertedData.FirstOrDefault().Name; + //ProSegListViewItems.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault().Name = InsertedData.FirstOrDefault().Name; + + var CurIndex = ListProgramSeg.FindIndex(a => a.Id == UpdateData.Id); + //移除旧的数据 + ListProgramSeg.Remove(ListProgramSeg.Find(a => a.Id == UpdateData.Id)!); + //新增数据 + ListProgramSeg.Insert(CurIndex, UpdateData); + + //移除旧的数据 + ProSegListViewItems.Remove(ProSegListViewItems.Where(a => a.Id == UpdateData.Id).FirstOrDefault()!); + //新增数据 + ProSegListViewItems.Insert(CurIndex, UpdateData); //获取全部的数据 - RefreshProSeg(); + //RefreshProSeg(); } else if (par.Result == ButtonResult.Cancel) @@ -1092,23 +475,14581 @@ namespace CapMachine.Wpf.ViewModels repo.DbContextOptions.EnableCascadeSave = true; //关键设置 var data = repo.Select.Where(a => a.Id == SelectedProgramSeg.Id) - .IncludeMany(a => a.ProSteps, then => then.IncludeMany(b => b.MeterSpeeds).IncludeMany(b => b.MeterPss).IncludeMany(b => b.MeterPds)) + .IncludeMany(a => a.ProSteps, then => then.IncludeMany(b => b.MeterSpeeds) + .IncludeMany(b => b.MeterCond1Temps) + .IncludeMany(b => b.MeterCond2Temps) + .IncludeMany(b => b.MeterCond2Presss) + .IncludeMany(b => b.MeterEVAPExpTemps) + .IncludeMany(b => b.MeterExPresss) + .IncludeMany(b => b.MeterHVVols) + .IncludeMany(b => b.MeterInhPresss) + .IncludeMany(b => b.MeterInhTemps) + .IncludeMany(b => b.MeterLubePresss) + .IncludeMany(b => b.MeterLVVols) + .IncludeMany(b => b.MeterOCRs) + .IncludeMany(b => b.MeterOS1Temps) + .IncludeMany(b => b.MeterOS2Temps) + .IncludeMany(b => b.MeterPTCEntTemps) + .IncludeMany(b => b.MeterPTCFlows) + .IncludeMany(b => b.MeterPTCPws) + .IncludeMany(b => b.MeterEnvRHs) + .IncludeMany(b => b.MeterEnvTemps)) + //.IncludeMany(b => b.MeterPds)) //.IncludeMany(a => a.QuickClutchStepCells) //.IncludeMany(a => a.QuickVoltageStepCells) .ToList(); repo.Delete(data); + //var UpdateData = ReFreshProSegById(InsertedData.FirstOrDefault()!.Id); + + //移除旧的数据 + ListProgramSeg.Remove(ListProgramSeg.Find(a => a.Id == SelectedProgramSeg.Id)!); + + //移除旧的数据 + ProSegListViewItems.Remove(ProSegListViewItems.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!); + + //清除内容区域的数据 + ClearCurProStepData(); + ////开始删除 //var InsertedData = FreeSql.Delete(SelectedProgramSeg.Id).ExecuteAffrows(); //获取全部的数据 - RefreshProSeg(); + //RefreshProSeg(); + } + } + + + private DelegateCommand _ProCopyCmd; + /// + /// 复制 命令 + /// + public DelegateCommand ProCopyCmd + { + set + { + _ProCopyCmd = value; + } + get + { + if (_ProCopyCmd == null) + { + _ProCopyCmd = new DelegateCommand(() => ProCopyCmdMethod()); + } + return _ProCopyCmd; + } + } + /// + /// 复制命令 + /// + /// + private void ProCopyCmdMethod() + { + if (SelectedProgramSeg == null) + { + MessageBox.Show("未选中要复制的工况程序"); + return; + } + + //SelectedProgramSeg + var RepoProSeg = FreeSql.GetRepository(); + RepoProSeg.DbContextOptions.EnableCascadeSave = true; + + //要复制的内容 + var SelectedCopyProgramSeg = SelectedProgramSeg.DeepClone(); + + SelectedCopyProgramSeg.Name = SelectedCopyProgramSeg.Name + "1"; + SelectedCopyProgramSeg.Id = 0; + + if (SelectedCopyProgramSeg.ProSteps != null) + { + foreach (var item in SelectedCopyProgramSeg.ProSteps) + { + SetModelId0(item); + } + } + + var InsertedProSeg = RepoProSeg.Insert(SelectedCopyProgramSeg); + + var InsertData = ReFreshProSegById(InsertedProSeg.Id); + //添加 ProSeg 新增的数据 + ListProgramSeg.Add(InsertData); + ProSegListViewItems.Add(InsertData); + + } + + + #endregion + + #region ProStep操作 + + private int _ProStepCycleCount; + /// + /// ProStep 循环次数 + /// + public int ProStepCycleCount + { + get { return _ProStepCycleCount; } + set { _ProStepCycleCount = value; RaisePropertyChanged(); } + } + + private int _ProStepProNo; + /// + /// ProStep 序号 + /// + public int ProStepProNo + { + get { return _ProStepProNo; } + set { _ProStepProNo = value; RaisePropertyChanged(); } + } + + private ProStepDto _SelectedProStepDto; + /// + /// 当前选中的程序步骤 + /// + public ProStepDto SelectedProStepDto + { + get { return _SelectedProStepDto; } + set { _SelectedProStepDto = value; RaisePropertyChanged(); } + } + + private ObservableCollection _ListProStepDtoItems; + /// + /// ProStep数据集合 + /// + public ObservableCollection ListProStepDtoItems + { + get { return _ListProStepDtoItems; } + set { _ListProStepDtoItems = value; RaisePropertyChanged(); } + } + + private List _ListProStep; + /// + /// ProStep数据集合 + /// + public List ListProStep + { + get { return _ListProStep; } + set { _ListProStep = value; } + } + + private int _SelectedIndex; + /// + /// 选中的行 + /// + public int SelectedIndex + { + get { return _SelectedIndex; } + set { _SelectedIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _GridSelectionChangedCmd; + /// + /// 选中行数据命令 + /// + public DelegateCommand GridSelectionChangedCmd + { + set + { + _GridSelectionChangedCmd = value; + } + get + { + if (_GridSelectionChangedCmd == null) + { + _GridSelectionChangedCmd = new DelegateCommand((par) => GridSelectionChangedCmdMethod(par)); + } + return _GridSelectionChangedCmd; + } + } + private void GridSelectionChangedCmdMethod(object par) + { + //先判断是否是正确的集合数据,防止DataGrid的数据源刷新导致的触发事件 + var Selecteddata = par as ProStepDto; + + ////选中的行数据 + //var Selecteddata = (par as DataGrid)!.SelectedItem as ProStepDto; + ////选中的列数据 + //var selectedColumn = (par as DataGrid)!.CurrentColumn; + + //SelectedIndex= ProParsHelper.GetIndexByName(selectedColumn); + + //SelectedProStepDto = par as ProStepDto; + if (Selecteddata != null) + { + SelectedProStepDto = Selecteddata; + ProStepCycleCount = SelectedProStepDto.StepRepeat; + ProStepProNo = SelectedProStepDto.StepNo; + + //控件启用 + SpeedTabControlEnable = true; + OtherParTabControlEnable = true; + + // + SelectedSlopMeterSpeed = null; + SelectedSlopCond1Temp = null; + SelectedSlopCond2Temp = null; + SelectedSlopCond2Press = null; + SelectedSlopEVAPExpTemp = null; + SelectedSlopExPress = null; + SelectedSlopHVVol = null; + SelectedSlopInhPress = null; + SelectedSlopInhTemp = null; + SelectedSlopLubePress = null; + SelectedSlopLVVol = null; + SelectedSlopOCR = null; + SelectedSlopOS1Temp = null; + SelectedSlopOS2Temp = null; + SelectedSlopPTCEntTemp = null; + SelectedSlopPTCFlow = null; + SelectedSlopPTCPw = null; + SelectedSlopEnvRH = null; + SelectedSlopEnvTemp = null; + + //////////////////////////Speed////////////////////////////////////// + var TempListMeterSpeed = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterSpeeds!.ToList(); + //判断是斜率还是常值 + if (TempListMeterSpeed != null && TempListMeterSpeed.Count > 0) + { + if (TempListMeterSpeed.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterSpeed = new List(); + ListSlopMeterSpeedItems = new ObservableCollection(ListSlopMeterSpeed); + + //常值信息 + ProStepSpeedSwitchConstSlopPar = false; + ProStepSpeedSwitchConstSlopIndex = 0; + + //常值只有一个 + SelectedConstSpeed = TempListMeterSpeed.FirstOrDefault()!; + SelectedConstSpeedValue = SelectedConstSpeed.Constant; + SelectedConstSpeedTimeValue = SelectedConstSpeed.KeepTime; + + //因为速度常值也可能跟随拓展的参数,那么拓展的参数也需要展示用的,此时不需要再选择,直接展示即可 + SelectedSlopMeterSpeed = SelectedConstSpeed; + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstSpeedValue = 0; + SelectedConstSpeedTimeValue = 0; + + ProStepSpeedSwitchConstSlopPar = true; + ProStepSpeedSwitchConstSlopIndex = 1; + + + ListSlopMeterSpeed = TempListMeterSpeed.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterSpeedItems = new ObservableCollection(ListSlopMeterSpeed); + + //更新后检测时间是否匹配并界面提示 + CheckSpeedSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepSpeedSwitchConstSlopPar = true; + ListSlopMeterSpeed = new List(); + ListSlopMeterSpeedItems = new ObservableCollection(ListSlopMeterSpeed); + SelectedConstSpeedValue = 0; + SelectedConstSpeedTimeValue = 0; + } + + + + //////////////////////////Cond1Temp////////////////////////////////////// + var TempListMeterCond1Temp = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond1Temps!.ToList(); + //判断是斜率还是常值 + if (TempListMeterCond1Temp != null && TempListMeterCond1Temp.Count > 0) + { + if (TempListMeterCond1Temp.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterCond1Temp = new List(); + ListSlopMeterCond1TempItems = new ObservableCollection(ListSlopMeterCond1Temp); + + //常值信息 + ProStepCond1TempSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstCond1Temp = TempListMeterCond1Temp.FirstOrDefault()!; + SelectedConstCond1TempValue = SelectedConstCond1Temp.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond1TempInfo = MeterCond1TempToString(new List() { SelectedConstCond1Temp }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstCond1TempValue = 0; + + ProStepCond1TempSwitchConstSlopIndex = 1; + + ListSlopMeterCond1Temp = TempListMeterCond1Temp.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterCond1TempItems = new ObservableCollection(ListSlopMeterCond1Temp); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond1TempInfo = MeterCond1TempToString(ListSlopMeterCond1Temp); + + //更新后检测时间是否匹配并界面提示 + CheckCond1TempSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepCond1TempSwitchConstSlopIndex = 1; + ListSlopMeterCond1Temp = new List(); + ListSlopMeterCond1TempItems = new ObservableCollection(ListSlopMeterCond1Temp); + SelectedConstCond1TempValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond1TempInfo = MeterCond1TempToString(ListSlopMeterCond1Temp); + } + + + //////////////////////////Cond2Temp////////////////////////////////////// + var TempListMeterCond2Temp = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Temps!.ToList(); + //判断是斜率还是常值 + if (TempListMeterCond2Temp != null && TempListMeterCond2Temp.Count > 0) + { + if (TempListMeterCond2Temp.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterCond2Temp = new List(); + ListSlopMeterCond2TempItems = new ObservableCollection(ListSlopMeterCond2Temp); + + //常值信息 + ProStepCond2TempSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstCond2Temp = TempListMeterCond2Temp.FirstOrDefault()!; + SelectedConstCond2TempValue = SelectedConstCond2Temp.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond2TempInfo = MeterCond2TempToString(new List() { SelectedConstCond2Temp }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstCond2TempValue = 0; + + ProStepCond2TempSwitchConstSlopIndex = 1; + + ListSlopMeterCond2Temp = TempListMeterCond2Temp.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterCond2TempItems = new ObservableCollection(ListSlopMeterCond2Temp); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond2TempInfo = MeterCond2TempToString(ListSlopMeterCond2Temp); + + //更新后检测时间是否匹配并界面提示 + CheckCond2TempSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepCond2TempSwitchConstSlopIndex = 1; + ListSlopMeterCond2Temp = new List(); + ListSlopMeterCond2TempItems = new ObservableCollection(ListSlopMeterCond2Temp); + SelectedConstCond2TempValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond2TempInfo = MeterCond2TempToString(ListSlopMeterCond2Temp); + } + + + //////////////////////////Cond2Press////////////////////////////////////// + var TempListMeterCond2Press = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Presss!.ToList(); + //判断是斜率还是常值 + if (TempListMeterCond2Press != null && TempListMeterCond2Press.Count > 0) + { + if (TempListMeterCond2Press.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterCond2Press = new List(); + ListSlopMeterCond2PressItems = new ObservableCollection(ListSlopMeterCond2Press); + + //常值信息 + ProStepCond2PressSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstCond2Press = TempListMeterCond2Press.FirstOrDefault()!; + SelectedConstCond2PressValue = SelectedConstCond2Press.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond2PressInfo = MeterCond2PressToString(new List() { SelectedConstCond2Press }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstCond2PressValue = 0; + + ProStepCond2PressSwitchConstSlopIndex = 1; + + ListSlopMeterCond2Press = TempListMeterCond2Press.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterCond2PressItems = new ObservableCollection(ListSlopMeterCond2Press); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond2PressInfo = MeterCond2PressToString(ListSlopMeterCond2Press); + + //更新后检测时间是否匹配并界面提示 + CheckCond2PressSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepCond2PressSwitchConstSlopIndex = 1; + ListSlopMeterCond2Press = new List(); + ListSlopMeterCond2PressItems = new ObservableCollection(ListSlopMeterCond2Press); + SelectedConstCond2PressValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond2PressInfo = MeterCond2PressToString(ListSlopMeterCond2Press); + } + + + //////////////////////////EVAPExpTemp////////////////////////////////////// + var TempListMeterEVAPExpTemp = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEVAPExpTemps!.ToList(); + //判断是斜率还是常值 + if (TempListMeterEVAPExpTemp != null && TempListMeterEVAPExpTemp.Count > 0) + { + if (TempListMeterEVAPExpTemp.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterEVAPExpTemp = new List(); + ListSlopMeterEVAPExpTempItems = new ObservableCollection(ListSlopMeterEVAPExpTemp); + + //常值信息 + ProStepEVAPExpTempSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstEVAPExpTemp = TempListMeterEVAPExpTemp.FirstOrDefault()!; + SelectedConstEVAPExpTempValue = SelectedConstEVAPExpTemp.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEVAPExpTempInfo = MeterEVAPExpTempToString(new List() { SelectedConstEVAPExpTemp }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstEVAPExpTempValue = 0; + + ProStepEVAPExpTempSwitchConstSlopIndex = 1; + + ListSlopMeterEVAPExpTemp = TempListMeterEVAPExpTemp.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterEVAPExpTempItems = new ObservableCollection(ListSlopMeterEVAPExpTemp); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEVAPExpTempInfo = MeterEVAPExpTempToString(ListSlopMeterEVAPExpTemp); + + //更新后检测时间是否匹配并界面提示 + CheckEVAPExpTempSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepEVAPExpTempSwitchConstSlopIndex = 1; + ListSlopMeterEVAPExpTemp = new List(); + ListSlopMeterEVAPExpTempItems = new ObservableCollection(ListSlopMeterEVAPExpTemp); + SelectedConstEVAPExpTempValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEVAPExpTempInfo = MeterEVAPExpTempToString(ListSlopMeterEVAPExpTemp); + } + + + //////////////////////////ExPress////////////////////////////////////// + var TempListMeterExPress = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterExPresss!.ToList(); + //判断是斜率还是常值 + if (TempListMeterExPress != null && TempListMeterExPress.Count > 0) + { + if (TempListMeterExPress.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterExPress = new List(); + ListSlopMeterExPressItems = new ObservableCollection(ListSlopMeterExPress); + + //常值信息 + ProStepExPressSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstExPress = TempListMeterExPress.FirstOrDefault()!; + SelectedConstExPressValue = SelectedConstExPress.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterExPressInfo = MeterExPressToString(new List() { SelectedConstExPress }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstExPressValue = 0; + + ProStepExPressSwitchConstSlopIndex = 1; + + ListSlopMeterExPress = TempListMeterExPress.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterExPressItems = new ObservableCollection(ListSlopMeterExPress); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterExPressInfo = MeterExPressToString(ListSlopMeterExPress); + + //更新后检测时间是否匹配并界面提示 + CheckExPressSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepExPressSwitchConstSlopIndex = 1; + ListSlopMeterExPress = new List(); + ListSlopMeterExPressItems = new ObservableCollection(ListSlopMeterExPress); + SelectedConstExPressValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterExPressInfo = MeterExPressToString(ListSlopMeterExPress); + } + + + //////////////////////////HVVol////////////////////////////////////// + var TempListMeterHVVol = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterHVVols!.ToList(); + //判断是斜率还是常值 + if (TempListMeterHVVol != null && TempListMeterHVVol.Count > 0) + { + if (TempListMeterHVVol.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterHVVol = new List(); + ListSlopMeterHVVolItems = new ObservableCollection(ListSlopMeterHVVol); + + //常值信息 + ProStepHVVolSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstHVVol = TempListMeterHVVol.FirstOrDefault()!; + SelectedConstHVVolValue = SelectedConstHVVol.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterHVVolInfo = MeterHVVolToString(new List() { SelectedConstHVVol }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstHVVolValue = 0; + + ProStepHVVolSwitchConstSlopIndex = 1; + + ListSlopMeterHVVol = TempListMeterHVVol.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterHVVolItems = new ObservableCollection(ListSlopMeterHVVol); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterHVVolInfo = MeterHVVolToString(ListSlopMeterHVVol); + + //更新后检测时间是否匹配并界面提示 + CheckHVVolSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepHVVolSwitchConstSlopIndex = 1; + ListSlopMeterHVVol = new List(); + ListSlopMeterHVVolItems = new ObservableCollection(ListSlopMeterHVVol); + SelectedConstHVVolValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterHVVolInfo = MeterHVVolToString(ListSlopMeterHVVol); + } + + + //////////////////////////InhPress////////////////////////////////////// + var TempListMeterInhPress = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhPresss!.ToList(); + //判断是斜率还是常值 + if (TempListMeterInhPress != null && TempListMeterInhPress.Count > 0) + { + if (TempListMeterInhPress.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterInhPress = new List(); + ListSlopMeterInhPressItems = new ObservableCollection(ListSlopMeterInhPress); + + //常值信息 + ProStepInhPressSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstInhPress = TempListMeterInhPress.FirstOrDefault()!; + SelectedConstInhPressValue = SelectedConstInhPress.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterInhPressInfo = MeterInhPressToString(new List() { SelectedConstInhPress }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstInhPressValue = 0; + + ProStepInhPressSwitchConstSlopIndex = 1; + + ListSlopMeterInhPress = TempListMeterInhPress.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterInhPressItems = new ObservableCollection(ListSlopMeterInhPress); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterInhPressInfo = MeterInhPressToString(ListSlopMeterInhPress); + + //更新后检测时间是否匹配并界面提示 + CheckInhPressSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepInhPressSwitchConstSlopIndex = 1; + ListSlopMeterInhPress = new List(); + ListSlopMeterInhPressItems = new ObservableCollection(ListSlopMeterInhPress); + SelectedConstInhPressValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterInhPressInfo = MeterInhPressToString(ListSlopMeterInhPress); + } + + + + //////////////////////////InhTemp////////////////////////////////////// + var TempListMeterInhTemp = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhTemps!.ToList(); + //判断是斜率还是常值 + if (TempListMeterInhTemp != null && TempListMeterInhTemp.Count > 0) + { + if (TempListMeterInhTemp.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterInhTemp = new List(); + ListSlopMeterInhTempItems = new ObservableCollection(ListSlopMeterInhTemp); + + //常值信息 + ProStepInhTempSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstInhTemp = TempListMeterInhTemp.FirstOrDefault()!; + SelectedConstInhTempValue = SelectedConstInhTemp.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterInhTempInfo = MeterInhTempToString(new List() { SelectedConstInhTemp }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstInhTempValue = 0; + + ProStepInhTempSwitchConstSlopIndex = 1; + + ListSlopMeterInhTemp = TempListMeterInhTemp.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterInhTempItems = new ObservableCollection(ListSlopMeterInhTemp); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterInhTempInfo = MeterInhTempToString(ListSlopMeterInhTemp); + + //更新后检测时间是否匹配并界面提示 + CheckInhTempSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepInhTempSwitchConstSlopIndex = 1; + ListSlopMeterInhTemp = new List(); + ListSlopMeterInhTempItems = new ObservableCollection(ListSlopMeterInhTemp); + SelectedConstInhTempValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterInhTempInfo = MeterInhTempToString(ListSlopMeterInhTemp); + } + + + //////////////////////////LubePress////////////////////////////////////// + var TempListMeterLubePress = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLubePresss!.ToList(); + //判断是斜率还是常值 + if (TempListMeterLubePress != null && TempListMeterLubePress.Count > 0) + { + if (TempListMeterLubePress.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterLubePress = new List(); + ListSlopMeterLubePressItems = new ObservableCollection(ListSlopMeterLubePress); + + //常值信息 + ProStepLubePressSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstLubePress = TempListMeterLubePress.FirstOrDefault()!; + SelectedConstLubePressValue = SelectedConstLubePress.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterLubePressInfo = MeterLubePressToString(new List() { SelectedConstLubePress }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstLubePressValue = 0; + + ProStepLubePressSwitchConstSlopIndex = 1; + + ListSlopMeterLubePress = TempListMeterLubePress.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterLubePressItems = new ObservableCollection(ListSlopMeterLubePress); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterLubePressInfo = MeterLubePressToString(ListSlopMeterLubePress); + + //更新后检测时间是否匹配并界面提示 + CheckLubePressSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepLubePressSwitchConstSlopIndex = 1; + ListSlopMeterLubePress = new List(); + ListSlopMeterLubePressItems = new ObservableCollection(ListSlopMeterLubePress); + SelectedConstLubePressValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterLubePressInfo = MeterLubePressToString(ListSlopMeterLubePress); + } + + + //////////////////////////LVVol////////////////////////////////////// + var TempListMeterLVVol = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLVVols!.ToList(); + //判断是斜率还是常值 + if (TempListMeterLVVol != null && TempListMeterLVVol.Count > 0) + { + if (TempListMeterLVVol.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterLVVol = new List(); + ListSlopMeterLVVolItems = new ObservableCollection(ListSlopMeterLVVol); + + //常值信息 + ProStepLVVolSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstLVVol = TempListMeterLVVol.FirstOrDefault()!; + SelectedConstLVVolValue = SelectedConstLVVol.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterLVVolInfo = MeterLVVolToString(new List() { SelectedConstLVVol }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstLVVolValue = 0; + + ProStepLVVolSwitchConstSlopIndex = 1; + + ListSlopMeterLVVol = TempListMeterLVVol.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterLVVolItems = new ObservableCollection(ListSlopMeterLVVol); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterLVVolInfo = MeterLVVolToString(ListSlopMeterLVVol); + + //更新后检测时间是否匹配并界面提示 + CheckLVVolSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepLVVolSwitchConstSlopIndex = 1; + ListSlopMeterLVVol = new List(); + ListSlopMeterLVVolItems = new ObservableCollection(ListSlopMeterLVVol); + SelectedConstLVVolValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterLVVolInfo = MeterLVVolToString(ListSlopMeterLVVol); + } + + + + //////////////////////////OCR////////////////////////////////////// + var TempListMeterOCR = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOCRs!.ToList(); + //判断是斜率还是常值 + if (TempListMeterOCR != null && TempListMeterOCR.Count > 0) + { + if (TempListMeterOCR.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterOCR = new List(); + ListSlopMeterOCRItems = new ObservableCollection(ListSlopMeterOCR); + + //常值信息 + ProStepOCRSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstOCR = TempListMeterOCR.FirstOrDefault()!; + SelectedConstOCRValue = SelectedConstOCR.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOCRInfo = MeterOCRToString(new List() { SelectedConstOCR }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstOCRValue = 0; + + ProStepOCRSwitchConstSlopIndex = 1; + + ListSlopMeterOCR = TempListMeterOCR.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterOCRItems = new ObservableCollection(ListSlopMeterOCR); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOCRInfo = MeterOCRToString(ListSlopMeterOCR); + + //更新后检测时间是否匹配并界面提示 + CheckOCRSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepOCRSwitchConstSlopIndex = 1; + ListSlopMeterOCR = new List(); + ListSlopMeterOCRItems = new ObservableCollection(ListSlopMeterOCR); + SelectedConstOCRValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOCRInfo = MeterOCRToString(ListSlopMeterOCR); + } + + + + //////////////////////////OS1Temp////////////////////////////////////// + var TempListMeterOS1Temp = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS1Temps!.ToList(); + //判断是斜率还是常值 + if (TempListMeterOS1Temp != null && TempListMeterOS1Temp.Count > 0) + { + if (TempListMeterOS1Temp.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterOS1Temp = new List(); + ListSlopMeterOS1TempItems = new ObservableCollection(ListSlopMeterOS1Temp); + + //常值信息 + ProStepOS1TempSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstOS1Temp = TempListMeterOS1Temp.FirstOrDefault()!; + SelectedConstOS1TempValue = SelectedConstOS1Temp.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOS1TempInfo = MeterOS1TempToString(new List() { SelectedConstOS1Temp }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstOS1TempValue = 0; + + ProStepOS1TempSwitchConstSlopIndex = 1; + + ListSlopMeterOS1Temp = TempListMeterOS1Temp.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterOS1TempItems = new ObservableCollection(ListSlopMeterOS1Temp); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOS1TempInfo = MeterOS1TempToString(ListSlopMeterOS1Temp); + + //更新后检测时间是否匹配并界面提示 + CheckOS1TempSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepOS1TempSwitchConstSlopIndex = 1; + ListSlopMeterOS1Temp = new List(); + ListSlopMeterOS1TempItems = new ObservableCollection(ListSlopMeterOS1Temp); + SelectedConstOS1TempValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOS1TempInfo = MeterOS1TempToString(ListSlopMeterOS1Temp); + } + + + + //////////////////////////OS2Temp////////////////////////////////////// + var TempListMeterOS2Temp = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS2Temps!.ToList(); + //判断是斜率还是常值 + if (TempListMeterOS2Temp != null && TempListMeterOS2Temp.Count > 0) + { + if (TempListMeterOS2Temp.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterOS2Temp = new List(); + ListSlopMeterOS2TempItems = new ObservableCollection(ListSlopMeterOS2Temp); + + //常值信息 + ProStepOS2TempSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstOS2Temp = TempListMeterOS2Temp.FirstOrDefault()!; + SelectedConstOS2TempValue = SelectedConstOS2Temp.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOS2TempInfo = MeterOS2TempToString(new List() { SelectedConstOS2Temp }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstOS2TempValue = 0; + + ProStepOS2TempSwitchConstSlopIndex = 1; + + ListSlopMeterOS2Temp = TempListMeterOS2Temp.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterOS2TempItems = new ObservableCollection(ListSlopMeterOS2Temp); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOS2TempInfo = MeterOS2TempToString(ListSlopMeterOS2Temp); + + //更新后检测时间是否匹配并界面提示 + CheckOS2TempSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepOS2TempSwitchConstSlopIndex = 1; + ListSlopMeterOS2Temp = new List(); + ListSlopMeterOS2TempItems = new ObservableCollection(ListSlopMeterOS2Temp); + SelectedConstOS2TempValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOS2TempInfo = MeterOS2TempToString(ListSlopMeterOS2Temp); + } + + + + //////////////////////////PTCEntTemp////////////////////////////////////// + var TempListMeterPTCEntTemp = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCEntTemps!.ToList(); + //判断是斜率还是常值 + if (TempListMeterPTCEntTemp != null && TempListMeterPTCEntTemp.Count > 0) + { + if (TempListMeterPTCEntTemp.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterPTCEntTemp = new List(); + ListSlopMeterPTCEntTempItems = new ObservableCollection(ListSlopMeterPTCEntTemp); + + //常值信息 + ProStepPTCEntTempSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstPTCEntTemp = TempListMeterPTCEntTemp.FirstOrDefault()!; + SelectedConstPTCEntTempValue = SelectedConstPTCEntTemp.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCEntTempInfo = MeterPTCEntTempToString(new List() { SelectedConstPTCEntTemp }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstPTCEntTempValue = 0; + + ProStepPTCEntTempSwitchConstSlopIndex = 1; + + ListSlopMeterPTCEntTemp = TempListMeterPTCEntTemp.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterPTCEntTempItems = new ObservableCollection(ListSlopMeterPTCEntTemp); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCEntTempInfo = MeterPTCEntTempToString(ListSlopMeterPTCEntTemp); + + //更新后检测时间是否匹配并界面提示 + CheckPTCEntTempSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepPTCEntTempSwitchConstSlopIndex = 1; + ListSlopMeterPTCEntTemp = new List(); + ListSlopMeterPTCEntTempItems = new ObservableCollection(ListSlopMeterPTCEntTemp); + SelectedConstPTCEntTempValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCEntTempInfo = MeterPTCEntTempToString(ListSlopMeterPTCEntTemp); + } + + + + //////////////////////////PTCFlow////////////////////////////////////// + var TempListMeterPTCFlow = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCFlows!.ToList(); + //判断是斜率还是常值 + if (TempListMeterPTCFlow != null && TempListMeterPTCFlow.Count > 0) + { + if (TempListMeterPTCFlow.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterPTCFlow = new List(); + ListSlopMeterPTCFlowItems = new ObservableCollection(ListSlopMeterPTCFlow); + + //常值信息 + ProStepPTCFlowSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstPTCFlow = TempListMeterPTCFlow.FirstOrDefault()!; + SelectedConstPTCFlowValue = SelectedConstPTCFlow.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCFlowInfo = MeterPTCFlowToString(new List() { SelectedConstPTCFlow }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstPTCFlowValue = 0; + + ProStepPTCFlowSwitchConstSlopIndex = 1; + + ListSlopMeterPTCFlow = TempListMeterPTCFlow.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterPTCFlowItems = new ObservableCollection(ListSlopMeterPTCFlow); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCFlowInfo = MeterPTCFlowToString(ListSlopMeterPTCFlow); + + //更新后检测时间是否匹配并界面提示 + CheckPTCFlowSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepPTCFlowSwitchConstSlopIndex = 1; + ListSlopMeterPTCFlow = new List(); + ListSlopMeterPTCFlowItems = new ObservableCollection(ListSlopMeterPTCFlow); + SelectedConstPTCFlowValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCFlowInfo = MeterPTCFlowToString(ListSlopMeterPTCFlow); + } + + + + //////////////////////////PTCPw////////////////////////////////////// + var TempListMeterPTCPw = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCPws!.ToList(); + //判断是斜率还是常值 + if (TempListMeterPTCPw != null && TempListMeterPTCPw.Count > 0) + { + if (TempListMeterPTCPw.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterPTCPw = new List(); + ListSlopMeterPTCPwItems = new ObservableCollection(ListSlopMeterPTCPw); + + //常值信息 + ProStepPTCPwSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstPTCPw = TempListMeterPTCPw.FirstOrDefault()!; + SelectedConstPTCPwValue = SelectedConstPTCPw.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCPwInfo = MeterPTCPwToString(new List() { SelectedConstPTCPw }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstPTCPwValue = 0; + + ProStepPTCPwSwitchConstSlopIndex = 1; + + ListSlopMeterPTCPw = TempListMeterPTCPw.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterPTCPwItems = new ObservableCollection(ListSlopMeterPTCPw); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCPwInfo = MeterPTCPwToString(ListSlopMeterPTCPw); + + //更新后检测时间是否匹配并界面提示 + CheckPTCPwSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepPTCPwSwitchConstSlopIndex = 1; + ListSlopMeterPTCPw = new List(); + ListSlopMeterPTCPwItems = new ObservableCollection(ListSlopMeterPTCPw); + SelectedConstPTCPwValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCPwInfo = MeterPTCPwToString(ListSlopMeterPTCPw); + } + + + + //////////////////////////EnvRH////////////////////////////////////// + var TempListMeterEnvRH = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvRHs!.ToList(); + //判断是斜率还是常值 + if (TempListMeterEnvRH != null && TempListMeterEnvRH.Count > 0) + { + if (TempListMeterEnvRH.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterEnvRH = new List(); + ListSlopMeterEnvRHItems = new ObservableCollection(ListSlopMeterEnvRH); + + //常值信息 + ProStepEnvRHSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstEnvRH = TempListMeterEnvRH.FirstOrDefault()!; + SelectedConstEnvRHValue = SelectedConstEnvRH.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEnvRHInfo = MeterEnvRHToString(new List() { SelectedConstEnvRH }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstEnvRHValue = 0; + + ProStepEnvRHSwitchConstSlopIndex = 1; + + ListSlopMeterEnvRH = TempListMeterEnvRH.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterEnvRHItems = new ObservableCollection(ListSlopMeterEnvRH); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEnvRHInfo = MeterEnvRHToString(ListSlopMeterEnvRH); + + //更新后检测时间是否匹配并界面提示 + CheckEnvRHSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepEnvRHSwitchConstSlopIndex = 1; + ListSlopMeterEnvRH = new List(); + ListSlopMeterEnvRHItems = new ObservableCollection(ListSlopMeterEnvRH); + SelectedConstEnvRHValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEnvRHInfo = MeterEnvRHToString(ListSlopMeterEnvRH); + } + + + + //////////////////////////EnvTemp////////////////////////////////////// + var TempListMeterEnvTemp = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvTemps!.ToList(); + //判断是斜率还是常值 + if (TempListMeterEnvTemp != null && TempListMeterEnvTemp.Count > 0) + { + if (TempListMeterEnvTemp.Any(a => a.ValueType == ConfigValueType.Constant)) + { + //清空之前的步骤的斜率集合状态信息 + ListSlopMeterEnvTemp = new List(); + ListSlopMeterEnvTempItems = new ObservableCollection(ListSlopMeterEnvTemp); + + //常值信息 + ProStepEnvTempSwitchConstSlopIndex = 0; + //常值只有一个 + SelectedConstEnvTemp = TempListMeterEnvTemp.FirstOrDefault()!; + SelectedConstEnvTempValue = SelectedConstEnvTemp.Constant; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEnvTempInfo = MeterEnvTempToString(new List() { SelectedConstEnvTemp }); + + } + else//斜率 + { + //清空之前的步骤的常值集合状态信息 + SelectedConstEnvTempValue = 0; + + ProStepEnvTempSwitchConstSlopIndex = 1; + + ListSlopMeterEnvTemp = TempListMeterEnvTemp.Where(a => a.ValueType == ConfigValueType.Slope).ToList(); + ListSlopMeterEnvTempItems = new ObservableCollection(ListSlopMeterEnvTemp); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEnvTempInfo = MeterEnvTempToString(ListSlopMeterEnvTemp); + + //更新后检测时间是否匹配并界面提示 + CheckEnvTempSlopListTime(); + } + } + else + { + //为空,一次也没有设置数据 + //清空之前的步骤的斜率/常值集合状态信息 + ProStepEnvTempSwitchConstSlopIndex = 1; + ListSlopMeterEnvTemp = new List(); + ListSlopMeterEnvTempItems = new ObservableCollection(ListSlopMeterEnvTemp); + SelectedConstEnvTempValue = 0; + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEnvTempInfo = MeterEnvTempToString(ListSlopMeterEnvTemp); + } + + + } + } + + + + private DelegateCommand _GridSelectedCellsChangedCmd; + /// + /// 选中列数据命令 + /// + public DelegateCommand GridSelectedCellsChangedCmd + { + set + { + _GridSelectedCellsChangedCmd = value; + } + get + { + if (_GridSelectedCellsChangedCmd == null) + { + _GridSelectedCellsChangedCmd = new DelegateCommand((par) => GridSelectedCellsChangedCmdMethod(par)); + } + return _GridSelectedCellsChangedCmd; + } + } + /// + /// 选中列数据命令执行方法 + /// + private void GridSelectedCellsChangedCmdMethod(object par) + { + ////Get the newly selected cells + //IList selectedcells = e.AddedCells; + + ////Get the value of each newly selected cell + //foreach (DataGridCellInfo di in selectedcells) + //{ + // //Cast the DataGridCellInfo.Item to the source object type + // //In this case the ItemsSource is a DataTable and individual items are DataRows + // DataRowView dvr = (DataRowView)di.Item; + + // //Clear values for all newly selected cells + // AdventureWorksLT2008DataSet.CustomerRow cr = (AdventureWorksLT2008DataSet.CustomerRow)dvr.Row; + // cr.BeginEdit(); + // cr.SetField(di.Column.DisplayIndex, ""); + // cr.EndEdit(); + //} + + var dd = par; + //var dd = new SelectedCellsCollection(); + //if (par is SelectedCellCo selectedCells) + //{ + // foreach (var cellInfo in selectedCells) + // { + // var column = cellInfo.Column; + // var item = cellInfo.Item; + // // Perform actions with the selected column and item + // // For example, display the column header + // System.Diagnostics.Debug.WriteLine($"Selected Column: {column.Header}, Item: {item}"); + // } + //} + } + + //GridSelectedCellsChangedCmd + + + + private DelegateCommand _ProStepAddCmd; + /// + /// 新增命令 + /// + public DelegateCommand ProStepAddCmd + { + set + { + _ProStepAddCmd = value; + } + get + { + if (_ProStepAddCmd == null) + { + _ProStepAddCmd = new DelegateCommand(() => ProStepAddCmdMethod()); + } + return _ProStepAddCmd; + } + } + + /// + /// 新增命令执行方法 + /// + private void ProStepAddCmdMethod() + { + //创建步骤数据,先创建步骤数据 + var NewStepData = new ProStep() + { + StepNo = AutoGetProStepNo(), + StepRepeat = ProStepCycleCount, + SpeedCycle = (int)MeterSpeedExDto.SlopCycle, + ProgramSegId = SelectedProgramSeg.Id, + Remark = "", + }; + //返回的创建步骤数据 + var InsertStepData = FreeSql.Insert(NewStepData).ExecuteInserted().FirstOrDefault(); + + //当前的速度表集合数据 速度表 + var CurMeterSpeeds = ListSlopMeterSpeedItems.ToList(); + if (CurMeterSpeeds != null && CurMeterSpeeds.Count() > 0) + { + //新增时有预设的速度工况时增加速度数据 + //更新要新增速度数据的Id + foreach (var item in CurMeterSpeeds) + { + item.ProStepId = InsertStepData!.Id; + } + FreeSql.Insert(CurMeterSpeeds).ExecuteAffrows(); + } + + //重新查询获取的数据包括子集 + var GetInsertStepData = RefreshProStepById(InsertStepData!.Id); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + //var CurIndex = InsertStepData.StepNo - 1; + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Count(), + SelectedProgramSeg!.ProSteps!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Insert(CurIndex, GetInsertStepData); + //SelectedProgramSeg!.ProSteps!.OrderBy(a => a.StepNo); + //新增数据到集合中 + ListProStep.Insert(CurIndex, GetInsertStepData); + + //新增数据到界面集合中,新增时当时最多有速度,所以展示数据时只要展示速度就行 + ListProStepDtoItems.Insert(CurIndex, new ProStepDto() + { + Id = GetInsertStepData.Id, + StepNo = GetInsertStepData.StepNo, + StepRepeat = GetInsertStepData.StepRepeat, + SpeedCycle = new CycleInfoDto() { Cycle = GetInsertStepData.SpeedCycle, IsSlop = CheckIsSlop(GetInsertStepData.MeterSpeeds!.Select(p => new MeterCom() { ValueType = p.ValueType }).ToList()) }, + SpeedInfo = MeterSpeedToString(GetInsertStepData.MeterSpeeds!.ToList()), + //MeterCond1TempInfo= MeterCond1TempToString(GetInsertStepData.MeterCond1Temps!.ToList()), + }); + } + + + + private DelegateCommand _ProStepEditCmd; + /// + /// 编辑命令 + /// + public DelegateCommand ProStepEditCmd + { + set + { + _ProStepEditCmd = value; + } + get + { + if (_ProStepEditCmd == null) + { + _ProStepEditCmd = new DelegateCommand(() => ProStepEditCmdMethod()); + } + return _ProStepEditCmd; + } + } + + /// + /// 编辑命令执行方法 + /// + private void ProStepEditCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("请选择后再进行编辑"); + return; + } + + var UpdateData = FreeSql.Update() + .Set(a => a.StepRepeat, ProStepCycleCount) + .Set(a => a.StepNo, ProStepProNo) + .Where(a => a.Id == SelectedProStepDto.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateStepData = RefreshProStepById(UpdateData!.Id); + var CurIndex = ListProStep.FindIndex(a => a.Id == UpdateData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.Remove(ListProStep.Find(a => a.Id == SelectedProStepDto!.Id)!); + //移除旧的数据 + ListProStep.Remove(ListProStep.Find(a => a.Id == UpdateData!.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.Insert(CurIndex, GetUpdateStepData); + //SelectedProgramSeg!.ProSteps!.OrderBy(a => a.StepNo); + //新增数据 + ListProStep.Insert(CurIndex, GetUpdateStepData); + + //移除旧的数据 + ListProStepDtoItems.Remove(ListProStepDtoItems.Where(a => a.Id == UpdateData!.Id).FirstOrDefault()!); + ListProStepDtoItems.Insert(CurIndex, GetProStepDtoMsg(GetUpdateStepData)); + } + + + private DelegateCommand _ProStepCopyCmd; + /// + /// 复制命令 + /// + public DelegateCommand ProStepCopyCmd + { + set + { + _ProStepCopyCmd = value; + } + get + { + if (_ProStepCopyCmd == null) + { + _ProStepCopyCmd = new DelegateCommand(() => ProStepCopyCmdMethod()); + } + return _ProStepCopyCmd; + } + } + /// + /// 复制命令执行方法 + /// + private void ProStepCopyCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("请选择后再进行编辑"); + return; + } + + var SelectedStep = ListProStep.Find(a => a.Id == SelectedProStepDto!.Id); + if (SelectedStep != null) + { + //联集增加 + var RepoProStep = FreeSql.GetRepository(); + RepoProStep.DbContextOptions.EnableCascadeSave = true; + + //要复制的ProStep + var SelectedCopyStep = SelectedStep.DeepClone(); + //更改序号和复位Id + SelectedCopyStep.StepNo = AutoGetProStepNo(); + SetModelId0(SelectedCopyStep); + + var InsertStepData = RepoProStep.Insert(SelectedCopyStep); + + //重新查询获取的数据包括子集 + var GetInsertStepData = RefreshProStepById(InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Count(), + SelectedProgramSeg!.ProSteps!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Insert(CurIndex, GetInsertStepData); + //SelectedProgramSeg!.ProSteps!.OrderBy(a => a.StepNo); + //新增数据到集合中 + ListProStep.Insert(CurIndex, GetInsertStepData); + + //新增数据到界面集合中,新增时当时最多有速度,所以展示数据时只要展示速度就行 + ListProStepDtoItems.Insert(CurIndex, GetProStepDtoMsg(GetInsertStepData)); + } + + + } + + private DelegateCommand _ProStepDeleteCmd; + /// + /// 删除命令 + /// + public DelegateCommand ProStepDeleteCmd + { + set + { + _ProStepDeleteCmd = value; + } + get + { + if (_ProStepDeleteCmd == null) + { + _ProStepDeleteCmd = new DelegateCommand(() => ProStepDeleteCmdMethod()); + } + return _ProStepDeleteCmd; + } + } + + /// + /// 删除命令执行方法 + /// + private void ProStepDeleteCmdMethod() + { + if (SelectedProStepDto == null && SelectedProgramSeg != null) + { + MessageBox.Show("请选择后再进行删除"); + return; + } + + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + //联级别删除 + var repo = FreeSql.GetRepository(); + repo.DbContextOptions.EnableCascadeSave = true; //关键设置 + + var data = repo.Select.Where(a => a.Id == SelectedProStepDto!.Id) + .IncludeMany(b => b.MeterCond1Temps) + .IncludeMany(b => b.MeterCond2Temps) + .IncludeMany(b => b.MeterCond2Presss) + .IncludeMany(b => b.MeterEVAPExpTemps) + .IncludeMany(b => b.MeterExPresss) + .IncludeMany(b => b.MeterHVVols) + .IncludeMany(b => b.MeterInhPresss) + .IncludeMany(b => b.MeterInhTemps) + .IncludeMany(b => b.MeterLubePresss) + .IncludeMany(b => b.MeterLVVols) + .IncludeMany(b => b.MeterOCRs) + .IncludeMany(b => b.MeterOS1Temps) + .IncludeMany(b => b.MeterOS2Temps) + .IncludeMany(b => b.MeterPTCEntTemps) + .IncludeMany(b => b.MeterPTCFlows) + .IncludeMany(b => b.MeterPTCPws) + .IncludeMany(b => b.MeterEnvRHs) + .IncludeMany(b => b.MeterEnvTemps) + //.IncludeMany(a => a.QuickClutchStepCells) + //.IncludeMany(a => a.QuickVoltageStepCells) + .ToList(); + + repo.Delete(data); + //var UpdateData = ReFreshProSegById(InsertedData.FirstOrDefault()!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.Remove(ListProStep.Find(a => a.Id == SelectedProStepDto!.Id)!); + //移除旧的数据 + ListProStep.Remove(ListProStep.Find(a => a.Id == SelectedProStepDto!.Id)!); + + //移除旧的数据 + ListProStepDtoItems.Remove(ListProStepDtoItems.Where(a => a.Id == SelectedProStepDto!.Id).FirstOrDefault()!); + + //清除内容区域的数据 + ClearCurMeterData(); + } + } + + private void RefreshProStepData() + { + ListProStep = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.ToList(); + ListProStepDtoItems.Clear(); + foreach (var item in ListProStep) + { + ListProStepDtoItems.Add(new ProStepDto() + { + Id = item.Id, + StepNo = item.StepNo, + StepRepeat = item.StepRepeat, + SpeedInfo = MeterSpeedToString(item.MeterSpeeds!.ToList()) + }); + } + } + + /// + /// 根据ID获取ProStep数据 + /// + /// + private ProStep RefreshProStepById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .IncludeMany(b => b.MeterSpeeds) + .IncludeMany(b => b.MeterCond1Temps) + .IncludeMany(b => b.MeterCond2Temps) + .IncludeMany(b => b.MeterCond2Presss) + .IncludeMany(b => b.MeterEVAPExpTemps) + .IncludeMany(b => b.MeterExPresss) + .IncludeMany(b => b.MeterHVVols) + .IncludeMany(b => b.MeterInhPresss) + .IncludeMany(b => b.MeterInhTemps) + .IncludeMany(b => b.MeterLubePresss) + .IncludeMany(b => b.MeterLVVols) + .IncludeMany(b => b.MeterOCRs) + .IncludeMany(b => b.MeterOS1Temps) + .IncludeMany(b => b.MeterOS2Temps) + .IncludeMany(b => b.MeterPTCEntTemps) + .IncludeMany(b => b.MeterPTCFlows) + .IncludeMany(b => b.MeterPTCPws) + .IncludeMany(b => b.MeterEnvRHs) + .IncludeMany(b => b.MeterEnvTemps) + .ToList(); + //【+++】 + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new ProStep(); + } + } + + + /// + /// 获取ProStepDto 的信息数据 + /// + /// + /// + private ProStepDto GetProStepDtoMsg(ProStep proStep) + { + if (proStep != null) + { + var Data = new ProStepDto() + { + Id = proStep.Id, + StepNo = proStep.StepNo, + StepRepeat = proStep.StepRepeat, + SpeedCycle = new CycleInfoDto() { Cycle = proStep.SpeedCycle, IsSlop = CheckIsSlop(proStep.MeterSpeeds!.Select(p => new MeterCom() { ValueType = p.ValueType }).ToList()) }, + SpeedInfo = MeterSpeedToString(proStep.MeterSpeeds!.ToList()), + MeterCond1TempInfo = MeterCond1TempToString(proStep.MeterCond1Temps!.ToList()), + MeterCond2TempInfo = MeterCond2TempToString(proStep.MeterCond2Temps!.ToList()), + MeterCond2PressInfo = MeterCond2PressToString(proStep.MeterCond2Presss!.ToList()), + MeterEVAPExpTempInfo = MeterEVAPExpTempToString(proStep.MeterEVAPExpTemps!.ToList()), + MeterExPressInfo = MeterExPressToString(proStep.MeterExPresss!.ToList()), + MeterHVVolInfo = MeterHVVolToString(proStep.MeterHVVols!.ToList()), + MeterInhPressInfo = MeterInhPressToString(proStep.MeterInhPresss!.ToList()), + MeterInhTempInfo = MeterInhTempToString(proStep.MeterInhTemps!.ToList()), + MeterLubePressInfo = MeterLubePressToString(proStep.MeterLubePresss!.ToList()), + MeterLVVolInfo = MeterLVVolToString(proStep.MeterLVVols!.ToList()), + MeterOCRInfo = MeterOCRToString(proStep.MeterOCRs!.ToList()), + MeterOS1TempInfo = MeterOS1TempToString(proStep.MeterOS1Temps!.ToList()), + MeterOS2TempInfo = MeterOS2TempToString(proStep.MeterOS2Temps!.ToList()), + MeterPTCEntTempInfo = MeterPTCEntTempToString(proStep.MeterPTCEntTemps!.ToList()), + MeterPTCFlowInfo = MeterPTCFlowToString(proStep.MeterPTCFlows!.ToList()), + MeterPTCPwInfo = MeterPTCPwToString(proStep.MeterPTCPws!.ToList()), + MeterEnvRHInfo = MeterEnvRHToString(proStep.MeterEnvRHs!.ToList()), + MeterEnvTempInfo = MeterEnvTempToString(proStep.MeterEnvTemps!.ToList()), + + }; + //【+++】 + return Data; + } + + return new ProStepDto(); + + } + + /// + /// 清除当前的ProStep的数据 + /// + private void ClearCurProStepData() + { + ListProStepDtoItems.Clear(); + ListProStep.Clear(); + //【+++】 + + + } + + /// + /// 清除当前的仪表的数据 + /// + private void ClearCurMeterData() + { + //速度 + ListSlopMeterSpeedItems.Clear(); + ListSlopMeterSpeed.Clear(); + SelectedSlopMeterSpeed = new MeterSpeed(); + MeterSpeedExDto = new MeterExInfoDto(); + SelectedConstSpeed = new MeterSpeed(); + + //【+++】 + + + } + + #endregion + + + #region 选择下载的操作 + + private ObservableCollection _ProSegRunListViewItems = new ObservableCollection(); + /// + /// 程序运行 数据集合 + /// + public ObservableCollection ProSegRunListViewItems + { + get { return _ProSegRunListViewItems; } + set { _ProSegRunListViewItems = value; RaisePropertyChanged(); } + } + + + private ProSegRun _ProSegRunSelectedItems; + /// + /// 选中的程序集合 + /// + public ProSegRun ProSegRunSelectedItems + { + get { return _ProSegRunSelectedItems; } + set { _ProSegRunSelectedItems = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _ProRunSelectedAdd; + /// + /// 新增命令 + /// + public DelegateCommand ProRunSelectedAdd + { + set + { + _ProRunSelectedAdd = value; + } + get + { + if (_ProRunSelectedAdd == null) + { + _ProRunSelectedAdd = new DelegateCommand(() => ProRunSelectedAddMethod()); + } + return _ProRunSelectedAdd; + } + } + /// + /// 选择增加方法 + /// + /// + private void ProRunSelectedAddMethod() + { + if (SelectedProgramSeg != null && ListProStep != null) + { + var InsertData = FreeSql.Insert(new ProSegRun() + { + Name = SelectedProgramSeg.Name, + StepNo = 1, + ProgramSegId = SelectedProgramSeg.Id, + }).ExecuteInserted(); + + //新增 + ProSegRunListViewItems.Add(InsertData.FirstOrDefault()!); + + } + else + { + MessageBox.Show("请选择后再操作!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + private DelegateCommand _ProRunSelectedDelete; + /// + /// 删除命令 + /// + public DelegateCommand ProRunSelectedDelete + { + set + { + _ProRunSelectedDelete = value; + } + get + { + if (_ProRunSelectedDelete == null) + { + _ProRunSelectedDelete = new DelegateCommand(() => ProRunSelectedDeleteMethod()); + } + return _ProRunSelectedDelete; + } + } + /// + /// 选择删除方法 + /// + /// + private void ProRunSelectedDeleteMethod() + { + if (ProSegRunSelectedItems != null) + { + var DeleteData = FreeSql.Delete(ProSegRunSelectedItems.Id).ExecuteDeleted(); + + //删除 DeleteData.FirstOrDefault()! + ProSegRunListViewItems.Remove(ProSegRunListViewItems.FirstOrDefault(a => a.Id == DeleteData.FirstOrDefault()!.Id)!); + + } + else + { + MessageBox.Show("请选择后再操作!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + private DelegateCommand _GenProPlcCmd; + /// + /// 新增命令 + /// + public DelegateCommand GenProPlcCmd + { + set + { + _GenProPlcCmd = value; + } + get + { + if (_GenProPlcCmd == null) + { + _GenProPlcCmd = new DelegateCommand(() => GenProPlcCmdMethod()); + } + return _GenProPlcCmd; + } + } + /// + /// 生产下载执行方法 + /// + private void GenProPlcCmdMethod() + { + if (ProSegRunListViewItems != null && ProSegRunListViewItems.Count() > 0) + { + //var Data=FreeSql.Select( + foreach (var item in ProSegRunListViewItems) + { + var FindData = FreeSql.Select(item.ProgramSegId) + .IncludeMany(a => a.ProSteps, + then => then.IncludeMany(b => b.MeterSpeeds) + .IncludeMany(b => b.MeterCond1Temps) + .IncludeMany(b => b.MeterCond2Temps) + .IncludeMany(b => b.MeterCond2Presss) + .IncludeMany(b => b.MeterEVAPExpTemps) + .IncludeMany(b => b.MeterExPresss) + .IncludeMany(b => b.MeterHVVols) + .IncludeMany(b => b.MeterInhPresss) + .IncludeMany(b => b.MeterInhTemps) + .IncludeMany(b => b.MeterLubePresss) + .IncludeMany(b => b.MeterLVVols) + .IncludeMany(b => b.MeterOCRs) + .IncludeMany(b => b.MeterOS1Temps) + .IncludeMany(b => b.MeterOS2Temps) + .IncludeMany(b => b.MeterPTCEntTemps) + .IncludeMany(b => b.MeterPTCFlows) + .IncludeMany(b => b.MeterPTCPws) + .IncludeMany(b => b.MeterEnvRHs) + .IncludeMany(b => b.MeterEnvTemps) + ).ToList().FirstOrDefault(); + + if (FindData != null && FindData.ProSteps != null) + { + var ReturnPlcParsData = ProParsHelper.GetPlcParsData(FindData.ProSteps, 1); + ProParsHelper.LoadDataToPLC(MachineRtDataService.SiemensDrive, ReturnPlcParsData); + } + + } + + } + + } + + + + + #endregion + + #region 速度表操作 + + + //#region 拓展的属性 + + //private int _ParNo; + ///// + ///// 参数编号(1~16) + ///// 跟随速度步骤的常值数据 + ///// + //public int ParNo + //{ + // get { return _ParNo; } + // set { _ParNo = value; RaisePropertyChanged(); } + //} + + + //private bool _OutLock; + ///// + ///// 输出锁定(0/1) + ///// 跟随速度步骤的常值数据 + ///// + //public bool OutLock + //{ + // get { return _OutLock; } + // set { _OutLock = value; RaisePropertyChanged(); } + //} + + + //private int _Ev; + ///// + ///// EV(1~4) + ///// 跟随速度步骤的常值数据 + ///// + //public int Ev + //{ + // get { return _Ev; } + // set { _Ev = value; RaisePropertyChanged(); } + //} + + //private bool _CapEnable; + ///// + /////压缩机使能(0/1) + ///// 跟随速度步骤的常值数据 + ///// + //public bool CapEnable + //{ + // get { return _CapEnable; } + // set { _CapEnable = value; RaisePropertyChanged(); } + //} + + + //private bool _InhExhValve; + ///// + /////吸排气阀(0/1) + ///// 跟随速度步骤的常值数据 + ///// + //public bool InhExhValve + //{ + // get { return _InhExhValve; } + // set { _InhExhValve = value; RaisePropertyChanged(); } + //} + + //private bool _HeatEnable; + ///// + /////加热器使能(0/1) + ///// 跟随速度步骤的常值数据 + ///// + //public bool HeatEnable + //{ + // get { return _HeatEnable; } + // set { _HeatEnable = value; RaisePropertyChanged(); } + //} + + //#endregion + + + private ObservableCollection _ListSlopMeterSpeedItems; + /// + /// MeterSpeedp数据集合 + /// + public ObservableCollection ListSlopMeterSpeedItems + { + get { return _ListSlopMeterSpeedItems; } + set { _ListSlopMeterSpeedItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterSpeed集合数据 斜率 + /// + public List ListSlopMeterSpeed { get; set; } + + + private MeterSpeed _SelectedSlopMeterSpeed; + /// + /// 当前选中的程序速度 带斜率的 + /// + public MeterSpeed SelectedSlopMeterSpeed + { + get { return _SelectedSlopMeterSpeed; } + set { _SelectedSlopMeterSpeed = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterSpeedExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 速度 + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterSpeedExDto + { + get { return _MeterSpeedExDto; } + set { _MeterSpeedExDto = value; RaisePropertyChanged(); } + } + + + private bool _ProStepSpeedSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 Speed + /// + public bool ProStepSpeedSwitchConstSlopPar + { + get { return _ProStepSpeedSwitchConstSlopPar; } + set { _ProStepSpeedSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + private bool _SpeedTabControlEnable; + /// + /// 控件是否启用 + /// + public bool SpeedTabControlEnable + { + get { return _SpeedTabControlEnable; } + set { _SpeedTabControlEnable = value; RaisePropertyChanged(); } + } + + + private int _ProStepSpeedSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Speed + /// + public int ProStepSpeedSwitchConstSlopIndex + { + get { return _ProStepSpeedSwitchConstSlopIndex; } + set { _ProStepSpeedSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + private bool _OtherParTabControlEnable; + /// + /// 其他参数控件是否启用 + /// + public bool OtherParTabControlEnable + { + get { return _SpeedTabControlEnable; } + set { _SpeedTabControlEnable = value; RaisePropertyChanged(); } + } + + + + + private MeterSpeed _SelectedConstSpeed; + /// + /// 当前选中的程序 MeterSpeed 常值 + /// + public MeterSpeed SelectedConstSpeed + { + get { return _SelectedConstSpeed; } + set { _SelectedConstSpeed = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstSpeedValue; + /// + /// 常值模式设置的数据 MeterSpeed + /// + public double SelectedConstSpeedValue + { + get { return _SelectedConstSpeedValue; } + set { _SelectedConstSpeedValue = value; RaisePropertyChanged(); } + } + + private int _SelectedConstSpeedTimeValue; + /// + /// 常值模式设置的时间数据 MeterSpeed + /// 因为没有多个步骤合并统计时间,此时间是当前步骤的总时间 + /// + public int SelectedConstSpeedTimeValue + { + get { return _SelectedConstSpeedTimeValue; } + set { _SelectedConstSpeedTimeValue = value; RaisePropertyChanged(); } + } + + private DelegateCommand _SpeedConstSlopSelectChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand SpeedConstSlopSelectChangedCmd + { + set + { + _SpeedConstSlopSelectChangedCmd = value; + } + get + { + if (_SpeedConstSlopSelectChangedCmd == null) + { + _SpeedConstSlopSelectChangedCmd = new DelegateCommand((str) => SpeedConstSlopSelectChangedCmdMethod(str)); + } + return _SpeedConstSlopSelectChangedCmd; + } + } + /// + /// 速度 常值和斜率切换命令 + /// + /// + private void SpeedConstSlopSelectChangedCmdMethod(object par) + { + if ((int)par == 0) + { + ProStepSpeedSwitchConstSlopPar = false; + //ProStepSpeedSwitchConstSlopIndex = 1; + } + else + { + ProStepSpeedSwitchConstSlopPar = true; + //ProStepSpeedSwitchConstSlopIndex = 0; + } + } + + private DelegateCommand _MeterSpeedSlopCycleLostFocusCmd; + /// + /// 速度循环个数 鼠标输入完毕的操作 + /// + public DelegateCommand MeterSpeedSlopCycleLostFocusCmd + { + set + { + _MeterSpeedSlopCycleLostFocusCmd = value; + } + get + { + if (_MeterSpeedSlopCycleLostFocusCmd == null) + { + _MeterSpeedSlopCycleLostFocusCmd = new DelegateCommand((str) => MeterSpeedSlopCycleLostFocusCmdMethod(str)); + } + return _MeterSpeedSlopCycleLostFocusCmd; + } + } + /// + /// 速度速度循环个数 鼠标输入完毕的操作 + /// + /// + private void MeterSpeedSlopCycleLostFocusCmdMethod(object par) + { + if (MeterSpeedExDto.SlopCycle >= 0) + { + var dara = MeterSpeedExDto.SlopCycle; + + //更新循环个数信息 + FreeSql.Update() + .Set(a => a.SpeedCycle, (int)MeterSpeedExDto.SlopCycle) + .Where(a => a.Id == SelectedProStepDto!.Id) + .ExecuteAffrows(); + + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).SpeedCycle = (int)MeterSpeedExDto.SlopCycle; + SelectedProStepDto.SpeedCycle.Cycle = (int)MeterSpeedExDto.SlopCycle; + CheckSpeedSlopListTime(); + } + else + { + MessageBox.Show("输入的循环个数应该大于或等于0!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + + } + + + private DelegateCommand _SpeedConstSaveCmd; + /// + ///速度常值保存命令 + /// + public DelegateCommand SpeedConstSaveCmd + { + set + { + _SpeedConstSaveCmd = value; + } + get + { + if (_SpeedConstSaveCmd == null) + { + _SpeedConstSaveCmd = new DelegateCommand(() => SpeedConstSaveCmdMethod()); + } + return _SpeedConstSaveCmd; + } + } + /// + /// 常值保存命令 速度 + /// + /// + private void SpeedConstSaveCmdMethod() + { + //SelectedConstSpeedValue + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterSpeedItems != null && ListSlopMeterSpeedItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterSpeedItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData!); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterSpeeds!.Remove(ListSlopMeterSpeed.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterSpeed.Remove(ListSlopMeterSpeed.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterSpeedItems.Remove(ListSlopMeterSpeedItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.SpeedInfo = MeterSpeedToString(ListSlopMeterSpeed); + + //更新后检测时间是否匹配并界面提示 + CheckSpeedSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstSpeedData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterSpeeds!.ToList(); + SelectedProStepDto.SpeedCycle!.IsSlop = false; + if (ConstSpeedData != null && ConstSpeedData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterSpeedData = new MeterSpeed() + { + Constant = SelectedConstSpeedValue, + ValueType = ConfigValueType.Constant, + KeepTime = SelectedConstSpeedTimeValue, + ProStepId = SelectedProStepDto.Id, + InhExhValve = SelectedSlopMeterSpeed.InhExhValve, + Ev = SelectedSlopMeterSpeed.Ev, + HeatEnable = SelectedSlopMeterSpeed.HeatEnable, + CapEnable = SelectedSlopMeterSpeed.CapEnable, + OutLock = SelectedSlopMeterSpeed.OutLock, + ParNo = SelectedSlopMeterSpeed.ParNo, + //StepNo = AutoGetMeterSpeedStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterSpeedData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshSpeedById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterSpeeds!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.SpeedInfo = MeterSpeedToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstSpeedData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstSpeedValue) + .Set(a => a.KeepTime, SelectedConstSpeedTimeValue) + .Set(a => a.ParNo, SelectedSlopMeterSpeed.ParNo) + .Set(a => a.OutLock, SelectedSlopMeterSpeed.OutLock) + .Set(a => a.CapEnable, SelectedSlopMeterSpeed.CapEnable) + .Set(a => a.Ev, SelectedSlopMeterSpeed.Ev) + .Set(a => a.HeatEnable, SelectedSlopMeterSpeed.HeatEnable) + .Set(a => a.InhExhValve, SelectedSlopMeterSpeed.InhExhValve) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshSpeedById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterSpeeds!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterSpeeds!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.SpeedInfo = MeterSpeedToString(new List() { GetUpdateData }); + + } + + } + + + private DelegateCommand _MeterSpeedSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterSpeedSelectedChangedCmd + { + set + { + _MeterSpeedSelectedChangedCmd = value; + } + get + { + if (_MeterSpeedSelectedChangedCmd == null) + { + _MeterSpeedSelectedChangedCmd = new DelegateCommand((str) => MeterSpeedSelectedChangedCmdMethod(str)); + } + return _MeterSpeedSelectedChangedCmd; + } + } + + + /// + /// 速度表选中行的执行方法 + /// + /// + /// + private void MeterSpeedSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterSpeed; + if (SelectedData != null) + { + SelectedSlopMeterSpeed = new MeterSpeed() + { + CapEnable = SelectedData.CapEnable, + Constant = SelectedData.Constant, + KeepTime = SelectedData.KeepTime, + CreateTime = SelectedData.CreateTime, + EndValue = SelectedData.EndValue, + Ev = SelectedData.Ev, + HeatEnable = SelectedData.HeatEnable, + Id = SelectedData.Id, + InhExhValve = SelectedData.InhExhValve, + OutLock = SelectedData.OutLock, + ParNo = SelectedData.ParNo, + ProStep = SelectedData.ProStep, + ProStepId = SelectedData.ProStepId, + StartValue = SelectedData.StartValue, + StepNo = SelectedData.StepNo, + ValueType = SelectedData.ValueType + }; + + + //ParNo = SelectedSlopMeterSpeed.ParNo; + //OutLock = SelectedSlopMeterSpeed.OutLock; + //Ev = SelectedSlopMeterSpeed.Ev; + //CapEnable = SelectedSlopMeterSpeed.CapEnable; + //InhExhValve = SelectedSlopMeterSpeed.InhExhValve; + //HeatEnable = SelectedSlopMeterSpeed.HeatEnable; + + } + + } + + + + private DelegateCommand _ProStepSpeedAddCmd; + /// + /// 新增速度命令 + /// + public DelegateCommand ProStepSpeedAddCmd + { + set + { + _ProStepSpeedAddCmd = value; + } + get + { + if (_ProStepSpeedAddCmd == null) + { + _ProStepSpeedAddCmd = new DelegateCommand(() => ProStepSpeedAddCmdMethod()); + } + return _ProStepSpeedAddCmd; + } + } + + /// + /// 新增速度命令执行方法 + /// + private void ProStepSpeedAddCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterSpeed.Sum(a => a.KeepTime) + SelectedSlopMeterSpeed.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterSpeeds!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterSpeeds!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterSpeeds!.Remove(ConstData!); + } + + + + //当前的速度表集合数据 + var MeterSpeeds = ListSlopMeterSpeedItems.ToList(); + + var MeterSpeedData = new MeterSpeed() + { + StartValue = SelectedSlopMeterSpeed.StartValue, + EndValue = SelectedSlopMeterSpeed.EndValue, + KeepTime = SelectedSlopMeterSpeed.KeepTime, + ProStepId = SelectedProStepDto.Id, + InhExhValve = SelectedSlopMeterSpeed.InhExhValve, + Ev = SelectedSlopMeterSpeed.Ev, + HeatEnable = SelectedSlopMeterSpeed.HeatEnable, + CapEnable = SelectedSlopMeterSpeed.CapEnable, + OutLock = SelectedSlopMeterSpeed.OutLock, + ParNo = SelectedSlopMeterSpeed.ParNo, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterSpeedStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterSpeedData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshSpeedById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + //var CurIndex = GetInsertData.StepNo - 1; + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterSpeeds!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterSpeeds!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterSpeeds!.Max(a => a.StepNo) : 0); + + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterSpeeds!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterSpeed.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterSpeedItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.SpeedInfo = MeterSpeedToString(ListSlopMeterSpeed); + + + + //更新后检测时间是否匹配并界面提示 + CheckSpeedSlopListTime(); + + } + + + private DelegateCommand _ProStepSpeedEditCmd; + /// + /// 修改速度命令 + /// + public DelegateCommand ProStepSpeedEditCmd + { + set + { + _ProStepSpeedEditCmd = value; + } + get + { + if (_ProStepSpeedEditCmd == null) + { + _ProStepSpeedEditCmd = new DelegateCommand(() => ProStepSpeedEditCmdMethod()); + } + return _ProStepSpeedEditCmd; + } + } + + /// + /// 新增速度命令执行方法 + /// + private void ProStepSpeedEditCmdMethod() + { + if (SelectedProStepDto == null || SelectedSlopMeterSpeed == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterSpeed.Where(a => a.Id != SelectedSlopMeterSpeed.Id).Sum(a => a.KeepTime) + SelectedSlopSpeed.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopMeterSpeed.StartValue) + .Set(a => a.EndValue, SelectedSlopMeterSpeed.EndValue) + .Set(a => a.KeepTime, SelectedSlopMeterSpeed.KeepTime) + .Set(a => a.StepNo, SelectedSlopMeterSpeed.StepNo) + + .Set(a => a.ParNo, SelectedSlopMeterSpeed.ParNo) + .Set(a => a.OutLock, SelectedSlopMeterSpeed.OutLock) + .Set(a => a.CapEnable, SelectedSlopMeterSpeed.CapEnable) + .Set(a => a.Ev, SelectedSlopMeterSpeed.Ev) + .Set(a => a.HeatEnable, SelectedSlopMeterSpeed.HeatEnable) + .Set(a => a.InhExhValve, SelectedSlopMeterSpeed.InhExhValve) + .Where(a => a.Id == SelectedSlopMeterSpeed.Id) + .ExecuteAffrows(); + + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshSpeedById(SelectedSlopMeterSpeed.Id); + var CurIndex = ListSlopMeterSpeed.FindIndex(a => a.Id == SelectedSlopMeterSpeed.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterSpeeds!.Remove(ListSlopMeterSpeed.Find(a => a.Id == SelectedSlopMeterSpeed!.Id)!); + //移除旧的数据 + ListSlopMeterSpeed.Remove(ListSlopMeterSpeed.Find(a => a.Id == SelectedSlopMeterSpeed.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterSpeeds!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterSpeed.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterSpeedItems.Remove(ListSlopMeterSpeedItems.Where(a => a.Id == SelectedSlopMeterSpeed!.Id).FirstOrDefault()!); + ListSlopMeterSpeedItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.SpeedInfo = MeterSpeedToString(ListSlopMeterSpeed); + + //更新后检测时间是否匹配并界面提示 + CheckSpeedSlopListTime(); + + } + + + private DelegateCommand _ProStepSpeedDeleteCmd; + /// + /// 修改速度命令 + /// + public DelegateCommand ProStepSpeedDeleteCmd + { + set + { + _ProStepSpeedDeleteCmd = value; + } + get + { + if (_ProStepSpeedDeleteCmd == null) + { + _ProStepSpeedDeleteCmd = new DelegateCommand(() => ProStepSpeedDeleteCmdMethod()); + } + return _ProStepSpeedDeleteCmd; + } + } + + /// + /// 删除速度命令执行方法 + /// + private void ProStepSpeedDeleteCmdMethod() + { + if (SelectedProStepDto != null && SelectedSlopMeterSpeed != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopMeterSpeed.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterSpeeds!.Remove(ListSlopMeterSpeed.Find(a => a.Id == SelectedSlopMeterSpeed!.Id)!); + //移除旧的数据 + ListSlopMeterSpeed.Remove(ListSlopMeterSpeed.Find(a => a.Id == SelectedSlopMeterSpeed.Id)!); + + //移除旧的数据 + ListSlopMeterSpeedItems.Remove(ListSlopMeterSpeedItems.Where(a => a.Id == SelectedSlopMeterSpeed!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.SpeedInfo = MeterSpeedToString(ListSlopMeterSpeed); + + //更新后检测时间是否匹配并界面提示 + CheckSpeedSlopListTime(); + + } + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + + } + + + + + + + /// + /// 更新速度表信息 + /// + private void RefreshMeterSpeed() + { + ListSlopMeterSpeed = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterSpeeds!.ToList(); + + ListSlopMeterSpeedItems.Clear(); + + ListSlopMeterSpeedItems = new ObservableCollection(ListSlopMeterSpeed!); + + } + + /// + /// 根据速度表获取KeepTime时间 + /// + /// + /// + private int GetKeepTimeBySpeed(int StepNo) + { + var data = ListSlopMeterSpeed.Where(a => a.StepNo == StepNo); + if (data.Count() > 0) + { + //返回第一个时间 + return data.FirstOrDefault()!.KeepTime; + } + else + { + //MessageBox.Show("请把设置对象和速度表的步骤序号匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return 0; + } + } + + /// + /// 根据速度表获取KeepTime时间 + /// + /// + /// + private int GetKeepTimeBySpeed() + { + var SpeedData = SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterSpeeds; + if (SpeedData != null) + { + if (SpeedData.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据 + return SpeedData.Sum(a => a.KeepTime); + } + else + { + //Slop集合数据 + var CurProStep = SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id); + return SpeedData.Sum(a => a.KeepTime) * CurProStep.SpeedCycle; + } + + } + else + { + return 0; + } + } + + + /// + /// 检查斜率配置时间集合是否满足要求 + /// Speed + /// + private void CheckSpeedSlopListTime() + { + MeterSpeedExDto.SlopCycle = SelectedProStepDto.SpeedCycle.Cycle; + //更新后检测时间是否匹配并界面提示 + MeterSpeedExDto.TotalSlopTime = ListSlopMeterSpeed.Sum(a => a.KeepTime) * (int)MeterSpeedExDto.SlopCycle; + MeterSpeedExDto.SlopTime = ListSlopMeterSpeed.Sum(a => a.KeepTime); + MeterSpeedExDto.IsTimeOk = true; + + //新增时,总是在斜率中 + SelectedProStepDto.SpeedCycle!.IsSlop = true; + SelectedProStepDto.SpeedCycle!.Cycle = SelectedProStepDto.SpeedCycle.Cycle; + //if (MeterSpeedExDto.TotalSlopTime != GetKeepTimeBySpeed()) + //{ + // MeterSpeedExDto.IsTimeOk = false; + //} + //else + //{ + // MeterSpeedExDto.IsTimeOk = true; + //} + } + + private string MeterSpeedToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + return strInfo.ToString(); + } + + /// + /// 根据ID获取MeterSpeed数据 + /// + /// + private MeterSpeed RefreshSpeedById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterSpeed(); } } #endregion + /// + /// 获取Index + /// 插入时需要判断 + /// + /// + private int GetListMeterIndex(int Count, int MaxNo) + { + if (MaxNo == Count) + { + //序号和个数能对上 + return MaxNo; + } + else if (MaxNo > Count) + { + //里面有稀疏的序号,非顺序序号 + return Count; + } + else + { + //里面有重复的序号 + return MaxNo; + } + } + + /// + /// 判断是常值还是带斜率的 + /// + /// + /// + private bool CheckIsSlop(List meterComs) + { + if (meterComs != null && meterComs.Count() > 0) + { + if (meterComs.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + return true; + } + else + { + return false; + } + } + else + { + return false; + } + } + + /// + /// 设置ProStep集合的数据的Id为0 + /// 在Copy中使用 + /// + /// + private void SetModelId0(ProStep item) + { + item.Id = 0; + foreach (var MeterSpeeds in item.MeterSpeeds) + { + MeterSpeeds.Id = 0; + } + foreach (var MeterCond1Temp in item.MeterCond1Temps) + { + MeterCond1Temp.Id = 0; + } + foreach (var MeterCond2Temp in item.MeterCond2Temps) + { + MeterCond2Temp.Id = 0; + } + foreach (var MeterCond2Press in item.MeterCond2Presss) + { + MeterCond2Press.Id = 0; + } + foreach (var MeterEVAPExpTemp in item.MeterEVAPExpTemps) + { + MeterEVAPExpTemp.Id = 0; + } + foreach (var MeterExPress in item.MeterExPresss) + { + MeterExPress.Id = 0; + } + foreach (var MeterHVVol in item.MeterHVVols) + { + MeterHVVol.Id = 0; + } + foreach (var MeterInhPress in item.MeterInhPresss) + { + MeterInhPress.Id = 0; + } + foreach (var MeterInhTemp in item.MeterInhTemps) + { + MeterInhTemp.Id = 0; + } + foreach (var MeterLubePress in item.MeterLubePresss) + { + MeterLubePress.Id = 0; + } + foreach (var MeterLVVol in item.MeterLVVols) + { + MeterLVVol.Id = 0; + } + foreach (var MeterOCR in item.MeterOCRs) + { + MeterOCR.Id = 0; + } + foreach (var MeterOS1Temp in item.MeterOS1Temps) + { + MeterOS1Temp.Id = 0; + } + foreach (var MeterOS2Temp in item.MeterOS2Temps) + { + MeterOS2Temp.Id = 0; + } + foreach (var MeterPTCEntTemp in item.MeterPTCEntTemps) + { + MeterPTCEntTemp.Id = 0; + } + foreach (var MeterPTCFlow in item.MeterPTCFlows) + { + MeterPTCFlow.Id = 0; + } + foreach (var MeterPTCPw in item.MeterPTCPws) + { + MeterPTCPw.Id = 0; + } + foreach (var MeterEnvRH in item.MeterEnvRHs) + { + MeterEnvRH.Id = 0; + } + foreach (var MeterEnvTemp in item.MeterEnvTemps) + { + MeterEnvTemp.Id = 0; + } + } + + #region InhPress表 + + + + /// + /// InhPress 初始化函数 + /// + private void InhPressInit() + { + ListSlopMeterInhPressItems = new ObservableCollection(); + SelectedSlopInhPress = new MeterInhPress(); + SelectedConstInhPress = new MeterInhPress(); + } + + + private ObservableCollection _ListSlopMeterInhPressItems; + /// + /// Meter InhPress数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterInhPressItems + { + get { return _ListSlopMeterInhPressItems; } + set { _ListSlopMeterInhPressItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterInhPress集合数据 斜率 + /// + public List ListSlopMeterInhPress { get; set; } + + + private MeterInhPress _SelectedSlopInhPress; + /// + /// 当前选中的程序 InhPress 斜率 + /// + public MeterInhPress SelectedSlopInhPress + { + get { return _SelectedSlopInhPress; } + set { _SelectedSlopInhPress = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterInhPressExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 InhPress + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterInhPressExDto + { + get { return _MeterInhPressExDto; } + set { _MeterInhPressExDto = value; RaisePropertyChanged(); } + } + + + + private MeterInhPress _SelectedConstInhPress; + /// + /// 当前选中的程序 InhPress 常值 + /// + public MeterInhPress SelectedConstInhPress + { + get { return _SelectedConstInhPress; } + set { _SelectedConstInhPress = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstInhPressValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstInhPressValue + { + get { return _SelectedConstInhPressValue; } + set { _SelectedConstInhPressValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterInhPressSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterInhPressSlopSelectedChangedCmd + { + set + { + _MeterInhPressSlopSelectedChangedCmd = value; + } + get + { + if (_MeterInhPressSlopSelectedChangedCmd == null) + { + _MeterInhPressSlopSelectedChangedCmd = new DelegateCommand((str) => MeterInhPressSlopSelectedChangedCmdMethod(str)); + } + return _MeterInhPressSlopSelectedChangedCmd; + } + } + + + /// + /// InhPress表选中行的执行方法 + /// + /// + /// + private void MeterInhPressSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterInhPress; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopInhPress = new MeterInhPress + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepInhPressAddCmd; + /// + /// 新增InhPress命令 + /// + public DelegateCommand ProStepInhPressAddCmd + { + set + { + _ProStepInhPressAddCmd = value; + } + get + { + if (_ProStepInhPressAddCmd == null) + { + _ProStepInhPressAddCmd = new DelegateCommand(() => ProStepInhPressAddCmdMethod()); + } + return _ProStepInhPressAddCmd; + } + } + + /// + /// 增加InhPress命令执行方法 + /// + private void ProStepInhPressAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterInhPress.Sum(a => a.KeepTime) + SelectedSlopInhPress.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhPresss!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhPresss!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhPresss!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterInhPresss = ListSlopMeterInhPressItems.ToList(); + + var MeterInhPressData = new MeterInhPress() + { + StartValue = SelectedSlopInhPress.StartValue, + EndValue = SelectedSlopInhPress.EndValue, + KeepTime = SelectedSlopInhPress.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterInhPressStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterInhPressData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshInhPressById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhPresss!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhPresss!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhPresss!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhPresss!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterInhPress.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterInhPressItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterInhPressInfo = MeterInhPressToString(ListSlopMeterInhPress); + + //更新后检测时间是否匹配并界面提示 + CheckInhPressSlopListTime(); + } + + + private DelegateCommand _ProStepInhPressEditCmd; + /// + /// 新增InhPress命令 + /// + public DelegateCommand ProStepInhPressEditCmd + { + set + { + _ProStepInhPressEditCmd = value; + } + get + { + if (_ProStepInhPressEditCmd == null) + { + _ProStepInhPressEditCmd = new DelegateCommand(() => ProStepInhPressEditCmdMethod()); + } + return _ProStepInhPressEditCmd; + } + } + + /// + /// 编辑InhPress命令执行方法 + /// + private void ProStepInhPressEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopInhPress == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterInhPress.Where(a => a.Id != SelectedSlopInhPress!.Id).Sum(a => a.KeepTime) + SelectedSlopInhPress!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopInhPress.StartValue) + .Set(a => a.EndValue, SelectedSlopInhPress.EndValue) + .Set(a => a.KeepTime, SelectedSlopInhPress.KeepTime) + .Set(a => a.StepNo, SelectedSlopInhPress.StepNo) + .Where(a => a.Id == SelectedSlopInhPress.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshInhPressById(SelectedSlopInhPress.Id); + var CurIndex = ListSlopMeterInhPress.FindIndex(a => a.Id == SelectedSlopInhPress.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterInhPresss!.Remove(ListSlopMeterInhPress.Find(a => a.Id == SelectedSlopInhPress!.Id)!); + //移除旧的数据 + ListSlopMeterInhPress.Remove(ListSlopMeterInhPress.Find(a => a.Id == SelectedSlopInhPress.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterInhPresss!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterInhPress.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterInhPressItems.Remove(ListSlopMeterInhPressItems.Where(a => a.Id == SelectedSlopInhPress!.Id).FirstOrDefault()!); + ListSlopMeterInhPressItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterInhPressInfo = MeterInhPressToString(ListSlopMeterInhPress); + + //更新后检测时间是否匹配并界面提示 + CheckInhPressSlopListTime(); + } + + private DelegateCommand _ProStepInhPressDeleteCmd; + /// + /// 新增InhPress命令 + /// + public DelegateCommand ProStepInhPressDeleteCmd + { + set + { + _ProStepInhPressDeleteCmd = value; + } + get + { + if (_ProStepInhPressDeleteCmd == null) + { + _ProStepInhPressDeleteCmd = new DelegateCommand(() => ProStepInhPressDeleteCmdMethod()); + } + return _ProStepInhPressDeleteCmd; + } + } + + /// + /// 增加InhPress命令执行方法 + /// + private void ProStepInhPressDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopInhPress != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopInhPress!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterInhPresss!.Remove(ListSlopMeterInhPress.Find(a => a.Id == SelectedSlopInhPress!.Id)!); + //移除旧的数据 + ListSlopMeterInhPress.Remove(ListSlopMeterInhPress.Find(a => a.Id == SelectedSlopInhPress.Id)!); + + //移除旧的数据 + ListSlopMeterInhPressItems.Remove(ListSlopMeterInhPressItems.Where(a => a.Id == SelectedSlopInhPress!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterInhPressInfo = MeterInhPressToString(ListSlopMeterInhPress); + + //更新后检测时间是否匹配并界面提示 + CheckInhPressSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新InhPress表信息 + /// + private void RefreshMeterInhPress() + { + ListSlopMeterInhPress = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterInhPresss!.ToList(); + + ListSlopMeterInhPressItems.Clear(); + + ListSlopMeterInhPressItems = new ObservableCollection(ListSlopMeterInhPress!); + + } + + /// + /// 获取InhPress当前的步骤的数据信息 + /// + private int AutoGetMeterInhPressStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepInhPressConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepInhPressConstantSaveCmd + { + set + { + _ProStepInhPressConstantSaveCmd = value; + } + get + { + if (_ProStepInhPressConstantSaveCmd == null) + { + _ProStepInhPressConstantSaveCmd = new DelegateCommand(() => ProStepInhPressConstantSaveCmdMethod()); + } + return _ProStepInhPressConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepInhPressConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterInhPressItems != null && ListSlopMeterInhPressItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterInhPressItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterInhPresss!.Remove(ListSlopMeterInhPress.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterInhPress.Remove(ListSlopMeterInhPress.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterInhPressItems.Remove(ListSlopMeterInhPressItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterInhPressInfo = MeterInhPressToString(ListSlopMeterInhPress); + + //更新后检测时间是否匹配并界面提示 + CheckInhPressSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstInhPressData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhPresss!.ToList(); + if (ConstInhPressData != null && ConstInhPressData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterInhPressData = new MeterInhPress() + { + Constant = SelectedConstInhPressValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterInhPressStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterInhPressData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshInhPressById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhPresss!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterInhPressInfo = MeterInhPressToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstInhPressData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstInhPressValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshInhPressById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterInhPresss!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterInhPresss!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterInhPressInfo = MeterInhPressToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterInhPressSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterInhPressSwitchConstSlopPar + { + get { return _ProStepMeterInhPressSwitchConstSlopPar; } + set { _ProStepMeterInhPressSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepInhPressSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepInhPressSwitchConstSlopIndex + { + get { return _ProStepInhPressSwitchConstSlopIndex; } + set { _ProStepInhPressSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterInhPressSwitchConstSlopCmd; + /// + /// InhPress 常值和斜率切换 命令 + /// + public DelegateCommand MeterInhPressSwitchConstSlopCmd + { + set + { + _MeterInhPressSwitchConstSlopCmd = value; + } + get + { + if (_MeterInhPressSwitchConstSlopCmd == null) + { + _MeterInhPressSwitchConstSlopCmd = new DelegateCommand((obj) => MeterInhPressSwitchConstSlopCmdMethod(obj)); + } + return _MeterInhPressSwitchConstSlopCmd; + } + } + private void MeterInhPressSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterInhPressSwitchConstSlopPar = false; + } + else + { + ProStepMeterInhPressSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterInhPressToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckInhPressSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterInhPressExDto.SlopTime = ListSlopMeterInhPress.Sum(a => a.KeepTime); + if (MeterInhPressExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterInhPressExDto.SlopTime != 0) + { + MeterInhPressExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterInhPressExDto.SlopTime; + MeterInhPressExDto.IsTimeOk = false; + } + else + { + MeterInhPressExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterInhPressExDto.SlopTime; + MeterInhPressExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterInhPress数据 + /// + /// + private MeterInhPress RefreshInhPressById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterInhPress(); + } + } + + + #endregion + + #region ExPress表 + + + + /// + /// ExPress 初始化函数 + /// + private void ExPressInit() + { + ListSlopMeterExPressItems = new ObservableCollection(); + SelectedSlopExPress = new MeterExPress(); + SelectedConstExPress = new MeterExPress(); + } + + + private ObservableCollection _ListSlopMeterExPressItems; + /// + /// Meter ExPress数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterExPressItems + { + get { return _ListSlopMeterExPressItems; } + set { _ListSlopMeterExPressItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterExPress集合数据 斜率 + /// + public List ListSlopMeterExPress { get; set; } + + + private MeterExPress _SelectedSlopExPress; + /// + /// 当前选中的程序 ExPress 斜率 + /// + public MeterExPress SelectedSlopExPress + { + get { return _SelectedSlopExPress; } + set { _SelectedSlopExPress = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterExPressExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 ExPress + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterExPressExDto + { + get { return _MeterExPressExDto; } + set { _MeterExPressExDto = value; RaisePropertyChanged(); } + } + + + + private MeterExPress _SelectedConstExPress; + /// + /// 当前选中的程序 ExPress 常值 + /// + public MeterExPress SelectedConstExPress + { + get { return _SelectedConstExPress; } + set { _SelectedConstExPress = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstExPressValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstExPressValue + { + get { return _SelectedConstExPressValue; } + set { _SelectedConstExPressValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterExPressSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterExPressSlopSelectedChangedCmd + { + set + { + _MeterExPressSlopSelectedChangedCmd = value; + } + get + { + if (_MeterExPressSlopSelectedChangedCmd == null) + { + _MeterExPressSlopSelectedChangedCmd = new DelegateCommand((str) => MeterExPressSlopSelectedChangedCmdMethod(str)); + } + return _MeterExPressSlopSelectedChangedCmd; + } + } + + + /// + /// ExPress表选中行的执行方法 + /// + /// + /// + private void MeterExPressSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterExPress; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopExPress = new MeterExPress + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepExPressAddCmd; + /// + /// 新增ExPress命令 + /// + public DelegateCommand ProStepExPressAddCmd + { + set + { + _ProStepExPressAddCmd = value; + } + get + { + if (_ProStepExPressAddCmd == null) + { + _ProStepExPressAddCmd = new DelegateCommand(() => ProStepExPressAddCmdMethod()); + } + return _ProStepExPressAddCmd; + } + } + + /// + /// 增加ExPress命令执行方法 + /// + private void ProStepExPressAddCmdMethod() + { + SelectedSlopExPress = new MeterExPress(); + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopExPress == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterExPress.Sum(a => a.KeepTime) + SelectedSlopExPress.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterExPresss!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterExPresss!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterExPresss!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterExPresss = ListSlopMeterExPressItems.ToList(); + + var MeterExPressData = new MeterExPress() + { + StartValue = SelectedSlopExPress.StartValue, + EndValue = SelectedSlopExPress.EndValue, + KeepTime = SelectedSlopExPress.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterExPressStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterExPressData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshExPressById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterExPresss!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterExPresss!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterExPresss!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterExPresss!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterExPress.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterExPressItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterExPressInfo = MeterExPressToString(ListSlopMeterExPress); + + //更新后检测时间是否匹配并界面提示 + CheckExPressSlopListTime(); + } + + + private DelegateCommand _ProStepExPressEditCmd; + /// + /// 新增ExPress命令 + /// + public DelegateCommand ProStepExPressEditCmd + { + set + { + _ProStepExPressEditCmd = value; + } + get + { + if (_ProStepExPressEditCmd == null) + { + _ProStepExPressEditCmd = new DelegateCommand(() => ProStepExPressEditCmdMethod()); + } + return _ProStepExPressEditCmd; + } + } + + /// + /// 编辑ExPress命令执行方法 + /// + private void ProStepExPressEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopExPress == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterExPress.Where(a => a.Id != SelectedSlopExPress!.Id).Sum(a => a.KeepTime) + SelectedSlopExPress!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopExPress.StartValue) + .Set(a => a.EndValue, SelectedSlopExPress.EndValue) + .Set(a => a.KeepTime, SelectedSlopExPress.KeepTime) + .Set(a => a.StepNo, SelectedSlopExPress.StepNo) + .Where(a => a.Id == SelectedSlopExPress.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshExPressById(SelectedSlopExPress.Id); + var CurIndex = ListSlopMeterExPress.FindIndex(a => a.Id == SelectedSlopExPress.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterExPresss!.Remove(ListSlopMeterExPress.Find(a => a.Id == SelectedSlopExPress!.Id)!); + //移除旧的数据 + ListSlopMeterExPress.Remove(ListSlopMeterExPress.Find(a => a.Id == SelectedSlopExPress.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterExPresss!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterExPress.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterExPressItems.Remove(ListSlopMeterExPressItems.Where(a => a.Id == SelectedSlopExPress!.Id).FirstOrDefault()!); + ListSlopMeterExPressItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterExPressInfo = MeterExPressToString(ListSlopMeterExPress); + + //更新后检测时间是否匹配并界面提示 + CheckExPressSlopListTime(); + } + + private DelegateCommand _ProStepExPressDeleteCmd; + /// + /// 新增ExPress命令 + /// + public DelegateCommand ProStepExPressDeleteCmd + { + set + { + _ProStepExPressDeleteCmd = value; + } + get + { + if (_ProStepExPressDeleteCmd == null) + { + _ProStepExPressDeleteCmd = new DelegateCommand(() => ProStepExPressDeleteCmdMethod()); + } + return _ProStepExPressDeleteCmd; + } + } + + /// + /// 增加ExPress命令执行方法 + /// + private void ProStepExPressDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopExPress != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopExPress!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterExPresss!.Remove(ListSlopMeterExPress.Find(a => a.Id == SelectedSlopExPress!.Id)!); + //移除旧的数据 + ListSlopMeterExPress.Remove(ListSlopMeterExPress.Find(a => a.Id == SelectedSlopExPress.Id)!); + + //移除旧的数据 + ListSlopMeterExPressItems.Remove(ListSlopMeterExPressItems.Where(a => a.Id == SelectedSlopExPress!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterExPressInfo = MeterExPressToString(ListSlopMeterExPress); + + //更新后检测时间是否匹配并界面提示 + CheckExPressSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新ExPress表信息 + /// + private void RefreshMeterExPress() + { + ListSlopMeterExPress = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterExPresss!.ToList(); + + ListSlopMeterExPressItems.Clear(); + + ListSlopMeterExPressItems = new ObservableCollection(ListSlopMeterExPress!); + + } + + /// + /// 获取ExPress当前的步骤的数据信息 + /// + private int AutoGetMeterExPressStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepExPressConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepExPressConstantSaveCmd + { + set + { + _ProStepExPressConstantSaveCmd = value; + } + get + { + if (_ProStepExPressConstantSaveCmd == null) + { + _ProStepExPressConstantSaveCmd = new DelegateCommand(() => ProStepExPressConstantSaveCmdMethod()); + } + return _ProStepExPressConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepExPressConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterExPressItems != null && ListSlopMeterExPressItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterExPressItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterExPresss!.Remove(ListSlopMeterExPress.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterExPress.Remove(ListSlopMeterExPress.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterExPressItems.Remove(ListSlopMeterExPressItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterExPressInfo = MeterExPressToString(ListSlopMeterExPress); + + //更新后检测时间是否匹配并界面提示 + CheckExPressSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstExPressData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterExPresss!.ToList(); + if (ConstExPressData != null && ConstExPressData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterExPressData = new MeterExPress() + { + Constant = SelectedConstExPressValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterExPressStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterExPressData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshExPressById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterExPresss!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterExPressInfo = MeterExPressToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstExPressData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstExPressValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshExPressById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterExPresss!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterExPresss!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterExPressInfo = MeterExPressToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterExPressSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterExPressSwitchConstSlopPar + { + get { return _ProStepMeterExPressSwitchConstSlopPar; } + set { _ProStepMeterExPressSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepExPressSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepExPressSwitchConstSlopIndex + { + get { return _ProStepExPressSwitchConstSlopIndex; } + set { _ProStepExPressSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterExPressSwitchConstSlopCmd; + /// + /// ExPress 常值和斜率切换 命令 + /// + public DelegateCommand MeterExPressSwitchConstSlopCmd + { + set + { + _MeterExPressSwitchConstSlopCmd = value; + } + get + { + if (_MeterExPressSwitchConstSlopCmd == null) + { + _MeterExPressSwitchConstSlopCmd = new DelegateCommand((obj) => MeterExPressSwitchConstSlopCmdMethod(obj)); + } + return _MeterExPressSwitchConstSlopCmd; + } + } + private void MeterExPressSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterExPressSwitchConstSlopPar = false; + } + else + { + ProStepMeterExPressSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterExPressToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckExPressSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterExPressExDto.SlopTime = ListSlopMeterExPress.Sum(a => a.KeepTime); + if (MeterExPressExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterExPressExDto.SlopTime != 0) + { + MeterExPressExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterExPressExDto.SlopTime; + MeterExPressExDto.IsTimeOk = false; + } + else + { + MeterExPressExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterExPressExDto.SlopTime; + MeterExPressExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterExPress数据 + /// + /// + private MeterExPress RefreshExPressById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterExPress(); + } + } + + + #endregion + + #region InhTemp表 + + + + /// + /// InhTemp 初始化函数 + /// + private void InhTempInit() + { + ListSlopMeterInhTempItems = new ObservableCollection(); + SelectedSlopInhTemp = new MeterInhTemp(); + SelectedConstInhTemp = new MeterInhTemp(); + } + + + private ObservableCollection _ListSlopMeterInhTempItems; + /// + /// Meter InhTemp数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterInhTempItems + { + get { return _ListSlopMeterInhTempItems; } + set { _ListSlopMeterInhTempItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterInhTemp集合数据 斜率 + /// + public List ListSlopMeterInhTemp { get; set; } + + + private MeterInhTemp _SelectedSlopInhTemp; + /// + /// 当前选中的程序 InhTemp 斜率 + /// + public MeterInhTemp SelectedSlopInhTemp + { + get { return _SelectedSlopInhTemp; } + set { _SelectedSlopInhTemp = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterInhTempExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 InhTemp + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterInhTempExDto + { + get { return _MeterInhTempExDto; } + set { _MeterInhTempExDto = value; RaisePropertyChanged(); } + } + + + + private MeterInhTemp _SelectedConstInhTemp; + /// + /// 当前选中的程序 InhTemp 常值 + /// + public MeterInhTemp SelectedConstInhTemp + { + get { return _SelectedConstInhTemp; } + set { _SelectedConstInhTemp = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstInhTempValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstInhTempValue + { + get { return _SelectedConstInhTempValue; } + set { _SelectedConstInhTempValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterInhTempSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterInhTempSlopSelectedChangedCmd + { + set + { + _MeterInhTempSlopSelectedChangedCmd = value; + } + get + { + if (_MeterInhTempSlopSelectedChangedCmd == null) + { + _MeterInhTempSlopSelectedChangedCmd = new DelegateCommand((str) => MeterInhTempSlopSelectedChangedCmdMethod(str)); + } + return _MeterInhTempSlopSelectedChangedCmd; + } + } + + + /// + /// InhTemp表选中行的执行方法 + /// + /// + /// + private void MeterInhTempSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterInhTemp; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopInhTemp = new MeterInhTemp + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepInhTempAddCmd; + /// + /// 新增InhTemp命令 + /// + public DelegateCommand ProStepInhTempAddCmd + { + set + { + _ProStepInhTempAddCmd = value; + } + get + { + if (_ProStepInhTempAddCmd == null) + { + _ProStepInhTempAddCmd = new DelegateCommand(() => ProStepInhTempAddCmdMethod()); + } + return _ProStepInhTempAddCmd; + } + } + + /// + /// 增加InhTemp命令执行方法 + /// + private void ProStepInhTempAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterInhTemp.Sum(a => a.KeepTime) + SelectedSlopInhTemp.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhTemps!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhTemps!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhTemps!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterInhTemps = ListSlopMeterInhTempItems.ToList(); + + var MeterInhTempData = new MeterInhTemp() + { + StartValue = SelectedSlopInhTemp.StartValue, + EndValue = SelectedSlopInhTemp.EndValue, + KeepTime = SelectedSlopInhTemp.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterInhTempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterInhTempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshInhTempById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhTemps!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhTemps!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhTemps!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhTemps!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterInhTemp.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterInhTempItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterInhTempInfo = MeterInhTempToString(ListSlopMeterInhTemp); + + //更新后检测时间是否匹配并界面提示 + CheckInhTempSlopListTime(); + } + + + private DelegateCommand _ProStepInhTempEditCmd; + /// + /// 新增InhTemp命令 + /// + public DelegateCommand ProStepInhTempEditCmd + { + set + { + _ProStepInhTempEditCmd = value; + } + get + { + if (_ProStepInhTempEditCmd == null) + { + _ProStepInhTempEditCmd = new DelegateCommand(() => ProStepInhTempEditCmdMethod()); + } + return _ProStepInhTempEditCmd; + } + } + + /// + /// 编辑InhTemp命令执行方法 + /// + private void ProStepInhTempEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopInhTemp == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterInhTemp.Where(a => a.Id != SelectedSlopInhTemp!.Id).Sum(a => a.KeepTime) + SelectedSlopInhTemp!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopInhTemp.StartValue) + .Set(a => a.EndValue, SelectedSlopInhTemp.EndValue) + .Set(a => a.KeepTime, SelectedSlopInhTemp.KeepTime) + .Set(a => a.StepNo, SelectedSlopInhTemp.StepNo) + .Where(a => a.Id == SelectedSlopInhTemp.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshInhTempById(SelectedSlopInhTemp.Id); + var CurIndex = ListSlopMeterInhTemp.FindIndex(a => a.Id == SelectedSlopInhTemp.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterInhTemps!.Remove(ListSlopMeterInhTemp.Find(a => a.Id == SelectedSlopInhTemp!.Id)!); + //移除旧的数据 + ListSlopMeterInhTemp.Remove(ListSlopMeterInhTemp.Find(a => a.Id == SelectedSlopInhTemp.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterInhTemps!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterInhTemp.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterInhTempItems.Remove(ListSlopMeterInhTempItems.Where(a => a.Id == SelectedSlopInhTemp!.Id).FirstOrDefault()!); + ListSlopMeterInhTempItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterInhTempInfo = MeterInhTempToString(ListSlopMeterInhTemp); + + //更新后检测时间是否匹配并界面提示 + CheckInhTempSlopListTime(); + } + + private DelegateCommand _ProStepInhTempDeleteCmd; + /// + /// 新增InhTemp命令 + /// + public DelegateCommand ProStepInhTempDeleteCmd + { + set + { + _ProStepInhTempDeleteCmd = value; + } + get + { + if (_ProStepInhTempDeleteCmd == null) + { + _ProStepInhTempDeleteCmd = new DelegateCommand(() => ProStepInhTempDeleteCmdMethod()); + } + return _ProStepInhTempDeleteCmd; + } + } + + /// + /// 增加InhTemp命令执行方法 + /// + private void ProStepInhTempDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopInhTemp != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopInhTemp!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterInhTemps!.Remove(ListSlopMeterInhTemp.Find(a => a.Id == SelectedSlopInhTemp!.Id)!); + //移除旧的数据 + ListSlopMeterInhTemp.Remove(ListSlopMeterInhTemp.Find(a => a.Id == SelectedSlopInhTemp.Id)!); + + //移除旧的数据 + ListSlopMeterInhTempItems.Remove(ListSlopMeterInhTempItems.Where(a => a.Id == SelectedSlopInhTemp!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterInhTempInfo = MeterInhTempToString(ListSlopMeterInhTemp); + + //更新后检测时间是否匹配并界面提示 + CheckInhTempSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新InhTemp表信息 + /// + private void RefreshMeterInhTemp() + { + ListSlopMeterInhTemp = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterInhTemps!.ToList(); + + ListSlopMeterInhTempItems.Clear(); + + ListSlopMeterInhTempItems = new ObservableCollection(ListSlopMeterInhTemp!); + + } + + /// + /// 获取InhTemp当前的步骤的数据信息 + /// + private int AutoGetMeterInhTempStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepInhTempConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepInhTempConstantSaveCmd + { + set + { + _ProStepInhTempConstantSaveCmd = value; + } + get + { + if (_ProStepInhTempConstantSaveCmd == null) + { + _ProStepInhTempConstantSaveCmd = new DelegateCommand(() => ProStepInhTempConstantSaveCmdMethod()); + } + return _ProStepInhTempConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepInhTempConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterInhTempItems != null && ListSlopMeterInhTempItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterInhTempItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterInhTemps!.Remove(ListSlopMeterInhTemp.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterInhTemp.Remove(ListSlopMeterInhTemp.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterInhTempItems.Remove(ListSlopMeterInhTempItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterInhTempInfo = MeterInhTempToString(ListSlopMeterInhTemp); + + //更新后检测时间是否匹配并界面提示 + CheckInhTempSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstInhTempData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhTemps!.ToList(); + if (ConstInhTempData != null && ConstInhTempData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterInhTempData = new MeterInhTemp() + { + Constant = SelectedConstInhTempValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterInhTempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterInhTempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshInhTempById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterInhTemps!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterInhTempInfo = MeterInhTempToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstInhTempData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstInhTempValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshInhTempById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterInhTemps!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterInhTemps!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterInhTempInfo = MeterInhTempToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterInhTempSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterInhTempSwitchConstSlopPar + { + get { return _ProStepMeterInhTempSwitchConstSlopPar; } + set { _ProStepMeterInhTempSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepInhTempSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepInhTempSwitchConstSlopIndex + { + get { return _ProStepInhTempSwitchConstSlopIndex; } + set { _ProStepInhTempSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterInhTempSwitchConstSlopCmd; + /// + /// InhTemp 常值和斜率切换 命令 + /// + public DelegateCommand MeterInhTempSwitchConstSlopCmd + { + set + { + _MeterInhTempSwitchConstSlopCmd = value; + } + get + { + if (_MeterInhTempSwitchConstSlopCmd == null) + { + _MeterInhTempSwitchConstSlopCmd = new DelegateCommand((obj) => MeterInhTempSwitchConstSlopCmdMethod(obj)); + } + return _MeterInhTempSwitchConstSlopCmd; + } + } + private void MeterInhTempSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterInhTempSwitchConstSlopPar = false; + } + else + { + ProStepMeterInhTempSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterInhTempToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckInhTempSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterInhTempExDto.SlopTime = ListSlopMeterInhTemp.Sum(a => a.KeepTime); + if (MeterInhTempExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterInhTempExDto.SlopTime != 0) + { + MeterInhTempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterInhTempExDto.SlopTime; + MeterInhTempExDto.IsTimeOk = false; + } + else + { + MeterInhTempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterInhTempExDto.SlopTime; + MeterInhTempExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterInhTemp数据 + /// + /// + private MeterInhTemp RefreshInhTempById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterInhTemp(); + } + } + + + #endregion + + #region Cond1Temp表 + + + + /// + /// Cond1Temp 初始化函数 + /// + private void Cond1TempInit() + { + ListSlopMeterCond1TempItems = new ObservableCollection(); + SelectedSlopCond1Temp = new MeterCond1Temp(); + SelectedConstCond1Temp = new MeterCond1Temp(); + } + + + private ObservableCollection _ListSlopMeterCond1TempItems; + /// + /// Meter Cond1Temp数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterCond1TempItems + { + get { return _ListSlopMeterCond1TempItems; } + set { _ListSlopMeterCond1TempItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterCond1Temp集合数据 斜率 + /// + public List ListSlopMeterCond1Temp { get; set; } + + + private MeterCond1Temp _SelectedSlopCond1Temp; + /// + /// 当前选中的程序 Cond1Temp 斜率 + /// + public MeterCond1Temp SelectedSlopCond1Temp + { + get { return _SelectedSlopCond1Temp; } + set { _SelectedSlopCond1Temp = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterCond1TempExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 Cond1Temp + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterCond1TempExDto + { + get { return _MeterCond1TempExDto; } + set { _MeterCond1TempExDto = value; RaisePropertyChanged(); } + } + + + + private MeterCond1Temp _SelectedConstCond1Temp; + /// + /// 当前选中的程序 Cond1Temp 常值 + /// + public MeterCond1Temp SelectedConstCond1Temp + { + get { return _SelectedConstCond1Temp; } + set { _SelectedConstCond1Temp = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstCond1TempValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstCond1TempValue + { + get { return _SelectedConstCond1TempValue; } + set { _SelectedConstCond1TempValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterCond1TempSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterCond1TempSlopSelectedChangedCmd + { + set + { + _MeterCond1TempSlopSelectedChangedCmd = value; + } + get + { + if (_MeterCond1TempSlopSelectedChangedCmd == null) + { + _MeterCond1TempSlopSelectedChangedCmd = new DelegateCommand((str) => MeterCond1TempSlopSelectedChangedCmdMethod(str)); + } + return _MeterCond1TempSlopSelectedChangedCmd; + } + } + + + /// + /// Cond1Temp表选中行的执行方法 + /// + /// + /// + private void MeterCond1TempSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterCond1Temp; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopCond1Temp = new MeterCond1Temp + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepCond1TempAddCmd; + /// + /// 新增Cond1Temp命令 + /// + public DelegateCommand ProStepCond1TempAddCmd + { + set + { + _ProStepCond1TempAddCmd = value; + } + get + { + if (_ProStepCond1TempAddCmd == null) + { + _ProStepCond1TempAddCmd = new DelegateCommand(() => ProStepCond1TempAddCmdMethod()); + } + return _ProStepCond1TempAddCmd; + } + } + + /// + /// 增加Cond1Temp命令执行方法 + /// + private void ProStepCond1TempAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterCond1Temp.Sum(a => a.KeepTime) + SelectedSlopCond1Temp.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond1Temps!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond1Temps!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond1Temps!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterCond1Temps = ListSlopMeterCond1TempItems.ToList(); + + var MeterCond1TempData = new MeterCond1Temp() + { + StartValue = SelectedSlopCond1Temp.StartValue, + EndValue = SelectedSlopCond1Temp.EndValue, + KeepTime = SelectedSlopCond1Temp.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterCond1TempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterCond1TempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshCond1TempById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond1Temps!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond1Temps!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond1Temps!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond1Temps!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterCond1Temp.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterCond1TempItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterCond1TempInfo = MeterCond1TempToString(ListSlopMeterCond1Temp); + + //更新后检测时间是否匹配并界面提示 + CheckCond1TempSlopListTime(); + } + + + private DelegateCommand _ProStepCond1TempEditCmd; + /// + /// 新增Cond1Temp命令 + /// + public DelegateCommand ProStepCond1TempEditCmd + { + set + { + _ProStepCond1TempEditCmd = value; + } + get + { + if (_ProStepCond1TempEditCmd == null) + { + _ProStepCond1TempEditCmd = new DelegateCommand(() => ProStepCond1TempEditCmdMethod()); + } + return _ProStepCond1TempEditCmd; + } + } + + /// + /// 编辑Cond1Temp命令执行方法 + /// + private void ProStepCond1TempEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopCond1Temp == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterCond1Temp.Where(a => a.Id != SelectedSlopCond1Temp!.Id).Sum(a => a.KeepTime) + SelectedSlopCond1Temp!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopCond1Temp.StartValue) + .Set(a => a.EndValue, SelectedSlopCond1Temp.EndValue) + .Set(a => a.KeepTime, SelectedSlopCond1Temp.KeepTime) + .Set(a => a.StepNo, SelectedSlopCond1Temp.StepNo) + .Where(a => a.Id == SelectedSlopCond1Temp.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshCond1TempById(SelectedSlopCond1Temp.Id); + var CurIndex = ListSlopMeterCond1Temp.FindIndex(a => a.Id == SelectedSlopCond1Temp.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond1Temps!.Remove(ListSlopMeterCond1Temp.Find(a => a.Id == SelectedSlopCond1Temp!.Id)!); + //移除旧的数据 + ListSlopMeterCond1Temp.Remove(ListSlopMeterCond1Temp.Find(a => a.Id == SelectedSlopCond1Temp.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond1Temps!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterCond1Temp.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterCond1TempItems.Remove(ListSlopMeterCond1TempItems.Where(a => a.Id == SelectedSlopCond1Temp!.Id).FirstOrDefault()!); + ListSlopMeterCond1TempItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond1TempInfo = MeterCond1TempToString(ListSlopMeterCond1Temp); + + //更新后检测时间是否匹配并界面提示 + CheckCond1TempSlopListTime(); + } + + private DelegateCommand _ProStepCond1TempDeleteCmd; + /// + /// 新增Cond1Temp命令 + /// + public DelegateCommand ProStepCond1TempDeleteCmd + { + set + { + _ProStepCond1TempDeleteCmd = value; + } + get + { + if (_ProStepCond1TempDeleteCmd == null) + { + _ProStepCond1TempDeleteCmd = new DelegateCommand(() => ProStepCond1TempDeleteCmdMethod()); + } + return _ProStepCond1TempDeleteCmd; + } + } + + /// + /// 增加Cond1Temp命令执行方法 + /// + private void ProStepCond1TempDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopCond1Temp != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopCond1Temp!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond1Temps!.Remove(ListSlopMeterCond1Temp.Find(a => a.Id == SelectedSlopCond1Temp!.Id)!); + //移除旧的数据 + ListSlopMeterCond1Temp.Remove(ListSlopMeterCond1Temp.Find(a => a.Id == SelectedSlopCond1Temp.Id)!); + + //移除旧的数据 + ListSlopMeterCond1TempItems.Remove(ListSlopMeterCond1TempItems.Where(a => a.Id == SelectedSlopCond1Temp!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond1TempInfo = MeterCond1TempToString(ListSlopMeterCond1Temp); + + //更新后检测时间是否匹配并界面提示 + CheckCond1TempSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新Cond1Temp表信息 + /// + private void RefreshMeterCond1Temp() + { + ListSlopMeterCond1Temp = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterCond1Temps!.ToList(); + + ListSlopMeterCond1TempItems.Clear(); + + ListSlopMeterCond1TempItems = new ObservableCollection(ListSlopMeterCond1Temp!); + + } + + /// + /// 获取Cond1Temp当前的步骤的数据信息 + /// + private int AutoGetMeterCond1TempStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepCond1TempConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepCond1TempConstantSaveCmd + { + set + { + _ProStepCond1TempConstantSaveCmd = value; + } + get + { + if (_ProStepCond1TempConstantSaveCmd == null) + { + _ProStepCond1TempConstantSaveCmd = new DelegateCommand(() => ProStepCond1TempConstantSaveCmdMethod()); + } + return _ProStepCond1TempConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepCond1TempConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterCond1TempItems != null && ListSlopMeterCond1TempItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterCond1TempItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond1Temps!.Remove(ListSlopMeterCond1Temp.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterCond1Temp.Remove(ListSlopMeterCond1Temp.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterCond1TempItems.Remove(ListSlopMeterCond1TempItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond1TempInfo = MeterCond1TempToString(ListSlopMeterCond1Temp); + + //更新后检测时间是否匹配并界面提示 + CheckCond1TempSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstCond1TempData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond1Temps!.ToList(); + if (ConstCond1TempData != null && ConstCond1TempData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterCond1TempData = new MeterCond1Temp() + { + Constant = SelectedConstCond1TempValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterCond1TempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterCond1TempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshCond1TempById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond1Temps!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterCond1TempInfo = MeterCond1TempToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstCond1TempData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstCond1TempValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshCond1TempById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond1Temps!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond1Temps!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond1TempInfo = MeterCond1TempToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterCond1TempSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterCond1TempSwitchConstSlopPar + { + get { return _ProStepMeterCond1TempSwitchConstSlopPar; } + set { _ProStepMeterCond1TempSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepCond1TempSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepCond1TempSwitchConstSlopIndex + { + get { return _ProStepCond1TempSwitchConstSlopIndex; } + set { _ProStepCond1TempSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterCond1TempSwitchConstSlopCmd; + /// + /// Cond1Temp 常值和斜率切换 命令 + /// + public DelegateCommand MeterCond1TempSwitchConstSlopCmd + { + set + { + _MeterCond1TempSwitchConstSlopCmd = value; + } + get + { + if (_MeterCond1TempSwitchConstSlopCmd == null) + { + _MeterCond1TempSwitchConstSlopCmd = new DelegateCommand((obj) => MeterCond1TempSwitchConstSlopCmdMethod(obj)); + } + return _MeterCond1TempSwitchConstSlopCmd; + } + } + private void MeterCond1TempSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterCond1TempSwitchConstSlopPar = false; + } + else + { + ProStepMeterCond1TempSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterCond1TempToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckCond1TempSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterCond1TempExDto.SlopTime = ListSlopMeterCond1Temp.Sum(a => a.KeepTime); + if (MeterCond1TempExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterCond1TempExDto.SlopTime != 0) + { + MeterCond1TempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterCond1TempExDto.SlopTime; + MeterCond1TempExDto.IsTimeOk = false; + } + else + { + MeterCond1TempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterCond1TempExDto.SlopTime; + MeterCond1TempExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterCond1Temp数据 + /// + /// + private MeterCond1Temp RefreshCond1TempById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterCond1Temp(); + } + } + + + #endregion + + #region Cond2Temp表 + + + + /// + /// Cond2Temp 初始化函数 + /// + private void Cond2TempInit() + { + ListSlopMeterCond2TempItems = new ObservableCollection(); + SelectedSlopCond2Temp = new MeterCond2Temp(); + SelectedConstCond2Temp = new MeterCond2Temp(); + } + + + private ObservableCollection _ListSlopMeterCond2TempItems; + /// + /// Meter Cond2Temp数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterCond2TempItems + { + get { return _ListSlopMeterCond2TempItems; } + set { _ListSlopMeterCond2TempItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterCond2Temp集合数据 斜率 + /// + public List ListSlopMeterCond2Temp { get; set; } + + + private MeterCond2Temp _SelectedSlopCond2Temp; + /// + /// 当前选中的程序 Cond2Temp 斜率 + /// + public MeterCond2Temp SelectedSlopCond2Temp + { + get { return _SelectedSlopCond2Temp; } + set { _SelectedSlopCond2Temp = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterCond2TempExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 Cond2Temp + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterCond2TempExDto + { + get { return _MeterCond2TempExDto; } + set { _MeterCond2TempExDto = value; RaisePropertyChanged(); } + } + + + + private MeterCond2Temp _SelectedConstCond2Temp; + /// + /// 当前选中的程序 Cond2Temp 常值 + /// + public MeterCond2Temp SelectedConstCond2Temp + { + get { return _SelectedConstCond2Temp; } + set { _SelectedConstCond2Temp = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstCond2TempValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstCond2TempValue + { + get { return _SelectedConstCond2TempValue; } + set { _SelectedConstCond2TempValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterCond2TempSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterCond2TempSlopSelectedChangedCmd + { + set + { + _MeterCond2TempSlopSelectedChangedCmd = value; + } + get + { + if (_MeterCond2TempSlopSelectedChangedCmd == null) + { + _MeterCond2TempSlopSelectedChangedCmd = new DelegateCommand((str) => MeterCond2TempSlopSelectedChangedCmdMethod(str)); + } + return _MeterCond2TempSlopSelectedChangedCmd; + } + } + + + /// + /// Cond2Temp表选中行的执行方法 + /// + /// + /// + private void MeterCond2TempSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterCond2Temp; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopCond2Temp = new MeterCond2Temp + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepCond2TempAddCmd; + /// + /// 新增Cond2Temp命令 + /// + public DelegateCommand ProStepCond2TempAddCmd + { + set + { + _ProStepCond2TempAddCmd = value; + } + get + { + if (_ProStepCond2TempAddCmd == null) + { + _ProStepCond2TempAddCmd = new DelegateCommand(() => ProStepCond2TempAddCmdMethod()); + } + return _ProStepCond2TempAddCmd; + } + } + + /// + /// 增加Cond2Temp命令执行方法 + /// + private void ProStepCond2TempAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterCond2Temp.Sum(a => a.KeepTime) + SelectedSlopCond2Temp.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Temps!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Temps!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Temps!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterCond2Temps = ListSlopMeterCond2TempItems.ToList(); + + var MeterCond2TempData = new MeterCond2Temp() + { + StartValue = SelectedSlopCond2Temp.StartValue, + EndValue = SelectedSlopCond2Temp.EndValue, + KeepTime = SelectedSlopCond2Temp.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterCond2TempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterCond2TempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshCond2TempById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Temps!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Temps!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Temps!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Temps!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterCond2Temp.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterCond2TempItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterCond2TempInfo = MeterCond2TempToString(ListSlopMeterCond2Temp); + + //更新后检测时间是否匹配并界面提示 + CheckCond2TempSlopListTime(); + } + + + private DelegateCommand _ProStepCond2TempEditCmd; + /// + /// 新增Cond2Temp命令 + /// + public DelegateCommand ProStepCond2TempEditCmd + { + set + { + _ProStepCond2TempEditCmd = value; + } + get + { + if (_ProStepCond2TempEditCmd == null) + { + _ProStepCond2TempEditCmd = new DelegateCommand(() => ProStepCond2TempEditCmdMethod()); + } + return _ProStepCond2TempEditCmd; + } + } + + /// + /// 编辑Cond2Temp命令执行方法 + /// + private void ProStepCond2TempEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopCond2Temp == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterCond2Temp.Where(a => a.Id != SelectedSlopCond2Temp!.Id).Sum(a => a.KeepTime) + SelectedSlopCond2Temp!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopCond2Temp.StartValue) + .Set(a => a.EndValue, SelectedSlopCond2Temp.EndValue) + .Set(a => a.KeepTime, SelectedSlopCond2Temp.KeepTime) + .Set(a => a.StepNo, SelectedSlopCond2Temp.StepNo) + .Where(a => a.Id == SelectedSlopCond2Temp.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshCond2TempById(SelectedSlopCond2Temp.Id); + var CurIndex = ListSlopMeterCond2Temp.FindIndex(a => a.Id == SelectedSlopCond2Temp.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond2Temps!.Remove(ListSlopMeterCond2Temp.Find(a => a.Id == SelectedSlopCond2Temp!.Id)!); + //移除旧的数据 + ListSlopMeterCond2Temp.Remove(ListSlopMeterCond2Temp.Find(a => a.Id == SelectedSlopCond2Temp.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond2Temps!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterCond2Temp.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterCond2TempItems.Remove(ListSlopMeterCond2TempItems.Where(a => a.Id == SelectedSlopCond2Temp!.Id).FirstOrDefault()!); + ListSlopMeterCond2TempItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond2TempInfo = MeterCond2TempToString(ListSlopMeterCond2Temp); + + //更新后检测时间是否匹配并界面提示 + CheckCond2TempSlopListTime(); + } + + private DelegateCommand _ProStepCond2TempDeleteCmd; + /// + /// 新增Cond2Temp命令 + /// + public DelegateCommand ProStepCond2TempDeleteCmd + { + set + { + _ProStepCond2TempDeleteCmd = value; + } + get + { + if (_ProStepCond2TempDeleteCmd == null) + { + _ProStepCond2TempDeleteCmd = new DelegateCommand(() => ProStepCond2TempDeleteCmdMethod()); + } + return _ProStepCond2TempDeleteCmd; + } + } + + /// + /// 增加Cond2Temp命令执行方法 + /// + private void ProStepCond2TempDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopCond2Temp != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopCond2Temp!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond2Temps!.Remove(ListSlopMeterCond2Temp.Find(a => a.Id == SelectedSlopCond2Temp!.Id)!); + //移除旧的数据 + ListSlopMeterCond2Temp.Remove(ListSlopMeterCond2Temp.Find(a => a.Id == SelectedSlopCond2Temp.Id)!); + + //移除旧的数据 + ListSlopMeterCond2TempItems.Remove(ListSlopMeterCond2TempItems.Where(a => a.Id == SelectedSlopCond2Temp!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond2TempInfo = MeterCond2TempToString(ListSlopMeterCond2Temp); + + //更新后检测时间是否匹配并界面提示 + CheckCond2TempSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新Cond2Temp表信息 + /// + private void RefreshMeterCond2Temp() + { + ListSlopMeterCond2Temp = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterCond2Temps!.ToList(); + + ListSlopMeterCond2TempItems.Clear(); + + ListSlopMeterCond2TempItems = new ObservableCollection(ListSlopMeterCond2Temp!); + + } + + /// + /// 获取Cond2Temp当前的步骤的数据信息 + /// + private int AutoGetMeterCond2TempStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepCond2TempConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepCond2TempConstantSaveCmd + { + set + { + _ProStepCond2TempConstantSaveCmd = value; + } + get + { + if (_ProStepCond2TempConstantSaveCmd == null) + { + _ProStepCond2TempConstantSaveCmd = new DelegateCommand(() => ProStepCond2TempConstantSaveCmdMethod()); + } + return _ProStepCond2TempConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepCond2TempConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterCond2TempItems != null && ListSlopMeterCond2TempItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterCond2TempItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond2Temps!.Remove(ListSlopMeterCond2Temp.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterCond2Temp.Remove(ListSlopMeterCond2Temp.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterCond2TempItems.Remove(ListSlopMeterCond2TempItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond2TempInfo = MeterCond2TempToString(ListSlopMeterCond2Temp); + + //更新后检测时间是否匹配并界面提示 + CheckCond2TempSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstCond2TempData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Temps!.ToList(); + if (ConstCond2TempData != null && ConstCond2TempData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterCond2TempData = new MeterCond2Temp() + { + Constant = SelectedConstCond2TempValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterCond2TempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterCond2TempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshCond2TempById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Temps!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterCond2TempInfo = MeterCond2TempToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstCond2TempData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstCond2TempValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshCond2TempById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond2Temps!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond2Temps!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond2TempInfo = MeterCond2TempToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterCond2TempSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterCond2TempSwitchConstSlopPar + { + get { return _ProStepMeterCond2TempSwitchConstSlopPar; } + set { _ProStepMeterCond2TempSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepCond2TempSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepCond2TempSwitchConstSlopIndex + { + get { return _ProStepCond2TempSwitchConstSlopIndex; } + set { _ProStepCond2TempSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterCond2TempSwitchConstSlopCmd; + /// + /// Cond2Temp 常值和斜率切换 命令 + /// + public DelegateCommand MeterCond2TempSwitchConstSlopCmd + { + set + { + _MeterCond2TempSwitchConstSlopCmd = value; + } + get + { + if (_MeterCond2TempSwitchConstSlopCmd == null) + { + _MeterCond2TempSwitchConstSlopCmd = new DelegateCommand((obj) => MeterCond2TempSwitchConstSlopCmdMethod(obj)); + } + return _MeterCond2TempSwitchConstSlopCmd; + } + } + private void MeterCond2TempSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterCond2TempSwitchConstSlopPar = false; + } + else + { + ProStepMeterCond2TempSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterCond2TempToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckCond2TempSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterCond2TempExDto.SlopTime = ListSlopMeterCond2Temp.Sum(a => a.KeepTime); + if (MeterCond2TempExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterCond2TempExDto.SlopTime != 0) + { + MeterCond2TempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterCond2TempExDto.SlopTime; + MeterCond2TempExDto.IsTimeOk = false; + } + else + { + MeterCond2TempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterCond2TempExDto.SlopTime; + MeterCond2TempExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterCond2Temp数据 + /// + /// + private MeterCond2Temp RefreshCond2TempById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterCond2Temp(); + } + } + + + #endregion + + #region Cond2Press表 + + + + /// + /// Cond2Press 初始化函数 + /// + private void Cond2PressInit() + { + ListSlopMeterCond2PressItems = new ObservableCollection(); + SelectedSlopCond2Press = new MeterCond2Press(); + SelectedConstCond2Press = new MeterCond2Press(); + } + + + private ObservableCollection _ListSlopMeterCond2PressItems; + /// + /// Meter Cond2Press数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterCond2PressItems + { + get { return _ListSlopMeterCond2PressItems; } + set { _ListSlopMeterCond2PressItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterCond2Press集合数据 斜率 + /// + public List ListSlopMeterCond2Press { get; set; } + + + private MeterCond2Press _SelectedSlopCond2Press; + /// + /// 当前选中的程序 Cond2Press 斜率 + /// + public MeterCond2Press SelectedSlopCond2Press + { + get { return _SelectedSlopCond2Press; } + set { _SelectedSlopCond2Press = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterCond2PressExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 Cond2Press + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterCond2PressExDto + { + get { return _MeterCond2PressExDto; } + set { _MeterCond2PressExDto = value; RaisePropertyChanged(); } + } + + + + private MeterCond2Press _SelectedConstCond2Press; + /// + /// 当前选中的程序 Cond2Press 常值 + /// + public MeterCond2Press SelectedConstCond2Press + { + get { return _SelectedConstCond2Press; } + set { _SelectedConstCond2Press = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstCond2PressValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstCond2PressValue + { + get { return _SelectedConstCond2PressValue; } + set { _SelectedConstCond2PressValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterCond2PressSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterCond2PressSlopSelectedChangedCmd + { + set + { + _MeterCond2PressSlopSelectedChangedCmd = value; + } + get + { + if (_MeterCond2PressSlopSelectedChangedCmd == null) + { + _MeterCond2PressSlopSelectedChangedCmd = new DelegateCommand((str) => MeterCond2PressSlopSelectedChangedCmdMethod(str)); + } + return _MeterCond2PressSlopSelectedChangedCmd; + } + } + + + /// + /// Cond2Press表选中行的执行方法 + /// + /// + /// + private void MeterCond2PressSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterCond2Press; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopCond2Press = new MeterCond2Press + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepCond2PressAddCmd; + /// + /// 新增Cond2Press命令 + /// + public DelegateCommand ProStepCond2PressAddCmd + { + set + { + _ProStepCond2PressAddCmd = value; + } + get + { + if (_ProStepCond2PressAddCmd == null) + { + _ProStepCond2PressAddCmd = new DelegateCommand(() => ProStepCond2PressAddCmdMethod()); + } + return _ProStepCond2PressAddCmd; + } + } + + /// + /// 增加Cond2Press命令执行方法 + /// + private void ProStepCond2PressAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterCond2Press.Sum(a => a.KeepTime) + SelectedSlopCond2Press.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Presss!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Presss!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Presss!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterCond2Presss = ListSlopMeterCond2PressItems.ToList(); + + var MeterCond2PressData = new MeterCond2Press() + { + StartValue = SelectedSlopCond2Press.StartValue, + EndValue = SelectedSlopCond2Press.EndValue, + KeepTime = SelectedSlopCond2Press.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterCond2PressStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterCond2PressData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshCond2PressById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Presss!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Presss!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Presss!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Presss!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterCond2Press.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterCond2PressItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterCond2PressInfo = MeterCond2PressToString(ListSlopMeterCond2Press); + + //更新后检测时间是否匹配并界面提示 + CheckCond2PressSlopListTime(); + } + + + private DelegateCommand _ProStepCond2PressEditCmd; + /// + /// 新增Cond2Press命令 + /// + public DelegateCommand ProStepCond2PressEditCmd + { + set + { + _ProStepCond2PressEditCmd = value; + } + get + { + if (_ProStepCond2PressEditCmd == null) + { + _ProStepCond2PressEditCmd = new DelegateCommand(() => ProStepCond2PressEditCmdMethod()); + } + return _ProStepCond2PressEditCmd; + } + } + + /// + /// 编辑Cond2Press命令执行方法 + /// + private void ProStepCond2PressEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopCond2Press == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterCond2Press.Where(a => a.Id != SelectedSlopCond2Press!.Id).Sum(a => a.KeepTime) + SelectedSlopCond2Press!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopCond2Press.StartValue) + .Set(a => a.EndValue, SelectedSlopCond2Press.EndValue) + .Set(a => a.KeepTime, SelectedSlopCond2Press.KeepTime) + .Set(a => a.StepNo, SelectedSlopCond2Press.StepNo) + .Where(a => a.Id == SelectedSlopCond2Press.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshCond2PressById(SelectedSlopCond2Press.Id); + var CurIndex = ListSlopMeterCond2Press.FindIndex(a => a.Id == SelectedSlopCond2Press.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond2Presss!.Remove(ListSlopMeterCond2Press.Find(a => a.Id == SelectedSlopCond2Press!.Id)!); + //移除旧的数据 + ListSlopMeterCond2Press.Remove(ListSlopMeterCond2Press.Find(a => a.Id == SelectedSlopCond2Press.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond2Presss!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterCond2Press.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterCond2PressItems.Remove(ListSlopMeterCond2PressItems.Where(a => a.Id == SelectedSlopCond2Press!.Id).FirstOrDefault()!); + ListSlopMeterCond2PressItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond2PressInfo = MeterCond2PressToString(ListSlopMeterCond2Press); + + //更新后检测时间是否匹配并界面提示 + CheckCond2PressSlopListTime(); + } + + private DelegateCommand _ProStepCond2PressDeleteCmd; + /// + /// 新增Cond2Press命令 + /// + public DelegateCommand ProStepCond2PressDeleteCmd + { + set + { + _ProStepCond2PressDeleteCmd = value; + } + get + { + if (_ProStepCond2PressDeleteCmd == null) + { + _ProStepCond2PressDeleteCmd = new DelegateCommand(() => ProStepCond2PressDeleteCmdMethod()); + } + return _ProStepCond2PressDeleteCmd; + } + } + + /// + /// 增加Cond2Press命令执行方法 + /// + private void ProStepCond2PressDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopCond2Press != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopCond2Press!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond2Presss!.Remove(ListSlopMeterCond2Press.Find(a => a.Id == SelectedSlopCond2Press!.Id)!); + //移除旧的数据 + ListSlopMeterCond2Press.Remove(ListSlopMeterCond2Press.Find(a => a.Id == SelectedSlopCond2Press.Id)!); + + //移除旧的数据 + ListSlopMeterCond2PressItems.Remove(ListSlopMeterCond2PressItems.Where(a => a.Id == SelectedSlopCond2Press!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond2PressInfo = MeterCond2PressToString(ListSlopMeterCond2Press); + + //更新后检测时间是否匹配并界面提示 + CheckCond2PressSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新Cond2Press表信息 + /// + private void RefreshMeterCond2Press() + { + ListSlopMeterCond2Press = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterCond2Presss!.ToList(); + + ListSlopMeterCond2PressItems.Clear(); + + ListSlopMeterCond2PressItems = new ObservableCollection(ListSlopMeterCond2Press!); + + } + + /// + /// 获取Cond2Press当前的步骤的数据信息 + /// + private int AutoGetMeterCond2PressStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepCond2PressConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepCond2PressConstantSaveCmd + { + set + { + _ProStepCond2PressConstantSaveCmd = value; + } + get + { + if (_ProStepCond2PressConstantSaveCmd == null) + { + _ProStepCond2PressConstantSaveCmd = new DelegateCommand(() => ProStepCond2PressConstantSaveCmdMethod()); + } + return _ProStepCond2PressConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepCond2PressConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterCond2PressItems != null && ListSlopMeterCond2PressItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterCond2PressItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond2Presss!.Remove(ListSlopMeterCond2Press.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterCond2Press.Remove(ListSlopMeterCond2Press.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterCond2PressItems.Remove(ListSlopMeterCond2PressItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond2PressInfo = MeterCond2PressToString(ListSlopMeterCond2Press); + + //更新后检测时间是否匹配并界面提示 + CheckCond2PressSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstCond2PressData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Presss!.ToList(); + if (ConstCond2PressData != null && ConstCond2PressData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterCond2PressData = new MeterCond2Press() + { + Constant = SelectedConstCond2PressValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterCond2PressStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterCond2PressData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshCond2PressById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterCond2Presss!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterCond2PressInfo = MeterCond2PressToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstCond2PressData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstCond2PressValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshCond2PressById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond2Presss!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterCond2Presss!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterCond2PressInfo = MeterCond2PressToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterCond2PressSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterCond2PressSwitchConstSlopPar + { + get { return _ProStepMeterCond2PressSwitchConstSlopPar; } + set { _ProStepMeterCond2PressSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepCond2PressSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepCond2PressSwitchConstSlopIndex + { + get { return _ProStepCond2PressSwitchConstSlopIndex; } + set { _ProStepCond2PressSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterCond2PressSwitchConstSlopCmd; + /// + /// Cond2Press 常值和斜率切换 命令 + /// + public DelegateCommand MeterCond2PressSwitchConstSlopCmd + { + set + { + _MeterCond2PressSwitchConstSlopCmd = value; + } + get + { + if (_MeterCond2PressSwitchConstSlopCmd == null) + { + _MeterCond2PressSwitchConstSlopCmd = new DelegateCommand((obj) => MeterCond2PressSwitchConstSlopCmdMethod(obj)); + } + return _MeterCond2PressSwitchConstSlopCmd; + } + } + private void MeterCond2PressSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterCond2PressSwitchConstSlopPar = false; + } + else + { + ProStepMeterCond2PressSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterCond2PressToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckCond2PressSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterCond2PressExDto.SlopTime = ListSlopMeterCond2Press.Sum(a => a.KeepTime); + if (MeterCond2PressExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterCond2PressExDto.SlopTime != 0) + { + MeterCond2PressExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterCond2PressExDto.SlopTime; + MeterCond2PressExDto.IsTimeOk = false; + } + else + { + MeterCond2PressExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterCond2PressExDto.SlopTime; + MeterCond2PressExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterCond2Press数据 + /// + /// + private MeterCond2Press RefreshCond2PressById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterCond2Press(); + } + } + + + #endregion + + #region EVAPExpTemp表 + + + + /// + /// EVAPExpTemp 初始化函数 + /// + private void EVAPExpTempInit() + { + ListSlopMeterEVAPExpTempItems = new ObservableCollection(); + SelectedSlopEVAPExpTemp = new MeterEVAPExpTemp(); + SelectedConstEVAPExpTemp = new MeterEVAPExpTemp(); + } + + + private ObservableCollection _ListSlopMeterEVAPExpTempItems; + /// + /// Meter EVAPExpTemp数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterEVAPExpTempItems + { + get { return _ListSlopMeterEVAPExpTempItems; } + set { _ListSlopMeterEVAPExpTempItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterEVAPExpTemp集合数据 斜率 + /// + public List ListSlopMeterEVAPExpTemp { get; set; } + + + private MeterEVAPExpTemp _SelectedSlopEVAPExpTemp; + /// + /// 当前选中的程序 EVAPExpTemp 斜率 + /// + public MeterEVAPExpTemp SelectedSlopEVAPExpTemp + { + get { return _SelectedSlopEVAPExpTemp; } + set { _SelectedSlopEVAPExpTemp = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterEVAPExpTempExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 EVAPExpTemp + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterEVAPExpTempExDto + { + get { return _MeterEVAPExpTempExDto; } + set { _MeterEVAPExpTempExDto = value; RaisePropertyChanged(); } + } + + + + private MeterEVAPExpTemp _SelectedConstEVAPExpTemp; + /// + /// 当前选中的程序 EVAPExpTemp 常值 + /// + public MeterEVAPExpTemp SelectedConstEVAPExpTemp + { + get { return _SelectedConstEVAPExpTemp; } + set { _SelectedConstEVAPExpTemp = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstEVAPExpTempValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstEVAPExpTempValue + { + get { return _SelectedConstEVAPExpTempValue; } + set { _SelectedConstEVAPExpTempValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterEVAPExpTempSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterEVAPExpTempSlopSelectedChangedCmd + { + set + { + _MeterEVAPExpTempSlopSelectedChangedCmd = value; + } + get + { + if (_MeterEVAPExpTempSlopSelectedChangedCmd == null) + { + _MeterEVAPExpTempSlopSelectedChangedCmd = new DelegateCommand((str) => MeterEVAPExpTempSlopSelectedChangedCmdMethod(str)); + } + return _MeterEVAPExpTempSlopSelectedChangedCmd; + } + } + + + /// + /// EVAPExpTemp表选中行的执行方法 + /// + /// + /// + private void MeterEVAPExpTempSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterEVAPExpTemp; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopEVAPExpTemp = new MeterEVAPExpTemp + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepEVAPExpTempAddCmd; + /// + /// 新增EVAPExpTemp命令 + /// + public DelegateCommand ProStepEVAPExpTempAddCmd + { + set + { + _ProStepEVAPExpTempAddCmd = value; + } + get + { + if (_ProStepEVAPExpTempAddCmd == null) + { + _ProStepEVAPExpTempAddCmd = new DelegateCommand(() => ProStepEVAPExpTempAddCmdMethod()); + } + return _ProStepEVAPExpTempAddCmd; + } + } + + /// + /// 增加EVAPExpTemp命令执行方法 + /// + private void ProStepEVAPExpTempAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterEVAPExpTemp.Sum(a => a.KeepTime) + SelectedSlopEVAPExpTemp.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEVAPExpTemps!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEVAPExpTemps!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEVAPExpTemps!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterEVAPExpTemps = ListSlopMeterEVAPExpTempItems.ToList(); + + var MeterEVAPExpTempData = new MeterEVAPExpTemp() + { + StartValue = SelectedSlopEVAPExpTemp.StartValue, + EndValue = SelectedSlopEVAPExpTemp.EndValue, + KeepTime = SelectedSlopEVAPExpTemp.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterEVAPExpTempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterEVAPExpTempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshEVAPExpTempById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEVAPExpTemps!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEVAPExpTemps!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEVAPExpTemps!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEVAPExpTemps!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterEVAPExpTemp.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterEVAPExpTempItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterEVAPExpTempInfo = MeterEVAPExpTempToString(ListSlopMeterEVAPExpTemp); + + //更新后检测时间是否匹配并界面提示 + CheckEVAPExpTempSlopListTime(); + } + + + private DelegateCommand _ProStepEVAPExpTempEditCmd; + /// + /// 新增EVAPExpTemp命令 + /// + public DelegateCommand ProStepEVAPExpTempEditCmd + { + set + { + _ProStepEVAPExpTempEditCmd = value; + } + get + { + if (_ProStepEVAPExpTempEditCmd == null) + { + _ProStepEVAPExpTempEditCmd = new DelegateCommand(() => ProStepEVAPExpTempEditCmdMethod()); + } + return _ProStepEVAPExpTempEditCmd; + } + } + + /// + /// 编辑EVAPExpTemp命令执行方法 + /// + private void ProStepEVAPExpTempEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopEVAPExpTemp == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterEVAPExpTemp.Where(a => a.Id != SelectedSlopEVAPExpTemp!.Id).Sum(a => a.KeepTime) + SelectedSlopEVAPExpTemp!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopEVAPExpTemp.StartValue) + .Set(a => a.EndValue, SelectedSlopEVAPExpTemp.EndValue) + .Set(a => a.KeepTime, SelectedSlopEVAPExpTemp.KeepTime) + .Set(a => a.StepNo, SelectedSlopEVAPExpTemp.StepNo) + .Where(a => a.Id == SelectedSlopEVAPExpTemp.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshEVAPExpTempById(SelectedSlopEVAPExpTemp.Id); + var CurIndex = ListSlopMeterEVAPExpTemp.FindIndex(a => a.Id == SelectedSlopEVAPExpTemp.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEVAPExpTemps!.Remove(ListSlopMeterEVAPExpTemp.Find(a => a.Id == SelectedSlopEVAPExpTemp!.Id)!); + //移除旧的数据 + ListSlopMeterEVAPExpTemp.Remove(ListSlopMeterEVAPExpTemp.Find(a => a.Id == SelectedSlopEVAPExpTemp.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEVAPExpTemps!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterEVAPExpTemp.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterEVAPExpTempItems.Remove(ListSlopMeterEVAPExpTempItems.Where(a => a.Id == SelectedSlopEVAPExpTemp!.Id).FirstOrDefault()!); + ListSlopMeterEVAPExpTempItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEVAPExpTempInfo = MeterEVAPExpTempToString(ListSlopMeterEVAPExpTemp); + + //更新后检测时间是否匹配并界面提示 + CheckEVAPExpTempSlopListTime(); + } + + private DelegateCommand _ProStepEVAPExpTempDeleteCmd; + /// + /// 新增EVAPExpTemp命令 + /// + public DelegateCommand ProStepEVAPExpTempDeleteCmd + { + set + { + _ProStepEVAPExpTempDeleteCmd = value; + } + get + { + if (_ProStepEVAPExpTempDeleteCmd == null) + { + _ProStepEVAPExpTempDeleteCmd = new DelegateCommand(() => ProStepEVAPExpTempDeleteCmdMethod()); + } + return _ProStepEVAPExpTempDeleteCmd; + } + } + + /// + /// 增加EVAPExpTemp命令执行方法 + /// + private void ProStepEVAPExpTempDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopEVAPExpTemp != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopEVAPExpTemp!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEVAPExpTemps!.Remove(ListSlopMeterEVAPExpTemp.Find(a => a.Id == SelectedSlopEVAPExpTemp!.Id)!); + //移除旧的数据 + ListSlopMeterEVAPExpTemp.Remove(ListSlopMeterEVAPExpTemp.Find(a => a.Id == SelectedSlopEVAPExpTemp.Id)!); + + //移除旧的数据 + ListSlopMeterEVAPExpTempItems.Remove(ListSlopMeterEVAPExpTempItems.Where(a => a.Id == SelectedSlopEVAPExpTemp!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEVAPExpTempInfo = MeterEVAPExpTempToString(ListSlopMeterEVAPExpTemp); + + //更新后检测时间是否匹配并界面提示 + CheckEVAPExpTempSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新EVAPExpTemp表信息 + /// + private void RefreshMeterEVAPExpTemp() + { + ListSlopMeterEVAPExpTemp = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterEVAPExpTemps!.ToList(); + + ListSlopMeterEVAPExpTempItems.Clear(); + + ListSlopMeterEVAPExpTempItems = new ObservableCollection(ListSlopMeterEVAPExpTemp!); + + } + + /// + /// 获取EVAPExpTemp当前的步骤的数据信息 + /// + private int AutoGetMeterEVAPExpTempStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepEVAPExpTempConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepEVAPExpTempConstantSaveCmd + { + set + { + _ProStepEVAPExpTempConstantSaveCmd = value; + } + get + { + if (_ProStepEVAPExpTempConstantSaveCmd == null) + { + _ProStepEVAPExpTempConstantSaveCmd = new DelegateCommand(() => ProStepEVAPExpTempConstantSaveCmdMethod()); + } + return _ProStepEVAPExpTempConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepEVAPExpTempConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterEVAPExpTempItems != null && ListSlopMeterEVAPExpTempItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterEVAPExpTempItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEVAPExpTemps!.Remove(ListSlopMeterEVAPExpTemp.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterEVAPExpTemp.Remove(ListSlopMeterEVAPExpTemp.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterEVAPExpTempItems.Remove(ListSlopMeterEVAPExpTempItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEVAPExpTempInfo = MeterEVAPExpTempToString(ListSlopMeterEVAPExpTemp); + + //更新后检测时间是否匹配并界面提示 + CheckEVAPExpTempSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstEVAPExpTempData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEVAPExpTemps!.ToList(); + if (ConstEVAPExpTempData != null && ConstEVAPExpTempData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterEVAPExpTempData = new MeterEVAPExpTemp() + { + Constant = SelectedConstEVAPExpTempValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterEVAPExpTempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterEVAPExpTempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshEVAPExpTempById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEVAPExpTemps!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterEVAPExpTempInfo = MeterEVAPExpTempToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstEVAPExpTempData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstEVAPExpTempValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshEVAPExpTempById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEVAPExpTemps!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEVAPExpTemps!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEVAPExpTempInfo = MeterEVAPExpTempToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterEVAPExpTempSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterEVAPExpTempSwitchConstSlopPar + { + get { return _ProStepMeterEVAPExpTempSwitchConstSlopPar; } + set { _ProStepMeterEVAPExpTempSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepEVAPExpTempSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepEVAPExpTempSwitchConstSlopIndex + { + get { return _ProStepEVAPExpTempSwitchConstSlopIndex; } + set { _ProStepEVAPExpTempSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterEVAPExpTempSwitchConstSlopCmd; + /// + /// EVAPExpTemp 常值和斜率切换 命令 + /// + public DelegateCommand MeterEVAPExpTempSwitchConstSlopCmd + { + set + { + _MeterEVAPExpTempSwitchConstSlopCmd = value; + } + get + { + if (_MeterEVAPExpTempSwitchConstSlopCmd == null) + { + _MeterEVAPExpTempSwitchConstSlopCmd = new DelegateCommand((obj) => MeterEVAPExpTempSwitchConstSlopCmdMethod(obj)); + } + return _MeterEVAPExpTempSwitchConstSlopCmd; + } + } + private void MeterEVAPExpTempSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterEVAPExpTempSwitchConstSlopPar = false; + } + else + { + ProStepMeterEVAPExpTempSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterEVAPExpTempToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckEVAPExpTempSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterEVAPExpTempExDto.SlopTime = ListSlopMeterEVAPExpTemp.Sum(a => a.KeepTime); + if (MeterEVAPExpTempExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterEVAPExpTempExDto.SlopTime != 0) + { + MeterEVAPExpTempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterEVAPExpTempExDto.SlopTime; + MeterEVAPExpTempExDto.IsTimeOk = false; + } + else + { + MeterEVAPExpTempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterEVAPExpTempExDto.SlopTime; + MeterEVAPExpTempExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterEVAPExpTemp数据 + /// + /// + private MeterEVAPExpTemp RefreshEVAPExpTempById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterEVAPExpTemp(); + } + } + + + #endregion + + #region HVVol表 + + + + /// + /// HVVol 初始化函数 + /// + private void HVVolInit() + { + ListSlopMeterHVVolItems = new ObservableCollection(); + SelectedSlopHVVol = new MeterHVVol(); + SelectedConstHVVol = new MeterHVVol(); + } + + + private ObservableCollection _ListSlopMeterHVVolItems; + /// + /// Meter HVVol数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterHVVolItems + { + get { return _ListSlopMeterHVVolItems; } + set { _ListSlopMeterHVVolItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterHVVol集合数据 斜率 + /// + public List ListSlopMeterHVVol { get; set; } + + + private MeterHVVol _SelectedSlopHVVol; + /// + /// 当前选中的程序 HVVol 斜率 + /// + public MeterHVVol SelectedSlopHVVol + { + get { return _SelectedSlopHVVol; } + set { _SelectedSlopHVVol = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterHVVolExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 HVVol + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterHVVolExDto + { + get { return _MeterHVVolExDto; } + set { _MeterHVVolExDto = value; RaisePropertyChanged(); } + } + + + + private MeterHVVol _SelectedConstHVVol; + /// + /// 当前选中的程序 HVVol 常值 + /// + public MeterHVVol SelectedConstHVVol + { + get { return _SelectedConstHVVol; } + set { _SelectedConstHVVol = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstHVVolValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstHVVolValue + { + get { return _SelectedConstHVVolValue; } + set { _SelectedConstHVVolValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterHVVolSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterHVVolSlopSelectedChangedCmd + { + set + { + _MeterHVVolSlopSelectedChangedCmd = value; + } + get + { + if (_MeterHVVolSlopSelectedChangedCmd == null) + { + _MeterHVVolSlopSelectedChangedCmd = new DelegateCommand((str) => MeterHVVolSlopSelectedChangedCmdMethod(str)); + } + return _MeterHVVolSlopSelectedChangedCmd; + } + } + + + /// + /// HVVol表选中行的执行方法 + /// + /// + /// + private void MeterHVVolSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterHVVol; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopHVVol = new MeterHVVol + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepHVVolAddCmd; + /// + /// 新增HVVol命令 + /// + public DelegateCommand ProStepHVVolAddCmd + { + set + { + _ProStepHVVolAddCmd = value; + } + get + { + if (_ProStepHVVolAddCmd == null) + { + _ProStepHVVolAddCmd = new DelegateCommand(() => ProStepHVVolAddCmdMethod()); + } + return _ProStepHVVolAddCmd; + } + } + + /// + /// 增加HVVol命令执行方法 + /// + private void ProStepHVVolAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterHVVol.Sum(a => a.KeepTime) + SelectedSlopHVVol.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterHVVols!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterHVVols!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterHVVols!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterHVVols = ListSlopMeterHVVolItems.ToList(); + + var MeterHVVolData = new MeterHVVol() + { + StartValue = SelectedSlopHVVol.StartValue, + EndValue = SelectedSlopHVVol.EndValue, + KeepTime = SelectedSlopHVVol.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterHVVolStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterHVVolData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshHVVolById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterHVVols!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterHVVols!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterHVVols!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterHVVols!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterHVVol.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterHVVolItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterHVVolInfo = MeterHVVolToString(ListSlopMeterHVVol); + + //更新后检测时间是否匹配并界面提示 + CheckHVVolSlopListTime(); + } + + + private DelegateCommand _ProStepHVVolEditCmd; + /// + /// 新增HVVol命令 + /// + public DelegateCommand ProStepHVVolEditCmd + { + set + { + _ProStepHVVolEditCmd = value; + } + get + { + if (_ProStepHVVolEditCmd == null) + { + _ProStepHVVolEditCmd = new DelegateCommand(() => ProStepHVVolEditCmdMethod()); + } + return _ProStepHVVolEditCmd; + } + } + + /// + /// 编辑HVVol命令执行方法 + /// + private void ProStepHVVolEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopHVVol == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterHVVol.Where(a => a.Id != SelectedSlopHVVol!.Id).Sum(a => a.KeepTime) + SelectedSlopHVVol!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopHVVol.StartValue) + .Set(a => a.EndValue, SelectedSlopHVVol.EndValue) + .Set(a => a.KeepTime, SelectedSlopHVVol.KeepTime) + .Set(a => a.StepNo, SelectedSlopHVVol.StepNo) + .Where(a => a.Id == SelectedSlopHVVol.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshHVVolById(SelectedSlopHVVol.Id); + var CurIndex = ListSlopMeterHVVol.FindIndex(a => a.Id == SelectedSlopHVVol.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterHVVols!.Remove(ListSlopMeterHVVol.Find(a => a.Id == SelectedSlopHVVol!.Id)!); + //移除旧的数据 + ListSlopMeterHVVol.Remove(ListSlopMeterHVVol.Find(a => a.Id == SelectedSlopHVVol.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterHVVols!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterHVVol.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterHVVolItems.Remove(ListSlopMeterHVVolItems.Where(a => a.Id == SelectedSlopHVVol!.Id).FirstOrDefault()!); + ListSlopMeterHVVolItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterHVVolInfo = MeterHVVolToString(ListSlopMeterHVVol); + + //更新后检测时间是否匹配并界面提示 + CheckHVVolSlopListTime(); + } + + private DelegateCommand _ProStepHVVolDeleteCmd; + /// + /// 新增HVVol命令 + /// + public DelegateCommand ProStepHVVolDeleteCmd + { + set + { + _ProStepHVVolDeleteCmd = value; + } + get + { + if (_ProStepHVVolDeleteCmd == null) + { + _ProStepHVVolDeleteCmd = new DelegateCommand(() => ProStepHVVolDeleteCmdMethod()); + } + return _ProStepHVVolDeleteCmd; + } + } + + /// + /// 增加HVVol命令执行方法 + /// + private void ProStepHVVolDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopHVVol != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopHVVol!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterHVVols!.Remove(ListSlopMeterHVVol.Find(a => a.Id == SelectedSlopHVVol!.Id)!); + //移除旧的数据 + ListSlopMeterHVVol.Remove(ListSlopMeterHVVol.Find(a => a.Id == SelectedSlopHVVol.Id)!); + + //移除旧的数据 + ListSlopMeterHVVolItems.Remove(ListSlopMeterHVVolItems.Where(a => a.Id == SelectedSlopHVVol!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterHVVolInfo = MeterHVVolToString(ListSlopMeterHVVol); + + //更新后检测时间是否匹配并界面提示 + CheckHVVolSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新HVVol表信息 + /// + private void RefreshMeterHVVol() + { + ListSlopMeterHVVol = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterHVVols!.ToList(); + + ListSlopMeterHVVolItems.Clear(); + + ListSlopMeterHVVolItems = new ObservableCollection(ListSlopMeterHVVol!); + + } + + /// + /// 获取HVVol当前的步骤的数据信息 + /// + private int AutoGetMeterHVVolStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepHVVolConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepHVVolConstantSaveCmd + { + set + { + _ProStepHVVolConstantSaveCmd = value; + } + get + { + if (_ProStepHVVolConstantSaveCmd == null) + { + _ProStepHVVolConstantSaveCmd = new DelegateCommand(() => ProStepHVVolConstantSaveCmdMethod()); + } + return _ProStepHVVolConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepHVVolConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterHVVolItems != null && ListSlopMeterHVVolItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterHVVolItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterHVVols!.Remove(ListSlopMeterHVVol.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterHVVol.Remove(ListSlopMeterHVVol.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterHVVolItems.Remove(ListSlopMeterHVVolItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterHVVolInfo = MeterHVVolToString(ListSlopMeterHVVol); + + //更新后检测时间是否匹配并界面提示 + CheckHVVolSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstHVVolData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterHVVols!.ToList(); + if (ConstHVVolData != null && ConstHVVolData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterHVVolData = new MeterHVVol() + { + Constant = SelectedConstHVVolValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterHVVolStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterHVVolData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshHVVolById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterHVVols!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterHVVolInfo = MeterHVVolToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstHVVolData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstHVVolValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshHVVolById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterHVVols!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterHVVols!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterHVVolInfo = MeterHVVolToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterHVVolSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterHVVolSwitchConstSlopPar + { + get { return _ProStepMeterHVVolSwitchConstSlopPar; } + set { _ProStepMeterHVVolSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepHVVolSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepHVVolSwitchConstSlopIndex + { + get { return _ProStepHVVolSwitchConstSlopIndex; } + set { _ProStepHVVolSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterHVVolSwitchConstSlopCmd; + /// + /// HVVol 常值和斜率切换 命令 + /// + public DelegateCommand MeterHVVolSwitchConstSlopCmd + { + set + { + _MeterHVVolSwitchConstSlopCmd = value; + } + get + { + if (_MeterHVVolSwitchConstSlopCmd == null) + { + _MeterHVVolSwitchConstSlopCmd = new DelegateCommand((obj) => MeterHVVolSwitchConstSlopCmdMethod(obj)); + } + return _MeterHVVolSwitchConstSlopCmd; + } + } + private void MeterHVVolSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterHVVolSwitchConstSlopPar = false; + } + else + { + ProStepMeterHVVolSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterHVVolToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckHVVolSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterHVVolExDto.SlopTime = ListSlopMeterHVVol.Sum(a => a.KeepTime); + if (MeterHVVolExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterHVVolExDto.SlopTime != 0) + { + MeterHVVolExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterHVVolExDto.SlopTime; + MeterHVVolExDto.IsTimeOk = false; + } + else + { + MeterHVVolExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterHVVolExDto.SlopTime; + MeterHVVolExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterHVVol数据 + /// + /// + private MeterHVVol RefreshHVVolById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterHVVol(); + } + } + + + #endregion + + #region LubePress表 + + + + /// + /// LubePress 初始化函数 + /// + private void LubePressInit() + { + ListSlopMeterLubePressItems = new ObservableCollection(); + SelectedSlopLubePress = new MeterLubePress(); + SelectedConstLubePress = new MeterLubePress(); + } + + + private ObservableCollection _ListSlopMeterLubePressItems; + /// + /// Meter LubePress数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterLubePressItems + { + get { return _ListSlopMeterLubePressItems; } + set { _ListSlopMeterLubePressItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterLubePress集合数据 斜率 + /// + public List ListSlopMeterLubePress { get; set; } + + + private MeterLubePress _SelectedSlopLubePress; + /// + /// 当前选中的程序 LubePress 斜率 + /// + public MeterLubePress SelectedSlopLubePress + { + get { return _SelectedSlopLubePress; } + set { _SelectedSlopLubePress = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterLubePressExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 LubePress + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterLubePressExDto + { + get { return _MeterLubePressExDto; } + set { _MeterLubePressExDto = value; RaisePropertyChanged(); } + } + + + + private MeterLubePress _SelectedConstLubePress; + /// + /// 当前选中的程序 LubePress 常值 + /// + public MeterLubePress SelectedConstLubePress + { + get { return _SelectedConstLubePress; } + set { _SelectedConstLubePress = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstLubePressValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstLubePressValue + { + get { return _SelectedConstLubePressValue; } + set { _SelectedConstLubePressValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterLubePressSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterLubePressSlopSelectedChangedCmd + { + set + { + _MeterLubePressSlopSelectedChangedCmd = value; + } + get + { + if (_MeterLubePressSlopSelectedChangedCmd == null) + { + _MeterLubePressSlopSelectedChangedCmd = new DelegateCommand((str) => MeterLubePressSlopSelectedChangedCmdMethod(str)); + } + return _MeterLubePressSlopSelectedChangedCmd; + } + } + + + /// + /// LubePress表选中行的执行方法 + /// + /// + /// + private void MeterLubePressSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterLubePress; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopLubePress = new MeterLubePress + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepLubePressAddCmd; + /// + /// 新增LubePress命令 + /// + public DelegateCommand ProStepLubePressAddCmd + { + set + { + _ProStepLubePressAddCmd = value; + } + get + { + if (_ProStepLubePressAddCmd == null) + { + _ProStepLubePressAddCmd = new DelegateCommand(() => ProStepLubePressAddCmdMethod()); + } + return _ProStepLubePressAddCmd; + } + } + + /// + /// 增加LubePress命令执行方法 + /// + private void ProStepLubePressAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterLubePress.Sum(a => a.KeepTime) + SelectedSlopLubePress.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLubePresss!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLubePresss!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLubePresss!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterLubePresss = ListSlopMeterLubePressItems.ToList(); + + var MeterLubePressData = new MeterLubePress() + { + StartValue = SelectedSlopLubePress.StartValue, + EndValue = SelectedSlopLubePress.EndValue, + KeepTime = SelectedSlopLubePress.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterLubePressStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterLubePressData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshLubePressById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLubePresss!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLubePresss!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLubePresss!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLubePresss!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterLubePress.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterLubePressItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterLubePressInfo = MeterLubePressToString(ListSlopMeterLubePress); + + //更新后检测时间是否匹配并界面提示 + CheckLubePressSlopListTime(); + } + + + private DelegateCommand _ProStepLubePressEditCmd; + /// + /// 新增LubePress命令 + /// + public DelegateCommand ProStepLubePressEditCmd + { + set + { + _ProStepLubePressEditCmd = value; + } + get + { + if (_ProStepLubePressEditCmd == null) + { + _ProStepLubePressEditCmd = new DelegateCommand(() => ProStepLubePressEditCmdMethod()); + } + return _ProStepLubePressEditCmd; + } + } + + /// + /// 编辑LubePress命令执行方法 + /// + private void ProStepLubePressEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopLubePress == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterLubePress.Where(a => a.Id != SelectedSlopLubePress!.Id).Sum(a => a.KeepTime) + SelectedSlopLubePress!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopLubePress.StartValue) + .Set(a => a.EndValue, SelectedSlopLubePress.EndValue) + .Set(a => a.KeepTime, SelectedSlopLubePress.KeepTime) + .Set(a => a.StepNo, SelectedSlopLubePress.StepNo) + .Where(a => a.Id == SelectedSlopLubePress.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshLubePressById(SelectedSlopLubePress.Id); + var CurIndex = ListSlopMeterLubePress.FindIndex(a => a.Id == SelectedSlopLubePress.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterLubePresss!.Remove(ListSlopMeterLubePress.Find(a => a.Id == SelectedSlopLubePress!.Id)!); + //移除旧的数据 + ListSlopMeterLubePress.Remove(ListSlopMeterLubePress.Find(a => a.Id == SelectedSlopLubePress.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterLubePresss!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterLubePress.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterLubePressItems.Remove(ListSlopMeterLubePressItems.Where(a => a.Id == SelectedSlopLubePress!.Id).FirstOrDefault()!); + ListSlopMeterLubePressItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterLubePressInfo = MeterLubePressToString(ListSlopMeterLubePress); + + //更新后检测时间是否匹配并界面提示 + CheckLubePressSlopListTime(); + } + + private DelegateCommand _ProStepLubePressDeleteCmd; + /// + /// 新增LubePress命令 + /// + public DelegateCommand ProStepLubePressDeleteCmd + { + set + { + _ProStepLubePressDeleteCmd = value; + } + get + { + if (_ProStepLubePressDeleteCmd == null) + { + _ProStepLubePressDeleteCmd = new DelegateCommand(() => ProStepLubePressDeleteCmdMethod()); + } + return _ProStepLubePressDeleteCmd; + } + } + + /// + /// 增加LubePress命令执行方法 + /// + private void ProStepLubePressDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopLubePress != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopLubePress!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterLubePresss!.Remove(ListSlopMeterLubePress.Find(a => a.Id == SelectedSlopLubePress!.Id)!); + //移除旧的数据 + ListSlopMeterLubePress.Remove(ListSlopMeterLubePress.Find(a => a.Id == SelectedSlopLubePress.Id)!); + + //移除旧的数据 + ListSlopMeterLubePressItems.Remove(ListSlopMeterLubePressItems.Where(a => a.Id == SelectedSlopLubePress!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterLubePressInfo = MeterLubePressToString(ListSlopMeterLubePress); + + //更新后检测时间是否匹配并界面提示 + CheckLubePressSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新LubePress表信息 + /// + private void RefreshMeterLubePress() + { + ListSlopMeterLubePress = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterLubePresss!.ToList(); + + ListSlopMeterLubePressItems.Clear(); + + ListSlopMeterLubePressItems = new ObservableCollection(ListSlopMeterLubePress!); + + } + + /// + /// 获取LubePress当前的步骤的数据信息 + /// + private int AutoGetMeterLubePressStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepLubePressConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepLubePressConstantSaveCmd + { + set + { + _ProStepLubePressConstantSaveCmd = value; + } + get + { + if (_ProStepLubePressConstantSaveCmd == null) + { + _ProStepLubePressConstantSaveCmd = new DelegateCommand(() => ProStepLubePressConstantSaveCmdMethod()); + } + return _ProStepLubePressConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepLubePressConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterLubePressItems != null && ListSlopMeterLubePressItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterLubePressItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterLubePresss!.Remove(ListSlopMeterLubePress.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterLubePress.Remove(ListSlopMeterLubePress.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterLubePressItems.Remove(ListSlopMeterLubePressItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterLubePressInfo = MeterLubePressToString(ListSlopMeterLubePress); + + //更新后检测时间是否匹配并界面提示 + CheckLubePressSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstLubePressData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLubePresss!.ToList(); + if (ConstLubePressData != null && ConstLubePressData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterLubePressData = new MeterLubePress() + { + Constant = SelectedConstLubePressValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterLubePressStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterLubePressData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshLubePressById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLubePresss!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterLubePressInfo = MeterLubePressToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstLubePressData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstLubePressValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshLubePressById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterLubePresss!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterLubePresss!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterLubePressInfo = MeterLubePressToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterLubePressSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterLubePressSwitchConstSlopPar + { + get { return _ProStepMeterLubePressSwitchConstSlopPar; } + set { _ProStepMeterLubePressSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepLubePressSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepLubePressSwitchConstSlopIndex + { + get { return _ProStepLubePressSwitchConstSlopIndex; } + set { _ProStepLubePressSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterLubePressSwitchConstSlopCmd; + /// + /// LubePress 常值和斜率切换 命令 + /// + public DelegateCommand MeterLubePressSwitchConstSlopCmd + { + set + { + _MeterLubePressSwitchConstSlopCmd = value; + } + get + { + if (_MeterLubePressSwitchConstSlopCmd == null) + { + _MeterLubePressSwitchConstSlopCmd = new DelegateCommand((obj) => MeterLubePressSwitchConstSlopCmdMethod(obj)); + } + return _MeterLubePressSwitchConstSlopCmd; + } + } + private void MeterLubePressSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterLubePressSwitchConstSlopPar = false; + } + else + { + ProStepMeterLubePressSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterLubePressToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckLubePressSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterLubePressExDto.SlopTime = ListSlopMeterLubePress.Sum(a => a.KeepTime); + if (MeterLubePressExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterLubePressExDto.SlopTime != 0) + { + MeterLubePressExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterLubePressExDto.SlopTime; + MeterLubePressExDto.IsTimeOk = false; + } + else + { + MeterLubePressExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterLubePressExDto.SlopTime; + MeterLubePressExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterLubePress数据 + /// + /// + private MeterLubePress RefreshLubePressById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterLubePress(); + } + } + + + #endregion + + #region LVVol表 + + + + /// + /// LVVol 初始化函数 + /// + private void LVVolInit() + { + ListSlopMeterLVVolItems = new ObservableCollection(); + SelectedSlopLVVol = new MeterLVVol(); + SelectedConstLVVol = new MeterLVVol(); + } + + + private ObservableCollection _ListSlopMeterLVVolItems; + /// + /// Meter LVVol数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterLVVolItems + { + get { return _ListSlopMeterLVVolItems; } + set { _ListSlopMeterLVVolItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterLVVol集合数据 斜率 + /// + public List ListSlopMeterLVVol { get; set; } + + + private MeterLVVol _SelectedSlopLVVol; + /// + /// 当前选中的程序 LVVol 斜率 + /// + public MeterLVVol SelectedSlopLVVol + { + get { return _SelectedSlopLVVol; } + set { _SelectedSlopLVVol = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterLVVolExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 LVVol + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterLVVolExDto + { + get { return _MeterLVVolExDto; } + set { _MeterLVVolExDto = value; RaisePropertyChanged(); } + } + + + + private MeterLVVol _SelectedConstLVVol; + /// + /// 当前选中的程序 LVVol 常值 + /// + public MeterLVVol SelectedConstLVVol + { + get { return _SelectedConstLVVol; } + set { _SelectedConstLVVol = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstLVVolValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstLVVolValue + { + get { return _SelectedConstLVVolValue; } + set { _SelectedConstLVVolValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterLVVolSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterLVVolSlopSelectedChangedCmd + { + set + { + _MeterLVVolSlopSelectedChangedCmd = value; + } + get + { + if (_MeterLVVolSlopSelectedChangedCmd == null) + { + _MeterLVVolSlopSelectedChangedCmd = new DelegateCommand((str) => MeterLVVolSlopSelectedChangedCmdMethod(str)); + } + return _MeterLVVolSlopSelectedChangedCmd; + } + } + + + /// + /// LVVol表选中行的执行方法 + /// + /// + /// + private void MeterLVVolSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterLVVol; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopLVVol = new MeterLVVol + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepLVVolAddCmd; + /// + /// 新增LVVol命令 + /// + public DelegateCommand ProStepLVVolAddCmd + { + set + { + _ProStepLVVolAddCmd = value; + } + get + { + if (_ProStepLVVolAddCmd == null) + { + _ProStepLVVolAddCmd = new DelegateCommand(() => ProStepLVVolAddCmdMethod()); + } + return _ProStepLVVolAddCmd; + } + } + + /// + /// 增加LVVol命令执行方法 + /// + private void ProStepLVVolAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterLVVol.Sum(a => a.KeepTime) + SelectedSlopLVVol.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLVVols!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLVVols!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLVVols!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterLVVols = ListSlopMeterLVVolItems.ToList(); + + var MeterLVVolData = new MeterLVVol() + { + StartValue = SelectedSlopLVVol.StartValue, + EndValue = SelectedSlopLVVol.EndValue, + KeepTime = SelectedSlopLVVol.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterLVVolStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterLVVolData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshLVVolById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLVVols!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLVVols!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLVVols!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLVVols!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterLVVol.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterLVVolItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterLVVolInfo = MeterLVVolToString(ListSlopMeterLVVol); + + //更新后检测时间是否匹配并界面提示 + CheckLVVolSlopListTime(); + } + + + private DelegateCommand _ProStepLVVolEditCmd; + /// + /// 新增LVVol命令 + /// + public DelegateCommand ProStepLVVolEditCmd + { + set + { + _ProStepLVVolEditCmd = value; + } + get + { + if (_ProStepLVVolEditCmd == null) + { + _ProStepLVVolEditCmd = new DelegateCommand(() => ProStepLVVolEditCmdMethod()); + } + return _ProStepLVVolEditCmd; + } + } + + /// + /// 编辑LVVol命令执行方法 + /// + private void ProStepLVVolEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopLVVol == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterLVVol.Where(a => a.Id != SelectedSlopLVVol!.Id).Sum(a => a.KeepTime) + SelectedSlopLVVol!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopLVVol.StartValue) + .Set(a => a.EndValue, SelectedSlopLVVol.EndValue) + .Set(a => a.KeepTime, SelectedSlopLVVol.KeepTime) + .Set(a => a.StepNo, SelectedSlopLVVol.StepNo) + .Where(a => a.Id == SelectedSlopLVVol.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshLVVolById(SelectedSlopLVVol.Id); + var CurIndex = ListSlopMeterLVVol.FindIndex(a => a.Id == SelectedSlopLVVol.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterLVVols!.Remove(ListSlopMeterLVVol.Find(a => a.Id == SelectedSlopLVVol!.Id)!); + //移除旧的数据 + ListSlopMeterLVVol.Remove(ListSlopMeterLVVol.Find(a => a.Id == SelectedSlopLVVol.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterLVVols!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterLVVol.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterLVVolItems.Remove(ListSlopMeterLVVolItems.Where(a => a.Id == SelectedSlopLVVol!.Id).FirstOrDefault()!); + ListSlopMeterLVVolItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterLVVolInfo = MeterLVVolToString(ListSlopMeterLVVol); + + //更新后检测时间是否匹配并界面提示 + CheckLVVolSlopListTime(); + } + + private DelegateCommand _ProStepLVVolDeleteCmd; + /// + /// 新增LVVol命令 + /// + public DelegateCommand ProStepLVVolDeleteCmd + { + set + { + _ProStepLVVolDeleteCmd = value; + } + get + { + if (_ProStepLVVolDeleteCmd == null) + { + _ProStepLVVolDeleteCmd = new DelegateCommand(() => ProStepLVVolDeleteCmdMethod()); + } + return _ProStepLVVolDeleteCmd; + } + } + + /// + /// 增加LVVol命令执行方法 + /// + private void ProStepLVVolDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopLVVol != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopLVVol!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterLVVols!.Remove(ListSlopMeterLVVol.Find(a => a.Id == SelectedSlopLVVol!.Id)!); + //移除旧的数据 + ListSlopMeterLVVol.Remove(ListSlopMeterLVVol.Find(a => a.Id == SelectedSlopLVVol.Id)!); + + //移除旧的数据 + ListSlopMeterLVVolItems.Remove(ListSlopMeterLVVolItems.Where(a => a.Id == SelectedSlopLVVol!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterLVVolInfo = MeterLVVolToString(ListSlopMeterLVVol); + + //更新后检测时间是否匹配并界面提示 + CheckLVVolSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新LVVol表信息 + /// + private void RefreshMeterLVVol() + { + ListSlopMeterLVVol = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterLVVols!.ToList(); + + ListSlopMeterLVVolItems.Clear(); + + ListSlopMeterLVVolItems = new ObservableCollection(ListSlopMeterLVVol!); + + } + + /// + /// 获取LVVol当前的步骤的数据信息 + /// + private int AutoGetMeterLVVolStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepLVVolConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepLVVolConstantSaveCmd + { + set + { + _ProStepLVVolConstantSaveCmd = value; + } + get + { + if (_ProStepLVVolConstantSaveCmd == null) + { + _ProStepLVVolConstantSaveCmd = new DelegateCommand(() => ProStepLVVolConstantSaveCmdMethod()); + } + return _ProStepLVVolConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepLVVolConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterLVVolItems != null && ListSlopMeterLVVolItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterLVVolItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterLVVols!.Remove(ListSlopMeterLVVol.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterLVVol.Remove(ListSlopMeterLVVol.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterLVVolItems.Remove(ListSlopMeterLVVolItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterLVVolInfo = MeterLVVolToString(ListSlopMeterLVVol); + + //更新后检测时间是否匹配并界面提示 + CheckLVVolSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstLVVolData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLVVols!.ToList(); + if (ConstLVVolData != null && ConstLVVolData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterLVVolData = new MeterLVVol() + { + Constant = SelectedConstLVVolValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterLVVolStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterLVVolData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshLVVolById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterLVVols!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterLVVolInfo = MeterLVVolToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstLVVolData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstLVVolValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshLVVolById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterLVVols!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterLVVols!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterLVVolInfo = MeterLVVolToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterLVVolSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterLVVolSwitchConstSlopPar + { + get { return _ProStepMeterLVVolSwitchConstSlopPar; } + set { _ProStepMeterLVVolSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepLVVolSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepLVVolSwitchConstSlopIndex + { + get { return _ProStepLVVolSwitchConstSlopIndex; } + set { _ProStepLVVolSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterLVVolSwitchConstSlopCmd; + /// + /// LVVol 常值和斜率切换 命令 + /// + public DelegateCommand MeterLVVolSwitchConstSlopCmd + { + set + { + _MeterLVVolSwitchConstSlopCmd = value; + } + get + { + if (_MeterLVVolSwitchConstSlopCmd == null) + { + _MeterLVVolSwitchConstSlopCmd = new DelegateCommand((obj) => MeterLVVolSwitchConstSlopCmdMethod(obj)); + } + return _MeterLVVolSwitchConstSlopCmd; + } + } + private void MeterLVVolSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterLVVolSwitchConstSlopPar = false; + } + else + { + ProStepMeterLVVolSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterLVVolToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckLVVolSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterLVVolExDto.SlopTime = ListSlopMeterLVVol.Sum(a => a.KeepTime); + if (MeterLVVolExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterLVVolExDto.SlopTime != 0) + { + MeterLVVolExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterLVVolExDto.SlopTime; + MeterLVVolExDto.IsTimeOk = false; + } + else + { + MeterLVVolExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterLVVolExDto.SlopTime; + MeterLVVolExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterLVVol数据 + /// + /// + private MeterLVVol RefreshLVVolById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterLVVol(); + } + } + + + #endregion + + #region OCR表 + + + + /// + /// OCR 初始化函数 + /// + private void OCRInit() + { + ListSlopMeterOCRItems = new ObservableCollection(); + SelectedSlopOCR = new MeterOCR(); + SelectedConstOCR = new MeterOCR(); + } + + + private ObservableCollection _ListSlopMeterOCRItems; + /// + /// Meter OCR数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterOCRItems + { + get { return _ListSlopMeterOCRItems; } + set { _ListSlopMeterOCRItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterOCR集合数据 斜率 + /// + public List ListSlopMeterOCR { get; set; } + + + private MeterOCR _SelectedSlopOCR; + /// + /// 当前选中的程序 OCR 斜率 + /// + public MeterOCR SelectedSlopOCR + { + get { return _SelectedSlopOCR; } + set { _SelectedSlopOCR = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterOCRExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 OCR + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterOCRExDto + { + get { return _MeterOCRExDto; } + set { _MeterOCRExDto = value; RaisePropertyChanged(); } + } + + + + private MeterOCR _SelectedConstOCR; + /// + /// 当前选中的程序 OCR 常值 + /// + public MeterOCR SelectedConstOCR + { + get { return _SelectedConstOCR; } + set { _SelectedConstOCR = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstOCRValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstOCRValue + { + get { return _SelectedConstOCRValue; } + set { _SelectedConstOCRValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterOCRSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterOCRSlopSelectedChangedCmd + { + set + { + _MeterOCRSlopSelectedChangedCmd = value; + } + get + { + if (_MeterOCRSlopSelectedChangedCmd == null) + { + _MeterOCRSlopSelectedChangedCmd = new DelegateCommand((str) => MeterOCRSlopSelectedChangedCmdMethod(str)); + } + return _MeterOCRSlopSelectedChangedCmd; + } + } + + + /// + /// OCR表选中行的执行方法 + /// + /// + /// + private void MeterOCRSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterOCR; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopOCR = new MeterOCR + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepOCRAddCmd; + /// + /// 新增OCR命令 + /// + public DelegateCommand ProStepOCRAddCmd + { + set + { + _ProStepOCRAddCmd = value; + } + get + { + if (_ProStepOCRAddCmd == null) + { + _ProStepOCRAddCmd = new DelegateCommand(() => ProStepOCRAddCmdMethod()); + } + return _ProStepOCRAddCmd; + } + } + + /// + /// 增加OCR命令执行方法 + /// + private void ProStepOCRAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterOCR.Sum(a => a.KeepTime) + SelectedSlopOCR.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOCRs!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOCRs!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOCRs!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterOCRs = ListSlopMeterOCRItems.ToList(); + + var MeterOCRData = new MeterOCR() + { + StartValue = SelectedSlopOCR.StartValue, + EndValue = SelectedSlopOCR.EndValue, + KeepTime = SelectedSlopOCR.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterOCRStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterOCRData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshOCRById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOCRs!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOCRs!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOCRs!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOCRs!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterOCR.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterOCRItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterOCRInfo = MeterOCRToString(ListSlopMeterOCR); + + //更新后检测时间是否匹配并界面提示 + CheckOCRSlopListTime(); + } + + + private DelegateCommand _ProStepOCREditCmd; + /// + /// 新增OCR命令 + /// + public DelegateCommand ProStepOCREditCmd + { + set + { + _ProStepOCREditCmd = value; + } + get + { + if (_ProStepOCREditCmd == null) + { + _ProStepOCREditCmd = new DelegateCommand(() => ProStepOCREditCmdMethod()); + } + return _ProStepOCREditCmd; + } + } + + /// + /// 编辑OCR命令执行方法 + /// + private void ProStepOCREditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopOCR == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterOCR.Where(a => a.Id != SelectedSlopOCR!.Id).Sum(a => a.KeepTime) + SelectedSlopOCR!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopOCR.StartValue) + .Set(a => a.EndValue, SelectedSlopOCR.EndValue) + .Set(a => a.KeepTime, SelectedSlopOCR.KeepTime) + .Set(a => a.StepNo, SelectedSlopOCR.StepNo) + .Where(a => a.Id == SelectedSlopOCR.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshOCRById(SelectedSlopOCR.Id); + var CurIndex = ListSlopMeterOCR.FindIndex(a => a.Id == SelectedSlopOCR.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOCRs!.Remove(ListSlopMeterOCR.Find(a => a.Id == SelectedSlopOCR!.Id)!); + //移除旧的数据 + ListSlopMeterOCR.Remove(ListSlopMeterOCR.Find(a => a.Id == SelectedSlopOCR.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOCRs!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterOCR.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterOCRItems.Remove(ListSlopMeterOCRItems.Where(a => a.Id == SelectedSlopOCR!.Id).FirstOrDefault()!); + ListSlopMeterOCRItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOCRInfo = MeterOCRToString(ListSlopMeterOCR); + + //更新后检测时间是否匹配并界面提示 + CheckOCRSlopListTime(); + } + + private DelegateCommand _ProStepOCRDeleteCmd; + /// + /// 新增OCR命令 + /// + public DelegateCommand ProStepOCRDeleteCmd + { + set + { + _ProStepOCRDeleteCmd = value; + } + get + { + if (_ProStepOCRDeleteCmd == null) + { + _ProStepOCRDeleteCmd = new DelegateCommand(() => ProStepOCRDeleteCmdMethod()); + } + return _ProStepOCRDeleteCmd; + } + } + + /// + /// 增加OCR命令执行方法 + /// + private void ProStepOCRDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopOCR != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopOCR!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOCRs!.Remove(ListSlopMeterOCR.Find(a => a.Id == SelectedSlopOCR!.Id)!); + //移除旧的数据 + ListSlopMeterOCR.Remove(ListSlopMeterOCR.Find(a => a.Id == SelectedSlopOCR.Id)!); + + //移除旧的数据 + ListSlopMeterOCRItems.Remove(ListSlopMeterOCRItems.Where(a => a.Id == SelectedSlopOCR!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOCRInfo = MeterOCRToString(ListSlopMeterOCR); + + //更新后检测时间是否匹配并界面提示 + CheckOCRSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新OCR表信息 + /// + private void RefreshMeterOCR() + { + ListSlopMeterOCR = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterOCRs!.ToList(); + + ListSlopMeterOCRItems.Clear(); + + ListSlopMeterOCRItems = new ObservableCollection(ListSlopMeterOCR!); + + } + + /// + /// 获取OCR当前的步骤的数据信息 + /// + private int AutoGetMeterOCRStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepOCRConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepOCRConstantSaveCmd + { + set + { + _ProStepOCRConstantSaveCmd = value; + } + get + { + if (_ProStepOCRConstantSaveCmd == null) + { + _ProStepOCRConstantSaveCmd = new DelegateCommand(() => ProStepOCRConstantSaveCmdMethod()); + } + return _ProStepOCRConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepOCRConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterOCRItems != null && ListSlopMeterOCRItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterOCRItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOCRs!.Remove(ListSlopMeterOCR.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterOCR.Remove(ListSlopMeterOCR.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterOCRItems.Remove(ListSlopMeterOCRItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOCRInfo = MeterOCRToString(ListSlopMeterOCR); + + //更新后检测时间是否匹配并界面提示 + CheckOCRSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstOCRData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOCRs!.ToList(); + if (ConstOCRData != null && ConstOCRData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterOCRData = new MeterOCR() + { + Constant = SelectedConstOCRValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterOCRStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterOCRData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshOCRById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOCRs!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterOCRInfo = MeterOCRToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstOCRData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstOCRValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshOCRById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOCRs!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOCRs!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOCRInfo = MeterOCRToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterOCRSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterOCRSwitchConstSlopPar + { + get { return _ProStepMeterOCRSwitchConstSlopPar; } + set { _ProStepMeterOCRSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepOCRSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepOCRSwitchConstSlopIndex + { + get { return _ProStepOCRSwitchConstSlopIndex; } + set { _ProStepOCRSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterOCRSwitchConstSlopCmd; + /// + /// OCR 常值和斜率切换 命令 + /// + public DelegateCommand MeterOCRSwitchConstSlopCmd + { + set + { + _MeterOCRSwitchConstSlopCmd = value; + } + get + { + if (_MeterOCRSwitchConstSlopCmd == null) + { + _MeterOCRSwitchConstSlopCmd = new DelegateCommand((obj) => MeterOCRSwitchConstSlopCmdMethod(obj)); + } + return _MeterOCRSwitchConstSlopCmd; + } + } + private void MeterOCRSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterOCRSwitchConstSlopPar = false; + } + else + { + ProStepMeterOCRSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterOCRToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckOCRSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterOCRExDto.SlopTime = ListSlopMeterOCR.Sum(a => a.KeepTime); + if (MeterOCRExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterOCRExDto.SlopTime != 0) + { + MeterOCRExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterOCRExDto.SlopTime; + MeterOCRExDto.IsTimeOk = false; + } + else + { + MeterOCRExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterOCRExDto.SlopTime; + MeterOCRExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterOCR数据 + /// + /// + private MeterOCR RefreshOCRById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterOCR(); + } + } + + + #endregion + + #region OS1Temp表 + + + + /// + /// OS1Temp 初始化函数 + /// + private void OS1TempInit() + { + ListSlopMeterOS1TempItems = new ObservableCollection(); + SelectedSlopOS1Temp = new MeterOS1Temp(); + SelectedConstOS1Temp = new MeterOS1Temp(); + } + + + private ObservableCollection _ListSlopMeterOS1TempItems; + /// + /// Meter OS1Temp数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterOS1TempItems + { + get { return _ListSlopMeterOS1TempItems; } + set { _ListSlopMeterOS1TempItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterOS1Temp集合数据 斜率 + /// + public List ListSlopMeterOS1Temp { get; set; } + + + private MeterOS1Temp _SelectedSlopOS1Temp; + /// + /// 当前选中的程序 OS1Temp 斜率 + /// + public MeterOS1Temp SelectedSlopOS1Temp + { + get { return _SelectedSlopOS1Temp; } + set { _SelectedSlopOS1Temp = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterOS1TempExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 OS1Temp + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterOS1TempExDto + { + get { return _MeterOS1TempExDto; } + set { _MeterOS1TempExDto = value; RaisePropertyChanged(); } + } + + + + private MeterOS1Temp _SelectedConstOS1Temp; + /// + /// 当前选中的程序 OS1Temp 常值 + /// + public MeterOS1Temp SelectedConstOS1Temp + { + get { return _SelectedConstOS1Temp; } + set { _SelectedConstOS1Temp = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstOS1TempValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstOS1TempValue + { + get { return _SelectedConstOS1TempValue; } + set { _SelectedConstOS1TempValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterOS1TempSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterOS1TempSlopSelectedChangedCmd + { + set + { + _MeterOS1TempSlopSelectedChangedCmd = value; + } + get + { + if (_MeterOS1TempSlopSelectedChangedCmd == null) + { + _MeterOS1TempSlopSelectedChangedCmd = new DelegateCommand((str) => MeterOS1TempSlopSelectedChangedCmdMethod(str)); + } + return _MeterOS1TempSlopSelectedChangedCmd; + } + } + + + /// + /// OS1Temp表选中行的执行方法 + /// + /// + /// + private void MeterOS1TempSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterOS1Temp; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopOS1Temp = new MeterOS1Temp + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepOS1TempAddCmd; + /// + /// 新增OS1Temp命令 + /// + public DelegateCommand ProStepOS1TempAddCmd + { + set + { + _ProStepOS1TempAddCmd = value; + } + get + { + if (_ProStepOS1TempAddCmd == null) + { + _ProStepOS1TempAddCmd = new DelegateCommand(() => ProStepOS1TempAddCmdMethod()); + } + return _ProStepOS1TempAddCmd; + } + } + + /// + /// 增加OS1Temp命令执行方法 + /// + private void ProStepOS1TempAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterOS1Temp.Sum(a => a.KeepTime) + SelectedSlopOS1Temp.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS1Temps!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS1Temps!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS1Temps!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterOS1Temps = ListSlopMeterOS1TempItems.ToList(); + + var MeterOS1TempData = new MeterOS1Temp() + { + StartValue = SelectedSlopOS1Temp.StartValue, + EndValue = SelectedSlopOS1Temp.EndValue, + KeepTime = SelectedSlopOS1Temp.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterOS1TempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterOS1TempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshOS1TempById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS1Temps!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS1Temps!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS1Temps!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS1Temps!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterOS1Temp.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterOS1TempItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterOS1TempInfo = MeterOS1TempToString(ListSlopMeterOS1Temp); + + //更新后检测时间是否匹配并界面提示 + CheckOS1TempSlopListTime(); + } + + + private DelegateCommand _ProStepOS1TempEditCmd; + /// + /// 新增OS1Temp命令 + /// + public DelegateCommand ProStepOS1TempEditCmd + { + set + { + _ProStepOS1TempEditCmd = value; + } + get + { + if (_ProStepOS1TempEditCmd == null) + { + _ProStepOS1TempEditCmd = new DelegateCommand(() => ProStepOS1TempEditCmdMethod()); + } + return _ProStepOS1TempEditCmd; + } + } + + /// + /// 编辑OS1Temp命令执行方法 + /// + private void ProStepOS1TempEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopOS1Temp == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterOS1Temp.Where(a => a.Id != SelectedSlopOS1Temp!.Id).Sum(a => a.KeepTime) + SelectedSlopOS1Temp!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopOS1Temp.StartValue) + .Set(a => a.EndValue, SelectedSlopOS1Temp.EndValue) + .Set(a => a.KeepTime, SelectedSlopOS1Temp.KeepTime) + .Set(a => a.StepNo, SelectedSlopOS1Temp.StepNo) + .Where(a => a.Id == SelectedSlopOS1Temp.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshOS1TempById(SelectedSlopOS1Temp.Id); + var CurIndex = ListSlopMeterOS1Temp.FindIndex(a => a.Id == SelectedSlopOS1Temp.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOS1Temps!.Remove(ListSlopMeterOS1Temp.Find(a => a.Id == SelectedSlopOS1Temp!.Id)!); + //移除旧的数据 + ListSlopMeterOS1Temp.Remove(ListSlopMeterOS1Temp.Find(a => a.Id == SelectedSlopOS1Temp.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOS1Temps!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterOS1Temp.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterOS1TempItems.Remove(ListSlopMeterOS1TempItems.Where(a => a.Id == SelectedSlopOS1Temp!.Id).FirstOrDefault()!); + ListSlopMeterOS1TempItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOS1TempInfo = MeterOS1TempToString(ListSlopMeterOS1Temp); + + //更新后检测时间是否匹配并界面提示 + CheckOS1TempSlopListTime(); + } + + private DelegateCommand _ProStepOS1TempDeleteCmd; + /// + /// 新增OS1Temp命令 + /// + public DelegateCommand ProStepOS1TempDeleteCmd + { + set + { + _ProStepOS1TempDeleteCmd = value; + } + get + { + if (_ProStepOS1TempDeleteCmd == null) + { + _ProStepOS1TempDeleteCmd = new DelegateCommand(() => ProStepOS1TempDeleteCmdMethod()); + } + return _ProStepOS1TempDeleteCmd; + } + } + + /// + /// 增加OS1Temp命令执行方法 + /// + private void ProStepOS1TempDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopOS1Temp != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopOS1Temp!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOS1Temps!.Remove(ListSlopMeterOS1Temp.Find(a => a.Id == SelectedSlopOS1Temp!.Id)!); + //移除旧的数据 + ListSlopMeterOS1Temp.Remove(ListSlopMeterOS1Temp.Find(a => a.Id == SelectedSlopOS1Temp.Id)!); + + //移除旧的数据 + ListSlopMeterOS1TempItems.Remove(ListSlopMeterOS1TempItems.Where(a => a.Id == SelectedSlopOS1Temp!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOS1TempInfo = MeterOS1TempToString(ListSlopMeterOS1Temp); + + //更新后检测时间是否匹配并界面提示 + CheckOS1TempSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新OS1Temp表信息 + /// + private void RefreshMeterOS1Temp() + { + ListSlopMeterOS1Temp = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterOS1Temps!.ToList(); + + ListSlopMeterOS1TempItems.Clear(); + + ListSlopMeterOS1TempItems = new ObservableCollection(ListSlopMeterOS1Temp!); + + } + + /// + /// 获取OS1Temp当前的步骤的数据信息 + /// + private int AutoGetMeterOS1TempStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepOS1TempConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepOS1TempConstantSaveCmd + { + set + { + _ProStepOS1TempConstantSaveCmd = value; + } + get + { + if (_ProStepOS1TempConstantSaveCmd == null) + { + _ProStepOS1TempConstantSaveCmd = new DelegateCommand(() => ProStepOS1TempConstantSaveCmdMethod()); + } + return _ProStepOS1TempConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepOS1TempConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterOS1TempItems != null && ListSlopMeterOS1TempItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterOS1TempItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOS1Temps!.Remove(ListSlopMeterOS1Temp.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterOS1Temp.Remove(ListSlopMeterOS1Temp.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterOS1TempItems.Remove(ListSlopMeterOS1TempItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOS1TempInfo = MeterOS1TempToString(ListSlopMeterOS1Temp); + + //更新后检测时间是否匹配并界面提示 + CheckOS1TempSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstOS1TempData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS1Temps!.ToList(); + if (ConstOS1TempData != null && ConstOS1TempData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterOS1TempData = new MeterOS1Temp() + { + Constant = SelectedConstOS1TempValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterOS1TempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterOS1TempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshOS1TempById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS1Temps!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterOS1TempInfo = MeterOS1TempToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstOS1TempData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstOS1TempValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshOS1TempById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOS1Temps!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOS1Temps!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOS1TempInfo = MeterOS1TempToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterOS1TempSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterOS1TempSwitchConstSlopPar + { + get { return _ProStepMeterOS1TempSwitchConstSlopPar; } + set { _ProStepMeterOS1TempSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepOS1TempSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepOS1TempSwitchConstSlopIndex + { + get { return _ProStepOS1TempSwitchConstSlopIndex; } + set { _ProStepOS1TempSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterOS1TempSwitchConstSlopCmd; + /// + /// OS1Temp 常值和斜率切换 命令 + /// + public DelegateCommand MeterOS1TempSwitchConstSlopCmd + { + set + { + _MeterOS1TempSwitchConstSlopCmd = value; + } + get + { + if (_MeterOS1TempSwitchConstSlopCmd == null) + { + _MeterOS1TempSwitchConstSlopCmd = new DelegateCommand((obj) => MeterOS1TempSwitchConstSlopCmdMethod(obj)); + } + return _MeterOS1TempSwitchConstSlopCmd; + } + } + private void MeterOS1TempSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterOS1TempSwitchConstSlopPar = false; + } + else + { + ProStepMeterOS1TempSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterOS1TempToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckOS1TempSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterOS1TempExDto.SlopTime = ListSlopMeterOS1Temp.Sum(a => a.KeepTime); + if (MeterOS1TempExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterOS1TempExDto.SlopTime != 0) + { + MeterOS1TempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterOS1TempExDto.SlopTime; + MeterOS1TempExDto.IsTimeOk = false; + } + else + { + MeterOS1TempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterOS1TempExDto.SlopTime; + MeterOS1TempExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterOS1Temp数据 + /// + /// + private MeterOS1Temp RefreshOS1TempById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterOS1Temp(); + } + } + + + #endregion + + #region OS2Temp表 + + + + /// + /// OS2Temp 初始化函数 + /// + private void OS2TempInit() + { + ListSlopMeterOS2TempItems = new ObservableCollection(); + SelectedSlopOS2Temp = new MeterOS2Temp(); + SelectedConstOS2Temp = new MeterOS2Temp(); + } + + + private ObservableCollection _ListSlopMeterOS2TempItems; + /// + /// Meter OS2Temp数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterOS2TempItems + { + get { return _ListSlopMeterOS2TempItems; } + set { _ListSlopMeterOS2TempItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterOS2Temp集合数据 斜率 + /// + public List ListSlopMeterOS2Temp { get; set; } + + + private MeterOS2Temp _SelectedSlopOS2Temp; + /// + /// 当前选中的程序 OS2Temp 斜率 + /// + public MeterOS2Temp SelectedSlopOS2Temp + { + get { return _SelectedSlopOS2Temp; } + set { _SelectedSlopOS2Temp = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterOS2TempExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 OS2Temp + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterOS2TempExDto + { + get { return _MeterOS2TempExDto; } + set { _MeterOS2TempExDto = value; RaisePropertyChanged(); } + } + + + + private MeterOS2Temp _SelectedConstOS2Temp; + /// + /// 当前选中的程序 OS2Temp 常值 + /// + public MeterOS2Temp SelectedConstOS2Temp + { + get { return _SelectedConstOS2Temp; } + set { _SelectedConstOS2Temp = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstOS2TempValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstOS2TempValue + { + get { return _SelectedConstOS2TempValue; } + set { _SelectedConstOS2TempValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterOS2TempSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterOS2TempSlopSelectedChangedCmd + { + set + { + _MeterOS2TempSlopSelectedChangedCmd = value; + } + get + { + if (_MeterOS2TempSlopSelectedChangedCmd == null) + { + _MeterOS2TempSlopSelectedChangedCmd = new DelegateCommand((str) => MeterOS2TempSlopSelectedChangedCmdMethod(str)); + } + return _MeterOS2TempSlopSelectedChangedCmd; + } + } + + + /// + /// OS2Temp表选中行的执行方法 + /// + /// + /// + private void MeterOS2TempSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterOS2Temp; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopOS2Temp = new MeterOS2Temp + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepOS2TempAddCmd; + /// + /// 新增OS2Temp命令 + /// + public DelegateCommand ProStepOS2TempAddCmd + { + set + { + _ProStepOS2TempAddCmd = value; + } + get + { + if (_ProStepOS2TempAddCmd == null) + { + _ProStepOS2TempAddCmd = new DelegateCommand(() => ProStepOS2TempAddCmdMethod()); + } + return _ProStepOS2TempAddCmd; + } + } + + /// + /// 增加OS2Temp命令执行方法 + /// + private void ProStepOS2TempAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterOS2Temp.Sum(a => a.KeepTime) + SelectedSlopOS2Temp.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS2Temps!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS2Temps!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS2Temps!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterOS2Temps = ListSlopMeterOS2TempItems.ToList(); + + var MeterOS2TempData = new MeterOS2Temp() + { + StartValue = SelectedSlopOS2Temp.StartValue, + EndValue = SelectedSlopOS2Temp.EndValue, + KeepTime = SelectedSlopOS2Temp.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterOS2TempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterOS2TempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshOS2TempById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS2Temps!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS2Temps!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS2Temps!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS2Temps!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterOS2Temp.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterOS2TempItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterOS2TempInfo = MeterOS2TempToString(ListSlopMeterOS2Temp); + + //更新后检测时间是否匹配并界面提示 + CheckOS2TempSlopListTime(); + } + + + private DelegateCommand _ProStepOS2TempEditCmd; + /// + /// 新增OS2Temp命令 + /// + public DelegateCommand ProStepOS2TempEditCmd + { + set + { + _ProStepOS2TempEditCmd = value; + } + get + { + if (_ProStepOS2TempEditCmd == null) + { + _ProStepOS2TempEditCmd = new DelegateCommand(() => ProStepOS2TempEditCmdMethod()); + } + return _ProStepOS2TempEditCmd; + } + } + + /// + /// 编辑OS2Temp命令执行方法 + /// + private void ProStepOS2TempEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopOS2Temp == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterOS2Temp.Where(a => a.Id != SelectedSlopOS2Temp!.Id).Sum(a => a.KeepTime) + SelectedSlopOS2Temp!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopOS2Temp.StartValue) + .Set(a => a.EndValue, SelectedSlopOS2Temp.EndValue) + .Set(a => a.KeepTime, SelectedSlopOS2Temp.KeepTime) + .Set(a => a.StepNo, SelectedSlopOS2Temp.StepNo) + .Where(a => a.Id == SelectedSlopOS2Temp.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshOS2TempById(SelectedSlopOS2Temp.Id); + var CurIndex = ListSlopMeterOS2Temp.FindIndex(a => a.Id == SelectedSlopOS2Temp.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOS2Temps!.Remove(ListSlopMeterOS2Temp.Find(a => a.Id == SelectedSlopOS2Temp!.Id)!); + //移除旧的数据 + ListSlopMeterOS2Temp.Remove(ListSlopMeterOS2Temp.Find(a => a.Id == SelectedSlopOS2Temp.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOS2Temps!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterOS2Temp.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterOS2TempItems.Remove(ListSlopMeterOS2TempItems.Where(a => a.Id == SelectedSlopOS2Temp!.Id).FirstOrDefault()!); + ListSlopMeterOS2TempItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOS2TempInfo = MeterOS2TempToString(ListSlopMeterOS2Temp); + + //更新后检测时间是否匹配并界面提示 + CheckOS2TempSlopListTime(); + } + + private DelegateCommand _ProStepOS2TempDeleteCmd; + /// + /// 新增OS2Temp命令 + /// + public DelegateCommand ProStepOS2TempDeleteCmd + { + set + { + _ProStepOS2TempDeleteCmd = value; + } + get + { + if (_ProStepOS2TempDeleteCmd == null) + { + _ProStepOS2TempDeleteCmd = new DelegateCommand(() => ProStepOS2TempDeleteCmdMethod()); + } + return _ProStepOS2TempDeleteCmd; + } + } + + /// + /// 增加OS2Temp命令执行方法 + /// + private void ProStepOS2TempDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopOS2Temp != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopOS2Temp!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOS2Temps!.Remove(ListSlopMeterOS2Temp.Find(a => a.Id == SelectedSlopOS2Temp!.Id)!); + //移除旧的数据 + ListSlopMeterOS2Temp.Remove(ListSlopMeterOS2Temp.Find(a => a.Id == SelectedSlopOS2Temp.Id)!); + + //移除旧的数据 + ListSlopMeterOS2TempItems.Remove(ListSlopMeterOS2TempItems.Where(a => a.Id == SelectedSlopOS2Temp!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOS2TempInfo = MeterOS2TempToString(ListSlopMeterOS2Temp); + + //更新后检测时间是否匹配并界面提示 + CheckOS2TempSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新OS2Temp表信息 + /// + private void RefreshMeterOS2Temp() + { + ListSlopMeterOS2Temp = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterOS2Temps!.ToList(); + + ListSlopMeterOS2TempItems.Clear(); + + ListSlopMeterOS2TempItems = new ObservableCollection(ListSlopMeterOS2Temp!); + + } + + /// + /// 获取OS2Temp当前的步骤的数据信息 + /// + private int AutoGetMeterOS2TempStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepOS2TempConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepOS2TempConstantSaveCmd + { + set + { + _ProStepOS2TempConstantSaveCmd = value; + } + get + { + if (_ProStepOS2TempConstantSaveCmd == null) + { + _ProStepOS2TempConstantSaveCmd = new DelegateCommand(() => ProStepOS2TempConstantSaveCmdMethod()); + } + return _ProStepOS2TempConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepOS2TempConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterOS2TempItems != null && ListSlopMeterOS2TempItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterOS2TempItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOS2Temps!.Remove(ListSlopMeterOS2Temp.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterOS2Temp.Remove(ListSlopMeterOS2Temp.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterOS2TempItems.Remove(ListSlopMeterOS2TempItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOS2TempInfo = MeterOS2TempToString(ListSlopMeterOS2Temp); + + //更新后检测时间是否匹配并界面提示 + CheckOS2TempSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstOS2TempData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS2Temps!.ToList(); + if (ConstOS2TempData != null && ConstOS2TempData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterOS2TempData = new MeterOS2Temp() + { + Constant = SelectedConstOS2TempValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterOS2TempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterOS2TempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshOS2TempById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterOS2Temps!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterOS2TempInfo = MeterOS2TempToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstOS2TempData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstOS2TempValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshOS2TempById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOS2Temps!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterOS2Temps!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterOS2TempInfo = MeterOS2TempToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterOS2TempSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterOS2TempSwitchConstSlopPar + { + get { return _ProStepMeterOS2TempSwitchConstSlopPar; } + set { _ProStepMeterOS2TempSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepOS2TempSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepOS2TempSwitchConstSlopIndex + { + get { return _ProStepOS2TempSwitchConstSlopIndex; } + set { _ProStepOS2TempSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterOS2TempSwitchConstSlopCmd; + /// + /// OS2Temp 常值和斜率切换 命令 + /// + public DelegateCommand MeterOS2TempSwitchConstSlopCmd + { + set + { + _MeterOS2TempSwitchConstSlopCmd = value; + } + get + { + if (_MeterOS2TempSwitchConstSlopCmd == null) + { + _MeterOS2TempSwitchConstSlopCmd = new DelegateCommand((obj) => MeterOS2TempSwitchConstSlopCmdMethod(obj)); + } + return _MeterOS2TempSwitchConstSlopCmd; + } + } + private void MeterOS2TempSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterOS2TempSwitchConstSlopPar = false; + } + else + { + ProStepMeterOS2TempSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterOS2TempToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckOS2TempSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterOS2TempExDto.SlopTime = ListSlopMeterOS2Temp.Sum(a => a.KeepTime); + if (MeterOS2TempExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterOS2TempExDto.SlopTime != 0) + { + MeterOS2TempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterOS2TempExDto.SlopTime; + MeterOS2TempExDto.IsTimeOk = false; + } + else + { + MeterOS2TempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterOS2TempExDto.SlopTime; + MeterOS2TempExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterOS2Temp数据 + /// + /// + private MeterOS2Temp RefreshOS2TempById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterOS2Temp(); + } + } + + + #endregion + + #region PTCEntTemp表 + + + + /// + /// PTCEntTemp 初始化函数 + /// + private void PTCEntTempInit() + { + ListSlopMeterPTCEntTempItems = new ObservableCollection(); + SelectedSlopPTCEntTemp = new MeterPTCEntTemp(); + SelectedConstPTCEntTemp = new MeterPTCEntTemp(); + } + + + private ObservableCollection _ListSlopMeterPTCEntTempItems; + /// + /// Meter PTCEntTemp数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterPTCEntTempItems + { + get { return _ListSlopMeterPTCEntTempItems; } + set { _ListSlopMeterPTCEntTempItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterPTCEntTemp集合数据 斜率 + /// + public List ListSlopMeterPTCEntTemp { get; set; } + + + private MeterPTCEntTemp _SelectedSlopPTCEntTemp; + /// + /// 当前选中的程序 PTCEntTemp 斜率 + /// + public MeterPTCEntTemp SelectedSlopPTCEntTemp + { + get { return _SelectedSlopPTCEntTemp; } + set { _SelectedSlopPTCEntTemp = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterPTCEntTempExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 PTCEntTemp + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterPTCEntTempExDto + { + get { return _MeterPTCEntTempExDto; } + set { _MeterPTCEntTempExDto = value; RaisePropertyChanged(); } + } + + + + private MeterPTCEntTemp _SelectedConstPTCEntTemp; + /// + /// 当前选中的程序 PTCEntTemp 常值 + /// + public MeterPTCEntTemp SelectedConstPTCEntTemp + { + get { return _SelectedConstPTCEntTemp; } + set { _SelectedConstPTCEntTemp = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstPTCEntTempValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstPTCEntTempValue + { + get { return _SelectedConstPTCEntTempValue; } + set { _SelectedConstPTCEntTempValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterPTCEntTempSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterPTCEntTempSlopSelectedChangedCmd + { + set + { + _MeterPTCEntTempSlopSelectedChangedCmd = value; + } + get + { + if (_MeterPTCEntTempSlopSelectedChangedCmd == null) + { + _MeterPTCEntTempSlopSelectedChangedCmd = new DelegateCommand((str) => MeterPTCEntTempSlopSelectedChangedCmdMethod(str)); + } + return _MeterPTCEntTempSlopSelectedChangedCmd; + } + } + + + /// + /// PTCEntTemp表选中行的执行方法 + /// + /// + /// + private void MeterPTCEntTempSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterPTCEntTemp; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopPTCEntTemp = new MeterPTCEntTemp + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepPTCEntTempAddCmd; + /// + /// 新增PTCEntTemp命令 + /// + public DelegateCommand ProStepPTCEntTempAddCmd + { + set + { + _ProStepPTCEntTempAddCmd = value; + } + get + { + if (_ProStepPTCEntTempAddCmd == null) + { + _ProStepPTCEntTempAddCmd = new DelegateCommand(() => ProStepPTCEntTempAddCmdMethod()); + } + return _ProStepPTCEntTempAddCmd; + } + } + + /// + /// 增加PTCEntTemp命令执行方法 + /// + private void ProStepPTCEntTempAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterPTCEntTemp.Sum(a => a.KeepTime) + SelectedSlopPTCEntTemp.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCEntTemps!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCEntTemps!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCEntTemps!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterPTCEntTemps = ListSlopMeterPTCEntTempItems.ToList(); + + var MeterPTCEntTempData = new MeterPTCEntTemp() + { + StartValue = SelectedSlopPTCEntTemp.StartValue, + EndValue = SelectedSlopPTCEntTemp.EndValue, + KeepTime = SelectedSlopPTCEntTemp.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterPTCEntTempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterPTCEntTempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshPTCEntTempById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCEntTemps!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCEntTemps!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCEntTemps!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCEntTemps!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterPTCEntTemp.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterPTCEntTempItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterPTCEntTempInfo = MeterPTCEntTempToString(ListSlopMeterPTCEntTemp); + + //更新后检测时间是否匹配并界面提示 + CheckPTCEntTempSlopListTime(); + } + + + private DelegateCommand _ProStepPTCEntTempEditCmd; + /// + /// 新增PTCEntTemp命令 + /// + public DelegateCommand ProStepPTCEntTempEditCmd + { + set + { + _ProStepPTCEntTempEditCmd = value; + } + get + { + if (_ProStepPTCEntTempEditCmd == null) + { + _ProStepPTCEntTempEditCmd = new DelegateCommand(() => ProStepPTCEntTempEditCmdMethod()); + } + return _ProStepPTCEntTempEditCmd; + } + } + + /// + /// 编辑PTCEntTemp命令执行方法 + /// + private void ProStepPTCEntTempEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopPTCEntTemp == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterPTCEntTemp.Where(a => a.Id != SelectedSlopPTCEntTemp!.Id).Sum(a => a.KeepTime) + SelectedSlopPTCEntTemp!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopPTCEntTemp.StartValue) + .Set(a => a.EndValue, SelectedSlopPTCEntTemp.EndValue) + .Set(a => a.KeepTime, SelectedSlopPTCEntTemp.KeepTime) + .Set(a => a.StepNo, SelectedSlopPTCEntTemp.StepNo) + .Where(a => a.Id == SelectedSlopPTCEntTemp.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshPTCEntTempById(SelectedSlopPTCEntTemp.Id); + var CurIndex = ListSlopMeterPTCEntTemp.FindIndex(a => a.Id == SelectedSlopPTCEntTemp.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCEntTemps!.Remove(ListSlopMeterPTCEntTemp.Find(a => a.Id == SelectedSlopPTCEntTemp!.Id)!); + //移除旧的数据 + ListSlopMeterPTCEntTemp.Remove(ListSlopMeterPTCEntTemp.Find(a => a.Id == SelectedSlopPTCEntTemp.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCEntTemps!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterPTCEntTemp.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterPTCEntTempItems.Remove(ListSlopMeterPTCEntTempItems.Where(a => a.Id == SelectedSlopPTCEntTemp!.Id).FirstOrDefault()!); + ListSlopMeterPTCEntTempItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCEntTempInfo = MeterPTCEntTempToString(ListSlopMeterPTCEntTemp); + + //更新后检测时间是否匹配并界面提示 + CheckPTCEntTempSlopListTime(); + } + + private DelegateCommand _ProStepPTCEntTempDeleteCmd; + /// + /// 新增PTCEntTemp命令 + /// + public DelegateCommand ProStepPTCEntTempDeleteCmd + { + set + { + _ProStepPTCEntTempDeleteCmd = value; + } + get + { + if (_ProStepPTCEntTempDeleteCmd == null) + { + _ProStepPTCEntTempDeleteCmd = new DelegateCommand(() => ProStepPTCEntTempDeleteCmdMethod()); + } + return _ProStepPTCEntTempDeleteCmd; + } + } + + /// + /// 增加PTCEntTemp命令执行方法 + /// + private void ProStepPTCEntTempDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopPTCEntTemp != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopPTCEntTemp!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCEntTemps!.Remove(ListSlopMeterPTCEntTemp.Find(a => a.Id == SelectedSlopPTCEntTemp!.Id)!); + //移除旧的数据 + ListSlopMeterPTCEntTemp.Remove(ListSlopMeterPTCEntTemp.Find(a => a.Id == SelectedSlopPTCEntTemp.Id)!); + + //移除旧的数据 + ListSlopMeterPTCEntTempItems.Remove(ListSlopMeterPTCEntTempItems.Where(a => a.Id == SelectedSlopPTCEntTemp!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCEntTempInfo = MeterPTCEntTempToString(ListSlopMeterPTCEntTemp); + + //更新后检测时间是否匹配并界面提示 + CheckPTCEntTempSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新PTCEntTemp表信息 + /// + private void RefreshMeterPTCEntTemp() + { + ListSlopMeterPTCEntTemp = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterPTCEntTemps!.ToList(); + + ListSlopMeterPTCEntTempItems.Clear(); + + ListSlopMeterPTCEntTempItems = new ObservableCollection(ListSlopMeterPTCEntTemp!); + + } + + /// + /// 获取PTCEntTemp当前的步骤的数据信息 + /// + private int AutoGetMeterPTCEntTempStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepPTCEntTempConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepPTCEntTempConstantSaveCmd + { + set + { + _ProStepPTCEntTempConstantSaveCmd = value; + } + get + { + if (_ProStepPTCEntTempConstantSaveCmd == null) + { + _ProStepPTCEntTempConstantSaveCmd = new DelegateCommand(() => ProStepPTCEntTempConstantSaveCmdMethod()); + } + return _ProStepPTCEntTempConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepPTCEntTempConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterPTCEntTempItems != null && ListSlopMeterPTCEntTempItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterPTCEntTempItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCEntTemps!.Remove(ListSlopMeterPTCEntTemp.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterPTCEntTemp.Remove(ListSlopMeterPTCEntTemp.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterPTCEntTempItems.Remove(ListSlopMeterPTCEntTempItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCEntTempInfo = MeterPTCEntTempToString(ListSlopMeterPTCEntTemp); + + //更新后检测时间是否匹配并界面提示 + CheckPTCEntTempSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstPTCEntTempData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCEntTemps!.ToList(); + if (ConstPTCEntTempData != null && ConstPTCEntTempData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterPTCEntTempData = new MeterPTCEntTemp() + { + Constant = SelectedConstPTCEntTempValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterPTCEntTempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterPTCEntTempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshPTCEntTempById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCEntTemps!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterPTCEntTempInfo = MeterPTCEntTempToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstPTCEntTempData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstPTCEntTempValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshPTCEntTempById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCEntTemps!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCEntTemps!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCEntTempInfo = MeterPTCEntTempToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterPTCEntTempSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterPTCEntTempSwitchConstSlopPar + { + get { return _ProStepMeterPTCEntTempSwitchConstSlopPar; } + set { _ProStepMeterPTCEntTempSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepPTCEntTempSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepPTCEntTempSwitchConstSlopIndex + { + get { return _ProStepPTCEntTempSwitchConstSlopIndex; } + set { _ProStepPTCEntTempSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterPTCEntTempSwitchConstSlopCmd; + /// + /// PTCEntTemp 常值和斜率切换 命令 + /// + public DelegateCommand MeterPTCEntTempSwitchConstSlopCmd + { + set + { + _MeterPTCEntTempSwitchConstSlopCmd = value; + } + get + { + if (_MeterPTCEntTempSwitchConstSlopCmd == null) + { + _MeterPTCEntTempSwitchConstSlopCmd = new DelegateCommand((obj) => MeterPTCEntTempSwitchConstSlopCmdMethod(obj)); + } + return _MeterPTCEntTempSwitchConstSlopCmd; + } + } + private void MeterPTCEntTempSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterPTCEntTempSwitchConstSlopPar = false; + } + else + { + ProStepMeterPTCEntTempSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterPTCEntTempToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckPTCEntTempSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterPTCEntTempExDto.SlopTime = ListSlopMeterPTCEntTemp.Sum(a => a.KeepTime); + if (MeterPTCEntTempExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterPTCEntTempExDto.SlopTime != 0) + { + MeterPTCEntTempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterPTCEntTempExDto.SlopTime; + MeterPTCEntTempExDto.IsTimeOk = false; + } + else + { + MeterPTCEntTempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterPTCEntTempExDto.SlopTime; + MeterPTCEntTempExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterPTCEntTemp数据 + /// + /// + private MeterPTCEntTemp RefreshPTCEntTempById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterPTCEntTemp(); + } + } + + + #endregion + + #region PTCFlow表 + + + + /// + /// PTCFlow 初始化函数 + /// + private void PTCFlowInit() + { + ListSlopMeterPTCFlowItems = new ObservableCollection(); + SelectedSlopPTCFlow = new MeterPTCFlow(); + SelectedConstPTCFlow = new MeterPTCFlow(); + } + + + private ObservableCollection _ListSlopMeterPTCFlowItems; + /// + /// Meter PTCFlow数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterPTCFlowItems + { + get { return _ListSlopMeterPTCFlowItems; } + set { _ListSlopMeterPTCFlowItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterPTCFlow集合数据 斜率 + /// + public List ListSlopMeterPTCFlow { get; set; } + + + private MeterPTCFlow _SelectedSlopPTCFlow; + /// + /// 当前选中的程序 PTCFlow 斜率 + /// + public MeterPTCFlow SelectedSlopPTCFlow + { + get { return _SelectedSlopPTCFlow; } + set { _SelectedSlopPTCFlow = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterPTCFlowExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 PTCFlow + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterPTCFlowExDto + { + get { return _MeterPTCFlowExDto; } + set { _MeterPTCFlowExDto = value; RaisePropertyChanged(); } + } + + + + private MeterPTCFlow _SelectedConstPTCFlow; + /// + /// 当前选中的程序 PTCFlow 常值 + /// + public MeterPTCFlow SelectedConstPTCFlow + { + get { return _SelectedConstPTCFlow; } + set { _SelectedConstPTCFlow = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstPTCFlowValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstPTCFlowValue + { + get { return _SelectedConstPTCFlowValue; } + set { _SelectedConstPTCFlowValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterPTCFlowSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterPTCFlowSlopSelectedChangedCmd + { + set + { + _MeterPTCFlowSlopSelectedChangedCmd = value; + } + get + { + if (_MeterPTCFlowSlopSelectedChangedCmd == null) + { + _MeterPTCFlowSlopSelectedChangedCmd = new DelegateCommand((str) => MeterPTCFlowSlopSelectedChangedCmdMethod(str)); + } + return _MeterPTCFlowSlopSelectedChangedCmd; + } + } + + + /// + /// PTCFlow表选中行的执行方法 + /// + /// + /// + private void MeterPTCFlowSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterPTCFlow; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopPTCFlow = new MeterPTCFlow + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepPTCFlowAddCmd; + /// + /// 新增PTCFlow命令 + /// + public DelegateCommand ProStepPTCFlowAddCmd + { + set + { + _ProStepPTCFlowAddCmd = value; + } + get + { + if (_ProStepPTCFlowAddCmd == null) + { + _ProStepPTCFlowAddCmd = new DelegateCommand(() => ProStepPTCFlowAddCmdMethod()); + } + return _ProStepPTCFlowAddCmd; + } + } + + /// + /// 增加PTCFlow命令执行方法 + /// + private void ProStepPTCFlowAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterPTCFlow.Sum(a => a.KeepTime) + SelectedSlopPTCFlow.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCFlows!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCFlows!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCFlows!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterPTCFlows = ListSlopMeterPTCFlowItems.ToList(); + + var MeterPTCFlowData = new MeterPTCFlow() + { + StartValue = SelectedSlopPTCFlow.StartValue, + EndValue = SelectedSlopPTCFlow.EndValue, + KeepTime = SelectedSlopPTCFlow.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterPTCFlowStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterPTCFlowData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshPTCFlowById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCFlows!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCFlows!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCFlows!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCFlows!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterPTCFlow.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterPTCFlowItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterPTCFlowInfo = MeterPTCFlowToString(ListSlopMeterPTCFlow); + + //更新后检测时间是否匹配并界面提示 + CheckPTCFlowSlopListTime(); + } + + + private DelegateCommand _ProStepPTCFlowEditCmd; + /// + /// 新增PTCFlow命令 + /// + public DelegateCommand ProStepPTCFlowEditCmd + { + set + { + _ProStepPTCFlowEditCmd = value; + } + get + { + if (_ProStepPTCFlowEditCmd == null) + { + _ProStepPTCFlowEditCmd = new DelegateCommand(() => ProStepPTCFlowEditCmdMethod()); + } + return _ProStepPTCFlowEditCmd; + } + } + + /// + /// 编辑PTCFlow命令执行方法 + /// + private void ProStepPTCFlowEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopPTCFlow == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterPTCFlow.Where(a => a.Id != SelectedSlopPTCFlow!.Id).Sum(a => a.KeepTime) + SelectedSlopPTCFlow!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopPTCFlow.StartValue) + .Set(a => a.EndValue, SelectedSlopPTCFlow.EndValue) + .Set(a => a.KeepTime, SelectedSlopPTCFlow.KeepTime) + .Set(a => a.StepNo, SelectedSlopPTCFlow.StepNo) + .Where(a => a.Id == SelectedSlopPTCFlow.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshPTCFlowById(SelectedSlopPTCFlow.Id); + var CurIndex = ListSlopMeterPTCFlow.FindIndex(a => a.Id == SelectedSlopPTCFlow.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCFlows!.Remove(ListSlopMeterPTCFlow.Find(a => a.Id == SelectedSlopPTCFlow!.Id)!); + //移除旧的数据 + ListSlopMeterPTCFlow.Remove(ListSlopMeterPTCFlow.Find(a => a.Id == SelectedSlopPTCFlow.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCFlows!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterPTCFlow.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterPTCFlowItems.Remove(ListSlopMeterPTCFlowItems.Where(a => a.Id == SelectedSlopPTCFlow!.Id).FirstOrDefault()!); + ListSlopMeterPTCFlowItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCFlowInfo = MeterPTCFlowToString(ListSlopMeterPTCFlow); + + //更新后检测时间是否匹配并界面提示 + CheckPTCFlowSlopListTime(); + } + + private DelegateCommand _ProStepPTCFlowDeleteCmd; + /// + /// 新增PTCFlow命令 + /// + public DelegateCommand ProStepPTCFlowDeleteCmd + { + set + { + _ProStepPTCFlowDeleteCmd = value; + } + get + { + if (_ProStepPTCFlowDeleteCmd == null) + { + _ProStepPTCFlowDeleteCmd = new DelegateCommand(() => ProStepPTCFlowDeleteCmdMethod()); + } + return _ProStepPTCFlowDeleteCmd; + } + } + + /// + /// 增加PTCFlow命令执行方法 + /// + private void ProStepPTCFlowDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopPTCFlow != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopPTCFlow!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCFlows!.Remove(ListSlopMeterPTCFlow.Find(a => a.Id == SelectedSlopPTCFlow!.Id)!); + //移除旧的数据 + ListSlopMeterPTCFlow.Remove(ListSlopMeterPTCFlow.Find(a => a.Id == SelectedSlopPTCFlow.Id)!); + + //移除旧的数据 + ListSlopMeterPTCFlowItems.Remove(ListSlopMeterPTCFlowItems.Where(a => a.Id == SelectedSlopPTCFlow!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCFlowInfo = MeterPTCFlowToString(ListSlopMeterPTCFlow); + + //更新后检测时间是否匹配并界面提示 + CheckPTCFlowSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新PTCFlow表信息 + /// + private void RefreshMeterPTCFlow() + { + ListSlopMeterPTCFlow = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterPTCFlows!.ToList(); + + ListSlopMeterPTCFlowItems.Clear(); + + ListSlopMeterPTCFlowItems = new ObservableCollection(ListSlopMeterPTCFlow!); + + } + + /// + /// 获取PTCFlow当前的步骤的数据信息 + /// + private int AutoGetMeterPTCFlowStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepPTCFlowConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepPTCFlowConstantSaveCmd + { + set + { + _ProStepPTCFlowConstantSaveCmd = value; + } + get + { + if (_ProStepPTCFlowConstantSaveCmd == null) + { + _ProStepPTCFlowConstantSaveCmd = new DelegateCommand(() => ProStepPTCFlowConstantSaveCmdMethod()); + } + return _ProStepPTCFlowConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepPTCFlowConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterPTCFlowItems != null && ListSlopMeterPTCFlowItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterPTCFlowItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCFlows!.Remove(ListSlopMeterPTCFlow.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterPTCFlow.Remove(ListSlopMeterPTCFlow.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterPTCFlowItems.Remove(ListSlopMeterPTCFlowItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCFlowInfo = MeterPTCFlowToString(ListSlopMeterPTCFlow); + + //更新后检测时间是否匹配并界面提示 + CheckPTCFlowSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstPTCFlowData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCFlows!.ToList(); + if (ConstPTCFlowData != null && ConstPTCFlowData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterPTCFlowData = new MeterPTCFlow() + { + Constant = SelectedConstPTCFlowValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterPTCFlowStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterPTCFlowData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshPTCFlowById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCFlows!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterPTCFlowInfo = MeterPTCFlowToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstPTCFlowData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstPTCFlowValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshPTCFlowById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCFlows!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCFlows!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCFlowInfo = MeterPTCFlowToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterPTCFlowSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterPTCFlowSwitchConstSlopPar + { + get { return _ProStepMeterPTCFlowSwitchConstSlopPar; } + set { _ProStepMeterPTCFlowSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepPTCFlowSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepPTCFlowSwitchConstSlopIndex + { + get { return _ProStepPTCFlowSwitchConstSlopIndex; } + set { _ProStepPTCFlowSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterPTCFlowSwitchConstSlopCmd; + /// + /// PTCFlow 常值和斜率切换 命令 + /// + public DelegateCommand MeterPTCFlowSwitchConstSlopCmd + { + set + { + _MeterPTCFlowSwitchConstSlopCmd = value; + } + get + { + if (_MeterPTCFlowSwitchConstSlopCmd == null) + { + _MeterPTCFlowSwitchConstSlopCmd = new DelegateCommand((obj) => MeterPTCFlowSwitchConstSlopCmdMethod(obj)); + } + return _MeterPTCFlowSwitchConstSlopCmd; + } + } + private void MeterPTCFlowSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterPTCFlowSwitchConstSlopPar = false; + } + else + { + ProStepMeterPTCFlowSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterPTCFlowToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckPTCFlowSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterPTCFlowExDto.SlopTime = ListSlopMeterPTCFlow.Sum(a => a.KeepTime); + if (MeterPTCFlowExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterPTCFlowExDto.SlopTime != 0) + { + MeterPTCFlowExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterPTCFlowExDto.SlopTime; + MeterPTCFlowExDto.IsTimeOk = false; + } + else + { + MeterPTCFlowExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterPTCFlowExDto.SlopTime; + MeterPTCFlowExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterPTCFlow数据 + /// + /// + private MeterPTCFlow RefreshPTCFlowById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterPTCFlow(); + } + } + + + #endregion + + #region PTCPw表 + + + + /// + /// PTCPw 初始化函数 + /// + private void PTCPwInit() + { + ListSlopMeterPTCPwItems = new ObservableCollection(); + SelectedSlopPTCPw = new MeterPTCPw(); + SelectedConstPTCPw = new MeterPTCPw(); + } + + + private ObservableCollection _ListSlopMeterPTCPwItems; + /// + /// Meter PTCPw数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterPTCPwItems + { + get { return _ListSlopMeterPTCPwItems; } + set { _ListSlopMeterPTCPwItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterPTCPw集合数据 斜率 + /// + public List ListSlopMeterPTCPw { get; set; } + + + private MeterPTCPw _SelectedSlopPTCPw; + /// + /// 当前选中的程序 PTCPw 斜率 + /// + public MeterPTCPw SelectedSlopPTCPw + { + get { return _SelectedSlopPTCPw; } + set { _SelectedSlopPTCPw = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterPTCPwExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 PTCPw + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterPTCPwExDto + { + get { return _MeterPTCPwExDto; } + set { _MeterPTCPwExDto = value; RaisePropertyChanged(); } + } + + + + private MeterPTCPw _SelectedConstPTCPw; + /// + /// 当前选中的程序 PTCPw 常值 + /// + public MeterPTCPw SelectedConstPTCPw + { + get { return _SelectedConstPTCPw; } + set { _SelectedConstPTCPw = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstPTCPwValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstPTCPwValue + { + get { return _SelectedConstPTCPwValue; } + set { _SelectedConstPTCPwValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterPTCPwSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterPTCPwSlopSelectedChangedCmd + { + set + { + _MeterPTCPwSlopSelectedChangedCmd = value; + } + get + { + if (_MeterPTCPwSlopSelectedChangedCmd == null) + { + _MeterPTCPwSlopSelectedChangedCmd = new DelegateCommand((str) => MeterPTCPwSlopSelectedChangedCmdMethod(str)); + } + return _MeterPTCPwSlopSelectedChangedCmd; + } + } + + + /// + /// PTCPw表选中行的执行方法 + /// + /// + /// + private void MeterPTCPwSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterPTCPw; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopPTCPw = new MeterPTCPw + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepPTCPwAddCmd; + /// + /// 新增PTCPw命令 + /// + public DelegateCommand ProStepPTCPwAddCmd + { + set + { + _ProStepPTCPwAddCmd = value; + } + get + { + if (_ProStepPTCPwAddCmd == null) + { + _ProStepPTCPwAddCmd = new DelegateCommand(() => ProStepPTCPwAddCmdMethod()); + } + return _ProStepPTCPwAddCmd; + } + } + + /// + /// 增加PTCPw命令执行方法 + /// + private void ProStepPTCPwAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterPTCPw.Sum(a => a.KeepTime) + SelectedSlopPTCPw.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCPws!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCPws!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCPws!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterPTCPws = ListSlopMeterPTCPwItems.ToList(); + + var MeterPTCPwData = new MeterPTCPw() + { + StartValue = SelectedSlopPTCPw.StartValue, + EndValue = SelectedSlopPTCPw.EndValue, + KeepTime = SelectedSlopPTCPw.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterPTCPwStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterPTCPwData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshPTCPwById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCPws!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCPws!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCPws!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCPws!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterPTCPw.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterPTCPwItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterPTCPwInfo = MeterPTCPwToString(ListSlopMeterPTCPw); + + //更新后检测时间是否匹配并界面提示 + CheckPTCPwSlopListTime(); + } + + + private DelegateCommand _ProStepPTCPwEditCmd; + /// + /// 新增PTCPw命令 + /// + public DelegateCommand ProStepPTCPwEditCmd + { + set + { + _ProStepPTCPwEditCmd = value; + } + get + { + if (_ProStepPTCPwEditCmd == null) + { + _ProStepPTCPwEditCmd = new DelegateCommand(() => ProStepPTCPwEditCmdMethod()); + } + return _ProStepPTCPwEditCmd; + } + } + + /// + /// 编辑PTCPw命令执行方法 + /// + private void ProStepPTCPwEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopPTCPw == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterPTCPw.Where(a => a.Id != SelectedSlopPTCPw!.Id).Sum(a => a.KeepTime) + SelectedSlopPTCPw!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopPTCPw.StartValue) + .Set(a => a.EndValue, SelectedSlopPTCPw.EndValue) + .Set(a => a.KeepTime, SelectedSlopPTCPw.KeepTime) + .Set(a => a.StepNo, SelectedSlopPTCPw.StepNo) + .Where(a => a.Id == SelectedSlopPTCPw.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshPTCPwById(SelectedSlopPTCPw.Id); + var CurIndex = ListSlopMeterPTCPw.FindIndex(a => a.Id == SelectedSlopPTCPw.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCPws!.Remove(ListSlopMeterPTCPw.Find(a => a.Id == SelectedSlopPTCPw!.Id)!); + //移除旧的数据 + ListSlopMeterPTCPw.Remove(ListSlopMeterPTCPw.Find(a => a.Id == SelectedSlopPTCPw.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCPws!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterPTCPw.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterPTCPwItems.Remove(ListSlopMeterPTCPwItems.Where(a => a.Id == SelectedSlopPTCPw!.Id).FirstOrDefault()!); + ListSlopMeterPTCPwItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCPwInfo = MeterPTCPwToString(ListSlopMeterPTCPw); + + //更新后检测时间是否匹配并界面提示 + CheckPTCPwSlopListTime(); + } + + private DelegateCommand _ProStepPTCPwDeleteCmd; + /// + /// 新增PTCPw命令 + /// + public DelegateCommand ProStepPTCPwDeleteCmd + { + set + { + _ProStepPTCPwDeleteCmd = value; + } + get + { + if (_ProStepPTCPwDeleteCmd == null) + { + _ProStepPTCPwDeleteCmd = new DelegateCommand(() => ProStepPTCPwDeleteCmdMethod()); + } + return _ProStepPTCPwDeleteCmd; + } + } + + /// + /// 增加PTCPw命令执行方法 + /// + private void ProStepPTCPwDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopPTCPw != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopPTCPw!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCPws!.Remove(ListSlopMeterPTCPw.Find(a => a.Id == SelectedSlopPTCPw!.Id)!); + //移除旧的数据 + ListSlopMeterPTCPw.Remove(ListSlopMeterPTCPw.Find(a => a.Id == SelectedSlopPTCPw.Id)!); + + //移除旧的数据 + ListSlopMeterPTCPwItems.Remove(ListSlopMeterPTCPwItems.Where(a => a.Id == SelectedSlopPTCPw!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCPwInfo = MeterPTCPwToString(ListSlopMeterPTCPw); + + //更新后检测时间是否匹配并界面提示 + CheckPTCPwSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新PTCPw表信息 + /// + private void RefreshMeterPTCPw() + { + ListSlopMeterPTCPw = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterPTCPws!.ToList(); + + ListSlopMeterPTCPwItems.Clear(); + + ListSlopMeterPTCPwItems = new ObservableCollection(ListSlopMeterPTCPw!); + + } + + /// + /// 获取PTCPw当前的步骤的数据信息 + /// + private int AutoGetMeterPTCPwStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepPTCPwConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepPTCPwConstantSaveCmd + { + set + { + _ProStepPTCPwConstantSaveCmd = value; + } + get + { + if (_ProStepPTCPwConstantSaveCmd == null) + { + _ProStepPTCPwConstantSaveCmd = new DelegateCommand(() => ProStepPTCPwConstantSaveCmdMethod()); + } + return _ProStepPTCPwConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepPTCPwConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterPTCPwItems != null && ListSlopMeterPTCPwItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterPTCPwItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCPws!.Remove(ListSlopMeterPTCPw.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterPTCPw.Remove(ListSlopMeterPTCPw.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterPTCPwItems.Remove(ListSlopMeterPTCPwItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCPwInfo = MeterPTCPwToString(ListSlopMeterPTCPw); + + //更新后检测时间是否匹配并界面提示 + CheckPTCPwSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstPTCPwData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCPws!.ToList(); + if (ConstPTCPwData != null && ConstPTCPwData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterPTCPwData = new MeterPTCPw() + { + Constant = SelectedConstPTCPwValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterPTCPwStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterPTCPwData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshPTCPwById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterPTCPws!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterPTCPwInfo = MeterPTCPwToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstPTCPwData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstPTCPwValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshPTCPwById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCPws!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterPTCPws!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterPTCPwInfo = MeterPTCPwToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterPTCPwSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterPTCPwSwitchConstSlopPar + { + get { return _ProStepMeterPTCPwSwitchConstSlopPar; } + set { _ProStepMeterPTCPwSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepPTCPwSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepPTCPwSwitchConstSlopIndex + { + get { return _ProStepPTCPwSwitchConstSlopIndex; } + set { _ProStepPTCPwSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterPTCPwSwitchConstSlopCmd; + /// + /// PTCPw 常值和斜率切换 命令 + /// + public DelegateCommand MeterPTCPwSwitchConstSlopCmd + { + set + { + _MeterPTCPwSwitchConstSlopCmd = value; + } + get + { + if (_MeterPTCPwSwitchConstSlopCmd == null) + { + _MeterPTCPwSwitchConstSlopCmd = new DelegateCommand((obj) => MeterPTCPwSwitchConstSlopCmdMethod(obj)); + } + return _MeterPTCPwSwitchConstSlopCmd; + } + } + private void MeterPTCPwSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterPTCPwSwitchConstSlopPar = false; + } + else + { + ProStepMeterPTCPwSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterPTCPwToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckPTCPwSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterPTCPwExDto.SlopTime = ListSlopMeterPTCPw.Sum(a => a.KeepTime); + if (MeterPTCPwExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterPTCPwExDto.SlopTime != 0) + { + MeterPTCPwExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterPTCPwExDto.SlopTime; + MeterPTCPwExDto.IsTimeOk = false; + } + else + { + MeterPTCPwExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterPTCPwExDto.SlopTime; + MeterPTCPwExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterPTCPw数据 + /// + /// + private MeterPTCPw RefreshPTCPwById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterPTCPw(); + } + } + + + #endregion + + #region EnvRH表 + + + + /// + /// EnvRH 初始化函数 + /// + private void EnvRHInit() + { + ListSlopMeterEnvRHItems = new ObservableCollection(); + SelectedSlopEnvRH = new MeterEnvRH(); + SelectedConstEnvRH = new MeterEnvRH(); + } + + + private ObservableCollection _ListSlopMeterEnvRHItems; + /// + /// Meter EnvRH数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterEnvRHItems + { + get { return _ListSlopMeterEnvRHItems; } + set { _ListSlopMeterEnvRHItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterEnvRH集合数据 斜率 + /// + public List ListSlopMeterEnvRH { get; set; } + + + private MeterEnvRH _SelectedSlopEnvRH; + /// + /// 当前选中的程序 EnvRH 斜率 + /// + public MeterEnvRH SelectedSlopEnvRH + { + get { return _SelectedSlopEnvRH; } + set { _SelectedSlopEnvRH = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterEnvRHExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 EnvRH + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterEnvRHExDto + { + get { return _MeterEnvRHExDto; } + set { _MeterEnvRHExDto = value; RaisePropertyChanged(); } + } + + + + private MeterEnvRH _SelectedConstEnvRH; + /// + /// 当前选中的程序 EnvRH 常值 + /// + public MeterEnvRH SelectedConstEnvRH + { + get { return _SelectedConstEnvRH; } + set { _SelectedConstEnvRH = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstEnvRHValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstEnvRHValue + { + get { return _SelectedConstEnvRHValue; } + set { _SelectedConstEnvRHValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterEnvRHSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterEnvRHSlopSelectedChangedCmd + { + set + { + _MeterEnvRHSlopSelectedChangedCmd = value; + } + get + { + if (_MeterEnvRHSlopSelectedChangedCmd == null) + { + _MeterEnvRHSlopSelectedChangedCmd = new DelegateCommand((str) => MeterEnvRHSlopSelectedChangedCmdMethod(str)); + } + return _MeterEnvRHSlopSelectedChangedCmd; + } + } + + + /// + /// EnvRH表选中行的执行方法 + /// + /// + /// + private void MeterEnvRHSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterEnvRH; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopEnvRH = new MeterEnvRH + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepEnvRHAddCmd; + /// + /// 新增EnvRH命令 + /// + public DelegateCommand ProStepEnvRHAddCmd + { + set + { + _ProStepEnvRHAddCmd = value; + } + get + { + if (_ProStepEnvRHAddCmd == null) + { + _ProStepEnvRHAddCmd = new DelegateCommand(() => ProStepEnvRHAddCmdMethod()); + } + return _ProStepEnvRHAddCmd; + } + } + + /// + /// 增加EnvRH命令执行方法 + /// + private void ProStepEnvRHAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterEnvRH.Sum(a => a.KeepTime) + SelectedSlopEnvRH.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvRHs!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvRHs!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvRHs!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterEnvRHs = ListSlopMeterEnvRHItems.ToList(); + + var MeterEnvRHData = new MeterEnvRH() + { + StartValue = SelectedSlopEnvRH.StartValue, + EndValue = SelectedSlopEnvRH.EndValue, + KeepTime = SelectedSlopEnvRH.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterEnvRHStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterEnvRHData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshEnvRHById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvRHs!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvRHs!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvRHs!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvRHs!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterEnvRH.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterEnvRHItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterEnvRHInfo = MeterEnvRHToString(ListSlopMeterEnvRH); + + //更新后检测时间是否匹配并界面提示 + CheckEnvRHSlopListTime(); + } + + + private DelegateCommand _ProStepEnvRHEditCmd; + /// + /// 新增EnvRH命令 + /// + public DelegateCommand ProStepEnvRHEditCmd + { + set + { + _ProStepEnvRHEditCmd = value; + } + get + { + if (_ProStepEnvRHEditCmd == null) + { + _ProStepEnvRHEditCmd = new DelegateCommand(() => ProStepEnvRHEditCmdMethod()); + } + return _ProStepEnvRHEditCmd; + } + } + + /// + /// 编辑EnvRH命令执行方法 + /// + private void ProStepEnvRHEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopEnvRH == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterEnvRH.Where(a => a.Id != SelectedSlopEnvRH!.Id).Sum(a => a.KeepTime) + SelectedSlopEnvRH!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopEnvRH.StartValue) + .Set(a => a.EndValue, SelectedSlopEnvRH.EndValue) + .Set(a => a.KeepTime, SelectedSlopEnvRH.KeepTime) + .Set(a => a.StepNo, SelectedSlopEnvRH.StepNo) + .Where(a => a.Id == SelectedSlopEnvRH.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshEnvRHById(SelectedSlopEnvRH.Id); + var CurIndex = ListSlopMeterEnvRH.FindIndex(a => a.Id == SelectedSlopEnvRH.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEnvRHs!.Remove(ListSlopMeterEnvRH.Find(a => a.Id == SelectedSlopEnvRH!.Id)!); + //移除旧的数据 + ListSlopMeterEnvRH.Remove(ListSlopMeterEnvRH.Find(a => a.Id == SelectedSlopEnvRH.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEnvRHs!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterEnvRH.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterEnvRHItems.Remove(ListSlopMeterEnvRHItems.Where(a => a.Id == SelectedSlopEnvRH!.Id).FirstOrDefault()!); + ListSlopMeterEnvRHItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEnvRHInfo = MeterEnvRHToString(ListSlopMeterEnvRH); + + //更新后检测时间是否匹配并界面提示 + CheckEnvRHSlopListTime(); + } + + private DelegateCommand _ProStepEnvRHDeleteCmd; + /// + /// 新增EnvRH命令 + /// + public DelegateCommand ProStepEnvRHDeleteCmd + { + set + { + _ProStepEnvRHDeleteCmd = value; + } + get + { + if (_ProStepEnvRHDeleteCmd == null) + { + _ProStepEnvRHDeleteCmd = new DelegateCommand(() => ProStepEnvRHDeleteCmdMethod()); + } + return _ProStepEnvRHDeleteCmd; + } + } + + /// + /// 增加EnvRH命令执行方法 + /// + private void ProStepEnvRHDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopEnvRH != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopEnvRH!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEnvRHs!.Remove(ListSlopMeterEnvRH.Find(a => a.Id == SelectedSlopEnvRH!.Id)!); + //移除旧的数据 + ListSlopMeterEnvRH.Remove(ListSlopMeterEnvRH.Find(a => a.Id == SelectedSlopEnvRH.Id)!); + + //移除旧的数据 + ListSlopMeterEnvRHItems.Remove(ListSlopMeterEnvRHItems.Where(a => a.Id == SelectedSlopEnvRH!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEnvRHInfo = MeterEnvRHToString(ListSlopMeterEnvRH); + + //更新后检测时间是否匹配并界面提示 + CheckEnvRHSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新EnvRH表信息 + /// + private void RefreshMeterEnvRH() + { + ListSlopMeterEnvRH = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterEnvRHs!.ToList(); + + ListSlopMeterEnvRHItems.Clear(); + + ListSlopMeterEnvRHItems = new ObservableCollection(ListSlopMeterEnvRH!); + + } + + /// + /// 获取EnvRH当前的步骤的数据信息 + /// + private int AutoGetMeterEnvRHStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepEnvRHConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepEnvRHConstantSaveCmd + { + set + { + _ProStepEnvRHConstantSaveCmd = value; + } + get + { + if (_ProStepEnvRHConstantSaveCmd == null) + { + _ProStepEnvRHConstantSaveCmd = new DelegateCommand(() => ProStepEnvRHConstantSaveCmdMethod()); + } + return _ProStepEnvRHConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepEnvRHConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterEnvRHItems != null && ListSlopMeterEnvRHItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterEnvRHItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEnvRHs!.Remove(ListSlopMeterEnvRH.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterEnvRH.Remove(ListSlopMeterEnvRH.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterEnvRHItems.Remove(ListSlopMeterEnvRHItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEnvRHInfo = MeterEnvRHToString(ListSlopMeterEnvRH); + + //更新后检测时间是否匹配并界面提示 + CheckEnvRHSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstEnvRHData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvRHs!.ToList(); + if (ConstEnvRHData != null && ConstEnvRHData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterEnvRHData = new MeterEnvRH() + { + Constant = SelectedConstEnvRHValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterEnvRHStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterEnvRHData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshEnvRHById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvRHs!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterEnvRHInfo = MeterEnvRHToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstEnvRHData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstEnvRHValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshEnvRHById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEnvRHs!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEnvRHs!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEnvRHInfo = MeterEnvRHToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterEnvRHSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterEnvRHSwitchConstSlopPar + { + get { return _ProStepMeterEnvRHSwitchConstSlopPar; } + set { _ProStepMeterEnvRHSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepEnvRHSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepEnvRHSwitchConstSlopIndex + { + get { return _ProStepEnvRHSwitchConstSlopIndex; } + set { _ProStepEnvRHSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterEnvRHSwitchConstSlopCmd; + /// + /// EnvRH 常值和斜率切换 命令 + /// + public DelegateCommand MeterEnvRHSwitchConstSlopCmd + { + set + { + _MeterEnvRHSwitchConstSlopCmd = value; + } + get + { + if (_MeterEnvRHSwitchConstSlopCmd == null) + { + _MeterEnvRHSwitchConstSlopCmd = new DelegateCommand((obj) => MeterEnvRHSwitchConstSlopCmdMethod(obj)); + } + return _MeterEnvRHSwitchConstSlopCmd; + } + } + private void MeterEnvRHSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterEnvRHSwitchConstSlopPar = false; + } + else + { + ProStepMeterEnvRHSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterEnvRHToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckEnvRHSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterEnvRHExDto.SlopTime = ListSlopMeterEnvRH.Sum(a => a.KeepTime); + if (MeterEnvRHExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterEnvRHExDto.SlopTime != 0) + { + MeterEnvRHExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterEnvRHExDto.SlopTime; + MeterEnvRHExDto.IsTimeOk = false; + } + else + { + MeterEnvRHExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterEnvRHExDto.SlopTime; + MeterEnvRHExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterEnvRH数据 + /// + /// + private MeterEnvRH RefreshEnvRHById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterEnvRH(); + } + } + + + #endregion + + #region EnvTemp表 + + + + /// + /// EnvTemp 初始化函数 + /// + private void EnvTempInit() + { + ListSlopMeterEnvTempItems = new ObservableCollection(); + SelectedSlopEnvTemp = new MeterEnvTemp(); + SelectedConstEnvTemp = new MeterEnvTemp(); + } + + + private ObservableCollection _ListSlopMeterEnvTempItems; + /// + /// Meter EnvTemp数据集合 斜率的 + /// + public ObservableCollection ListSlopMeterEnvTempItems + { + get { return _ListSlopMeterEnvTempItems; } + set { _ListSlopMeterEnvTempItems = value; RaisePropertyChanged(); } + } + + /// + /// MeterEnvTemp集合数据 斜率 + /// + public List ListSlopMeterEnvTemp { get; set; } + + + private MeterEnvTemp _SelectedSlopEnvTemp; + /// + /// 当前选中的程序 EnvTemp 斜率 + /// + public MeterEnvTemp SelectedSlopEnvTemp + { + get { return _SelectedSlopEnvTemp; } + set { _SelectedSlopEnvTemp = value; RaisePropertyChanged(); } + } + + private MeterExInfoDto _MeterEnvTempExDto = new MeterExInfoDto(); + /// + /// 当前的拓展模型 EnvTemp + /// 用作统计,计算等 + /// + public MeterExInfoDto MeterEnvTempExDto + { + get { return _MeterEnvTempExDto; } + set { _MeterEnvTempExDto = value; RaisePropertyChanged(); } + } + + + + private MeterEnvTemp _SelectedConstEnvTemp; + /// + /// 当前选中的程序 EnvTemp 常值 + /// + public MeterEnvTemp SelectedConstEnvTemp + { + get { return _SelectedConstEnvTemp; } + set { _SelectedConstEnvTemp = value; RaisePropertyChanged(); } + } + + + private double _SelectedConstEnvTempValue; + /// + /// 常值模式设置的数据 + /// + public double SelectedConstEnvTempValue + { + get { return _SelectedConstEnvTempValue; } + set { _SelectedConstEnvTempValue = value; RaisePropertyChanged(); } + } + + + + private DelegateCommand _MeterEnvTempSlopSelectedChangedCmd; + /// + /// 刷新数据命令 + /// + public DelegateCommand MeterEnvTempSlopSelectedChangedCmd + { + set + { + _MeterEnvTempSlopSelectedChangedCmd = value; + } + get + { + if (_MeterEnvTempSlopSelectedChangedCmd == null) + { + _MeterEnvTempSlopSelectedChangedCmd = new DelegateCommand((str) => MeterEnvTempSlopSelectedChangedCmdMethod(str)); + } + return _MeterEnvTempSlopSelectedChangedCmd; + } + } + + + /// + /// EnvTemp表选中行的执行方法 + /// + /// + /// + private void MeterEnvTempSlopSelectedChangedCmdMethod(object par) + { + var SelectedData = par as MeterEnvTemp; + if (SelectedData != null) + { + //直接属性赋值,防止更改后未保存但是列表是同一个实例,列表更新了 + SelectedSlopEnvTemp = new MeterEnvTemp + { + StartValue = SelectedData.StartValue, + EndValue = SelectedData.EndValue, + StepNo = SelectedData.StepNo, + Id = SelectedData.Id, + ProStepId = SelectedData.ProStepId, + ProStep = SelectedData.ProStep, + Constant = SelectedData.Constant, + ValueType = SelectedData.ValueType, + CreateTime = SelectedData.CreateTime, + KeepTime = SelectedData.KeepTime, + }; + + } + } + + private DelegateCommand _ProStepEnvTempAddCmd; + /// + /// 新增EnvTemp命令 + /// + public DelegateCommand ProStepEnvTempAddCmd + { + set + { + _ProStepEnvTempAddCmd = value; + } + get + { + if (_ProStepEnvTempAddCmd == null) + { + _ProStepEnvTempAddCmd = new DelegateCommand(() => ProStepEnvTempAddCmdMethod()); + } + return _ProStepEnvTempAddCmd; + } + } + + /// + /// 增加EnvTemp命令执行方法 + /// + private void ProStepEnvTempAddCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterEnvTemp.Sum(a => a.KeepTime) + SelectedSlopEnvTemp.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + //删除可能之前的常值数据 + var Data = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvTemps!.ToList(); + if (Data != null && Data.Where(a => a.ValueType == ConfigValueType.Constant).Any()) + { + //常值数据库数据删除 + FreeSql.Delete(Data.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault()!.Id).ExecuteAffrows(); + //界面集合数据删除 + var ConstData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvTemps!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvTemps!.Remove(ConstData!); + } + + //当前的速度表集合数据 + var MeterEnvTemps = ListSlopMeterEnvTempItems.ToList(); + + var MeterEnvTempData = new MeterEnvTemp() + { + StartValue = SelectedSlopEnvTemp.StartValue, + EndValue = SelectedSlopEnvTemp.EndValue, + KeepTime = SelectedSlopEnvTemp.KeepTime, + ProStepId = SelectedProStepDto.Id, + ValueType = ConfigValueType.Slope, + StepNo = AutoGetMeterEnvTempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterEnvTempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshEnvTempById(InsertDataId); + //var CurIndex = ListProStep.FindIndex(a => a.Id == InsertStepData!.Id); + + var CurIndex = GetListMeterIndex(SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvTemps!.Count(), + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvTemps!.Count() != 0 ? SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvTemps!.Max(a => a.StepNo) : 0); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvTemps!.Insert(CurIndex, GetInsertData); + //新增数据到集合中 + ListSlopMeterEnvTemp.Insert(CurIndex, GetInsertData); + + //新增数据到界面集合中 + ListSlopMeterEnvTempItems.Insert(CurIndex, GetInsertData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterEnvTempInfo = MeterEnvTempToString(ListSlopMeterEnvTemp); + + //更新后检测时间是否匹配并界面提示 + CheckEnvTempSlopListTime(); + } + + + private DelegateCommand _ProStepEnvTempEditCmd; + /// + /// 新增EnvTemp命令 + /// + public DelegateCommand ProStepEnvTempEditCmd + { + set + { + _ProStepEnvTempEditCmd = value; + } + get + { + if (_ProStepEnvTempEditCmd == null) + { + _ProStepEnvTempEditCmd = new DelegateCommand(() => ProStepEnvTempEditCmdMethod()); + } + return _ProStepEnvTempEditCmd; + } + } + + /// + /// 编辑EnvTemp命令执行方法 + /// + private void ProStepEnvTempEditCmdMethod() + { + if (SelectedProgramSeg == null || SelectedProStepDto == null || SelectedSlopEnvTemp == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //if (GetKeepTimeBySpeed() < (ListSlopMeterEnvTemp.Where(a => a.Id != SelectedSlopEnvTemp!.Id).Sum(a => a.KeepTime) + SelectedSlopEnvTemp!.KeepTime)) + //{ + // MessageBox.Show("请把设置对象和速度表的时间匹配上!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + // return; + //} + + var UpdateData = FreeSql.Update() + .Set(a => a.StartValue, SelectedSlopEnvTemp.StartValue) + .Set(a => a.EndValue, SelectedSlopEnvTemp.EndValue) + .Set(a => a.KeepTime, SelectedSlopEnvTemp.KeepTime) + .Set(a => a.StepNo, SelectedSlopEnvTemp.StepNo) + .Where(a => a.Id == SelectedSlopEnvTemp.Id) + .ExecuteUpdated().FirstOrDefault(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshEnvTempById(SelectedSlopEnvTemp.Id); + var CurIndex = ListSlopMeterEnvTemp.FindIndex(a => a.Id == SelectedSlopEnvTemp.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEnvTemps!.Remove(ListSlopMeterEnvTemp.Find(a => a.Id == SelectedSlopEnvTemp!.Id)!); + //移除旧的数据 + ListSlopMeterEnvTemp.Remove(ListSlopMeterEnvTemp.Find(a => a.Id == SelectedSlopEnvTemp.Id)!); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEnvTemps!.Insert(CurIndex, GetUpdateData); + //新增数据 + ListSlopMeterEnvTemp.Insert(CurIndex, GetUpdateData); + + //移除旧的数据 + ListSlopMeterEnvTempItems.Remove(ListSlopMeterEnvTempItems.Where(a => a.Id == SelectedSlopEnvTemp!.Id).FirstOrDefault()!); + ListSlopMeterEnvTempItems.Insert(CurIndex, GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEnvTempInfo = MeterEnvTempToString(ListSlopMeterEnvTemp); + + //更新后检测时间是否匹配并界面提示 + CheckEnvTempSlopListTime(); + } + + private DelegateCommand _ProStepEnvTempDeleteCmd; + /// + /// 新增EnvTemp命令 + /// + public DelegateCommand ProStepEnvTempDeleteCmd + { + set + { + _ProStepEnvTempDeleteCmd = value; + } + get + { + if (_ProStepEnvTempDeleteCmd == null) + { + _ProStepEnvTempDeleteCmd = new DelegateCommand(() => ProStepEnvTempDeleteCmdMethod()); + } + return _ProStepEnvTempDeleteCmd; + } + } + + /// + /// 增加EnvTemp命令执行方法 + /// + private void ProStepEnvTempDeleteCmdMethod() + { + if (SelectedProgramSeg != null && SelectedProStepDto != null && SelectedSlopEnvTemp != null) + { + MessageBoxResult dialogResult = MessageBox.Show("你确定要删除当前的数据吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (dialogResult == MessageBoxResult.OK) + { + FreeSql.Delete(SelectedSlopEnvTemp!.Id).ExecuteAffrows(); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEnvTemps!.Remove(ListSlopMeterEnvTemp.Find(a => a.Id == SelectedSlopEnvTemp!.Id)!); + //移除旧的数据 + ListSlopMeterEnvTemp.Remove(ListSlopMeterEnvTemp.Find(a => a.Id == SelectedSlopEnvTemp.Id)!); + + //移除旧的数据 + ListSlopMeterEnvTempItems.Remove(ListSlopMeterEnvTempItems.Where(a => a.Id == SelectedSlopEnvTemp!.Id).FirstOrDefault()!); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEnvTempInfo = MeterEnvTempToString(ListSlopMeterEnvTemp); + + //更新后检测时间是否匹配并界面提示 + CheckEnvTempSlopListTime(); + } + + } + else + { + MessageBox.Show("未发现选中要删除的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + } + } + + + + /// + /// 更新EnvTemp表信息 + /// + private void RefreshMeterEnvTemp() + { + ListSlopMeterEnvTemp = ListProgramSeg.Where(a => a.Id == SelectedProgramSeg.Id).FirstOrDefault()!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id)! + .FirstOrDefault()!.MeterEnvTemps!.ToList(); + + ListSlopMeterEnvTempItems.Clear(); + + ListSlopMeterEnvTempItems = new ObservableCollection(ListSlopMeterEnvTemp!); + + } + + /// + /// 获取EnvTemp当前的步骤的数据信息 + /// + private int AutoGetMeterEnvTempStepNo() + { + var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); + if (StepInfo != null && StepInfo.Count > 0) + { + var MaxStep = StepInfo.Max(a => a.StepNo); + return MaxStep + 1; + } + else + { + return 1; + } + + } + + private DelegateCommand _ProStepEnvTempConstantSaveCmd; + /// + ///ConstantSaveCommand 常值保存命令 + /// + public DelegateCommand ProStepEnvTempConstantSaveCmd + { + set + { + _ProStepEnvTempConstantSaveCmd = value; + } + get + { + if (_ProStepEnvTempConstantSaveCmd == null) + { + _ProStepEnvTempConstantSaveCmd = new DelegateCommand(() => ProStepEnvTempConstantSaveCmdMethod()); + } + return _ProStepEnvTempConstantSaveCmd; + } + } + /// + /// ConstantSaveCommand 常值保存命令执行方法 + /// + private void ProStepEnvTempConstantSaveCmdMethod() + { + if (SelectedProStepDto == null) + { + MessageBox.Show("未发现选中要操作的数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return; + } + + //1 先判断是否有斜率数据,有则判断后删除,否则退回。 + if (ListSlopMeterEnvTempItems != null && ListSlopMeterEnvTempItems.Where(a => a.ValueType == ConfigValueType.Slope && a.ProStepId == SelectedProStepDto.Id).Count() > 0) + { + var result = MessageBox.Show("你将要保存常值模式的数据,同一个时刻只能配置一个模式生效,检测到【斜率】设置中存在多天数据,是否删除?【确定】将要删除斜率数据且设置常值信息,【取消】则不删除斜率数据且常值不保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand); + if (result == MessageBoxResult.OK) + { + var ListTempDeleteData = new List(); + //删除以前的斜率数据 + foreach (var item in ListSlopMeterEnvTempItems) + { + var DeleteData = FreeSql.Delete(item.Id).ExecuteDeleted().FirstOrDefault(); + ListTempDeleteData.Add(DeleteData); + } + + //再循环删除数据 + foreach (var DeleteData in ListTempDeleteData) + { + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEnvTemps!.Remove(ListSlopMeterEnvTemp.Find(a => a.Id == DeleteData!.Id)!); + //移除旧的数据 + ListSlopMeterEnvTemp.Remove(ListSlopMeterEnvTemp.Find(a => a.Id == DeleteData!.Id)!); + + //移除旧的数据 + ListSlopMeterEnvTempItems.Remove(ListSlopMeterEnvTempItems.Where(a => a.Id == DeleteData!.Id).FirstOrDefault()!); + } + + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEnvTempInfo = MeterEnvTempToString(ListSlopMeterEnvTemp); + + //更新后检测时间是否匹配并界面提示 + CheckEnvTempSlopListTime(); + + } + else + { + //不删除,不进行动作 + return; + } + } + + //2 再判断之前是否存在常值数据 + var ConstEnvTempData = ListProStep.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvTemps!.ToList(); + if (ConstEnvTempData != null && ConstEnvTempData.Where(a => a.ValueType == ConfigValueType.Constant && a.ProStepId == SelectedProStepDto.Id).Count() == 0) + { + //没有常值数据,则新增 + var MeterEnvTempData = new MeterEnvTemp() + { + Constant = SelectedConstEnvTempValue, + ValueType = ConfigValueType.Constant, + KeepTime = GetKeepTimeBySpeed(), + ProStepId = SelectedProStepDto.Id, + //StepNo = AutoGetMeterEnvTempStepNo(), + }; + + //增加数据 + var InsertDataId = FreeSql.Insert(MeterEnvTempData).ExecuteIdentity(); + + //重新查询获取的数据包括子集 + var GetInsertData = RefreshEnvTempById(InsertDataId); + + //上级的新增数据到集合中 + SelectedProgramSeg!.ProSteps!.Where(a => a.Id == SelectedProStepDto.Id).FirstOrDefault()!.MeterEnvTemps!.Add(GetInsertData);//常值只有一个 + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto.Id)!.MeterEnvTempInfo = MeterEnvTempToString(new List { GetInsertData }); + + + } + else + { + //常值数据不为0,那么说明之前是存在数据的,则需要更改操作 + var ConstantData = ConstEnvTempData!.Where(a => a.ValueType == ConfigValueType.Constant).FirstOrDefault(); + //更新常值信息 + FreeSql.Update() + .Set(a => a.Constant, SelectedConstEnvTempValue) + .Set(a => a.KeepTime, GetKeepTimeBySpeed()) + .Where(a => a.Id == ConstantData!.Id) + .ExecuteAffrows(); + + //重新查询获取的数据包括子集 + var GetUpdateData = RefreshEnvTempById(ConstantData!.Id); + + //删除上级的旧数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEnvTemps!.Remove(ConstantData); + + //上级新增数据 + SelectedProgramSeg!.ProSteps!.FindFirst(a => a.Id == SelectedProStepDto!.Id).MeterEnvTemps!.Add(GetUpdateData); + + //更新ProStep的字符串的集合数据 + ListProStepDtoItems.FindFirst(a => a.Id == SelectedProStepDto!.Id)!.MeterEnvTempInfo = MeterEnvTempToString(new List() { GetUpdateData }); + + } + } + + private bool _ProStepMeterEnvTempSwitchConstSlopPar; + /// + /// Constant/Slop 切换命令的参数值 + /// + public bool ProStepMeterEnvTempSwitchConstSlopPar + { + get { return _ProStepMeterEnvTempSwitchConstSlopPar; } + set { _ProStepMeterEnvTempSwitchConstSlopPar = value; RaisePropertyChanged(); } + } + + + private int _ProStepEnvTempSwitchConstSlopIndex; + /// + /// Constant/Slop 切换命令的参数值 Index + /// + public int ProStepEnvTempSwitchConstSlopIndex + { + get { return _ProStepEnvTempSwitchConstSlopIndex; } + set { _ProStepEnvTempSwitchConstSlopIndex = value; RaisePropertyChanged(); } + } + + + private DelegateCommand _MeterEnvTempSwitchConstSlopCmd; + + + /// + /// EnvTemp 常值和斜率切换 命令 + /// + public DelegateCommand MeterEnvTempSwitchConstSlopCmd + { + set + { + _MeterEnvTempSwitchConstSlopCmd = value; + } + get + { + if (_MeterEnvTempSwitchConstSlopCmd == null) + { + _MeterEnvTempSwitchConstSlopCmd = new DelegateCommand((obj) => MeterEnvTempSwitchConstSlopCmdMethod(obj)); + } + return _MeterEnvTempSwitchConstSlopCmd; + } + } + private void MeterEnvTempSwitchConstSlopCmdMethod(object obj) + { + if ((int)obj == 0) + { + ProStepMeterEnvTempSwitchConstSlopPar = false; + } + else + { + ProStepMeterEnvTempSwitchConstSlopPar = true; + } + + } + + /// + /// 步骤数据转字符串格式 + /// + /// + /// + private string MeterEnvTempToString(List data) + { + var strInfo = new StringBuilder(); + if (data != null && data.Count() > 0) + { + if (data.Where(a => a.ValueType == ConfigValueType.Slope).Count() > 0) + { + var Count = data.Count; + foreach (var item in data) + { + Count--; + strInfo.Append(item.StartValue); + strInfo.Append("->"); + strInfo.Append(item.EndValue); + strInfo.Append(" ["); + strInfo.Append(SecToString((int)item.KeepTime)); + strInfo.Append("]"); + if (Count != 0) + { + strInfo.Append(Environment.NewLine); + } + } + } + else + { + strInfo.Append(data.FirstOrDefault()!.Constant); + strInfo.Append($" [{SecToString(data.FirstOrDefault()!.KeepTime)}]"); + } + } + else + { + //空的集合数据 + strInfo.Append("---"); + } + + + + return strInfo.ToString(); + //return @"< ASDFA-ADFA-FASD-ADF "+ Environment.NewLine+" ASDFA-ADFA-FASD-ADF ASDFA-ADFA-FASD-ADF "; + } + + /// + /// 检查斜率配置时间集合是否满足要求 + /// + private void CheckEnvTempSlopListTime() + { + //更新后检测时间是否匹配并界面提示 + MeterEnvTempExDto.SlopTime = ListSlopMeterEnvTemp.Sum(a => a.KeepTime); + if (MeterEnvTempExDto.SlopTime != 0) + { + if (GetKeepTimeBySpeed() % MeterEnvTempExDto.SlopTime != 0) + { + MeterEnvTempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterEnvTempExDto.SlopTime; + MeterEnvTempExDto.IsTimeOk = false; + } + else + { + MeterEnvTempExDto.SlopCycle = GetKeepTimeBySpeed() * 1.0 / MeterEnvTempExDto.SlopTime; + MeterEnvTempExDto.IsTimeOk = true; + } + } + else + { + //被除数为0, + } + + } + + + /// + /// 根据ID获取MeterEnvTemp数据 + /// + /// + private MeterEnvTemp RefreshEnvTempById(long id) + { + var Data = FreeSql.Select() + .Where(c => c.Id == id) + .Include(a => a.ProStep) + .ToList(); + + if (Data != null && Data.Count() > 0) + { + return Data.FirstOrDefault()!; + } + else + { + return new MeterEnvTemp(); + } + } + + + #endregion + + + /// + /// 秒时间到 00:00:00字符串 + /// + /// + private string SecToString(int TotalSec) + { + try + { + TimeSpan TimeInfo = TimeSpan.FromSeconds(TotalSec); + return TimeInfo.ToString(); + } + catch (Exception ex) + { + MessageBox.Show("请检查输入时间数据!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand); + return "00:00:00"; + } + + } + + #region 公共库 @@ -1148,23 +15089,7 @@ namespace CapMachine.Wpf.ViewModels } - /// - /// 获取MeterSpeed当前的步骤的数据信息 - /// - private int AutoGetMeterPsStepNo() - { - var StepInfo = FreeSql.Select().Where(a => a.ProStepId == SelectedProStepDto.Id).ToList(); - if (StepInfo != null && StepInfo.Count > 0) - { - var MaxStep = StepInfo.Max(a => a.StepNo); - return MaxStep + 1; - } - else - { - return 1; - } - } #endregion diff --git a/CapMachine.Wpf/ViewModels/QuickMeterStepViewModel.cs b/CapMachine.Wpf/ViewModels/QuickMeterStepViewModel.cs new file mode 100644 index 0000000..b0bf64e --- /dev/null +++ b/CapMachine.Wpf/ViewModels/QuickMeterStepViewModel.cs @@ -0,0 +1,34 @@ +using CapMachine.Core; +using CapMachine.Wpf.Dtos; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CapMachine.Wpf.ViewModels +{ + public class QuickMeterStepViewModel : NavigationViewModel + { + /// + /// 实例化函数 + /// + public QuickMeterStepViewModel() + { + + } + + private ObservableCollection _ListQuickMeterStepDto; + /// + /// 程序集合 + /// + public ObservableCollection ListQuickMeterStepDto + { + get { return _ListQuickMeterStepDto; } + set { _ListQuickMeterStepDto = value; RaisePropertyChanged(); } + } + + + } +} diff --git a/CapMachine.Wpf/Views/ProConfigView.xaml b/CapMachine.Wpf/Views/ProConfigView.xaml index 58f9947..b16effd 100644 --- a/CapMachine.Wpf/Views/ProConfigView.xaml +++ b/CapMachine.Wpf/Views/ProConfigView.xaml @@ -3,6 +3,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Controls="clr-namespace:CapMachine.Shared.Controls;assembly=CapMachine.Shared" + xmlns:convert="clr-namespace:CapMachine.Wpf.Converts" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:local="clr-namespace:CapMachine.Wpf.Views" @@ -15,13 +16,17 @@ mc:Ignorable="d"> + + + + + - + - + + + - + - + @@ -216,8 +241,19 @@ - - + + + + + + + + + @@ -234,95 +270,466 @@ - + + Margin="2,0"> + + - - + - - - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +