-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExamsForm.cs
163 lines (153 loc) · 7.78 KB
/
ExamsForm.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Entity;
using University.DataModel;
namespace University
{
public partial class ExamsForm : Form
{
UniversityContext db;
protected internal int currentEnrolleeId;
public ExamsForm (int _currentEnrolleeId)
{
InitializeComponent();
currentEnrolleeId = _currentEnrolleeId;
db = new UniversityContext();
db.Disciplines.Load();
}
private void OkBT_Click(object sender, EventArgs e)
{
this.Close();
}
private void добавитьЭкзаменToolStripMenuItem_Click(object sender, EventArgs e)
{
var add = new AddExam();
add.DisciplinesCB.DataSource = db.Disciplines.Local.ToBindingList(); // дисциплины
add.DisciplinesCB.DisplayMember = "Name";
if (add.ShowDialog() == DialogResult.OK)
{
ExamSheet examSheet = new ExamSheet();
examSheet.Examiner = add.ExaminerTB.Text;
examSheet.Comment = add.CommentTB.Text;
examSheet.Score = Convert.ToInt32(add.ScoreNumericUpDown.Value);
examSheet.EnrolleeId = currentEnrolleeId;
examSheet.discipline = (Discipline)add.DisciplinesCB.SelectedItem;
db.ExamSheets.Add(examSheet); // добавление абитуриента
db.SaveChanges();
//ExamsDataGV.DataSource = db.ExamSheets.Where(idenrollee => idenrollee.EnrolleeId == currentEnrolleeId).ToList();
ExamsDataGV.DataSource = new BindingSource
{
DataSource = db.ExamSheets.Where(idenrollee => idenrollee.EnrolleeId == currentEnrolleeId).ToList().Select(b =>
new { b.Id, b.EnrolleeId, b.Examiner, b.discipline.Name, b.Score, b.Comment }
)};
ExamsDataGV.Columns[0].HeaderText = "id";
ExamsDataGV.Columns[1].HeaderText = "id абитуриента";
ExamsDataGV.Columns[2].HeaderText = "Экзаменатор";
ExamsDataGV.Columns[3].HeaderText = "Название дисциплины";
ExamsDataGV.Columns[4].HeaderText = "Количество набранных баллов";
ExamsDataGV.Columns[5].HeaderText = "Комментарий";
ExamsDataGV.Refresh();
}
}
private void изменитьИнформациюToolStripMenuItem_Click(object sender, EventArgs e)
{
if (ExamsDataGV.SelectedRows.Count > 0)
{
foreach (DataGridViewRow i in ExamsDataGV.SelectedRows)
{
try
{
bool converted = Int32.TryParse(ExamsDataGV[0, i.Index].Value.ToString(), out int id);
if (converted == false)
return;
ExamSheet examSheet = db.ExamSheets.Find(id);
var add = new AddExam(examSheet.Examiner, examSheet.Comment, examSheet.Score);
add.DisciplinesCB.DataSource = db.Disciplines.Local.ToBindingList(); // дисциплины
add.DisciplinesCB.DisplayMember = "Name";
if (add.ShowDialog(this) == DialogResult.OK)
{
try
{
examSheet.Examiner = add.ExaminerTB.Text;
examSheet.Comment = add.CommentTB.Text;
examSheet.Score = Convert.ToInt32(add.ScoreNumericUpDown.Value);
examSheet.discipline = (Discipline)add.DisciplinesCB.SelectedItem;
db.SaveChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
add.Close(); // если нажали кнопку отмены
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//dataGridView1.DataSource = new BindingSource { DataSource = list.Select(b => new { b.prop1, p2 = b.prop2.prop1, b.prop2.prop2 }) };
//ExamsDataGV.DataSource = db.ExamSheets.Where(idenrollee => idenrollee.EnrolleeId == currentEnrolleeId).ToList();
ExamsDataGV.DataSource = new BindingSource
{
DataSource = db.ExamSheets.Where(idenrollee => idenrollee.EnrolleeId == currentEnrolleeId).ToList().Select(b =>
new { b.Id, b.EnrolleeId, b.Examiner, b.discipline.Name, b.Score, b.Comment }
)}; // АХТУНГ
ExamsDataGV.Columns[0].HeaderText = "id";
ExamsDataGV.Columns[1].HeaderText = "id абитуриента";
ExamsDataGV.Columns[2].HeaderText = "Экзаменатор";
ExamsDataGV.Columns[3].HeaderText = "Название дисциплины";
ExamsDataGV.Columns[4].HeaderText = "Количество набранных баллов";
ExamsDataGV.Columns[5].HeaderText = "Комментарий";
ExamsDataGV.Refresh();
MessageBox.Show("Информация успешно обновлена!");
}
}
private void удалитьИнформациюToolStripMenuItem_Click(object sender, EventArgs e)
{
if (ExamsDataGV.SelectedRows.Count > 0)
{
try
{
foreach (DataGridViewRow i in ExamsDataGV.SelectedRows)
{
bool converted = Int32.TryParse(ExamsDataGV[0, i.Index].Value.ToString(), out int id);
if (converted == false)
return;
ExamSheet examSheet = db.ExamSheets.Find(id);
db.ExamSheets.Remove(examSheet);
db.SaveChanges();
}
//ExamsDataGV.DataSource = db.ExamSheets.Where(idenrollee => idenrollee.EnrolleeId == currentEnrolleeId).ToList();
ExamsDataGV.DataSource = new BindingSource
{
DataSource = db.ExamSheets.Where(idenrollee => idenrollee.EnrolleeId == currentEnrolleeId).ToList().Select(b =>
new { b.Id, b.EnrolleeId, b.Examiner, b.discipline.Name, b.Score, b.Comment }
)};
ExamsDataGV.Columns[0].HeaderText = "id";
ExamsDataGV.Columns[1].HeaderText = "id абитуриента";
ExamsDataGV.Columns[2].HeaderText = "Экзаменатор";
ExamsDataGV.Columns[3].HeaderText = "Название дисциплины";
ExamsDataGV.Columns[4].HeaderText = "Количество набранных баллов";
ExamsDataGV.Columns[5].HeaderText = "Комментарий";
ExamsDataGV.Refresh();
MessageBox.Show("Удаление прошло успешно!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}