using JinYuan.Models; using JinYuan.VirtualDataLibrary; 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 LargeSquareOne { public partial class FrmChannelCfg : Form { private ChannelConfig _config; private Channel _currentChannel; public FrmChannelCfg() { InitializeComponent(); LoadData(); } private void LoadData() { _config = CommonMethods.LoadFromJson(CommonMethods.ChannelPath); listBoxChannels.DataSource = _config.Channels; listBoxChannels.DisplayMember = "AllContent"; } // 选中通道时更新右侧详情 private void listBoxChannels_SelectedIndexChanged(object sender, EventArgs e) { _currentChannel = (Channel)listBoxChannels.SelectedItem; if (_currentChannel != null) { numChannelId.Value = _currentChannel.ChannelId; numDefaultValue.Value = _currentChannel.DefaultValue; UpdateGearsList(); } } private void UpdateGearsList() { listBoxGears.DataSource = null; listBoxGears.DataSource = _currentChannel.Gears; } private void UpdateChannelList() { listBoxChannels.DataSource = null; listBoxChannels.DataSource = _config.Channels; listBoxChannels.DisplayMember = "AllContent"; } // 添加档位 private void btnAddGear_Click(object sender, EventArgs e) { var gearName = txtNewGear.Text.Trim(); if (!string.IsNullOrEmpty(gearName)) { _currentChannel.Gears.Add(gearName); txtNewGear.Text = ""; UpdateGearsList(); } } // 删除档位 private void btnRemoveGear_Click(object sender, EventArgs e) { if (listBoxGears.SelectedItem != null) { var gear = listBoxGears.SelectedItem.ToString(); _currentChannel.Gears.Remove(gear); UpdateGearsList(); } } // 保存 private void btnSave_Click(object sender, EventArgs e) { // 更新当前通道数据 if (_currentChannel != null) { _currentChannel.DefaultValue = (int)numDefaultValue.Value; } CommonMethods.SaveToJson(CommonMethods.ChannelPath, _config); MessageBox.Show("保存成功!"); } private void button4_Click(object sender, EventArgs e) { this.Close(); } private void listBoxGears_MouseDoubleClick(object sender, MouseEventArgs e) { int index = listBoxGears.IndexFromPoint(e.Location); if (index != ListBox.NoMatches) { string oldValue = listBoxGears.Items[index].ToString(); FrmInput frm = new FrmInput(oldValue); frm.ShowDialog(); string newValue = frm.CurGear; if (!string.IsNullOrEmpty(newValue)) { var gearIndex = _currentChannel.Gears.IndexOf(oldValue); _currentChannel.Gears[gearIndex] = newValue; // 直接修改 Items UpdateChannelList(); } } } private void numDefaultValue_ValueChanged(object sender, EventArgs e) { _currentChannel.DefaultValue = (int)numDefaultValue.Value; UpdateChannelList(); } private void numDefaultValue_Validating(object sender, CancelEventArgs e) { if ((int)numDefaultValue.Value == 98) { MessageBox.Show("98: 扫码NG(不允许在界面配置)"); e.Cancel = true; return; } } } }