From 7c0760fdba29204c2d885e76f62b55674025568c Mon Sep 17 00:00:00 2001 From: dasha Date: Sat, 6 May 2023 21:47:57 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B1=D0=B1=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BeautySaloon/BeautySaloon.sln | 2 +- .../Employee.cs | 8 +- .../Implements/ClientStorage.cs | 4 +- .../Implements/EmployeeStorage.cs | 4 +- .../Implements/OrderStorage.cs | 6 +- .../Implements/PositionStorage.cs | 4 +- .../Implements/ServiceStorage.cs | 22 ++- .../{NewdbContext.cs => MongoDBContext.cs} | 10 +- .../Order.cs | 8 +- .../BeautySaloonView/FormClientOrders.cs | 3 +- .../BeautySaloonView/FormMain.Designer.cs | 64 ++++--- BeautySaloon/BeautySaloonView/FormMain.cs | 9 + BeautySaloon/BeautySaloonView/FormPosition.cs | 1 - .../BeautySaloonView/FormReportServices.cs | 2 - BeautySaloon/BeautySaloonView/FormTest.cs | 6 +- .../BeautySaloonView/FormTransfer.Designer.cs | 77 ++++++++ BeautySaloon/BeautySaloonView/FormTransfer.cs | 170 ++++++++++++++++++ .../BeautySaloonView/FormTransfer.resx | 60 +++++++ BeautySaloon/BeautySaloonView/Program.cs | 1 + BeautySaloon/ConsoleTransfer/App.config | 9 + .../ConsoleTransfer/ConsoleTransfer.csproj | 15 ++ BeautySaloon/ConsoleTransfer/Program.cs | 16 ++ 22 files changed, 440 insertions(+), 61 deletions(-) rename BeautySaloon/BeautySaloonNoSQLDatabaseImplement/{NewdbContext.cs => MongoDBContext.cs} (84%) create mode 100644 BeautySaloon/BeautySaloonView/FormTransfer.Designer.cs create mode 100644 BeautySaloon/BeautySaloonView/FormTransfer.cs create mode 100644 BeautySaloon/BeautySaloonView/FormTransfer.resx create mode 100644 BeautySaloon/ConsoleTransfer/App.config create mode 100644 BeautySaloon/ConsoleTransfer/ConsoleTransfer.csproj create mode 100644 BeautySaloon/ConsoleTransfer/Program.cs diff --git a/BeautySaloon/BeautySaloon.sln b/BeautySaloon/BeautySaloon.sln index c2d5669..e6d39ce 100644 --- a/BeautySaloon/BeautySaloon.sln +++ b/BeautySaloon/BeautySaloon.sln @@ -13,7 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeautySaloonBusinessLogic", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeautySaloonDatabaseImplement", "BeautySaloonDatabaseImplement\BeautySaloonDatabaseImplement.csproj", "{BB7AD640-FF4A-415B-A09B-BB802D64CE27}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeautySaloonNoSQLDatabaseImplement", "BeautySaloonNoSQLDatabaseImplement\BeautySaloonNoSQLDatabaseImplement.csproj", "{153FD23E-4112-4C64-B270-914A6F17C7FE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeautySaloonNoSQLDatabaseImplement", "BeautySaloonNoSQLDatabaseImplement\BeautySaloonNoSQLDatabaseImplement.csproj", "{153FD23E-4112-4C64-B270-914A6F17C7FE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Employee.cs b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Employee.cs index 643daf9..4ab87ab 100644 --- a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Employee.cs +++ b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Employee.cs @@ -28,7 +28,7 @@ namespace BeautySaloonNoSQLDatabaseImplement public string Phone { get; set; } = string.Empty; [BsonElement("position")] - public string Position { get; set; } = string.Empty; + public string PositionName { get; set; } = string.Empty; [BsonIgnore] public int PositionId { get; set; } @@ -47,7 +47,7 @@ namespace BeautySaloonNoSQLDatabaseImplement Patronymic = model.Patronymic, Phone = model.Phone, PositionId = model.PositionId, - Position = model.PositionName + PositionName = model.PositionName }; } @@ -62,7 +62,7 @@ namespace BeautySaloonNoSQLDatabaseImplement Patronymic = model.Patronymic; Phone = model.Phone; PositionId = model.PositionId; - Position = model.PositionName; + PositionName = model.PositionName; } public EmployeeViewModel GetViewModel => new() @@ -73,7 +73,7 @@ namespace BeautySaloonNoSQLDatabaseImplement Patronymic = Patronymic, Phone = Phone, PositionId = PositionId, - PositionName = Position, + PositionName = PositionName, FIO = Name + ' ' + Surname + ' ' + Patronymic, }; } diff --git a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/ClientStorage.cs b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/ClientStorage.cs index 6fe041e..dbab936 100644 --- a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/ClientStorage.cs +++ b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/ClientStorage.cs @@ -9,10 +9,10 @@ namespace BeautySaloonNoSQLDatabaseImplement.Implements { public class ClientStorage : IClientStorage { - private readonly NewdbContext _source; + private readonly MongoDBContext _source; public ClientStorage() { - _source = NewdbContext.GetInstance(); + _source = MongoDBContext.GetInstance(); } public ClientViewModel? Delete(ClientBindingModel model) { diff --git a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/EmployeeStorage.cs b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/EmployeeStorage.cs index 7fadb75..8fd34e5 100644 --- a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/EmployeeStorage.cs +++ b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/EmployeeStorage.cs @@ -10,10 +10,10 @@ namespace BeautySaloonNoSQLDatabaseImplement.Implements { public class EmployeeStorage : IEmployeeStorage { - private readonly NewdbContext _source; + private readonly MongoDBContext _source; public EmployeeStorage() { - _source = NewdbContext.GetInstance(); + _source = MongoDBContext.GetInstance(); } public EmployeeViewModel? Delete(EmployeeBindingModel model) { diff --git a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/OrderStorage.cs b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/OrderStorage.cs index 7e3c076..70e0036 100644 --- a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/OrderStorage.cs +++ b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/OrderStorage.cs @@ -9,10 +9,10 @@ namespace BeautySaloonNoSQLDatabaseImplement.Implements { public class OrderStorage : IOrderStorage { - private readonly NewdbContext _source; + private readonly MongoDBContext _source; public OrderStorage() { - _source = NewdbContext.GetInstance(); + _source = MongoDBContext.GetInstance(); } public OrderViewModel? Delete(OrderBindingModel model) { @@ -57,7 +57,7 @@ namespace BeautySaloonNoSQLDatabaseImplement.Implements public List GetFullList() { var filterDefinition = Builders.Filter.Empty; - return _source.Orders.Find(filterDefinition).ToList().Select(x => x.GetViewModel).ToList(); + return _source.Orders.Find(filterDefinition).ToList().Select(x => x.GetViewModel).ToList().OrderByDescending(x => x.Date).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) diff --git a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/PositionStorage.cs b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/PositionStorage.cs index aa83637..142e9a5 100644 --- a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/PositionStorage.cs +++ b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/PositionStorage.cs @@ -10,10 +10,10 @@ namespace BeautySaloonNoSQLDatabaseImplement.Implements { public class PositionStorage : IPositionStorage { - private readonly NewdbContext _source; + private readonly MongoDBContext _source; public PositionStorage() { - _source = NewdbContext.GetInstance(); + _source = MongoDBContext.GetInstance(); } public PositionViewModel? Delete(PositionBindingModel model) { diff --git a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/ServiceStorage.cs b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/ServiceStorage.cs index 57db240..3c00d4b 100644 --- a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/ServiceStorage.cs +++ b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Implements/ServiceStorage.cs @@ -10,10 +10,10 @@ namespace BeautySaloonNoSQLDatabaseImplement.Implements { public class ServiceStorage : IServiceStorage { - private readonly NewdbContext _source; + private readonly MongoDBContext _source; public ServiceStorage() { - _source = NewdbContext.GetInstance(); + _source = MongoDBContext.GetInstance(); } public ServiceViewModel? Delete(ServiceBindingModel model) { @@ -66,10 +66,20 @@ namespace BeautySaloonNoSQLDatabaseImplement.Implements public List ReadMostPopular() { - /*var filterDefinition = Builders.Filter.Empty; - _source.Orders.Find(filterDefinition).ToList().Select(x => x.ServiceOrders) - */ - return new(); + var filterDefinition = Builders.Filter.Empty; + var result = _source.Orders + .Find(filterDefinition) + .ToList() + .SelectMany(x => x.ServiceOrders) + .GroupBy(x => x.Service.Name) + .Select(x => new ReportViewModel() + { + Name = x.Key, + Sum = x.Sum(x => x.Service.Price) + }) + .OrderByDescending(x => x.Sum) + .ToList(); + return result; } public ServiceViewModel? Update(ServiceBindingModel model) diff --git a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/NewdbContext.cs b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/MongoDBContext.cs similarity index 84% rename from BeautySaloon/BeautySaloonNoSQLDatabaseImplement/NewdbContext.cs rename to BeautySaloon/BeautySaloonNoSQLDatabaseImplement/MongoDBContext.cs index e8d1193..f465754 100644 --- a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/NewdbContext.cs +++ b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/MongoDBContext.cs @@ -3,15 +3,15 @@ using System.Configuration; namespace BeautySaloonNoSQLDatabaseImplement { - public class NewdbContext + public class MongoDBContext { - private static NewdbContext? _instance; + private static MongoDBContext? _instance; public IMongoCollection Clients { get; set; } public IMongoCollection Orders { get; set; } public IMongoCollection Employees { get; set; } public IMongoCollection Services { get; set; } public IMongoCollection Positions { get; set; } - private NewdbContext() + private MongoDBContext() { var connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnection"].ConnectionString; var databaseName = MongoUrl.Create(connectionString).DatabaseName; @@ -24,11 +24,11 @@ namespace BeautySaloonNoSQLDatabaseImplement Services = database.GetCollection("services"); Positions = database.GetCollection("positions"); } - public static NewdbContext GetInstance() + public static MongoDBContext GetInstance() { if (_instance == null) { - _instance = new NewdbContext(); + _instance = new MongoDBContext(); } return _instance; } diff --git a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Order.cs b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Order.cs index 23fae20..abe913f 100644 --- a/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Order.cs +++ b/BeautySaloon/BeautySaloonNoSQLDatabaseImplement/Order.cs @@ -48,7 +48,7 @@ namespace BeautySaloonNoSQLDatabaseImplement { if (_client == null) { - _client = NewdbContext.GetInstance().Clients + _client = MongoDBContext.GetInstance().Clients .Find(new BsonDocument("id", ClientId)).FirstOrDefault(); } return _client; @@ -61,7 +61,7 @@ namespace BeautySaloonNoSQLDatabaseImplement { if (_employee == null) { - _employee = NewdbContext.GetInstance().Employees + _employee = MongoDBContext.GetInstance().Employees .Find(new BsonDocument("id", EmployeeId)).FirstOrDefault(); } return _employee; @@ -102,9 +102,9 @@ namespace BeautySaloonNoSQLDatabaseImplement EmployeeId = model.EmployeeId, ServiceOrders = model.OrderServices.Select(x => new ServiceOrder { - Service = NewdbContext.GetInstance().Services.Find(new BsonDocument("id", x.Key)).FirstOrDefault(), + Service = MongoDBContext.GetInstance().Services.Find(new BsonDocument("id", x.Key)).FirstOrDefault(), Date = x.Value.Item1, - Employee = NewdbContext.GetInstance().Employees.Find(new BsonDocument("id", x.Value.Item3)).FirstOrDefault(), + Employee = MongoDBContext.GetInstance().Employees.Find(new BsonDocument("id", x.Value.Item3)).FirstOrDefault(), }).ToList() }; } diff --git a/BeautySaloon/BeautySaloonView/FormClientOrders.cs b/BeautySaloon/BeautySaloonView/FormClientOrders.cs index 504b455..92b60c8 100644 --- a/BeautySaloon/BeautySaloonView/FormClientOrders.cs +++ b/BeautySaloon/BeautySaloonView/FormClientOrders.cs @@ -1,5 +1,4 @@ -using BeautySaloonContracts.BindingModels; -using BeautySaloonContracts.BusinessLogicsContracts; +using BeautySaloonContracts.BusinessLogicsContracts; using BeautySaloonContracts.SearchModels; namespace BeautySaloonView diff --git a/BeautySaloon/BeautySaloonView/FormMain.Designer.cs b/BeautySaloon/BeautySaloonView/FormMain.Designer.cs index 9936a33..c31bd9b 100644 --- a/BeautySaloon/BeautySaloonView/FormMain.Designer.cs +++ b/BeautySaloon/BeautySaloonView/FormMain.Designer.cs @@ -35,10 +35,11 @@ this.услугиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.сотрудникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.buttonUpdate = new System.Windows.Forms.Button(); - this.buttonTest = new System.Windows.Forms.Button(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.услугиToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonTest = new System.Windows.Forms.Button(); + this.buttonTransfer = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -105,28 +106,6 @@ this.клиентыToolStripMenuItem.Text = "Клиенты"; this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click); // - // buttonUpdate - // - this.buttonUpdate.Location = new System.Drawing.Point(917, 225); - this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonUpdate.Name = "buttonUpdate"; - this.buttonUpdate.Size = new System.Drawing.Size(116, 58); - this.buttonUpdate.TabIndex = 17; - this.buttonUpdate.Text = "Обновить"; - this.buttonUpdate.UseVisualStyleBackColor = true; - this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); - // - // buttonTest - // - this.buttonTest.Location = new System.Drawing.Point(917, 287); - this.buttonTest.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonTest.Name = "buttonTest"; - this.buttonTest.Size = new System.Drawing.Size(116, 58); - this.buttonTest.TabIndex = 18; - this.buttonTest.Text = "Тесты"; - this.buttonTest.UseVisualStyleBackColor = true; - this.buttonTest.Click += new System.EventHandler(this.ButtonTest_Click); - // // отчетыToolStripMenuItem // this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -138,15 +117,49 @@ // услугиToolStripMenuItem1 // this.услугиToolStripMenuItem1.Name = "услугиToolStripMenuItem1"; - this.услугиToolStripMenuItem1.Size = new System.Drawing.Size(180, 22); + this.услугиToolStripMenuItem1.Size = new System.Drawing.Size(112, 22); this.услугиToolStripMenuItem1.Text = "Услуги"; this.услугиToolStripMenuItem1.Click += new System.EventHandler(this.ReportServicesToolStripMenuItem_Click); // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(917, 188); + this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(116, 58); + this.buttonUpdate.TabIndex = 17; + this.buttonUpdate.Text = "Обновить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonTest + // + this.buttonTest.Location = new System.Drawing.Point(917, 250); + this.buttonTest.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonTest.Name = "buttonTest"; + this.buttonTest.Size = new System.Drawing.Size(116, 58); + this.buttonTest.TabIndex = 18; + this.buttonTest.Text = "Тесты"; + this.buttonTest.UseVisualStyleBackColor = true; + this.buttonTest.Click += new System.EventHandler(this.ButtonTest_Click); + // + // buttonTransfer + // + this.buttonTransfer.Location = new System.Drawing.Point(917, 312); + this.buttonTransfer.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonTransfer.Name = "buttonTransfer"; + this.buttonTransfer.Size = new System.Drawing.Size(116, 58); + this.buttonTransfer.TabIndex = 19; + this.buttonTransfer.Text = "PostgreSQL -> MongoDB"; + this.buttonTransfer.UseVisualStyleBackColor = true; + this.buttonTransfer.Click += new System.EventHandler(this.ButtonTransfer_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1037, 539); + this.Controls.Add(this.buttonTransfer); this.Controls.Add(this.buttonTest); this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.dataGridView); @@ -177,5 +190,6 @@ private Button buttonTest; private ToolStripMenuItem отчетыToolStripMenuItem; private ToolStripMenuItem услугиToolStripMenuItem1; + private Button buttonTransfer; } } \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormMain.cs b/BeautySaloon/BeautySaloonView/FormMain.cs index eba7d0d..acc0ff7 100644 --- a/BeautySaloon/BeautySaloonView/FormMain.cs +++ b/BeautySaloon/BeautySaloonView/FormMain.cs @@ -90,5 +90,14 @@ namespace BeautySaloonView form.ShowDialog(); } } + + private void ButtonTransfer_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTransfer)); + if (service is FormTransfer form) + { + form.ShowDialog(); + } + } } } \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormPosition.cs b/BeautySaloon/BeautySaloonView/FormPosition.cs index 90af17e..bfd75c0 100644 --- a/BeautySaloon/BeautySaloonView/FormPosition.cs +++ b/BeautySaloon/BeautySaloonView/FormPosition.cs @@ -1,7 +1,6 @@ using BeautySaloonContracts.BindingModels; using BeautySaloonContracts.BusinessLogicsContracts; using BeautySaloonContracts.SearchModels; -using System.Windows.Forms; namespace BeautySaloonView { diff --git a/BeautySaloon/BeautySaloonView/FormReportServices.cs b/BeautySaloon/BeautySaloonView/FormReportServices.cs index dd12bc8..13a9e84 100644 --- a/BeautySaloon/BeautySaloonView/FormReportServices.cs +++ b/BeautySaloon/BeautySaloonView/FormReportServices.cs @@ -1,6 +1,4 @@ using BeautySaloonContracts.BusinessLogicsContracts; -using BeautySaloonContracts.SearchModels; -using System.Windows.Forms; namespace BeautySaloonView { diff --git a/BeautySaloon/BeautySaloonView/FormTest.cs b/BeautySaloon/BeautySaloonView/FormTest.cs index 90bb568..40303b0 100644 --- a/BeautySaloon/BeautySaloonView/FormTest.cs +++ b/BeautySaloon/BeautySaloonView/FormTest.cs @@ -4,6 +4,7 @@ using BeautySaloonContracts.SearchModels; using BeautySaloonContracts.ViewModels; using BeautySaloonDatabaseImplement; using BeautySaloonDataModels; +using BeautySaloonNoSQLDatabaseImplement; using System.Diagnostics; using System.Text; @@ -210,7 +211,7 @@ namespace BeautySaloonView case "Сложный запрос": Stopwatch stopwatch3 = new Stopwatch(); stopwatch3.Start(); - using (NewdbContext db = new NewdbContext()) + /*using (NewdbContext db = new NewdbContext()) { var users = (from o in db.Orders join c in db.Clients on o.ClientId equals c.Id @@ -227,7 +228,8 @@ namespace BeautySaloonView Date = o.Date, Sum = o.Sum }).ToList(); - } + }*/ + var result = _OLogic.ReadList(null)?.OrderByDescending(x => x.Date).OrderBy(x => x.Sum).ToList(); stopwatch3.Stop(); TimeSpan ts3 = stopwatch3.Elapsed; string elapsedTime3 = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", diff --git a/BeautySaloon/BeautySaloonView/FormTransfer.Designer.cs b/BeautySaloon/BeautySaloonView/FormTransfer.Designer.cs new file mode 100644 index 0000000..eaab376 --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormTransfer.Designer.cs @@ -0,0 +1,77 @@ +namespace BeautySaloonView +{ + partial class FormTransfer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.comboBox = new System.Windows.Forms.ComboBox(); + this.button = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBox + // + this.comboBox.FormattingEnabled = true; + this.comboBox.Items.AddRange(new object[] { + "клиенты", + "сотрудники", + "услуги", + "должности", + "заказы"}); + this.comboBox.Location = new System.Drawing.Point(12, 12); + this.comboBox.Name = "comboBox"; + this.comboBox.Size = new System.Drawing.Size(407, 23); + this.comboBox.TabIndex = 0; + // + // button + // + this.button.Location = new System.Drawing.Point(12, 46); + this.button.Name = "button"; + this.button.Size = new System.Drawing.Size(407, 23); + this.button.TabIndex = 1; + this.button.Text = "А ну давай"; + this.button.UseVisualStyleBackColor = true; + this.button.Click += new System.EventHandler(this.Button_Click); + // + // FormTransfer + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(431, 81); + this.Controls.Add(this.button); + this.Controls.Add(this.comboBox); + this.Name = "FormTransfer"; + this.Text = "FormTransfer"; + this.ResumeLayout(false); + + } + + #endregion + + private ComboBox comboBox; + private Button button; + } +} \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/FormTransfer.cs b/BeautySaloon/BeautySaloonView/FormTransfer.cs new file mode 100644 index 0000000..8d1fbc7 --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormTransfer.cs @@ -0,0 +1,170 @@ +using BeautySaloonContracts.BusinessLogicsContracts; +using BeautySaloonDatabaseImplement; +using BeautySaloonNoSQLDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using MongoDB.Bson; +using System.Data; + +namespace BeautySaloonView +{ + public partial class FormTransfer : Form + { + private readonly IOrderLogic _logic; + public FormTransfer(IOrderLogic logic) + { + InitializeComponent(); + _logic = logic; + } + + private void Button_Click(object sender, EventArgs e) + { + switch (comboBox.SelectedItem) + { + case "клиенты": + TransferClients(); + break; + case "сотрудники": + TransferEmployees(); + break; + case "должности": + TransferPositions(); + break; + case "услуги": + TransferServices(); + break; + case "заказы": + TransferOrders(); + break; + } + } + + private void TransferClients() + { + try + { + using var pgsqlContext = new NewdbContext(); + var pgsqlClients = pgsqlContext.Clients; + var mongoClients = MongoDBContext.GetInstance().Clients; + mongoClients.DeleteMany(new BsonDocument()); + mongoClients.InsertMany(pgsqlClients + .Select(model => BeautySaloonNoSQLDatabaseImplement.Client.Create(new() + { + Id = model.Id, + Name = model.Name, + Surname = model.Surname, + Patronymic = model.Patronymic ?? string.Empty, + Phone = model.Phone + }))); + MessageBox.Show("Трансфер прошел успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception e) + { + MessageBox.Show(e.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void TransferPositions() + { + try + { + using var pgsqlContext = new NewdbContext(); + var pgsqlPositions = pgsqlContext.Positions; + var mongoPositions = MongoDBContext.GetInstance().Positions; + mongoPositions.DeleteMany(new BsonDocument()); + mongoPositions.InsertMany(pgsqlPositions + .Select(model => BeautySaloonNoSQLDatabaseImplement.Position.Create(new() + { + Id = model.Id, + Name = model.Name + }))); + MessageBox.Show("Трансфер прошел успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception e) + { + MessageBox.Show(e.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void TransferServices() + { + try + { + using var pgsqlContext = new NewdbContext(); + var pgsqlServices = pgsqlContext.Services; + var mongoServices = MongoDBContext.GetInstance().Services; + mongoServices.DeleteMany(new BsonDocument()); + mongoServices.InsertMany(pgsqlServices + .Select(model => BeautySaloonNoSQLDatabaseImplement.Service.Create(new() + { + Id = model.Id, + Name = model.Name, + Price = model.Price + }))); + MessageBox.Show("Трансфер прошел успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception e) + { + MessageBox.Show(e.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void TransferEmployees() + { + try + { + using var pgsqlContext = new NewdbContext(); + var pgsqlEmployees = pgsqlContext.Employees; + var mongoEmployees = MongoDBContext.GetInstance().Employees; + mongoEmployees.DeleteMany(new BsonDocument()); + mongoEmployees.InsertMany(pgsqlEmployees + .Select(model => BeautySaloonNoSQLDatabaseImplement.Employee.Create(new() + { + Id = model.Id, + Name = model.Name, + Surname = model.Surname, + Patronymic = model.Patronymic, + Phone = model.Phone, + PositionId = model.PositionId, + PositionName = model.Position.Name + }))); + MessageBox.Show("Трансфер прошел успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception e) + { + MessageBox.Show(e.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void TransferOrders() + { + try + { + var mongoOrders = MongoDBContext.GetInstance().Orders; + mongoOrders.DeleteMany(new BsonDocument()); + using var context = new NewdbContext(); + var orders = context.Orders + .Include(x => x.Employee) + .Include(x => x.Client) + .Include(x => x.ServiceOrders) + .ThenInclude(x => x.Service) + .Select(x => x.GetViewModel) + .ToList(); + + mongoOrders.InsertMany(orders + .Select(model => BeautySaloonNoSQLDatabaseImplement.Order.Create(new() + { + Id = model.Id, + Date = model.Date, + Sum = model.Sum, + ClientId = model.ClientId, + EmployeeId = model.EmployeeId, + OrderServices = model.OrderServices + }))); + MessageBox.Show("Трансфер прошел успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception e) + { + MessageBox.Show(e.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/BeautySaloon/BeautySaloonView/FormTransfer.resx b/BeautySaloon/BeautySaloonView/FormTransfer.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/BeautySaloon/BeautySaloonView/FormTransfer.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BeautySaloon/BeautySaloonView/Program.cs b/BeautySaloon/BeautySaloonView/Program.cs index 8cdff29..ea531d5 100644 --- a/BeautySaloon/BeautySaloonView/Program.cs +++ b/BeautySaloon/BeautySaloonView/Program.cs @@ -55,6 +55,7 @@ namespace BeautySaloonView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/BeautySaloon/ConsoleTransfer/App.config b/BeautySaloon/ConsoleTransfer/App.config new file mode 100644 index 0000000..45a2e13 --- /dev/null +++ b/BeautySaloon/ConsoleTransfer/App.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/BeautySaloon/ConsoleTransfer/ConsoleTransfer.csproj b/BeautySaloon/ConsoleTransfer/ConsoleTransfer.csproj new file mode 100644 index 0000000..50a2609 --- /dev/null +++ b/BeautySaloon/ConsoleTransfer/ConsoleTransfer.csproj @@ -0,0 +1,15 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + diff --git a/BeautySaloon/ConsoleTransfer/Program.cs b/BeautySaloon/ConsoleTransfer/Program.cs new file mode 100644 index 0000000..1861591 --- /dev/null +++ b/BeautySaloon/ConsoleTransfer/Program.cs @@ -0,0 +1,16 @@ +using BeautySaloonDatabaseImplement; +using BeautySaloonDataModels; +using BeautySaloonNoSQLDatabaseImplement; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using MongoDB.Bson; +using MongoDB.Driver; + +namespace BeautySaloonDatabaseTransfer +{ + public class Program + { + + + + } +}