HamBook – Blame information for rev 5
?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. |
||
5 | office | 46 | comboBox1.DataBindings.Add(nameof(comboBox1.Text), _configuration, nameof(_configuration.Port), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
47 | comboBox2.DataBindings.Add(nameof(comboBox2.Text), _configuration, nameof(_configuration.Speed), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
48 | comboBox3.DataBindings.Add(nameof(comboBox3.Text), _configuration, nameof(_configuration.DataBits), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
49 | comboBox4.DataBindings.Add(nameof(comboBox4.Text), _configuration, nameof(_configuration.Parity), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
50 | comboBox5.DataBindings.Add(nameof(comboBox5.Text), _configuration, nameof(_configuration.StopBits), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
1 | office | 51 | |
5 | office | 52 | comboBox7.DataBindings.Add(nameof(comboBox7.Text), _configuration, nameof(_configuration.Radio), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
53 | |||
54 | var bandBindingSource = new BindingSource(); |
||
55 | bandBindingSource.DataSource = _configuration.Definitions.Bands; |
||
56 | comboBox6.DataSource = bandBindingSource; |
||
57 | comboBox6.DisplayMember = nameof(Band.Meters); |
||
58 | |||
59 | textBox1.DataBindings.Add(nameof(textBox1.Text), bandBindingSource, nameof(Band.Min), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
60 | textBox2.DataBindings.Add(nameof(textBox1.Text), bandBindingSource, nameof(Band.Max), true, DataSourceUpdateMode.OnPropertyChanged, string.Empty); |
||
1 | office | 61 | } |
62 | |||
63 | private void button1_Click(object sender, EventArgs e) |
||
64 | { |
||
65 | SaveOnClose = true; |
||
66 | Close(); |
||
67 | } |
||
68 | |||
69 | private void button2_Click(object sender, EventArgs e) |
||
70 | { |
||
71 | SaveOnClose = false; |
||
72 | Close(); |
||
73 | } |
||
5 | office | 74 | |
75 | private void textBox1_TextChanged(object sender, EventArgs e) |
||
76 | { |
||
77 | var textBox = (TextBox)sender; |
||
78 | if(string.IsNullOrEmpty(textBox.Text) || !int.TryParse(textBox.Text, out var frequency)) |
||
79 | { |
||
80 | return; |
||
81 | } |
||
82 | |||
83 | var band = (Band)comboBox6.SelectedValue; |
||
84 | band.Min = frequency; |
||
85 | } |
||
86 | |||
87 | private void textBox2_TextChanged(object sender, EventArgs e) |
||
88 | { |
||
89 | var textBox = (TextBox)sender; |
||
90 | if (string.IsNullOrEmpty(textBox.Text) || !int.TryParse(textBox.Text, out var frequency)) |
||
91 | { |
||
92 | return; |
||
93 | } |
||
94 | |||
95 | var band = (Band)comboBox6.SelectedValue; |
||
96 | band.Max = frequency; |
||
97 | } |
||
1 | office | 98 | } |
99 | } |