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

55 lines
1.8 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;
public DlgEditPlcValue(PlcTagColumn tag)
{
InitializeComponent();
this.txtTag. = (uint)tag.DecimalPlaces;
this.txtTag. = (uint)tag.StringLength;
this.txtTag. = (.DatType)tag.DatType;
this.txtTag.Text = tag.VarValue;
this.tag = tag;
}
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;
}
PlcValueHelper.SetValue(this.tag);
this.DialogResult = DialogResult.OK;
}
}
}