Добавление связи "многие ко многим" и разделения

This commit is contained in:
artur-kalimullin 2024-11-04 22:01:55 +04:00
parent a902a2d7bb
commit 91af80d9ea
13 changed files with 169 additions and 104 deletions

View File

@ -5,9 +5,13 @@ namespace ProjectSchedule.Entities;
public class Audience
{
public int Id { get; private set; }
public string NumberAudience { get; private set; } = string.Empty;
public TypeAudience TypeAudience { get; private set; }
public int QuantitySeats { get; private set; }
public static Audience CreateEntity(int id, string numberAudience, TypeAudience typeAudience, int quantitySeats)
{
return new Audience

View File

@ -5,14 +5,23 @@ namespace ProjectSchedule.Entities;
public class CompilingSchedule
{
public int Id { get; private set; }
public int EducatorId { get; private set; }
public int DisciplineId { get; private set; }
public int GroupStudentsId { get; private set; }
public int AudienceId { get; private set; }
public TypeWeek TypeWeek { get; private set; }
public int NumberDay { get; private set; }
public int NumberPair { get; private set; }
public TypeActivity TypeActivity { get; private set; }
public static CompilingSchedule CreateOperation(int id, int educatorId, int disciplineId, int groupStudentsId, int audienceId, TypeWeek typeWeek,
int numberDay, int numberPair, TypeActivity typeActivity)
{

View File

@ -3,24 +3,25 @@
public class CurriculumSupplement
{
public int Id { get; private set; }
public int DisciplineId { get; private set; }
public int GroupStudentsId { get; private set; }
public string NameCurriculum { get; private set; } = string.Empty;
public int QuantityLectures { get; private set; }
public int QuantityPractices { get; private set; }
public string Semester { get; private set; } = string.Empty;
public static CurriculumSupplement CreateOperation(int id, int disciplineId, int groupStudentsId, string nameCurriculum,
int quantityLectures, int quantityPractices, string semester)
public IEnumerable<DisciplineCurriculumSupplement> DisciplineCurriculumSupplements { get; private set; } = [];
public static CurriculumSupplement CreateOperation(int id, int groupStudentsId, string nameCurriculum,
string semester, IEnumerable<DisciplineCurriculumSupplement> disciplineCurriculumSupplements)
{
return new CurriculumSupplement
{
Id = id,
DisciplineId = disciplineId,
GroupStudentsId = groupStudentsId,
NameCurriculum = nameCurriculum ?? string.Empty,
QuantityLectures = quantityLectures,
QuantityPractices = quantityPractices,
Semester = semester ?? string.Empty
Semester = semester ?? string.Empty,
DisciplineCurriculumSupplements = disciplineCurriculumSupplements
};
}
}

View File

@ -3,7 +3,9 @@
public class Discipline
{
public int Id { get; private set; }
public string NameDiscipline { get; private set; } = string.Empty;
public static Discipline CreateEntity(int id, string nameDiscipline)
{
return new Discipline

View File

@ -0,0 +1,23 @@
namespace ProjectSchedule.Entities;
public class DisciplineCurriculumSupplement
{
public int Id { get; private set; }
public int DisciplineId { get; private set; }
public int QuantityLectures { get; private set; }
public int QuantityPractices { get; private set; }
public static DisciplineCurriculumSupplement CreateElement(int id, int disciplineId, int quantityLectures, int quantityPractices)
{
return new DisciplineCurriculumSupplement
{
Id = id,
DisciplineId = disciplineId,
QuantityLectures = quantityLectures,
QuantityPractices = quantityPractices
};
}
}

View File

@ -3,9 +3,13 @@
public class Educator
{
public int Id { get; private set; }
public string Surname { get; private set; } = string.Empty;
public string Name { get; private set; } = string.Empty;
public string Patronymic { get; private set; } = string.Empty;
public static Educator CreateEntity(int id, string surname, string name, string patronymic)
{
return new Educator

View File

@ -3,9 +3,13 @@
public class GroupStudents
{
public int Id { get; private set; }
public string AbbreviationGroup { get; private set; } = string.Empty;
public string GroupNumber { get; private set; } = string.Empty;
public int QuantityStudents { get; private set; }
public static GroupStudents CreateEntity(int id, string abbreviationGroup, string groupNumber, int quantityStudents)
{
return new GroupStudents

View File

@ -28,55 +28,36 @@
/// </summary>
private void InitializeComponent()
{
comboBoxDiscipline = new ComboBox();
comboBoxGroupStudents = new ComboBox();
labelDiscipline = new Label();
labelGroupStudents = new Label();
labelNameCurriculum = new Label();
labelQuantityLectures = new Label();
labelQuantityPractices = new Label();
labelSemester = new Label();
textBoxNameCurriculum = new TextBox();
numericUpDownQuantityLectures = new NumericUpDown();
numericUpDownQuantityPractices = new NumericUpDown();
buttonSave = new Button();
buttonCancel = new Button();
textBoxSemester = new TextBox();
((System.ComponentModel.ISupportInitialize)numericUpDownQuantityLectures).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownQuantityPractices).BeginInit();
groupBoxDisciplines = new GroupBox();
dataGridViewDisciplines = new DataGridView();
ColumnDiscipline = new DataGridViewComboBoxColumn();
ColumnQuantityLectures = new DataGridViewTextBoxColumn();
ColumnQuantityPractices = new DataGridViewTextBoxColumn();
groupBoxDisciplines.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewDisciplines).BeginInit();
SuspendLayout();
//
// comboBoxDiscipline
//
comboBoxDiscipline.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxDiscipline.FormattingEnabled = true;
comboBoxDiscipline.Location = new Point(252, 12);
comboBoxDiscipline.Name = "comboBoxDiscipline";
comboBoxDiscipline.Size = new Size(218, 28);
comboBoxDiscipline.TabIndex = 0;
//
// comboBoxGroupStudents
//
comboBoxGroupStudents.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxGroupStudents.FormattingEnabled = true;
comboBoxGroupStudents.Location = new Point(252, 68);
comboBoxGroupStudents.Location = new Point(252, 6);
comboBoxGroupStudents.Name = "comboBoxGroupStudents";
comboBoxGroupStudents.Size = new Size(218, 28);
comboBoxGroupStudents.TabIndex = 1;
//
// labelDiscipline
//
labelDiscipline.AutoSize = true;
labelDiscipline.Location = new Point(12, 15);
labelDiscipline.Name = "labelDiscipline";
labelDiscipline.Size = new Size(99, 20);
labelDiscipline.TabIndex = 2;
labelDiscipline.Text = "Дисциплина:";
//
// labelGroupStudents
//
labelGroupStudents.AutoSize = true;
labelGroupStudents.Location = new Point(12, 71);
labelGroupStudents.Location = new Point(12, 9);
labelGroupStudents.Name = "labelGroupStudents";
labelGroupStudents.Size = new Size(133, 20);
labelGroupStudents.TabIndex = 3;
@ -85,34 +66,16 @@
// labelNameCurriculum
//
labelNameCurriculum.AutoSize = true;
labelNameCurriculum.Location = new Point(12, 130);
labelNameCurriculum.Location = new Point(12, 46);
labelNameCurriculum.Name = "labelNameCurriculum";
labelNameCurriculum.Size = new Size(230, 20);
labelNameCurriculum.TabIndex = 4;
labelNameCurriculum.Text = "Название учебной программы:";
//
// labelQuantityLectures
//
labelQuantityLectures.AutoSize = true;
labelQuantityLectures.Location = new Point(12, 189);
labelQuantityLectures.Name = "labelQuantityLectures";
labelQuantityLectures.Size = new Size(147, 20);
labelQuantityLectures.TabIndex = 5;
labelQuantityLectures.Text = "Количество лекций:";
//
// labelQuantityPractices
//
labelQuantityPractices.AutoSize = true;
labelQuantityPractices.Location = new Point(12, 236);
labelQuantityPractices.Name = "labelQuantityPractices";
labelQuantityPractices.Size = new Size(152, 20);
labelQuantityPractices.TabIndex = 6;
labelQuantityPractices.Text = "Количество практик:";
//
// labelSemester
//
labelSemester.AutoSize = true;
labelSemester.Location = new Point(12, 278);
labelSemester.Location = new Point(12, 83);
labelSemester.Name = "labelSemester";
labelSemester.Size = new Size(70, 20);
labelSemester.TabIndex = 7;
@ -120,30 +83,15 @@
//
// textBoxNameCurriculum
//
textBoxNameCurriculum.Location = new Point(252, 127);
textBoxNameCurriculum.Location = new Point(252, 43);
textBoxNameCurriculum.Name = "textBoxNameCurriculum";
textBoxNameCurriculum.Size = new Size(218, 27);
textBoxNameCurriculum.TabIndex = 8;
//
// numericUpDownQuantityLectures
//
numericUpDownQuantityLectures.Location = new Point(252, 187);
numericUpDownQuantityLectures.Maximum = new decimal(new int[] { 40, 0, 0, 0 });
numericUpDownQuantityLectures.Name = "numericUpDownQuantityLectures";
numericUpDownQuantityLectures.Size = new Size(218, 27);
numericUpDownQuantityLectures.TabIndex = 10;
//
// numericUpDownQuantityPractices
//
numericUpDownQuantityPractices.Location = new Point(252, 234);
numericUpDownQuantityPractices.Maximum = new decimal(new int[] { 40, 0, 0, 0 });
numericUpDownQuantityPractices.Name = "numericUpDownQuantityPractices";
numericUpDownQuantityPractices.Size = new Size(218, 27);
numericUpDownQuantityPractices.TabIndex = 11;
//
// buttonSave
//
buttonSave.Location = new Point(12, 312);
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonSave.Location = new Point(12, 462);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(116, 29);
buttonSave.TabIndex = 12;
@ -153,7 +101,8 @@
//
// buttonCancel
//
buttonCancel.Location = new Point(354, 312);
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(354, 462);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(116, 29);
buttonCancel.TabIndex = 13;
@ -163,55 +112,93 @@
//
// textBoxSemester
//
textBoxSemester.Location = new Point(252, 275);
textBoxSemester.Location = new Point(252, 80);
textBoxSemester.Name = "textBoxSemester";
textBoxSemester.Size = new Size(218, 27);
textBoxSemester.TabIndex = 15;
//
// groupBoxDisciplines
//
groupBoxDisciplines.Controls.Add(dataGridViewDisciplines);
groupBoxDisciplines.Location = new Point(12, 113);
groupBoxDisciplines.Name = "groupBoxDisciplines";
groupBoxDisciplines.Size = new Size(458, 343);
groupBoxDisciplines.TabIndex = 16;
groupBoxDisciplines.TabStop = false;
groupBoxDisciplines.Text = "Дисциплины";
//
// dataGridViewDisciplines
//
dataGridViewDisciplines.AllowUserToResizeColumns = false;
dataGridViewDisciplines.AllowUserToResizeRows = false;
dataGridViewDisciplines.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewDisciplines.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewDisciplines.Columns.AddRange(new DataGridViewColumn[] { ColumnDiscipline, ColumnQuantityLectures, ColumnQuantityPractices });
dataGridViewDisciplines.Dock = DockStyle.Fill;
dataGridViewDisciplines.Location = new Point(3, 23);
dataGridViewDisciplines.MultiSelect = false;
dataGridViewDisciplines.Name = "dataGridViewDisciplines";
dataGridViewDisciplines.RowHeadersVisible = false;
dataGridViewDisciplines.RowHeadersWidth = 51;
dataGridViewDisciplines.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewDisciplines.Size = new Size(452, 317);
dataGridViewDisciplines.TabIndex = 0;
//
// ColumnDiscipline
//
ColumnDiscipline.HeaderText = "Дисциплина";
ColumnDiscipline.MinimumWidth = 6;
ColumnDiscipline.Name = "ColumnDiscipline";
//
// ColumnQuantityLectures
//
ColumnQuantityLectures.HeaderText = "Количество лекций";
ColumnQuantityLectures.MinimumWidth = 6;
ColumnQuantityLectures.Name = "ColumnQuantityLectures";
//
// ColumnQuantityPractices
//
ColumnQuantityPractices.HeaderText = "Количество практик";
ColumnQuantityPractices.MinimumWidth = 6;
ColumnQuantityPractices.Name = "ColumnQuantityPractices";
//
// FormCurriculumSupplement
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(482, 353);
ClientSize = new Size(482, 503);
Controls.Add(groupBoxDisciplines);
Controls.Add(textBoxSemester);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(numericUpDownQuantityPractices);
Controls.Add(numericUpDownQuantityLectures);
Controls.Add(textBoxNameCurriculum);
Controls.Add(labelSemester);
Controls.Add(labelQuantityPractices);
Controls.Add(labelQuantityLectures);
Controls.Add(labelNameCurriculum);
Controls.Add(labelGroupStudents);
Controls.Add(labelDiscipline);
Controls.Add(comboBoxGroupStudents);
Controls.Add(comboBoxDiscipline);
Name = "FormCurriculumSupplement";
StartPosition = FormStartPosition.CenterParent;
Text = "Дополнение учебного плана";
((System.ComponentModel.ISupportInitialize)numericUpDownQuantityLectures).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownQuantityPractices).EndInit();
groupBoxDisciplines.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewDisciplines).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private ComboBox comboBoxDiscipline;
private ComboBox comboBoxGroupStudents;
private Label labelDiscipline;
private Label labelGroupStudents;
private Label labelNameCurriculum;
private Label labelQuantityLectures;
private Label labelQuantityPractices;
private Label labelSemester;
private TextBox textBoxNameCurriculum;
private NumericUpDown numericUpDownQuantityLectures;
private NumericUpDown numericUpDownQuantityPractices;
private Button buttonSave;
private Button buttonCancel;
private NumericUpDown numericUpDown;
private TextBox textBoxSemester;
private GroupBox groupBoxDisciplines;
private DataGridView dataGridViewDisciplines;
private DataGridViewComboBoxColumn ColumnDiscipline;
private DataGridViewTextBoxColumn ColumnQuantityLectures;
private DataGridViewTextBoxColumn ColumnQuantityPractices;
}
}

View File

@ -15,28 +15,27 @@ namespace ProjectSchedule.Forms
_curriculumSupplementRepository = curriculumSupplementRepository ??
throw new ArgumentNullException(nameof(curriculumSupplementRepository));
comboBoxDiscipline.DataSource = disciplineRepository.ReadDisciplines();
comboBoxDiscipline.DisplayMember = "NameDiscipline";
comboBoxDiscipline.ValueMember = "Id";
comboBoxGroupStudents.DataSource = groupStudentsRepository.ReadGroupsStudents();
comboBoxGroupStudents.DisplayMember = "AbbreviationGroup";
comboBoxGroupStudents.ValueMember = "Id";
ColumnDiscipline.DataSource = disciplineRepository.ReadDisciplines();
ColumnDiscipline.DisplayMember = "NameDiscipline";
ColumnDiscipline.ValueMember = "Id";
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (comboBoxDiscipline.SelectedIndex < 0 || comboBoxGroupStudents.SelectedIndex < 0)
if (dataGridViewDisciplines.RowCount < 1 || comboBoxGroupStudents.SelectedIndex < 0)
{
throw new Exception("Имеются незаполненные поля");
}
_curriculumSupplementRepository.CreateCurriculumSupplement(CurriculumSupplement.CreateOperation(0,
(int)comboBoxDiscipline.SelectedValue!, (int)comboBoxGroupStudents.SelectedValue!,
textBoxNameCurriculum.Text, Convert.ToInt32(numericUpDownQuantityLectures.Value),
Convert.ToInt32(numericUpDownQuantityPractices.Value), textBoxSemester.Text));
(int)comboBoxGroupStudents.SelectedValue!, textBoxNameCurriculum.Text, textBoxSemester.Text,
CreateListDisciplineCurriculumSupplementsFromDataGrid()));
Close();
}
@ -47,5 +46,24 @@ namespace ProjectSchedule.Forms
}
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private List<DisciplineCurriculumSupplement> CreateListDisciplineCurriculumSupplementsFromDataGrid()
{
var list = new List<DisciplineCurriculumSupplement>();
foreach (DataGridViewRow row in dataGridViewDisciplines.Rows)
{
if (row.Cells["ColumnDiscipline"].Value == null || row.Cells["ColumnQuantityLectures"].Value == null ||
row.Cells["ColumnQuantityPractices"].Value == null)
{
continue;
}
list.Add(DisciplineCurriculumSupplement.CreateElement(0, Convert.ToInt32(row.Cells["ColumnDiscipline"].Value),
Convert.ToInt32(row.Cells["ColumnQuantityLectures"].Value),
Convert.ToInt32(row.Cells["ColumnQuantityPractices"].Value)));
}
return list;
}
}
}

View File

@ -117,4 +117,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ColumnDiscipline.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnQuantityLectures.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnQuantityPractices.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -6,6 +6,8 @@ public interface ICompilingScheduleRepository
{
IEnumerable<CompilingSchedule> ReadCompilingSchedules(int? educatorId = null, int? disciplineId = null,
int? groupStudentsId = null, int? audienceId = null);
void CreateCompilingSchedule(CompilingSchedule compilingSchedule);
void DeleteCompilingSchedule(int id);
}

View File

@ -5,6 +5,8 @@ namespace ProjectSchedule.Repositories;
public interface ICurriculumSupplementRepository
{
IEnumerable<CurriculumSupplement> ReadCurriculumSupplements(int? disciplineId = null, int? groupStudentsId = null);
void CreateCurriculumSupplement(CurriculumSupplement curriculumSupplement);
void DeleteCurriculumSupplement(int id);
}