2021-06-05 14:17:30 +08:00
|
|
|
|
using CleanMachineHMI.FrmUserControl;
|
|
|
|
|
|
using CleanMachineHMI.Utils;
|
2021-12-26 21:30:02 +08:00
|
|
|
|
using Krypton.Toolkit;
|
2021-06-05 14:17:30 +08:00
|
|
|
|
using LeadDataBaseUtility;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
|
|
namespace CleanMachineHMI.frmChild
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class frmEditPlcItem : KryptonForm
|
|
|
|
|
|
{
|
|
|
|
|
|
public frmEditPlcItem()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
public string PlcItemId { get; set; }
|
|
|
|
|
|
int modbusMinIndex = 0;
|
|
|
|
|
|
private void txt_GotFocus(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
KeyboardAutoPopUp.ShowInputPanel();
|
|
|
|
|
|
}
|
|
|
|
|
|
private void txt_LostFocus(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
KeyboardAutoPopUp.HideInputPanel();
|
|
|
|
|
|
}
|
|
|
|
|
|
private void InitControlEvent()
|
|
|
|
|
|
{
|
|
|
|
|
|
ktb_plcItemCode.GotFocus += new EventHandler(txt_GotFocus); //获取焦点前发生事件
|
|
|
|
|
|
ktb_plcItemCode.LostFocus += new EventHandler(txt_LostFocus); //失去焦点后发生事件
|
|
|
|
|
|
|
|
|
|
|
|
ktb_plcItemName.GotFocus += new EventHandler(txt_GotFocus); //获取焦点前发生事件
|
|
|
|
|
|
ktb_plcItemName.LostFocus += new EventHandler(txt_LostFocus); //失去焦点后发生事件
|
|
|
|
|
|
|
|
|
|
|
|
knud_plcItemPriAddress.GotFocus += new EventHandler(txt_GotFocus); //获取焦点前发生事件
|
|
|
|
|
|
knud_plcItemPriAddress.LostFocus += new EventHandler(txt_LostFocus); //失去焦点后发生事件
|
|
|
|
|
|
|
|
|
|
|
|
knud_plcItemDeviationAddress.GotFocus += new EventHandler(txt_GotFocus); //获取焦点前发生事件
|
|
|
|
|
|
knud_plcItemDeviationAddress.LostFocus += new EventHandler(txt_LostFocus); //失去焦点后发生事件
|
|
|
|
|
|
}
|
|
|
|
|
|
private void frmEditPlcItem_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
InitControlEvent();
|
2022-03-18 19:06:26 +08:00
|
|
|
|
this.SetFormControlText();
|
2022-03-18 21:25:34 +08:00
|
|
|
|
|
2021-06-05 14:17:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
kcmb_plcItemType.Items.Clear();
|
2022-03-19 16:14:32 +08:00
|
|
|
|
foreach (string item in this.GetComBoboxItemArr(kcmb_plcItemType.Name))
|
2021-06-05 14:17:30 +08:00
|
|
|
|
{
|
2022-03-18 21:25:34 +08:00
|
|
|
|
kcmb_plcItemType.Items.Add(item);
|
2021-06-05 14:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
kcmb_plcItemDataType.Items.Clear();
|
2022-03-19 16:14:32 +08:00
|
|
|
|
foreach (string item in this.GetComBoboxItemArr(kcmb_plcItemDataType.Name))
|
2021-06-05 14:17:30 +08:00
|
|
|
|
{
|
2022-03-18 21:25:34 +08:00
|
|
|
|
kcmb_plcItemDataType.Items.Add(item);
|
2021-06-05 14:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
kcmb_plcItemType.SelectedIndex = 0;
|
|
|
|
|
|
kcmb_plcItemDataType.SelectedIndex = 0;
|
|
|
|
|
|
string sql = $@"SELECT * FROM BAS_PLC_ITEM WHERE PLC_ITEM_ID = '{PlcItemId}'";
|
|
|
|
|
|
DataTable dt = LeadDbHelperSQLite.Query(sql).Tables[0];
|
|
|
|
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
ktb_plcItemCode.Text = dt.Rows[0]["PLC_ITEM_CODE"].ToString();
|
|
|
|
|
|
ktb_plcItemName.Text = dt.Rows[0]["PLC_ITEM_NAME"].ToString();
|
|
|
|
|
|
kcmb_plcItemType.SelectedIndex = Convert.ToInt32(dt.Rows[0]["PLC_ITEM_TYPE"]);
|
|
|
|
|
|
kcmb_plcItemDataType.SelectedIndex = Convert.ToInt32(dt.Rows[0]["PLC_ITEM_DATA_TYPE"]);
|
|
|
|
|
|
knud_plcItemPriAddress.Value = Convert.ToInt32(dt.Rows[0]["PLC_ITEM_PRI_ADDRESS"]);
|
|
|
|
|
|
knud_plcItemDeviationAddress.Value = Convert.ToInt32(dt.Rows[0]["PLC_ITEM_DEVIATION_ADDRESS"]);
|
|
|
|
|
|
ktb_plcItemCode.Enabled = false;
|
|
|
|
|
|
kcmb_plcItemDataType_SelectionChangeCommitted(sender, e);
|
|
|
|
|
|
}
|
|
|
|
|
|
kryptonPanel1.Focus();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2022-05-06 08:45:56 +08:00
|
|
|
|
KryptonMessageBox.Show(this.T("编辑PLC变量数据界面加载异常", "LoadEditFrmExp") + $":【{ex.Message}】!");
|
2021-06-05 14:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 判断是否八进制格式字符串
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="str"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public bool IsOctal(string str)
|
|
|
|
|
|
{
|
|
|
|
|
|
string PATTERN = @"[0-7]+$";
|
|
|
|
|
|
return System.Text.RegularExpressions.Regex.IsMatch(str, PATTERN);
|
|
|
|
|
|
}
|
|
|
|
|
|
private void kryptonButton1_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(ktb_plcItemCode.Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
//KryptonMessageBox.Show("请输入PLC编码");
|
2022-05-06 08:45:56 +08:00
|
|
|
|
KryptonMessageBox.Show(this.T("请输入PLC变量编码!", "EnterPlcItemCodeInfo"));
|
2021-06-05 14:17:30 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(ktb_plcItemName.Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
//KryptonMessageBox.Show("请输入PLC名称");
|
2022-05-06 08:45:56 +08:00
|
|
|
|
KryptonMessageBox.Show(this.T("请输入PLC变量名称!", "EnterPlcItemNameInfo"));
|
2021-06-05 14:17:30 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(kcmb_plcItemType.Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
//KryptonMessageBox.Show("请选择PLC类型");
|
2022-05-06 08:45:56 +08:00
|
|
|
|
KryptonMessageBox.Show(this.T("请选择PLC变量类型!", "SelectPlcItemTypeInfo"));
|
2021-06-05 14:17:30 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (string.IsNullOrEmpty(kcmb_plcItemDataType.Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
//KryptonMessageBox.Show("请选择PLC数据类型");
|
2022-05-06 08:45:56 +08:00
|
|
|
|
KryptonMessageBox.Show(this.T("请选择PLC变量数据类型!", "SelectPlcItemDataTypeInfo"));
|
2021-06-05 14:17:30 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
int addPriIndex = Convert.ToInt32(knud_plcItemPriAddress.Value);
|
|
|
|
|
|
if (kcmb_plcItemDataType.SelectedIndex == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (addPriIndex <= 1535)
|
|
|
|
|
|
{
|
|
|
|
|
|
modbusMinIndex = 2049;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
modbusMinIndex = 5057;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (kcmb_plcItemDataType.SelectedIndex == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
modbusMinIndex = 4097;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (kcmb_plcItemDataType.SelectedIndex == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
modbusMinIndex = 1025;
|
|
|
|
|
|
if (!IsOctal(addPriIndex.ToString()))
|
|
|
|
|
|
{
|
|
|
|
|
|
//KryptonMessageBox.Show("当PLC数据类型为:【X】,输入的PLC地址只能是八进制的数字!");
|
|
|
|
|
|
KryptonMessageBox.Show("When PLC item data type is【X】, input PLC address can only be octal number!");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (kcmb_plcItemDataType.SelectedIndex == 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
modbusMinIndex = 1281;
|
|
|
|
|
|
if (!IsOctal(addPriIndex.ToString()))
|
|
|
|
|
|
{
|
|
|
|
|
|
//KryptonMessageBox.Show("当PLC数据类型为:【Y】,输入的PLC地址只能是八进制的数字!");
|
|
|
|
|
|
KryptonMessageBox.Show("When PLC item data type is【Y】, input PLC address can only be octal number!");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
int plcModbusAdd = modbusMinIndex + addPriIndex - 1;
|
|
|
|
|
|
string sql = $@"
|
|
|
|
|
|
UPDATE BAS_PLC_ITEM
|
|
|
|
|
|
SET PLC_ITEM_NAME = '{ktb_plcItemName.Text}',
|
|
|
|
|
|
PLC_ITEM_TYPE = '{kcmb_plcItemType.SelectedIndex}',
|
|
|
|
|
|
PLC_ITEM_DATA_TYPE = '{kcmb_plcItemDataType.SelectedIndex}',
|
|
|
|
|
|
PLC_ITEM_MODBUS_ADDRESS = '{plcModbusAdd}',
|
|
|
|
|
|
PLC_ITEM_DEVIATION_ADDRESS = '{Convert.ToInt32(knud_plcItemDeviationAddress.Value)}',
|
|
|
|
|
|
PLC_ITEM_PRI_ADDRESS = '{addPriIndex}',
|
2022-05-06 12:28:16 +08:00
|
|
|
|
UPDATE_BY = '{Global.UserInfo.UserId}',
|
2021-06-05 14:17:30 +08:00
|
|
|
|
UPDATE_TIME = datetime('now', 'localtime'),
|
|
|
|
|
|
DATA_VERSION = DATA_VERSION + 1
|
|
|
|
|
|
WHERE
|
|
|
|
|
|
PLC_ITEM_ID = '{PlcItemId}'
|
|
|
|
|
|
";
|
2022-05-16 09:03:42 +08:00
|
|
|
|
int row = LeadDbHelperSQLite.Execute(sql);
|
2021-06-05 14:17:30 +08:00
|
|
|
|
if (row > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
//KryptonMessageBox.Show("编辑PLC变量数据成功!");
|
2022-05-06 08:45:56 +08:00
|
|
|
|
KryptonMessageBox.Show(this.T("编辑PLC变量数据成功!", "EditSuccessInfo"));
|
2021-06-05 14:17:30 +08:00
|
|
|
|
frmPlcItemConfig.RefreshFrmHost();
|
|
|
|
|
|
this.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
//KryptonMessageBox.Show("编辑PLC变量数据失败!");
|
2022-05-06 08:45:56 +08:00
|
|
|
|
KryptonMessageBox.Show(this.T("编辑PLC变量数据失败!", "EditFailInfo"));
|
2021-06-05 14:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
2022-05-06 08:45:56 +08:00
|
|
|
|
KryptonMessageBox.Show(this.T("编辑PLC变量数据发生异常", "EditPlcItemDataExp") + $":【{ex.Message}】!");
|
2021-06-05 14:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void kcmb_plcItemDataType_SelectionChangeCommitted(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (kcmb_plcItemDataType.SelectedIndex == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
knud_plcItemPriAddress.Maximum = 4095;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (kcmb_plcItemDataType.SelectedIndex == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
knud_plcItemPriAddress.Maximum = 9999;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (kcmb_plcItemDataType.SelectedIndex == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
knud_plcItemPriAddress.Maximum = 377;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (kcmb_plcItemDataType.SelectedIndex == 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
knud_plcItemPriAddress.Maximum = 377;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void kryptonButton2_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|