|
@@ -58,10 +58,16 @@ namespace Bird_tool
|
|
|
private static LogLevel show_log_level = LogLevel.info;
|
|
|
private static StringBuilder logBuilder = new StringBuilder();
|
|
|
|
|
|
+ private static ExcelDataManager m_excel_manager;
|
|
|
+ private string m_config_uuid = "";
|
|
|
+
|
|
|
+
|
|
|
private bool result_success = false;
|
|
|
private string result_msg = "";
|
|
|
private TestMode m_test_mode = TestMode.none;
|
|
|
|
|
|
+ private string AppConfigPath = "";
|
|
|
+
|
|
|
private bool SetWifi = false;
|
|
|
private string wifi_ssid = "";
|
|
|
private string wifi_password = "";
|
|
@@ -72,6 +78,9 @@ namespace Bird_tool
|
|
|
private string excel_path = "test.xlsx";
|
|
|
private string excel_primary_key = "uuid";
|
|
|
|
|
|
+ private string hw_test_csv_path = "TestReport/report.csv";
|
|
|
+ private string config_csv_path = "ConfigReport/report.csv";
|
|
|
+
|
|
|
|
|
|
public bird_tool()
|
|
|
{
|
|
@@ -117,7 +126,7 @@ namespace Bird_tool
|
|
|
|
|
|
static public void Log_show(string message)
|
|
|
{
|
|
|
- MessageBox.Show(message);
|
|
|
+ TopMostMessageBox.Show(message);
|
|
|
}
|
|
|
|
|
|
private void ShowLogWindow()
|
|
@@ -287,7 +296,9 @@ namespace Bird_tool
|
|
|
|
|
|
private void Tool_load(object sender, EventArgs e)
|
|
|
{
|
|
|
+
|
|
|
load_app_config();
|
|
|
+
|
|
|
_uart_ui_change(false);
|
|
|
SerialPort_Load();
|
|
|
|
|
@@ -309,20 +320,47 @@ namespace Bird_tool
|
|
|
{
|
|
|
_uart_ui_change(false);
|
|
|
// 判断是否在测试
|
|
|
- StopTest(isError);
|
|
|
+ if (isError)
|
|
|
+ {
|
|
|
+ StopTest(false, "串口异常断开连接");
|
|
|
+ }
|
|
|
};
|
|
|
+ _serialManager.OnLog += Log;
|
|
|
+ Log("初始化串口组件中...");
|
|
|
_serialManager.OnConnect += () =>
|
|
|
{
|
|
|
_uart_ui_change(true);
|
|
|
};
|
|
|
+
|
|
|
+ if (appConfig.enable_excel_load)
|
|
|
+ {
|
|
|
+ m_excel_manager = new ExcelDataManager(appConfig);
|
|
|
+ m_excel_manager.OnLog += Log;
|
|
|
+ m_excel_manager.OnLogShow += Log_show;
|
|
|
+ if (!m_excel_manager.IsValid)
|
|
|
+ {
|
|
|
+ Log("excel 文件加载失败, 将禁用ecxel相关功能", LogLevel.error);
|
|
|
+ Log_show("excel 文件加载失败, 将禁用ecxel相关功能");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
private void load_app_config()
|
|
|
{
|
|
|
+ Log($"加载配置文件 {ConfigManager.getConfigPath()}");
|
|
|
appConfig = ConfigManager.LoadConfig();
|
|
|
wifi_ssid = appConfig.wifi_ssid;
|
|
|
wifi_password = appConfig.wifi_passwd;
|
|
|
txt_ssid.Text = wifi_ssid;
|
|
|
txt_password.Text = wifi_password;
|
|
|
+ if (appConfig.enable_excel_load)
|
|
|
+ {
|
|
|
+ Log($"启用excel文件,尝试加载excel文件中 {appConfig.excel_path}");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log($"不使用excel加载, 仅使用基础检测功能");
|
|
|
+ Log($"如果需要使用excel配置功能, 请在配置文件{ConfigManager.getConfigPath()}中进行配置");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void SerialPort_Load()
|
|
@@ -339,7 +377,6 @@ namespace Bird_tool
|
|
|
|
|
|
// 初始加载串口列表
|
|
|
RefreshPortList();
|
|
|
- Log("inti ");
|
|
|
_testExecutor = new TestExecutor(_serialManager);
|
|
|
|
|
|
// 绑定事件处理
|
|
@@ -425,13 +462,10 @@ namespace Bird_tool
|
|
|
}
|
|
|
// 尝试连接串口
|
|
|
Log($"连接串口{currentSelection}");
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
if (_serialManager.IsOpen())
|
|
|
{
|
|
|
// 调用停止函数
|
|
|
- StopTest(true);
|
|
|
+ StopTest(true, "主动关闭串口");
|
|
|
_serialManager.Disconnect();
|
|
|
System.Threading.Thread.Sleep(100);
|
|
|
_uart_ui_change(false);
|
|
@@ -446,7 +480,7 @@ namespace Bird_tool
|
|
|
Log("串口开启成功");
|
|
|
// 设置窗口内容
|
|
|
_uart_ui_change(true);
|
|
|
-
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
@@ -463,6 +497,23 @@ namespace Bird_tool
|
|
|
checkWifi();
|
|
|
hw_test();
|
|
|
}
|
|
|
+ private void Evt_config_click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ if (appConfig.enable_excel_load && !m_excel_manager.IsValid)
|
|
|
+ {
|
|
|
+ Log_show($"excel 文件异常, 请检查配置文件 {ConfigManager.getConfigPath()}");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!_serialManager.IsOpen())
|
|
|
+ {
|
|
|
+ MessageBox.Show("请先打开串口");
|
|
|
+ _serialManager.Disconnect();
|
|
|
+ System.Threading.Thread.Sleep(100);
|
|
|
+ _uart_ui_change(false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ config_test();
|
|
|
+ }
|
|
|
private void Evt_sd_click(object sender, EventArgs e)
|
|
|
{
|
|
|
if (!_serialManager.IsOpen())
|
|
@@ -481,6 +532,27 @@ namespace Bird_tool
|
|
|
checkWifi();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private void Evt_re_main()
|
|
|
+ {
|
|
|
+ ui_show_start_panpel();
|
|
|
+ progressPanel.ResetPanel();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Evt_start_query_test()
|
|
|
+ {
|
|
|
+ StartTest(TestType.StartIndex);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Evt_setpStart(string key, TestType testType)
|
|
|
+ {
|
|
|
+ StartTest(testType, key);
|
|
|
+ }
|
|
|
+ private void Evt_StopTest(bool isQuery)
|
|
|
+ {
|
|
|
+ StopTest(isQuery, "手动停止测试");
|
|
|
+ }
|
|
|
+
|
|
|
private void checkWifi ()
|
|
|
{
|
|
|
// 获取wifi值
|
|
@@ -508,7 +580,16 @@ namespace Bird_tool
|
|
|
{
|
|
|
el_btn_hw_test.Enabled = enabled;
|
|
|
el_btn_sd_test.Enabled = enabled;
|
|
|
- el_btn_config.Enabled = enabled;
|
|
|
+
|
|
|
+ if (appConfig.enable_excel_load)
|
|
|
+ {
|
|
|
+ el_btn_config.Enabled = enabled;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ el_btn_config.Enabled = false;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
// 可选:添加视觉反馈
|
|
|
if (enabled)
|
|
@@ -518,11 +599,13 @@ namespace Bird_tool
|
|
|
el_btn_hw_test.FlatStyle = FlatStyle.Standard; // 恢复原始样式
|
|
|
el_btn_hw_test.Cursor = Cursors.Default;
|
|
|
|
|
|
- el_btn_config.BackColor = SystemColors.Control;
|
|
|
- el_btn_config.ForeColor = SystemColors.ControlText;
|
|
|
- el_btn_config.FlatStyle = FlatStyle.Standard;
|
|
|
- el_btn_config.Cursor = Cursors.Default;
|
|
|
-
|
|
|
+ if (appConfig.enable_excel_load)
|
|
|
+ {
|
|
|
+ el_btn_config.BackColor = SystemColors.Control;
|
|
|
+ el_btn_config.ForeColor = SystemColors.ControlText;
|
|
|
+ el_btn_config.FlatStyle = FlatStyle.Standard;
|
|
|
+ el_btn_config.Cursor = Cursors.Default;
|
|
|
+ }
|
|
|
el_btn_sd_test.BackColor = SystemColors.Control; // 标准按钮背景色
|
|
|
el_btn_sd_test.ForeColor = SystemColors.ControlText; // 标准文本色
|
|
|
el_btn_sd_test.FlatStyle = FlatStyle.Standard; // 恢复原始样式
|
|
@@ -571,17 +654,29 @@ namespace Bird_tool
|
|
|
this.Refresh();
|
|
|
}
|
|
|
|
|
|
+ private void UpdateConnButtonText(bool uart_flag, string text)
|
|
|
+ {
|
|
|
+ if (el_btn_conn.InvokeRequired)
|
|
|
+ {
|
|
|
+ el_btn_conn.Invoke(new Action<bool, string>(UpdateConnButtonText), uart_flag, text);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ el_btn_conn.Text = text;
|
|
|
+ _SetTestButtonsEnabled(uart_flag);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void _uart_ui_change(bool uart_flag)
|
|
|
{
|
|
|
if (uart_flag)
|
|
|
{
|
|
|
- el_btn_conn.Text = "断开连接";
|
|
|
+ UpdateConnButtonText(uart_flag, "断开连接");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- el_btn_conn.Text = "连接串口";
|
|
|
+ UpdateConnButtonText(uart_flag, "连接串口");
|
|
|
}
|
|
|
- _SetTestButtonsEnabled(uart_flag);
|
|
|
}
|
|
|
|
|
|
private void _ip_ui_change()
|
|
@@ -604,187 +699,6 @@ namespace Bird_tool
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void PromptUser(string question, Action onYes, Action onNo, int waitTime = -1)
|
|
|
- {
|
|
|
- this.Invoke((Action)(() =>
|
|
|
- {
|
|
|
- // 创建自定义提示窗口
|
|
|
- var prompt = new Form
|
|
|
- {
|
|
|
- Width = 450,
|
|
|
- Height = 250,
|
|
|
- FormBorderStyle = FormBorderStyle.FixedDialog,
|
|
|
- Text = "操作确认",
|
|
|
- StartPosition = FormStartPosition.CenterParent,
|
|
|
- Font = new Font("Microsoft YaHei UI", 10),
|
|
|
- Icon = this.Icon,
|
|
|
- MinimizeBox = false,
|
|
|
- MaximizeBox = false
|
|
|
- };
|
|
|
-
|
|
|
- // 主面板 - 使用表格布局实现更好的响应式设计
|
|
|
- var mainPanel = new TableLayoutPanel
|
|
|
- {
|
|
|
- Dock = DockStyle.Fill,
|
|
|
- ColumnCount = 1,
|
|
|
- RowCount = 3,
|
|
|
- Padding = new Padding(15),
|
|
|
- RowStyles = {
|
|
|
- new RowStyle(SizeType.Percent, 70F),
|
|
|
- new RowStyle(SizeType.AutoSize),
|
|
|
- new RowStyle(SizeType.AutoSize)
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- // 问题标签
|
|
|
- var label = new Label
|
|
|
- {
|
|
|
- Text = question,
|
|
|
- Dock = DockStyle.Fill,
|
|
|
- TextAlign = ContentAlignment.MiddleCenter,
|
|
|
- Font = new Font("Microsoft YaHei UI", 12, FontStyle.Regular),
|
|
|
- AutoSize = false
|
|
|
- };
|
|
|
-
|
|
|
- // 倒计时标签(初始隐藏)
|
|
|
- var countdownLabel = new Label
|
|
|
- {
|
|
|
- Text = "",
|
|
|
- Dock = DockStyle.Top,
|
|
|
- TextAlign = ContentAlignment.MiddleCenter,
|
|
|
- Font = new Font("Microsoft YaHei UI", 9, FontStyle.Italic),
|
|
|
- ForeColor = Color.Gray,
|
|
|
- Height = 30,
|
|
|
- Visible = false
|
|
|
- };
|
|
|
-
|
|
|
- // 按钮面板
|
|
|
- var buttonPanel = new FlowLayoutPanel
|
|
|
- {
|
|
|
- Dock = DockStyle.Fill,
|
|
|
- FlowDirection = FlowDirection.RightToLeft,
|
|
|
- Padding = new Padding(0, 10, 0, 0),
|
|
|
- AutoSize = true
|
|
|
- };
|
|
|
-
|
|
|
- // 否按钮
|
|
|
- var noButton = new Button
|
|
|
- {
|
|
|
- Text = "否",
|
|
|
- DialogResult = DialogResult.No,
|
|
|
- Size = new Size(100, 35),
|
|
|
- Font = new Font("Microsoft YaHei UI", 9.5F),
|
|
|
- BackColor = Color.White,
|
|
|
- FlatStyle = FlatStyle.Flat,
|
|
|
- Cursor = Cursors.Hand
|
|
|
- };
|
|
|
-
|
|
|
- // 是按钮
|
|
|
- var yesButton = new Button
|
|
|
- {
|
|
|
- Text = "是",
|
|
|
- DialogResult = DialogResult.Yes,
|
|
|
- Size = new Size(100, 35),
|
|
|
- Font = new Font("Microsoft YaHei UI", 9.5F, FontStyle.Bold),
|
|
|
- BackColor = Color.FromArgb(220, 235, 252),
|
|
|
- FlatStyle = FlatStyle.Flat,
|
|
|
- Cursor = Cursors.Hand
|
|
|
- };
|
|
|
-
|
|
|
- // 计时器(用于倒计时)
|
|
|
- System.Windows.Forms.Timer timeoutTimer = null;
|
|
|
- int remainingTime = waitTime;
|
|
|
-
|
|
|
- if (waitTime > 0)
|
|
|
- {
|
|
|
- // 显示倒计时标签
|
|
|
- countdownLabel.Visible = true;
|
|
|
- countdownLabel.Text = $"操作将在 {remainingTime} 秒后自动取消";
|
|
|
-
|
|
|
- // 设置按钮初始文本(包含倒计时)
|
|
|
- noButton.Text = $"否 ({remainingTime})";
|
|
|
-
|
|
|
- // 创建并启动计时器
|
|
|
- timeoutTimer = new System.Windows.Forms.Timer { Interval = 1000 };
|
|
|
- timeoutTimer.Tick += (s, e) => {
|
|
|
- remainingTime--;
|
|
|
-
|
|
|
- // 更新倒计时显示
|
|
|
- countdownLabel.Text = $"操作将在 {remainingTime} 秒后自动取消";
|
|
|
- noButton.Text = $"否 ({remainingTime})";
|
|
|
-
|
|
|
- // 倒计时结束
|
|
|
- if (remainingTime <= 0)
|
|
|
- {
|
|
|
- timeoutTimer.Stop();
|
|
|
- prompt.Close();
|
|
|
- onNo?.Invoke();
|
|
|
- }
|
|
|
- };
|
|
|
- timeoutTimer.Start();
|
|
|
-
|
|
|
- // 记录日志
|
|
|
- Log($"配置询问倒计时 {waitTime} 秒,超时则自动选择'否'");
|
|
|
- }
|
|
|
-
|
|
|
- // 是按钮点击事件
|
|
|
- yesButton.Click += (sender, e) => {
|
|
|
- timeoutTimer?.Stop();
|
|
|
- prompt.Close();
|
|
|
- onYes?.Invoke();
|
|
|
- };
|
|
|
-
|
|
|
- // 否按钮点击事件
|
|
|
- noButton.Click += (sender, e) => {
|
|
|
- timeoutTimer?.Stop();
|
|
|
- prompt.Close();
|
|
|
- onNo?.Invoke();
|
|
|
- };
|
|
|
-
|
|
|
- // 处理窗体关闭事件
|
|
|
- prompt.FormClosed += (sender, e) => {
|
|
|
- timeoutTimer?.Stop();
|
|
|
- // 如果窗体关闭时倒计时仍在运行,执行No操作
|
|
|
- if (timeoutTimer != null && timeoutTimer.Enabled)
|
|
|
- {
|
|
|
- onNo?.Invoke();
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- // 添加键盘快捷键
|
|
|
- prompt.KeyPreview = true;
|
|
|
- prompt.KeyDown += (sender, e) => {
|
|
|
- if (e.KeyCode == Keys.Enter)
|
|
|
- {
|
|
|
- yesButton.PerformClick();
|
|
|
- e.Handled = true;
|
|
|
- }
|
|
|
- else if (e.KeyCode == Keys.Escape)
|
|
|
- {
|
|
|
- noButton.PerformClick();
|
|
|
- e.Handled = true;
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- // 组装按钮面板
|
|
|
- buttonPanel.Controls.Add(noButton);
|
|
|
- buttonPanel.Controls.Add(yesButton);
|
|
|
-
|
|
|
- // 添加间距
|
|
|
- buttonPanel.Controls.Add(new Panel { Width = 15 });
|
|
|
-
|
|
|
- // 组装主面板
|
|
|
- mainPanel.Controls.Add(label, 0, 0);
|
|
|
- mainPanel.Controls.Add(countdownLabel, 0, 1);
|
|
|
- mainPanel.Controls.Add(buttonPanel, 0, 2);
|
|
|
-
|
|
|
- prompt.Controls.Add(mainPanel);
|
|
|
-
|
|
|
- // 显示窗口
|
|
|
- prompt.ShowDialog(this);
|
|
|
- }));
|
|
|
- }
|
|
|
-
|
|
|
// ui控件操作
|
|
|
private void ui_show_sd(bool isShow)
|
|
|
{
|
|
@@ -810,28 +724,15 @@ namespace Bird_tool
|
|
|
progressPanel.BringToFront();
|
|
|
}
|
|
|
|
|
|
- private void re_main()
|
|
|
- {
|
|
|
- ui_show_start_panpel();
|
|
|
- progressPanel.ResetPanel();
|
|
|
- }
|
|
|
-
|
|
|
- private void start_query_test()
|
|
|
- {
|
|
|
- Log($"start_query_test");
|
|
|
- // 判断当前的id是
|
|
|
- StartTest(TestType.StartIndex);
|
|
|
- }
|
|
|
-
|
|
|
- private void setpStart(string key, TestType testType)
|
|
|
- {
|
|
|
- StartTest(testType, key);
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
private void config_test()
|
|
|
{
|
|
|
- Log_show("无法创建测试表");
|
|
|
- StopTest(false);
|
|
|
+ StopTest(false, "配置模式");
|
|
|
+ m_test_mode = TestMode.config;
|
|
|
+ ui_show_test_panpel();
|
|
|
+ progressPanel.ResetPanel();
|
|
|
+ progressPanel.Message = "点击开始测试按钮进行设备配置";
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -843,7 +744,7 @@ namespace Bird_tool
|
|
|
if (!_testExecutor.InitTest(steps))
|
|
|
{
|
|
|
Log_show("无法创建测试表");
|
|
|
- StopTest(false);
|
|
|
+ StopTest(false, "无法创建测试表");
|
|
|
return;
|
|
|
}
|
|
|
m_test_mode = TestMode.hw_test;
|
|
@@ -871,28 +772,92 @@ namespace Bird_tool
|
|
|
if (!_testExecutor.InitTest(steps))
|
|
|
{
|
|
|
Log_show("无法创建测试表");
|
|
|
- StopTest(false);
|
|
|
+ StopTest(false, "无法创建测试表");
|
|
|
return;
|
|
|
}
|
|
|
- m_test_mode = TestMode.sd_test;
|
|
|
- ui_show_test_panpel();
|
|
|
- progressPanel.ResetPanel();
|
|
|
+ m_test_mode = TestMode.sd_test;
|
|
|
+ ui_show_test_panpel();
|
|
|
+ progressPanel.ResetPanel();
|
|
|
+
|
|
|
+ var groups = _testExecutor.GetGroupInfos();
|
|
|
+ foreach (var group in groups)
|
|
|
+ {
|
|
|
+ if (group.ShowStep)
|
|
|
+ {
|
|
|
+ progressPanel.AddTestStep(group.RowKey, group.GroupName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ progressPanel.Message = "点击开始测试按钮进行测试";
|
|
|
+
|
|
|
+ Log($"[{DateTime.Now}] 格式化sd卡");
|
|
|
+ }
|
|
|
+ private string ask_query_id()
|
|
|
+ {
|
|
|
+ string deviceId = "";
|
|
|
+ while (true) // 使用循环代替递归
|
|
|
+ {
|
|
|
+ if (!appConfig.enable_excel_load || m_excel_manager == null || !m_excel_manager.IsValid)
|
|
|
+ {
|
|
|
+ Log_show("excel组件加载异常, 请检查excel配置文件");
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ using (var idDialog = new IdInputDialog("请输入uuid"))
|
|
|
+ {
|
|
|
+ if (idDialog.ShowDialog() == DialogResult.OK)
|
|
|
+ {
|
|
|
+ deviceId = idDialog.EnteredId;
|
|
|
+ var row = m_excel_manager.GetRowByKey(deviceId);
|
|
|
+ if (row == null)
|
|
|
+ {
|
|
|
+ StopTest(false, "uuid异常, 请重新输入或者检查excel文件");
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (m_excel_manager.IsKeyUsed(deviceId))
|
|
|
+ {
|
|
|
+ // 显示选项并获取用户选择
|
|
|
+ var result = ShowIdUsedOptions(deviceId);
|
|
|
+ if (result == "reenter")
|
|
|
+ {
|
|
|
+ continue; // 继续循环让用户重新输入
|
|
|
+ }
|
|
|
+ else if (result == "reconfigure")
|
|
|
+ {
|
|
|
+ return deviceId; // 返回ID进行重新配置
|
|
|
+ }
|
|
|
+ else if (result == "cancel")
|
|
|
+ {
|
|
|
+ StopTest(false, "未输入设备uuid");
|
|
|
+ return ""; // 返回ID进行重新配置
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return deviceId; // ID可用,返回
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ StopTest(false, "未输入设备uuid");
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- var groups = _testExecutor.GetGroupInfos();
|
|
|
- foreach (var group in groups)
|
|
|
+ private async void StartTest(TestType testType, string groupId = null)
|
|
|
+ {
|
|
|
+ //
|
|
|
+ if (m_test_mode == TestMode.config)
|
|
|
{
|
|
|
- if (group.ShowStep)
|
|
|
+ if (!initConfigTest())
|
|
|
{
|
|
|
- progressPanel.AddTestStep(group.RowKey, group.GroupName);
|
|
|
+ Log("涂鸦uuid输入错误!!", LogLevel.error);
|
|
|
+ //Log_show("无法初始化涂鸦相关命令");
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
- progressPanel.Message = "点击开始测试按钮进行测试";
|
|
|
-
|
|
|
- Log($"[{DateTime.Now}] 格式化sd卡");
|
|
|
- }
|
|
|
-
|
|
|
- private void StartTest(TestType testType, string groupId = null)
|
|
|
- {
|
|
|
if (!_testExecutor.isInit)
|
|
|
{
|
|
|
Log_show("测试引擎未初始化!");
|
|
@@ -908,21 +873,31 @@ namespace Bird_tool
|
|
|
progressPanel.AddTestStep(group.RowKey, group.GroupName);
|
|
|
}
|
|
|
}
|
|
|
- progressPanel.StartTimer();
|
|
|
+
|
|
|
// 初始化测试状态
|
|
|
progressPanel.ProgressValue = 0;
|
|
|
progressPanel.CurrentTest = "初始化测试环境";
|
|
|
progressPanel.Message = "准备开始硬件测试...";
|
|
|
+ await Task.Delay(500);
|
|
|
+ progressPanel.StartTimer();
|
|
|
progressPanel.startTest();
|
|
|
+
|
|
|
bool start_flag = false;
|
|
|
bool makeResult = false;
|
|
|
+ string csv_path = "";
|
|
|
if (m_test_mode == TestMode.hw_test)
|
|
|
{
|
|
|
makeResult = true;
|
|
|
+ csv_path = hw_test_csv_path;
|
|
|
+ }
|
|
|
+ if (m_test_mode == TestMode.config)
|
|
|
+ {
|
|
|
+ makeResult = true;
|
|
|
+ csv_path = config_csv_path;
|
|
|
}
|
|
|
if (string.IsNullOrEmpty(groupId))
|
|
|
{
|
|
|
- start_flag = _testExecutor.StartTest(makeResult);
|
|
|
+ start_flag = _testExecutor.StartTest(makeResult, csv_path);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -936,19 +911,26 @@ namespace Bird_tool
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- start_flag = _testExecutor.StartTest(makeResult);
|
|
|
+ StopTest(false, "无法找到对应的分组列表, 请重试");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!start_flag)
|
|
|
{
|
|
|
Log("启动测试失败, 等待重新执行中", LogLevel.error);
|
|
|
- StopTest(false);
|
|
|
+ StopTest(false, "无法启动测试");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- private void StopTest(bool isQuery = true)
|
|
|
+ private void StopTest(bool isQuery = true, string message = "停止异常中止")
|
|
|
{
|
|
|
+
|
|
|
+ if(!_testExecutor.isStart)
|
|
|
+ {
|
|
|
+ Log($"停止测试:{message} 但是测试未开始");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Log($"开始执行停止测试, 原因:{message}");
|
|
|
// 停止测试
|
|
|
if (isQuery && _testExecutor.isStart)
|
|
|
{
|
|
@@ -961,21 +943,19 @@ namespace Bird_tool
|
|
|
progressPanel.ShowTestResult(false, "测试已取消", LoadCancelledImage());
|
|
|
|
|
|
// 添加日志
|
|
|
- logBuilder.AppendLine($"[{DateTime.Now}] 测试已取消");
|
|
|
+ Log($"[{DateTime.Now}] 测试已取消");
|
|
|
_testExecutor.StopTestAsync();
|
|
|
progressPanel.Message = "用户手动停止测试";
|
|
|
Log($"[{DateTime.Now}] 测试中止");
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
progressPanel.ShowTestResult(false, "测试已取消", LoadCancelledImage());
|
|
|
|
|
|
// 添加日志
|
|
|
- logBuilder.AppendLine($"[{DateTime.Now}] 测试已取消");
|
|
|
- _testExecutor.StopTestAsync();
|
|
|
- progressPanel.Message = "停止异常中止";
|
|
|
+ //_testExecutor.StopTestAsync();
|
|
|
+ progressPanel.Message = message;
|
|
|
Log($"[{DateTime.Now}] 测试中止");
|
|
|
}
|
|
|
|
|
@@ -984,7 +964,6 @@ namespace Bird_tool
|
|
|
private void TestFailedhandle(TestStepConfig step, TestContext context)
|
|
|
{
|
|
|
string str = $"------ 测试失败-------";
|
|
|
- _testExecutor.StopTestAsync();
|
|
|
result_success = false;
|
|
|
result_msg = str;
|
|
|
Log(str);
|
|
@@ -994,7 +973,24 @@ namespace Bird_tool
|
|
|
private void TestSuccesshandle(TestContext context)
|
|
|
{
|
|
|
string str = $"------ 测试完成, 请更换设备-------";
|
|
|
- _testExecutor.StopTestAsync();
|
|
|
+ if (m_test_mode == TestMode.config)
|
|
|
+ {
|
|
|
+ // 获取之前测试使用的uuid
|
|
|
+ if (!string.IsNullOrEmpty(m_config_uuid))
|
|
|
+ {
|
|
|
+ string mac = context.Variables.TryGetValue("mac", out mac) ? mac : null;
|
|
|
+ string uuid = context.Variables.TryGetValue("uuid", out uuid) ? uuid : null;
|
|
|
+ m_excel_manager.MarkKeyAsUsed(m_config_uuid, "测试工具", mac);
|
|
|
+ m_config_uuid = "";
|
|
|
+ m_excel_manager.SaveProgress();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Log($"测试完成, 但是未获取到正确的uuid. 联系管理员", LogLevel.error);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //_testExecutor.StopTestAsync();
|
|
|
result_success = true;
|
|
|
result_msg = str;
|
|
|
Log(str);
|
|
@@ -1014,9 +1010,6 @@ namespace Bird_tool
|
|
|
|
|
|
return new List<TestStepConfig>
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
// 按钮长按功能测试
|
|
|
///**
|
|
|
new TestStepConfig
|
|
@@ -1024,7 +1017,7 @@ namespace Bird_tool
|
|
|
GroupId = "btn_long",
|
|
|
GroupName = "按钮测试",
|
|
|
Name = "长按测试1",
|
|
|
- Tips = "请长按电源按钮 6秒后再次长按 第一次",
|
|
|
+ Tips = "请长按电源按钮5秒后松开, 没成功在按一次按钮 等6秒后再次长按",
|
|
|
Command = "\r\n",
|
|
|
SuccessPattern = "sys off",
|
|
|
Timeout = 20000,
|
|
@@ -1035,7 +1028,7 @@ namespace Bird_tool
|
|
|
{
|
|
|
GroupId = "btn_long",
|
|
|
Name = "开机测试1",
|
|
|
- Tips = "点击电源按钮 2秒后再次点击 第一次",
|
|
|
+ Tips = "灯灭后按下电源按钮后松开 2秒后再次按下后松开",
|
|
|
Command = "\r\n",
|
|
|
SuccessPattern = "OS start",
|
|
|
Timeout = 20000,
|
|
@@ -1126,24 +1119,12 @@ namespace Bird_tool
|
|
|
DelayAfter = 100,
|
|
|
MaxRetries = 3,
|
|
|
},
|
|
|
- new TestStepConfig
|
|
|
- {
|
|
|
- GroupId = "pir_test",
|
|
|
- Name = "等待红外录像完成 1",
|
|
|
- Tips = "等待红外任务结束 第一次",
|
|
|
- Command = "\r\n",
|
|
|
- SuccessPattern = "CAM: Close",
|
|
|
- Timeout = 30000,
|
|
|
- DelayAfter = 10,
|
|
|
- MaxRetries = 3,
|
|
|
- },
|
|
|
-
|
|
|
new TestStepConfig
|
|
|
{
|
|
|
GroupId = "pir_test",
|
|
|
GroupName = "红外触发测试",
|
|
|
- Name = "红外触发2",
|
|
|
- Tips = "请将手移动至红外传感器上 第二次",
|
|
|
+ Name = "红外触发1",
|
|
|
+ Tips = "请将手移动至红外传感器上 第一次",
|
|
|
Command = "\r\n",
|
|
|
SuccessPattern = "cmd:17",
|
|
|
Timeout = 30000,
|
|
@@ -1272,8 +1253,9 @@ namespace Bird_tool
|
|
|
DelayBefore = 1000,
|
|
|
MaxJump = 5,
|
|
|
},
|
|
|
-
|
|
|
|
|
|
+ // 设备基础参数配置
|
|
|
+
|
|
|
// 音频测试
|
|
|
///**
|
|
|
new TestStepConfig
|
|
@@ -1361,8 +1343,6 @@ namespace Bird_tool
|
|
|
Tips = "补光灯测试中",
|
|
|
Command = "AT+SEND=1,AT+FACTORY=4\\,\"echo 0 > /sys/class/gpio/gpio107/value\"\r\n",
|
|
|
SuccessText = "+FACTORY: 4",
|
|
|
- RequiresUserPrompt = true,
|
|
|
- PromptQuestion = "LED补光灯是否熄灭?",
|
|
|
Timeout = 5000,
|
|
|
DelayBefore = 200,
|
|
|
MaxRetries = 3,
|
|
@@ -1386,8 +1366,6 @@ namespace Bird_tool
|
|
|
Name = "关闭红外灯",
|
|
|
Command = "AT+SEND=1,AT+FACTORY=4\\,\"echo 0 > /sys/class/gpio/gpio108/value\"\r\n",
|
|
|
SuccessText = "+FACTORY: 4",
|
|
|
- RequiresUserPrompt = true,
|
|
|
- PromptQuestion = "红外补光灯是否熄灭?",
|
|
|
Timeout = 5000,
|
|
|
DelayBefore = 200,
|
|
|
MaxRetries = 3,
|
|
@@ -1487,6 +1465,147 @@ namespace Bird_tool
|
|
|
},
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
+ private bool initConfigTest()
|
|
|
+ {
|
|
|
+ string uuid = ask_query_id();
|
|
|
+ if (string.IsNullOrEmpty(uuid))
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Log($"用户输入id: {uuid}");
|
|
|
+ var (names, values) = m_excel_manager.GetVariableListByKey(uuid);
|
|
|
+ m_config_uuid = uuid;
|
|
|
+ List<TestStepConfig> ret_steps = new List<TestStepConfig>();
|
|
|
+ // 构建配置文件
|
|
|
+ ret_steps.Add(new TestStepConfig
|
|
|
+ {
|
|
|
+ Name = "获取MAC地址",
|
|
|
+ Tips = "提取设备MAC地址",
|
|
|
+ IsDeviceInfoItem = true,
|
|
|
+ InfoDisplayName = "设备mac地址",
|
|
|
+ Command = "AT+MAC?\r\n",
|
|
|
+ SuccessPattern = "MAC:",
|
|
|
+ FailurePattern = "ERROR|FAIL",
|
|
|
+ ExtractPattern = @"MAC:([0-9A-Fa-f]{2}(?::[0-9A-Fa-f]{2}){5})",
|
|
|
+ VariableNames = { "mac" },
|
|
|
+ PrivateCammand = true,
|
|
|
+ Timeout = 3000,
|
|
|
+ DelayBefore = 300,
|
|
|
+ Validator = (response, ctx) =>
|
|
|
+ {
|
|
|
+ // 示例:检查MAC地址格式
|
|
|
+ var mac = ctx.Variables["mac"];
|
|
|
+ Log($"设备mac地址{mac}", LogLevel.info);
|
|
|
+ return !IsValidMac(mac);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ ret_steps.Add(new TestStepConfig
|
|
|
+ {
|
|
|
+ GroupId = "tuya_config",
|
|
|
+ GroupName = "配置涂鸦sdk",
|
|
|
+ ShowStep = false,
|
|
|
+ IsDeviceInfoItem = true,
|
|
|
+ InfoDisplayName = "涂鸦uuid",
|
|
|
+ Name = "配置涂鸦id",
|
|
|
+ Tips = "配置涂鸦参数中",
|
|
|
+ Action = ActionMode.SetVal,
|
|
|
+ VariableNames = names,
|
|
|
+ VariableValues = values,
|
|
|
+ });
|
|
|
+ ret_steps.Add(new TestStepConfig
|
|
|
+ {
|
|
|
+ GroupId = "tuya_config",
|
|
|
+ Name = "涂鸦id配置",
|
|
|
+ Key = "config_id",
|
|
|
+ Tips = "配置涂鸦sdk账户中",
|
|
|
+ Command = "AT+SCFG={\"target\":\"tuya\"\\,\"data\":{\"pid\":\"9kifakenvwsj1a9v\"\\,\"uuid\":\"{{uuid}}\"\\,\"authkey\":\"{{authkey}}\"\\,\"state\":\"0\"\r\n}}",
|
|
|
+ SuccessPattern = "<=OK cmd:24",
|
|
|
+ Timeout = 6000,
|
|
|
+ DelayBefore = 1000,
|
|
|
+ });
|
|
|
+ ret_steps.Add(new TestStepConfig
|
|
|
+ {
|
|
|
+ GroupId = "tuya_config",
|
|
|
+ Name = "涂鸦基础配置",
|
|
|
+ Tips = "配置涂鸦sdk基础信息",
|
|
|
+ Command = "AT+SCFG={\"target\":\"tuya\"\\,\"data\":{\"storage\":\"/data/\"\\,\"media_path\":\"/tmp/media/\"\\,\"sd_path\":\"/tmp/sdcard/\"\\,\"upgrade_file\":\"/tmp/upgrade.file\"\\,\"app_version\":\"1.2.3\"}}\r\n",
|
|
|
+ SuccessPattern = "<=OK cmd:24",
|
|
|
+ Timeout = 6000,
|
|
|
+ DelayBefore = 1000,
|
|
|
+ });
|
|
|
+ // 查询配置
|
|
|
+ ret_steps.Add(new TestStepConfig
|
|
|
+ {
|
|
|
+ GroupId = "tuya_config",
|
|
|
+ Name = "涂鸦id查询",
|
|
|
+ Tips = "检查是否配置涂鸦uuid成功",
|
|
|
+ Command = "AT+SEND=1,AT+FACTORY=4\\,\"cat /data/tuya_device_cfg.json | grep uuid | awk -F[:\\,] '{for(i=1;i<=NF;i++){if($i~/uuid/){print $(i+1)}}}'\"\r\n",
|
|
|
+ SuccessText = "\"{{uuid}}",
|
|
|
+ RetryFromKey = "config_id",
|
|
|
+ Timeout = 6000,
|
|
|
+ DelayBefore = 1000,
|
|
|
+ MaxJump = 5,
|
|
|
+ });
|
|
|
+ ret_steps.Add(new TestStepConfig
|
|
|
+ {
|
|
|
+ GroupId = "tuya_config",
|
|
|
+ Name = "涂鸦id查询",
|
|
|
+ Tips = "检查是否配置涂鸦sdk成功",
|
|
|
+ Command = "AT+SEND=1,AT+FACTORY=4\\,\"cat /data/tuya_device_cfg.json | grep storage | awk -F[:\\,] '{for(i=1;i<=NF;i++){if($i~/storage/){print $(i+1)}}}'\"\r\n",
|
|
|
+ SuccessText = "\"/data",
|
|
|
+ RetryFromKey = "config_id",
|
|
|
+ Timeout = 6000,
|
|
|
+ DelayBefore = 1000,
|
|
|
+ MaxJump = 5,
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ // 配置梵悦测试信息
|
|
|
+ ret_steps.Add(new TestStepConfig
|
|
|
+ {
|
|
|
+ GroupId = "device_config",
|
|
|
+ GroupName = "设备参数配置",
|
|
|
+ Name = "配置视频水印",
|
|
|
+ Tips = "配置视频水印...",
|
|
|
+ Command = "AT+SEND=1, AT+CAMISP=6\\,0\\,0\r\n",
|
|
|
+ SuccessPattern = "<=OK cmd:20",
|
|
|
+ Timeout = 6000,
|
|
|
+ DelayBefore = 1000,
|
|
|
+ MaxRetries = 2,
|
|
|
+ });
|
|
|
+ ret_steps.Add(new TestStepConfig
|
|
|
+ {
|
|
|
+ GroupId = "device_config",
|
|
|
+ Name = "配置图片水印",
|
|
|
+ Tips = "配置图片水印...",
|
|
|
+ Command = "AT+SEND=1, AT+CAMISP=5\\,0\\,0\r\n",
|
|
|
+ SuccessPattern = "<=OK cmd:20",
|
|
|
+ Timeout = 6000,
|
|
|
+ DelayBefore = 1000,
|
|
|
+ MaxRetries = 2,
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ if (!_testExecutor.InitTest(ret_steps))
|
|
|
+ {
|
|
|
+ Log_show("无法创建测试表");
|
|
|
+ StopTest(false, "生成配置命令失败" );
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ var groups = _testExecutor.GetGroupInfos();
|
|
|
+ foreach (var group in groups)
|
|
|
+ {
|
|
|
+ if (group.ShowStep)
|
|
|
+ {
|
|
|
+ progressPanel.AddTestStep(group.RowKey, group.GroupName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
private bool IsValidMac(string mac)
|
|
|
{
|
|
|
// 实现MAC地址验证逻辑
|
|
@@ -1745,6 +1864,188 @@ namespace Bird_tool
|
|
|
|
|
|
|
|
|
|
|
|
+ private void PromptUser(string question, Action onYes, Action onNo, int waitTime = -1)
|
|
|
+ {
|
|
|
+ this.Invoke((Action)(() =>
|
|
|
+ {
|
|
|
+ // 创建自定义提示窗口
|
|
|
+ var prompt = new Form
|
|
|
+ {
|
|
|
+ Width = 450,
|
|
|
+ Height = 250,
|
|
|
+ FormBorderStyle = FormBorderStyle.FixedDialog,
|
|
|
+ Text = "操作确认",
|
|
|
+ StartPosition = FormStartPosition.CenterParent,
|
|
|
+ Font = new Font("Microsoft YaHei UI", 10),
|
|
|
+ Icon = this.Icon,
|
|
|
+ MinimizeBox = false,
|
|
|
+ MaximizeBox = false
|
|
|
+ };
|
|
|
+
|
|
|
+ // 主面板 - 使用表格布局实现更好的响应式设计
|
|
|
+ var mainPanel = new TableLayoutPanel
|
|
|
+ {
|
|
|
+ Dock = DockStyle.Fill,
|
|
|
+ ColumnCount = 1,
|
|
|
+ RowCount = 3,
|
|
|
+ Padding = new Padding(15),
|
|
|
+ RowStyles = {
|
|
|
+ new RowStyle(SizeType.Percent, 120F),
|
|
|
+ new RowStyle(SizeType.AutoSize),
|
|
|
+ new RowStyle(SizeType.AutoSize)
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 问题标签
|
|
|
+ var label = new Label
|
|
|
+ {
|
|
|
+ Text = question,
|
|
|
+ Dock = DockStyle.Fill,
|
|
|
+ TextAlign = ContentAlignment.MiddleCenter,
|
|
|
+ Font = new Font("Microsoft YaHei UI", 20, FontStyle.Regular),
|
|
|
+ AutoSize = false
|
|
|
+ };
|
|
|
+
|
|
|
+ // 倒计时标签(初始隐藏)
|
|
|
+ var countdownLabel = new Label
|
|
|
+ {
|
|
|
+ Text = "",
|
|
|
+ Dock = DockStyle.Top,
|
|
|
+ TextAlign = ContentAlignment.MiddleCenter,
|
|
|
+ Font = new Font("Microsoft YaHei UI", 9, FontStyle.Italic),
|
|
|
+ ForeColor = Color.Gray,
|
|
|
+ Height = 30,
|
|
|
+ Visible = false
|
|
|
+ };
|
|
|
+
|
|
|
+ // 按钮面板
|
|
|
+ var buttonPanel = new FlowLayoutPanel
|
|
|
+ {
|
|
|
+ Dock = DockStyle.Fill,
|
|
|
+ FlowDirection = FlowDirection.RightToLeft,
|
|
|
+ Padding = new Padding(0, 10, 0, 0),
|
|
|
+ AutoSize = true
|
|
|
+ };
|
|
|
+
|
|
|
+ // 否按钮
|
|
|
+ var noButton = new Button
|
|
|
+ {
|
|
|
+ Text = "否",
|
|
|
+ DialogResult = DialogResult.No,
|
|
|
+ Size = new Size(100, 35),
|
|
|
+ Font = new Font("Microsoft YaHei UI", 9.5F),
|
|
|
+ BackColor = Color.White,
|
|
|
+ FlatStyle = FlatStyle.Flat,
|
|
|
+ Cursor = Cursors.Hand
|
|
|
+ };
|
|
|
+
|
|
|
+ // 是按钮
|
|
|
+ var yesButton = new Button
|
|
|
+ {
|
|
|
+ Text = "是",
|
|
|
+ DialogResult = DialogResult.Yes,
|
|
|
+ Size = new Size(100, 35),
|
|
|
+ Font = new Font("Microsoft YaHei UI", 9.5F, FontStyle.Bold),
|
|
|
+ BackColor = Color.FromArgb(220, 235, 252),
|
|
|
+ FlatStyle = FlatStyle.Flat,
|
|
|
+ Cursor = Cursors.Hand
|
|
|
+ };
|
|
|
+
|
|
|
+ // 计时器(用于倒计时)
|
|
|
+ System.Windows.Forms.Timer timeoutTimer = null;
|
|
|
+ int remainingTime = waitTime;
|
|
|
+
|
|
|
+ if (waitTime > 0)
|
|
|
+ {
|
|
|
+ // 显示倒计时标签
|
|
|
+ countdownLabel.Visible = true;
|
|
|
+ countdownLabel.Text = $"操作将在 {remainingTime} 秒后自动取消";
|
|
|
+
|
|
|
+ // 设置按钮初始文本(包含倒计时)
|
|
|
+ noButton.Text = $"否 ({remainingTime})";
|
|
|
+
|
|
|
+ // 创建并启动计时器
|
|
|
+ timeoutTimer = new System.Windows.Forms.Timer { Interval = 1000 };
|
|
|
+ timeoutTimer.Tick += (s, e) => {
|
|
|
+ remainingTime--;
|
|
|
+
|
|
|
+ // 更新倒计时显示
|
|
|
+ countdownLabel.Text = $"操作将在 {remainingTime} 秒后自动取消";
|
|
|
+ noButton.Text = $"否 ({remainingTime})";
|
|
|
+
|
|
|
+ // 倒计时结束
|
|
|
+ if (remainingTime <= 0)
|
|
|
+ {
|
|
|
+ timeoutTimer.Stop();
|
|
|
+ prompt.Close();
|
|
|
+ onNo?.Invoke();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ timeoutTimer.Start();
|
|
|
+
|
|
|
+ // 记录日志
|
|
|
+ Log($"配置询问倒计时 {waitTime} 秒,超时则自动选择'否'");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 是按钮点击事件
|
|
|
+ yesButton.Click += (sender, e) => {
|
|
|
+ timeoutTimer?.Stop();
|
|
|
+ prompt.Close();
|
|
|
+ onYes?.Invoke();
|
|
|
+ };
|
|
|
+
|
|
|
+ // 否按钮点击事件
|
|
|
+ noButton.Click += (sender, e) => {
|
|
|
+ timeoutTimer?.Stop();
|
|
|
+ prompt.Close();
|
|
|
+ onNo?.Invoke();
|
|
|
+ };
|
|
|
+
|
|
|
+ // 处理窗体关闭事件
|
|
|
+ prompt.FormClosed += (sender, e) => {
|
|
|
+ timeoutTimer?.Stop();
|
|
|
+ // 如果窗体关闭时倒计时仍在运行,执行No操作
|
|
|
+ if (timeoutTimer != null && timeoutTimer.Enabled)
|
|
|
+ {
|
|
|
+ onNo?.Invoke();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 添加键盘快捷键
|
|
|
+ prompt.KeyPreview = true;
|
|
|
+ prompt.KeyDown += (sender, e) => {
|
|
|
+ if (e.KeyCode == Keys.Enter)
|
|
|
+ {
|
|
|
+ yesButton.PerformClick();
|
|
|
+ e.Handled = true;
|
|
|
+ }
|
|
|
+ else if (e.KeyCode == Keys.Escape)
|
|
|
+ {
|
|
|
+ noButton.PerformClick();
|
|
|
+ e.Handled = true;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 组装按钮面板
|
|
|
+ buttonPanel.Controls.Add(noButton);
|
|
|
+ buttonPanel.Controls.Add(yesButton);
|
|
|
+
|
|
|
+ // 添加间距
|
|
|
+ buttonPanel.Controls.Add(new Panel { Width = 15 });
|
|
|
+
|
|
|
+ // 组装主面板
|
|
|
+ mainPanel.Controls.Add(label, 0, 0);
|
|
|
+ mainPanel.Controls.Add(countdownLabel, 0, 1);
|
|
|
+ mainPanel.Controls.Add(buttonPanel, 0, 2);
|
|
|
+
|
|
|
+ prompt.Controls.Add(mainPanel);
|
|
|
+
|
|
|
+ // 显示窗口
|
|
|
+ prompt.ShowDialog(this);
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|