添加项目文件。

This commit is contained in:
gongxh
2021-06-05 14:17:30 +08:00
parent f24605d16b
commit f5dbabdfc9
247 changed files with 58383 additions and 0 deletions

View File

@@ -0,0 +1,250 @@
using CleanMachineHMI.FrmUserControl;
using CleanMachineHMI.Utils;
using ComponentFactory.Krypton.Toolkit;
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 frmAddPlcItem : KryptonForm
{
public frmAddPlcItem()
{
InitializeComponent();
_ComboBoxLanguageTextList = this.GetInfoLanguageText(GlobalHelper.LanguageCode, "KryptonComboBox");
_InfoLanguageTextList = this.GetInfoLanguageText(GlobalHelper.LanguageCode);
}
private DataTable _ComboBoxLanguageTextList;
private DataTable _InfoLanguageTextList;
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); //失去焦点后发生事件
}
int modbusMinIndex = 0;
private void frmAddPlcItem_Load(object sender, EventArgs e)
{
InitControlEvent();
this.SetFormControlText(GlobalHelper.LanguageCode);
if (GlobalHelper.LanguageCode == "English")
{
kcmb_plcItemType.Items.Clear();
foreach (DataRow item in _ComboBoxLanguageTextList.GetComBoboxItemArr(kcmb_plcItemType.Name, "KryptonComboBox"))
{
kcmb_plcItemType.Items.Add(item["CONTROL_NAME"].ToString());
}
kcmb_plcItemDataType.Items.Clear();
foreach (DataRow item in _ComboBoxLanguageTextList.GetComBoboxItemArr(kcmb_plcItemDataType.Name, "KryptonComboBox"))
{
kcmb_plcItemDataType.Items.Add(item["CONTROL_NAME"].ToString());
}
}
kcmb_plcItemType.SelectedIndex = 0;
kcmb_plcItemDataType.SelectedIndex = 0;
kryptonPanel1.Focus();
}
/// <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编码");
KryptonMessageBox.Show(_InfoLanguageTextList.GetInfoText("请输入PLC变量编码!", "EnterPlcItemCodeInfo"));
return;
}
if (string.IsNullOrEmpty(ktb_plcItemName.Text))
{
//KryptonMessageBox.Show("请输入PLC名称");
KryptonMessageBox.Show(_InfoLanguageTextList.GetInfoText("请输入PLC变量名称!", "EnterPlcItemNameInfo"));
return;
}
if (string.IsNullOrEmpty(kcmb_plcItemType.Text))
{
//KryptonMessageBox.Show("请选择PLC类型");
KryptonMessageBox.Show(_InfoLanguageTextList.GetInfoText("请选择PLC变量类型!", "SelectPlcItemTypeInfo"));
return;
}
if (string.IsNullOrEmpty(kcmb_plcItemDataType.Text))
{
//KryptonMessageBox.Show("请选择PLC数据类型");
KryptonMessageBox.Show(_InfoLanguageTextList.GetInfoText("请选择PLC变量数据类型!", "SelectPlcItemDataTypeInfo"));
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 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 data type is【Y】, input PLC address can only be octal number!");
return;
}
}
int plcModbusAdd = modbusMinIndex + addPriIndex - 1;
string sqlCheck = $@"SELECT 1 FROM BAS_PLC_ITEM WHERE PLC_ITEM_CODE = '{ktb_plcItemCode.Text}'";
DataTable dtCheck = LeadDbHelperSQLite.Query(sqlCheck).Tables[0];
if (dtCheck != null && dtCheck.Rows.Count > 0)
{
//KryptonMessageBox.Show($"PLC编码:【{ktb_plcItemCode.Text}】已经被使用,请重新输入!");
KryptonMessageBox.Show($"PLC item code 【{0}】already exist, please re-enter");
return;
}
string sql = $@"
INSERT INTO [BAS_PLC_ITEM] (
[PLC_ITEM_CODE],
[PLC_ITEM_NAME],
[PLC_ITEM_TYPE],
[PLC_ITEM_DATA_TYPE],
[PLC_ITEM_DATA_LENGTH],
[PLC_ITEM_PRI_ADDRESS],
[PLC_ITEM_MODBUS_ADDRESS],
[PLC_ITEM_DEVIATION_ADDRESS],
[PLC_ITEM_VALUE],
[USED_FLAG],
[DEL_FLAG],
[CREATE_BY],
[CREATE_TIME],
[UPDATE_BY],
[UPDATE_TIME],
[DATA_VERSION],
[REMARKS1],
[REMARKS2],
[REMARKS3],
[REMARKS4],
[REMARKS5]
)
VALUES
(
'{ktb_plcItemCode.Text}',
'{ktb_plcItemName.Text}',
'{kcmb_plcItemType.SelectedIndex}',
'{kcmb_plcItemDataType.SelectedIndex}',
'{0}',
'{addPriIndex}',
'{plcModbusAdd}',
'{Convert.ToInt32(knud_plcItemDeviationAddress.Value)}',
NULL,
1,
0,
'{GlobalHelper.UserInfo.USER_ID}',
datetime('now', 'localtime'),
'{GlobalHelper.UserInfo.USER_ID}',
datetime('now', 'localtime'),
0,
NULL,
NULL,
NULL,
NULL,
NULL
);
";
int row = LeadDbHelperSQLite.ExecuteSql(sql);
if (row > 0)
{
//KryptonMessageBox.Show("添加PLC变量数据成功!");
KryptonMessageBox.Show(_InfoLanguageTextList.GetInfoText("新增PLC变量数据成功!", "AddSuccessInfo"));
frmPlcItemConfig.RefreshFrmHost();
this.Close();
}
else
{
//KryptonMessageBox.Show("添加PLC变量数据失败!");
KryptonMessageBox.Show(_InfoLanguageTextList.GetInfoText("新增PLC变量数据失败!", "AddFailInfo"));
}
}
catch (Exception ex)
{
KryptonMessageBox.Show(_InfoLanguageTextList.GetInfoText("新增PLC变量数据发生异常", "AddPlcItemDataExp") + $":【{ex.Message}】!");
}
}
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();
}
}
}