-
Notifications
You must be signed in to change notification settings - Fork 2
/
frmCourseNotFound.cs
111 lines (92 loc) · 3.77 KB
/
frmCourseNotFound.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
using System;
using System.Data;
using System.Linq;
using System.Windows.Forms;
namespace h24
{
public partial class frmCourseNotFound : Form
{
klc01 db;
public int course;
public int prv_course;
public frmCourseNotFound(int competitor_id, int readout_id, int previous_course)
{
InitializeComponent();
this.label3.Text = this.competitorDetail(competitor_id) + readout_id.ToString();
this.label4.Text = this.courseDetail(previous_course);
prv_course = previous_course;
}
private string competitorDetail(int competitor_id)
{
db = new klc01();
var oneCompetitor = db.competitors.FirstOrDefault(c => c.comp_id == competitor_id);
return oneCompetitor.bib + " - " + oneCompetitor.comp_name + " Chip: " + oneCompetitor.comp_chip_id;
}
private string courseDetail(int course_id)
{
db = new klc01();
var oneCourse = db.courses.FirstOrDefault(c => c.course_id == course_id);
return oneCourse == null ? "": "Previously selected course: " + oneCourse.course_name ?? "N/A";
}
private void frmCourseNotFound_Load(object sender, EventArgs e)
{
db = new klc01();
dgCourses.DataSource = db.courses.OrderBy(x=>x.course_name).ToList();
DataGridViewRow row = dgCourses.Rows
.Cast<DataGridViewRow>()
.FirstOrDefault(r => Convert.ToInt32(r.Cells["course_id"].Value) == prv_course);
if (row != null)
{
// Select the row
row.Selected = true;
// Optionally, you can scroll to the selected row
dgCourses.FirstDisplayedScrollingRowIndex = row.Index;
}
}
private void dgCourses_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
{
Properties.Settings.Default.dgCourses_course_name = dgCourses.Columns["course_name"].Width;
Properties.Settings.Default.dgCourses_course_length = dgCourses.Columns["course_length"].Width;
Properties.Settings.Default.dgCourses_course_climb = dgCourses.Columns["course_climb"].Width;
Properties.Settings.Default.dgCourses_control_count = dgCourses.Columns["control_count"].Width;
Properties.Settings.Default.Save();
}
private void btnSave_Click(object sender, EventArgs e)
{
int curRow = this.dgCourses.CurrentRow.Index;
course = Convert.ToInt32(this.dgCourses.Rows[curRow].Cells["course_id"].Value);
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
course = 0;
this.Close();
}
private void txSearch_TextChanged(object sender, EventArgs e)
{
if (txSearch.Text.Length > 0)
{
using (var db = new klc01())
{
var query = from c in db.courses
where c.course_name.Contains(txSearch.Text)
select c;
dgCourses.DataSource = //query.ToList();
query.OrderBy(x => x.course_name).ToList();
dgCourses.Refresh();
}
}
}
private void btClear_Click(object sender, EventArgs e)
{
this.txSearch.Text = "";
ActiveControl = this.txSearch;
}
private void dgCourses_DoubleClick(object sender, EventArgs e)
{
int curRow = this.dgCourses.CurrentRow.Index;
course = Convert.ToInt32(this.dgCourses.Rows[curRow].Cells["course_id"].Value);
this.Close();
}
}
}