Остался pdf и excel
This commit is contained in:
parent
462e8f8bb4
commit
c65bcbb792
@ -9,14 +9,18 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ComponentsLibraryNet60" Version="1.0.0" />
|
||||
<PackageReference Include="ControlsLibraryNet60" Version="1.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.14">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="PdfFormsLibrary" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DateBaseImplement\DateBaseImplement.csproj" />
|
||||
<ProjectReference Include="..\WinFormsLibrary\WinFormsLibrary.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
39
WinFormsProject/AppView/Form1.Designer.cs
generated
39
WinFormsProject/AppView/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace AppView
|
||||
{
|
||||
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 AppView
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
142
WinFormsProject/AppView/FormMain.Designer.cs
generated
Normal file
142
WinFormsProject/AppView/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,142 @@
|
||||
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()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.dataTable = new ControlsLibraryNet60.Data.ControlDataTableTable();
|
||||
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.создатьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.изменитьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.удалитьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.справочникToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.сформирироватьWordToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.сформироватьPdfToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.сформироватьExcelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.documentWithImage1 = new WinFormsLibrary.DocumentWithImage(this.components);
|
||||
this.contextMenuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dataTable
|
||||
//
|
||||
this.dataTable.Location = new System.Drawing.Point(13, 12);
|
||||
this.dataTable.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
this.dataTable.Name = "dataTable";
|
||||
this.dataTable.SelectedRowIndex = -1;
|
||||
this.dataTable.Size = new System.Drawing.Size(774, 426);
|
||||
this.dataTable.TabIndex = 0;
|
||||
//
|
||||
// contextMenuStrip1
|
||||
//
|
||||
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.создатьToolStripMenuItem,
|
||||
this.изменитьToolStripMenuItem,
|
||||
this.удалитьToolStripMenuItem,
|
||||
this.справочникToolStripMenuItem,
|
||||
this.сформирироватьWordToolStripMenuItem,
|
||||
this.сформироватьPdfToolStripMenuItem,
|
||||
this.сформироватьExcelToolStripMenuItem});
|
||||
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
||||
this.contextMenuStrip1.Size = new System.Drawing.Size(205, 180);
|
||||
//
|
||||
// создатьToolStripMenuItem
|
||||
//
|
||||
this.создатьToolStripMenuItem.Name = "создатьToolStripMenuItem";
|
||||
this.создатьToolStripMenuItem.Size = new System.Drawing.Size(204, 22);
|
||||
this.создатьToolStripMenuItem.Text = "Создать";
|
||||
this.создатьToolStripMenuItem.Click += new System.EventHandler(this.создатьToolStripMenuItem_Click);
|
||||
//
|
||||
// изменитьToolStripMenuItem
|
||||
//
|
||||
this.изменитьToolStripMenuItem.Name = "изменитьToolStripMenuItem";
|
||||
this.изменитьToolStripMenuItem.Size = new System.Drawing.Size(204, 22);
|
||||
this.изменитьToolStripMenuItem.Text = "Изменить";
|
||||
this.изменитьToolStripMenuItem.Click += new System.EventHandler(this.изменитьToolStripMenuItem_Click);
|
||||
//
|
||||
// удалитьToolStripMenuItem
|
||||
//
|
||||
this.удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem";
|
||||
this.удалитьToolStripMenuItem.Size = new System.Drawing.Size(204, 22);
|
||||
this.удалитьToolStripMenuItem.Text = "Удалить";
|
||||
this.удалитьToolStripMenuItem.Click += new System.EventHandler(this.удалитьToolStripMenuItem_Click);
|
||||
//
|
||||
// справочникToolStripMenuItem
|
||||
//
|
||||
this.справочникToolStripMenuItem.Name = "справочникToolStripMenuItem";
|
||||
this.справочникToolStripMenuItem.Size = new System.Drawing.Size(204, 22);
|
||||
this.справочникToolStripMenuItem.Text = "Справочник";
|
||||
this.справочникToolStripMenuItem.Click += new System.EventHandler(this.справочникToolStripMenuItem_Click);
|
||||
//
|
||||
// сформирироватьWordToolStripMenuItem
|
||||
//
|
||||
this.сформирироватьWordToolStripMenuItem.Name = "сформирироватьWordToolStripMenuItem";
|
||||
this.сформирироватьWordToolStripMenuItem.Size = new System.Drawing.Size(204, 22);
|
||||
this.сформирироватьWordToolStripMenuItem.Text = "Сформирировать Word";
|
||||
this.сформирироватьWordToolStripMenuItem.Click += new System.EventHandler(this.сформирироватьWordToolStripMenuItem_Click);
|
||||
//
|
||||
// сформироватьPdfToolStripMenuItem
|
||||
//
|
||||
this.сформироватьPdfToolStripMenuItem.Name = "сформироватьPdfToolStripMenuItem";
|
||||
this.сформироватьPdfToolStripMenuItem.Size = new System.Drawing.Size(204, 22);
|
||||
this.сформироватьPdfToolStripMenuItem.Text = "Сформировать Pdf";
|
||||
this.сформироватьPdfToolStripMenuItem.Click += new System.EventHandler(this.сформироватьPdfToolStripMenuItem_Click);
|
||||
//
|
||||
// сформироватьExcelToolStripMenuItem
|
||||
//
|
||||
this.сформироватьExcelToolStripMenuItem.Name = "сформироватьExcelToolStripMenuItem";
|
||||
this.сформироватьExcelToolStripMenuItem.Size = new System.Drawing.Size(204, 22);
|
||||
this.сформироватьExcelToolStripMenuItem.Text = "Сформировать Excel";
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.dataTable);
|
||||
this.Name = "FormMain";
|
||||
this.Text = "Главная форма";
|
||||
this.Load += new System.EventHandler(this.FormMain_Load);
|
||||
this.contextMenuStrip1.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private ControlsLibraryNet60.Data.ControlDataTableTable dataTable;
|
||||
private ContextMenuStrip contextMenuStrip1;
|
||||
private ToolStripMenuItem создатьToolStripMenuItem;
|
||||
private ToolStripMenuItem изменитьToolStripMenuItem;
|
||||
private ToolStripMenuItem удалитьToolStripMenuItem;
|
||||
private ToolStripMenuItem справочникToolStripMenuItem;
|
||||
private ToolStripMenuItem сформирироватьWordToolStripMenuItem;
|
||||
private ToolStripMenuItem сформироватьPdfToolStripMenuItem;
|
||||
private ToolStripMenuItem сформироватьExcelToolStripMenuItem;
|
||||
private WinFormsLibrary.DocumentWithImage documentWithImage1;
|
||||
}
|
||||
}
|
154
WinFormsProject/AppView/FormMain.cs
Normal file
154
WinFormsProject/AppView/FormMain.cs
Normal file
@ -0,0 +1,154 @@
|
||||
using Contracts.StorageContracts;
|
||||
using Contracts.ViewModels;
|
||||
using ControlsLibraryNet60.Data;
|
||||
using ControlsLibraryNet60.Models;
|
||||
using DocumentFormat.OpenXml.Drawing.Charts;
|
||||
using System.ComponentModel;
|
||||
using WinFormsLibrary;
|
||||
using WinFormsLibrary.SupportClasses;
|
||||
|
||||
namespace AppView
|
||||
{
|
||||
public partial class FormMain : Form
|
||||
{
|
||||
private readonly IProviderStorage _providerStorage;
|
||||
private readonly ITypeStorage _typeStorage;
|
||||
|
||||
public FormMain(IProviderStorage providerStorage, ITypeStorage typeStorage)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_providerStorage = providerStorage;
|
||||
_typeStorage = typeStorage;
|
||||
|
||||
ContextMenuStrip = contextMenuStrip1;
|
||||
|
||||
List<DataTableColumnConfig> columns = new List<DataTableColumnConfig>()
|
||||
{
|
||||
new DataTableColumnConfig
|
||||
{
|
||||
ColumnHeader = "Id",
|
||||
PropertyName = "Id",
|
||||
Visible = false
|
||||
},
|
||||
new DataTableColumnConfig
|
||||
{
|
||||
ColumnHeader = "Íàçâàíèå",
|
||||
PropertyName = "Name",
|
||||
Visible = true
|
||||
},
|
||||
new DataTableColumnConfig
|
||||
{
|
||||
ColumnHeader = "Òèï èçäåëèé",
|
||||
PropertyName = "Type",
|
||||
Visible = true
|
||||
},
|
||||
new DataTableColumnConfig
|
||||
{
|
||||
ColumnHeader = "Òåëåôîí",
|
||||
PropertyName = "Number",
|
||||
Visible = true
|
||||
}
|
||||
};
|
||||
dataTable.LoadColumns(columns);
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
var list = _providerStorage.GetFullList();
|
||||
dataTable.Clear();
|
||||
dataTable.AddTable(list);
|
||||
}
|
||||
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void ñîçäàòüToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormProvider));
|
||||
if (!(service is FormProvider form)) return;
|
||||
if (form.ShowDialog() == DialogResult.OK) LoadData();
|
||||
}
|
||||
|
||||
private void èçìåíèòüToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataTable.GetSelectedObject<ProviderViewModel>() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormProvider));
|
||||
if (service is FormProvider form)
|
||||
{
|
||||
form.Id = Convert.ToInt32(dataTable.GetSelectedObject<ProviderViewModel>()?.Id);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void óäàëèòüToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (dataTable.GetSelectedObject<ProviderViewModel>() == null) return;
|
||||
if (MessageBox.Show(
|
||||
"Âû õîòèòå óäàëèòü âûáðàííûå ýëåìåíòû?",
|
||||
"Âîïðîñ",
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_providerStorage.Delete(new(dataTable.GetSelectedObject<ProviderViewModel>()));
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void ñïðàâî÷íèêToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormType));
|
||||
if (service is FormType form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void toolStripButton1_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void ñôîðìèðèðîâàòüWordToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
string fileName = "";
|
||||
using (var dialog = new SaveFileDialog { Filter = "docx|*.docx" })
|
||||
{
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
fileName = dialog.FileName.ToString();
|
||||
MessageBox.Show("Âûïîëíåíî", "Óñïåõ", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
|
||||
ImageClass info = new ImageClass();
|
||||
|
||||
var images = _providerStorage.GetFullList().Select(x => x.Logo).ToList();
|
||||
|
||||
info.Title = "Images";
|
||||
info.Path = fileName;
|
||||
info.Files = images;
|
||||
|
||||
documentWithImage1.CreateDocument(info);
|
||||
}
|
||||
|
||||
private void ñôîðìèðîâàòüPdfToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
66
WinFormsProject/AppView/FormMain.resx
Normal file
66
WinFormsProject/AppView/FormMain.resx
Normal file
@ -0,0 +1,66 @@
|
||||
<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="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="documentWithImage1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>172, 17</value>
|
||||
</metadata>
|
||||
</root>
|
207
WinFormsProject/AppView/FormProvider.Designer.cs
generated
Normal file
207
WinFormsProject/AppView/FormProvider.Designer.cs
generated
Normal file
@ -0,0 +1,207 @@
|
||||
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()
|
||||
{
|
||||
this.labelName = new System.Windows.Forms.Label();
|
||||
this.textBoxName = new System.Windows.Forms.TextBox();
|
||||
this.labelLogo = new System.Windows.Forms.Label();
|
||||
this.textBoxNumber = new System.Windows.Forms.TextBox();
|
||||
this.labelType = new System.Windows.Forms.Label();
|
||||
this.labelNumber = new System.Windows.Forms.Label();
|
||||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.dropDownList1 = new WinForm.DropDownList();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonType = new System.Windows.Forms.Button();
|
||||
this.buttonImage = new System.Windows.Forms.Button();
|
||||
this.ImgFile = new System.Windows.Forms.OpenFileDialog();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
this.labelName.AutoSize = true;
|
||||
this.labelName.Location = new System.Drawing.Point(12, 9);
|
||||
this.labelName.Name = "labelName";
|
||||
this.labelName.Size = new System.Drawing.Size(59, 15);
|
||||
this.labelName.TabIndex = 0;
|
||||
this.labelName.Text = "Название";
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
this.textBoxName.Location = new System.Drawing.Point(12, 27);
|
||||
this.textBoxName.Name = "textBoxName";
|
||||
this.textBoxName.Size = new System.Drawing.Size(239, 23);
|
||||
this.textBoxName.TabIndex = 1;
|
||||
this.textBoxName.TabStop = false;
|
||||
this.textBoxName.TextChanged += new System.EventHandler(this.OnInputChange);
|
||||
//
|
||||
// labelLogo
|
||||
//
|
||||
this.labelLogo.AutoSize = true;
|
||||
this.labelLogo.Location = new System.Drawing.Point(12, 59);
|
||||
this.labelLogo.Name = "labelLogo";
|
||||
this.labelLogo.Size = new System.Drawing.Size(53, 15);
|
||||
this.labelLogo.TabIndex = 2;
|
||||
this.labelLogo.Text = "Логотип";
|
||||
//
|
||||
// textBoxNumber
|
||||
//
|
||||
this.textBoxNumber.Location = new System.Drawing.Point(12, 424);
|
||||
this.textBoxNumber.Name = "textBoxNumber";
|
||||
this.textBoxNumber.Size = new System.Drawing.Size(239, 23);
|
||||
this.textBoxNumber.TabIndex = 4;
|
||||
this.textBoxNumber.TabStop = false;
|
||||
this.textBoxNumber.TextChanged += new System.EventHandler(this.OnInputChange);
|
||||
//
|
||||
// labelType
|
||||
//
|
||||
this.labelType.AutoSize = true;
|
||||
this.labelType.Location = new System.Drawing.Point(12, 307);
|
||||
this.labelType.Name = "labelType";
|
||||
this.labelType.Size = new System.Drawing.Size(75, 15);
|
||||
this.labelType.TabIndex = 5;
|
||||
this.labelType.Text = "Тип изделий";
|
||||
//
|
||||
// labelNumber
|
||||
//
|
||||
this.labelNumber.AutoSize = true;
|
||||
this.labelNumber.Location = new System.Drawing.Point(12, 406);
|
||||
this.labelNumber.Name = "labelNumber";
|
||||
this.labelNumber.Size = new System.Drawing.Size(101, 15);
|
||||
this.labelNumber.TabIndex = 6;
|
||||
this.labelNumber.Text = "Номер телефона";
|
||||
//
|
||||
// pictureBox1
|
||||
//
|
||||
this.pictureBox1.Location = new System.Drawing.Point(12, 77);
|
||||
this.pictureBox1.Name = "pictureBox1";
|
||||
this.pictureBox1.Size = new System.Drawing.Size(239, 159);
|
||||
this.pictureBox1.TabIndex = 7;
|
||||
this.pictureBox1.TabStop = false;
|
||||
//
|
||||
// dropDownList1
|
||||
//
|
||||
this.dropDownList1.Location = new System.Drawing.Point(12, 325);
|
||||
this.dropDownList1.Name = "dropDownList1";
|
||||
this.dropDownList1.Selected = "";
|
||||
this.dropDownList1.Size = new System.Drawing.Size(239, 30);
|
||||
this.dropDownList1.TabIndex = 8;
|
||||
this.dropDownList1.TabStop = false;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(38, 471);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonSave.TabIndex = 9;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(146, 471);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
|
||||
this.buttonCancel.TabIndex = 10;
|
||||
this.buttonCancel.Text = "Отменить";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// buttonType
|
||||
//
|
||||
this.buttonType.Location = new System.Drawing.Point(109, 361);
|
||||
this.buttonType.Name = "buttonType";
|
||||
this.buttonType.Size = new System.Drawing.Size(142, 23);
|
||||
this.buttonType.TabIndex = 11;
|
||||
this.buttonType.TabStop = false;
|
||||
this.buttonType.Text = "Редактировать типы";
|
||||
this.buttonType.UseVisualStyleBackColor = true;
|
||||
this.buttonType.Click += new System.EventHandler(this.buttonType_Click);
|
||||
//
|
||||
// buttonImage
|
||||
//
|
||||
this.buttonImage.Location = new System.Drawing.Point(109, 242);
|
||||
this.buttonImage.Name = "buttonImage";
|
||||
this.buttonImage.Size = new System.Drawing.Size(142, 23);
|
||||
this.buttonImage.TabIndex = 12;
|
||||
this.buttonImage.TabStop = false;
|
||||
this.buttonImage.Text = "Загрузить картинку";
|
||||
this.buttonImage.UseVisualStyleBackColor = true;
|
||||
this.buttonImage.Click += new System.EventHandler(this.buttonImage_Click);
|
||||
//
|
||||
// ImgFile
|
||||
//
|
||||
this.ImgFile.FileName = "openFileDialog1";
|
||||
//
|
||||
// FormProvider
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(263, 509);
|
||||
this.Controls.Add(this.buttonImage);
|
||||
this.Controls.Add(this.buttonType);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.dropDownList1);
|
||||
this.Controls.Add(this.pictureBox1);
|
||||
this.Controls.Add(this.labelNumber);
|
||||
this.Controls.Add(this.labelType);
|
||||
this.Controls.Add(this.textBoxNumber);
|
||||
this.Controls.Add(this.labelLogo);
|
||||
this.Controls.Add(this.textBoxName);
|
||||
this.Controls.Add(this.labelName);
|
||||
this.Name = "FormProvider";
|
||||
this.Text = "FormProvider";
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormProvider_FormClosing);
|
||||
this.Load += new System.EventHandler(this.FormProvider_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelName;
|
||||
private TextBox textBoxName;
|
||||
private Label labelLogo;
|
||||
private TextBox textBoxNumber;
|
||||
private Label labelType;
|
||||
private Label labelNumber;
|
||||
private PictureBox pictureBox1;
|
||||
private WinForm.DropDownList dropDownList1;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private Button buttonType;
|
||||
private Button buttonImage;
|
||||
private OpenFileDialog ImgFile;
|
||||
}
|
||||
}
|
186
WinFormsProject/AppView/FormProvider.cs
Normal file
186
WinFormsProject/AppView/FormProvider.cs
Normal file
@ -0,0 +1,186 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.StorageContracts;
|
||||
using DocumentFormat.OpenXml.Vml;
|
||||
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;
|
||||
using WinForm;
|
||||
|
||||
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;
|
||||
private byte[] _logo = new byte[0];
|
||||
|
||||
public FormProvider(IProviderStorage providerStorage, ITypeStorage typeStorage)
|
||||
{
|
||||
_providerStorage = providerStorage;
|
||||
_typeStorage = typeStorage;
|
||||
isEdited = false;
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private Image byteArrayToImage(byte[] byteArrayIn)
|
||||
{
|
||||
Image res = null;
|
||||
try
|
||||
{
|
||||
MemoryStream ms = new MemoryStream(byteArrayIn, 0, byteArrayIn.Length);
|
||||
ms.Write(byteArrayIn, 0, byteArrayIn.Length);
|
||||
res = Image.FromStream(ms, true);//Exception occurs here
|
||||
}
|
||||
catch { }
|
||||
return res;
|
||||
}
|
||||
|
||||
private void FormProvider_Load(object sender, EventArgs e)
|
||||
{
|
||||
dropDownList1.ExplicitEvent += OnInputChange;
|
||||
LoadData();
|
||||
if (_id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = _providerStorage.GetElement(new ProviderSearchModel { Id = _id!.Value });
|
||||
if (element != null)
|
||||
{
|
||||
textBoxName.Text = element.Name;
|
||||
_logo = element.Logo;
|
||||
dropDownList1.Selected = element.Type;
|
||||
textBoxNumber.Text = element.Number;
|
||||
|
||||
pictureBox1.Image = byteArrayToImage(_logo);
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка при получении записи", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
var list = _typeStorage.GetFullList().Select(item => item.Name).ToList();
|
||||
dropDownList1.Clear();
|
||||
foreach (var item in list)
|
||||
{
|
||||
dropDownList1.ComboBoxItems.Add(item);
|
||||
}
|
||||
|
||||
if (_id != null)
|
||||
{
|
||||
var provider = _providerStorage.GetElement(new ProviderSearchModel() { Id = _id!.Value });
|
||||
dropDownList1.Selected = provider!.Type;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||
{
|
||||
MessageBox.Show("Название не указано.");
|
||||
return;
|
||||
}
|
||||
if (_logo.Length == 0)
|
||||
{
|
||||
MessageBox.Show("Выберите фото", "Ошибка");
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(dropDownList1.Selected))
|
||||
{
|
||||
MessageBox.Show("Не выбран тип изделий.");
|
||||
return;
|
||||
}
|
||||
if (!Regex.IsMatch(textBoxNumber.Text, @"^\d-\d{3}-\d{3}-\d{2}-\d{2}$"))
|
||||
{
|
||||
MessageBox.Show("Неправильный формат номера телефона.");
|
||||
return;
|
||||
}
|
||||
|
||||
isEdited = false;
|
||||
|
||||
try
|
||||
{
|
||||
var model = new ProviderBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
Name = textBoxName.Text,
|
||||
Logo = _logo,
|
||||
Type = dropDownList1.Selected,
|
||||
Number = textBoxNumber.Text
|
||||
};
|
||||
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 buttonType_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;
|
||||
}
|
||||
|
||||
private void buttonImage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (ImgFile.ShowDialog() != DialogResult.OK) return;
|
||||
|
||||
Image img = Image.FromFile(ImgFile.FileName);
|
||||
using (MemoryStream mStream = new MemoryStream())
|
||||
{
|
||||
img.Save(mStream, img.RawFormat);
|
||||
_logo = mStream.ToArray();
|
||||
}
|
||||
|
||||
pictureBox1.Image = img;
|
||||
}
|
||||
|
||||
private void OnInputChange(object sender, EventArgs e)
|
||||
{
|
||||
isEdited = true;
|
||||
}
|
||||
}
|
||||
}
|
63
WinFormsProject/AppView/FormProvider.resx
Normal file
63
WinFormsProject/AppView/FormProvider.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="ImgFile.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
65
WinFormsProject/AppView/FormType.Designer.cs
generated
Normal file
65
WinFormsProject/AppView/FormType.Designer.cs
generated
Normal file
@ -0,0 +1,65 @@
|
||||
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()
|
||||
{
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.dataGridView.Location = new System.Drawing.Point(0, 0);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowTemplate.Height = 25;
|
||||
this.dataGridView.Size = new System.Drawing.Size(367, 447);
|
||||
this.dataGridView.TabIndex = 0;
|
||||
this.dataGridView.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellValueChanged);
|
||||
this.dataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dataGridView_KeyDown);
|
||||
//
|
||||
// FormType
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(367, 447);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Name = "FormType";
|
||||
this.Text = "FormType";
|
||||
this.Load += new System.EventHandler(this.FormType_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView;
|
||||
}
|
||||
}
|
138
WinFormsProject/AppView/FormType.cs
Normal file
138
WinFormsProject/AppView/FormType.cs
Normal file
@ -0,0 +1,138 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.StorageContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Runtime.CompilerServices;
|
||||
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
WinFormsProject/AppView/FormType.resx
Normal file
60
WinFormsProject/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>
|
@ -1,7 +1,13 @@
|
||||
using Contracts.StorageContracts;
|
||||
using DateBaseImplement.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>
|
||||
@ -11,7 +17,19 @@ namespace AppView
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
var services = new ServiceCollection();
|
||||
ConfigureService(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
}
|
||||
|
||||
private static void ConfigureService(IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<IProviderStorage, ProviderStorage>();
|
||||
services.AddTransient<ITypeStorage, TypeStorage>();
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormProvider>();
|
||||
services.AddTransient<FormType>();
|
||||
}
|
||||
}
|
||||
}
|
@ -39,7 +39,6 @@ namespace WinFormsLibrary
|
||||
|
||||
public void CreateDocument(ImageClass imageClass)
|
||||
{
|
||||
// Проверка наличия данных
|
||||
if (string.IsNullOrEmpty(imageClass.Path) || string.IsNullOrEmpty(imageClass.Title) || imageClass.Files.Count == 0)
|
||||
{
|
||||
throw new Exception("Не все данные заполнены");
|
||||
@ -58,22 +57,16 @@ namespace WinFormsLibrary
|
||||
|
||||
// Добавляем изображения
|
||||
mainPart.Document.Append(body);
|
||||
foreach (string imagePath in imageClass.Files)
|
||||
{
|
||||
if (File.Exists(imagePath))
|
||||
{
|
||||
ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
|
||||
using (FileStream stream = new FileStream(imagePath, FileMode.Open))
|
||||
{
|
||||
imagePart.FeedData(stream);
|
||||
}
|
||||
|
||||
AddImageToBody(wordDocument, mainPart.GetIdOfPart(imagePart));
|
||||
}
|
||||
else
|
||||
foreach (byte[] imageData in imageClass.Files)
|
||||
{
|
||||
ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
|
||||
using (MemoryStream stream = new MemoryStream(imageData))
|
||||
{
|
||||
Console.WriteLine($"Изображение '{imagePath}' не найдено.");
|
||||
imagePart.FeedData(stream);
|
||||
}
|
||||
|
||||
AddImageToBody(wordDocument, mainPart.GetIdOfPart(imagePart));
|
||||
}
|
||||
|
||||
Console.WriteLine($"Word-документ успешно создан в файле '{imageClass.Path}'.");
|
||||
@ -82,66 +75,67 @@ namespace WinFormsLibrary
|
||||
|
||||
private void AddImageToBody(WordprocessingDocument wordDoc, string relationshipId)
|
||||
{
|
||||
var element =
|
||||
new Drawing(
|
||||
new DW.Inline(
|
||||
new DW.Extent() { Cx = 1990000L, Cy = 1792000L },
|
||||
new DW.EffectExtent()
|
||||
{
|
||||
LeftEdge = 0L,
|
||||
TopEdge = 0L,
|
||||
RightEdge = 0L,
|
||||
BottomEdge = 0L
|
||||
},
|
||||
new DW.DocProperties()
|
||||
{
|
||||
Id = (UInt32Value)1U,
|
||||
Name = "Picture 1"
|
||||
},
|
||||
new DW.NonVisualGraphicFrameDrawingProperties(
|
||||
new A.GraphicFrameLocks() { NoChangeAspect = true }),
|
||||
new A.Graphic(
|
||||
new A.GraphicData(
|
||||
new PIC.Picture(
|
||||
new PIC.NonVisualPictureProperties(
|
||||
new PIC.NonVisualDrawingProperties()
|
||||
{
|
||||
Id = (UInt32Value)0U,
|
||||
Name = "New Bitmap Image.jpg"
|
||||
},
|
||||
new PIC.NonVisualPictureDrawingProperties()),
|
||||
new PIC.BlipFill(
|
||||
new A.Blip(
|
||||
new A.BlipExtensionList(
|
||||
new A.BlipExtension()
|
||||
{
|
||||
Uri =
|
||||
"{28A0092B-C50C-407E-A947-70E740481C1C}"
|
||||
})
|
||||
)
|
||||
{
|
||||
Embed = relationshipId,
|
||||
CompressionState =
|
||||
A.BlipCompressionValues.Print
|
||||
},
|
||||
new A.Stretch(
|
||||
new A.FillRectangle())),
|
||||
new PIC.ShapeProperties(
|
||||
new A.Transform2D(
|
||||
new A.Offset() { X = 0L, Y = 0L },
|
||||
new A.Extents() { Cx = 990000L, Cy = 792000L }),
|
||||
new A.PresetGeometry(
|
||||
new A.AdjustValueList()
|
||||
) { Preset = A.ShapeTypeValues.Rectangle }))
|
||||
) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" })
|
||||
)
|
||||
{
|
||||
DistanceFromTop = (UInt32Value)0U,
|
||||
DistanceFromBottom = (UInt32Value)0U,
|
||||
DistanceFromLeft = (UInt32Value)0U,
|
||||
DistanceFromRight = (UInt32Value)0U,
|
||||
EditId = "50D07946"
|
||||
});
|
||||
var element = new Drawing(
|
||||
new DW.Inline(
|
||||
new DW.Extent() { Cx = 1990000L, Cy = 1792000L },
|
||||
new DW.EffectExtent()
|
||||
{
|
||||
LeftEdge = 0L,
|
||||
TopEdge = 0L,
|
||||
RightEdge = 0L,
|
||||
BottomEdge = 0L
|
||||
},
|
||||
new DW.DocProperties()
|
||||
{
|
||||
Id = (UInt32Value)1U,
|
||||
Name = "Picture 1"
|
||||
},
|
||||
new DW.NonVisualGraphicFrameDrawingProperties(
|
||||
new A.GraphicFrameLocks() { NoChangeAspect = true }),
|
||||
new A.Graphic(
|
||||
new A.GraphicData(
|
||||
new PIC.Picture(
|
||||
new PIC.NonVisualPictureProperties(
|
||||
new PIC.NonVisualDrawingProperties()
|
||||
{
|
||||
Id = (UInt32Value)0U,
|
||||
Name = "New Bitmap Image.jpg"
|
||||
},
|
||||
new PIC.NonVisualPictureDrawingProperties()),
|
||||
new PIC.BlipFill(
|
||||
new A.Blip(
|
||||
new A.BlipExtensionList(
|
||||
new A.BlipExtension()
|
||||
{
|
||||
Uri =
|
||||
"{28A0092B-C50C-407E-A947-70E740481C1C}"
|
||||
})
|
||||
)
|
||||
{
|
||||
Embed = relationshipId,
|
||||
CompressionState =
|
||||
A.BlipCompressionValues.Print
|
||||
},
|
||||
new A.Stretch(
|
||||
new A.FillRectangle())),
|
||||
new PIC.ShapeProperties(
|
||||
new A.Transform2D(
|
||||
new A.Offset() { X = 0L, Y = 0L },
|
||||
new A.Extents() { Cx = 990000L, Cy = 792000L }),
|
||||
new A.PresetGeometry(
|
||||
new A.AdjustValueList()
|
||||
)
|
||||
{ Preset = A.ShapeTypeValues.Rectangle }))
|
||||
)
|
||||
{ Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" })
|
||||
)
|
||||
{
|
||||
DistanceFromTop = (UInt32Value)0U,
|
||||
DistanceFromBottom = (UInt32Value)0U,
|
||||
DistanceFromLeft = (UInt32Value)0U,
|
||||
DistanceFromRight = (UInt32Value)0U,
|
||||
EditId = "50D07946"
|
||||
});
|
||||
|
||||
// Append the reference to the body. The element should be in
|
||||
// a DocumentFormat.OpenXml.Wordprocessing.Run.
|
||||
|
@ -10,13 +10,13 @@ namespace WinFormsLibrary.SupportClasses
|
||||
{
|
||||
private string path;
|
||||
private string title;
|
||||
private List<string> files;
|
||||
private List<byte[]> files;
|
||||
public string Path { get { return path; } set { path = value; } }
|
||||
public string Title { get { return title; } set { title = value; } }
|
||||
public List<string> Files { get { return files; } set { files = value; } }
|
||||
public List<byte[]> Files { get { return files; } set { files = value; } }
|
||||
public ImageClass() { }
|
||||
|
||||
public ImageClass(string filePath, string documentTitle, List<string> textData)
|
||||
public ImageClass(string filePath, string documentTitle, List<byte[]> textData)
|
||||
{
|
||||
Path = filePath;
|
||||
Title = documentTitle;
|
||||
|
Loading…
Reference in New Issue
Block a user