-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
141 lines (129 loc) · 4.84 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using ProcessQslAdif.adif;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ProcessQslAdif
{
public partial class MainForm : Form
{
Dictionary<DateTime, string> adiUser1 = new Dictionary<DateTime,string>();
Dictionary<DateTime, string> adiUser2 = new Dictionary<DateTime,string>();
string fileName = null;
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
// Load file with activity periods
var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string cfglocation = System.IO.Path.Combine(dir, "dates.csv");
System.IO.StreamReader file = new System.IO.StreamReader(cfglocation);
string line;
CultureInfo provider = CultureInfo.InvariantCulture;
while ((line = file.ReadLine()) != null)
{
line.Trim();
if (line.StartsWith("#")) {
continue;
}
var splitted = line.Split(';');
var timestamp = DateTime.ParseExact(splitted[0] + splitted[1], "yyyyMMddHHmmss", provider);
adiUser1.Add(timestamp, splitted[2].Trim());
adiUser2.Add(timestamp, splitted[3].Trim());
}
file.Close();
new QsoEntry().loadFromString("");
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = @"ADIF log files (*.adi, *.adif)|*.adi;*.adif";
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
if (result == DialogResult.OK) // Test result.
{
fileName = openFileDialog1.FileName;
var fnLen = fileName.Length;
if (fnLen < 30)
{
textBox1.Text = fileName;
}
else
{
textBox1.Text = "..." +fileName.Substring(fnLen - 28, 28);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
if (fileName == null)
{
MessageBox.Show("Select ADIF file");
return;
}
var log = new AdifLog();
log.loadFromFile(fileName);
CultureInfo provider = CultureInfo.InvariantCulture;
foreach (var q in log.qsos) {
// get q datetime
var timestamp = DateTime.ParseExact(q.fields["QSO_DATE"] + q.fields["TIME_ON"], "yyyyMMddHHmmss", provider);
var tsKey = adiUser1.Keys.Where(n => n < timestamp).Max();
q.fields["APP_LOGGER32_USER_1"] = adiUser1[tsKey];
q.fields["APP_LOGGER32_USER_2"] = adiUser2[tsKey];
// process freq
var band = q.fields["BAND"];
switch (band)
{
case "160M":
q.fields["FREQ"] = "1.8";
break;
case "80M":
q.fields["FREQ"] = "3.5";
break;
case "40M":
q.fields["FREQ"] = "7.0";
break;
case "30M":
q.fields["FREQ"] = "10.1";
break;
case "20M":
q.fields["FREQ"] = "14.0";
break;
case "17M":
q.fields["FREQ"] = "18.1";
break;
case "15M":
q.fields["FREQ"] = "21.0";
break;
case "12M":
q.fields["FREQ"] = "24.9";
break;
case "10M":
q.fields["FREQ"] = "28.0";
break;
case "6M":
q.fields["FREQ"] = "50.0";
break;
case "2M":
q.fields["FREQ"] = "144";
break;
case "70CM":
q.fields["FREQ"] = "432";
break;
}
}
var ext = Path.GetExtension(fileName);
var pathWithoutExtension = fileName.Remove(fileName.Length - ext.Length);
log.saveToFile(pathWithoutExtension + "-proc" + ext);
MessageBox.Show("ADIF processing complete");
}
}
}