Близко к завершению (надеюсь)

This commit is contained in:
gg12 darfren 2024-04-08 22:40:44 +04:00
parent e763e1179b
commit 90d80a7c9a
8 changed files with 371 additions and 6 deletions

View File

@ -0,0 +1,119 @@
namespace SchoolSchedule
{
partial class EditStudentForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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();
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -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;
}
}

View File

@ -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();
}
}
}
}

View File

@ -126,4 +126,7 @@
<metadata name="Mark.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Id.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -48,6 +48,7 @@ namespace SchoolSchedule
services.AddTransient<LessonCreateForm>();
services.AddTransient<LessonsForm>();
services.AddTransient<LessonForm>();
services.AddTransient<EditStudentForm>();
}
}
}

View File

@ -19,14 +19,14 @@ namespace SchoolScheduleDataBaseImplement.Implements
public List<StudentViewModel> 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<StudentViewModel> 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;