From 4fb672e0affc763f0901a9d52b895bf8e4f14479 Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Thu, 2 Nov 2023 02:24:20 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D0=BD=D0=B0=20=D0=AD=D0=B3=D0=BE=D0=B2=D1=8B=D1=85=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=D0=B0?= =?UTF-8?q?=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinForm/AppView/AppView.csproj | 2 + WinForm/AppView/Form1.Designer.cs | 39 -- WinForm/AppView/Form1.cs | 10 - WinForm/AppView/Form1.resx | 120 ------ WinForm/AppView/FormMain.Designer.cs | 144 ++++++++ WinForm/AppView/FormMain.cs | 349 ++++++++++++++++++ WinForm/AppView/FormMain.resx | 75 ++++ WinForm/AppView/FormProvider.Designer.cs | 279 ++++++++++++++ WinForm/AppView/FormProvider.cs | 159 ++++++++ WinForm/AppView/FormProvider.resx | 60 +++ WinForm/AppView/FormType.Designer.cs | 65 ++++ WinForm/AppView/FormType.cs | 145 ++++++++ WinForm/AppView/FormType.resx | 60 +++ WinForm/AppView/Program.cs | 20 +- .../PdfFormsLibrary/DropDownList.Designer.cs | 21 +- 15 files changed, 1361 insertions(+), 187 deletions(-) delete mode 100644 WinForm/AppView/Form1.Designer.cs delete mode 100644 WinForm/AppView/Form1.cs delete mode 100644 WinForm/AppView/Form1.resx create mode 100644 WinForm/AppView/FormMain.Designer.cs create mode 100644 WinForm/AppView/FormMain.cs create mode 100644 WinForm/AppView/FormMain.resx create mode 100644 WinForm/AppView/FormProvider.Designer.cs create mode 100644 WinForm/AppView/FormProvider.cs create mode 100644 WinForm/AppView/FormProvider.resx create mode 100644 WinForm/AppView/FormType.Designer.cs create mode 100644 WinForm/AppView/FormType.cs create mode 100644 WinForm/AppView/FormType.resx diff --git a/WinForm/AppView/AppView.csproj b/WinForm/AppView/AppView.csproj index 657ed43..e11cd51 100644 --- a/WinForm/AppView/AppView.csproj +++ b/WinForm/AppView/AppView.csproj @@ -9,6 +9,8 @@ + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/WinForm/AppView/Form1.Designer.cs b/WinForm/AppView/Form1.Designer.cs deleted file mode 100644 index 1b9a8ab..0000000 --- a/WinForm/AppView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace AppView -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/WinForm/AppView/Form1.cs b/WinForm/AppView/Form1.cs deleted file mode 100644 index c023e9d..0000000 --- a/WinForm/AppView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AppView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/WinForm/AppView/Form1.resx b/WinForm/AppView/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/WinForm/AppView/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/WinForm/AppView/FormMain.Designer.cs b/WinForm/AppView/FormMain.Designer.cs new file mode 100644 index 0000000..ef1e718 --- /dev/null +++ b/WinForm/AppView/FormMain.Designer.cs @@ -0,0 +1,144 @@ +namespace AppView +{ + partial class FormMain + { + /// + /// 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() + { + components = new System.ComponentModel.Container(); + contextMenuStrip = new ContextMenuStrip(components); + addProviderItem = new ToolStripMenuItem(); + editProviderItem = new ToolStripMenuItem(); + removeProviderItem = new ToolStripMenuItem(); + getSimpleDocumentItem = new ToolStripMenuItem(); + getTableDocumentItem = new ToolStripMenuItem(); + getDiagramDocumentItem = new ToolStripMenuItem(); + открытьСправочникToolStripMenuItem = new ToolStripMenuItem(); + controlDataTreeCell = new ControlsLibraryNet60.Data.ControlDataTreeCell(); + componentDocumentWithTableMultiHeaderExcel = new ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderExcel(components); + componentDocumentWithChartPieWord = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartPieWord(components); + componentDocumentWithChartBarWord = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord(components); + pdfGeneratorControl = new PdfFormsLibrary.PdfGeneratorControl(components); + contextMenuStrip.SuspendLayout(); + SuspendLayout(); + // + // contextMenuStrip + // + contextMenuStrip.Items.AddRange(new ToolStripItem[] { addProviderItem, editProviderItem, removeProviderItem, getSimpleDocumentItem, getTableDocumentItem, getDiagramDocumentItem, открытьСправочникToolStripMenuItem }); + contextMenuStrip.Name = "contextMenuStrip1"; + contextMenuStrip.Size = new Size(265, 158); + contextMenuStrip.Text = "Меню"; + // + // addProviderItem + // + addProviderItem.DisplayStyle = ToolStripItemDisplayStyle.Text; + addProviderItem.Name = "addProviderItem"; + addProviderItem.Size = new Size(264, 22); + addProviderItem.Text = "Добавить"; + addProviderItem.Click += AddProviderItem_Click; + // + // editProviderItem + // + editProviderItem.Name = "editProviderItem"; + editProviderItem.Size = new Size(264, 22); + editProviderItem.Text = "Изменить"; + editProviderItem.Click += EditProviderItem_Click; + // + // removeProviderItem + // + removeProviderItem.Name = "removeProviderItem"; + removeProviderItem.Size = new Size(264, 22); + removeProviderItem.Text = "Удалить"; + removeProviderItem.Click += RemoveProviderItem_Click; + // + // getSimpleDocumentItem + // + getSimpleDocumentItem.Name = "getSimpleDocumentItem"; + getSimpleDocumentItem.Size = new Size(264, 22); + getSimpleDocumentItem.Text = "Получить простой документ"; + getSimpleDocumentItem.Click += GetSimpleDocumentItem_Click; + // + // getTableDocumentItem + // + getTableDocumentItem.Name = "getTableDocumentItem"; + getTableDocumentItem.Size = new Size(264, 22); + getTableDocumentItem.Text = "Получить документ с таблицей"; + getTableDocumentItem.Click += GetTableDocumentItem_Click; + // + // getDiagramDocumentItem + // + getDiagramDocumentItem.Name = "getDiagramDocumentItem"; + getDiagramDocumentItem.Size = new Size(264, 22); + getDiagramDocumentItem.Text = "Получить документ с диаграммой"; + getDiagramDocumentItem.Click += GetDiagramDocumentItem_Click; + // + // открытьСправочникToolStripMenuItem + // + открытьСправочникToolStripMenuItem.Name = "открытьСправочникToolStripMenuItem"; + открытьСправочникToolStripMenuItem.Size = new Size(264, 22); + открытьСправочникToolStripMenuItem.Text = "Открыть справочник"; + открытьСправочникToolStripMenuItem.Click += OpenListToolStripMenuItem_Click; + // + // controlDataTreeCell + // + controlDataTreeCell.ContextMenuStrip = contextMenuStrip; + controlDataTreeCell.Location = new Point(0, 0); + controlDataTreeCell.Margin = new Padding(4, 3, 4, 3); + controlDataTreeCell.Name = "controlDataTreeCell"; + controlDataTreeCell.Size = new Size(618, 450); + controlDataTreeCell.TabIndex = 1; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(618, 450); + Controls.Add(controlDataTreeCell); + KeyPreview = true; + Name = "FormMain"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Основная форма"; + Load += FormMain_Load; + contextMenuStrip.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + private ContextMenuStrip contextMenuStrip; + private ToolStripMenuItem addProviderItem; + private ToolStripMenuItem editProviderItem; + private ToolStripMenuItem removeProviderItem; + private ToolStripMenuItem getSimpleDocumentItem; + private ToolStripMenuItem getTableDocumentItem; + private ToolStripMenuItem getDiagramDocumentItem; + private ControlsLibraryNet60.Data.ControlDataTreeCell controlDataTreeCell; + private ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderExcel componentDocumentWithTableMultiHeaderExcel; + private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartPieWord componentDocumentWithChartPieWord; + private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarWord componentDocumentWithChartBarWord; + private ToolStripMenuItem открытьСправочникToolStripMenuItem; + private PdfFormsLibrary.PdfGeneratorControl pdfGeneratorControl; + } +} \ No newline at end of file diff --git a/WinForm/AppView/FormMain.cs b/WinForm/AppView/FormMain.cs new file mode 100644 index 0000000..dd118c5 --- /dev/null +++ b/WinForm/AppView/FormMain.cs @@ -0,0 +1,349 @@ +using ComponentsLibraryNet60.Core; +using ComponentsLibraryNet60.Models; +using Contracts.StoragesContracts; +using Contracts.ViewModels; +using ControlsLibraryNet60.Models; +using DataBaseImplement.Implements; +using Microsoft.EntityFrameworkCore.Diagnostics; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +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 System.Windows.Forms.VisualStyles; +using PdfFormsLibrary; +using PdfFormsLibrary.Helpers; + +namespace AppView +{ + public partial class FormMain : Form + { + private readonly IProviderStorage _providerStorage; + private readonly ITypeStorage _typeStorage; + + public FormMain( + IProviderStorage providerStorage, + ITypeStorage typeStorage + ) + { + _providerStorage = providerStorage; + _typeStorage = typeStorage; + + InitializeComponent(); + KeyDown += new KeyEventHandler(FormMain_KeyDown); + } + + private void FormMain_Load( + object sender, + EventArgs e + ) + { + LoadData(); + + } + + private void LoadData() + { + try + { + var providers = _providerStorage.GetFullList(); + if (providers != null) + { + controlDataTreeCell.Clear(); + TreeColumnConfiguration(); + if (providers.Count > 0) AddTreeData(providers); + } + } + catch (Exception ex) + { + MessageBox.Show( + ex.Message, + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Error + ); + } + } + + private void TreeColumnConfiguration() + { + DataTreeNodeConfig treeConfig = new(); + treeConfig.NodeNames = new(); + treeConfig.NodeNames.Enqueue("Type"); + treeConfig.NodeNames.Enqueue("SupplyDateTime"); + treeConfig.NodeNames.Enqueue("Id"); + treeConfig.NodeNames.Enqueue("Name"); + + controlDataTreeCell.LoadConfig(treeConfig); + } + + private void AddTreeData(List providers) + { + int numOfProperties = typeof(ProviderViewModel).GetProperties().Length; + for (int i = 0; i < providers.Count; ++i) + { + providers[i].SupplyDateTime = providers[i].SupplyDate.ToString(); + for (int j = 0; j < numOfProperties; ++j) + { + controlDataTreeCell.AddCell(j, providers[i]); + } + } + } + + private void AddProviderItem_Click( + object sender, + EventArgs e + ) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProvider)); + if (service is FormProvider form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void EditProviderItem_Click(object sender, EventArgs e) + { + if (controlDataTreeCell.GetSelectedObject() == null) + { + return; + } + else + { + var service = Program.ServiceProvider?.GetService(typeof(FormProvider)); + if (service is FormProvider form) + { + form.Id = Convert.ToInt32(controlDataTreeCell.GetSelectedObject()?.Id); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void RemoveProviderItem_Click(object sender, EventArgs e) + { + if (controlDataTreeCell.GetSelectedObject() == null) return; + if (MessageBox.Show( + "Вы хотите удалить выбранный элементы?", + "Вопрос", + MessageBoxButtons.YesNo, + MessageBoxIcon.Question) == DialogResult.Yes) + { + _providerStorage.Delete(new(controlDataTreeCell.GetSelectedObject())); + LoadData(); + } + } + + private void GetSimpleDocumentItem_Click(object sender, EventArgs e) + { + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + SaveFileDialog saveFileDialog = new() + { + Filter = "PDF Files|*.pdf" + }; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + string filePath = saveFileDialog.FileName; + string documentTitle = "Поставщики"; + List textData = new(); + + foreach (var provider in _providerStorage.GetFullList()) + { + textData.Add(provider.Name + ": " + provider.Furniture); + } + + try + { + pdfGeneratorControl.GeneratePdf(filePath, documentTitle, textData); + MessageBox.Show("PDF-документ успешно сохранен.", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show( + $"Ошибка при создании PDF-документа: {ex.Message}", + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Error + ); + } + } + } + + private void GetTableDocumentItem_Click(object sender, EventArgs e) + { + List providersList = _providerStorage.GetFullList(); + foreach (var provider in providersList) + { + if (provider.SupplyDate == null) + { + provider.SupplyDateTime = "Поставок не было"; + provider.SupplyDate = DateTime.MinValue; + continue; + } + provider.SupplyDateTime = provider.SupplyDate.ToString(); + } + + ComponentDocumentWithTableHeaderDataConfig config = new() + { + Data = providersList, + Headers = new() + { + (0, 0, "Идентификатор", "Id"), + (1, 0, "Название", "Name"), + (2, 0, "Тип организации", "Type"), + (3, 0, "Дата поставки", "SupplyDateTime"), + }, + Header = "Отчет по всем поставщикам", + UseUnion = false, + ColumnsRowsWidth = new() + { + (10,10), + (10,10), + (10,10), + (10,10), + }, + ColumnsRowsDataCount = new() + }; + + SaveFileDialog saveFileDialog = new() + { + Filter = "Excel Files|*.xlsx" + }; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + config.FilePath = saveFileDialog.FileName; + + try + { + + componentDocumentWithTableMultiHeaderExcel.CreateDoc(config); + MessageBox.Show( + "Excel-документ успешно сохранен.", + "Успех", + MessageBoxButtons.OK, + MessageBoxIcon.Information + ); + } + catch (Exception ex) + { + MessageBox.Show( + $"Ошибка при создании Excel-документа: {ex.Message}", + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Error + ); + } + } + } + + private void GetDiagramDocumentItem_Click(object sender, EventArgs e) + { + var providersList = _providerStorage + .GetFullList() + .Where(item => item.SupplyDate?.Year == DateTime.Now.Year) + .GroupBy(item => item.Type) + .Select(group => new + { + Type = group.Key, + Date = group.Select(item => item.SupplyDate), + Count = (double)group.Count(), + }); + + var resultData = new List<(int, double)>(); + + foreach (var provider in providersList) + { + resultData.Add((DateTime.Now.Year, provider.Count)); + } + + ComponentDocumentWithChartConfig config = new() + { + ChartTitle = "Количество поставщиков в разрезе типа организации", + LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom, + Header = "Круговая диаграмма", + Data = new() + { + { "Тип организации", resultData }, + }, + }; + + SaveFileDialog saveFileDialog = new() + { + Filter = "Word Files|*.docx" + }; + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + config.FilePath = saveFileDialog.FileName; + try + { + componentDocumentWithChartPieWord.CreateDoc(config); + MessageBox.Show( + "Word-документ успешно сохранен.", + "Успех", + MessageBoxButtons.OK, + MessageBoxIcon.Information + ); + } + catch (Exception ex) + { + MessageBox.Show( + $"Ошибка при создании Word-документа: {ex.Message}", + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Error + ); + } + } + } + + private void FormMain_KeyDown(object sender, KeyEventArgs e) + { + if (e.Control) + { + switch (e.KeyCode) + { + case Keys.A: + AddProviderItem_Click(sender, e); + break; + case Keys.U: + EditProviderItem_Click(sender, e); + break; + case Keys.D: + RemoveProviderItem_Click(sender, e); + break; + case Keys.S: + GetSimpleDocumentItem_Click(sender, e); + break; + case Keys.T: + GetTableDocumentItem_Click(sender, e); + break; + case Keys.C: + GetDiagramDocumentItem_Click(sender, e); + break; + case Keys.M: + OpenListToolStripMenuItem_Click(sender, e); + break; + } + } + } + + private void OpenListToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormType)); + if (service is FormType form) + { + form.ShowDialog(); + LoadData(); + } + } + } +} diff --git a/WinForm/AppView/FormMain.resx b/WinForm/AppView/FormMain.resx new file mode 100644 index 0000000..0a30cfe --- /dev/null +++ b/WinForm/AppView/FormMain.resx @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + + 328, 17 + + + 923, 17 + + + 17, 54 + + + 291, 54 + + \ No newline at end of file diff --git a/WinForm/AppView/FormProvider.Designer.cs b/WinForm/AppView/FormProvider.Designer.cs new file mode 100644 index 0000000..e9cf51e --- /dev/null +++ b/WinForm/AppView/FormProvider.Designer.cs @@ -0,0 +1,279 @@ +namespace AppView +{ + partial class FormProvider + { + /// + /// 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() + { + labelProviderName = new Label(); + textBoxName = new TextBox(); + panelName = new Panel(); + panelFurniture = new Panel(); + textBoxFurniture = new TextBox(); + labelFurniture = new Label(); + panelType = new Panel(); + buttonType = new Button(); + dropDownList = new WinForm.DropDownList(); + labelType = new Label(); + panelDate = new Panel(); + controlInputNullableDate = new ControlsLibraryNet60.Input.ControlInputNullableDate(); + labelDate = new Label(); + buttonSave = new Button(); + panelButtons = new Panel(); + buttonCancel = new Button(); + panelName.SuspendLayout(); + panelFurniture.SuspendLayout(); + panelType.SuspendLayout(); + panelDate.SuspendLayout(); + panelButtons.SuspendLayout(); + SuspendLayout(); + // + // labelProviderName + // + labelProviderName.AutoSize = true; + labelProviderName.Dock = DockStyle.Top; + labelProviderName.Location = new Point(10, 10); + labelProviderName.Name = "labelProviderName"; + labelProviderName.Size = new Size(59, 15); + labelProviderName.TabIndex = 0; + labelProviderName.Text = "Название"; + // + // textBoxName + // + textBoxName.Dock = DockStyle.Top; + textBoxName.Location = new Point(10, 25); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(340, 23); + textBoxName.TabIndex = 1; + textBoxName.TextChanged += OnInputChange; + // + // panelName + // + panelName.AutoSize = true; + panelName.Controls.Add(textBoxName); + panelName.Controls.Add(labelProviderName); + panelName.Dock = DockStyle.Top; + panelName.Location = new Point(0, 0); + panelName.Margin = new Padding(0); + panelName.Name = "panelName"; + panelName.Padding = new Padding(10); + panelName.Size = new Size(360, 58); + panelName.TabIndex = 2; + // + // panelFurniture + // + panelFurniture.AutoSize = true; + panelFurniture.Controls.Add(textBoxFurniture); + panelFurniture.Controls.Add(labelFurniture); + panelFurniture.Dock = DockStyle.Top; + panelFurniture.Location = new Point(0, 58); + panelFurniture.Margin = new Padding(0); + panelFurniture.Name = "panelFurniture"; + panelFurniture.Padding = new Padding(10); + panelFurniture.Size = new Size(360, 58); + panelFurniture.TabIndex = 3; + // + // textBoxFurniture + // + textBoxFurniture.Dock = DockStyle.Top; + textBoxFurniture.Location = new Point(10, 25); + textBoxFurniture.Name = "textBoxFurniture"; + textBoxFurniture.Size = new Size(340, 23); + textBoxFurniture.TabIndex = 1; + textBoxFurniture.TextChanged += OnInputChange; + // + // labelFurniture + // + labelFurniture.AutoSize = true; + labelFurniture.Dock = DockStyle.Top; + labelFurniture.Location = new Point(10, 10); + labelFurniture.Name = "labelFurniture"; + labelFurniture.Size = new Size(50, 15); + labelFurniture.TabIndex = 0; + labelFurniture.Text = "Мебель"; + // + // panelType + // + panelType.AutoSize = true; + panelType.Controls.Add(buttonType); + panelType.Controls.Add(dropDownList); + panelType.Controls.Add(labelType); + panelType.Dock = DockStyle.Top; + panelType.Location = new Point(0, 116); + panelType.Margin = new Padding(0); + panelType.Name = "panelType"; + panelType.Padding = new Padding(10); + panelType.Size = new Size(360, 100); + panelType.TabIndex = 4; + // + // buttonType + // + buttonType.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + buttonType.Location = new Point(115, 64); + buttonType.Name = "buttonType"; + buttonType.Size = new Size(127, 23); + buttonType.TabIndex = 2; + buttonType.Text = "Редактировать типы"; + buttonType.UseVisualStyleBackColor = true; + buttonType.Click += ButtonTypeForm_Click; + // + // dropDownList + // + dropDownList.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dropDownList.Location = new Point(10, 28); + dropDownList.Name = "dropDownList"; + dropDownList.Selected = ""; + dropDownList.Size = new Size(340, 30); + dropDownList.TabIndex = 1; + // + // labelType + // + labelType.AutoSize = true; + labelType.Dock = DockStyle.Top; + labelType.Location = new Point(10, 10); + labelType.Name = "labelType"; + labelType.Size = new Size(101, 15); + labelType.TabIndex = 0; + labelType.Text = "Тип организации"; + // + // panelDate + // + panelDate.AutoSize = true; + panelDate.Controls.Add(controlInputNullableDate); + panelDate.Controls.Add(labelDate); + panelDate.Dock = DockStyle.Top; + panelDate.Location = new Point(0, 216); + panelDate.Margin = new Padding(0); + panelDate.Name = "panelDate"; + panelDate.Padding = new Padding(10); + panelDate.Size = new Size(360, 58); + panelDate.TabIndex = 6; + // + // controlInputNullableDate + // + controlInputNullableDate.Dock = DockStyle.Top; + controlInputNullableDate.Location = new Point(10, 25); + controlInputNullableDate.Margin = new Padding(4, 3, 4, 3); + controlInputNullableDate.Name = "controlInputNullableDate"; + controlInputNullableDate.Size = new Size(340, 23); + controlInputNullableDate.TabIndex = 1; + controlInputNullableDate.Value = null; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Dock = DockStyle.Top; + labelDate.Location = new Point(10, 10); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(85, 15); + labelDate.TabIndex = 0; + labelDate.Text = "Дата поставки"; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSave.Location = new Point(10, 7); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // panelButtons + // + panelButtons.AutoSize = true; + panelButtons.Controls.Add(buttonCancel); + panelButtons.Controls.Add(buttonSave); + panelButtons.Dock = DockStyle.Top; + panelButtons.Location = new Point(0, 274); + panelButtons.Margin = new Padding(0); + panelButtons.Name = "panelButtons"; + panelButtons.Padding = new Padding(10); + panelButtons.Size = new Size(360, 64); + panelButtons.TabIndex = 8; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(275, 7); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormProvider + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(360, 311); + Controls.Add(panelButtons); + Controls.Add(panelDate); + Controls.Add(panelType); + Controls.Add(panelFurniture); + Controls.Add(panelName); + MaximumSize = new Size(900, 350); + MinimumSize = new Size(200, 350); + Name = "FormProvider"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Редактирование"; + FormClosing += FormProvider_FormClosing; + Load += FormProvider_Load; + panelName.ResumeLayout(false); + panelName.PerformLayout(); + panelFurniture.ResumeLayout(false); + panelFurniture.PerformLayout(); + panelType.ResumeLayout(false); + panelType.PerformLayout(); + panelDate.ResumeLayout(false); + panelDate.PerformLayout(); + panelButtons.ResumeLayout(false); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelProviderName; + private TextBox textBoxName; + private Panel panelName; + private Panel panelFurniture; + private TextBox textBoxFurniture; + private Label labelFurniture; + private Panel panelType; + private Label labelType; + private Panel panelDate; + private ControlsLibraryNet60.Input.ControlInputNullableDate controlInputNullableDate; + private Label labelDate; + private Button buttonSave; + private Panel panelButtons; + private Button buttonCancel; + private Button buttonType; + private WinForm.DropDownList dropDownList; + } +} \ No newline at end of file diff --git a/WinForm/AppView/FormProvider.cs b/WinForm/AppView/FormProvider.cs new file mode 100644 index 0000000..cc9f194 --- /dev/null +++ b/WinForm/AppView/FormProvider.cs @@ -0,0 +1,159 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.StoragesContracts; +using Contracts.ViewModels; +using DocumentFormat.OpenXml.VariantTypes; + +namespace AppView +{ + public partial class FormProvider : Form + { + private int? _id; + public int Id { set { _id = value; } } + public readonly IProviderStorage _providerStorage; + public readonly ITypeStorage _typeStorage; + private bool isEdited; + + public FormProvider(IProviderStorage providerStorage, ITypeStorage typeStorage) + { + _providerStorage = providerStorage; + _typeStorage = typeStorage; + isEdited = false; + + InitializeComponent(); + } + + private void FormProvider_Load(object sender, EventArgs e) + { + controlInputNullableDate.ElementChanged += OnInputChange; + dropDownList.ExplicitEvent += OnInputChange; + LoadData(); + if (_id.HasValue) + { + try + { + var element = _providerStorage.GetElement(new ProviderSearchModel + { + Id = _id.Value, + }); + if (element != null) + { + textBoxName.Text = element.Name; + textBoxFurniture.Text = element.Furniture; + dropDownList.Selected = element.Type; + controlInputNullableDate.Value = element.SupplyDate; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении записи", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + try + { + var strings = _typeStorage.GetFullList().Select(item => item.Name).ToList(); + dropDownList.Clear(); + foreach (var item in strings) + { + dropDownList.ComboBoxItems.Add(item); + } + if (_id.HasValue) + { + var view = _providerStorage.GetElement(new ProviderSearchModel + { + Id = _id!.Value + }); + dropDownList.Selected = view!.Type; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка загрузки формы", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void OnInputChange(object sender, EventArgs e) + { + isEdited = true; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Название не указано"); + return; + } + + if (string.IsNullOrEmpty(textBoxFurniture.Text)) + { + MessageBox.Show("Перечень мебели не указан"); + return; + } + + if (string.IsNullOrEmpty(dropDownList.Selected)) + { + MessageBox.Show("Тип предприятия не выбран"); + return; + } + + isEdited = false; + + try + { + var model = new ProviderBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text, + Furniture = textBoxFurniture.Text, + Type = dropDownList.Selected, + SupplyDate = (controlInputNullableDate.Value != null) ? + DateTime.SpecifyKind((DateTime)controlInputNullableDate.Value, DateTimeKind.Utc) + : controlInputNullableDate.Value, + }; + var action = _id.HasValue ? _providerStorage.Update(model) : _providerStorage.Insert(model); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + Close(); + } + + private void ButtonTypeForm_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormType)); + if (service is FormType form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void FormProvider_FormClosing(object sender, FormClosingEventArgs e) + { + if (!isEdited) return; + + var confirmResult = MessageBox.Show( + "Имеются незафиксированные изменения." + + "\n" + + "Вы действительно хотите закрыть форму?", + "Подтвердите действие", + MessageBoxButtons.YesNo, + MessageBoxIcon.Question + ); + + if (confirmResult == DialogResult.No) e.Cancel = true; + } + } +} diff --git a/WinForm/AppView/FormProvider.resx b/WinForm/AppView/FormProvider.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/WinForm/AppView/FormProvider.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WinForm/AppView/FormType.Designer.cs b/WinForm/AppView/FormType.Designer.cs new file mode 100644 index 0000000..b293276 --- /dev/null +++ b/WinForm/AppView/FormType.Designer.cs @@ -0,0 +1,65 @@ +namespace AppView +{ + partial class FormType + { + /// + /// 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() + { + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ButtonHighlight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(355, 306); + dataGridView.TabIndex = 0; + dataGridView.CellValueChanged += DataGridView_CellValueChanged; + dataGridView.KeyDown += DataGridView_KeyDown; + // + // FormType + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(355, 306); + Controls.Add(dataGridView); + Name = "FormType"; + Text = "Редактирование типов организаций"; + Load += FormType_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/WinForm/AppView/FormType.cs b/WinForm/AppView/FormType.cs new file mode 100644 index 0000000..2d81ffc --- /dev/null +++ b/WinForm/AppView/FormType.cs @@ -0,0 +1,145 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.StoragesContracts; +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 AppView +{ + public partial class FormType : Form + { + private readonly ITypeStorage _typeStorage; + + public FormType(ITypeStorage typeStorage) + { + _typeStorage = typeStorage; + + InitializeComponent(); + } + + private void FormType_Load(object sender, EventArgs e) + { + LoadData(); + } + + public void LoadData() + { + try + { + var types = _typeStorage.GetFullList(); + if (types != null) + { + dataGridView.DataSource = types; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Name"].Tag = "Название"; + } + } + catch (Exception ex) + { + MessageBox.Show( + ex.Message, + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Error + ); + } + } + + private void DataGridView_KeyDown(object sender, KeyEventArgs e) + { + switch (e.KeyCode) + { + case Keys.Insert: + AddType(); + e.Handled = true; + break; + case Keys.Delete: + RemoveType(); + e.Handled = true; + break; + + } + } + + private void AddType() + { + var list = _typeStorage.GetFullList(); + list.Add(new()); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + + private void RemoveType() + { + if (dataGridView.SelectedRows.Count > 0) + { + DialogResult result = MessageBox.Show( + "Вы уверены, что хотите удалить выбранные записи?", + "Подтверждение удаления", + MessageBoxButtons.YesNo, + MessageBoxIcon.Question + ); + if (result == DialogResult.Yes) + { + foreach (DataGridViewRow row in dataGridView.SelectedRows) + { + if (!row.IsNewRow) + { + int id = Convert.ToInt32(row.Cells["Id"].Value); + var view = _typeStorage.GetElement(new TypeSearchModel + { + Id = id + }); + _typeStorage.Delete(new(view!)); + } + } + LoadData(); + } + } + } + + private void DataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex >= 0) + { + DataGridViewRow row = dataGridView.Rows[e.RowIndex]; + int id = Convert.ToInt32(row.Cells["Id"].Value); + string? name = row.Cells["Name"].Value?.ToString(); + + if (string.IsNullOrWhiteSpace(name)) + { + MessageBox.Show( + "Нельзя сохранить запись с пустым именем!", + "Ошибка", + MessageBoxButtons.OK, + MessageBoxIcon.Error + ); + LoadData(); + } + else + { + var model = new TypeBindingModel + { + Id = id, + Name = name + }; + if (model.Id == 0) _typeStorage.Insert(model); + else _typeStorage.Update(model); + LoadData(); + } + } + } + } +} diff --git a/WinForm/AppView/FormType.resx b/WinForm/AppView/FormType.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/WinForm/AppView/FormType.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/WinForm/AppView/Program.cs b/WinForm/AppView/Program.cs index 5561de2..9057480 100644 --- a/WinForm/AppView/Program.cs +++ b/WinForm/AppView/Program.cs @@ -1,7 +1,13 @@ +using Contracts.StoragesContracts; +using DataBaseImplement.Implements; +using Microsoft.Extensions.DependencyInjection; + namespace AppView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// /// The main entry point for the application. /// @@ -11,7 +17,19 @@ namespace AppView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureService(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + + private static void ConfigureService(IServiceCollection services) + { + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/WinForm/PdfFormsLibrary/DropDownList.Designer.cs b/WinForm/PdfFormsLibrary/DropDownList.Designer.cs index 0ca55a2..d6818bb 100644 --- a/WinForm/PdfFormsLibrary/DropDownList.Designer.cs +++ b/WinForm/PdfFormsLibrary/DropDownList.Designer.cs @@ -29,43 +29,30 @@ private void InitializeComponent() { comboBox = new ComboBox(); - labelTitle = new Label(); SuspendLayout(); // // comboBox // + comboBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; comboBox.FormattingEnabled = true; - comboBox.Location = new Point(13, 39); + comboBox.Location = new Point(3, 3); comboBox.Name = "comboBox"; - comboBox.Size = new Size(232, 23); + comboBox.Size = new Size(244, 23); comboBox.TabIndex = 0; comboBox.SelectedValueChanged += ComboBox_SelectedValueChanged; // - // labelTitle - // - labelTitle.AutoSize = true; - labelTitle.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point); - labelTitle.Location = new Point(13, 11); - labelTitle.Name = "labelTitle"; - labelTitle.Size = new Size(133, 15); - labelTitle.TabIndex = 1; - labelTitle.Text = "Выпадающий список"; - // // DropDownList // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - Controls.Add(labelTitle); Controls.Add(comboBox); Name = "DropDownList"; - Size = new Size(260, 80); + Size = new Size(250, 30); ResumeLayout(false); - PerformLayout(); } #endregion private ComboBox comboBox; - private Label labelTitle; } }