-
Notifications
You must be signed in to change notification settings - Fork 0
/
LOG export.cs
1022 lines (918 loc) · 42.6 KB
/
LOG export.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//=================================================================
// LOG Export
//=================================================================
// Copyright (C) 2012-2015 S56A YT7PWR
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//=================================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Collections;
using System.Runtime.InteropServices;
namespace CWExpert
{
public partial class LOG_export : Form
{
#region Enum
enum LOGMode
{
BARTG_RTTY_Contest = 0,
RSGB_IOTA_Contest,
NA_Sprint,
ARRL_DX_SSB,
CQ_VHF_Contest,
ARRL_SS_CW
}
#endregion
#region DLL imports
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern int SetWindowPos(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
#endregion
#region variable
public CWExpert MainForm;
LOGStnSettings SettingsForm;
public string MyCALL = "";
public string MyName = "";
public string MyQTH = "";
public string MyLOC = "";
public string MyInfo = "";
public string MyZone = "";
public string ContestName = "";
public string MyClub = "";
public string Operators1 = "";
public string Operators2 = "";
public string MyAddr1 = "";
public string MyAddr2 = "";
public string MyCity = "";
public string MyCountry = "";
public string MyPhone = "";
public string Remarks = "";
public string Antenna = "";
public string TXequ = "";
public string RXequ = "";
public string Category = "";
public string TXPower = "";
const double PI = 3.141592653589;
#endregion
#region Structures
struct location
{
public double longit;
public double latit;
};
struct polar
{
public double distance;
public double direction;
};
#endregion
#region constructor/destructor
public LOG_export(CWExpert form)
{
this.AutoScaleMode = AutoScaleMode.Inherit;
InitializeComponent();
float dpi = this.CreateGraphics().DpiX;
float ratio = dpi / 96.0f;
string font_name = this.Font.Name;
float size = 8.25f / ratio;
System.Drawing.Font new_font = new System.Drawing.Font(font_name, size);
this.Font = new_font;
comboLOGformat.SelectedIndex = 0;
MainForm = form;
GetOptions();
SetWindowPos(this.Handle.ToInt32(), -1, this.Left, this.Top,
this.Width, this.Height, 0); // on top others
SettingsForm = new LOGStnSettings(this);
}
private void LOGExport_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
SaveOptions();
}
catch (Exception ex)
{
MessageBox.Show("Error in LOGExport closing!\n" + ex.ToString());
}
}
#endregion
#region export function
private void btnLOGExport_Click(object sender, EventArgs e)
{
try
{
int first = (int)udFirst.Value;
int last = (int)udLast.Value;
string date = "";
string time = "";
string text = "";
string call = "";
string nr = "";
string my_nr = "";
string freq = "";
string rst = "";
string snt = "";
string day = "";
string month = "";
string name = "";
string qth = "";
string loc = "";
string distance = "";
string zone = "";
string band = "";
string info = "";
string mode = "";
string my_call = MyCALL.PadRight(10, ' ');
string my_name = MyName.PadRight(10, ' ');
string my_qth = MyQTH.PadRight(10, ' ');
DataRow[] rows = DB.log_ds.Tables["LOG"].Select("", "No");
DateTime date_time;
CultureInfo provider = CultureInfo.CurrentCulture;
if (last < first)
{
MessageBox.Show("Wrong settings! \n Last must be greater than first.", "Error!");
return;
}
switch (comboLOGformat.Text)
{
case "Cabrillo ARI DX":
string hour = "";
string minute = "";
text += "START-OF-LOG: 3.0 \n";
text += "CONTEST: " + ContestName + "\n";
text += "CALLSIGN: " + MyCALL + "\n";
text += "CATEGORY: " + "\n";
text += "CATEGORY-ASSISTED: " + "\n";
text += "CATEGORY-OVERLAY: " + "\n";
text += "CLAIMED-SCORE: " + "\n";
text += "CATEGORY-TRANSMITTER: " + "\n";
text += "CLUB: " + MyClub + "\n";
text += "CLAIMED-SCORE: " + "\n";
text += "OPERATORS: " + MyCALL + " " + Operators1 + " " + Operators2 + "\n";
text += "NAME: " + MyName + "\n";
text += "ADDRESS: " + MyAddr1 + "\n";
text += "SOAPBOX: " + Remarks + "\n";
text += "CREATED-BY:" + MainForm.programVersion + "\n";
rtbLOGPreview.AppendText(text);
for (int i = first - 1; i < last; i++)
{
date = rows[i]["Date"].ToString();
DateTime.TryParse(date, provider, DateTimeStyles.AssumeLocal, out date_time);
day = date_time.Day.ToString();
day = day.PadLeft(2, '0');
month = date_time.Month.ToString();
month = month.PadLeft(2, '0');
date = date_time.Year + "-" + month + "-" + day;
time = rows[i]["Time"].ToString();
DateTime.TryParse(time, provider, DateTimeStyles.AssumeLocal, out date_time);
hour = date_time.Hour.ToString();
hour = hour.PadLeft(2, '0');
minute = date_time.Minute.ToString();
minute = minute.PadLeft(2, '0');
time = hour + minute;
call = rows[i]["CALL"].ToString();
call = call.ToUpper();
call = call.PadRight(13, ' ');
nr = rows[i]["NR"].ToString();
nr = nr.PadRight(6, ' ');
nr = nr.Remove(3);
my_nr = rows[i]["MyNR"].ToString();
my_nr = my_nr.PadRight(6, ' ');
my_nr = my_nr.Remove(3);
freq = rows[i]["Freq"].ToString();
freq = freq.PadLeft(5, ' ');
freq = freq.Remove(5);
freq = freq.Replace(".", "");
freq = freq.PadLeft(5, ' ');
rst = rows[i]["RST"].ToString();
rst = rst.PadRight(3, ' ');
snt = rows[i]["SNT"].ToString();
snt = snt.PadRight(3, ' ');
qth = rows[i]["QTH"].ToString();
mode = rows[i]["Mode"].ToString();
mode = mode.Replace("RTTY", "RY");
mode = mode.Replace("SSB", "PH");
if (qth == "")
qth = "DX";
text = "QSO: " + freq + " " + mode + " " +
date + " " + time + " " +
my_call.PadRight(13, ' ') + " " + snt + " " +
my_nr + " " + call + " " +
rst + " " + nr + "\n";
rtbLOGPreview.AppendText(text);
}
text = "END-OF-LOG:\n";
rtbLOGPreview.AppendText(text);
break;
case "Cabrillo CQ-WW-RTTY":
hour = "";
minute = "";
text += "START-OF-LOG: 3.0 \n";
text += "CONTEST: " + ContestName + "\n";
text += "CALLSIGN: " + MyCALL + "\n";
text += "CATEGORY-OPERATOR: " + Category + "\n";
text += "CATEGORY-BAND: " + "\n";
text += "CATEGORY-POWER: " + TXPower + "\n";
text += "CATEGORY-MODE: " + "\n";
text += "CATEGORY-ASSISTED: " + "\n";
text += "CATEGORY-TRANSMITTER: " + "\n";
text += "CLUB=" + MyClub + "\n";
text += "CLAIMED-SCORE: " + "\n";
text += "OPERATORS: " + MyCALL + " " + Operators1 + " " + Operators2 + "\n";
text += "NAME: "+ MyName + "\n";
text += "ADDRESS: " + MyAddr1 + "\n";
text += "ADDRESS: " + MyAddr2 + "\n";
text += "ADDRESS-CITY: " + MyCity + "\n";
text += "ADDRESS: " + MyCountry + "\n";
text += "CREATED-BY:" + MainForm.programVersion + "\n";
rtbLOGPreview.AppendText(text);
for (int i = first - 1; i < last; i++)
{
date = rows[i]["Date"].ToString();
DateTime.TryParse(date, provider, DateTimeStyles.AssumeLocal, out date_time);
day = date_time.Day.ToString();
day = day.PadLeft(2, '0');
month = date_time.Month.ToString();
month = month.PadLeft(2, '0');
date = date_time.Year + "-" + month + "-" + day;
time = rows[i]["Time"].ToString();
DateTime.TryParse(time, provider, DateTimeStyles.AssumeLocal, out date_time);
hour = date_time.Hour.ToString();
hour = hour.PadLeft(2, '0');
minute = date_time.Minute.ToString();
minute = minute.PadLeft(2, '0');
time = hour + minute;
call = rows[i]["CALL"].ToString();
call = call.ToUpper();
call = call.PadRight(13, ' ');
nr = rows[i]["NR"].ToString();
nr = nr.PadLeft(2, '0');
my_nr = rows[i]["MyNR"].ToString();
my_nr = my_nr.PadLeft(2, '0');
freq = rows[i]["Freq"].ToString();
freq = freq.PadLeft(6, ' ');
freq = freq.Remove(5);
freq = freq.Replace(".", "");
freq = freq.PadLeft(5, ' ');
rst = rows[i]["RST"].ToString();
rst = rst.PadRight(3, ' ');
snt = rows[i]["SNT"].ToString();
snt = snt.PadRight(3, ' ');
qth = rows[i]["QTH"].ToString();
if (qth == "")
qth = "DX";
mode = "RY";
text = "QSO: " + freq + " " + mode + " " +
date + " " + time + " " +
my_call.PadRight(13, ' ') + " " + snt + " " +
MyZone + " " + call + " " +
rst + " " + nr + " " + qth + " " + "\n";
rtbLOGPreview.AppendText(text);
}
text = "END-OF-LOG:\n";
rtbLOGPreview.AppendText(text);
break;
case "ADIF":
double tmp_freq = 0.0;
text = "data exported from CWExpert LOG Book, conforming to ADIF standard specification version 2.2.7<eoh>\n";
text += "<CONTEST_ID:" + ContestName.Length.ToString() + ">" + ContestName + "\n";
text += "<OPERATOR:" + MyCALL.Length.ToString() + ">" + MyCALL + "\n";
text += "<MY_NAME:" + MyName.Length.ToString() + ">" + MyName + "\n";
text += "<MY_GRIDSQUARE:" + MyLOC.Length.ToString() + ">" + MyLOC + "\n";
text += "<MY_CQ_ZONE:" + MyZone.Length.ToString() + ">" + MyZone + "\n";
text += "<MY_COUNTRY:" + MyCountry.Length.ToString() + ">" + MyCountry + "\n";
text += "<MY_CITY:" + MyCity.Length.ToString() + ">" + MyCity + "\n";
text += "<MY_STREET:" + (MyAddr1.Length + MyAddr2.Length).ToString() + ">" + MyAddr1 +
" " + MyAddr2 + "\n";
text += "<MY_RIG:" + TXequ.Length.ToString() + ">" + TXequ + "\n";
text += "<MY_SIG_INFO:" + Remarks.Length.ToString() + ">" + Remarks + "\n";
rtbLOGPreview.AppendText(text);
for (int i = first - 1; i < last; i++)
{
date = rows[i]["Date"].ToString();
DateTime.TryParse(date, provider, DateTimeStyles.AssumeLocal, out date_time);
day = date_time.Day.ToString();
day = day.PadLeft(2, '0');
month = date_time.Month.ToString();
month = month.PadLeft(2, '0');
date = date_time.Year + month + day;
time = rows[i]["Time"].ToString();
DateTime.TryParse(time, provider, DateTimeStyles.AssumeLocal, out date_time);
hour = date_time.Hour.ToString();
hour = hour.PadLeft(2, '0');
minute = date_time.Minute.ToString();
minute = minute.PadLeft(2, '0');
time = hour + minute;
call = rows[i]["CALL"].ToString();
call = call.ToUpper();
nr = rows[i]["NR"].ToString();
my_nr = rows[i]["MyNR"].ToString();
mode = rows[i]["Mode"].ToString();
rst = rows[i]["RST"].ToString();
snt = rows[i]["SNT"].ToString();
band = rows[i]["Band"].ToString();
info = rows[i]["Info"].ToString();
name = rows[i]["Name"].ToString();
freq = rows[i]["Freq"].ToString();
tmp_freq = double.Parse(freq, CultureInfo.InvariantCulture) / 1e3;
freq = tmp_freq.ToString();
freq = freq.Replace(',', '.');
text = "<call:" + call.Length.ToString() + ">" + call +
"<band:" + band.Length.ToString() + ">" + band +
"<freq:" + freq.Length.ToString() + ">" + freq +
"<mode:" + mode.Length.ToString() + ">" + mode +
"<qso_date:" + date.Length.ToString() + ">" + date +
"<time_on:" + time.Length.ToString() + ">" + time +
"<rst_rcvd:" + rst.Length.ToString() + ">" + rst +
"<rst_sent:" + snt.Length.ToString() + ">" + snt +
"<stx:" + my_nr.Length.ToString() + ">" + my_nr +
"<srx:" + nr.Length.ToString() + ">" + nr +
"<name:" + name.Length.ToString() + ">" + name +
"<sig_info:" + info.Length.ToString() + ">" + info + "<eor>" + "\n";
rtbLOGPreview.AppendText(text);
}
break;
case "BARTG RTTY Contest":
text = "BARTG RTTY Contest\n";
rtbLOGPreview.AppendText(text);
for (int i = first - 1; i < last; i++)
{
date = rows[i]["Date"].ToString();
DateTime.TryParse(date, provider, DateTimeStyles.AssumeLocal, out date_time);
day = date_time.Day.ToString();
day = day.PadLeft(2, '0');
month = date_time.Month.ToString();
month = month.PadLeft(2, '0');
date = date_time.Year + "-" + month + "-" + day;
time = rows[i]["Time"].ToString();
DateTime.TryParse(time, provider, DateTimeStyles.AssumeLocal, out date_time);
hour = date_time.Hour.ToString();
hour = hour.PadLeft(2, '0');
minute = date_time.Minute.ToString();
minute = minute.PadLeft(2, '0');
time = hour + minute;
call = rows[i]["CALL"].ToString();
call = call.ToUpper();
call = call.PadRight(10);
nr = rows[i]["NR"].ToString();
nr = nr.PadLeft(4, '0');
my_nr = rows[i]["MyNR"].ToString();
my_nr = my_nr.PadLeft(4, '0');
freq = rows[i]["Freq"].ToString();
freq = freq.PadLeft(6, ' ');
freq = freq.Remove(5);
rst = rows[i]["RST"].ToString();
rst = rst.PadRight(3, ' ');
snt = rows[i]["SNT"].ToString();
snt = snt.PadRight(3, ' ');
text = freq + " RY " +
date + " " + time + " " +
my_call + " " + snt + " " +
my_nr + " " + call + " " +
rst + " " + nr + " " + "\n";
rtbLOGPreview.AppendText(text);
}
break;
case "NA Sprint":
my_qth = my_qth.Remove(3);
my_name = my_name.Remove(9);
text = "NA Sprint\n";
rtbLOGPreview.AppendText(text);
for (int i = first - 1; i < last; i++)
{
date = rows[i]["Date"].ToString();
DateTime.TryParse(date, provider, DateTimeStyles.AssumeLocal, out date_time);
day = date_time.Day.ToString();
day = day.PadLeft(2, '0');
month = date_time.Month.ToString();
month = month.PadLeft(2, '0');
date = date_time.Year + "-" + month + "-" + day;
time = rows[i]["Time"].ToString();
DateTime.TryParse(time, provider, DateTimeStyles.AssumeLocal, out date_time);
hour = date_time.Hour.ToString();
hour = hour.PadLeft(2, '0');
minute = date_time.Minute.ToString();
minute = minute.PadLeft(2, '0');
time = hour + minute;
call = rows[i]["CALL"].ToString();
call = call.ToUpper();
call = call.PadRight(10);
nr = rows[i]["NR"].ToString();
nr = nr.PadLeft(4, '0');
my_nr = rows[i]["MyNR"].ToString();
my_nr = my_nr.PadLeft(4, '0');
freq = rows[i]["Freq"].ToString();
freq = freq.PadLeft(6, ' ');
freq = freq.Remove(5);
name = rows[i]["Name"].ToString();
name = name.Trim();
name = name.PadRight(10, ' ');
name = name.Remove(9);
qth = rows[i]["QTH"].ToString();
qth = qth.Trim();
qth = qth.PadRight(4, ' ');
qth = qth.Remove(3);
text = freq + " CW " + date + " " + time + " " +
my_call + " " + my_nr + " " + my_name + " " + my_qth + " " +
call + " " + nr + " " + name + " " + qth + "\r\n";
rtbLOGPreview.AppendText(text);
}
break;
case "TXT":
int no = 1;
for (int i = first - 1; i < last; i++)
{
date = rows[i]["Date"].ToString();
time = rows[i]["Time"].ToString();
call = rows[i]["CALL"].ToString();
nr = rows[i]["NR"].ToString();
my_nr = rows[i]["MyNR"].ToString();
freq = rows[i]["Freq"].ToString();
name = rows[i]["Name"].ToString();
name = name.Replace("\n", " ");
name = name.Replace("\r", " ");
qth = rows[i]["QTH"].ToString();
qth = qth.Replace("\n", " ");
qth = qth.Replace("\r", " ");
rst = rows[i]["RST"].ToString();
snt = rows[i]["SNT"].ToString();
zone = rows[i]["Zone"].ToString();
band = rows[i]["Band"].ToString();
info = rows[i]["Info"].ToString();
info = info.Replace("\n", " ");
info = info.Replace("\r", " ");
mode = rows[i]["Mode"].ToString();
text = no.ToString() + " " + date + " " + time + " " +
call + " " + rst + " " + snt + " " + my_nr + " " +
nr + " " + nr + " " + zone + " " + freq + " " + band +
" " + mode + " " + loc + " " + qth + " " + name + " " + info + "\r\n";
no++;
rtbLOGPreview.AppendText(text);
}
break;
case "EDI":
string last_date = "";
int qrb = 0;
int qrb_final = 0;
string loc_list = "";
string tmp_loc = "";
int loc_count = 0;
int odx_qrb = 0;
string tmp_output = "";
string odx = "";
string mode_code = "";
for (int i = first - 1; i < last; i++)
{
date = rows[i]["Date"].ToString();
DateTime.TryParse(date, provider, DateTimeStyles.AssumeLocal, out date_time);
day = date_time.Day.ToString();
day = day.PadLeft(2, '0');
month = date_time.Month.ToString();
month = month.PadLeft(2, '0');
date = date_time.Year + month + day;
time = rows[i]["Time"].ToString();
DateTime.TryParse(time, provider, DateTimeStyles.AssumeLocal, out date_time);
hour = date_time.Hour.ToString();
hour = hour.PadLeft(2, '0');
minute = date_time.Minute.ToString();
minute = minute.PadLeft(2, '0');
time = hour + minute;
call = rows[i]["CALL"].ToString();
call = call.ToUpper();
nr = rows[i]["NR"].ToString();
nr = nr.PadLeft(4, '0');
my_nr = rows[i]["MyNR"].ToString();
my_nr = my_nr.PadLeft(4, '0');
snt = rows[i]["SNT"].ToString();
rst = rows[i]["RST"].ToString();
loc = rows[i]["LOC"].ToString();
loc = loc.ToUpper();
loc = loc.PadRight(6);
tmp_loc = loc.Remove(3, 2);
mode = rows[i]["Mode"].ToString();
switch (mode)
{
case "SSB":
mode_code = "1";
break;
case "CW":
mode_code = "2";
break;
case "AM":
mode_code = "5";
break;
case "RTTY":
mode_code = "7";
break;
case "SSTV":
mode_code = "8";
break;
case "ATV":
mode_code = "9";
break;
default:
mode_code = "0";
break;
}
if (!loc_list.Contains(tmp_loc))
{
loc_list += tmp_loc + " ";
loc_count++;
}
qrb = CalculateQRB(MyLOC, loc);
if (qrb >= 0)
{
qrb_final += qrb;
distance = qrb.ToString();
if (qrb > odx_qrb)
{
odx_qrb = qrb;
odx = call + ";" + loc + ";" + odx_qrb.ToString();
}
}
else
distance = "";
tmp_output += date + ";" + time + ";" +
call + ";" + mode_code + ";" + snt + ";" + my_nr +
";" + rst + ";" + nr + ";;" + loc + ";" + distance + ";;;" +
"\r\n";
}
date = rows[first - 1]["Date"].ToString();
DateTime.TryParse(date, provider, DateTimeStyles.AssumeLocal, out date_time);
day = date_time.Day.ToString();
day = day.PadLeft(2, '0');
month = date_time.Month.ToString();
month = month.PadLeft(2, '0');
date = date_time.Year + month + day;
last_date = rows[last - 1]["Date"].ToString();
DateTime.TryParse(last_date, provider, DateTimeStyles.AssumeLocal, out date_time);
day = date_time.Day.ToString();
day = day.PadLeft(2, '0');
month = date_time.Month.ToString();
month = month.PadLeft(2, '0');
last_date = date_time.Year + month + day;
text += ContestName + "\n";
text += "[REG1TEST;1] \n";
text += "Tname=" + ContestName + "\n"; ;
text += "Tdate:" + date + ";" + last_date + "\n";
text += "PCall=" + MyCALL + "\n";
text += "PWWLo=" + MyLOC + "\n";
text += "PExch=\n";
text += "PAdr1=" + MyAddr1 + "\n";
text += "PAdr2=" + MyAddr2 + "\n";
text += "PSect=\n";
text += "PBand=\n";
text += "PClub=" + MyClub + "\n";
text += "RName=" + MyName + "\n";
text += "RCall=\n";
text += "RAdr1=" + MyAddr1 + "\n";
text += "RAdr2=" + MyAddr2 + "\n";
text += "RPoco\n";
text += "RCity=" + MyCity + "\n";
text += "RCoun=" + MyCountry + "\n";
text += "RPhon\n";
text += "RHBBS=\n";
text += "MOpe1=" + Operators1 + "\n";
text += "MOpe2=" + Operators2 + "\n";
text += "STXEq=" + TXequ + "\n";
text += "SPowe=" + TXPower + "\n";
text += "SRXEq=" + RXequ + "\n";
text += "SAnte=\n";
text += "SAntH=" + Antenna + "\n";
text += "CQSOs=" + (last - first + 1).ToString() + "\n";
text += "CQSOP=" + qrb_final.ToString() + "\n";
text += "CWWLs=" + loc_count.ToString() + "\n";
text += "CWWLB=\n";
text += "CExcs=\n";
text += "CExcB=\n";
text += "CDXCs=\n";
text += "CDXCB=\n";
text += "CToSc=\n";
text += "CODXC=" + odx + "\n";
text += "[Remarks]" + "\n" + Remarks + "\n";
text += "[QSOrecords;" + (last - first + 1).ToString() + "]\n";
text += tmp_output;
rtbLOGPreview.AppendText(text);
break;
case "Custom":
break;
}
}
catch (Exception ex)
{
Debug.Write(ex.ToString());
rtbLOGPreview.AppendText(ex.ToString());
}
}
#endregion
#region Save File
private void btnLOGSaveAs_Click(object sender, EventArgs e)
{
try
{
string path = Application.StartupPath;
saveFileDialog1.InitialDirectory = path;
saveFileDialog1.ShowDialog();
}
catch (Exception ex)
{
Debug.Write(ex.ToString());
MessageBox.Show("Failed to export LogBook! \n" + ex.ToString(), "Error!");
}
}
private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
try
{
FileStream file;
ASCIIEncoding buff = new ASCIIEncoding();
byte[] buffer = new byte[rtbLOGPreview.Text.Length];
buff.GetBytes(rtbLOGPreview.Text.ToString(), 0, rtbLOGPreview.Text.ToCharArray().Length, buffer, 0);
file = File.Create(saveFileDialog1.FileName);
file.Write(buffer, 0, buffer.Length);
file.Flush();
file.Close();
file.Dispose();
}
catch (Exception ex)
{
Debug.Write(ex.ToString());
}
}
#endregion
#region misc function
private void btnCancel_Click(object sender, EventArgs e)
{
try
{
this.Close();
}
catch (Exception ex)
{
Debug.Write(ex.ToString());
}
}
private void btnPreviewClear_Click(object sender, EventArgs e)
{
try
{
rtbLOGPreview.Clear();
}
catch (Exception ex)
{
Debug.Write(ex.ToString());
}
}
private int CalculateQRB(string my_loc, string loc)
{
try
{
char[] from = new char[6];
char[] to = new char[6];
location from_spheric = new location();
location to_spheric = new location();
polar bearing = new polar();
int from_status, to_status;
int distance = 0;
my_loc = my_loc.ToLower();
loc = loc.ToLower();
from = my_loc.ToCharArray();
to = loc.ToCharArray();
from_status = convert(from, ref from_spheric);
to_status = convert(to, ref to_spheric);
if ((from_status + to_status) > 0)
return (0);
transform(ref from_spheric, ref to_spheric, ref bearing);
distance = (int)bearing.distance;
return distance;
}
catch (Exception ex)
{
Debug.Write(ex.ToString());
return 0;
}
}
private int convert(char[] loc, ref location place)
{
try
{
int i;
for (i = 0; i <= 1; i++)
{
if ((loc[i] < 'a') || (loc[i] > 'r')) return 1;
}
for (i = 2; i <= 3; i++)
{
if ((loc[i] < '0') || (loc[i] > '9')) return 1;
}
for (i = 4; i <= 5; i++)
{
if ((loc[i] < 'a') || (loc[i] > 'x')) return 1;
}
(place.latit) = 10 * (loc[1] - 'a') - 90;
(place.latit) += loc[3] - '0';
(place.latit) += (loc[5] - 'a') / 24.0 + 1 / 48.0;
(place.latit) *= PI / 180.0;
(place.longit) = 20 * (loc[0] - 'a') - 180;
(place.longit) += 2 * (loc[2] - '0');
(place.longit) += (loc[4] - 'a') / 12.0 + 1 / 24.0;
(place.longit) *= PI / 180.0;
return 0;
}
catch (Exception ex)
{
Debug.Write(ex.ToString());
return 1;
}
}
private int transform(ref location from, ref location to, ref polar dd)
{
try
{
double temp, nominator, radius;
radius = 180.0 / PI * (111.1451 + 0.56 * Math.Sin(to.latit + from.latit - PI / 2.0));
(dd.distance) = radius * Math.Acos(temp = (Math.Sin(to.latit) * Math.Sin(from.latit)
+ Math.Cos(to.latit) * Math.Cos(from.latit) * Math.Cos(to.longit - from.longit)));
if (dd.distance < 0.1)
{
dd.direction = 0;
}
else
{
(dd.direction) = Math.Atan((Math.Cos(from.latit)
* Math.Sin(to.longit - from.longit)
* Math.Cos(to.latit))
/ (nominator = (Math.Sin(to.latit) - temp * Math.Sin(from.latit))));
if (nominator < 0) dd.direction -= PI;
if (dd.direction < 0) dd.direction += 2 * PI;
}
return 0;
}
catch (Exception ex)
{
Debug.Write(ex.ToString());
return 0;
}
}
private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (SettingsForm == null || SettingsForm.IsDisposed)
SettingsForm = new LOGStnSettings(this);
SettingsForm.Show();
}
catch (Exception ex)
{
Debug.Write(ex.ToString());
}
}
#endregion
#region Save/Get options
public void SaveOptions()
{
try
{
ArrayList a = new ArrayList();
a.Add("LOGExport_top/" + this.Top.ToString()); // save form positions
a.Add("LOGExport_left/" + this.Left.ToString());
a.Add("ContestName/" + ContestName);
a.Add("MyClub/" + MyClub);
a.Add("Operators1/" + Operators1);
a.Add("Operators2/" + Operators2);
a.Add("MyAddr1/" + MyAddr1);
a.Add("MyAddr2/" + MyAddr2);
a.Add("MyCity/" + MyCity);
a.Add("MyCountry/" + MyCountry);
a.Add("MyPhone/" + MyPhone);
a.Add("Remarks/" + Remarks);
a.Add("Antenna/" + Antenna);
a.Add("TXEqu/" + TXequ);
a.Add("RXEqu/" + RXequ);
a.Add("Category/" + Category);
a.Add("TXPower/" + TXPower);
DB.SaveVars("LOGExportOptions", ref a); // save the values to the DB
DB.Update();
}
catch (Exception ex)
{
MessageBox.Show("Error in LOG Export SaveOptions function!\n" + ex.ToString());
}
}
public void GetOptions()
{
try
{
ArrayList a = DB.GetVars("LOGExportOptions");
a.Sort();
foreach (string s in a)
{
string[] vals = s.Split('/');
string name = vals[0];
if (vals.Length > 2)
{
for (int i = 2; i < vals.Length; i++)
vals[1] += "/" + vals[i];
}
string val = vals[1];
if (s.StartsWith("LOGexport_top"))
{
int top = Int32.Parse(vals[1]);
this.Top = top;
}
else if (s.StartsWith("LOGExport_left"))
{
int left = Int32.Parse(vals[1]);
this.Left = left;
}
else if (s.StartsWith("ContestName"))
{
ContestName = vals[1];
}
else if (s.StartsWith("MyClub"))
{
MyClub = vals[1];
}
else if (s.StartsWith("Operators1"))
{
Operators1 = vals[1];
}
else if (s.StartsWith("Operators2"))
{
Operators2 = vals[1];
}
else if (s.StartsWith("MyAddr1"))
{
MyAddr1 = vals[1];
}
else if (s.StartsWith("MyAddr2"))
{
MyAddr2 = vals[1];
}
else if (s.StartsWith("MyCity"))
{
MyCity = vals[1];
}
else if (s.StartsWith("MyCountry"))
{
MyCountry = vals[1];
}
else if (s.StartsWith("MyPhone"))
{
MyPhone = vals[1];
}
else if (s.StartsWith("Remarks"))
{
Remarks = vals[1];
}
else if (s.StartsWith("Antenna"))
{
Antenna = vals[1];
}
else if (s.StartsWith("TXEqu"))
{
TXequ = vals[1];
}
else if (s.StartsWith("RXEqu"))