diff --git a/SoftwareInstallation/FormMain.Designer.cs b/SoftwareInstallation/FormMain.Designer.cs index 82f47a0..0afadc6 100644 --- a/SoftwareInstallation/FormMain.Designer.cs +++ b/SoftwareInstallation/FormMain.Designer.cs @@ -1,4 +1,4 @@ -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { partial class FormMain { @@ -20,203 +20,221 @@ base.Dispose(disposing); } - #region Windows Form Designer generated code + #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() - { - menuStrip1 = new MenuStrip(); - справочникToolStripMenuItem = new ToolStripMenuItem(); - компонентыToolStripMenuItem = new ToolStripMenuItem(); - изделияToolStripMenuItem = new ToolStripMenuItem(); - отчетыToolStripMenuItem = new ToolStripMenuItem(); - списокИзделийToolStripMenuItem = new ToolStripMenuItem(); - изделияПоКомпонентамToolStripMenuItem = new ToolStripMenuItem(); - списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); - dataGridView = new DataGridView(); - buttonCreateOrder = new Button(); - buttonTakeOrderInWork = new Button(); - buttonOrderReady = new Button(); - buttonIssuedOrder = new Button(); - buttonRef = new Button(); - клиентыToolStripMenuItem = new ToolStripMenuItem(); - menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // menuStrip1 - // - menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { справочникToolStripMenuItem, отчетыToolStripMenuItem }); - menuStrip1.Location = new Point(0, 0); - menuStrip1.Name = "menuStrip1"; - menuStrip1.Padding = new Padding(6, 3, 0, 3); - menuStrip1.Size = new Size(1256, 30); - menuStrip1.TabIndex = 0; - menuStrip1.Text = "menuStrip1"; - // - // справочникToolStripMenuItem - // - справочникToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, клиентыToolStripMenuItem }); - справочникToolStripMenuItem.Name = "справочникToolStripMenuItem"; - справочникToolStripMenuItem.Size = new Size(117, 24); - справочникToolStripMenuItem.Text = "Справочники"; - // - // компонентыToolStripMenuItem - // - компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(224, 26); - компонентыToolStripMenuItem.Text = "Компоненты"; - компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; - // - // изделияToolStripMenuItem - // - изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - изделияToolStripMenuItem.Size = new Size(224, 26); - изделияToolStripMenuItem.Text = "ПО"; - изделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click; - // - // отчетыToolStripMenuItem - // - отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокИзделийToolStripMenuItem, изделияПоКомпонентамToolStripMenuItem, списокЗаказовToolStripMenuItem }); - отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - отчетыToolStripMenuItem.Size = new Size(73, 24); - отчетыToolStripMenuItem.Text = "Отчеты"; - // - // списокИзделийToolStripMenuItem - // - списокИзделийToolStripMenuItem.Name = "списокИзделийToolStripMenuItem"; - списокИзделийToolStripMenuItem.Size = new Size(240, 26); - списокИзделийToolStripMenuItem.Text = "Список компонентов"; - списокИзделийToolStripMenuItem.Click += списокИзделийToolStripMenuItem_Click; - // - // изделияПоКомпонентамToolStripMenuItem - // - изделияПоКомпонентамToolStripMenuItem.Name = "изделияПоКомпонентамToolStripMenuItem"; - изделияПоКомпонентамToolStripMenuItem.Size = new Size(240, 26); - изделияПоКомпонентамToolStripMenuItem.Text = "ПО по компонентам"; - изделияПоКомпонентамToolStripMenuItem.Click += компонентыПоИзделиямToolStripMenuItem_Click; - // - // списокЗаказовToolStripMenuItem - // - списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - списокЗаказовToolStripMenuItem.Size = new Size(240, 26); - списокЗаказовToolStripMenuItem.Text = "Список заказов"; - списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; - // - // dataGridView - // - dataGridView.AllowUserToAddRows = false; - dataGridView.AllowUserToDeleteRows = false; - dataGridView.BackgroundColor = Color.White; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 31); - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(984, 396); - dataGridView.TabIndex = 1; - // - // buttonCreateOrder - // - buttonCreateOrder.Location = new Point(991, 53); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(247, 29); - buttonCreateOrder.TabIndex = 2; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += ButtonCreateOrder_Click; - // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Location = new Point(991, 121); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(247, 29); - buttonTakeOrderInWork.TabIndex = 3; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; - // - // buttonOrderReady - // - buttonOrderReady.Location = new Point(991, 191); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(247, 29); - buttonOrderReady.TabIndex = 4; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += ButtonOrderReady_Click; - // - // buttonIssuedOrder - // - buttonIssuedOrder.Location = new Point(991, 255); - buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(247, 29); - buttonIssuedOrder.TabIndex = 5; - buttonIssuedOrder.Text = "Заказ выдан"; - buttonIssuedOrder.UseVisualStyleBackColor = true; - buttonIssuedOrder.Click += ButtonIssuedOrder_Click; - // - // buttonRef - // - buttonRef.Location = new Point(991, 309); - buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(247, 29); - buttonRef.TabIndex = 6; - buttonRef.Text = "Обновить список"; - buttonRef.UseVisualStyleBackColor = true; - buttonRef.Click += ButtonRef_Click; - // - // клиентыToolStripMenuItem - // - клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(224, 26); - клиентыToolStripMenuItem.Text = "Клиенты"; - клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1256, 427); - Controls.Add(buttonRef); - Controls.Add(buttonIssuedOrder); - Controls.Add(buttonOrderReady); - Controls.Add(buttonTakeOrderInWork); - Controls.Add(buttonCreateOrder); - Controls.Add(dataGridView); - Controls.Add(menuStrip1); - MainMenuStrip = menuStrip1; - Name = "FormMain"; - Text = "Установка ПО"; - Load += FormMain_Load; - menuStrip1.ResumeLayout(false); - menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain)); + toolStrip1 = new ToolStrip(); + toolStripDropDownButton1 = new ToolStripDropDownButton(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + ПутёвкиToolStripMenuItem = new ToolStripMenuItem(); + клиентыToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); + списокКомпонентовToolStripMenuItem = new ToolStripMenuItem(); + компонентыПоПутёвкамToolStripMenuItem = new ToolStripMenuItem(); + списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); + запускРаботToolStripMenuItem = new ToolStripMenuItem(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + dataGridView = new DataGridView(); + исполнителиToolStripMenuItem = new ToolStripMenuItem(); + toolStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // toolStrip1 + // + toolStrip1.ImageScalingSize = new Size(20, 20); + toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, отчетыToolStripMenuItem, запускРаботToolStripMenuItem }); + toolStrip1.Location = new Point(0, 0); + toolStrip1.Name = "toolStrip1"; + toolStrip1.Size = new Size(969, 25); + toolStrip1.TabIndex = 0; + toolStrip1.Text = "toolStrip1"; + // + // toolStripDropDownButton1 + // + toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; + toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, ПутёвкиToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem }); + toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image"); + toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; + toolStripDropDownButton1.Name = "toolStripDropDownButton1"; + toolStripDropDownButton1.Size = new Size(88, 22); + toolStripDropDownButton1.Text = "Справочник"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(180, 22); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; + // + // ПутёвкиToolStripMenuItem + // + ПутёвкиToolStripMenuItem.Name = "ПутёвкиToolStripMenuItem"; + ПутёвкиToolStripMenuItem.Size = new Size(180, 22); + ПутёвкиToolStripMenuItem.Text = "Туристич. путёвки"; + ПутёвкиToolStripMenuItem.Click += консервыToolStripMenuItem_Click; + // + // клиентыToolStripMenuItem + // + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(180, 22); + клиентыToolStripMenuItem.Text = "Клиенты"; + клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; + // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокКомпонентовToolStripMenuItem, компонентыПоПутёвкамToolStripMenuItem, списокЗаказовToolStripMenuItem }); + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(60, 25); + отчетыToolStripMenuItem.Text = "Отчеты"; + // + // списокКомпонентовToolStripMenuItem + // + списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem"; + списокКомпонентовToolStripMenuItem.Size = new Size(216, 22); + списокКомпонентовToolStripMenuItem.Text = "Список компонентов"; + списокКомпонентовToolStripMenuItem.Click += списокКомпонентовToolStripMenuItem_Click; + // + // компонентыПоПутёвкамToolStripMenuItem + // + компонентыПоПутёвкамToolStripMenuItem.Name = "компонентыПоПутёвкамToolStripMenuItem"; + компонентыПоПутёвкамToolStripMenuItem.Size = new Size(216, 22); + компонентыПоПутёвкамToolStripMenuItem.Text = "Компоненты по путёвкам"; + компонентыПоПутёвкамToolStripMenuItem.Click += компонентыПоПутёвкамToolStripMenuItem_Click; + // + // списокЗаказовToolStripMenuItem + // + списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; + списокЗаказовToolStripMenuItem.Size = new Size(216, 22); + списокЗаказовToolStripMenuItem.Text = "Список заказов"; + списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; + // + // запускРаботToolStripMenuItem + // + запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem"; + запускРаботToolStripMenuItem.Size = new Size(92, 25); + запускРаботToolStripMenuItem.Text = "Запуск работ"; + запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(800, 56); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(141, 24); + buttonCreateOrder.TabIndex = 1; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += buttonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(800, 100); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(141, 24); + buttonTakeOrderInWork.TabIndex = 2; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(800, 142); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(141, 24); + buttonOrderReady.TabIndex = 3; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += buttonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(800, 181); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(141, 24); + buttonIssuedOrder.TabIndex = 4; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += buttonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Location = new Point(800, 222); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(141, 24); + buttonRef.TabIndex = 5; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 26); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 24; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(763, 435); + dataGridView.TabIndex = 6; + // + // исполнителиToolStripMenuItem + // + исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + исполнителиToolStripMenuItem.Size = new Size(180, 22); + исполнителиToolStripMenuItem.Text = "Исполнители"; + исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(969, 461); + Controls.Add(dataGridView); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(toolStrip1); + Name = "FormMain"; + Text = "Туристическая фирма"; + Load += FormMain_Load; + toolStrip1.ResumeLayout(false); + toolStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private MenuStrip menuStrip1; - private ToolStripMenuItem справочникToolStripMenuItem; - private ToolStripMenuItem компонентыToolStripMenuItem; - private ToolStripMenuItem изделияToolStripMenuItem; - private DataGridView dataGridView; + private ToolStrip toolStrip1; private Button buttonCreateOrder; private Button buttonTakeOrderInWork; private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; + private DataGridView dataGridView; + private ToolStripDropDownButton toolStripDropDownButton1; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem ПутёвкиToolStripMenuItem; private ToolStripMenuItem отчетыToolStripMenuItem; - private ToolStripMenuItem списокИзделийToolStripMenuItem; - private ToolStripMenuItem изделияПоКомпонентамToolStripMenuItem; + private ToolStripMenuItem списокКомпонентовToolStripMenuItem; + private ToolStripMenuItem компонентыПоПутёвкамToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; - private ToolStripMenuItem клиентыToolStripMenuItem; - } + private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripMenuItem запускРаботToolStripMenuItem; + private ToolStripMenuItem исполнителиToolStripMenuItem; + } } \ No newline at end of file diff --git a/SoftwareInstallation/FormMain.cs b/SoftwareInstallation/FormMain.cs index 9acc75e..ab4935e 100644 --- a/SoftwareInstallation/FormMain.cs +++ b/SoftwareInstallation/FormMain.cs @@ -1,7 +1,6 @@ -using Microsoft.Extensions.Logging; -using SoftwareInstallationBusinessLogic.BusinessLogic; -using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.ComponentModel; @@ -11,186 +10,216 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using SoftwareInstallationBusinessLogic.BusinessLogic; +using SoftwareInstallationView; -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - _reportLogic = reportLogic; - } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - try - { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["SoftwareId"].Visible = false; - dataGridView.Columns["SoftwareName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormSoftwares)); - if (service is FormSoftwares form) - { - form.ShowDialog(); - } - } - private void ButtonCreateOrder_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = id - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { - Id = id - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonIssuedOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No{id}. Меняется статус на 'Выдан'", id); - try - { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel - { - Id = id - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ No{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonRef_Click(object sender, EventArgs e) - { - LoadData(); - } - private void списокИзделийToolStripMenuItem_Click(object sender, EventArgs e) - { - using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; - if (dialog.ShowDialog() == DialogResult.OK) - { - _reportLogic.SaveSoftwaresToWordFile(new ReportBindingModel { FileName = dialog.FileName }); - MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - } + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + private readonly IReportLogic _reportLogic; + private readonly IWorkProcess _workProcess; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + _reportLogic = reportLogic; + _workProcess = workProcess; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); - private void компонентыПоИзделиямToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportSoftwareComponents)); - if (service is FormReportSoftwareComponents form) - { - form.ShowDialog(); - } - } + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["SoftwareId"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; + dataGridView.Columns["SoftwareName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } - private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); - if (service is FormReportOrders form) - { - form.ShowDialog(); - } - } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + } + } + private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void консервыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSoftwares)); - private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = + if (service is FormSoftwares form) + { + form.ShowDialog(); + } + } + private void buttonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void buttonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id, + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void списокКомпонентовToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveSoftwaresToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + } + + private void компонентыПоПутёвкамToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = +Program.ServiceProvider?.GetService(typeof(FormReportSoftwareComponents)); + if (service is FormReportSoftwareComponents form) + { + form.ShowDialog(); + } + } + + private void списокЗаказовToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = +Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + if (service is FormReportOrders form) + { + form.ShowDialog(); + } + } + + private void клиентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClients)); - if (service is FormClients form) - { - form.ShowDialog(); - } - } - } + if (service is FormClients form) + { + form.ShowDialog(); + } + } + + private void запускРаботToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic +)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = +Program.ServiceProvider?.GetService(typeof(ImplementersForm)); + if (service is ImplementersForm form) + { + form.ShowDialog(); + } + } + } } diff --git a/SoftwareInstallation/FormMain.resx b/SoftwareInstallation/FormMain.resx index a0623c8..e226a59 100644 --- a/SoftwareInstallation/FormMain.resx +++ b/SoftwareInstallation/FormMain.resx @@ -117,7 +117,26 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + 56 + \ No newline at end of file diff --git a/SoftwareInstallation/ImplementerForm.Designer.cs b/SoftwareInstallation/ImplementerForm.Designer.cs new file mode 100644 index 0000000..7db51e5 --- /dev/null +++ b/SoftwareInstallation/ImplementerForm.Designer.cs @@ -0,0 +1,162 @@ +namespace SoftwareInstallation.Forms +{ + partial class ImplementerForm + { + /// + /// 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() + { + FIOTextBox = new TextBox(); + PasswordTextBox = new TextBox(); + QualificationTextBox = new TextBox(); + WorkExperienceTextBox = new TextBox(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + SaveButton = new Button(); + CancelButton = new Button(); + SuspendLayout(); + // + // FIOTextBox + // + FIOTextBox.Location = new Point(124, 19); + FIOTextBox.Name = "FIOTextBox"; + FIOTextBox.Size = new Size(411, 27); + FIOTextBox.TabIndex = 0; + // + // PasswordTextBox + // + PasswordTextBox.Location = new Point(124, 52); + PasswordTextBox.Name = "PasswordTextBox"; + PasswordTextBox.Size = new Size(411, 27); + PasswordTextBox.TabIndex = 1; + // + // QualificationTextBox + // + QualificationTextBox.Location = new Point(124, 85); + QualificationTextBox.Name = "QualificationTextBox"; + QualificationTextBox.Size = new Size(411, 27); + QualificationTextBox.TabIndex = 2; + // + // WorkExperienceTextBox + // + WorkExperienceTextBox.Location = new Point(124, 118); + WorkExperienceTextBox.Name = "WorkExperienceTextBox"; + WorkExperienceTextBox.Size = new Size(411, 27); + WorkExperienceTextBox.TabIndex = 3; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(9, 19); + label1.Name = "label1"; + label1.Size = new Size(42, 20); + label1.TabIndex = 4; + label1.Text = "ФИО"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(9, 52); + label2.Name = "label2"; + label2.Size = new Size(62, 20); + label2.TabIndex = 5; + label2.Text = "Пароль"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(9, 85); + label3.Name = "label3"; + label3.Size = new Size(111, 20); + label3.TabIndex = 6; + label3.Text = "Квалификация"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(9, 118); + label4.Name = "label4"; + label4.Size = new Size(99, 20); + label4.TabIndex = 7; + label4.Text = "Стаж работы"; + // + // SaveButton + // + SaveButton.Location = new Point(341, 151); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(94, 29); + SaveButton.TabIndex = 8; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; + // + // CancelButton + // + CancelButton.Location = new Point(441, 151); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(94, 29); + CancelButton.TabIndex = 9; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += CancelButton_Click; + // + // ImplementerForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(548, 186); + Controls.Add(CancelButton); + Controls.Add(SaveButton); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(WorkExperienceTextBox); + Controls.Add(QualificationTextBox); + Controls.Add(PasswordTextBox); + Controls.Add(FIOTextBox); + Name = "ImplementerForm"; + Text = "Исполнитель"; + Load += ImplementerForm_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox FIOTextBox; + private TextBox PasswordTextBox; + private TextBox QualificationTextBox; + private TextBox WorkExperienceTextBox; + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private Button SaveButton; + private Button CancelButton; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/ImplementerForm.cs b/SoftwareInstallation/ImplementerForm.cs new file mode 100644 index 0000000..2beeef2 --- /dev/null +++ b/SoftwareInstallation/ImplementerForm.cs @@ -0,0 +1,109 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SoftwareInstallation.Forms +{ + public partial class ImplementerForm : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public ImplementerForm(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ImplementerForm_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + FIOTextBox.Text = view.ImplementerFIO; + PasswordTextBox.Text = view.Password; + QualificationTextBox.Text = view.Qualification.ToString(); + WorkExperienceTextBox.Text = view.WorkExperience.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(FIOTextBox.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(PasswordTextBox.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = FIOTextBox.Text, + Password = PasswordTextBox.Text, + Qualification = Convert.ToInt32(QualificationTextBox.Text), + WorkExperience = Convert.ToInt32(WorkExperienceTextBox.Text), + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SoftwareInstallation/ImplementerForm.resx b/SoftwareInstallation/ImplementerForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SoftwareInstallation/ImplementerForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SoftwareInstallation/ImplementersForm.Designer.cs b/SoftwareInstallation/ImplementersForm.Designer.cs new file mode 100644 index 0000000..79a1d66 --- /dev/null +++ b/SoftwareInstallation/ImplementersForm.Designer.cs @@ -0,0 +1,114 @@ +namespace SoftwareInstallation.Forms +{ + partial class ImplementersForm + { + /// + /// 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() + { + dataGridView1 = new DataGridView(); + CreateButton = new Button(); + ChangeButton = new Button(); + DeleteButton = new Button(); + RefreshButton = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + SuspendLayout(); + // + // dataGridView1 + // + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Location = new Point(12, 12); + dataGridView1.Name = "dataGridView1"; + dataGridView1.RowHeadersWidth = 51; + dataGridView1.RowTemplate.Height = 29; + dataGridView1.Size = new Size(565, 426); + dataGridView1.TabIndex = 0; + // + // CreateButton + // + CreateButton.Location = new Point(583, 12); + CreateButton.Name = "CreateButton"; + CreateButton.Size = new Size(205, 29); + CreateButton.TabIndex = 1; + CreateButton.Text = "Создать"; + CreateButton.UseVisualStyleBackColor = true; + CreateButton.Click += CreateButton_Click; + // + // ChangeButton + // + ChangeButton.Location = new Point(583, 47); + ChangeButton.Name = "ChangeButton"; + ChangeButton.Size = new Size(205, 29); + ChangeButton.TabIndex = 2; + ChangeButton.Text = "Изменить"; + ChangeButton.UseVisualStyleBackColor = true; + ChangeButton.Click += ChangeButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(583, 82); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(205, 29); + DeleteButton.TabIndex = 3; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // RefreshButton + // + RefreshButton.Location = new Point(583, 117); + RefreshButton.Name = "RefreshButton"; + RefreshButton.Size = new Size(205, 29); + RefreshButton.TabIndex = 4; + RefreshButton.Text = "Обновить"; + RefreshButton.UseVisualStyleBackColor = true; + RefreshButton.Click += RefreshButton_Click; + // + // ImplementersForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(RefreshButton); + Controls.Add(DeleteButton); + Controls.Add(ChangeButton); + Controls.Add(CreateButton); + Controls.Add(dataGridView1); + Name = "ImplementersForm"; + Text = "Исполнители"; + Load += ImplementersForm_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView1; + private Button CreateButton; + private Button ChangeButton; + private Button DeleteButton; + private Button RefreshButton; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/ImplementersForm.cs b/SoftwareInstallation/ImplementersForm.cs new file mode 100644 index 0000000..b774070 --- /dev/null +++ b/SoftwareInstallation/ImplementersForm.cs @@ -0,0 +1,127 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using SoftwareInstallationView; + +namespace SoftwareInstallation.Forms +{ + public partial class ImplementersForm : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public ImplementersForm(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ImplementersForm_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView1.DataSource = list; + dataGridView1.Columns["Id"].Visible = false; + dataGridView1.Columns["ImplementerFIO"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + dataGridView1.Columns["Password"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + dataGridView1.Columns["Qualification"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + dataGridView1.Columns["WorkExperience"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void CreateButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(ImplementerForm)); + if (service is ImplementerForm form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(ImplementerForm)); + if (service is ImplementerForm form) + { + form.Id = + Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void DeleteButton_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ImplementerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SoftwareInstallation/ImplementersForm.resx b/SoftwareInstallation/ImplementersForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SoftwareInstallation/ImplementersForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SoftwareInstallation/Program.cs b/SoftwareInstallation/Program.cs index 5a5653a..65599ed 100644 --- a/SoftwareInstallation/Program.cs +++ b/SoftwareInstallation/Program.cs @@ -8,6 +8,7 @@ using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationDatabaseImplement.Implements; using System; +using SoftwareInstallation.Forms; namespace SoftwareInstallationView { @@ -45,8 +46,13 @@ namespace SoftwareInstallationView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -60,7 +66,10 @@ namespace SoftwareInstallationView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } - } + } } \ No newline at end of file diff --git a/SoftwareInstallationBusinessLogic/BusinessLogics/ImplementerLogic.cs b/SoftwareInstallationBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..2c6b77b --- /dev/null +++ b/SoftwareInstallationBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,128 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationBusinessLogic.BusinessLogic +{ + public class ImplementerLogic : IImplementerLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + public ImplementerLogic(ILogger logger, IImplementerStorage + implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + public List? ReadList(ImplementerSearchModel? model) + { + _logger.LogInformation("ReadList. ImplementerFIO:{ClientFIO}. Id:{ Id}", model?.ImplementerFIO, model?.Id); + var list = model == null ? _implementerStorage.GetFullList() : + _implementerStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ImplementerViewModel? ReadElement(ImplementerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ImplementerFIO:{ImplementerFIO}.Id:{ Id}", model.ImplementerFIO, model.Id); + var element = _implementerStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ImplementerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_implementerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ImplementerBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + throw new ArgumentNullException("Нет ФИО исполнителя", + nameof(model.ImplementerFIO)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля клиента", + nameof(model.Password)); + } + if (model.WorkExperience < 0) + { + throw new ArgumentNullException("Стаж меньше 0", + nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentException("Квалификация меньше 0", nameof(model.Qualification)); + } + _logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}." + + "Password:{ Password}. WorkExperience:{ WorkExperience}. Qualification:{ Qualification}. Id: { Id} ", + model.ImplementerFIO, model.Password, model.WorkExperience, model.Qualification, model.Id); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/SoftwareInstallationBusinessLogic/BusinessLogics/OrderLogic.cs b/SoftwareInstallationBusinessLogic/BusinessLogics/OrderLogic.cs index 1b2a9ea..d82c6be 100644 --- a/SoftwareInstallationBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SoftwareInstallationBusinessLogic/BusinessLogics/OrderLogic.cs @@ -1,136 +1,136 @@ -using Microsoft.Extensions.Logging; -using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + namespace SoftwareInstallationBusinessLogic.BusinessLogic { - public class OrderLogic : IOrderLogic - { - //Класс с логикой для заказов будет отвечать за получение списка заказов, - //создания заказа и смены его статусов. Следует учитывать, что у заказа можно - //менять статус на новый, если его текущий статус предшествует новому + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + static readonly object locker = new object(); - private readonly ILogger _logger; - private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } - public OrderLogic(ILogger logger, IOrderStorage orderStorage) - { - _logger = logger; - _orderStorage = orderStorage; - } + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } - public List? ReadList(OrderSearchModel? model) - { - _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); - var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } - public bool CreateOrder(OrderBindingModel model) - { - CheckModel(model); + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); - if (model.Status != OrderStatus.Неизвестен) - return false; - model.Status = OrderStatus.Принят; + if (model.Status != OrderStatus.Неизвестен) + return false; + model.Status = OrderStatus.Принят; - if (_orderStorage.Insert(model) == null) - { - model.Status = OrderStatus.Неизвестен; - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } - public bool TakeOrderInWork(OrderBindingModel model) - { - return ToNextStatus(model, OrderStatus.Выполняется); - } + public bool TakeOrderInWork(OrderBindingModel model) + { + lock (locker) + { + return ToNextStatus(model, OrderStatus.Выполняется); + } + } - public bool FinishOrder(OrderBindingModel model) - { - return ToNextStatus(model, OrderStatus.Готов); - } + public bool FinishOrder(OrderBindingModel model) + { + return ToNextStatus(model, OrderStatus.Готов); + } - public bool DeliveryOrder(OrderBindingModel model) - { - return ToNextStatus(model, OrderStatus.Выдан); - } + public bool DeliveryOrder(OrderBindingModel model) + { + return ToNextStatus(model, OrderStatus.Выдан); + } - public bool ToNextStatus(OrderBindingModel model, OrderStatus orderStatus) - { - CheckModel(model, false); - var element = _orderStorage.GetElement(new OrderSearchModel() - { - Id = model.Id - }); - if (element == null) - { - throw new ArgumentNullException(nameof(element)); - } + public bool ToNextStatus(OrderBindingModel model, OrderStatus orderStatus) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != orderStatus - 1) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); + } + model.Status = orderStatus; + if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + if (element.ImplementerId.HasValue) + model.ImplementerId = element.ImplementerId; + _orderStorage.Update(model); + return true; + } - model.SoftwareId = element.SoftwareId; - model.DateCreate = element.DateCreate; - model.DateImplement = element.DateImplement; - model.Status = element.Status; - model.Count = element.Count; - model.Sum = element.Sum; - - if (model.Status != orderStatus - 1) - { - _logger.LogWarning("Status update to " + orderStatus + " operation failed"); - return false; - } - model.Status = orderStatus; - - if (model.Status == OrderStatus.Выдан) - { - model.DateImplement = DateTime.Now; - } - - if (_orderStorage.Update(model) == null) - { - model.Status--; - _logger.LogWarning("Changing status operation faled"); - return false; - } - return true; - } - - private void CheckModel(OrderBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.Count <= 0) - { - throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); - } - if (model.Sum <= 0) - { - throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); - } - if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) - { - throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} должна быть позже даты его создания {model.DateCreate}"); - } - _logger.LogInformation("Software. SoftwareId:{SoftwareId}.Count:{Count}.Sum:{Sum}Id:{Id}", model.SoftwareId, model.Count, model.Sum, model.Id); - } - } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Software. SoftwareId:{SoftwareId}.Count:{Count}.Sum:{Sum}Id:{Id}", model.SoftwareId, model.Count, model.Sum, model.Id); + } + } } diff --git a/SoftwareInstallationBusinessLogic/BusinessLogics/WorkModeling.cs b/SoftwareInstallationBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..e5eedce --- /dev/null +++ b/SoftwareInstallationBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,135 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationBusinessLogic.BusinessLogic +{ + public class WorkModeling : IWorkProcess + { + private readonly ILogger _logger; + private readonly Random _rnd; + private IOrderLogic? _orderLogic; + public WorkModeling(ILogger logger) + { + _logger = logger; + _rnd = new Random(1000); + } + public void DoWork(IImplementerLogic implementerLogic, IOrderLogic + orderLogic) + { + _orderLogic = orderLogic; + var implementers = implementerLogic.ReadList(null); + if (implementers == null) + { + _logger.LogWarning("DoWork. Implementers is null"); + return; + } + var orders = _orderLogic.ReadList(new OrderSearchModel + { + Status = + OrderStatus.Принят + }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + + private async Task WorkerWorkAsync(ImplementerViewModel implementer, + List orders) + { + if (_orderLogic == null || implementer == null) + { + return; + } + await RunOrderInWork(implementer); + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order { Order}", implementer.Id, order.Id); + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, + 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order { Order}", implementer.Id, order.Id); + + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id + }); + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + }); + } + private async Task RunOrderInWork(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + try + { + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new + OrderSearchModel + { + ImplementerId = implementer.Id, + Status = OrderStatus.Выполняется + })); + if (runOrder == null) + { + return; + } + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", + implementer.Id, runOrder.Id); + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * + runOrder.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", + implementer.Id, runOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/SoftwareInstallationClientApp/Models/ErrorViewModel.cs b/SoftwareInstallationClientApp/Models/ErrorViewModel.cs index 3351e89..4d655b6 100644 --- a/SoftwareInstallationClientApp/Models/ErrorViewModel.cs +++ b/SoftwareInstallationClientApp/Models/ErrorViewModel.cs @@ -1,9 +1,9 @@ namespace SoftwareInstallationClientApp.Models { - public class ErrorViewModel - { - public string? RequestId { get; set; } + public class ErrorViewModel + { + public string? RequestId { get; set; } - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); - } + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + } } diff --git a/SoftwareInstallationClientApp/Program.cs b/SoftwareInstallationClientApp/Program.cs index 13bd7b3..29ac96a 100644 --- a/SoftwareInstallationClientApp/Program.cs +++ b/SoftwareInstallationClientApp/Program.cs @@ -1,6 +1,5 @@ using SoftwareInstallationClientApp; - var builder = WebApplication.CreateBuilder(args); // Add services to the container. diff --git a/SoftwareInstallationClientApp/Properties/launchSettings.json b/SoftwareInstallationClientApp/Properties/launchSettings.json index 66744d5..c5b8a70 100644 --- a/SoftwareInstallationClientApp/Properties/launchSettings.json +++ b/SoftwareInstallationClientApp/Properties/launchSettings.json @@ -3,8 +3,8 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:22282", - "sslPort": 44384 + "applicationUrl": "http://localhost:17756", + "sslPort": 44387 } }, "profiles": { @@ -12,7 +12,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "applicationUrl": "http://localhost:5221", + "applicationUrl": "http://localhost:5072", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } @@ -21,7 +21,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "applicationUrl": "https://localhost:7265;http://localhost:5221", + "applicationUrl": "https://localhost:7101;http://localhost:5072", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/SoftwareInstallationClientApp/SoftwareInstallationClientApp.csproj b/SoftwareInstallationClientApp/SoftwareInstallationClientApp.csproj index 7b8371a..39f3a5c 100644 --- a/SoftwareInstallationClientApp/SoftwareInstallationClientApp.csproj +++ b/SoftwareInstallationClientApp/SoftwareInstallationClientApp.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/SoftwareInstallationClientApp/appsettings.json b/SoftwareInstallationClientApp/appsettings.json index 3db752b..910eed3 100644 --- a/SoftwareInstallationClientApp/appsettings.json +++ b/SoftwareInstallationClientApp/appsettings.json @@ -6,4 +6,5 @@ } }, "AllowedHosts": "*", - "IPAddress": "http://localhost:5221/" \ No newline at end of file + "IPAddress": "http://localhost:5221/" +} diff --git a/SoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs b/SoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..ee17510 --- /dev/null +++ b/SoftwareInstallationContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,18 @@ +using SoftwareInstallationDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + public string ImplementerFIO { get; set; } = string.Empty; + public int WorkExperience { get; set; } = 0; + public int Qualification { get; set; } = 0; + public string Password { get; set; } = string.Empty; + } +} diff --git a/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs b/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs index 0b18464..2451de4 100644 --- a/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs +++ b/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs @@ -15,7 +15,8 @@ namespace SoftwareInstallationContracts.BindingModels public int SoftwareId { get; set; } public int Count { get; set; } public double Sum { get; set; } - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public int? ImplementerId { get; set; } = null; + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } } diff --git a/SoftwareInstallationContracts/BusinessLogicsContracts/IImplementerLogic.cs b/SoftwareInstallationContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..dbb3d57 --- /dev/null +++ b/SoftwareInstallationContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,20 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.BusinessLogicsContracts +{ + public interface IImplementerLogic + { + List? ReadList(ImplementerSearchModel? model); + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + bool Create(ImplementerBindingModel model); + bool Update(ImplementerBindingModel model); + bool Delete(ImplementerBindingModel model); + } +} diff --git a/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs b/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs index 41bc7f7..e58b261 100644 --- a/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,7 +12,8 @@ namespace SoftwareInstallationContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); - bool CreateOrder(OrderBindingModel model); + OrderViewModel? ReadElement(OrderSearchModel model); + bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); bool DeliveryOrder(OrderBindingModel model); diff --git a/SoftwareInstallationContracts/BusinessLogicsContracts/IWorkProcess.cs b/SoftwareInstallationContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..d47071a --- /dev/null +++ b/SoftwareInstallationContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/SoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs b/SoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..ff6f071 --- /dev/null +++ b/SoftwareInstallationContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + public string? ImplementerFIO { get; set; } = string.Empty; + public string? Password { get; set; } = string.Empty; + } +} diff --git a/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs b/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs index 6ed52ac..3736f6d 100644 --- a/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs +++ b/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using SoftwareInstallationDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,7 +11,9 @@ namespace SoftwareInstallationContracts.SearchModels { public int? Id { get; set; } public int? ClientId { get; set; } - public DateTime? DateFrom { get; set; } + public int? ImplementerId { get; set; } + public OrderStatus? Status { get; set; } + public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } } diff --git a/SoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs b/SoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..82c0d05 --- /dev/null +++ b/SoftwareInstallationContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.StoragesContracts +{ + public interface IImplementerStorage + { + List GetFullList(); + List GetFilteredList(ImplementerSearchModel model); + ImplementerViewModel? GetElement(ImplementerSearchModel model); + ImplementerViewModel? Insert(ImplementerBindingModel model); + ImplementerViewModel? Update(ImplementerBindingModel model); + ImplementerViewModel? Delete(ImplementerBindingModel model); + } +} diff --git a/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs b/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..a27982d --- /dev/null +++ b/SoftwareInstallationContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,23 @@ +using SoftwareInstallationDataModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } = 0; + [DisplayName("Квалификация")] + public int Qualification { get; set; } = 0; + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + } +} diff --git a/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs b/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs index ce1d796..c6207bb 100644 --- a/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs +++ b/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs @@ -14,12 +14,15 @@ namespace SoftwareInstallationContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } public int ClientId { get; set; } - [DisplayName("Клиент")] + public int? ImplementerId { get; set; } = null; + [DisplayName("Клиент")] public string ClientFIO { get; set; } = string.Empty; public int SoftwareId { get; set; } [DisplayName("Изделие")] public string SoftwareName { get; set; } = string.Empty; - [DisplayName("Количество")] + [DisplayName("Исполнитель")] + public string ImplementerFIO { get; set; } = string.Empty; + [DisplayName("Количество")] public int Count { get; set; } [DisplayName("Сумма")] public double Sum { get; set; } diff --git a/SoftwareInstallationDataModels/Models/IImplementerModel.cs b/SoftwareInstallationDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..ddfc609 --- /dev/null +++ b/SoftwareInstallationDataModels/Models/IImplementerModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationDataModels +{ + public interface IImplementerModel + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + + } +} diff --git a/SoftwareInstallationDataModels/Models/IOrderModel.cs b/SoftwareInstallationDataModels/Models/IOrderModel.cs index 7232cd7..679b10f 100644 --- a/SoftwareInstallationDataModels/Models/IOrderModel.cs +++ b/SoftwareInstallationDataModels/Models/IOrderModel.cs @@ -11,7 +11,8 @@ namespace SoftwareInstallationDataModels.Models { int SoftwareId { get; } int ClientId { get; } - int Count { get; } + int? ImplementerId { get; } + int Count { get; } double Sum { get; } OrderStatus Status { get; } DateTime DateCreate { get; } diff --git a/SoftwareInstallationDatabaseImplement/Implements/ImplementerStorage.cs b/SoftwareInstallationDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..fca6025 --- /dev/null +++ b/SoftwareInstallationDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,87 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new SoftwareInstallationDataBase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + context.Implementers.Remove(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && + !model.Id.HasValue) + { + return null; + } + using var context = new SoftwareInstallationDataBase(); + return context.Implementers + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || x.Id == model.Id) && + (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + ?.GetViewModel; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + return new(); + } + + public List GetFullList() + { + using var context = new SoftwareInstallationDataBase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new SoftwareInstallationDataBase(); + var res = Implementer.Create(model); + if (res != null) + { + context.Implementers.Add(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new SoftwareInstallationDataBase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + return res?.GetViewModel; + } + } +} diff --git a/SoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs b/SoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs index bdc9c00..31224a8 100644 --- a/SoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs +++ b/SoftwareInstallationDatabaseImplement/Implements/OrderStorage.cs @@ -12,78 +12,79 @@ using System.Threading.Tasks; namespace SoftwareInstallationDatabaseImplement.Implements { - public class OrderStorage : IOrderStorage - { - public List GetFullList() - { - using var context = new SoftwareInstallationDataBase(); - return context.Orders.Include(x => x.Software) - .Include(x => x.Client).Select(x => x.GetViewModel) - .ToList(); - } - public List GetFilteredList(OrderSearchModel model) - { + public class OrderStorage : IOrderStorage + { + public List GetFullList() + { + using var context = new SoftwareInstallationDataBase(); + return context.Orders.Include(x => x.Software) + .Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(OrderSearchModel model) + { - using var context = new SoftwareInstallationDataBase(); - return context.Orders - .Include(x => x.Software) - .Include(x => x.Client).Where(x => ( - (!model.Id.HasValue || x.Id == model.Id) && - (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && - (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) - && - (!model.ClientId.HasValue || x.ClientId == model.ClientId) - ) - ) - .Select(x => x.GetViewModel) - .ToList(); - } - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return null; - } - using var context = new SoftwareInstallationDataBase(); - return context.Orders.Include(x => x.Software).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; - } - public OrderViewModel? Insert(OrderBindingModel model) - { - using var context = new SoftwareInstallationDataBase(); - var newOrder = Order.Create(context, model); - if (newOrder == null) - { - return null; - } - context.Orders.Add(newOrder); - context.SaveChanges(); - return newOrder.GetViewModel; - } - public OrderViewModel? Update(OrderBindingModel model) - { - using var context = new SoftwareInstallationDataBase(); - var order = context.Orders.Include(x => x.Software).Include(x => x.Client).FirstOrDefault(x => x.Id == - model.Id); - if (order == null) - { - return null; - } - order.Update(model); - context.SaveChanges(); - return order.GetViewModel; - } - public OrderViewModel? Delete(OrderBindingModel model) - { - using var context = new SoftwareInstallationDataBase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == - model.Id); - if (element != null) - { - context.Orders.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - } + using var context = new SoftwareInstallationDataBase(); + return context.Orders + .Include(x => x.Software) + .Include(x => x.Client).Include(x => x.Implementer).Where(x => ( + (!model.Id.HasValue || x.Id == model.Id) && + (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && + (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) + && + (!model.ClientId.HasValue || x.ClientId == model.ClientId) + && + (!model.Status.HasValue || x.Status == model.Status) + ) + ) + .Select(x => x.GetViewModel) + .ToList(); + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + using var context = new SoftwareInstallationDataBase(); + return context.Orders.Include(x => x.Software).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault( + x => ((model.Id.HasValue && x.Id == model.Id) || + (model.ImplementerId.HasValue && model.Status.HasValue && + x.ImplementerId == model.ImplementerId && x.Status == model.Status)))?.GetViewModel; + } + public OrderViewModel? Insert(OrderBindingModel model) + { + using var context = new SoftwareInstallationDataBase(); + var newOrder = Order.Create(context, model); + if (newOrder == null) + { + return null; + } + context.Orders.Add(newOrder); + context.SaveChanges(); + return newOrder.GetViewModel; + } + public OrderViewModel? Update(OrderBindingModel model) + { + using var context = new SoftwareInstallationDataBase(); + var order = context.Orders.Include(x => x.Software).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == + model.Id); + if (order == null) + { + return null; + } + order.Update(model); + context.SaveChanges(); + return order.GetViewModel; + } + public OrderViewModel? Delete(OrderBindingModel model) + { + using var context = new SoftwareInstallationDataBase(); + var element = context.Orders.FirstOrDefault(rec => rec.Id == + model.Id); + if (element != null) + { + context.Orders.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } } diff --git a/SoftwareInstallationDatabaseImplement/Migrations/20240418180214_InitialCreate.Designer.cs b/SoftwareInstallationDatabaseImplement/Migrations/20240502175831_InitialCreate.Designer.cs similarity index 82% rename from SoftwareInstallationDatabaseImplement/Migrations/20240418180214_InitialCreate.Designer.cs rename to SoftwareInstallationDatabaseImplement/Migrations/20240502175831_InitialCreate.Designer.cs index b20de7f..e1eb745 100644 --- a/SoftwareInstallationDatabaseImplement/Migrations/20240418180214_InitialCreate.Designer.cs +++ b/SoftwareInstallationDatabaseImplement/Migrations/20240502175831_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using SoftwareInstallationDatabaseImplement; namespace SoftwareInstallationDatabaseImplement.Migrations { [DbContext(typeof(SoftwareInstallationDataBase))] - [Migration("20240418180214_InitialCreate")] + [Migration("20240502175831_InitialCreate")] partial class InitialCreate { /// @@ -70,6 +70,33 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -90,6 +117,9 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("SoftwareId") .HasColumnType("int"); @@ -103,6 +133,8 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("SoftwareId"); b.ToTable("Orders"); @@ -162,6 +194,10 @@ namespace SoftwareInstallationDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("SoftwareInstallationDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("SoftwareInstallationDatabaseImplement.Models.Software", "Software") .WithMany("Orders") .HasForeignKey("SoftwareId") @@ -170,6 +206,8 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Software"); }); @@ -202,6 +240,11 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.Navigation("SoftwareComponents"); }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Software", b => { b.Navigation("Components"); diff --git a/SoftwareInstallationDatabaseImplement/Migrations/20240418180214_InitialCreate.cs b/SoftwareInstallationDatabaseImplement/Migrations/20240502175831_InitialCreate.cs similarity index 82% rename from SoftwareInstallationDatabaseImplement/Migrations/20240418180214_InitialCreate.cs rename to SoftwareInstallationDatabaseImplement/Migrations/20240502175831_InitialCreate.cs index 2cc972e..e389401 100644 --- a/SoftwareInstallationDatabaseImplement/Migrations/20240418180214_InitialCreate.cs +++ b/SoftwareInstallationDatabaseImplement/Migrations/20240502175831_InitialCreate.cs @@ -40,6 +40,22 @@ namespace SoftwareInstallationDatabaseImplement.Migrations table.PrimaryKey("PK_Components", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Qualification = table.Column(type: "int", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Softwares", columns: table => new @@ -66,7 +82,8 @@ namespace SoftwareInstallationDatabaseImplement.Migrations DateCreate = table.Column(type: "datetime2", nullable: false), DateImplement = table.Column(type: "datetime2", nullable: true), SoftwareId = table.Column(type: "int", nullable: false), - ClientId = table.Column(type: "int", nullable: false) + ClientId = table.Column(type: "int", nullable: false), + ImplementerId = table.Column(type: "int", nullable: true) }, constraints: table => { @@ -77,6 +94,11 @@ namespace SoftwareInstallationDatabaseImplement.Migrations principalTable: "Clients", principalColumn: "Id", onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id"); table.ForeignKey( name: "FK_Orders_Softwares_SoftwareId", column: x => x.SoftwareId, @@ -117,6 +139,11 @@ namespace SoftwareInstallationDatabaseImplement.Migrations table: "Orders", column: "ClientId"); + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + migrationBuilder.CreateIndex( name: "IX_Orders_SoftwareId", table: "Orders", @@ -145,6 +172,9 @@ namespace SoftwareInstallationDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Clients"); + migrationBuilder.DropTable( + name: "Implementers"); + migrationBuilder.DropTable( name: "Components"); diff --git a/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs b/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs index 819caa8..d6b1ff3 100644 --- a/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs +++ b/SoftwareInstallationDatabaseImplement/Migrations/SoftwareInstallationDataBaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -87,6 +114,9 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("SoftwareId") .HasColumnType("int"); @@ -100,6 +130,8 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("SoftwareId"); b.ToTable("Orders"); @@ -159,6 +191,10 @@ namespace SoftwareInstallationDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("SoftwareInstallationDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("SoftwareInstallationDatabaseImplement.Models.Software", "Software") .WithMany("Orders") .HasForeignKey("SoftwareId") @@ -167,6 +203,8 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Software"); }); @@ -199,6 +237,11 @@ namespace SoftwareInstallationDatabaseImplement.Migrations b.Navigation("SoftwareComponents"); }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("SoftwareInstallationDatabaseImplement.Models.Software", b => { b.Navigation("Components"); diff --git a/SoftwareInstallationDatabaseImplement/Models/Implementer.cs b/SoftwareInstallationDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..2416aa4 --- /dev/null +++ b/SoftwareInstallationDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,65 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationDatabaseImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + [Required] + public string Password { get; set; } = string.Empty; + [Required] + public int Qualification { get; set; } = 0; + [Required] + public int WorkExperience { get; set; } = 0; + [ForeignKey("ImplementerId")] + public virtual List Orders { get; set; } = + new(); + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience, + }; + } +} diff --git a/SoftwareInstallationDatabaseImplement/Models/Order.cs b/SoftwareInstallationDatabaseImplement/Models/Order.cs index 5a781fd..72e1434 100644 --- a/SoftwareInstallationDatabaseImplement/Models/Order.cs +++ b/SoftwareInstallationDatabaseImplement/Models/Order.cs @@ -26,7 +26,9 @@ namespace SoftwareInstallationDatabaseImplement.Models [Required] public int ClientId { get; private set; } public virtual Client Client { get; private set; } - public static Order? Create(SoftwareInstallationDataBase context, OrderBindingModel model) + public int? ImplementerId { get; private set; } = null; + public virtual Implementer? Implementer { get; private set; } + public static Order? Create(SoftwareInstallationDataBase context, OrderBindingModel model) { if (model == null) { @@ -44,7 +46,10 @@ namespace SoftwareInstallationDatabaseImplement.Models Software = context.Softwares.FirstOrDefault(x => x.Id == model.SoftwareId), ClientId = model.ClientId, Client = context.Clients.FirstOrDefault(x => x.Id == model.ClientId), - }; + ImplementerId = model.ImplementerId, + Implementer = (model.ImplementerId.HasValue ? context.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId) + : null), + }; } public void Update(OrderBindingModel? model) @@ -55,7 +60,8 @@ namespace SoftwareInstallationDatabaseImplement.Models } Status = model.Status; DateImplement = model.DateImplement; - } + ImplementerId = model.ImplementerId; + } public OrderViewModel GetViewModel => new() { @@ -68,8 +74,9 @@ namespace SoftwareInstallationDatabaseImplement.Models DateImplement = DateImplement, SoftwareName = Software.SoftwareName, Id = Id, - ClientFIO = Client.ClientFIO - }; + ClientFIO = Client.ClientFIO, + ImplementerFIO = (Implementer != null ? Implementer.ImplementerFIO : string.Empty) + }; } } diff --git a/SoftwareInstallationDatabaseImplement/SoftwareInstallationDataBase.cs b/SoftwareInstallationDatabaseImplement/SoftwareInstallationDataBase.cs index e3b215d..c303428 100644 --- a/SoftwareInstallationDatabaseImplement/SoftwareInstallationDataBase.cs +++ b/SoftwareInstallationDatabaseImplement/SoftwareInstallationDataBase.cs @@ -16,7 +16,7 @@ optionsBuilder) { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-952S2NGN;Initial Catalog=SoftInstallation;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-952S2NGN;Initial Catalog=SOFT;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } @@ -25,5 +25,6 @@ optionsBuilder) public virtual DbSet SoftwareComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } - } + public virtual DbSet Implementers { set; get; } + } } diff --git a/SoftwareInstallationFileImplement/DataFileSingleton.cs b/SoftwareInstallationFileImplement/DataFileSingleton.cs index 15e0960..9d32ba0 100644 --- a/SoftwareInstallationFileImplement/DataFileSingleton.cs +++ b/SoftwareInstallationFileImplement/DataFileSingleton.cs @@ -16,10 +16,12 @@ namespace SoftwareInstallationFileImplement private readonly string ClientFileName = "Client.xml"; private readonly string SoftwareFileName = "Software.xml"; public List Components { get; private set; } - public List Orders { get; private set; } + private readonly string ImplementerFileName = "Implementer.xml"; + public List Orders { get; private set; } public List Softwares { get; private set; } public List Clients { get; private set; } - public static DataFileSingleton GetInstance() + public List Implementers { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) { @@ -32,12 +34,17 @@ namespace SoftwareInstallationFileImplement public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); - private DataFileSingleton() + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, +"Implementers", x => x.GetXElement); + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Softwares = LoadData(SoftwareFileName, "Software", x => Software.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; - } + Implementers = LoadData(ImplementerFileName, "Implementer", x => +Implementer.Create(x)!)!; + } + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { if (File.Exists(filename)) diff --git a/SoftwareInstallationFileImplement/Implements/ImplementerStorage.cs b/SoftwareInstallationFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..87c2ef9 --- /dev/null +++ b/SoftwareInstallationFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,83 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ImplementerSearchModel + model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password)) + { + return new(); + } + return source.Implementers + .Where(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO.Contains(model.ImplementerFIO)) && + (string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password))) + .Select(x => x.GetViewModel) + .ToList(); + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + return source.Implementers + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + ?.GetViewModel; + } + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => + x.Id) + 1 : 1; + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + source.SaveImplementers(); + return implementer.GetViewModel; + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/SoftwareInstallationFileImplement/Implements/OrderStorage.cs b/SoftwareInstallationFileImplement/Implements/OrderStorage.cs index 8530894..abbb872 100644 --- a/SoftwareInstallationFileImplement/Implements/OrderStorage.cs +++ b/SoftwareInstallationFileImplement/Implements/OrderStorage.cs @@ -11,107 +11,103 @@ using System.Threading.Tasks; namespace SoftwareInstallationFileImplement.Implements { - public class OrderStorage : IOrderStorage - { - private readonly DataFileSingleton source; - public OrderStorage() - { - source = DataFileSingleton.GetInstance(); - } + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } - public List GetFullList() - { - return source.Orders - .Select(x => AccessSoftwareStorage(x.GetViewModel)) - .ToList(); - } + public List GetFullList() + { + return source.Orders + .Select(x => AccessStorage(x.GetViewModel)) + .ToList(); + } - public List GetFilteredList(OrderSearchModel + public List GetFilteredList(OrderSearchModel model) - { - return source.Orders - .Where(x => ( - (!model.Id.HasValue || x.Id == model.Id) && - (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && - (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) - && - (!model.ClientId.HasValue || x.ClientId == model.ClientId) - ) - ) - .Select(x => AccessSoftwareStorage(x.GetViewModel)) - .ToList(); - } + { + return source.Orders + .Where(x => ( + (!model.Id.HasValue || x.Id == model.Id) && + (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && + (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) + && + (!model.ClientId.HasValue || x.ClientId == model.ClientId) + && + (!model.Status.HasValue || x.Status == model.Status) + ) + ) + .Select(x => AccessStorage(x.GetViewModel)) + .ToList(); + } - public OrderViewModel? GetElement(OrderSearchModel model) - { - if (!model.Id.HasValue) - { - return null; - } - return AccessSoftwareStorage(source.Orders - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel); - } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return AccessStorage(source.Orders + .FirstOrDefault( + x => ((model.Id.HasValue && x.Id == model.Id) || + (model.ImplementerId.HasValue && model.Status.HasValue && + x.ImplementerId == model.ImplementerId && x.Status == model.Status)))?.GetViewModel); + } - public OrderViewModel? Insert(OrderBindingModel model) - { - model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; - var newOrder = Order.Create(model); - if (newOrder == null) - { - return null; - } - source.Orders.Add(newOrder); - source.SaveOrders(); - return AccessSoftwareStorage(newOrder.GetViewModel); - } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return AccessStorage(newOrder.GetViewModel); + } - public OrderViewModel? Update(OrderBindingModel model) - { - var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); - if (order == null) - { - return null; - } - order.Update(model); - source.SaveOrders(); - return AccessSoftwareStorage(order.GetViewModel); - } - public OrderViewModel? Delete(OrderBindingModel model) - { - var element = source.Orders.FirstOrDefault(x => x.Id == - model.Id); - if (element != null) - { - source.Orders.Remove(element); - source.SaveOrders(); - return AccessSoftwareStorage(element.GetViewModel); - } - return null; - } + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return AccessStorage(order.GetViewModel); + } + public OrderViewModel? Delete(OrderBindingModel model) + { + var element = source.Orders.FirstOrDefault(x => x.Id == + model.Id); + if (element != null) + { + source.Orders.Remove(element); + source.SaveOrders(); + return AccessStorage(element.GetViewModel); + } + return null; + } - public OrderViewModel AccessSoftwareStorage(OrderViewModel model) - { - if (model == null) - return null; - foreach (var Software in source.Softwares) - { - if (Software.Id == model.SoftwareId) - { - model.SoftwareName = Software.SoftwareName; - break; - } - } - return model; - } - - public OrderViewModel AccessClientStorage(OrderViewModel model) - { - if (model == null) - return null; - var client = source.Clients.FirstOrDefault(x => x.Id == model.Id); - if (client != null) - model.ClientFIO = client.ClientFIO; - return model; - } - } + public OrderViewModel AccessStorage(OrderViewModel model) + { + if (model == null) + return null; + var iceCream = source.Softwares.FirstOrDefault(x => x.Id == model.Id); + var client = source.Clients.FirstOrDefault(x => x.Id == model.Id); + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId); + if (iceCream != null) + model.SoftwareName = iceCream.SoftwareName; + if (client != null) + model.ClientFIO = client.ClientFIO; + if (implementer != null) + model.ImplementerFIO = implementer.ImplementerFIO; + return model; + } + } } diff --git a/SoftwareInstallationFileImplement/Models/Implementer.cs b/SoftwareInstallationFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..20a54c2 --- /dev/null +++ b/SoftwareInstallationFileImplement/Models/Implementer.cs @@ -0,0 +1,78 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SoftwareInstallationFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + public string ImplementerFIO { get; private set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public int Qualification { get; set; } = 0; + public int WorkExperience { get; set; } = 0; + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implementer() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("ImplementerFIO")!.Value, + Password = element.Element("Password")!.Value, + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value) + }; + } + + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("Qualification", Qualification.ToString()), + new XElement("WorkExperience", WorkExperience.ToString()) + ); + } +} diff --git a/SoftwareInstallationFileImplement/Models/Order.cs b/SoftwareInstallationFileImplement/Models/Order.cs index 5b24a25..ec0363d 100644 --- a/SoftwareInstallationFileImplement/Models/Order.cs +++ b/SoftwareInstallationFileImplement/Models/Order.cs @@ -11,8 +11,9 @@ namespace SoftwareInstallationFileImplement.Models { public int SoftwareId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } = null; - public int Count { get; private set; } + public int Count { get; private set; } public double Sum { get; private set; } @@ -39,8 +40,9 @@ namespace SoftwareInstallationFileImplement.Models Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement - }; + DateImplement = model.DateImplement, + ImplementerId = model.ImplementerId, + }; } public static Order? Create(XElement element) @@ -58,8 +60,9 @@ namespace SoftwareInstallationFileImplement.Models Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value.ToString()), DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), - DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value) - }; + DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), + }; } public void Update(OrderBindingModel? model) @@ -81,8 +84,9 @@ namespace SoftwareInstallationFileImplement.Models Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement - }; + DateImplement = DateImplement, + ImplementerId = ImplementerId, + }; public XElement GetXElement => new("Order", new XAttribute("Id", Id), diff --git a/SoftwareInstallationRestAP/Controllers/ImplementerController.cs b/SoftwareInstallationRestAP/Controllers/ImplementerController.cs new file mode 100644 index 0000000..58ce2ed --- /dev/null +++ b/SoftwareInstallationRestAP/Controllers/ImplementerController.cs @@ -0,0 +1,105 @@ +using DocumentFormat.OpenXml.Office2010.Excel; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Enums; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace SoftwareInstallationRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : ControllerBase + { + private readonly ILogger _logger; + private readonly IOrderLogic _order; + private readonly IImplementerLogic _logic; + public ImplementerController(IOrderLogic order, IImplementerLogic logic, + ILogger logger) + { + _logger = logger; + _order = order; + _logic = logic; + } + [HttpGet] + public ImplementerViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new ImplementerSearchModel + { + ImplementerFIO = login, + Password = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка авторизации сотрудника"); + throw; + } + } + [HttpGet] + public List? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + Status = OrderStatus.Принят + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения новых заказов"); + throw; + } + } + [HttpGet] + public OrderViewModel? GetImplementerOrder(int implementerId) + { + try + { + return _order.ReadElement(new OrderSearchModel + { + ImplementerId = implementerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения текущего заказа исполнителя"); + + throw; + } + } + + [HttpPost] + public void TakeOrderInWork(OrderBindingModel model) + { + try + { + _order.TakeOrderInWork(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", + model.Id); + throw; + } + } + [HttpPost] + public void FinishOrder(OrderBindingModel model) + { + try + { + _order.FinishOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа с №{ Id}", model.Id); + throw; + } + } + } +} diff --git a/SoftwareInstallationRestAP/Program.cs b/SoftwareInstallationRestAP/Program.cs index 6443a6a..bee9be2 100644 --- a/SoftwareInstallationRestAP/Program.cs +++ b/SoftwareInstallationRestAP/Program.cs @@ -38,43 +38,3 @@ app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.Run(); -using SoftwareInstallationBusinessLogic.BusinessLogic; -using SoftwareInstallationContracts.BusinessLogicsContracts; -using SoftwareInstallationContracts.StoragesContracts; -using SoftwareInstallationDatabaseImplement.Implements; -using Microsoft.OpenApi.Models; -var builder = WebApplication.CreateBuilder(args); -builder.Logging.SetMinimumLevel(LogLevel.Trace); -builder.Logging.AddLog4Net("log4net.config"); -// Add services to the container. -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddControllers(); -// Learn more about configuring Swagger/OpenAPI at -https://aka.ms/aspnetcore/swashbuckle -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(c => -{ - c.SwaggerDoc("v1", new OpenApiInfo - { - Title = "SoftwareInstallationRestApi", - Version - = "v1" - }); -}); -var app = builder.Build(); -// Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) -{ - app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", - "SoftwareInstallationRestApi v1")); -} -app.UseHttpsRedirection(); -app.UseAuthorization(); -app.MapControllers(); -app.Run(); diff --git a/SoftwareInstallationRestAP/Properties/launchSettings.json b/SoftwareInstallationRestAP/Properties/launchSettings.json index f1d5e60..513d110 100644 --- a/SoftwareInstallationRestAP/Properties/launchSettings.json +++ b/SoftwareInstallationRestAP/Properties/launchSettings.json @@ -1,33 +1,14 @@ -{ - "$schema": "https://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:19543", - "sslPort": 44332 - } - }, +{ "profiles": { - "http": { + "SoftwareInstallationRestAPI": { "commandName": "Project", - "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "http://localhost:5087", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "https": { - "commandName": "Project", + }, "dotnetRunMessages": true, - "launchBrowser": true, - "launchUrl": "swagger", - "applicationUrl": "https://localhost:7062;http://localhost:5087", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } + "applicationUrl": "https://localhost:7162;http://localhost:5221" }, "IIS Express": { "commandName": "IISExpress", @@ -37,5 +18,14 @@ "ASPNETCORE_ENVIRONMENT": "Development" } } + }, + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:6203", + "sslPort": 44341 + } } -} +} \ No newline at end of file diff --git a/SoftwareInstallationRestAP/SoftwareInstallationRestAP.csproj b/SoftwareInstallationRestAP/SoftwareInstallationRestAP.csproj index 5e7a992..315de7e 100644 --- a/SoftwareInstallationRestAP/SoftwareInstallationRestAP.csproj +++ b/SoftwareInstallationRestAP/SoftwareInstallationRestAP.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/SoftwareInstallationRestAP/log4net.config b/SoftwareInstallationRestAP/log4net.config new file mode 100644 index 0000000..fbbf5db --- /dev/null +++ b/SoftwareInstallationRestAP/log4net.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file