完善功能

This commit is contained in:
2025-09-22 14:30:54 +08:00
parent fde5919d99
commit 365cd2397a
31 changed files with 1849 additions and 467 deletions

View File

@@ -0,0 +1,57 @@
using System;
using System.Windows.Input;
namespace .Base
{
public class DelegateCommand : ICommand
{
public Action<object> ExecuteCommand = null;
public event EventHandler CanExecuteChanged;
public DelegateCommand(DelegateCommand focusAdjustToCommand)
{
}
public DelegateCommand(Action<object> Command)
{
ExecuteCommand = Command;
}
public bool CanExecute(object paramter)
{
return true;
}
public void Execute(object paramter)
{
ExecuteCommand?.Invoke(paramter);
}
}
public class DelegateCommand<T> : ICommand
{
public Action<T> ExecuteCommand = null;
public event EventHandler CanExecuteChanged;
public DelegateCommand()
{
}
public DelegateCommand(Action<T> Command)
{
ExecuteCommand = Command;
}
public bool CanExecute(object paramter)
{
return true;
}
public void Execute(object paramter)
{
ExecuteCommand?.Invoke((T)paramter);
}
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using .Utility.Core;
using .Utility.Extension;
namespace .Base
{
public class GlobalVariable
{
private static MyConfig _config;
/// <summary>
/// 配置数据
/// </summary>
public static MyConfig Config
{
get
{
if (_config == null)
_config = File.ReadAllText(MyEnvironment.Root("/Configs/Config.json")).ToObject<MyConfig>();
return _config;
}
set
{
_config = value;
}
}
public static void SaveConfig()
{
File.WriteAllText(MyEnvironment.Root("/Configs/Config.json"), Config.ToJson());
}
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Dynamic;
using System.Runtime.CompilerServices;
using System.Xml.Serialization;
namespace .Base
{
public class ModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged([CallerMemberName] string propertyname = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyname));
}
}
}

View File

@@ -0,0 +1,150 @@
using System;
using System.Linq;
using System.Text;
namespace .Base
{
/// <summary>
/// 配置类
/// </summary>
public class MyConfig : ModelBase
{
/// <summary>
/// 时间
/// </summary>
[Comment("时间")]
public string Time { get; set; }
/// <summary>
/// 时间字体大小
/// </summary>
[Comment("时间字体大小")]
public int TimeSize { get; set; }
/// <summary>
/// 负责人
/// </summary>
[Comment("负责人")]
public string Charger { get; set; }
/// <summary>
/// 负责人字体大小
/// </summary>
[Comment("负责人字体大小")]
public int ChargerSize { get; set; }
/// <summary>
/// 风险等级
/// </summary>
[Comment("风险等级")]
public string RiskLevel { get; set; }
/// <summary>
/// 风险等级字体大小
/// </summary>
[Comment("风险等级字体大小")]
public int RiskLevelSize { get; set; }
/// <summary>
/// 工作内容
/// </summary>
[Comment("工作内容")]
public string Content { get; set; }
/// <summary>
/// 工作内容字体大小
/// </summary>
[Comment("工作内容字体大小")]
public int ContentSize { get; set; }
/// <summary>
/// 危险点
/// </summary>
[Comment("危险点")]
public string DangerPoint { get; set; }
/// <summary>
/// 危险点
/// </summary>
[Comment("危险点字体大小")]
public int DangerPointSize { get; set; }
/// <summary>
/// 重点措施
/// </summary>
[Comment("重点措施")]
public string Measures { get; set; }
[Comment("重点措施字体大小")]
public int MeasuresSize { get; set; }
[Comment("党员1图片路径")]
public string CPCMember1Path { get; set; }
[Comment("党员1姓名")]
public string CPCMember1Name { get; set; }
[Comment("党员2图片路径")]
public string CPCMember2Path { get; set; }
[Comment("党员2姓名")]
public string CPCMember2Name { get; set; }
[Comment("党员3图片路径")]
public string CPCMember3Path { get; set; }
[Comment("党员3姓名")]
public string CPCMember3Name { get; set; }
[Comment("党员4图片路径")]
public string CPCMember4Path { get; set; }
[Comment("党员4姓名")]
public string CPCMember4Name { get; set; }
[Comment("党员字体大小")]
public int CPCMemberSize { get; set;}
/// <summary>
/// 转换成JSON字符串
/// </summary>
/// <returns></returns>
public string ToJson()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("{");
//得到所有的Property
var properties = GetType().GetProperties();
for (int i = 0; i < properties.Length; i++)
{
var property = properties[i];
string endChar = ",";
if (i == properties.Length - 1)
{
endChar = "";
}
var comment = property.GetCustomAttributes(typeof(CommentAttribute), false).FirstOrDefault() as CommentAttribute;
string commentText = "";
if (comment != null)
{
commentText = $" /* {comment.Comment} */";
}
string propertyName = property.Name;
var value = property.GetValue(this, null);
if (value != null)
{
var valueType = value.GetType();
if (valueType == typeof(string))
{
sb.AppendLine($" \"{propertyName}\":\"{value}\"{endChar}{commentText}");
}
else
{
sb.AppendLine($" \"{propertyName}\":{value}{endChar}{commentText}");
}
}
}
sb.AppendLine("}");
return sb.ToString();
}
}
public class CommentAttribute : Attribute
{
public string Comment { get; set; }
public CommentAttribute(string comment)
{
Comment = comment;
}
}
}

View File

@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace .Base
{
public class ViewModelBase : ModelBase
{
public MyConfig Config => GlobalVariable.Config;
public static object _lock = new object();
//获取PLC变量值
//public object GetPlcValue(string plcVariableName, bool isLog = true)
//{
// lock (_lock)
// {
// try
// {
// return adsServer.GetValue(plcVariableName);
// }
// catch
// {
// if (string.IsNullOrEmpty(plcVariableName))
// LogErr($"Error in GetPLCVar() Plc variable is null or empty.");
// else
// LogErr($"Error in GetPLCVar(), PLC variable '{plcVariableName}'");
// }
// return "0";
// }
//}
//public T GetPlcValue<T>(string plcVariableName)
//{
// lock (_lock)
// {
// try
// {
// object value = adsServer.GetValue(plcVariableName);
// return (T)Convert.ChangeType(value, typeof(T));
// }
// catch
// {
// if (string.IsNullOrEmpty(plcVariableName))
// LogErr($"Error in GetPLCVar() Plc variable is null or empty.");
// else
// LogErr($"Error in GetPLCVar(), PLC variable '{plcVariableName}'");
// return default(T);
// }
// }
//}
//设置PLC变量值
//public bool SetPlcValue(string plcVariableName, object plcValue, bool isLog = true)
//{
// lock (_lock)
// {
// bool res = false;
// try
// {
// res = adsServer.SetValue(plcVariableName, plcValue);
// }
// catch
// {
// if (string.IsNullOrEmpty(plcVariableName))
// LogErr($"Error in SetPLCVar() Plc variable is null or empty.");
// else
// LogErr($"Error in SetPLCVar(), PLC variable '{plcVariableName}'");
// }
// return res;
// }
//}
}
}