using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.IO.Ports; using System.Linq; using System.Media; using System.Reflection; using System.Reflection.Emit; using System.Runtime.InteropServices; using System.Runtime.Remoting.Contexts; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml.Linq; using HslCommunication.LogNet; using WindowsFormsApp1.db; using WindowsFormsApp1.form; using WindowsFormsApp1.mod; using WindowsFormsApp1.mod.database; using WindowsFormsApp1.mod.server; using WindowsFormsApp1.server; using static SQLite.SQLite3; using static WindowsFormsApp1.server.ApiClient; using Label = System.Windows.Forms.Label; namespace WindowsFormsApp1 { public partial class MainForm : Form { #region 内部变量 // 添加一个静态互斥体对象,用于防止程序多开 private static Mutex _singleInstanceMutex; // 添加一个标志变量,用于标记是否已经执行了清理操作 private bool _isCleanupDone = false; // 添加标志,表示窗体正在关闭 private bool _isFormClosing = false; // 添加一个静态变量来跟踪下一个要使用的槽位 private static int _nextEventSlot = 1; // 在MainForm类中添加一个字典,用于存储PLC状态控件 private Dictionary plcStatusLabels = new Dictionary(); private Dictionary plcStatusIndicators = new Dictionary(); // 在MainForm类的成员变量部分添加一个定时器 private System.Windows.Forms.Timer statusReportTimer = new System.Windows.Forms.Timer(); private System.Windows.Forms.Timer screwReportTimer = new System.Windows.Forms.Timer(); private ApiClient statusApiClient = new ApiClient(); // 专用于状态上报的API客户端 private object curingLock = new object(); private Dictionary OldPlcTrigger = new Dictionary(); // 在MainForm类的成员变量部分添加 private List