代码拉取完成,页面将自动刷新
同步操作将从 老大哥/SerialPortForward 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace SerialPortForward
{
public partial class FrmDatas : Form
{
Dictionary<string, string> oldDic;
public delegate void SaveDatas(Dictionary<string, string> dic);
/// <summary>
/// 保存了新的应答数据
/// </summary>
public event SaveDatas SaveDatasEvent;
public FrmDatas(Dictionary<string, string> dic)
{
InitializeComponent();
oldDic = dic;
}
void ShowList(Dictionary<string, string> dic)
{
foreach (var item in dic)
{
AddData(item.Key, item.Value);
}
}
void AddData(string Receiv = "", string Reply = "")
{
HexAutoAnswer autoAnswer = new HexAutoAnswer(Receiv, Reply);
autoAnswer.RemoveSelfEvent += (HexAutoAnswer hexAutoAnswer) =>
{
tableLayoutPanel1.Controls.Remove(hexAutoAnswer);
};
tableLayoutPanel1.Controls.Add(autoAnswer, 0, tableLayoutPanel1.RowCount - 1);
autoAnswer.Dock = DockStyle.Fill;
autoAnswer.BringToFront();
tableLayoutPanel1.RowCount += 1;
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
}
private void FrmDatas_Load(object sender, EventArgs e)
{
ShowList(oldDic);
}
private void btnAdd_Click(object sender, EventArgs e)
{
AddData();
GoToLast();
}
private void btnSave_Click(object sender, EventArgs e)
{
Dictionary<string, string> dicNew = new Dictionary<string, string>();
//按照控件顺序倒叙保存
int max = tableLayoutPanel1.Controls.Count;
for (int i = max - 1; i >= 0; i--)
{
HexAutoAnswer autoAnswer = tableLayoutPanel1.Controls[i] as HexAutoAnswer;
if (string.IsNullOrEmpty(autoAnswer.ReceivHex) || string.IsNullOrEmpty(autoAnswer.ReplyHex) || !autoAnswer.IsHex)
{
MessageBox.Show("请检查数据全部是否为HEX格式");
return;
}
dicNew.Add(autoAnswer.ReceivHex, autoAnswer.ReplyHex);
}
SaveDatasEvent?.Invoke(dicNew);
DialogResult = DialogResult.OK;
}
private void FrmDatas_Shown(object sender, EventArgs e)
{
if (oldDic.Count > 0)
{
GoToLast();
}
}
void GoToLast()
{
tableLayoutPanel1.VerticalScroll.Value = tableLayoutPanel1.VerticalScroll.Maximum;
HexAutoAnswer haa = tableLayoutPanel1.Controls[0] as HexAutoAnswer;
haa.txtReceiv.Focus();
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。