Привет, я лаба 3, я готова)

This commit is contained in:
Володя 2023-10-26 16:26:41 +03:00
parent 8f8f0ab6c1
commit e10dd34475
48 changed files with 2226 additions and 77 deletions

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DatabaseImplement\DatabaseImplement.csproj" />
<ProjectReference Include="..\DataContracts\DataContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,117 @@
using DatabaseImplement.Implements;
using DataContracts.bindingModels;
using DataContracts.BLs;
using DataContracts.searchModels;
using DataContracts.storages;
using DataContracts.viewModels;
namespace BusinessLogic
{
public class ClientBL : IClientBL
{
private readonly ClientStorage _clientStorage;
private readonly ProductBL productBL;
public ClientBL()
{
_clientStorage = new();
productBL = new ProductBL();
}
public bool Create(ClientBindingModel model)
{
CheckModel(model);
if (_clientStorage.Insert(model) == null)
{
return false;
}
return true;
}
public List<(string title, int count)> FindDataDiagram()
{
List<(string, int)> list = new List<(string, int)>();
List<ClientViewModel> clients = ReadList();
List<ProductViewModel> products = productBL.ReadList();
foreach(ProductViewModel product in products)
{
int count = 0;
foreach(ClientViewModel client in clients)
{
if(client.products.Contains(product.title))
count++;
}
list.Add((product.title, count));
}
return list;
}
public bool Delete(ClientBindingModel model)
{
CheckModel(model, false);
if (_clientStorage.Delete(model) == null)
{
return false;
}
return true;
}
public ClientViewModel? ReadElement(ClientSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _clientStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public List<ClientViewModel>? ReadList()
{
var list = _clientStorage.GetFullList();
if (list == null)
{
return null;
}
return list;
}
public bool Update(ClientBindingModel model)
{
CheckModel(model);
if (_clientStorage.Update(model) == null)
{
return false;
}
return true;
}
private void CheckModel(ClientBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.FIO))
{
throw new ArgumentNullException("Нет имени клиента", nameof(model.FIO));
}
if (string.IsNullOrEmpty(model.email))
{
throw new ArgumentNullException("Нет почты клиента", nameof(model.email));
}
if (string.IsNullOrEmpty(model.products))
{
throw new ArgumentNullException("Нет продуктов клиента", nameof(model.products));
}
}
}
}

View File

@ -0,0 +1,90 @@
using DatabaseImplement.Implements;
using DataContracts.bindingModels;
using DataContracts.BLs;
using DataContracts.searchModels;
using DataContracts.viewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic
{
public class ProductBL : IProductBL
{
private readonly ProductStorage _productStorage = new();
public bool Create(ProductBindingModel model)
{
CheckModel(model);
if (_productStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Delete(ProductBindingModel model)
{
CheckModel(model, false);
if (_productStorage.Delete(model) == null)
{
return false;
}
return true;
}
public ProductViewModel? ReadElement(ProductSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _productStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public List<ProductViewModel>? ReadList()
{
var list = _productStorage.GetFullList();
if (list == null)
{
return null;
}
return list;
}
public bool Update(ProductBindingModel model)
{
CheckModel(model);
if (_productStorage.Update(model) == null)
{
return false;
}
return true;
}
private void CheckModel(ProductBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.title))
{
throw new ArgumentNullException("Нет имени клиента", nameof(model.title));
}
}
}
}

145
VisEl/ClientForms/Client.Designer.cs generated Normal file
View File

@ -0,0 +1,145 @@
namespace ClientForms
{
partial class Client
{
/// <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.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
this.textBoxFIO = new System.Windows.Forms.TextBox();
this.myEmailTextBox = new VisualCompLib.MyEmailTextBox();
this.buttonPhoto = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button();
this.myCheckListProducts = new VisableComponents.MyCheckList();
this.openFileDialogPath = new System.Windows.Forms.OpenFileDialog();
this.tableLayoutPanel.SuspendLayout();
this.SuspendLayout();
//
// tableLayoutPanel
//
this.tableLayoutPanel.ColumnCount = 1;
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel.Controls.Add(this.textBoxFIO, 0, 0);
this.tableLayoutPanel.Controls.Add(this.myEmailTextBox, 0, 1);
this.tableLayoutPanel.Controls.Add(this.buttonPhoto, 0, 2);
this.tableLayoutPanel.Controls.Add(this.buttonSave, 0, 4);
this.tableLayoutPanel.Controls.Add(this.myCheckListProducts, 0, 3);
this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel.Name = "tableLayoutPanel";
this.tableLayoutPanel.Padding = new System.Windows.Forms.Padding(3);
this.tableLayoutPanel.RowCount = 5;
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 47.05882F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 52.94118F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 56F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 310F));
this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 48F));
this.tableLayoutPanel.Size = new System.Drawing.Size(363, 517);
this.tableLayoutPanel.TabIndex = 0;
//
// textBoxFIO
//
this.textBoxFIO.Dock = System.Windows.Forms.DockStyle.Fill;
this.textBoxFIO.Location = new System.Drawing.Point(6, 6);
this.textBoxFIO.Name = "textBoxFIO";
this.textBoxFIO.Size = new System.Drawing.Size(351, 27);
this.textBoxFIO.TabIndex = 0;
this.textBoxFIO.TextChanged += new System.EventHandler(this.textBoxFIO_TextChanged);
//
// myEmailTextBox
//
this.myEmailTextBox.Location = new System.Drawing.Point(6, 52);
this.myEmailTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.myEmailTextBox.Name = "myEmailTextBox";
this.myEmailTextBox.Pattern = null;
this.myEmailTextBox.Size = new System.Drawing.Size(221, 43);
this.myEmailTextBox.TabIndex = 1;
//
// buttonPhoto
//
this.buttonPhoto.Dock = System.Windows.Forms.DockStyle.Fill;
this.buttonPhoto.Location = new System.Drawing.Point(6, 102);
this.buttonPhoto.Name = "buttonPhoto";
this.buttonPhoto.Size = new System.Drawing.Size(351, 50);
this.buttonPhoto.TabIndex = 2;
this.buttonPhoto.Text = "Выбрать фото";
this.buttonPhoto.UseVisualStyleBackColor = true;
this.buttonPhoto.Click += new System.EventHandler(this.buttonPhoto_Click);
//
// buttonSave
//
this.buttonSave.Dock = System.Windows.Forms.DockStyle.Fill;
this.buttonSave.Location = new System.Drawing.Point(6, 468);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(351, 43);
this.buttonSave.TabIndex = 3;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
//
// myCheckListProducts
//
this.myCheckListProducts.AutoSize = true;
this.myCheckListProducts.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.myCheckListProducts.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.myCheckListProducts.Location = new System.Drawing.Point(6, 159);
this.myCheckListProducts.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.myCheckListProducts.Name = "myCheckListProducts";
this.myCheckListProducts.selectedValue = "";
this.myCheckListProducts.Size = new System.Drawing.Size(285, 298);
this.myCheckListProducts.TabIndex = 4;
//
// openFileDialogPath
//
this.openFileDialogPath.FileName = "openFileDialog1";
//
// Client
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(363, 517);
this.Controls.Add(this.tableLayoutPanel);
this.Name = "Client";
this.Text = "Client";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Client_FormClosing);
this.Load += new System.EventHandler(this.Client_Load);
this.tableLayoutPanel.ResumeLayout(false);
this.tableLayoutPanel.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private TableLayoutPanel tableLayoutPanel;
private TextBox textBoxFIO;
private VisualCompLib.MyEmailTextBox myEmailTextBox;
private Button buttonPhoto;
private Button buttonSave;
private OpenFileDialog openFileDialogPath;
private VisableComponents.MyCheckList myCheckListProducts;
}
}

173
VisEl/ClientForms/Client.cs Normal file
View File

@ -0,0 +1,173 @@
using BusinessLogic;
using DataContracts.bindingModels;
using DataContracts.searchModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ClientForms
{
public partial class Client : Form
{
private readonly ClientBL clientBL = new ClientBL();
private readonly ProductBL productBL = new ProductBL();
private int? _id;
private bool fioFlag = false;
private bool emailFlag = false;
private bool photoFlag = false;
private bool EditfioFlag = false;
private bool EditemailFlag = false;
private bool EditphotoFlag = false;
private bool close = false;
private byte[] image;
private List<string> oldProducts = new List<string>();
public int? Id { get { return _id; } set { _id = value; } }
public Client()
{
InitializeComponent();
myEmailTextBox.ValueChanged += EmailTextBox_TextChanged;
myEmailTextBox.Pattern = "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$";
}
private void Client_Load(object sender, EventArgs e)
{
LoadData();
if (Id.HasValue)
{
var current_client = clientBL.ReadElement(new ClientSearchModel { Id = Id });
if(current_client != null)
{
textBoxFIO.Text = current_client.FIO;
myEmailTextBox.TextBoxValue = current_client.email;
image = current_client.photo;
oldProducts = current_client.products.Split(',').ToList();
buttonPhoto.BackColor = Color.DarkOliveGreen;
myCheckListProducts.setValues(current_client.products.Split(',').ToList());
EditfioFlag = false;
EditemailFlag = false;
EditphotoFlag = false;
fioFlag = true;
emailFlag = true;
photoFlag = true;
}
}
}
private bool checkProducts()
{
if(oldProducts.Count != myCheckListProducts.getSelectedItems().Count)
return true;
foreach(var oldProd in oldProducts)
{
if(!myCheckListProducts.getSelectedItems().Contains(oldProd))
return true;
}
return false;
}
private void LoadData()
{
myCheckListProducts.LoadValues(productBL.ReadList().Select(x => x.title).ToList());
}
private void textBoxFIO_TextChanged(object sender, EventArgs e)
{
EditfioFlag = true;
if (textBoxFIO.Text.Length != 0)
{
fioFlag = true;
textBoxFIO.BackColor = Color.DarkOliveGreen;
}
else
{
fioFlag = false;
textBoxFIO.BackColor = Color.IndianRed;
}
}
private void EmailTextBox_TextChanged(object sender, EventArgs e)
{
EditemailFlag = true;
if (myEmailTextBox.TextBoxValue != null)
{
emailFlag = true;
myEmailTextBox.BackColor = Color.DarkOliveGreen;
}
else
{
emailFlag = false;
myEmailTextBox.BackColor = Color.IndianRed;
}
}
private void buttonPhoto_Click(object sender, EventArgs e)
{
EditphotoFlag = true;
if (openFileDialogPath.ShowDialog() == DialogResult.Cancel)
return;
string filename = openFileDialogPath.FileName;
Image img = Image.FromFile(filename);
byte[] bA;
using (MemoryStream mStream = new MemoryStream())
{
img.Save(mStream, img.RawFormat);
bA = mStream.ToArray();
}
image = bA;
photoFlag = true;
buttonPhoto.BackColor = Color.DarkOliveGreen;
}
private void buttonSave_Click(object sender, EventArgs e)
{
if(fioFlag & emailFlag & photoFlag & myCheckListProducts.selectedValuesCount != 0)
{
if(!Id.HasValue)
clientBL.Create(new ClientBindingModel {
FIO = textBoxFIO.Text,
email = myEmailTextBox.TextBoxValue,
photo = image,
products = string.Join(",", myCheckListProducts.getSelectedItems().ToArray())
});
else
clientBL.Update(new ClientBindingModel
{
Id = (int)Id,
FIO = textBoxFIO.Text,
email = myEmailTextBox.TextBoxValue,
photo = image,
products = string.Join(",", myCheckListProducts.getSelectedItems())
});
close = true;
this.Close();
}
else
{
MessageBox.Show("Не заполнены поля");
}
}
private void Client_FormClosing(object sender, FormClosingEventArgs e)
{
if (close)
{
e.Cancel = false;
return;
}
if ((EditfioFlag || EditemailFlag || EditphotoFlag || checkProducts()))
{
DialogResult dialogResult = MessageBox.Show("Вы забыли сохранить изменения! Желаете выйти?", "Важно", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
e.Cancel = false;
else
e.Cancel = true;
}
}
}
}

View 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="openFileDialogPath.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,33 @@
<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="Microsoft.EntityFrameworkCore.Design" Version="7.0.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
<PackageReference Include="UnvisableComponents" Version="1.0.0" />
<PackageReference Include="VisableComponents" Version="1.0.6" />
<PackageReference Include="VisualCompLib" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj" />
<ProjectReference Include="..\DataContracts\DataContracts.csproj" />
</ItemGroup>
</Project>

157
VisEl/ClientForms/Main.Designer.cs generated Normal file
View File

@ -0,0 +1,157 @@
namespace ClientForms
{
partial class Main
{
/// <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.controlDataTableTable = 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.сохранитьВЭксельToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.сохранитьВПдфToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.обновитьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.imageExcel1 = new UnvisableComponents.ImageExcel(this.components);
this.wordTable1 = new VisualCompLib.Components.WordTable(this.components);
this.componentDocumentWithChartBarPdf1 = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarPdf(this.components);
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.contextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
// controlDataTableTable
//
this.controlDataTableTable.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.controlDataTableTable.Dock = System.Windows.Forms.DockStyle.Fill;
this.controlDataTableTable.Location = new System.Drawing.Point(0, 0);
this.controlDataTableTable.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.controlDataTableTable.Name = "controlDataTableTable";
this.controlDataTableTable.SelectedRowIndex = -1;
this.controlDataTableTable.Size = new System.Drawing.Size(800, 450);
this.controlDataTableTable.TabIndex = 0;
//
// contextMenuStrip1
//
this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.добавитьToolStripMenuItem,
this.редактироватьToolStripMenuItem,
this.удалитьToolStripMenuItem,
this.сохранитьВВордToolStripMenuItem,
this.сохранитьВЭксельToolStripMenuItem,
this.сохранитьВПдфToolStripMenuItem,
this.обновитьToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(216, 172);
//
// добавитьToolStripMenuItem
//
this.добавитьToolStripMenuItem.Name = обавитьToolStripMenuItem";
this.добавитьToolStripMenuItem.Size = new System.Drawing.Size(215, 24);
this.добавитьToolStripMenuItem.Text = "Добавить";
this.добавитьToolStripMenuItem.Click += new System.EventHandler(this.добавитьToolStripMenuItem_Click);
//
// редактироватьToolStripMenuItem
//
this.редактироватьToolStripMenuItem.Name = "редактироватьToolStripMenuItem";
this.редактироватьToolStripMenuItem.Size = new System.Drawing.Size(215, 24);
this.редактироватьToolStripMenuItem.Text = "Редактировать";
this.редактироватьToolStripMenuItem.Click += new System.EventHandler(this.редактироватьToolStripMenuItem_Click);
//
// удалитьToolStripMenuItem
//
this.удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem";
this.удалитьToolStripMenuItem.Size = new System.Drawing.Size(215, 24);
this.удалитьToolStripMenuItem.Text = "Удалить";
this.удалитьToolStripMenuItem.Click += new System.EventHandler(this.удалитьToolStripMenuItem_Click);
//
// сохранитьВВордToolStripMenuItem
//
this.сохранитьВВордToolStripMenuItem.Name = "сохранитьВВордToolStripMenuItem";
this.сохранитьВВордToolStripMenuItem.Size = new System.Drawing.Size(215, 24);
this.сохранитьВВордToolStripMenuItem.Text = "Сохранить в Ворд";
this.сохранитьВВордToolStripMenuItem.Click += new System.EventHandler(this.сохранитьВВордToolStripMenuItem_Click);
//
// сохранитьВЭксельToolStripMenuItem
//
this.сохранитьВЭксельToolStripMenuItem.Name = "сохранитьВЭксельToolStripMenuItem";
this.сохранитьВЭксельToolStripMenuItem.Size = new System.Drawing.Size(215, 24);
this.сохранитьВЭксельToolStripMenuItem.Text = "Сохранить в Эксель";
this.сохранитьВЭксельToolStripMenuItem.Click += new System.EventHandler(this.сохранитьВЭксельToolStripMenuItem_Click);
//
// сохранитьВПдфToolStripMenuItem
//
this.сохранитьВПдфToolStripMenuItem.Name = "сохранитьВПдфToolStripMenuItem";
this.сохранитьВПдфToolStripMenuItem.Size = new System.Drawing.Size(215, 24);
this.сохранитьВПдфToolStripMenuItem.Text = "Сохранить в пдф";
this.сохранитьВПдфToolStripMenuItem.Click += new System.EventHandler(this.сохранитьВПдфToolStripMenuItem_Click);
//
// обновитьToolStripMenuItem
//
this.обновитьToolStripMenuItem.Name = "обновитьToolStripMenuItem";
this.обновитьToolStripMenuItem.Size = new System.Drawing.Size(215, 24);
this.обновитьToolStripMenuItem.Text = "Обновить";
this.обновитьToolStripMenuItem.Click += new System.EventHandler(this.обновитьToolStripMenuItem_Click);
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// Main
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.controlDataTableTable);
this.Name = "Main";
this.Text = "Main";
this.Load += new System.EventHandler(this.Main_Load);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Main_KeyDown);
this.contextMenuStrip1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private ControlsLibraryNet60.Data.ControlDataTableTable controlDataTableTable;
private ContextMenuStrip contextMenuStrip1;
private ToolStripMenuItem добавитьToolStripMenuItem;
private ToolStripMenuItem редактироватьToolStripMenuItem;
private ToolStripMenuItem удалитьToolStripMenuItem;
private ToolStripMenuItem сохранитьВВордToolStripMenuItem;
private ToolStripMenuItem сохранитьВЭксельToolStripMenuItem;
private ToolStripMenuItem сохранитьВПдфToolStripMenuItem;
private ToolStripMenuItem обновитьToolStripMenuItem;
private UnvisableComponents.ImageExcel imageExcel1;
private VisualCompLib.Components.WordTable wordTable1;
private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartBarPdf componentDocumentWithChartBarPdf1;
private OpenFileDialog openFileDialog1;
}
}

227
VisEl/ClientForms/Main.cs Normal file
View File

@ -0,0 +1,227 @@
using BusinessLogic;
using ControlsLibraryNet60.Data;
using ControlsLibraryNet60.Models;
using DataContracts.bindingModels;
using DataContracts.viewModels;
using OfficeOpenXml.LoadFunctions.Params;
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 UnvisableComponents;
using VisualCompLib.Components;
using VisualCompLib.Components.SupportClasses;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
using VisualCompLib.Object;
using ComponentsLibraryNet60.DocumentWithChart;
using ComponentsLibraryNet60.Models;
namespace ClientForms
{
public partial class Main : Form
{
private readonly ClientBL clientBl = new();
public Main()
{
InitializeComponent();
this.KeyPreview = true;
controlDataTableTable.ContextMenuStrip = contextMenuStrip1;
}
private void Main_Load(object sender, EventArgs e)
{
List<DataTableColumnConfig> columns = new List<DataTableColumnConfig>();
columns.Add(new DataTableColumnConfig
{
ColumnHeader = "Id",
PropertyName = "Id",
Visible = false
});
columns.Add(new DataTableColumnConfig
{
ColumnHeader = "ФИО",
PropertyName = "FIO",
Visible = true
});
columns.Add(new DataTableColumnConfig
{
ColumnHeader = "Почта",
PropertyName = "email",
Visible = true
});
columns.Add(new DataTableColumnConfig
{
ColumnHeader = "Продукты",
PropertyName = "products",
Visible = true
});
controlDataTableTable.LoadColumns(columns);
controlDataTableTable.AddTable<ClientViewModel>(clientBl.ReadList());
}
private void добавитьToolStripMenuItem_Click(object sender, EventArgs e)
{
Client client = new Client();
client.Show();
}
private void обновитьToolStripMenuItem_Click(object sender, EventArgs e)
{
UpdateTable();
}
private void редактироватьToolStripMenuItem_Click(object sender, EventArgs e)
{
var client = controlDataTableTable.GetSelectedObject<ClientViewModel>();
if (client != null)
{
Client clientForm = new Client();
clientForm.Id = client.Id;
clientForm.Show();
}
else
MessageBox.Show("Выберите запись!!");
UpdateTable();
}
private void UpdateTable()
{
controlDataTableTable.Clear();
controlDataTableTable.AddTable<ClientViewModel>(clientBl.ReadList());
}
private void удалитьToolStripMenuItem_Click(object sender, EventArgs e)
{
var client = controlDataTableTable.GetSelectedObject<ClientViewModel>();
if (client != null)
{
DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
clientBl.Delete(new ClientBindingModel { Id = client.Id });
}
else
MessageBox.Show("Выберите запись!!");
UpdateTable();
}
private void сохранитьВВордToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Word files (*.docx)|*.docx";
if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
return;
string filename = openFileDialog1.FileName;
string titleTable = "Клиенты";
List<ColumnDefinition> columnDefinitionsUp = new List<ColumnDefinition> {
new ColumnDefinition{Header = "#", PropertyName = "Id", Weight = 30},
new ColumnDefinition{Header = "Личные данные", PropertyName = "FioEmail", Weight = 30},
new ColumnDefinition{Header = "", PropertyName = "FioEmail", Weight = 30},
new ColumnDefinition{Header = "Продукты", PropertyName = "products", Weight = 30},
};
List<ColumnDefinition> columnDefinitionsDown = new List<ColumnDefinition> {
new ColumnDefinition{Header = "#", PropertyName = "Id", Weight = 30},
new ColumnDefinition{Header = "ФИО", PropertyName = "FIO", Weight = 30},
new ColumnDefinition{Header = "Почта", PropertyName = "email", Weight = 30},
new ColumnDefinition{Header = "Продукты", PropertyName = "products", Weight = 30},
};
List<int[]> mergedColums = new() { new int[] { 1, 2 } };
List<ClientViewModel> clients = clientBl.ReadList();
BigTable<ClientViewModel> bigTable = new(filename, titleTable, columnDefinitionsUp, columnDefinitionsDown, clients, mergedColums);
wordTable1.CreateTable(bigTable);
MessageBox.Show("Готово");
}
private void сохранитьВЭксельToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "Excel files (*.xlsx)|*.xlsx";
if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
return;
string filename = openFileDialog1.FileName;
string title = "Отчет о клиентах";
List<byte[]> bytes = clientBl.ReadList().Select(x => x.photo).ToList();
ImageInfo info = new ImageInfo();
info.Title = title;
info.Path = filename;
info.Files = bytes;
imageExcel1.Load(info);
MessageBox.Show("Готово");
}
private void сохранитьВПдфToolStripMenuItem_Click(object sender, EventArgs e)
{
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
openFileDialog1.Filter = "Pdf files (*.pdf)|*.pdf";
if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
return;
string filename = openFileDialog1.FileName;
Dictionary<string, List<(int Date, double Value)>> data = new Dictionary<string, List<(int Date, double Value)>>();
foreach(var item in clientBl.FindDataDiagram())
{
data.Add(
item.title,
new List<(int Date, double Value)> { (1, item.count) }
);
}
componentDocumentWithChartBarPdf1.CreateDoc(new ComponentDocumentWithChartConfig
{
FilePath = filename,
Header = "Категории и клиенты",
ChartTitle = "Соотношение",
LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom,
Data = data
});
MessageBox.Show("Готово");
}
private void Main_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.A)
{
добавитьToolStripMenuItem_Click(sender, e);
}
if (e.Control && e.KeyCode == Keys.U)
{
редактироватьToolStripMenuItem_Click(sender, e);
}
if (e.Control && e.KeyCode == Keys.Z)
{
UpdateTable();
}
if (e.Control && e.KeyCode == Keys.D)
{
удалитьToolStripMenuItem_Click(sender, e);
}
if (e.Control && e.KeyCode == Keys.S)
{
сохранитьВЭксельToolStripMenuItem_Click(sender,e);
}
if (e.Control && e.KeyCode == Keys.T)
{
сохранитьВВордToolStripMenuItem_Click(sender, e);
}
if (e.Control && e.KeyCode == Keys.C)
{
сохранитьВПдфToolStripMenuItem_Click(sender, e);
}
if (e.KeyCode == Keys.Tab)
{
Products products = new();
products.Show();
}
}
}
}

View File

@ -0,0 +1,75 @@
<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="imageExcel1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>203, 17</value>
</metadata>
<metadata name="wordTable1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>340, 17</value>
</metadata>
<metadata name="componentDocumentWithChartBarPdf1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>472, 17</value>
</metadata>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>796, 17</value>
</metadata>
</root>

68
VisEl/ClientForms/Products.Designer.cs generated Normal file
View File

@ -0,0 +1,68 @@
namespace ClientForms
{
partial class Products
{
/// <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(5, 5);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(317, 268);
this.dataGridView.TabIndex = 0;
this.dataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellEndEdit);
this.dataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Products_KeyDown);
//
// Products
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ClientSize = new System.Drawing.Size(327, 278);
this.Controls.Add(this.dataGridView);
this.Name = "Products";
this.Padding = new System.Windows.Forms.Padding(5);
this.Text = "Products";
this.Load += new System.EventHandler(this.Products_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,96 @@
using BusinessLogic;
using DatabaseImplement.models;
using DataContracts.bindingModels;
using DataContracts.viewModels;
using DocumentFormat.OpenXml.Bibliography;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
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 ClientForms
{
public partial class Products : Form
{
private readonly ProductBL productBl = new();
BindingList<ProductViewModel> list ;
public Products()
{
InitializeComponent();
}
public void LoadData()
{
list = productBl.ReadList() != null ? new BindingList<ProductViewModel>(productBl.ReadList()) : new BindingList<ProductViewModel>();
dataGridView.DataSource = list;
dataGridView.MultiSelect = false;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["title"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
private void Products_Load(object sender, EventArgs e)
{
LoadData();
}
private void Products_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Insert)
{
dataGridView.Rows[^1].Cells["title"].Selected = true;
dataGridView.BeginEdit(true);
}
if (e.KeyCode == Keys.Delete)
{
if(dataGridView.CurrentCell != null)
{
DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
productBl.Delete(new ProductBindingModel { Id = (int)dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells["Id"].Value });
LoadData();
}
}
}
private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView.Rows[e.RowIndex].Cells["title"].Value == null || string.IsNullOrEmpty(dataGridView.Rows[e.RowIndex].Cells["title"].Value.ToString()) )
{
return;
}
else
{
if((int)dataGridView.Rows[e.RowIndex].Cells["Id"].Value != 0)
{
productBl.Update(new ProductBindingModel
{
Id = (int)dataGridView.Rows[e.RowIndex].Cells["Id"].Value,
title = dataGridView.Rows[e.RowIndex].Cells["title"].Value.ToString()
});
}
else
{
productBl.Create(new ProductBindingModel
{
title = dataGridView.Rows[e.RowIndex].Cells["title"].Value.ToString()
});
}
LoadData();
}
}
}
}

View 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>

View File

@ -0,0 +1,17 @@
namespace ClientForms
{
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 Main());
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataContracts.bindingModels;
using DataContracts.searchModels;
using DataContracts.viewModels;
namespace DataContracts.BLs
{
public interface IClientBL
{
List<ClientViewModel>? ReadList();
ClientViewModel? ReadElement(ClientSearchModel model);
List<(string title, int count)> FindDataDiagram();
bool Create(ClientBindingModel model);
bool Update(ClientBindingModel model);
bool Delete(ClientBindingModel model);
}
}

View File

@ -0,0 +1,21 @@

using DataContracts.bindingModels;
using DataContracts.searchModels;
using DataContracts.viewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataContracts.BLs
{
public interface IProductBL
{
List<ProductViewModel>? ReadList();
ProductViewModel? ReadElement(ProductSearchModel model);
bool Create(ProductBindingModel model);
bool Update(ProductBindingModel model);
bool Delete(ProductBindingModel model);
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataContracts.models;
namespace DataContracts.bindingModels
{
public class ClientBindingModel : IClient
{
public int Id { get; set; }
public string FIO { get; set; } = string.Empty;
public byte[] photo { get; set; }
public string email { get; set; } = string.Empty;
public string products { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,16 @@
using DataContracts.models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataContracts.bindingModels
{
public class ProductBindingModel : IProduct
{
public int Id { get; set; }
public string title {get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataContracts.models
{
public interface IClient
{
public int Id { get; }
public string FIO { get; set; }
public byte[] photo { get; set; }
public string email { get; set; }
public string products { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataContracts.models
{
public interface IProduct
{
int Id { get; }
string title { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataContracts.searchModels
{
public class ClientSearchModel
{
public int? Id { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataContracts.searchModels
{
public class ProductSearchModel
{
public int? Id { get; set; }
}
}

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataContracts.bindingModels;
using DataContracts.searchModels;
using DataContracts.viewModels;
namespace DataContracts.storages
{
public interface IClientStorage
{
List<ClientViewModel> GetFullList();
ClientViewModel? GetElement(ClientSearchModel model);
ClientViewModel? Insert(ClientBindingModel model);
ClientViewModel? Update(ClientBindingModel model);
ClientViewModel? Delete(ClientBindingModel model);
}
}

View File

@ -0,0 +1,20 @@
using DataContracts.bindingModels;
using DataContracts.searchModels;
using DataContracts.viewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataContracts.storages
{
public interface IProductStorage
{
List<ProductViewModel> GetFullList();
ProductViewModel? GetElement(ProductSearchModel model);
ProductViewModel? Insert(ProductBindingModel model);
ProductViewModel? Update(ProductBindingModel model);
ProductViewModel? Delete(ProductBindingModel model);
}
}

View File

@ -0,0 +1,22 @@
using DataContracts.models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataContracts.viewModels
{
public class ClientViewModel : IClient
{
public int Id { get; set; }
[DisplayName("ФИО")]
public string FIO { get; set; } = string.Empty;
public byte[] photo { get; set; }
[DisplayName("Почта")]
public string email { get; set; } = string.Empty;
[DisplayName("Категории продуктов")]
public string products { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,18 @@
using DataContracts.models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataContracts.viewModels
{
public class ProductViewModel : IProduct
{
public int Id { get; set; }
[DisplayName("Название")]
public string title { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,28 @@
using DatabaseImplement.models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement
{
public class AppDataBase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseNpgsql("Server=PostgreSQL;Host=localhost;Port=5432;Database=ClientsAndProducts;Username=postgres;Password=123456");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Client> Clients { set; get; }
public virtual DbSet<Product> Products { set; get; }
}
}

View File

@ -0,0 +1,22 @@
<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="..\DataContracts\DataContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,75 @@
using DatabaseImplement.models;
using DataContracts.bindingModels;
using DataContracts.searchModels;
using DataContracts.storages;
using DataContracts.viewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Implements
{
public class ClientStorage : IClientStorage
{
public ClientViewModel? Delete(ClientBindingModel model)
{
using var context = new AppDataBase();
var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Clients.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new AppDataBase();
return context.Clients
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
public List<ClientViewModel> GetFullList()
{
using var context = new AppDataBase();
return context.Clients
.Select(x => x.GetViewModel)
.ToList();
}
public ClientViewModel? Insert(ClientBindingModel model)
{
var newClient = Client.Create(model);
if (newClient == null)
{
return null;
}
using var context = new AppDataBase();
context.Clients.Add(newClient);
context.SaveChanges();
return newClient.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
using var context = new AppDataBase();
var client = context.Clients.FirstOrDefault(x => x.Id == model.Id);
if (client == null)
{
return null;
}
client.Update(model);
context.SaveChanges();
return client.GetViewModel;
}
}
}

View File

@ -0,0 +1,75 @@
using DatabaseImplement.models;
using DataContracts.bindingModels;
using DataContracts.searchModels;
using DataContracts.storages;
using DataContracts.viewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Implements
{
public class ProductStorage : IProductStorage
{
public ProductViewModel? Delete(ProductBindingModel model)
{
using var context = new AppDataBase();
var element = context.Products.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Products.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public ProductViewModel? GetElement(ProductSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new AppDataBase();
return context.Products
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
public List<ProductViewModel> GetFullList()
{
using var context = new AppDataBase();
return context.Products
.Select(x => x.GetViewModel)
.ToList();
}
public ProductViewModel? Insert(ProductBindingModel model)
{
var newProduct = Product.Create(model);
if (newProduct == null)
{
return null;
}
using var context = new AppDataBase();
context.Products.Add(newProduct);
context.SaveChanges();
return newProduct.GetViewModel;
}
public ProductViewModel? Update(ProductBindingModel model)
{
using var context = new AppDataBase();
var product = context.Products.FirstOrDefault(x => x.Id == model.Id);
if (product == null)
{
return null;
}
product.Update(model);
context.SaveChanges();
return product.GetViewModel;
}
}
}

View File

@ -0,0 +1,75 @@
// <auto-generated />
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(AppDataBase))]
[Migration("20231025110458_initial")]
partial class initial
{
/// <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.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("email")
.IsRequired()
.HasColumnType("text");
b.Property<byte[]>("photo")
.IsRequired()
.HasColumnType("bytea");
b.Property<string>("products")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("DatabaseImplement.models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Products");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,54 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FIO = table.Column<string>(type: "text", nullable: false),
photo = table.Column<byte[]>(type: "bytea", nullable: false),
email = table.Column<string>(type: "text", nullable: false),
products = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Products",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
title = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Products", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable(
name: "Products");
}
}
}

View File

@ -0,0 +1,75 @@
// <auto-generated />
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(AppDataBase))]
[Migration("20231025152005_initial2")]
partial class initial2
{
/// <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.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("email")
.IsRequired()
.HasColumnType("text");
b.Property<byte[]>("photo")
.IsRequired()
.HasColumnType("bytea");
b.Property<string>("products")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("DatabaseImplement.models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Products");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class initial2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

@ -0,0 +1,72 @@
// <auto-generated />
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(AppDataBase))]
partial class AppDataBaseModelSnapshot : 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.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("email")
.IsRequired()
.HasColumnType("text");
b.Property<byte[]>("photo")
.IsRequired()
.HasColumnType("bytea");
b.Property<string>("products")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("DatabaseImplement.models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Products");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,51 @@
using DataContracts.bindingModels;
using DataContracts.models;
using DataContracts.viewModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Reflection;
namespace DatabaseImplement.models
{
public class Client : IClient
{
public int Id { get; set; }
[Required]
public string FIO { get; set; } = string.Empty;
[Required]
public byte[] photo { get; set; } = new byte[0];
[Required]
public string email { get; set; } = string.Empty;
public string products { get; set; } = string.Empty;
public static Client Create(ClientBindingModel model)
{
return new Client()
{
Id = model.Id,
FIO = model.FIO,
photo = model.photo,
email = model.email,
products = model.products
};
}
public void Update(ClientBindingModel model)
{
FIO = model.FIO;
email = model.email;
photo = model.photo;
products = model.products;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
FIO = FIO,
photo = photo,
email = email,
products = products
};
}
}

View File

@ -0,0 +1,40 @@
using DataContracts.bindingModels;
using DataContracts.models;
using DataContracts.viewModels;
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 Product : IProduct
{
public int Id { get; set; }
[Required]
public string title { get; set; } = string.Empty;
public static Product Create(ProductBindingModel model)
{
return new Product()
{
Id = model.Id,
title = model.title
};
}
public void Update(ProductBindingModel model)
{
title = model.title;
}
public ProductViewModel GetViewModel => new()
{
Id = Id,
title = title,
};
}
}

View File

@ -3,11 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.3.32825.248 VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnvisableComponents", "UnvisableComponents\UnvisableComponents.csproj", "{B720A881-1A22-48BB-B0C6-23F616E6D10D}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnvisableComponents", "UnvisableComponents\UnvisableComponents.csproj", "{B720A881-1A22-48BB-B0C6-23F616E6D10D}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestForm", "TestForm\TestForm.csproj", "{53DEA306-E3B4-4662-A337-7076CF636F6A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestForm", "TestForm\TestForm.csproj", "{53DEA306-E3B4-4662-A337-7076CF636F6A}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisableComponents", "VisableComponents\VisableComponents.csproj", "{B0E42147-22BB-4B22-AB76-3C7DB2BF5353}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisableComponents", "VisableComponents\VisableComponents.csproj", "{B0E42147-22BB-4B22-AB76-3C7DB2BF5353}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataContracts", "DataContracts\DataContracts.csproj", "{F0B8E9FD-AAEF-4F1A-87E5-4361F22BA00A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DatabaseImplement", "DatabaseImplement\DatabaseImplement.csproj", "{AE492748-D76A-40D0-B3B0-FAE321F6DA91}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BusinessLogic", "BusinessLogic\BusinessLogic.csproj", "{5CA23F59-94F6-4A49-B114-F9B1A3D147CB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClientForms", "ClientForms\ClientForms.csproj", "{A1EE2F68-9359-4377-AFDB-3223F6DF5F40}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -27,6 +35,22 @@ Global
{B0E42147-22BB-4B22-AB76-3C7DB2BF5353}.Debug|Any CPU.Build.0 = Debug|Any CPU {B0E42147-22BB-4B22-AB76-3C7DB2BF5353}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0E42147-22BB-4B22-AB76-3C7DB2BF5353}.Release|Any CPU.ActiveCfg = Release|Any CPU {B0E42147-22BB-4B22-AB76-3C7DB2BF5353}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0E42147-22BB-4B22-AB76-3C7DB2BF5353}.Release|Any CPU.Build.0 = Release|Any CPU {B0E42147-22BB-4B22-AB76-3C7DB2BF5353}.Release|Any CPU.Build.0 = Release|Any CPU
{F0B8E9FD-AAEF-4F1A-87E5-4361F22BA00A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F0B8E9FD-AAEF-4F1A-87E5-4361F22BA00A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0B8E9FD-AAEF-4F1A-87E5-4361F22BA00A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0B8E9FD-AAEF-4F1A-87E5-4361F22BA00A}.Release|Any CPU.Build.0 = Release|Any CPU
{AE492748-D76A-40D0-B3B0-FAE321F6DA91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE492748-D76A-40D0-B3B0-FAE321F6DA91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE492748-D76A-40D0-B3B0-FAE321F6DA91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE492748-D76A-40D0-B3B0-FAE321F6DA91}.Release|Any CPU.Build.0 = Release|Any CPU
{5CA23F59-94F6-4A49-B114-F9B1A3D147CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5CA23F59-94F6-4A49-B114-F9B1A3D147CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5CA23F59-94F6-4A49-B114-F9B1A3D147CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5CA23F59-94F6-4A49-B114-F9B1A3D147CB}.Release|Any CPU.Build.0 = Release|Any CPU
{A1EE2F68-9359-4377-AFDB-3223F6DF5F40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A1EE2F68-9359-4377-AFDB-3223F6DF5F40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A1EE2F68-9359-4377-AFDB-3223F6DF5F40}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1EE2F68-9359-4377-AFDB-3223F6DF5F40}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -31,7 +31,6 @@ namespace TestForm
comboBox1.Items.AddRange(typeof(Sportsmen).GetProperties().Select(x => x.Name).ToArray()); comboBox1.Items.AddRange(typeof(Sportsmen).GetProperties().Select(x => x.Name).ToArray());
myTextBoxDate.DateMax = new DateTime(2019, 12, 1); myTextBoxDate.DateMax = new DateTime(2019, 12, 1);
myTextBoxDate.DateMin = new DateTime(2012, 12, 1); myTextBoxDate.DateMin = new DateTime(2012, 12, 1);
newCheckList1.ValueChanged += CustomEvent_Handler; newCheckList1.ValueChanged += CustomEvent_Handler;
myTextBoxDate.ValueChanged += CustomEvent_HandlerDate; myTextBoxDate.ValueChanged += CustomEvent_HandlerDate;
} }

View File

@ -17,7 +17,7 @@ namespace TestForm
{ {
ImageInfo info; ImageInfo info;
List<string> files; List<byte[]> files;
string[] names = { "Vova M", "Sasha A", "Dima D", "Danila L" }; string[] names = { "Vova M", "Sasha A", "Dima D", "Danila L" };
string[] sports = { "Run", "Swim", "Cycle", "Race", "Box" }; string[] sports = { "Run", "Swim", "Cycle", "Race", "Box" };
string[] cities = { "Moskow", "Samara", "Piter", "Kazan", "Kyrsk" }; string[] cities = { "Moskow", "Samara", "Piter", "Kazan", "Kyrsk" };
@ -28,7 +28,7 @@ namespace TestForm
{ {
InitializeComponent(); InitializeComponent();
info = new ImageInfo(); info = new ImageInfo();
files = new List<string>(); files = new List<byte[]>();
} }
private void buttonOne_Click(object sender, EventArgs e) private void buttonOne_Click(object sender, EventArgs e)
@ -57,7 +57,14 @@ namespace TestForm
if (openFileDialogPath.ShowDialog() == DialogResult.Cancel) if (openFileDialogPath.ShowDialog() == DialogResult.Cancel)
return; return;
string filename = openFileDialogPath.FileName; string filename = openFileDialogPath.FileName;
files.Add(filename); Image img = Image.FromFile(filename);
byte[] bA;
using (MemoryStream mStream = new MemoryStream())
{
img.Save(mStream, img.RawFormat);
bA = mStream.ToArray();
}
files.Add(bA);
labelTakenImages.Text +=" " + openFileDialogPath.FileName; labelTakenImages.Text +=" " + openFileDialogPath.FileName;
MessageBox.Show("Файл открыт"); MessageBox.Show("Файл открыт");
} }

View File

@ -47,8 +47,8 @@ namespace UnvisableComponents
foreach(var image in info.Files) foreach(var image in info.Files)
{ {
ExcelPicture excelImage = null; ExcelPicture excelImage = null;
Stream stream = new MemoryStream(image);
excelImage = worksheet.Drawings.AddPicture("image" + i, image); excelImage = worksheet.Drawings.AddPicture("image" + i, stream);
excelImage.SetPosition(posString, 0, posColumn, 0); excelImage.SetPosition(posString, 0, posColumn, 0);
excelImage.SetSize(100, 100); excelImage.SetSize(100, 100);
i++; i++;

View File

@ -10,10 +10,10 @@ namespace UnvisableComponents
{ {
private string path; private string path;
private string title; private string title;
private List<string> files; private List<byte[]> files;
public string Path { get { return path; } set { path = value; } } public string Path { get { return path; } set { path = value; } }
public string Title { get { return title; } set { title = 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 ImageInfo() { } public ImageInfo() { }
} }
} }

View File

@ -5,6 +5,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -16,7 +17,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="EPPlus" Version="6.2.9" /> <PackageReference Include="EPPlus" Version="6.2.10" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -50,6 +50,33 @@ namespace VisableComponents
checkedList.Items[checkedList.SelectedIndex] = value; checkedList.Items[checkedList.SelectedIndex] = value;
} }
} }
public int selectedValuesCount
{
get
{
if (checkedList.CheckedItems != null)
return checkedList.CheckedItems.Count;
return 0;
}
}
public void setValues(List<string> Values)
{
foreach(string Value in Values)
if(checkedList.Items.Contains(Value))
checkedList.SetItemCheckState(checkedList.Items.IndexOf(Value), CheckState.Checked);
}
public List<string> getSelectedItems()
{
List<string> values = new List<string>();
if (checkedList.CheckedItems != null)
{
foreach(var item in checkedList.CheckedItems)
values.Add(item.ToString());
return values;
}
return null;
}
private void checkedList_ItemCheck(object sender, ItemCheckEventArgs e) private void checkedList_ItemCheck(object sender, ItemCheckEventArgs e)
{ {

View File

@ -33,21 +33,24 @@
// //
// treeView // treeView
// //
this.treeView.Location = new System.Drawing.Point(3, 3); this.treeView.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeView.Location = new System.Drawing.Point(0, 0);
this.treeView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.treeView.Name = "treeView"; this.treeView.Name = "treeView";
this.treeView.Size = new System.Drawing.Size(421, 397); this.treeView.Size = new System.Drawing.Size(600, 600);
this.treeView.TabIndex = 0; this.treeView.TabIndex = 0;
// //
// MyTreeView // MyTreeView
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.BackColor = System.Drawing.SystemColors.ControlDark; this.BackColor = System.Drawing.SystemColors.ControlDark;
this.Controls.Add(this.treeView); this.Controls.Add(this.treeView);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.MinimumSize = new System.Drawing.Size(200, 200);
this.Name = "MyTreeView"; this.Name = "MyTreeView";
this.Size = new System.Drawing.Size(427, 403); this.Size = new System.Drawing.Size(600, 600);
this.ResumeLayout(false); this.ResumeLayout(false);
} }

View File

@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <root>
<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: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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">

View File

@ -1,10 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<Version>1.0.8</Version>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>