From 90d80a7c9ad5d44c3e2aa9189272677164e67a6f Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Mon, 8 Apr 2024 22:40:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=BB=D0=B8=D0=B7=D0=BA=D0=BE=20=D0=BA?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D0=B5=D0=BD=D0=B8=D1=8E?= =?UTF-8?q?=20(=D0=BD=D0=B0=D0=B4=D0=B5=D1=8E=D1=81=D1=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EditStudentForm.Designer.cs | 119 +++++++++++++++++ .../SchoolSchedule/EditStudentForm.cs | 92 ++++++++++++++ .../SchoolSchedule/EditStudentForm.resx | 120 ++++++++++++++++++ .../SchoolSchedule/LessonForm.Designer.cs | 11 +- SchoolSchedule/SchoolSchedule/LessonForm.cs | 25 +++- SchoolSchedule/SchoolSchedule/LessonForm.resx | 3 + SchoolSchedule/SchoolSchedule/Program.cs | 1 + .../Implements/StudentStorage.cs | 6 +- 8 files changed, 371 insertions(+), 6 deletions(-) create mode 100644 SchoolSchedule/SchoolSchedule/EditStudentForm.Designer.cs create mode 100644 SchoolSchedule/SchoolSchedule/EditStudentForm.cs create mode 100644 SchoolSchedule/SchoolSchedule/EditStudentForm.resx diff --git a/SchoolSchedule/SchoolSchedule/EditStudentForm.Designer.cs b/SchoolSchedule/SchoolSchedule/EditStudentForm.Designer.cs new file mode 100644 index 0000000..8b03005 --- /dev/null +++ b/SchoolSchedule/SchoolSchedule/EditStudentForm.Designer.cs @@ -0,0 +1,119 @@ +namespace SchoolSchedule +{ + partial class EditStudentForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + comboBox1 = new ComboBox(); + textBox1 = new TextBox(); + label1 = new Label(); + label2 = new Label(); + AddButton = new Button(); + CancelButton = new Button(); + SuspendLayout(); + // + // comboBox1 + // + comboBox1.FormattingEnabled = true; + comboBox1.Location = new Point(89, 12); + comboBox1.Name = "comboBox1"; + comboBox1.Size = new Size(79, 23); + comboBox1.TabIndex = 0; + // + // textBox1 + // + textBox1.Location = new Point(89, 41); + textBox1.Name = "textBox1"; + textBox1.Size = new Size(79, 23); + textBox1.TabIndex = 1; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(42, 15); + label1.Name = "label1"; + label1.Size = new Size(41, 15); + label1.TabIndex = 2; + label1.Text = "статус"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(37, 44); + label2.Name = "label2"; + label2.Size = new Size(46, 15); + label2.TabIndex = 3; + label2.Text = "оценка"; + // + // AddButton + // + AddButton.Location = new Point(12, 70); + AddButton.Name = "AddButton"; + AddButton.Size = new Size(75, 23); + AddButton.TabIndex = 4; + AddButton.Text = "Добавить"; + AddButton.UseVisualStyleBackColor = true; + AddButton.Click += AddButton_Click; + // + // CancelButton + // + CancelButton.Location = new Point(93, 70); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(75, 23); + CancelButton.TabIndex = 5; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += CancelButton_Click; + // + // EditStudentForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(174, 98); + Controls.Add(CancelButton); + Controls.Add(AddButton); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(textBox1); + Controls.Add(comboBox1); + Name = "EditStudentForm"; + Text = "EditStudentForm"; + Load += EditStudentForm_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBox1; + private TextBox textBox1; + private Label label1; + private Label label2; + private Button AddButton; + private Button CancelButton; + } +} \ No newline at end of file diff --git a/SchoolSchedule/SchoolSchedule/EditStudentForm.cs b/SchoolSchedule/SchoolSchedule/EditStudentForm.cs new file mode 100644 index 0000000..4a6016a --- /dev/null +++ b/SchoolSchedule/SchoolSchedule/EditStudentForm.cs @@ -0,0 +1,92 @@ +using SchoolScheduleContracts.BindingModels; +using SchoolScheduleContracts.BusinessLogicsContracts; +using SchoolScheduleDataModels.Enums; +using SchoolScheduleDataModels.Models; +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 static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace SchoolSchedule +{ + public partial class EditStudentForm : Form + { + public IStudentModel student { get; set; } = null; + public ILessonModel lesson { get; set; } = null; + IStudentLogic _logic; + public EditStudentForm(IStudentLogic logic) + { + InitializeComponent(); + _logic = logic; + } + + private void EditStudentForm_Load(object sender, EventArgs e) + { + comboBox1.DataSource = Enum.GetValues(typeof(StudentStatus)); + } + public void LoadData() + { + if (student.Attendance[lesson.Id].Item3 != null) + textBox1.Text = student.Attendance[lesson.Id].Item3.ToString(); + } + + private void AddButton_Click(object sender, EventArgs e) + { + if (comboBox1.SelectedValue == null) + { + MessageBox.Show("Выберите классного руководителя", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBox1.Text)) + { + MessageBox.Show("Заполните поле оценка", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + int year = int.Parse(textBox1.Text); + if (!(year >= 2 && year <= 5) && year != 0) + { + throw new Exception("Ошибка при создании."); + } + student.Attendance[lesson.Id] = (student.Attendance[lesson.Id].Item1, (StudentStatus)comboBox1.SelectedValue, (year == 0 ? null : year)); + StudentBindingModel model = new StudentBindingModel + { + Id = student.Id, + GradeId = student.GradeId, + FullName = student.FullName, + Attendance = student.Attendance + }; + var operationResult = _logic.Update(model); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + + } + + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SchoolSchedule/SchoolSchedule/EditStudentForm.resx b/SchoolSchedule/SchoolSchedule/EditStudentForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SchoolSchedule/SchoolSchedule/EditStudentForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SchoolSchedule/SchoolSchedule/LessonForm.Designer.cs b/SchoolSchedule/SchoolSchedule/LessonForm.Designer.cs index bfdb394..216994e 100644 --- a/SchoolSchedule/SchoolSchedule/LessonForm.Designer.cs +++ b/SchoolSchedule/SchoolSchedule/LessonForm.Designer.cs @@ -32,6 +32,7 @@ Name = new DataGridViewTextBoxColumn(); Status = new DataGridViewTextBoxColumn(); Mark = new DataGridViewTextBoxColumn(); + Id = new DataGridViewTextBoxColumn(); ChangeButton = new Button(); CancelButton = new Button(); ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); @@ -40,7 +41,7 @@ // dataGridView1 // dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView1.Columns.AddRange(new DataGridViewColumn[] { Name, Status, Mark }); + dataGridView1.Columns.AddRange(new DataGridViewColumn[] { Name, Status, Mark, Id }); dataGridView1.Location = new Point(12, 12); dataGridView1.Name = "dataGridView1"; dataGridView1.Size = new Size(462, 401); @@ -62,6 +63,12 @@ Mark.HeaderText = "Оценка"; Mark.Name = "Mark"; // + // Id + // + Id.HeaderText = ""; + Id.Name = "Id"; + Id.Visible = false; + // // ChangeButton // ChangeButton.Location = new Point(318, 419); @@ -70,6 +77,7 @@ ChangeButton.TabIndex = 1; ChangeButton.Text = "Изменить"; ChangeButton.UseVisualStyleBackColor = true; + ChangeButton.Click += ChangeButton_Click; // // CancelButton // @@ -101,5 +109,6 @@ private DataGridViewTextBoxColumn Mark; private Button ChangeButton; private Button CancelButton; + private DataGridViewTextBoxColumn Id; } } \ No newline at end of file diff --git a/SchoolSchedule/SchoolSchedule/LessonForm.cs b/SchoolSchedule/SchoolSchedule/LessonForm.cs index e5ee99c..f473bf3 100644 --- a/SchoolSchedule/SchoolSchedule/LessonForm.cs +++ b/SchoolSchedule/SchoolSchedule/LessonForm.cs @@ -29,10 +29,31 @@ namespace SchoolSchedule if (Lesson != null) { var students = _logic.ReadList(new StudentSearchModel { GradeId = Lesson.GradeId }); + dataGridView1.Rows.Clear(); foreach (var student in students) { - dataGridView1.Rows.Clear(); - dataGridView1.Rows.Add(new object[] { student.FullName, student.Attendance[Lesson.Id].Item2, student.Attendance[Lesson.Id].Item3 }); + dataGridView1.Rows.Add(new object[] { student.FullName, student.Attendance[Lesson.Id].Item2, student.Attendance[Lesson.Id].Item3, student.Id }); + } + } + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + + if (dataGridView1.SelectedRows.Count == 1) + { + var tmp = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + var service = +Program.ServiceProvider?.GetService(typeof(EditStudentForm)); + if (service is EditStudentForm form) + { + form.student = _logic.ReadElement(new StudentSearchModel { Id = tmp }); + form.lesson = Lesson; + form.LoadData(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } } } } diff --git a/SchoolSchedule/SchoolSchedule/LessonForm.resx b/SchoolSchedule/SchoolSchedule/LessonForm.resx index f210634..c580d8b 100644 --- a/SchoolSchedule/SchoolSchedule/LessonForm.resx +++ b/SchoolSchedule/SchoolSchedule/LessonForm.resx @@ -126,4 +126,7 @@ True + + True + \ No newline at end of file diff --git a/SchoolSchedule/SchoolSchedule/Program.cs b/SchoolSchedule/SchoolSchedule/Program.cs index 4945513..ed2c6b9 100644 --- a/SchoolSchedule/SchoolSchedule/Program.cs +++ b/SchoolSchedule/SchoolSchedule/Program.cs @@ -48,6 +48,7 @@ namespace SchoolSchedule services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/SchoolSchedule/SchoolScheduleDataBaseImplement/Implements/StudentStorage.cs b/SchoolSchedule/SchoolScheduleDataBaseImplement/Implements/StudentStorage.cs index 4a65d5a..24c05f0 100644 --- a/SchoolSchedule/SchoolScheduleDataBaseImplement/Implements/StudentStorage.cs +++ b/SchoolSchedule/SchoolScheduleDataBaseImplement/Implements/StudentStorage.cs @@ -19,14 +19,14 @@ namespace SchoolScheduleDataBaseImplement.Implements public List GetFullList() { using var context = new SchoolScheduleDataBase(); - return context.Students.Include(x => x.Grade) + return context.Students.Include(x => x.Lessons).Include(x => x.Grade) .Select(x => x.GetViewModel) .ToList(); } public List GetFilteredList(StudentSearchModel model) { using var context = new SchoolScheduleDataBase(); - return context.Students.Include(x => x.Grade) + return context.Students.Include(x => x.Lessons).Include(x => x.Grade) .Where(x => (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.FullName) || x.FullName == model.FullName) && (!model.GradeId.HasValue || x.GradeId == model.GradeId)) .Select(x => x.GetViewModel) @@ -39,7 +39,7 @@ namespace SchoolScheduleDataBaseImplement.Implements return null; } using var context = new SchoolScheduleDataBase(); - return context.Students.Include(x => x.Grade) + return context.Students.Include(x => x.Lessons).Include(x => x.Grade) .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel;