HamBook – Blame information for rev 9
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using Configuration; |
2 | using System; |
||
3 | using System.Collections.Generic; |
||
4 | using System.ComponentModel; |
||
5 | using System.Data; |
||
6 | using System.Drawing; |
||
7 | using System.IO.Ports; |
||
8 | using System.Linq; |
||
9 | using System.Text; |
||
10 | using System.Threading; |
||
11 | using System.Threading.Tasks; |
||
12 | using System.Windows.Forms; |
||
13 | |||
14 | namespace HamBook |
||
15 | { |
||
16 | public partial class SettingsForm : Form |
||
17 | { |
||
18 | public bool SaveOnClose { get; private set; } |
||
19 | |||
20 | private Configuration.Configuration _configuration; |
||
21 | |||
22 | public SettingsForm() |
||
23 | { |
||
24 | InitializeComponent(); |
||
25 | } |
||
26 | public SettingsForm(Configuration.Configuration configuration, CancellationToken cancellationToken) : this() |
||
27 | { |
||
28 | _configuration = configuration; |
||
29 | } |
||
30 | |||
31 | private void SettingsForm_Load(object sender, EventArgs e) |
||
32 | { |
||
33 | var ports = SerialPort.GetPortNames(); |
||
34 | |||
35 | if (ports != null && ports.Length != 0) |
||
36 | { |
||
37 | foreach (var port in ports) |
||
38 | { |
||
39 | comboBox1.Items.Add(port); |
||
40 | } |
||
41 | |||
42 | comboBox1.Text = ports[0]; |
||
43 | } |
||
44 | |||
45 | // Create data bindings. |
||
8 | office | 46 | checkBox1.DataBindings.Add(nameof(checkBox1.Checked), _configuration, nameof(_configuration.LaunchOnBoot), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
47 | |||
5 | office | 48 | comboBox1.DataBindings.Add(nameof(comboBox1.Text), _configuration, nameof(_configuration.Port), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
49 | comboBox2.DataBindings.Add(nameof(comboBox2.Text), _configuration, nameof(_configuration.Speed), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
50 | comboBox3.DataBindings.Add(nameof(comboBox3.Text), _configuration, nameof(_configuration.DataBits), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
51 | comboBox4.DataBindings.Add(nameof(comboBox4.Text), _configuration, nameof(_configuration.Parity), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
52 | comboBox5.DataBindings.Add(nameof(comboBox5.Text), _configuration, nameof(_configuration.StopBits), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
1 | office | 53 | |
5 | office | 54 | comboBox7.DataBindings.Add(nameof(comboBox7.Text), _configuration, nameof(_configuration.Radio), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
7 | office | 55 | comboBox8.DataBindings.Add(nameof(comboBox8.Text), _configuration, nameof(_configuration.Handshake), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
5 | office | 56 | |
57 | var bandBindingSource = new BindingSource(); |
||
58 | bandBindingSource.DataSource = _configuration.Definitions.Bands; |
||
59 | comboBox6.DataSource = bandBindingSource; |
||
60 | comboBox6.DisplayMember = nameof(Band.Meters); |
||
61 | |||
62 | textBox1.DataBindings.Add(nameof(textBox1.Text), bandBindingSource, nameof(Band.Min), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
63 | textBox2.DataBindings.Add(nameof(textBox1.Text), bandBindingSource, nameof(Band.Max), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
7 | office | 64 | |
65 | textBox3.DataBindings.Add(nameof(textBox3.Text), _configuration.SerialPortTimeout, nameof(SerialPortTimeout.Read), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
66 | textBox4.DataBindings.Add(nameof(textBox4.Text), _configuration.SerialPortTimeout, nameof(SerialPortTimeout.Write), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
9 | office | 67 | textBox5.DataBindings.Add(nameof(textBox5.Text), _configuration, nameof(_configuration.ScanDetectPause), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
1 | office | 68 | } |
69 | |||
70 | private void button1_Click(object sender, EventArgs e) |
||
71 | { |
||
72 | SaveOnClose = true; |
||
73 | Close(); |
||
74 | } |
||
75 | |||
76 | private void button2_Click(object sender, EventArgs e) |
||
77 | { |
||
78 | SaveOnClose = false; |
||
79 | Close(); |
||
80 | } |
||
5 | office | 81 | |
82 | private void textBox1_TextChanged(object sender, EventArgs e) |
||
83 | { |
||
84 | var textBox = (TextBox)sender; |
||
85 | if(string.IsNullOrEmpty(textBox.Text) || !int.TryParse(textBox.Text, out var frequency)) |
||
86 | { |
||
87 | return; |
||
88 | } |
||
89 | |||
90 | var band = (Band)comboBox6.SelectedValue; |
||
91 | band.Min = frequency; |
||
92 | } |
||
93 | |||
94 | private void textBox2_TextChanged(object sender, EventArgs e) |
||
95 | { |
||
96 | var textBox = (TextBox)sender; |
||
97 | if (string.IsNullOrEmpty(textBox.Text) || !int.TryParse(textBox.Text, out var frequency)) |
||
98 | { |
||
99 | return; |
||
100 | } |
||
101 | |||
102 | var band = (Band)comboBox6.SelectedValue; |
||
103 | band.Max = frequency; |
||
104 | } |
||
1 | office | 105 | } |
106 | } |