SUBD_LAB/SUBD_LABA/View/MainForm.cs

172 lines
4.8 KiB
C#
Raw Permalink Normal View History

2024-05-14 22:32:28 +04:00
using Commentbase;
using Database;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
2024-05-21 22:20:17 +04:00
using static System.Windows.Forms.DataFormats;
2024-05-14 22:32:28 +04:00
namespace View
{
public partial class MainForm : Form
{
2024-05-21 22:20:17 +04:00
public MainForm()
2024-05-14 22:32:28 +04:00
{
InitializeComponent();
}
2024-05-21 22:20:17 +04:00
private void albumToolStripMenuItem_Click(object sender, EventArgs e)
2024-05-14 22:32:28 +04:00
{
var service = Program.ServiceProvider?.GetService(typeof(FormAlbums));
if (service is FormAlbums form)
{
2024-05-21 22:20:17 +04:00
form.ShowDialog();
2024-05-14 22:32:28 +04:00
}
}
2024-05-21 22:20:17 +04:00
private void locationToolStripMenuItem_Click(object sender, EventArgs e)
2024-05-14 22:32:28 +04:00
{
var service = Program.ServiceProvider?.GetService(typeof(FormLocations));
if (service is FormLocations form)
{
2024-05-21 22:20:17 +04:00
form.ShowDialog();
2024-05-14 22:32:28 +04:00
}
}
2024-05-21 22:20:17 +04:00
private void authorToolStripMenuItem_Click(object sender, EventArgs e)
2024-05-14 22:32:28 +04:00
{
var service = Program.ServiceProvider?.GetService(typeof(FormAuthors));
if (service is FormAuthors form)
{
2024-05-21 22:20:17 +04:00
form.ShowDialog();
2024-05-14 22:32:28 +04:00
}
}
2024-05-21 22:20:17 +04:00
private void photoToolStripMenuItem_Click(object sender, EventArgs e)
2024-05-14 22:32:28 +04:00
{
var service = Program.ServiceProvider?.GetService(typeof(FormPhotos));
if (service is FormPhotos form)
{
2024-05-21 22:20:17 +04:00
form.ShowDialog();
2024-05-14 22:32:28 +04:00
}
}
2024-05-21 22:20:17 +04:00
private void commentToolStripMenuItem_Click(object sender, EventArgs e)
2024-05-14 22:32:28 +04:00
{
var service = Program.ServiceProvider?.GetService(typeof(FormComments));
if (service is FormComments form)
{
2024-05-21 22:20:17 +04:00
form.ShowDialog();
2024-05-14 22:32:28 +04:00
}
}
2024-05-21 22:20:17 +04:00
private void buttonTest_Click(object sender, EventArgs e)
2024-05-14 22:32:28 +04:00
{
2024-05-21 22:20:17 +04:00
var photo = new Photo()
2024-05-14 22:32:28 +04:00
{
2024-05-21 22:20:17 +04:00
Id = 0,
Title = "photo",
Description = "cool photo",
Privacy = "public",
UploadDate = DateTime.Now,
ImagePath = "Image/312",
AlbumId = 1,
LocationId = 1,
AuthorId = 1,
};
ImplementsPostgres bd = new();
DateTime startTime = DateTime.Now;
bd.DeletePhoto(40);
bd.DeletePhoto(41);
bd.DeletePhoto(42);
bd.DeletePhoto(43);
bd.DeletePhoto(44);
DateTime endTime = DateTime.Now;
// Выводим время выполнения запроса в консоль
textBoxTest.Text = $"Время выполнения запроса в постгресе: {(endTime - startTime).TotalMilliseconds} миллисекунд ";
ImplementsMongoDB bdMongodb = new();
startTime = DateTime.Now;
bdMongodb.DeletePhoto(40);
bdMongodb.DeletePhoto(41);
bdMongodb.DeletePhoto(42);
bdMongodb.DeletePhoto(43);
bdMongodb.DeletePhoto(44);
endTime = DateTime.Now;
textBoxTest.Text += $"Время выполнения запроса в монгоДб: {(endTime - startTime).TotalMilliseconds} миллисекунд";
2024-05-14 22:32:28 +04:00
}
2024-05-21 22:20:17 +04:00
private void trackBarDB_MouseUp(object sender, MouseEventArgs e)
2024-05-14 22:32:28 +04:00
{
2024-05-21 22:20:17 +04:00
if (trackBarDB.Value > 50)
2024-05-14 22:32:28 +04:00
{
2024-05-21 22:20:17 +04:00
trackBarDB.Value = 100;
Program.ChangeDB(false);
2024-05-14 22:32:28 +04:00
}
2024-05-21 22:20:17 +04:00
else
2024-05-14 22:32:28 +04:00
{
2024-05-21 22:20:17 +04:00
trackBarDB.Value = 0;
Program.ChangeDB(true);
2024-05-14 22:32:28 +04:00
}
}
2024-05-21 22:20:17 +04:00
private void buttonTransferDataFromPostgresToMongo_Click(object sender, EventArgs e)
2024-05-14 22:32:28 +04:00
{
2024-05-21 22:20:17 +04:00
ImplementsMongoDB implementsMongoDB = new();
// очищаем всё
foreach (var it in implementsMongoDB.GetAlbums())
implementsMongoDB.DeleteAlbum(it.Id);
foreach (var it in implementsMongoDB.GetLocations())
implementsMongoDB.DeleteLocation(it.Id);
foreach (var it in implementsMongoDB.GetAuthors())
implementsMongoDB.DeleteAuthor(it.Id);
foreach (var it in implementsMongoDB.GetPhotos())
implementsMongoDB.DeletePhoto(it.Id);
foreach (var it in implementsMongoDB.GetComments())
implementsMongoDB.DeleteComment(it.Id);
ImplementsPostgres implementsPostgres = new();
// скачиваем из постгреса
var listAlbums = implementsPostgres.GetAlbums();
var listLocations = implementsPostgres.GetLocations();
var listAuthors = implementsPostgres.GetAuthors();
var listPhotos = implementsPostgres.GetPhotos();
var listComments = implementsPostgres.GetComments();
// вливаем данные монго дб
foreach (var it in listAlbums)
implementsMongoDB.CreateAlbum(it);
foreach (var it in listLocations)
implementsMongoDB.CreateLocation(it);
foreach (var it in listAuthors)
implementsMongoDB.CreateAuthor(it);
foreach (var it in listPhotos)
implementsMongoDB.CreatePhoto(it);
foreach (var it in listComments)
implementsMongoDB.CreateComment(it);
// забираем информацию о последовательностях
var listSequence = implementsPostgres.GetSequences();
foreach (var it in listSequence)
if (it.Id == "Album" ||
it.Id == "Location" ||
it.Id == "Author" ||
it.Id == "Photo" ||
it.Id == "Comment"
)
implementsMongoDB.UpdateSequence(it);
else
throw new Exception("неправильнй id последовательности");
2024-05-14 22:32:28 +04:00
}
}
}