Files
6150-HMI/CowainHmi/PlcDataTable/DlgEditPlcValue.cs
2026-01-15 15:06:36 +08:00

60 lines
2.1 KiB
C#

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;
}
}
}