using System.Windows; using YuncangTrace.LocalService.Services.Scan; namespace YuncangTrace.LocalService; /// /// 「重命名通道」弹窗:只改**名字**(通道号是现场认工位的号,改名不动它)。 /// /// 名字既落在本机通道配置里(并同步服务器),也可以顺手写进设备 `SYS.HostName` /// —— 与添加通道时的处理一致,写失败不影响本机改名。 /// public partial class RenameChannelWindow : Window { public RenameChannelWindow(ScanChannel channel) { InitializeComponent(); var ip = string.IsNullOrWhiteSpace(channel.LastIp) ? "IP 未知" : channel.LastIp; ChannelText.Text = $"通道 {channel.Number} · {channel.Mac} · {ip}"; NameBox.Text = channel.DisplayName; // 设备 IP 未知就写不进去,别给用户一个必然失败的勾选框 WriteDeviceBox.IsEnabled = !string.IsNullOrWhiteSpace(channel.LastIp); WriteDeviceBox.IsChecked = WriteDeviceBox.IsEnabled; Loaded += (_, _) => { NameBox.Focus(); NameBox.SelectAll(); }; } /// 用户填的新名字(确定后有值) public string ChannelName { get; private set; } = string.Empty; /// 是否同时把名字写进设备 public bool WriteToDevice => WriteDeviceBox.IsChecked == true; private void Ok_Click(object sender, RoutedEventArgs e) { var name = (NameBox.Text ?? string.Empty).Trim(); if (name.Length == 0) { MessageBox.Show(this, "通道名不能为空", "重命名通道", MessageBoxButton.OK, MessageBoxImage.Information); return; } ChannelName = name; DialogResult = true; } private void Cancel_Click(object sender, RoutedEventArgs e) => DialogResult = false; }