Compare commits
21 Commits
main
...
LabWork_04
Author | SHA1 | Date | |
---|---|---|---|
|
4786d2afe1 | ||
|
8f25b5ee36 | ||
|
b61f216f16 | ||
|
0bc52d4d10 | ||
|
608cc8afb1 | ||
|
088dedd6db | ||
|
d7fdaccf6d | ||
|
a3edd285d7 | ||
|
3df672c516 | ||
|
9e96681e74 | ||
|
f030f99ec3 | ||
|
82b55a47f4 | ||
|
4fb672e0af | ||
|
54da80ac79 | ||
|
313e38ecf2 | ||
|
0ddfe833c4 | ||
|
e7f656e80d | ||
|
e768fc4056 | ||
|
7eb1dcd63d | ||
|
a75923818e | ||
|
79a329d782 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,6 +4,8 @@
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
|
||||
|
||||
*.dll
|
||||
|
||||
# User-specific files
|
||||
*.rsuser
|
||||
*.suo
|
||||
|
37
WinForm/AppView/AppView.csproj
Normal file
37
WinForm/AppView/AppView.csproj
Normal file
@ -0,0 +1,37 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ComponentsLibraryNet60" Version="1.0.0" />
|
||||
<PackageReference Include="ControlsLibraryNet60" Version="1.0.0" />
|
||||
<PackageReference Include="ExcelFormsLibrary" Version="1.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="WinFormsLibrary" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
||||
<ProjectReference Include="..\DataBaseImplement\DataBaseImplement.csproj" />
|
||||
<ProjectReference Include="..\PdfFormsLibrary\PdfFormsLibrary.csproj" />
|
||||
<ProjectReference Include="..\PluginsConventionLibrary\PluginsConventionLibrary.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CreatePluginsFolder" BeforeTargets="PreBuildEvent" Condition="!Exists('$(SolutionDir)Plugins')">
|
||||
<MakeDir Directories="$(SolutionDir)Plugins" />
|
||||
</Target>
|
||||
|
||||
<Target Name="CopyPlugins" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="copy /Y "$(TargetDir)*.dll" "$(SolutionDir)Plugins\*.dll"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
149
WinForm/AppView/FormMain.Designer.cs
generated
Normal file
149
WinForm/AppView/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,149 @@
|
||||
namespace AppView
|
||||
{
|
||||
partial class FormMain
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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);
|
||||
circleDiagram = new WinFormsLibrary.CircleDiagram(components);
|
||||
componentWithSettings = new WinFormsLibrary.not_visual.ComponentWithSettings(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.Dock = DockStyle.Fill;
|
||||
controlDataTreeCell.Location = new Point(0, 0);
|
||||
controlDataTreeCell.Margin = new Padding(4, 3, 4, 3);
|
||||
controlDataTreeCell.Name = "controlDataTreeCell";
|
||||
controlDataTreeCell.Size = new Size(820, 450);
|
||||
controlDataTreeCell.TabIndex = 1;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(820, 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;
|
||||
private WinFormsLibrary.CircleDiagram circleDiagram;
|
||||
private WinFormsLibrary.not_visual.ComponentWithSettings componentWithSettings;
|
||||
}
|
||||
}
|
326
WinForm/AppView/FormMain.cs
Normal file
326
WinForm/AppView/FormMain.cs
Normal file
@ -0,0 +1,326 @@
|
||||
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;
|
||||
using WinFormsLibrary.SupportClasses;
|
||||
using WinFormsLibrary.SupportClasses.Enums;
|
||||
using DataBaseImplement.Models;
|
||||
using WinFormsLibrary.not_visual;
|
||||
|
||||
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<ProviderViewModel> 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<ProviderViewModel>() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormProvider));
|
||||
if (service is FormProvider form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(controlDataTreeCell.GetSelectedObject<ProviderViewModel>()?.Id);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveProviderItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (controlDataTreeCell.GetSelectedObject<ProviderViewModel>() == null) return;
|
||||
if (MessageBox.Show(
|
||||
"Вы хотите удалить выбранный элементы?",
|
||||
"Вопрос",
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_providerStorage.Delete(new(controlDataTreeCell.GetSelectedObject<ProviderViewModel>()));
|
||||
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<string> 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<ProviderViewModel> providersList = _providerStorage.GetFullList();
|
||||
foreach (var provider in providersList)
|
||||
{
|
||||
if (provider.SupplyDate == null)
|
||||
{
|
||||
provider.SupplyDateTime = "Поставок не было";
|
||||
provider.SupplyDate = DateTime.MinValue;
|
||||
continue;
|
||||
}
|
||||
provider.SupplyDateTime = provider.SupplyDate.ToString();
|
||||
}
|
||||
|
||||
var columnConfigs = new List<ColumnConfig>
|
||||
{
|
||||
new ColumnConfig { Width = 50f, PropertyName = "Id" },
|
||||
new ColumnConfig { Width = 50f, PropertyName = "Name" },
|
||||
new ColumnConfig { Width = 50f, PropertyName = "Type" },
|
||||
new ColumnConfig { Width = 70f, PropertyName = "SupplyDateTime" },
|
||||
};
|
||||
|
||||
SaveFileDialog saveFileDialog = new()
|
||||
{
|
||||
Filter = "Excel Files|*.xlsx"
|
||||
};
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
componentWithSettings.GenerateExcelDocument(saveFileDialog.FileName, "Отчет по всем поставщикам", columnConfigs, 25f, 35f, providersList);
|
||||
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(),
|
||||
});
|
||||
|
||||
List<double> results = new();
|
||||
List<string> names = new();
|
||||
|
||||
foreach (var provider in providersList)
|
||||
{
|
||||
results.Add(provider.Count);
|
||||
names.Add(provider.Type);
|
||||
}
|
||||
|
||||
SaveFileDialog saveFileDialog = new()
|
||||
{
|
||||
Filter = "Word Files|*.docx"
|
||||
};
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
SimpleCircleDiagram simpleCircleDiagram = new(saveFileDialog.FileName, "Круговая диаграмма", "Количество поставщиков в разрезе типа организации",
|
||||
EnumAreaLegend.Right, new() { new DataCircleDiagram("Типы организации", results.ToArray()) });
|
||||
simpleCircleDiagram.NameData = names.ToArray();
|
||||
try
|
||||
{
|
||||
circleDiagram.AddCircleDiagram(simpleCircleDiagram);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
81
WinForm/AppView/FormMain.resx
Normal file
81
WinForm/AppView/FormMain.resx
Normal file
@ -0,0 +1,81 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="contextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="componentDocumentWithTableMultiHeaderExcel.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>328, 17</value>
|
||||
</metadata>
|
||||
<metadata name="componentDocumentWithChartPieWord.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>923, 17</value>
|
||||
</metadata>
|
||||
<metadata name="componentDocumentWithChartBarWord.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 54</value>
|
||||
</metadata>
|
||||
<metadata name="pdfGeneratorControl.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>291, 54</value>
|
||||
</metadata>
|
||||
<metadata name="circleDiagram.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>456, 54</value>
|
||||
</metadata>
|
||||
<metadata name="componentWithSettings.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>582, 54</value>
|
||||
</metadata>
|
||||
</root>
|
278
WinForm/AppView/FormProvider.Designer.cs
generated
Normal file
278
WinForm/AppView/FormProvider.Designer.cs
generated
Normal file
@ -0,0 +1,278 @@
|
||||
namespace AppView
|
||||
{
|
||||
partial class FormProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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();
|
||||
customTextBox1 = new WinFormsLibrary.CustomTextBox();
|
||||
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.Right;
|
||||
buttonType.Location = new Point(220, 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(customTextBox1);
|
||||
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, 57);
|
||||
panelDate.TabIndex = 6;
|
||||
//
|
||||
// customTextBox1
|
||||
//
|
||||
customTextBox1.DateValue = null;
|
||||
customTextBox1.Location = new Point(112, 13);
|
||||
customTextBox1.Name = "customTextBox1";
|
||||
customTextBox1.Size = new Size(235, 31);
|
||||
customTextBox1.TabIndex = 1;
|
||||
//
|
||||
// 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.Right;
|
||||
buttonSave.Location = new Point(194, 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, 273);
|
||||
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, 358);
|
||||
Controls.Add(panelButtons);
|
||||
Controls.Add(panelDate);
|
||||
Controls.Add(panelType);
|
||||
Controls.Add(panelFurniture);
|
||||
Controls.Add(panelName);
|
||||
MaximumSize = new Size(900, 500);
|
||||
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 Label labelDate;
|
||||
private Button buttonSave;
|
||||
private Panel panelButtons;
|
||||
private Button buttonCancel;
|
||||
private Button buttonType;
|
||||
private WinForm.DropDownList dropDownList;
|
||||
private WinFormsLibrary.CustomTextBox customTextBox;
|
||||
private WinFormsLibrary.CustomTextBox customTextBox1;
|
||||
}
|
||||
}
|
158
WinForm/AppView/FormProvider.cs
Normal file
158
WinForm/AppView/FormProvider.cs
Normal file
@ -0,0 +1,158 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.StoragesContracts;
|
||||
using Contracts.ViewModels;
|
||||
|
||||
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)
|
||||
{
|
||||
customTextBox1.ValueChanged += 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;
|
||||
customTextBox1.DateValue = 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 = (customTextBox1.DateValue != null) ?
|
||||
DateTime.SpecifyKind((DateTime)customTextBox1.DateValue, DateTimeKind.Utc)
|
||||
: customTextBox1.DateValue,
|
||||
};
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
60
WinForm/AppView/FormProvider.resx
Normal file
60
WinForm/AppView/FormProvider.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
66
WinForm/AppView/FormType.Designer.cs
generated
Normal file
66
WinForm/AppView/FormType.Designer.cs
generated
Normal file
@ -0,0 +1,66 @@
|
||||
namespace AppView
|
||||
{
|
||||
partial class FormType
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Редактирование типов организаций";
|
||||
Load += FormType_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
}
|
||||
}
|
145
WinForm/AppView/FormType.cs
Normal file
145
WinForm/AppView/FormType.cs
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
WinForm/AppView/FormType.resx
Normal file
60
WinForm/AppView/FormType.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
249
WinForm/AppView/PluginsConvention.cs
Normal file
249
WinForm/AppView/PluginsConvention.cs
Normal file
@ -0,0 +1,249 @@
|
||||
using Contracts.StoragesContracts;
|
||||
using Contracts.ViewModels;
|
||||
using ControlsLibraryNet60.Data;
|
||||
using ControlsLibraryNet60.Models;
|
||||
using DataBaseImplement.Implements;
|
||||
using PdfFormsLibrary;
|
||||
using PluginsConventionLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WinFormsLibrary;
|
||||
using WinFormsLibrary.not_visual;
|
||||
using WinFormsLibrary.SupportClasses.Enums;
|
||||
using WinFormsLibrary.SupportClasses;
|
||||
|
||||
namespace AppView
|
||||
{
|
||||
public class PluginsConvention : IPluginsConvention
|
||||
{
|
||||
private readonly IProviderStorage _providerStorage;
|
||||
private readonly ITypeStorage _typeStorage;
|
||||
private readonly ControlDataTreeCell _controlDataTreeCell;
|
||||
private readonly PdfGeneratorControl _pdfGeneratorControl;
|
||||
private readonly ComponentWithSettings _componentWithSettings;
|
||||
private readonly CircleDiagram _circleDiagram;
|
||||
public string PluginName { get; set; } = "LabWork_03_plugin";
|
||||
|
||||
public UserControl GetControl
|
||||
{
|
||||
get { return _controlDataTreeCell; }
|
||||
}
|
||||
|
||||
public PluginsConventionElement GetElement
|
||||
{
|
||||
get
|
||||
{
|
||||
int Id = _controlDataTreeCell.GetSelectedObject<ProviderViewModel>()!.Id;
|
||||
byte[] bytes = new byte[16];
|
||||
BitConverter.GetBytes(Id).CopyTo(bytes, 0);
|
||||
Guid guid = new Guid(bytes);
|
||||
return new PluginsConventionElement() { Id = guid };
|
||||
}
|
||||
}
|
||||
|
||||
public PluginsConvention()
|
||||
{
|
||||
_providerStorage = new ProviderStorage();
|
||||
_typeStorage = new TypeStorage();
|
||||
_pdfGeneratorControl = new();
|
||||
_componentWithSettings = new();
|
||||
_circleDiagram = new();
|
||||
_controlDataTreeCell = new();
|
||||
}
|
||||
|
||||
public Form GetForm(PluginsConventionElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return new FormProvider(_providerStorage, _typeStorage);
|
||||
}
|
||||
else
|
||||
{
|
||||
FormProvider form = new FormProvider(_providerStorage, _typeStorage);
|
||||
form.Id = element.Id.GetHashCode();
|
||||
return form;
|
||||
}
|
||||
}
|
||||
|
||||
public Form GetThesaurus()
|
||||
{
|
||||
return new FormType(_typeStorage);
|
||||
}
|
||||
|
||||
public bool DeleteElement(PluginsConventionElement element)
|
||||
{
|
||||
_providerStorage.Delete(
|
||||
new(element.Id.GetHashCode())
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void ReloadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var providers = _providerStorage.GetFullList();
|
||||
if (providers != null)
|
||||
{
|
||||
_controlDataTreeCell.Clear();
|
||||
|
||||
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);
|
||||
|
||||
if (providers.Count > 0)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
ex.Message,
|
||||
"Ошибка",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument)
|
||||
{
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
string filePath = saveDocument.FileName;
|
||||
string documentTitle = "Поставщики";
|
||||
List<string> 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);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
$"Ошибка при создании PDF-документа: {ex.Message}",
|
||||
"Ошибка",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CreateTableDocument(PluginsConventionSaveDocument saveDocument)
|
||||
{
|
||||
List<ProviderViewModel> providersList = _providerStorage.GetFullList();
|
||||
foreach (var provider in providersList)
|
||||
{
|
||||
if (provider.SupplyDate == null)
|
||||
{
|
||||
provider.SupplyDateTime = "Поставок не было";
|
||||
provider.SupplyDate = DateTime.MinValue;
|
||||
continue;
|
||||
}
|
||||
provider.SupplyDateTime = provider.SupplyDate.ToString();
|
||||
}
|
||||
|
||||
var columnConfigs = new List<ColumnConfig>
|
||||
{
|
||||
new ColumnConfig { Width = 50f, PropertyName = "Id" },
|
||||
new ColumnConfig { Width = 50f, PropertyName = "Name" },
|
||||
new ColumnConfig { Width = 50f, PropertyName = "Type" },
|
||||
new ColumnConfig { Width = 70f, PropertyName = "SupplyDateTime" },
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
_componentWithSettings.GenerateExcelDocument(saveDocument.FileName, "Отчет по всем поставщикам", columnConfigs, 25f, 35f, providersList);
|
||||
MessageBox.Show(
|
||||
"Excel-документ успешно сохранен.",
|
||||
"Успех",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information
|
||||
);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
$"Ошибка при создании Excel-документа: {ex.Message}",
|
||||
"Ошибка",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CreateChartDocument(PluginsConventionSaveDocument saveDocument)
|
||||
{
|
||||
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(),
|
||||
});
|
||||
|
||||
List<double> results = new();
|
||||
List<string> names = new();
|
||||
|
||||
foreach (var provider in providersList)
|
||||
{
|
||||
results.Add(provider.Count);
|
||||
names.Add(provider.Type);
|
||||
}
|
||||
|
||||
SimpleCircleDiagram simpleCircleDiagram = new(saveDocument.FileName, "Круговая диаграмма", "Количество поставщиков в разрезе типа организации",
|
||||
EnumAreaLegend.Right, new() { new DataCircleDiagram("Типы организации", results.ToArray()) });
|
||||
simpleCircleDiagram.NameData = names.ToArray();
|
||||
try
|
||||
{
|
||||
_circleDiagram.AddCircleDiagram(simpleCircleDiagram);
|
||||
MessageBox.Show(
|
||||
"Word-документ успешно сохранен.",
|
||||
"Успех",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information
|
||||
);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
$"Ошибка при создании Word-документа: {ex.Message}",
|
||||
"Ошибка",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
35
WinForm/AppView/Program.cs
Normal file
35
WinForm/AppView/Program.cs
Normal file
@ -0,0 +1,35 @@
|
||||
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;
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
var services = new ServiceCollection();
|
||||
ConfigureService(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
}
|
||||
|
||||
private static void ConfigureService(IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<IProviderStorage, ProviderStorage>();
|
||||
services.AddTransient<ITypeStorage, TypeStorage>();
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormProvider>();
|
||||
services.AddTransient<FormType>();
|
||||
}
|
||||
}
|
||||
}
|
31
WinForm/Contracts/BindingModels/ProviderBindingModel.cs
Normal file
31
WinForm/Contracts/BindingModels/ProviderBindingModel.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.BindingModels
|
||||
{
|
||||
public class ProviderBindingModel : IProviderModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string Furniture { get; set; }
|
||||
public DateTime? SupplyDate { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public ProviderBindingModel() { }
|
||||
|
||||
public ProviderBindingModel(IProviderModel provider)
|
||||
{
|
||||
Id = provider.Id;
|
||||
}
|
||||
|
||||
public ProviderBindingModel(int id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
}
|
||||
}
|
22
WinForm/Contracts/BindingModels/TypeBindingModel.cs
Normal file
22
WinForm/Contracts/BindingModels/TypeBindingModel.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.BindingModels
|
||||
{
|
||||
public class TypeBindingModel : ITypeModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
public TypeBindingModel() { }
|
||||
|
||||
public TypeBindingModel(ITypeModel type)
|
||||
{
|
||||
Id = type.Id;
|
||||
}
|
||||
}
|
||||
}
|
13
WinForm/Contracts/Contracts.csproj
Normal file
13
WinForm/Contracts/Contracts.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DataModels\DataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
13
WinForm/Contracts/SearchModels/ProviderSearchModel.cs
Normal file
13
WinForm/Contracts/SearchModels/ProviderSearchModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.SearchModels
|
||||
{
|
||||
public class ProviderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
}
|
13
WinForm/Contracts/SearchModels/TypeSearchModel.cs
Normal file
13
WinForm/Contracts/SearchModels/TypeSearchModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.SearchModels
|
||||
{
|
||||
public class TypeSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
}
|
21
WinForm/Contracts/StoragesContracts/IProviderStorage.cs
Normal file
21
WinForm/Contracts/StoragesContracts/IProviderStorage.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.StoragesContracts
|
||||
{
|
||||
public interface IProviderStorage
|
||||
{
|
||||
List<ProviderViewModel> GetFullList();
|
||||
ProviderViewModel? GetElement(ProviderSearchModel model);
|
||||
List<ProviderViewModel> GetFilteredList(ProviderSearchModel model);
|
||||
ProviderViewModel? Insert(ProviderBindingModel model);
|
||||
ProviderViewModel? Update(ProviderBindingModel model);
|
||||
ProviderViewModel? Delete(ProviderBindingModel model);
|
||||
}
|
||||
}
|
20
WinForm/Contracts/StoragesContracts/ITypeStorage.cs
Normal file
20
WinForm/Contracts/StoragesContracts/ITypeStorage.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.StoragesContracts
|
||||
{
|
||||
public interface ITypeStorage
|
||||
{
|
||||
List<TypeViewModel> GetFullList();
|
||||
TypeViewModel? GetElement(TypeSearchModel model);
|
||||
TypeViewModel? Insert(TypeBindingModel model);
|
||||
TypeViewModel? Update(TypeBindingModel model);
|
||||
TypeViewModel? Delete(TypeBindingModel model);
|
||||
}
|
||||
}
|
19
WinForm/Contracts/ViewModels/ProviderViewModel.cs
Normal file
19
WinForm/Contracts/ViewModels/ProviderViewModel.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.ViewModels
|
||||
{
|
||||
public class ProviderViewModel : IProviderModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Type { get; set; }
|
||||
public string Furniture { get; set; }
|
||||
public DateTime? SupplyDate { get; set; }
|
||||
public string? SupplyDateTime { get; set; }
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
15
WinForm/Contracts/ViewModels/TypeViewModel.cs
Normal file
15
WinForm/Contracts/ViewModels/TypeViewModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.ViewModels
|
||||
{
|
||||
public class TypeViewModel : ITypeModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
18
WinForm/DataBaseImplement/DBContext.cs
Normal file
18
WinForm/DataBaseImplement/DBContext.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using DataBaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DataBaseImplement
|
||||
{
|
||||
public class DBContext:DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if(!optionsBuilder.IsConfigured)
|
||||
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=COP;Username=courseuser;Password=courseuser");
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
public virtual DbSet<Provider> Providers { get; set; }
|
||||
public virtual DbSet<Models.Type> Types { get; set; }
|
||||
}
|
||||
}
|
23
WinForm/DataBaseImplement/DataBaseImplement.csproj
Normal file
23
WinForm/DataBaseImplement/DataBaseImplement.csproj
Normal file
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
||||
<ProjectReference Include="..\DataModels\DataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
89
WinForm/DataBaseImplement/Implements/ProviderStorage.cs
Normal file
89
WinForm/DataBaseImplement/Implements/ProviderStorage.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.StoragesContracts;
|
||||
using Contracts.ViewModels;
|
||||
using DataBaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataBaseImplement.Implements
|
||||
{
|
||||
public class ProviderStorage : IProviderStorage
|
||||
{
|
||||
public ProviderViewModel? Delete(ProviderBindingModel model)
|
||||
{
|
||||
using var context = new DBContext();
|
||||
var element = context.Providers.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Providers.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
public ProviderViewModel? GetElement(ProviderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new DBContext();
|
||||
return context.Providers.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ProviderViewModel> GetFilteredList(ProviderSearchModel model)
|
||||
{
|
||||
using var context = new DBContext();
|
||||
return context.Providers
|
||||
.Where(x => model.Id.HasValue && x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ProviderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new DBContext();
|
||||
return context.Providers
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ProviderViewModel? Insert(ProviderBindingModel model)
|
||||
{
|
||||
var newProvider = Provider.Create(model);
|
||||
|
||||
if (newProvider == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new DBContext();
|
||||
context.Providers.Add(newProvider);
|
||||
context.SaveChanges();
|
||||
return newProvider.GetViewModel;
|
||||
}
|
||||
|
||||
public ProviderViewModel? Update(ProviderBindingModel model)
|
||||
{
|
||||
using var context = new DBContext();
|
||||
var provider = context.Providers.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (provider == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
provider.Update(model);
|
||||
context.SaveChanges();
|
||||
return provider.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
79
WinForm/DataBaseImplement/Implements/TypeStorage.cs
Normal file
79
WinForm/DataBaseImplement/Implements/TypeStorage.cs
Normal file
@ -0,0 +1,79 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.StoragesContracts;
|
||||
using Contracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataBaseImplement.Implements
|
||||
{
|
||||
public class TypeStorage : ITypeStorage
|
||||
{
|
||||
public TypeViewModel? Delete(TypeBindingModel model)
|
||||
{
|
||||
using var context = new DBContext();
|
||||
var element = context.Types.FirstOrDefault(x => x.Id == x.Id);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Types.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
public TypeViewModel? GetElement(TypeSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new DBContext();
|
||||
return context.Types.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<TypeViewModel> GetFullList()
|
||||
{
|
||||
using var context = new DBContext();
|
||||
return context.Types
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public TypeViewModel? Insert(TypeBindingModel model)
|
||||
{
|
||||
var newType = Models.Type.Create(model);
|
||||
|
||||
if (newType == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new DBContext();
|
||||
context.Types.Add(newType);
|
||||
context.SaveChanges();
|
||||
return newType.GetViewModel;
|
||||
}
|
||||
|
||||
public TypeViewModel? Update(TypeBindingModel model)
|
||||
{
|
||||
using var context = new DBContext();
|
||||
var type = context.Types.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (type == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
type.Update(model);
|
||||
context.SaveChanges();
|
||||
return type.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
75
WinForm/DataBaseImplement/Migrations/20231101203036_InitMig.Designer.cs
generated
Normal file
75
WinForm/DataBaseImplement/Migrations/20231101203036_InitMig.Designer.cs
generated
Normal file
@ -0,0 +1,75 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DataBaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DataBaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(DBContext))]
|
||||
[Migration("20231101203036_InitMig")]
|
||||
partial class InitMig
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.13")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("DataBaseImplement.Models.Provider", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Furniture")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime?>("SupplyDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Providers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DataBaseImplement.Models.Type", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Types");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DataBaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitMig : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Providers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Type = table.Column<string>(type: "text", nullable: false),
|
||||
Furniture = table.Column<string>(type: "text", nullable: false),
|
||||
SupplyDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Providers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Types",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Types", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Providers");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Types");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DataBaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DataBaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(DBContext))]
|
||||
partial class DBContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.13")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("DataBaseImplement.Models.Provider", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Furniture")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime?>("SupplyDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Providers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DataBaseImplement.Models.Type", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Types");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
55
WinForm/DataBaseImplement/Models/Provider.cs
Normal file
55
WinForm/DataBaseImplement/Models/Provider.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.ViewModels;
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataBaseImplement.Models
|
||||
{
|
||||
public class Provider : IProviderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
[Required]
|
||||
public string Type { get; set; }
|
||||
[Required]
|
||||
public string Furniture { get; set; }
|
||||
public DateTime? SupplyDate { get; set; } = DateTime.MinValue;
|
||||
|
||||
public static Provider? Create(ProviderBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
return new Provider()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Type = model.Type,
|
||||
Furniture = model.Furniture,
|
||||
SupplyDate = model.SupplyDate,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ProviderBindingModel model)
|
||||
{
|
||||
if (model == null) return;
|
||||
Name = model.Name;
|
||||
Type = model.Type;
|
||||
Furniture = model.Furniture;
|
||||
SupplyDate = model.SupplyDate;
|
||||
}
|
||||
|
||||
public ProviderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Type = Type,
|
||||
Furniture = Furniture,
|
||||
SupplyDate = SupplyDate,
|
||||
};
|
||||
}
|
||||
}
|
41
WinForm/DataBaseImplement/Models/Type.cs
Normal file
41
WinForm/DataBaseImplement/Models/Type.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.ViewModels;
|
||||
using DataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataBaseImplement.Models
|
||||
{
|
||||
public class Type : ITypeModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
|
||||
public static Type? Create(TypeBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
return new Type()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(TypeBindingModel? model)
|
||||
{
|
||||
if (model == null) return;
|
||||
Name = model.Name;
|
||||
}
|
||||
|
||||
public TypeViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
};
|
||||
}
|
||||
}
|
9
WinForm/DataModels/DataModels.csproj
Normal file
9
WinForm/DataModels/DataModels.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
13
WinForm/DataModels/IId.cs
Normal file
13
WinForm/DataModels/IId.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataModels
|
||||
{
|
||||
public interface IId
|
||||
{
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
16
WinForm/DataModels/Models/IProviderModel.cs
Normal file
16
WinForm/DataModels/Models/IProviderModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataModels.Models
|
||||
{
|
||||
public interface IProviderModel : IId
|
||||
{
|
||||
string Name { get; set; }
|
||||
string Type { get; set; }
|
||||
string Furniture { get; set; }
|
||||
DateTime? SupplyDate { get; set; }
|
||||
}
|
||||
}
|
13
WinForm/DataModels/Models/ITypeModel.cs
Normal file
13
WinForm/DataModels/Models/ITypeModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataModels.Models
|
||||
{
|
||||
public interface ITypeModel : IId
|
||||
{
|
||||
string Name { get; }
|
||||
}
|
||||
}
|
58
WinForm/PdfFormsLibrary/DropDownList.Designer.cs
generated
Normal file
58
WinForm/PdfFormsLibrary/DropDownList.Designer.cs
generated
Normal file
@ -0,0 +1,58 @@
|
||||
namespace WinForm
|
||||
{
|
||||
partial class DropDownList
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
comboBox = new ComboBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// comboBox
|
||||
//
|
||||
comboBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
comboBox.FormattingEnabled = true;
|
||||
comboBox.Location = new Point(3, 3);
|
||||
comboBox.Name = "comboBox";
|
||||
comboBox.Size = new Size(244, 23);
|
||||
comboBox.TabIndex = 0;
|
||||
comboBox.SelectedValueChanged += ComboBox_SelectedValueChanged;
|
||||
//
|
||||
// DropDownList
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(comboBox);
|
||||
Name = "DropDownList";
|
||||
Size = new Size(250, 30);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBox;
|
||||
}
|
||||
}
|
72
WinForm/PdfFormsLibrary/DropDownList.cs
Normal file
72
WinForm/PdfFormsLibrary/DropDownList.cs
Normal file
@ -0,0 +1,72 @@
|
||||
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 WinForm
|
||||
{
|
||||
public partial class DropDownList : UserControl
|
||||
{
|
||||
public DropDownList()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
comboBox.Items.Clear();
|
||||
}
|
||||
|
||||
public string Selected
|
||||
{
|
||||
get
|
||||
{
|
||||
if (comboBox.Items.Count == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
if (comboBox.SelectedItem == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return comboBox.SelectedItem.ToString()!;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (comboBox.Items.Contains(value))
|
||||
{
|
||||
comboBox.SelectedItem = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public ComboBox.ObjectCollection ComboBoxItems
|
||||
{
|
||||
get { return comboBox.Items; }
|
||||
}
|
||||
|
||||
private EventHandler _explicitEvent;
|
||||
public event EventHandler ExplicitEvent
|
||||
{
|
||||
add
|
||||
{
|
||||
_explicitEvent += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_explicitEvent -= value;
|
||||
}
|
||||
}
|
||||
|
||||
private void ComboBox_SelectedValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
_explicitEvent?.Invoke(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
60
WinForm/PdfFormsLibrary/DropDownList.resx
Normal file
60
WinForm/PdfFormsLibrary/DropDownList.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
57
WinForm/PdfFormsLibrary/Helpers/DiagramLegendPosition.cs
Normal file
57
WinForm/PdfFormsLibrary/Helpers/DiagramLegendPosition.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using OxyPlot.Legends;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PdfFormsLibrary.Helpers
|
||||
{
|
||||
public class LegendSettingsAttribute : Attribute
|
||||
{
|
||||
public LegendPosition Position { get; }
|
||||
public LegendPlacement Placement { get; }
|
||||
|
||||
public LegendSettingsAttribute(LegendPosition position, LegendPlacement placement)
|
||||
{
|
||||
Position = position;
|
||||
Placement = placement;
|
||||
}
|
||||
}
|
||||
|
||||
public enum DiagramLegendPosition
|
||||
{
|
||||
[LegendSettings(LegendPosition.LeftTop, LegendPlacement.Outside)]
|
||||
TopLeftOutside,
|
||||
[LegendSettings(LegendPosition.TopCenter, LegendPlacement.Outside)]
|
||||
TopCenterOutside,
|
||||
[LegendSettings(LegendPosition.RightTop, LegendPlacement.Outside)]
|
||||
TopRightOutside,
|
||||
[LegendSettings(LegendPosition.LeftMiddle, LegendPlacement.Outside)]
|
||||
MiddleLeftOutside,
|
||||
[LegendSettings(LegendPosition.RightMiddle, LegendPlacement.Outside)]
|
||||
MiddleRightOutside,
|
||||
[LegendSettings(LegendPosition.BottomLeft, LegendPlacement.Outside)]
|
||||
BottomLeftOutside,
|
||||
[LegendSettings(LegendPosition.BottomCenter, LegendPlacement.Outside)]
|
||||
BottomCenterOutside,
|
||||
[LegendSettings(LegendPosition.BottomRight, LegendPlacement.Outside)]
|
||||
BottomRightOutside,
|
||||
[LegendSettings(LegendPosition.LeftTop, LegendPlacement.Inside)]
|
||||
TopLeftInside,
|
||||
[LegendSettings(LegendPosition.TopCenter, LegendPlacement.Inside)]
|
||||
TopCenterInside,
|
||||
[LegendSettings(LegendPosition.RightTop, LegendPlacement.Inside)]
|
||||
TopRightInside,
|
||||
[LegendSettings(LegendPosition.LeftMiddle, LegendPlacement.Inside)]
|
||||
MiddleLeftInside,
|
||||
[LegendSettings(LegendPosition.RightMiddle, LegendPlacement.Inside)]
|
||||
MiddleRightInside,
|
||||
[LegendSettings(LegendPosition.BottomLeft, LegendPlacement.Inside)]
|
||||
BottomLeftInside,
|
||||
[LegendSettings(LegendPosition.BottomCenter, LegendPlacement.Inside)]
|
||||
BottomCenterInside,
|
||||
[LegendSettings(LegendPosition.BottomRight, LegendPlacement.Inside)]
|
||||
BottomRightInside,
|
||||
}
|
||||
}
|
17
WinForm/PdfFormsLibrary/Helpers/PdfWithDiagramData.cs
Normal file
17
WinForm/PdfFormsLibrary/Helpers/PdfWithDiagramData.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PdfFormsLibrary.Helpers
|
||||
{
|
||||
public class PdfWithDiagramData
|
||||
{
|
||||
public string FilePath { get; set; } = string.Empty;
|
||||
public string DocumentTitle { get; set; } = string.Empty;
|
||||
public string DiagramName { get; set; } = string.Empty;
|
||||
public DiagramLegendPosition LegendPosition { get; set; } = DiagramLegendPosition.BottomCenterOutside;
|
||||
public List<PdfWithDiagramSeries> Series { get; set; } = new();
|
||||
}
|
||||
}
|
14
WinForm/PdfFormsLibrary/Helpers/PdfWithDiagramSeries.cs
Normal file
14
WinForm/PdfFormsLibrary/Helpers/PdfWithDiagramSeries.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PdfFormsLibrary.Helpers
|
||||
{
|
||||
public class PdfWithDiagramSeries
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public List<(double, double)> Data { get; set; } = new();
|
||||
}
|
||||
}
|
17
WinForm/PdfFormsLibrary/Helpers/PdfWithTableData.cs
Normal file
17
WinForm/PdfFormsLibrary/Helpers/PdfWithTableData.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PdfFormsLibrary.Helpers
|
||||
{
|
||||
public class PdfWithTableData<T>
|
||||
{
|
||||
public string FilePath { get; set; } = string.Empty;
|
||||
public string DocumentTitle { get; set; } = string.Empty;
|
||||
public List<PdfWithTableHeader> TableHeader { get; set; } = new();
|
||||
public List<T> TableData { get; set; } = new();
|
||||
public List<string> Props { get; set; } = new();
|
||||
}
|
||||
}
|
15
WinForm/PdfFormsLibrary/Helpers/PdfWithTableHeader.cs
Normal file
15
WinForm/PdfFormsLibrary/Helpers/PdfWithTableHeader.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PdfFormsLibrary.Helpers
|
||||
{
|
||||
public class PdfWithTableHeader
|
||||
{
|
||||
public string? ColumnName { get; set; } = string.Empty;
|
||||
public int ColumnWidth { get; set; } = 100;
|
||||
public List<PdfWithTableSubHeader> SubColumns { get; set; } = new List<PdfWithTableSubHeader>();
|
||||
}
|
||||
}
|
14
WinForm/PdfFormsLibrary/Helpers/PdfWithTableSubHeader.cs
Normal file
14
WinForm/PdfFormsLibrary/Helpers/PdfWithTableSubHeader.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PdfFormsLibrary.Helpers
|
||||
{
|
||||
public class PdfWithTableSubHeader
|
||||
{
|
||||
public string? ColumnName { get; set; } = string.Empty;
|
||||
public int ColumnWidth { get; set; } = 100;
|
||||
}
|
||||
}
|
57
WinForm/PdfFormsLibrary/ListBoxValues.Designer.cs
generated
Normal file
57
WinForm/PdfFormsLibrary/ListBoxValues.Designer.cs
generated
Normal file
@ -0,0 +1,57 @@
|
||||
namespace WinForm
|
||||
{
|
||||
partial class ListBoxValues
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
listBox = new ListBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// listBox
|
||||
//
|
||||
listBox.FormattingEnabled = true;
|
||||
listBox.ItemHeight = 15;
|
||||
listBox.Location = new Point(3, 3);
|
||||
listBox.Name = "listBox";
|
||||
listBox.Size = new Size(194, 154);
|
||||
listBox.TabIndex = 0;
|
||||
//
|
||||
// ListBoxValues
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(listBox);
|
||||
Name = "ListBoxValues";
|
||||
Size = new Size(200, 160);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ListBox listBox;
|
||||
}
|
||||
}
|
113
WinForm/PdfFormsLibrary/ListBoxValues.cs
Normal file
113
WinForm/PdfFormsLibrary/ListBoxValues.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace WinForm
|
||||
{
|
||||
public partial class ListBoxValues : UserControl
|
||||
{
|
||||
private string layoutString;
|
||||
private string startSymbol;
|
||||
private string endSymbol;
|
||||
|
||||
public ListBoxValues()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void SetLayoutInfo(string layout, string startS, string endS)
|
||||
{
|
||||
if (layout == null || startS == null || endS == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
layoutString = layout;
|
||||
startSymbol = startS;
|
||||
endSymbol = endS;
|
||||
}
|
||||
|
||||
public int SelectedIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
if (listBox.SelectedIndex == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return listBox.SelectedIndex;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (listBox.SelectedItems.Count != 0)
|
||||
{
|
||||
listBox.SelectedIndex = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T GetObjectFromStr<T>() where T : class, new()
|
||||
{
|
||||
if (listBox.SelectedIndex == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string row = listBox.SelectedItem.ToString()!;
|
||||
T curObject = new T();
|
||||
StringBuilder sb = new StringBuilder(row);
|
||||
foreach (var property in typeof(T).GetProperties())
|
||||
{
|
||||
if (!property.CanWrite)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int borderOne = sb.ToString().IndexOf(startSymbol);
|
||||
if (borderOne == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
int borderTwo = sb.ToString().IndexOf(endSymbol, borderOne + 1);
|
||||
if (borderTwo == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
string propertyValue = sb.ToString(borderOne + 1, borderTwo - borderOne - 1);
|
||||
sb.Remove(0, borderTwo + 1);
|
||||
property.SetValue(curObject, Convert.ChangeType(propertyValue, property.PropertyType));
|
||||
}
|
||||
return curObject;
|
||||
}
|
||||
|
||||
public void FillProperty<T>(T dataObject, int rowIndex, string propertyName)
|
||||
{
|
||||
if (layoutString == null || startSymbol == null || endSymbol == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (listBox.Items.Count <= rowIndex)
|
||||
{
|
||||
listBox.Items.Add(layoutString);
|
||||
}
|
||||
|
||||
string row = listBox.Items[rowIndex].ToString();
|
||||
PropertyInfo propertyInfo = dataObject.GetType().GetProperty(propertyName);
|
||||
|
||||
if (propertyInfo != null)
|
||||
{
|
||||
object propertyValue = propertyInfo.GetValue(dataObject);
|
||||
row = row.Replace($"{startSymbol}{propertyName}{endSymbol}", propertyValue.ToString());
|
||||
listBox.Items[rowIndex] = row;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
WinForm/PdfFormsLibrary/ListBoxValues.resx
Normal file
60
WinForm/PdfFormsLibrary/ListBoxValues.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
60
WinForm/PdfFormsLibrary/NumberTextBox.Designer.cs
generated
Normal file
60
WinForm/PdfFormsLibrary/NumberTextBox.Designer.cs
generated
Normal file
@ -0,0 +1,60 @@
|
||||
namespace WinForm
|
||||
{
|
||||
partial class NumberTextBox
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
textBox = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// textBox
|
||||
//
|
||||
textBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
textBox.Location = new Point(3, 3);
|
||||
textBox.Name = "textBox";
|
||||
textBox.Size = new Size(254, 23);
|
||||
textBox.TabIndex = 2;
|
||||
textBox.TextChanged += TextBox_TextChanged;
|
||||
textBox.Enter += TextBox_Enter;
|
||||
//
|
||||
// NumberTextBox
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(textBox);
|
||||
Name = "NumberTextBox";
|
||||
Size = new Size(260, 29);
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TextBox numberTextBox;
|
||||
private TextBox textBox;
|
||||
}
|
||||
}
|
86
WinForm/PdfFormsLibrary/NumberTextBox.cs
Normal file
86
WinForm/PdfFormsLibrary/NumberTextBox.cs
Normal file
@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace WinForm
|
||||
{
|
||||
public partial class NumberTextBox : UserControl
|
||||
{
|
||||
//Шаблон для textbox
|
||||
private string? pattern;
|
||||
private string example = "+7XXXXXXXXXX";
|
||||
|
||||
public NumberTextBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
//Публичное свойство для получения и заполнения шаблона
|
||||
public string? Pattern
|
||||
{
|
||||
get { return pattern; }
|
||||
set { pattern = value; }
|
||||
}
|
||||
|
||||
public string? TextBoxValue
|
||||
{
|
||||
get
|
||||
{
|
||||
if (new Regex(Pattern).IsMatch(textBox.Text))
|
||||
{
|
||||
return textBox.Text;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (new Regex(Pattern).IsMatch(value))
|
||||
{
|
||||
textBox.Text = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Метод для заполнения примера
|
||||
public void SetExample(string str)
|
||||
{
|
||||
if (new Regex(Pattern).IsMatch(str))
|
||||
{
|
||||
example = str;
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_Enter(object sender, EventArgs e)
|
||||
{
|
||||
int VisibleTime = 3000;
|
||||
ToolTip tt = new ToolTip();
|
||||
tt.Show(example, textBox, 0, 25, VisibleTime);
|
||||
}
|
||||
|
||||
private EventHandler _explicitEvent;
|
||||
public event EventHandler ExplicitEvent
|
||||
{
|
||||
add
|
||||
{
|
||||
_explicitEvent += value;
|
||||
}
|
||||
remove
|
||||
{
|
||||
_explicitEvent -= value;
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
_explicitEvent?.Invoke(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
60
WinForm/PdfFormsLibrary/NumberTextBox.resx
Normal file
60
WinForm/PdfFormsLibrary/NumberTextBox.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
17
WinForm/PdfFormsLibrary/PdfFormsLibrary.csproj
Normal file
17
WinForm/PdfFormsLibrary/PdfFormsLibrary.csproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="OxyPlot.Core" Version="2.1.2" />
|
||||
<PackageReference Include="OxyPlot.WindowsForms" Version="2.1.2" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
36
WinForm/PdfFormsLibrary/PdfGeneratorControl.Designer.cs
generated
Normal file
36
WinForm/PdfFormsLibrary/PdfGeneratorControl.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace PdfFormsLibrary
|
||||
{
|
||||
partial class PdfGeneratorControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
55
WinForm/PdfFormsLibrary/PdfGeneratorControl.cs
Normal file
55
WinForm/PdfFormsLibrary/PdfGeneratorControl.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.Rendering;
|
||||
using PdfSharp.Fonts;
|
||||
using PdfSharp.Pdf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PdfFormsLibrary
|
||||
{
|
||||
public partial class PdfGeneratorControl : Component
|
||||
{
|
||||
public PdfGeneratorControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public PdfGeneratorControl(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void GeneratePdf(string filePath, string documentTitle, List<string> textData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath) || string.IsNullOrEmpty(documentTitle) || textData == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Document document = new Document();
|
||||
|
||||
Section section = document.AddSection();
|
||||
|
||||
Paragraph title = section.AddParagraph(documentTitle);
|
||||
title.Format.Font.Bold = true;
|
||||
|
||||
foreach (var item in textData)
|
||||
{
|
||||
Paragraph paragraph = section.AddParagraph();
|
||||
paragraph.AddText(item);
|
||||
}
|
||||
|
||||
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true, PdfFontEmbedding.Always);
|
||||
pdfRenderer.Document = document;
|
||||
pdfRenderer.RenderDocument();
|
||||
pdfRenderer.PdfDocument.Save(filePath);
|
||||
}
|
||||
}
|
||||
}
|
36
WinForm/PdfFormsLibrary/PdfGeneratorLinearDiagram.Designer.cs
generated
Normal file
36
WinForm/PdfFormsLibrary/PdfGeneratorLinearDiagram.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace PdfFormsLibrary
|
||||
{
|
||||
partial class PdfGeneratorLinearDiagram
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
84
WinForm/PdfFormsLibrary/PdfGeneratorLinearDiagram.cs
Normal file
84
WinForm/PdfFormsLibrary/PdfGeneratorLinearDiagram.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.Rendering;
|
||||
using OxyPlot;
|
||||
using OxyPlot.Axes;
|
||||
using OxyPlot.Legends;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot.WindowsForms;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using PdfFormsLibrary.Helpers;
|
||||
|
||||
namespace PdfFormsLibrary
|
||||
{
|
||||
public partial class PdfGeneratorLinearDiagram : Component
|
||||
{
|
||||
public PdfGeneratorLinearDiagram()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public PdfGeneratorLinearDiagram(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void GeneratePdfDocumentWithChart(PdfWithDiagramData pdfDiagram)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pdfDiagram.FilePath) || string.IsNullOrEmpty(pdfDiagram.DocumentTitle)
|
||||
|| string.IsNullOrEmpty(pdfDiagram.DiagramName) || pdfDiagram.Series == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var plotModel = new PlotModel { Title = pdfDiagram.DiagramName };
|
||||
|
||||
var xAxis = new LinearAxis { Position = AxisPosition.Bottom };
|
||||
var yAxis = new LinearAxis { Position = AxisPosition.Left };
|
||||
plotModel.Axes.Add(xAxis);
|
||||
plotModel.Axes.Add(yAxis);
|
||||
|
||||
foreach (var item in pdfDiagram.Series)
|
||||
{
|
||||
var singleSeries = new LineSeries { Title = item.Name };
|
||||
foreach (var coordinates in item.Data)
|
||||
{
|
||||
singleSeries.Points.Add(new DataPoint(coordinates.Item1, coordinates.Item2));
|
||||
}
|
||||
plotModel.Series.Add(singleSeries);
|
||||
}
|
||||
|
||||
var fieldInfo = typeof(DiagramLegendPosition).GetField(pdfDiagram.LegendPosition.ToString());
|
||||
var attribute = fieldInfo?.GetCustomAttribute<LegendSettingsAttribute>();
|
||||
|
||||
plotModel.Legends.Add(new Legend()
|
||||
{
|
||||
LegendTitle = "Легенда",
|
||||
LegendPlacement = attribute.Placement,
|
||||
LegendPosition = attribute.Position,
|
||||
});
|
||||
plotModel.IsLegendVisible = true;
|
||||
|
||||
var document = new Document();
|
||||
document.Info.Title = pdfDiagram.DocumentTitle;
|
||||
|
||||
var section = document.AddSection();
|
||||
section.PageSetup.TopMargin = "1cm";
|
||||
|
||||
var image = new PngExporter { Width = 600, Height = 400 }.ExportToBitmap(plotModel);
|
||||
image.Save("temp.png");
|
||||
|
||||
var chartImage = section.AddImage("temp.png");
|
||||
chartImage.LockAspectRatio = true;
|
||||
chartImage.Width = "15cm";
|
||||
chartImage.Height = "10cm";
|
||||
|
||||
var pdfRenderer = new PdfDocumentRenderer(true);
|
||||
pdfRenderer.Document = document;
|
||||
pdfRenderer.RenderDocument();
|
||||
pdfRenderer.PdfDocument.Save(pdfDiagram.FilePath);
|
||||
}
|
||||
}
|
||||
}
|
36
WinForm/PdfFormsLibrary/PdfTableGenerator.Designer.cs
generated
Normal file
36
WinForm/PdfFormsLibrary/PdfTableGenerator.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace PdfFormsLibrary
|
||||
{
|
||||
partial class PdfTableGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
134
WinForm/PdfFormsLibrary/PdfTableGenerator.cs
Normal file
134
WinForm/PdfFormsLibrary/PdfTableGenerator.cs
Normal file
@ -0,0 +1,134 @@
|
||||
using PdfSharp.Pdf;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using MigraDoc.Rendering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using PdfFormsLibrary.Helpers;
|
||||
|
||||
namespace PdfFormsLibrary
|
||||
{
|
||||
public partial class PdfTableGenerator : Component
|
||||
{
|
||||
private int fontSize = 14;
|
||||
|
||||
public PdfTableGenerator()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public PdfTableGenerator(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void GeneratePdf<T>(PdfWithTableData<T> pdfTable)
|
||||
{
|
||||
if (pdfTable == null || string.IsNullOrEmpty(pdfTable.FilePath)
|
||||
|| string.IsNullOrEmpty(pdfTable.DocumentTitle) || pdfTable.TableHeader == null)
|
||||
{
|
||||
throw new ArgumentException("Недостаточно данных для создания PDF-документа.");
|
||||
}
|
||||
Document document = new Document();
|
||||
Section section = document.AddSection();
|
||||
|
||||
Paragraph title = section.AddParagraph(pdfTable.DocumentTitle);
|
||||
title.Format.Font.Bold = true;
|
||||
title.Format.Alignment = ParagraphAlignment.Center;
|
||||
|
||||
Table table = section.AddTable();
|
||||
table.Borders.Visible = true;
|
||||
|
||||
foreach (var column in pdfTable.TableHeader)
|
||||
{
|
||||
if (column.SubColumns.Count > 0)
|
||||
{
|
||||
foreach(var sub in column.SubColumns)
|
||||
{
|
||||
Column newsub = table.AddColumn();
|
||||
newsub.Width = sub.ColumnWidth;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
Column newcolumn = table.AddColumn();
|
||||
newcolumn.Width = column.ColumnWidth;
|
||||
}
|
||||
|
||||
CreateTableHeader(table, pdfTable.TableHeader);
|
||||
|
||||
CreateTableData(table, pdfTable);
|
||||
|
||||
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);
|
||||
pdfRenderer.Document = document;
|
||||
pdfRenderer.RenderDocument();
|
||||
pdfRenderer.PdfDocument.Save(pdfTable.FilePath);
|
||||
}
|
||||
|
||||
public void CreateTableHeader(Table table, List<PdfWithTableHeader> headerInfo)
|
||||
{
|
||||
Row headerRow1 = table.AddRow();
|
||||
Row headerRow2 = table.AddRow();
|
||||
|
||||
foreach (Row headerRow in new Row[] { headerRow1, headerRow2 })
|
||||
{
|
||||
headerRow.HeadingFormat = true;
|
||||
headerRow.Format.Alignment = ParagraphAlignment.Center;
|
||||
headerRow.Format.Font.Bold = true;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
foreach (var column in headerInfo)
|
||||
{
|
||||
int rowSpan = Math.Max(1, column.SubColumns.Count);
|
||||
|
||||
if (column.SubColumns.Count > 0)
|
||||
{
|
||||
headerRow1.Cells[i].MergeRight = rowSpan - 1;
|
||||
|
||||
for (int j = 0; j < column.SubColumns.Count; j++)
|
||||
{
|
||||
headerRow2.Cells[i + j].AddParagraph(column.SubColumns[j].ColumnName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
headerRow1.Cells[i].MergeDown = rowSpan;
|
||||
}
|
||||
|
||||
headerRow1.Cells[i].AddParagraph(column.ColumnName);
|
||||
i += rowSpan;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateTableData<T>(Table table, PdfWithTableData<T> data)
|
||||
{
|
||||
if (data == null || data.TableData == null)
|
||||
return;
|
||||
|
||||
foreach (var rowData in data.TableData)
|
||||
{
|
||||
Row newrow = table.AddRow();
|
||||
int i = 0;
|
||||
foreach (var column in data.Props)
|
||||
{
|
||||
try
|
||||
{
|
||||
object cellValue = typeof(T).GetProperty(column).GetValue(rowData);
|
||||
string cellText = cellValue?.ToString() ?? string.Empty;
|
||||
newrow.Cells[i].AddParagraph(cellText);
|
||||
++i;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
22
WinForm/PluginsConventionLibrary/IPluginsConvention.cs
Normal file
22
WinForm/PluginsConventionLibrary/IPluginsConvention.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PluginsConventionLibrary
|
||||
{
|
||||
public interface IPluginsConvention
|
||||
{
|
||||
string PluginName { get; }
|
||||
UserControl GetControl { get; }
|
||||
PluginsConventionElement GetElement { get; }
|
||||
Form GetForm(PluginsConventionElement element);
|
||||
Form GetThesaurus();
|
||||
bool DeleteElement(PluginsConventionElement element);
|
||||
void ReloadData();
|
||||
bool CreateSimpleDocument(PluginsConventionSaveDocument saveDocument);
|
||||
bool CreateTableDocument(PluginsConventionSaveDocument saveDocument);
|
||||
bool CreateChartDocument(PluginsConventionSaveDocument saveDocument);
|
||||
}
|
||||
}
|
13
WinForm/PluginsConventionLibrary/PluginsConventionElement.cs
Normal file
13
WinForm/PluginsConventionLibrary/PluginsConventionElement.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PluginsConventionLibrary
|
||||
{
|
||||
public class PluginsConventionElement
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PluginsConventionLibrary
|
||||
{
|
||||
public class PluginsConventionSaveDocument
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
}
|
||||
}
|
@ -3,7 +3,21 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.33424.131
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinForm", "WinForm\WinForm.csproj", "{79A863DB-93E6-44C2-AB0F-DE0D19BE72DC}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForm", "WinForm\WinForm.csproj", "{79A863DB-93E6-44C2-AB0F-DE0D19BE72DC}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataModels", "DataModels\DataModels.csproj", "{D468732D-BA49-4D2C-8854-DD4FDA8FDC1D}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contracts", "Contracts\Contracts.csproj", "{B90EEDCA-96C8-4E5C-9C5B-7F663023802D}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataBaseImplement", "DataBaseImplement\DataBaseImplement.csproj", "{E94AC3C7-A9BB-4262-9C87-5DF8E03B643B}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AppView", "AppView\AppView.csproj", "{9BD73EC6-6B32-4CBB-8D04-9D4650562846}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PdfFormsLibrary", "PdfFormsLibrary\PdfFormsLibrary.csproj", "{2BFDA66F-E786-4C74-8D3A-054C6D1FDF7D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsAppByPlugins", "WinFormsAppByPlugins\WinFormsAppByPlugins.csproj", "{77CB7F0C-2666-40BC-96A6-CC210D2F008B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginsConventionLibrary", "PluginsConventionLibrary\PluginsConventionLibrary.csproj", "{98754D56-A3B4-4A0E-A7F2-74FFE8AE67BA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -15,6 +29,34 @@ Global
|
||||
{79A863DB-93E6-44C2-AB0F-DE0D19BE72DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{79A863DB-93E6-44C2-AB0F-DE0D19BE72DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{79A863DB-93E6-44C2-AB0F-DE0D19BE72DC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D468732D-BA49-4D2C-8854-DD4FDA8FDC1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D468732D-BA49-4D2C-8854-DD4FDA8FDC1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D468732D-BA49-4D2C-8854-DD4FDA8FDC1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D468732D-BA49-4D2C-8854-DD4FDA8FDC1D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B90EEDCA-96C8-4E5C-9C5B-7F663023802D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B90EEDCA-96C8-4E5C-9C5B-7F663023802D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B90EEDCA-96C8-4E5C-9C5B-7F663023802D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B90EEDCA-96C8-4E5C-9C5B-7F663023802D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E94AC3C7-A9BB-4262-9C87-5DF8E03B643B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E94AC3C7-A9BB-4262-9C87-5DF8E03B643B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E94AC3C7-A9BB-4262-9C87-5DF8E03B643B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E94AC3C7-A9BB-4262-9C87-5DF8E03B643B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9BD73EC6-6B32-4CBB-8D04-9D4650562846}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9BD73EC6-6B32-4CBB-8D04-9D4650562846}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9BD73EC6-6B32-4CBB-8D04-9D4650562846}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9BD73EC6-6B32-4CBB-8D04-9D4650562846}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2BFDA66F-E786-4C74-8D3A-054C6D1FDF7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2BFDA66F-E786-4C74-8D3A-054C6D1FDF7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2BFDA66F-E786-4C74-8D3A-054C6D1FDF7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2BFDA66F-E786-4C74-8D3A-054C6D1FDF7D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{77CB7F0C-2666-40BC-96A6-CC210D2F008B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{77CB7F0C-2666-40BC-96A6-CC210D2F008B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{77CB7F0C-2666-40BC-96A6-CC210D2F008B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{77CB7F0C-2666-40BC-96A6-CC210D2F008B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{98754D56-A3B4-4A0E-A7F2-74FFE8AE67BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{98754D56-A3B4-4A0E-A7F2-74FFE8AE67BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{98754D56-A3B4-4A0E-A7F2-74FFE8AE67BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{98754D56-A3B4-4A0E-A7F2-74FFE8AE67BA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
24
WinForm/WinForm/ExampleClass.cs
Normal file
24
WinForm/WinForm/ExampleClass.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinForm
|
||||
{
|
||||
public class ExampleClass
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Book { get; set; }
|
||||
public string Genre { get; set; }
|
||||
public string Author { get; set; }
|
||||
|
||||
public ExampleClass(int Id, string Book, string Genre, string Author)
|
||||
{
|
||||
this.Id = Id;
|
||||
this.Book = Book;
|
||||
this.Genre = Genre;
|
||||
this.Author = Author;
|
||||
}
|
||||
}
|
||||
}
|
39
WinForm/WinForm/Form1.Designer.cs
generated
39
WinForm/WinForm/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace WinForm
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace WinForm
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
153
WinForm/WinForm/FormNoGraphics.Designer.cs
generated
Normal file
153
WinForm/WinForm/FormNoGraphics.Designer.cs
generated
Normal file
@ -0,0 +1,153 @@
|
||||
namespace WinForm
|
||||
{
|
||||
partial class FormNoGraphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
pdfGeneratorControl = new PdfFormsLibrary.PdfGeneratorControl(components);
|
||||
groupBoxPdfText = new GroupBox();
|
||||
buttonSaveDiagram = new Button();
|
||||
buttonSaveTable = new Button();
|
||||
buttonSaveFile = new Button();
|
||||
richTextBox = new RichTextBox();
|
||||
labelBigText = new Label();
|
||||
labelTitle = new Label();
|
||||
textBoxTitle = new TextBox();
|
||||
pdfTableGenerator = new PdfFormsLibrary.PdfTableGenerator(components);
|
||||
pdfGeneratorLinearDiagram = new PdfFormsLibrary.PdfGeneratorLinearDiagram(components);
|
||||
groupBoxPdfText.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxPdfText
|
||||
//
|
||||
groupBoxPdfText.Controls.Add(buttonSaveDiagram);
|
||||
groupBoxPdfText.Controls.Add(buttonSaveTable);
|
||||
groupBoxPdfText.Controls.Add(buttonSaveFile);
|
||||
groupBoxPdfText.Controls.Add(richTextBox);
|
||||
groupBoxPdfText.Controls.Add(labelBigText);
|
||||
groupBoxPdfText.Controls.Add(labelTitle);
|
||||
groupBoxPdfText.Controls.Add(textBoxTitle);
|
||||
groupBoxPdfText.Location = new Point(12, 12);
|
||||
groupBoxPdfText.Name = "groupBoxPdfText";
|
||||
groupBoxPdfText.Size = new Size(328, 369);
|
||||
groupBoxPdfText.TabIndex = 0;
|
||||
groupBoxPdfText.TabStop = false;
|
||||
groupBoxPdfText.Text = "Работа с большим текстом pdf";
|
||||
//
|
||||
// buttonSaveDiagram
|
||||
//
|
||||
buttonSaveDiagram.Location = new Point(41, 319);
|
||||
buttonSaveDiagram.Name = "buttonSaveDiagram";
|
||||
buttonSaveDiagram.Size = new Size(226, 23);
|
||||
buttonSaveDiagram.TabIndex = 7;
|
||||
buttonSaveDiagram.Text = "Сохранить Диаграмму в PDF";
|
||||
buttonSaveDiagram.UseVisualStyleBackColor = true;
|
||||
buttonSaveDiagram.Click += ButtonSaveDiagram_Click;
|
||||
//
|
||||
// buttonSaveTable
|
||||
//
|
||||
buttonSaveTable.Location = new Point(41, 290);
|
||||
buttonSaveTable.Name = "buttonSaveTable";
|
||||
buttonSaveTable.Size = new Size(226, 23);
|
||||
buttonSaveTable.TabIndex = 6;
|
||||
buttonSaveTable.Text = "Сохранить Таблицу в PDF";
|
||||
buttonSaveTable.UseVisualStyleBackColor = true;
|
||||
buttonSaveTable.Click += ButtonSaveTable_Click;
|
||||
//
|
||||
// buttonSaveFile
|
||||
//
|
||||
buttonSaveFile.Location = new Point(41, 261);
|
||||
buttonSaveFile.Name = "buttonSaveFile";
|
||||
buttonSaveFile.Size = new Size(226, 23);
|
||||
buttonSaveFile.TabIndex = 4;
|
||||
buttonSaveFile.Text = "Сохранить Текст в PDF";
|
||||
buttonSaveFile.UseVisualStyleBackColor = true;
|
||||
buttonSaveFile.Click += ButtonSaveFile_Click;
|
||||
//
|
||||
// richTextBox
|
||||
//
|
||||
richTextBox.Location = new Point(41, 56);
|
||||
richTextBox.Name = "richTextBox";
|
||||
richTextBox.Size = new Size(268, 199);
|
||||
richTextBox.TabIndex = 3;
|
||||
richTextBox.Text = "";
|
||||
//
|
||||
// labelBigText
|
||||
//
|
||||
labelBigText.AutoSize = true;
|
||||
labelBigText.Location = new Point(6, 56);
|
||||
labelBigText.Name = "labelBigText";
|
||||
labelBigText.Size = new Size(28, 15);
|
||||
labelBigText.TabIndex = 2;
|
||||
labelBigText.Text = "Text";
|
||||
//
|
||||
// labelTitle
|
||||
//
|
||||
labelTitle.AutoSize = true;
|
||||
labelTitle.Location = new Point(6, 25);
|
||||
labelTitle.Name = "labelTitle";
|
||||
labelTitle.Size = new Size(29, 15);
|
||||
labelTitle.TabIndex = 1;
|
||||
labelTitle.Text = "Title";
|
||||
//
|
||||
// textBoxTitle
|
||||
//
|
||||
textBoxTitle.Location = new Point(41, 22);
|
||||
textBoxTitle.Name = "textBoxTitle";
|
||||
textBoxTitle.Size = new Size(268, 23);
|
||||
textBoxTitle.TabIndex = 0;
|
||||
//
|
||||
// FormNoGraphics
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(351, 393);
|
||||
Controls.Add(groupBoxPdfText);
|
||||
Name = "FormNoGraphics";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Form";
|
||||
groupBoxPdfText.ResumeLayout(false);
|
||||
groupBoxPdfText.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PdfFormsLibrary.PdfGeneratorControl pdfGeneratorControl;
|
||||
private GroupBox groupBoxPdfText;
|
||||
private Label labelTitle;
|
||||
private TextBox textBoxTitle;
|
||||
private Button buttonSaveFile;
|
||||
private RichTextBox richTextBox;
|
||||
private Label labelBigText;
|
||||
private PdfFormsLibrary.PdfTableGenerator pdfTableGenerator;
|
||||
private Button buttonSaveDiagram;
|
||||
private Button buttonSaveTable;
|
||||
private PdfFormsLibrary.PdfGeneratorLinearDiagram pdfGeneratorLinearDiagram;
|
||||
}
|
||||
}
|
129
WinForm/WinForm/FormNoGraphics.cs
Normal file
129
WinForm/WinForm/FormNoGraphics.cs
Normal file
@ -0,0 +1,129 @@
|
||||
using PdfFormsLibrary.Helpers;
|
||||
|
||||
namespace WinForm
|
||||
{
|
||||
public partial class FormNoGraphics : Form
|
||||
{
|
||||
public FormNoGraphics()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private List<(double, double)> GenerateRandomData(int count)
|
||||
{
|
||||
Random random = new Random();
|
||||
var data = new List<(double, double)>();
|
||||
for (int i = 1; i <= count; i++)
|
||||
{
|
||||
data.Add((i, random.NextDouble() * 50));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private List<ExampleClass> GenerateRandomClass(int count)
|
||||
{
|
||||
string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
Random random = new Random();
|
||||
List<ExampleClass> returnedList = new List<ExampleClass>();
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
char[] stringChars = new char[10];
|
||||
for (int j = 0; j < 10; ++j)
|
||||
{
|
||||
stringChars[j] = chars[random.Next(chars.Length)];
|
||||
}
|
||||
returnedList.Add(new ExampleClass(i, new string(stringChars), new string(stringChars), new string(stringChars)));
|
||||
}
|
||||
return returnedList;
|
||||
}
|
||||
|
||||
private string SavePath()
|
||||
{
|
||||
string filePath = string.Empty;
|
||||
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
||||
saveFileDialog.Filter = "PDF Files|*.pdf";
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
filePath = saveFileDialog.FileName;
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
private void ButtonSaveFile_Click(object sender, EventArgs e)
|
||||
{
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
pdfGeneratorControl.GeneratePdf(SavePath(), textBoxTitle.Text, richTextBox.Lines.ToList());
|
||||
MessageBox.Show("PDF-äîêóìåíò óñïåøíî ñîõðàíåí.", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
|
||||
private void ButtonSaveTable_Click(object sender, EventArgs e)
|
||||
{
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
PdfWithTableData<ExampleClass> tableData = new();
|
||||
List<PdfWithTableHeader> tableHeader = new()
|
||||
{
|
||||
new PdfWithTableHeader()
|
||||
{
|
||||
ColumnName="Id",
|
||||
ColumnWidth=50
|
||||
},
|
||||
new PdfWithTableHeader()
|
||||
{
|
||||
ColumnName="Book",
|
||||
ColumnWidth=100
|
||||
},
|
||||
new PdfWithTableHeader()
|
||||
{
|
||||
ColumnName="Params",
|
||||
ColumnWidth=250,
|
||||
SubColumns = new()
|
||||
{
|
||||
new (){ ColumnName="Genre", ColumnWidth=125},
|
||||
new (){ ColumnName="Author", ColumnWidth=125}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
tableData.TableHeader = tableHeader;
|
||||
tableData.Props = new List<string> { "Id", "Book", "Genre", "Author" };
|
||||
tableData.TableData = GenerateRandomClass(5);
|
||||
|
||||
tableData.DocumentTitle = textBoxTitle.Text;
|
||||
tableData.FilePath = SavePath();
|
||||
pdfTableGenerator.GeneratePdf(tableData);
|
||||
MessageBox.Show("PDF-äîêóìåíò óñïåøíî ñîõðàíåí.", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
|
||||
private void ButtonSaveDiagram_Click(object sender, EventArgs e)
|
||||
{
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
PdfWithDiagramData diagramData = new();
|
||||
|
||||
diagramData.DocumentTitle = textBoxTitle.Text;
|
||||
diagramData.DiagramName = textBoxTitle.Text;
|
||||
diagramData.LegendPosition = DiagramLegendPosition.BottomCenterOutside;
|
||||
diagramData.Series = new(){
|
||||
new()
|
||||
{
|
||||
Name = "Ðÿä-1",
|
||||
Data = GenerateRandomData(5)
|
||||
},
|
||||
new()
|
||||
{
|
||||
Name = "Ðÿä-2",
|
||||
Data = GenerateRandomData(5)
|
||||
}
|
||||
};
|
||||
diagramData.FilePath = SavePath();
|
||||
try
|
||||
{
|
||||
pdfGeneratorLinearDiagram.GeneratePdfDocumentWithChart(diagramData);
|
||||
MessageBox.Show("PDF-äîêóìåíò ñîçäàí.", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"PDF-äîêóìåíòà íå ñîçäàí: {ex.Message}", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace WinForm
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new FormNoGraphics());
|
||||
}
|
||||
}
|
||||
}
|
@ -8,4 +8,8 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PdfFormsLibrary\PdfFormsLibrary.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
173
WinForm/WinFormsAppByPlugins/FormMain.Designer.cs
generated
Normal file
173
WinForm/WinFormsAppByPlugins/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,173 @@
|
||||
namespace WinFormsAppByPlugins
|
||||
{
|
||||
partial class FormMain
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
menuStrip = new MenuStrip();
|
||||
ControlsStripMenuItem = new ToolStripMenuItem();
|
||||
ActionsToolStripMenuItem = new ToolStripMenuItem();
|
||||
ThesaurusToolStripMenuItem = new ToolStripMenuItem();
|
||||
AddElementToolStripMenuItem = new ToolStripMenuItem();
|
||||
UpdElementToolStripMenuItem = new ToolStripMenuItem();
|
||||
DelElementToolStripMenuItem = new ToolStripMenuItem();
|
||||
DocsToolStripMenuItem = new ToolStripMenuItem();
|
||||
SimpleDocToolStripMenuItem = new ToolStripMenuItem();
|
||||
TableDocToolStripMenuItem = new ToolStripMenuItem();
|
||||
ChartDocToolStripMenuItem = new ToolStripMenuItem();
|
||||
panelControl = new Panel();
|
||||
menuStrip.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { ControlsStripMenuItem, ActionsToolStripMenuItem, DocsToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Size = new Size(800, 24);
|
||||
menuStrip.TabIndex = 0;
|
||||
menuStrip.Text = "Меню";
|
||||
//
|
||||
// ControlsStripMenuItem
|
||||
//
|
||||
ControlsStripMenuItem.Name = "ControlsStripMenuItem";
|
||||
ControlsStripMenuItem.Size = new Size(90, 20);
|
||||
ControlsStripMenuItem.Text = "Компоненты";
|
||||
//
|
||||
// ActionsToolStripMenuItem
|
||||
//
|
||||
ActionsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ThesaurusToolStripMenuItem, AddElementToolStripMenuItem, UpdElementToolStripMenuItem, DelElementToolStripMenuItem });
|
||||
ActionsToolStripMenuItem.Name = "ActionsToolStripMenuItem";
|
||||
ActionsToolStripMenuItem.Size = new Size(70, 20);
|
||||
ActionsToolStripMenuItem.Text = "Действия";
|
||||
//
|
||||
// ThesaurusToolStripMenuItem
|
||||
//
|
||||
ThesaurusToolStripMenuItem.Name = "ThesaurusToolStripMenuItem";
|
||||
ThesaurusToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.I;
|
||||
ThesaurusToolStripMenuItem.Size = new Size(180, 22);
|
||||
ThesaurusToolStripMenuItem.Text = "Справочник";
|
||||
ThesaurusToolStripMenuItem.Click += ThesaurusToolStripMenuItem_Click;
|
||||
//
|
||||
// AddElementToolStripMenuItem
|
||||
//
|
||||
AddElementToolStripMenuItem.Name = "AddElementToolStripMenuItem";
|
||||
AddElementToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.A;
|
||||
AddElementToolStripMenuItem.Size = new Size(180, 22);
|
||||
AddElementToolStripMenuItem.Text = "Добавить";
|
||||
AddElementToolStripMenuItem.Click += AddElementToolStripMenuItem_Click;
|
||||
//
|
||||
// UpdElementToolStripMenuItem
|
||||
//
|
||||
UpdElementToolStripMenuItem.Name = "UpdElementToolStripMenuItem";
|
||||
UpdElementToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.U;
|
||||
UpdElementToolStripMenuItem.Size = new Size(180, 22);
|
||||
UpdElementToolStripMenuItem.Text = "Изменить";
|
||||
UpdElementToolStripMenuItem.Click += UpdElementToolStripMenuItem_Click;
|
||||
//
|
||||
// DelElementToolStripMenuItem
|
||||
//
|
||||
DelElementToolStripMenuItem.Name = "DelElementToolStripMenuItem";
|
||||
DelElementToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.D;
|
||||
DelElementToolStripMenuItem.Size = new Size(180, 22);
|
||||
DelElementToolStripMenuItem.Text = "Удалить";
|
||||
DelElementToolStripMenuItem.Click += DelElementToolStripMenuItem_Click;
|
||||
//
|
||||
// DocsToolStripMenuItem
|
||||
//
|
||||
DocsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SimpleDocToolStripMenuItem, TableDocToolStripMenuItem, ChartDocToolStripMenuItem });
|
||||
DocsToolStripMenuItem.Name = "DocsToolStripMenuItem";
|
||||
DocsToolStripMenuItem.Size = new Size(82, 20);
|
||||
DocsToolStripMenuItem.Text = "Документы";
|
||||
//
|
||||
// SimpleDocToolStripMenuItem
|
||||
//
|
||||
SimpleDocToolStripMenuItem.Name = "SimpleDocToolStripMenuItem";
|
||||
SimpleDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
|
||||
SimpleDocToolStripMenuItem.Size = new Size(233, 22);
|
||||
SimpleDocToolStripMenuItem.Text = "Простой документ";
|
||||
SimpleDocToolStripMenuItem.Click += SimpleDocToolStripMenuItem_Click;
|
||||
//
|
||||
// TableDocToolStripMenuItem
|
||||
//
|
||||
TableDocToolStripMenuItem.Name = "TableDocToolStripMenuItem";
|
||||
TableDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T;
|
||||
TableDocToolStripMenuItem.Size = new Size(233, 22);
|
||||
TableDocToolStripMenuItem.Text = "Документ с таблицой";
|
||||
TableDocToolStripMenuItem.Click += TableDocToolStripMenuItem_Click;
|
||||
//
|
||||
// ChartDocToolStripMenuItem
|
||||
//
|
||||
ChartDocToolStripMenuItem.Name = "ChartDocToolStripMenuItem";
|
||||
ChartDocToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.C;
|
||||
ChartDocToolStripMenuItem.Size = new Size(233, 22);
|
||||
ChartDocToolStripMenuItem.Text = "Круговая диаграмма";
|
||||
ChartDocToolStripMenuItem.Click += ChartDocToolStripMenuItem_Click;
|
||||
//
|
||||
// panelControl
|
||||
//
|
||||
panelControl.Dock = DockStyle.Fill;
|
||||
panelControl.Location = new Point(0, 24);
|
||||
panelControl.Name = "panelControl";
|
||||
panelControl.Size = new Size(800, 426);
|
||||
panelControl.TabIndex = 1;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(panelControl);
|
||||
Controls.Add(menuStrip);
|
||||
MainMenuStrip = menuStrip;
|
||||
Name = "FormMain";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Главная форма";
|
||||
WindowState = FormWindowState.Maximized;
|
||||
KeyDown += FormMain_KeyDown;
|
||||
menuStrip.ResumeLayout(false);
|
||||
menuStrip.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.MenuStrip menuStrip;
|
||||
private System.Windows.Forms.ToolStripMenuItem ControlsStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem DocsToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem SimpleDocToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem TableDocToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem ChartDocToolStripMenuItem;
|
||||
private System.Windows.Forms.Panel panelControl;
|
||||
private System.Windows.Forms.ToolStripMenuItem ActionsToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem ThesaurusToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem AddElementToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem UpdElementToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem DelElementToolStripMenuItem;
|
||||
}
|
||||
}
|
227
WinForm/WinFormsAppByPlugins/FormMain.cs
Normal file
227
WinForm/WinFormsAppByPlugins/FormMain.cs
Normal file
@ -0,0 +1,227 @@
|
||||
using PluginsConventionLibrary;
|
||||
using System.Reflection;
|
||||
|
||||
namespace WinFormsAppByPlugins
|
||||
{
|
||||
public partial class FormMain : Form
|
||||
{
|
||||
private readonly Dictionary<string, IPluginsConvention> _plugins;
|
||||
private string _selectedPlugin;
|
||||
|
||||
public FormMain()
|
||||
{
|
||||
InitializeComponent();
|
||||
_plugins = new();
|
||||
LoadPlugins();
|
||||
_selectedPlugin = string.Empty;
|
||||
}
|
||||
|
||||
private void LoadPlugins()
|
||||
{
|
||||
List<IPluginsConvention> pluginsList = GetPlugins();
|
||||
|
||||
foreach (var plugin in pluginsList)
|
||||
{
|
||||
_plugins[plugin.PluginName] = plugin;
|
||||
CreateMenuItem(plugin.PluginName);
|
||||
}
|
||||
}
|
||||
|
||||
private List<IPluginsConvention> GetPlugins()
|
||||
{
|
||||
string currentDir = Environment.CurrentDirectory;
|
||||
string pluginsDir = Directory.GetParent(currentDir).Parent.Parent.Parent.FullName + "\\Plugins";
|
||||
string[] dllFiles = Directory.GetFiles(
|
||||
pluginsDir,
|
||||
"*.dll",
|
||||
SearchOption.AllDirectories
|
||||
);
|
||||
List<IPluginsConvention> plugins = new();
|
||||
foreach (string dllFile in dllFiles)
|
||||
{
|
||||
try
|
||||
{
|
||||
Assembly assembly = Assembly.LoadFrom(dllFile);
|
||||
Type[] types = assembly.GetTypes();
|
||||
foreach (Type type in types)
|
||||
{
|
||||
if (typeof(IPluginsConvention).IsAssignableFrom(type) && !type.IsInterface)
|
||||
{
|
||||
if (Activator.CreateInstance(type) is IPluginsConvention plugin)
|
||||
{
|
||||
plugins.Add(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(
|
||||
ex.Message
|
||||
);
|
||||
}
|
||||
}
|
||||
return plugins;
|
||||
}
|
||||
|
||||
private void CreateMenuItem(string pluginName)
|
||||
{
|
||||
ToolStripMenuItem menuItem = new(pluginName);
|
||||
menuItem.Click += (object? sender, EventArgs e) =>
|
||||
{
|
||||
UserControl userControl = _plugins[pluginName].GetControl;
|
||||
if (userControl != null)
|
||||
{
|
||||
panelControl.Controls.Clear();
|
||||
userControl.Dock = DockStyle.Fill;
|
||||
_plugins[pluginName].ReloadData();
|
||||
_selectedPlugin = pluginName;
|
||||
panelControl.Controls.Add(userControl);
|
||||
}
|
||||
};
|
||||
ControlsStripMenuItem.DropDownItems.Add(menuItem);
|
||||
}
|
||||
|
||||
private void FormMain_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_selectedPlugin) ||
|
||||
!_plugins.ContainsKey(_selectedPlugin))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!e.Control)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.I:
|
||||
ShowThesaurus();
|
||||
break;
|
||||
case Keys.A:
|
||||
AddNewElement();
|
||||
break;
|
||||
case Keys.U:
|
||||
UpdateElement();
|
||||
break;
|
||||
case Keys.D:
|
||||
DeleteElement();
|
||||
break;
|
||||
case Keys.S:
|
||||
CreateSimpleDoc();
|
||||
break;
|
||||
case Keys.T:
|
||||
CreateTableDoc();
|
||||
break;
|
||||
case Keys.C:
|
||||
CreateChartDoc();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowThesaurus()
|
||||
{
|
||||
_plugins[_selectedPlugin].GetThesaurus()?.Show();
|
||||
}
|
||||
|
||||
private void AddNewElement()
|
||||
{
|
||||
var form = _plugins[_selectedPlugin].GetForm(null);
|
||||
if (form != null && form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_plugins[_selectedPlugin].ReloadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateElement()
|
||||
{
|
||||
var element = _plugins[_selectedPlugin].GetElement;
|
||||
if (element == null)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Не выбран элемент для обновления",
|
||||
"Ошибка",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error
|
||||
);
|
||||
return;
|
||||
}
|
||||
var form = _plugins[_selectedPlugin].GetForm(element);
|
||||
if (form != null && form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_plugins[_selectedPlugin].ReloadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteElement()
|
||||
{
|
||||
if (MessageBox.Show(
|
||||
"Удалить выбранный элемент?",
|
||||
"Удаление",
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var element = _plugins[_selectedPlugin].GetElement;
|
||||
if (element == null)
|
||||
{
|
||||
MessageBox.Show(
|
||||
"Не выбран элемент для удаления",
|
||||
"Ошибка",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (_plugins[_selectedPlugin].DeleteElement(element))
|
||||
{
|
||||
_plugins[_selectedPlugin].ReloadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateSimpleDoc()
|
||||
{
|
||||
SaveFileDialog saveFileDialog = new()
|
||||
{
|
||||
Filter = "PDF Files|*.pdf"
|
||||
};
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_plugins[_selectedPlugin].CreateSimpleDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName });
|
||||
|
||||
}
|
||||
}
|
||||
private void CreateTableDoc()
|
||||
{
|
||||
SaveFileDialog saveFileDialog = new()
|
||||
{
|
||||
Filter = "Excel Files|*.xlsx"
|
||||
};
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_plugins[_selectedPlugin].CreateTableDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName });
|
||||
|
||||
}
|
||||
}
|
||||
private void CreateChartDoc()
|
||||
{
|
||||
SaveFileDialog saveFileDialog = new()
|
||||
{
|
||||
Filter = "Word Files|*.docx"
|
||||
};
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
_plugins[_selectedPlugin].CreateChartDocument(new PluginsConventionSaveDocument() { FileName = saveFileDialog.FileName });
|
||||
}
|
||||
}
|
||||
|
||||
private void ThesaurusToolStripMenuItem_Click(object sender, EventArgs e) => ShowThesaurus();
|
||||
private void AddElementToolStripMenuItem_Click(object sender, EventArgs e) => AddNewElement();
|
||||
private void UpdElementToolStripMenuItem_Click(object sender, EventArgs e) => UpdateElement();
|
||||
private void DelElementToolStripMenuItem_Click(object sender, EventArgs e) => DeleteElement();
|
||||
private void SimpleDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateSimpleDoc();
|
||||
private void TableDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateTableDoc();
|
||||
private void ChartDocToolStripMenuItem_Click(object sender, EventArgs e) => CreateChartDoc();
|
||||
}
|
||||
}
|
63
WinForm/WinFormsAppByPlugins/FormMain.resx
Normal file
63
WinForm/WinFormsAppByPlugins/FormMain.resx
Normal file
@ -0,0 +1,63 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
17
WinForm/WinFormsAppByPlugins/Program.cs
Normal file
17
WinForm/WinFormsAppByPlugins/Program.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace WinFormsAppByPlugins
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormMain());
|
||||
}
|
||||
}
|
||||
}
|
15
WinForm/WinFormsAppByPlugins/WinFormsAppByPlugins.csproj
Normal file
15
WinForm/WinFormsAppByPlugins/WinFormsAppByPlugins.csproj
Normal file
@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PluginsConventionLibrary\PluginsConventionLibrary.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user