From 6d0b54541c1ea90b6a48ef9912605786a60f379d Mon Sep 17 00:00:00 2001 From: frog24 Date: Mon, 20 May 2024 04:55:24 +0400 Subject: [PATCH] =?UTF-8?q?=D0=AD=D1=82=D0=BE=20=D0=BD=D0=B5=20=D0=BA?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8B=D0=BB=D1=8C,=20=D1=8D=D1=82=D0=BE=20?= =?UTF-8?q?=D1=83=D0=B6=D0=B5=20=D1=80=D0=B5=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE?= =?UTF-8?q?=20=D0=B8=D0=BD=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=BD=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BB=D1=8F=D1=81=D0=BA=D0=B0.=20=D0=95=D1=81?= =?UTF-8?q?=D0=BB=D0=B8=20=D1=8D=D1=82=D0=BE=20=D1=84=D0=B8=D0=BA=D1=81=20?= =?UTF-8?q?=D1=81=D0=BB=D0=BE=D0=BC=D0=B0=D0=BB=20=D0=BC=D0=BD=D0=B5=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=83=20=D1=81=20=D0=BF=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B3=D1=80=D0=B5=D1=81=D0=BE=D0=BC,=20=D1=8F=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B2=D0=B5=D1=88=D1=83=D1=81=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DepartmentStaffDatabase/Models.cs | 1 + .../MongoImplements.cs | 22 ++++++++++++++++++- .../FormEmployee_Courses.cs | 13 +++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/DepartmentStaffView/DepartmentStaffDatabase/Models.cs b/DepartmentStaffView/DepartmentStaffDatabase/Models.cs index 4704774..a765d2c 100644 --- a/DepartmentStaffView/DepartmentStaffDatabase/Models.cs +++ b/DepartmentStaffView/DepartmentStaffDatabase/Models.cs @@ -53,6 +53,7 @@ namespace DepartmentStaffDatabase } public class Employee_Course { + public int? Id { get; set; } [BsonRepresentation(BsonType.Int32)] public int EmployeeId { get; set; } [BsonRepresentation(BsonType.Int32)] diff --git a/DepartmentStaffView/DepartmentStaffDatabase/MongoImplements.cs b/DepartmentStaffView/DepartmentStaffDatabase/MongoImplements.cs index 864ab5e..ba45499 100644 --- a/DepartmentStaffView/DepartmentStaffDatabase/MongoImplements.cs +++ b/DepartmentStaffView/DepartmentStaffDatabase/MongoImplements.cs @@ -235,6 +235,12 @@ namespace DepartmentStaffDatabase public override void CreateEmployee_Course(Employee_Course employee_course) { + var maxId = 0; + if (GetEmployee_Courses().Count > 0) + { + maxId = _employee_CourseCollection.AsQueryable().Max(crs => crs.Id).Value; + } + employee_course.Id = maxId + 1; _employee_CourseCollection.InsertOne(employee_course); } public override void DeleteEmployee_Course(int empId, int courseId) @@ -247,7 +253,21 @@ namespace DepartmentStaffDatabase } public override List GetEmployee_Courses() { - return _employee_CourseCollection.Find(_ => true).ToList(); + var employee_CourseList = _employee_CourseCollection.Find(_ => true).ToList(); + + var resultList = new List(); + + foreach (var employee_Course in employee_CourseList) + { + resultList.Add(new Employee_Course + { + Id = employee_Course.Id, + EmployeeId = employee_Course.EmployeeId, + CourseId = employee_Course.CourseId + }); + } + + return resultList; } public override void DeleteEmployee_Courses() { diff --git a/DepartmentStaffView/DepartmentStaffView/FormEmployee_Courses.cs b/DepartmentStaffView/DepartmentStaffView/FormEmployee_Courses.cs index d95cc36..ae18888 100644 --- a/DepartmentStaffView/DepartmentStaffView/FormEmployee_Courses.cs +++ b/DepartmentStaffView/DepartmentStaffView/FormEmployee_Courses.cs @@ -24,7 +24,20 @@ namespace DepartmentStaffView { try { + if (dataGridView1.ColumnCount == 0) + { + dataGridView1.Columns.Add("EmployeeId", "EmployeeId"); + dataGridView1.Columns.Add("CourseId", "CourseId"); + } var list = db.GetEmployee_Courses(); + if (list != null) + { + dataGridView1.Rows.Clear(); + foreach (var el in list) + { + dataGridView1.Rows.Add(el.EmployeeId, el.CourseId); + } + } } catch (Exception ex) {