-
Notifications
You must be signed in to change notification settings - Fork 2
/
FrmResults.cs
340 lines (295 loc) · 15 KB
/
FrmResults.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
using CsvHelper;
using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Entity;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
namespace h24
{
public partial class FrmResults : Form
{
public FrmResults()
{
InitializeComponent();
}
private void FrmResults_Load(object sender, EventArgs e)
{
List<results> results = null;
int cat_id = 2;
using (var db = new klc01())
{
results = db.results.Where(a => a.cat_id == cat_id).ToList();
this.reportViewer1.LocalReport.ReportPath = "rpt_results.rdlc";
this.reportViewer1.LocalReport.DataSources.Clear();
ReportDataSource rdc = new ReportDataSource("ds_result", results);
this.reportViewer1.LocalReport.DataSources.Add(rdc);
this.reportViewer1.RefreshReport();
var categories_list = db.categories.Where(a=> a.valid == true)
.OrderBy(t => t.cat_name)
.ToList();
var cat_all = new List<KeyValuePair<string, int>>();
cat_all.Add(new KeyValuePair<string, int>("All", -1));
foreach (var cat in categories_list)
{
cat_all.Add(new KeyValuePair<string, int>(cat.cat_name, cat.cat_id));
}
this.cbCategory.DataSource = cat_all;
this.cbCategory.SelectedIndex = 0;
this.cbCategory.ValueMember = "Key";
this.cbCategory.DisplayMember = "Key";
}
}
private void BtnTeamResults_Click(object sender, EventArgs e)
{
string stringToInsert;
// Define the string to insert
using (var db = new klc01())
{
db.Database.CommandTimeout = 360;
string cat = cbCategory.Text== "All" ? "" : cbCategory.Text;
stringToInsert = db.get_results_json(cat).FirstOrDefault();
}
save_json(stringToInsert);
}
private void BtnCourseResults_Click(object sender, EventArgs e)
{
string stringToInsert;
// Define the string to insert
using (var db = new klc01())
{
db.Database.CommandTimeout = 360;
stringToInsert = db.get_course_results_json("").FirstOrDefault();
}
save_json(stringToInsert);
}
public void save_json(string stringToInsert)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog
{
Title = "Browse Template File - ; html",
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = "html",
Filter = "html files (*.html)|*.html|htm files (*.htm)|*.htm|All files (*.*)|*.*",
FilterIndex = 1,
RestoreDirectory = true,
ReadOnlyChecked = true,
ShowReadOnly = true
};
string templateFilePath = "";
string templateContent = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
templateFilePath = openFileDialog1.FileName;
// Read the HTML template file
templateContent = File.ReadAllText(templateFilePath);
}
string placeholder = "<!-- placeholder -->";
string modifiedContent = templateContent.Replace(placeholder, stringToInsert);
// Write the modified content back to the HTML file
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "HTML Files|*.html;*.htm|All Files|*.*";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
string outputFilePath = saveFileDialog.FileName;
File.WriteAllText(outputFilePath, modifiedContent);
MessageBox.Show("Output saved successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void BtnRefresh_Click(object sender, EventArgs e)
{
List<results> results = null;
int cat_id = 2;
using (var db = new klc01())
{
results = db.results.Where(a => a.cat_id == cat_id).ToList();
this.reportViewer1.LocalReport.ReportPath = "rpt_results.rdlc";
this.reportViewer1.LocalReport.DataSources.Clear();
ReportDataSource rdc = new ReportDataSource("ds_result", results);
this.reportViewer1.LocalReport.DataSources.Add(rdc);
this.reportViewer1.RefreshReport();
}
}
private void btXMLresult_Click(object sender, EventArgs e)
{
// Write the modified content back to the HTML file
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "XML Files|*.xml;*.htm|All Files|*.*";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
string outputFilePath = saveFileDialog.FileName;
string utc_offset = NewCard.get_config_item("utc_offset") == "" ? @"+02:00" : NewCard.get_config_item("utc_offset");
string str_time = NewCard.get_config_item("start_time") == "" ? @"2024-05-11 09:00:00.000" : NewCard.get_config_item("start_time");
DateTime start_time = DateTime.ParseExact(str_time, "yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture);
DateTime end_time = start_time.AddHours(25);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = "\t";
settings.NewLineOnAttributes = true;
//string file_name = "StartList.xml";
using (XmlWriter writer = XmlWriter.Create(outputFilePath, settings))
{
writer.WriteStartElement("ResultList", "http://www.orienteering.org/datastandard/3.0");
writer.WriteAttributeString("xmlns", "", null, "http://www.orienteering.org/datastandard/3.0");
writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString("iofVersion", "3.0");
writer.WriteAttributeString("createTime", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz"));
writer.WriteAttributeString("creator", "h24");
writer.WriteStartElement("Event");
writer.WriteStartElement("Name");
writer.WriteString("h24");
writer.WriteEndElement();
writer.WriteStartElement("StartTime");
writer.WriteStartElement("Date");
writer.WriteString(start_time.ToString("yyyy-MM-dd"));
writer.WriteEndElement();//Date
writer.WriteStartElement("Time");
writer.WriteString(start_time.ToString("HH:mm:ss" + utc_offset));
writer.WriteEndElement();//Time
writer.WriteEndElement();//StartTime
writer.WriteStartElement("EndTime");
writer.WriteStartElement("Date");
writer.WriteString(end_time.ToString("yyyy-MM-dd"));
writer.WriteEndElement();//Date
writer.WriteStartElement("Time");
writer.WriteString(end_time.ToString("HH:mm:ss" + utc_offset));
writer.WriteEndElement();//Time
writer.WriteEndElement();//EndTime
writer.WriteEndElement();//Event
var db = new klc01();
db.Configuration.LazyLoadingEnabled = false;
db.Configuration.ProxyCreationEnabled = false;
List<v_iof_results> AllSlips = db.v_iof_results
/* .OrderBy(s => s.course_id)
.ThenBy(s => s.l_time)
.ThenBy(s => s.position ?? 99)*/
.ToList();
int course_id = 0;
int comp_id = 0;
int position = 0;
int i = 0;
foreach (var oneSlip in AllSlips)
{
Console.WriteLine($"slip ID: {oneSlip.slip_id}");
if (oneSlip.course_id != course_id)
{
if (i != 0)
writer.WriteEndElement();//ClassResult
writer.WriteStartElement("ClassResult");
writer.WriteStartElement("Class");
writer.WriteStartElement("Id");
writer.WriteValue(oneSlip.course_id);
writer.WriteEndElement();//Id
writer.WriteStartElement("Name");
writer.WriteValue(oneSlip.course_name);
writer.WriteEndElement();//Name
writer.WriteEndElement();//Class
writer.WriteStartElement("Course");
writer.WriteStartElement("Length");
writer.WriteValue(oneSlip.course_length);
writer.WriteEndElement();//Length
writer.WriteStartElement("Climb");
writer.WriteValue(oneSlip.course_climb ?? 0);
writer.WriteEndElement();//Climb
writer.WriteEndElement();//Course
}
if (oneSlip.comp_id != comp_id)
{
if (i != 0)
{
writer.WriteEndElement();//Result
writer.WriteEndElement();//PersonResult
}
writer.WriteStartElement("PersonResult");
writer.WriteStartElement("Person");
writer.WriteStartElement("Id");
writer.WriteValue(oneSlip.comp_id);
writer.WriteEndElement();//Id
writer.WriteStartElement("Name");
writer.WriteStartElement("Family");
writer.WriteValue(oneSlip.comp_name);
writer.WriteEndElement();//Family
writer.WriteEndElement();//Name
writer.WriteEndElement();//Person
writer.WriteStartElement("Organisation");
writer.WriteStartElement("Id");
writer.WriteValue(oneSlip.team_id);
writer.WriteEndElement();//Id
writer.WriteStartElement("Name");
writer.WriteValue(oneSlip.team_name);
writer.WriteEndElement();//Name
writer.WriteEndElement();//Organisation
writer.WriteStartElement("Result");
writer.WriteStartElement("BibNumber");
writer.WriteValue(oneSlip.bib);
writer.WriteEndElement();//BibNumber
writer.WriteStartElement("StartTime");
writer.WriteValue(oneSlip.start_dtime);
writer.WriteEndElement();//StartTime
writer.WriteStartElement("FinishTime");
writer.WriteValue(oneSlip.finish_dtime);
writer.WriteEndElement();//FinishTime
writer.WriteStartElement("Time");
writer.WriteValue(oneSlip.l_time);
writer.WriteEndElement();//Time
writer.WriteStartElement("TimeBehind");
writer.WriteValue(oneSlip.t_behind);
writer.WriteEndElement();//TimeBehind
position++;
if(oneSlip.course_id != course_id)
position = 1;
writer.WriteStartElement("Position");
writer.WriteValue(position);
writer.WriteEndElement();//Position
writer.WriteStartElement("Status");
writer.WriteValue(oneSlip.leg_status);
writer.WriteEndElement();//Status
writer.WriteStartElement("Course");
writer.WriteStartElement("Id");
writer.WriteValue(oneSlip.course_id);
writer.WriteEndElement();//Id
writer.WriteStartElement("Name");
writer.WriteValue(oneSlip.course_name);
writer.WriteEndElement();//Name
writer.WriteStartElement("Length");
writer.WriteValue(oneSlip.course_length);
writer.WriteEndElement();//Length
writer.WriteStartElement("Climb");
writer.WriteValue(oneSlip.course_climb ?? 0);
writer.WriteEndElement();//Climb
writer.WriteEndElement();//Course
}
writer.WriteStartElement("SplitTime");
writer.WriteStartElement("ControlCode");
writer.WriteValue(oneSlip.control_code);
writer.WriteEndElement();//ControlCode
writer.WriteStartElement("Time");
writer.WriteValue(oneSlip.split_time);
writer.WriteEndElement();//Time
writer.WriteEndElement();//SplitTime
course_id = oneSlip.course_id;
comp_id = oneSlip.comp_id;
i++;
//
}
writer.WriteEndElement();//Result
writer.WriteEndElement();//PersonResult
// writer.WriteEndElement();//ClassResult
writer.Flush();
MessageBox.Show("Export copmlete");
}
}
}
}
}