diff --git a/TransportCompany/TransportCompamyMongoDBImplementer/Implements/ClientStorage.cs b/TransportCompany/TransportCompamyMongoDBImplementer/Implements/ClientStorage.cs index e447f20..c3bba14 100644 --- a/TransportCompany/TransportCompamyMongoDBImplementer/Implements/ClientStorage.cs +++ b/TransportCompany/TransportCompamyMongoDBImplementer/Implements/ClientStorage.cs @@ -75,17 +75,19 @@ namespace TransportCompamyMongoDBImplementer.Implements //метод для замера вставки большого кол-ва клиентов в бд public string TestRandomInsert(int count, string[] _name, string[] _surname, string[] _patronymic, string[] _telephone, string[] _email) { - /*using var context = new ElegevContext(); + var clientCollection = context.ConnectToMongo("client"); Random rnd = new Random(DateTime.Now.ToString().GetHashCode()); - int lastId = context.Clients.Count() > 0 ? context.Clients.Max(x => x.Id) + 1 : 1; + //старт замера времени добавления в бд + Stopwatch stopwatch = new(); + + stopwatch.Start(); for (int i = 0; i < count; i++) { var model = new Client { - Id = lastId, Name = _name[rnd.Next(0, _name.Length)], Surname = _surname[rnd.Next(0, _surname.Length)], Patronymic = _patronymic[rnd.Next(0, _patronymic.Length)], @@ -93,29 +95,19 @@ namespace TransportCompamyMongoDBImplementer.Implements Email = _email[rnd.Next(0, _email.Length)], }; - lastId++; - - context.Clients.Add(model); + clientCollection.InsertOne(model); } - //старт замера времени добавления в бд - Stopwatch stopwatch = new(); - - stopwatch.Start(); - - context.SaveChanges(); - stopwatch.Stop(); - return stopwatch.ElapsedMilliseconds.ToString();*/ - - return null; + return stopwatch.ElapsedMilliseconds.ToString(); } public string SecondJoin() { - /*using var context = new ElegevContext(); + var clientCollection = context.ConnectToMongo("client"); + var truckingCollection = context.ConnectToMongo("trucking"); Random rnd = new Random(DateTime.Now.ToString().GetHashCode()); @@ -124,34 +116,30 @@ namespace TransportCompamyMongoDBImplementer.Implements stopwatch.Start(); - var secondJoin = from t in context.Set() - from c in context.Set().Where(c => c.Id == t.ClientId) + var secondJoin = from t in truckingCollection.Find(_ => true).ToList() + from c in clientCollection.Find(c => c.Id == t.Client.Id).ToList() select new { c, t }; //ВСЁ ГОТОВО ДЛЯ СЛЕДУЮЩЕГО ЗАМЕРА foreach (var element in secondJoin) { - element.t.Update(new TruckingBindingModel - { - Id = element.t.Id, - ClientId = element.t.ClientId, - CargoId = element.t.CargoId, - Price = element.t.Price, - DateStart = element.t.DateStart.AddDays(-10), - DateEnd = element.t.DateEnd.AddDays(-10), - TransportationId = element.t.TransportationId, - TransportId = element.t.TransportId, - }); - } + var trucking = truckingCollection.Find(x => x.Id == element.t.Id).FirstOrDefault(); - context.SaveChanges(); + trucking.Update(new TruckingBindingModel + { + Price = element.t.Price, + DateStart = element.t.DateStart.AddDays(10), + DateEnd = element.t.DateEnd.AddDays(10) + }); + + var filter = Builders.Filter.Eq("Id", element.t.Id); + truckingCollection.ReplaceOne(filter, trucking, new ReplaceOptions { IsUpsert = true }); + } stopwatch.Stop(); - return stopwatch.ElapsedMilliseconds.ToString();*/ - - return null; + return stopwatch.ElapsedMilliseconds.ToString(); } public ClientViewModel? Update(ClientBindingModel model) diff --git a/TransportCompany/TransportCompamyMongoDBImplementer/Implements/TruckingStorage.cs b/TransportCompany/TransportCompamyMongoDBImplementer/Implements/TruckingStorage.cs index 5eaed82..caae3a9 100644 --- a/TransportCompany/TransportCompamyMongoDBImplementer/Implements/TruckingStorage.cs +++ b/TransportCompany/TransportCompamyMongoDBImplementer/Implements/TruckingStorage.cs @@ -1,6 +1,7 @@ using MongoDB.Driver; using System; using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.Contracts; using System.Linq; using System.Text; @@ -35,7 +36,41 @@ namespace TransportCompamyMongoDBImplementer.Implements public string FirstJoin() { - throw new NotImplementedException(); + var truckingCollection = context.ConnectToMongo("trucking"); + var clientCollection = context.ConnectToMongo("client"); + + Random rnd = new Random(DateTime.Now.ToString().GetHashCode()); + + //старт замера времени добавления в бд + Stopwatch stopwatch = new(); + + stopwatch.Start(); + + var firstJoin = from t in truckingCollection.Find(t => t.Price == 999999.0).ToList() + from c in clientCollection.Find(c => c.Id == t.Client.Id).ToList() + select new { t, c }; + + //ВСЁ ГОТОВО ДЛЯ СЛЕДУЮЩЕГО ЗАМЕРА + // 999999.0 + + foreach (var element in firstJoin) + { + var trucking = truckingCollection.Find(x => x.Id == element.t.Id).FirstOrDefault(); + + trucking.Update(new TruckingBindingModel + { + Price = 1200000.0, + DateStart = element.t.DateStart, + DateEnd = element.t.DateEnd, + }); + + var filter = Builders.Filter.Eq("Id", element.t.Id); + truckingCollection.ReplaceOne(filter, trucking, new ReplaceOptions { IsUpsert = true }); + } + + stopwatch.Stop(); + + return stopwatch.ElapsedMilliseconds.ToString(); } public TruckingViewModel? GetElement(TruckingSearchModel model) @@ -126,14 +161,61 @@ namespace TransportCompamyMongoDBImplementer.Implements public string TestGetFullList() { - //может и надо сделать - throw new NotImplementedException(); + var truckingCollection = context.ConnectToMongo("trucking"); + + string result = null; + + //для замера времени считывания из бд + Stopwatch stopwatch = new(); + + stopwatch.Start(); + + List list = truckingCollection.Find(_ => true) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + + stopwatch.Stop(); + + result = list.Count.ToString(); + + list.Clear(); + + return result + " " + stopwatch.ElapsedMilliseconds.ToString(); } public string TestRandomInsert(int count, List clients, List cargos, List transports, List transportations) { - //может и надо сделать - throw new NotImplementedException(); + var truckingCollection = context.ConnectToMongo("trucking"); + + Random rnd = new Random(DateTime.Now.ToString().GetHashCode()); + + //старт замера времени добавления в бд + Stopwatch stopwatch = new(); + + stopwatch.Start(); + + for (int i = 0; i < count; i++) + { + DateTime dateStart = new(rnd.Next(1991, 2023), rnd.Next(1, 12), rnd.Next(1, 28)); + DateTime dateEnd = dateStart.AddDays(20); + + var model = Trucking.Create(context, new() + { + Client = clients[rnd.Next(0, clients.Count)].MongoId, + Cargo = cargos[rnd.Next(0, cargos.Count)].MongoId, + Transport = transports[rnd.Next(0, transports.Count)].MongoId, + DateStart = dateStart, + DateEnd = dateEnd, + Price = clients.Count * rnd.Next(100, 5000) + }); + + truckingCollection.InsertOne(model); + } + + stopwatch.Stop(); + + return stopwatch.ElapsedMilliseconds.ToString(); } public TruckingViewModel? Update(TruckingBindingModel model) diff --git a/TransportCompany/TransportCompany/FormTransferData.cs b/TransportCompany/TransportCompany/FormTransferData.cs index a9e4b24..ba26408 100644 --- a/TransportCompany/TransportCompany/FormTransferData.cs +++ b/TransportCompany/TransportCompany/FormTransferData.cs @@ -36,7 +36,7 @@ namespace TransportCompany private void ButtonStartTransfer_Click(object sender, EventArgs e) { - var soundPlayer = new SoundPlayer(@"C:\Users\Programmist73\Desktop\Практика\2-й курс\4-й семестр\СУБД\Лаб. раб. №8\uda_requie.wav"); + var soundPlayer = new SoundPlayer(@"C:\Users\Programmist73\Desktop\Практика\2-й курс\4-й семестр\СУБД\Лаб. раб. №8\led-tronulsya.wav"); soundPlayer.PlaySync(); // can also use soundPlayer.PlaySync()