using CowainHmi.Helper; using PCHMI; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace CowainHmi.Common { public partial class DlgEditPlcValue : Form { private PlcTagColumn tag; private string oldValue; public DlgEditPlcValue(PlcTagColumn tag) { InitializeComponent(); if (Enum.TryParse<数据显示器.DatType>(tag.DatType.ToString(), out 数据显示器.DatType datType)) { this.txtTag.数据类型 = datType; } this.txtTag.小数位数 = (uint)tag.DecimalPlaces; this.txtTag.字符串长度 = (uint)tag.StringLength; this.txtTag.Text = tag.VarValue; this.tag = tag; oldValue = tag.VarValue; } private void btnOk_Click(object sender, EventArgs e) { var result = MessageBox.Show("确定要修改变量吗?", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result != DialogResult.Yes) { return; } if (tag.DatType == 字段.DatType.INT32 || tag.DatType == 字段.DatType.UINT32 || tag.DatType == 字段.DatType.UINT16 || tag.DatType == 字段.DatType.INT16) { if (int.TryParse(this.txtTag.Text, out int val)) { this.tag.VarValue = tag.DecimalPlaces > 0 ? (val * tag.DecimalPlaces * 10).ToString() : val.ToString(); } } else { this.tag.VarValue = this.txtTag.Text; } PCHMI.OPTLOG.WLOG($"修改了变量值,名称:{this.tag.VarName},地址:{this.tag.Address},原值:{oldValue},新值:{this.tag.VarValue}"); PlcValueHelper.SetValue(this.tag); this.DialogResult = DialogResult.OK; } } }