172 lines
4.8 KiB
C#
172 lines
4.8 KiB
C#
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;
|
||
using static System.Windows.Forms.DataFormats;
|
||
|
||
namespace View
|
||
{
|
||
public partial class MainForm : Form
|
||
{
|
||
public MainForm()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
private void albumToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormAlbums));
|
||
if (service is FormAlbums form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
|
||
private void locationToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormLocations));
|
||
if (service is FormLocations form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
|
||
private void authorToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormAuthors));
|
||
if (service is FormAuthors form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
|
||
private void photoToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormPhotos));
|
||
if (service is FormPhotos form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
|
||
private void commentToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
var service = Program.ServiceProvider?.GetService(typeof(FormComments));
|
||
if (service is FormComments form)
|
||
{
|
||
form.ShowDialog();
|
||
}
|
||
}
|
||
private void buttonTest_Click(object sender, EventArgs e)
|
||
{
|
||
var photo = new Photo()
|
||
{
|
||
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} миллисекунд";
|
||
}
|
||
|
||
private void trackBarDB_MouseUp(object sender, MouseEventArgs e)
|
||
{
|
||
if (trackBarDB.Value > 50)
|
||
{
|
||
trackBarDB.Value = 100;
|
||
Program.ChangeDB(false);
|
||
}
|
||
else
|
||
{
|
||
trackBarDB.Value = 0;
|
||
Program.ChangeDB(true);
|
||
}
|
||
}
|
||
|
||
private void buttonTransferDataFromPostgresToMongo_Click(object sender, EventArgs e)
|
||
{
|
||
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 последовательности");
|
||
}
|
||
}
|
||
}
|