From 0a3d0f073fde7574239b9a41cf2e036e0a88132c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=20=D0=94?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=BB=D0=BE=D0=B2?= Date: Mon, 20 May 2024 17:19:20 +0400 Subject: [PATCH] =?UTF-8?q?1000=20=D0=BF=D0=BE=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WorkAbstractions/IAuthorWork.cs | 2 ++ .../WorkImplementation/AuthorWork.cs | 13 +++++++++++++ NewsBlog/NewsBlogView/FormMain.cs | 16 ++++++++-------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/NewsBlog/NewsBlogAbstractions/WorkAbstractions/IAuthorWork.cs b/NewsBlog/NewsBlogAbstractions/WorkAbstractions/IAuthorWork.cs index c07fdab..b06610e 100644 --- a/NewsBlog/NewsBlogAbstractions/WorkAbstractions/IAuthorWork.cs +++ b/NewsBlog/NewsBlogAbstractions/WorkAbstractions/IAuthorWork.cs @@ -15,6 +15,8 @@ namespace NewsBlogAbstractions.WorkAbstractions Author? Create(Author author); + Author? CreateId(Author author); + Author? Update(Author author); Author? Delete(int id); diff --git a/NewsBlog/NewsBlogDatabaseImplementation/WorkImplementation/AuthorWork.cs b/NewsBlog/NewsBlogDatabaseImplementation/WorkImplementation/AuthorWork.cs index de655dd..d996345 100644 --- a/NewsBlog/NewsBlogDatabaseImplementation/WorkImplementation/AuthorWork.cs +++ b/NewsBlog/NewsBlogDatabaseImplementation/WorkImplementation/AuthorWork.cs @@ -23,6 +23,19 @@ namespace NewsBlogDatabaseImplementation.WorkImplementation return author; } + public Author? CreateId(Author author) + { + using var con = SqlConnection.GetConnection(); + con.Open(); + using var cmd = new NpgsqlCommand("INSERT INTO author (author_id, name, description, phone) VALUES (@Author_id, @Name, @Description, @Phone)", con); + cmd.Parameters.AddWithValue("@Author_id", author.Id); + cmd.Parameters.AddWithValue("@Name", author.Name); + cmd.Parameters.AddWithValue("@Description", author.Description); + cmd.Parameters.AddWithValue("@Phone", author.Phone); + cmd.ExecuteNonQuery(); + return author; + } + public Author? Delete(int id) { var element = Get(id); diff --git a/NewsBlog/NewsBlogView/FormMain.cs b/NewsBlog/NewsBlogView/FormMain.cs index 6054b70..0ca8c5e 100644 --- a/NewsBlog/NewsBlogView/FormMain.cs +++ b/NewsBlog/NewsBlogView/FormMain.cs @@ -66,11 +66,12 @@ namespace NewsBlogView { Author author = new() { + Id = i + 1000, Name = "ФИО " + i, Description = "Описание " + i, Phone = "Номер " + i }; - authorLogic.Create(author); + authorLogic.CreateId(author); } DateTime endTime = DateTime.Now; @@ -84,7 +85,8 @@ namespace NewsBlogView if (service is IAuthorWork authorLogic) { DateTime startTime = DateTime.Now; - authorLogic.GetAll(); + for (int i =0; i < 1000; i++) + authorLogic.Get(i + 1000); DateTime endTime = DateTime.Now; labelTest.Text = $"Получение 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд"; @@ -96,13 +98,12 @@ namespace NewsBlogView var service = Program.ServiceProvider?.GetService(typeof(IAuthorWork)); if (service is IAuthorWork authorLogic) { - List ids = authorLogic.GetAll().Select(area => area.Id).ToList(); DateTime startTime = DateTime.Now; - for (int i = 0; i < ids.Count; i++) + for (int i = 0; i < 1000; i++) { Author author = new() { - Id = ids[i], + Id = i + 1000, Name = "ФИО " + i + 2000, Description = "Описание " + i + 2000, Phone = "Номер " + i + 2000 @@ -120,11 +121,10 @@ namespace NewsBlogView var service = Program.ServiceProvider?.GetService(typeof(IAuthorWork)); if (service is IAuthorWork authorLogic) { - List ids = authorLogic.GetAll().Select(area => area.Id).ToList(); DateTime startTime = DateTime.Now; - for (int i = 0; i < ids.Count; i++) + for (int i = 0; i < 1000; i++) { - authorLogic.Delete(ids[i]); + authorLogic.Delete(i + 1000); } DateTime endTime = DateTime.Now;