Работает доп задание(сложный запрос)!

This commit is contained in:
ityurner02@mail.ru 2023-04-19 20:23:31 +04:00
parent 0920c27757
commit 0b2fbd945c
8 changed files with 277 additions and 2 deletions

View File

@ -51,6 +51,7 @@ namespace ElectronicJournalDatabaseImplement.Implements
.Include(x => x.Group)
.Include(x => x.Teacher)
.Where(x =>
(x.Id == model.Id) ||
(x.Date >= model.DateFrom && x.Date <= model.DateTo)
|| x.Discipline.Title.Contains(model.DisciplineName)
|| x.Group.Title.Contains(model.GroupName)

View File

@ -0,0 +1,87 @@
namespace SUBD
{
partial class FormDisciplineLowMark
{
/// <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()
{
dataGridView = new DataGridView();
labelCount = new Label();
labelTime = new Label();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(3, 3);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(626, 435);
dataGridView.TabIndex = 0;
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(635, 9);
labelCount.Name = "labelCount";
labelCount.Size = new Size(51, 20);
labelCount.TabIndex = 1;
labelCount.Text = "Count:";
//
// labelTime
//
labelTime.AutoSize = true;
labelTime.Location = new Point(635, 38);
labelTime.Name = "labelTime";
labelTime.Size = new Size(42, 20);
labelTime.TabIndex = 2;
labelTime.Text = "Time";
//
// FormDisciplineLowMark
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(labelTime);
Controls.Add(labelCount);
Controls.Add(dataGridView);
Name = "FormDisciplineLowMark";
Text = "FormDisciplineLowMark";
Load += FormDisciplineLowMark_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private DataGridView dataGridView;
private Label labelCount;
private Label labelTime;
}
}

View File

@ -0,0 +1,103 @@
using ElectronicJournalBusinessLogic.BusinessLogic;
using ElectronicJournalContracts.BusinessLogicContracts;
using ElectronicJournalContracts.SearchModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
namespace SUBD
{
public partial class FormDisciplineLowMark : Form
{
private readonly ILogger _logger;
private readonly IStatementLogic _statementLogic;
private readonly IResultOfControlLogic _resultLogic;
public FormDisciplineLowMark(ILogger<FormStatement> logger, IStatementLogic statementLogic, IResultOfControlLogic resultLogic)
{
InitializeComponent();
_logger = logger;
_statementLogic = statementLogic;
_resultLogic = resultLogic;
}
private void LoadData()
{
try
{
StatementSearchModel model = new StatementSearchModel();
Dictionary<int, int> badResults = new Dictionary<int, int>();
int[] arrayTopBadId = new int[10];
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var listAllRes = _resultLogic.ReadList(null);
for(int i = 0; i < listAllRes.Count; i++)
{
if ((listAllRes[i].Mark == "Не зачтено" || listAllRes[i].Mark == "Неудовлетворительно") &&
listAllRes[i].Date >= DateOnly.FromDateTime(DateTime.Now.AddYears(-1)))
{
if (!badResults.ContainsKey(listAllRes[i].StatementId))
{
badResults.Add(listAllRes[i].StatementId, 1);
}
else
{
badResults[listAllRes[i].StatementId] += 1;
}
}
}
for (int i = 0; i < arrayTopBadId.Length; i++)
{
int maxValueKey = badResults.Aggregate((x, y) => x.Value > y.Value ? x : y).Key;
arrayTopBadId[i] = maxValueKey;
badResults.Remove(maxValueKey);
}
model.Id = arrayTopBadId[0];
var listTopStat = _statementLogic.ReadList(model);
for (int i = 1; i < arrayTopBadId.Length; i++)
{
model.Id = arrayTopBadId[i];
var listTemp = _statementLogic.ReadList(model);
listTopStat.AddRange(listTemp.ToArray());
}
if (listTopStat != null)
{
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.DataSource = listTopStat;
dataGridView.Columns["DisciplineId"].Visible = false;
dataGridView.Columns["GroupId"].Visible = false;
dataGridView.Columns["TeacherId"].Visible = false;
}
stopwatch.Stop();
TimeSpan ts = stopwatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
labelTime.Text = ("RunTime " + elapsedTime);
labelCount.Text = "Count: " + listTopStat.Count();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки ведомости");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void FormDisciplineLowMark_Load(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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

@ -35,6 +35,7 @@
buttonStatement = new Button();
buttonResultOfControl = new Button();
buttonGenerate = new Button();
buttonDisciplineLowMark = new Button();
SuspendLayout();
//
// buttonDiscipline
@ -107,11 +108,22 @@
buttonGenerate.UseVisualStyleBackColor = true;
buttonGenerate.Click += buttonGenerate_Click;
//
// buttonDisciplineLowMark
//
buttonDisciplineLowMark.Location = new Point(12, 158);
buttonDisciplineLowMark.Name = "buttonDisciplineLowMark";
buttonDisciplineLowMark.Size = new Size(149, 67);
buttonDisciplineLowMark.TabIndex = 7;
buttonDisciplineLowMark.Text = "Топ ведомостей с неуд";
buttonDisciplineLowMark.UseVisualStyleBackColor = true;
buttonDisciplineLowMark.Click += buttonDisciplineLowMark_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(486, 255);
ClientSize = new Size(486, 241);
Controls.Add(buttonDisciplineLowMark);
Controls.Add(buttonGenerate);
Controls.Add(buttonResultOfControl);
Controls.Add(buttonStatement);
@ -133,5 +145,6 @@
private Button buttonStatement;
private Button buttonResultOfControl;
private Button buttonGenerate;
private Button buttonDisciplineLowMark;
}
}

View File

@ -76,5 +76,15 @@ namespace SUBD
form.ShowDialog();
}
}
private void buttonDisciplineLowMark_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDisciplineLowMark));
if (service is FormDisciplineLowMark form)
{
form.ShowDialog();
}
}
}
}

View File

@ -111,7 +111,7 @@ namespace SUBD
{
Id = 0,
Name = names[rd.Next(0, names.Length)],
GroupId = rd.Next(1, grouplist - 1)
GroupId = rd.Next(1, grouplist)
};
_STlogic.Create(modelST);
}

View File

@ -56,6 +56,7 @@ namespace SUBD
services.AddTransient<FormCreateStatement>();
services.AddTransient<FormCreateResultOfControl>();
services.AddTransient<FormRandom>();
services.AddTransient<FormDisciplineLowMark>();
services.AddTransient<FormMain>();
}
}