SUBD_SportCompetitions/SportCompetitionsView/FormMain.cs

149 lines
4.0 KiB
C#
Raw Blame History

using SportCompetitionsContracts.BindingModels;
using SportCompetitionsContracts.BusinessLogicsContracts;
using SportCompetitionsDatabaseImplement;
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;
namespace SportCompetitionsView
{
public partial class FormMain : Form
{
private ICompetitionLogic _logicC;
private ITeamLogic _logicT;
public FormMain(ITeamLogic logicT, ICompetitionLogic logicC)
{
InitializeComponent();
_logicT = logicT;
_logicC = logicC;
}
private void CompetitionToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCompetitions));
if (service is FormCompetitions form)
{
form.ShowDialog();
}
}
private void TeamsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormTeams));
if (service is FormTeams form)
{
form.ShowDialog();
}
}
private void MembersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMembers));
if (service is FormMembers form)
{
form.ShowDialog();
}
}
private void RecordsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormRecords));
if (service is FormRecords form)
{
form.ShowDialog();
}
}
private void ResultsToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormResults));
if (service is FormResults form)
{
form.ShowDialog();
}
}
private void buttonTest1_Click(object sender, EventArgs e)
{
DateTime startCreation = DateTime.Now;
for (int i = 1; i <= 100; i++)
{
CompetitionBindingModel model = new CompetitionBindingModel()
{
Id = i + 100,
CompetitionName = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> " + i,
CompetitionDateHolding = DateTime.Now,
CompetitionCity = "<22><><EFBFBD><EFBFBD><EFBFBD> " + i
};
_logicC.Create(model);
}
DateTime stopCreation = DateTime.Now;
TimeSpan creationTime = stopCreation - startCreation;
MessageBox.Show($"<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {creationTime}", "Test", MessageBoxButtons.OK);
}
private void buttonTest2_Click(object sender, EventArgs e)
{
DateTime startDeletion = DateTime.Now;
for (int i = 1; i <= 100; i++)
{
_logicC.Delete(new CompetitionBindingModel { Id = i + 100 });
}
DateTime stopDeletion = DateTime.Now;
TimeSpan deletionTime = stopDeletion - startDeletion;
MessageBox.Show($"<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {deletionTime}", "Test", MessageBoxButtons.OK);
}
private void button_Click(object sender, EventArgs e)
{
DateTime start = DateTime.Now; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
using (var db = new SportCompetitionsDatabase())
{
var query = from member in db.Members
join team in db.Teams on member.TeamId + 1 equals team.Id
select new
{
member.MemberFCs,
member.MemberBirthDate,
member.MemberGender,
team.TeamName,
team.TeamCountry
};
var result = query.ToList();
DateTime stop = DateTime.Now; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TimeSpan queryTime = stop - start; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var form = new Form();
form.Width = 800;
form.Height = 600;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> DataGridView
var dataGridView = new DataGridView();
dataGridView.Dock = DockStyle.Fill;
dataGridView.AutoGenerateColumns = true;
dataGridView.DataSource = result;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> DataGridView <20><> <20><><EFBFBD><EFBFBD><EFBFBD>
form.Controls.Add(dataGridView);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
form.ShowDialog();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
MessageBox.Show($"<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {queryTime.TotalMilliseconds} <20><>", "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}