Продупление
This commit is contained in:
parent
b9e819f309
commit
d3bc885bc9
112
Laba3/MainForm.Designer.cs
generated
Normal file
112
Laba3/MainForm.Designer.cs
generated
Normal file
@ -0,0 +1,112 @@
|
||||
namespace Laba3
|
||||
{
|
||||
partial class MainForm
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
menuStrip1 = new MenuStrip();
|
||||
createToolStripMenuItem = new ToolStripMenuItem();
|
||||
updateToolStripMenuItem = new ToolStripMenuItem();
|
||||
outputTableResults = new Library15Gerimovich.OutputTableResults();
|
||||
deleteToolStripMenuItem = new ToolStripMenuItem();
|
||||
manufacturerToolStripMenuItem = new ToolStripMenuItem();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
menuStrip1.ImageScalingSize = new Size(20, 20);
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { createToolStripMenuItem, updateToolStripMenuItem, deleteToolStripMenuItem, manufacturerToolStripMenuItem });
|
||||
menuStrip1.Location = new Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Size = new Size(800, 28);
|
||||
menuStrip1.TabIndex = 0;
|
||||
menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// createToolStripMenuItem
|
||||
//
|
||||
createToolStripMenuItem.Name = "createToolStripMenuItem";
|
||||
createToolStripMenuItem.Size = new Size(66, 24);
|
||||
createToolStripMenuItem.Text = "Create";
|
||||
createToolStripMenuItem.Click += addToolStripMenuItem_Click;
|
||||
//
|
||||
// updateToolStripMenuItem
|
||||
//
|
||||
updateToolStripMenuItem.Name = "updateToolStripMenuItem";
|
||||
updateToolStripMenuItem.Size = new Size(72, 24);
|
||||
updateToolStripMenuItem.Text = "Update";
|
||||
updateToolStripMenuItem.Click += editToolStripMenuItem_Click;
|
||||
//
|
||||
// outputTableResults
|
||||
//
|
||||
outputTableResults.Location = new Point(12, 32);
|
||||
outputTableResults.Margin = new Padding(3, 4, 3, 4);
|
||||
outputTableResults.Name = "outputTableResults";
|
||||
outputTableResults.SelectedRow = -1;
|
||||
outputTableResults.Size = new Size(462, 306);
|
||||
outputTableResults.TabIndex = 1;
|
||||
//
|
||||
// deleteToolStripMenuItem
|
||||
//
|
||||
deleteToolStripMenuItem.Name = "deleteToolStripMenuItem";
|
||||
deleteToolStripMenuItem.Size = new Size(67, 24);
|
||||
deleteToolStripMenuItem.Text = "Delete";
|
||||
deleteToolStripMenuItem.Click += deleteToolStripMenuItem_Click;
|
||||
//
|
||||
// manufacturerToolStripMenuItem
|
||||
//
|
||||
manufacturerToolStripMenuItem.Name = "manufacturerToolStripMenuItem";
|
||||
manufacturerToolStripMenuItem.Size = new Size(111, 24);
|
||||
manufacturerToolStripMenuItem.Text = "Manufacturer";
|
||||
manufacturerToolStripMenuItem.Click += manufacturersToolStripMenuItem_Click;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(outputTableResults);
|
||||
Controls.Add(menuStrip1);
|
||||
MainMenuStrip = menuStrip1;
|
||||
Name = "MainForm";
|
||||
Text = "Form1";
|
||||
menuStrip1.ResumeLayout(false);
|
||||
menuStrip1.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private MenuStrip menuStrip1;
|
||||
private ToolStripMenuItem createToolStripMenuItem;
|
||||
private ToolStripMenuItem updateToolStripMenuItem;
|
||||
private Library15Gerimovich.OutputTableResults outputTableResults;
|
||||
private ToolStripMenuItem deleteToolStripMenuItem;
|
||||
private ToolStripMenuItem manufacturerToolStripMenuItem;
|
||||
}
|
||||
}
|
96
Laba3/MainForm.cs
Normal file
96
Laba3/MainForm.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using Data;
|
||||
using Data.Repositories;
|
||||
using View;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using Data.Models;
|
||||
|
||||
namespace Laba3
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
private readonly IProductRepository _productRepository;
|
||||
private readonly IManufacturerRepository _manufacturerRepository;
|
||||
|
||||
public MainForm(IProductRepository productRepository, IManufacturerRepository manufacturerRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_productRepository = productRepository;
|
||||
_manufacturerRepository = manufacturerRepository;
|
||||
InitializeOutputTableResults();
|
||||
LoadProducts();
|
||||
}
|
||||
|
||||
private void InitializeOutputTableResults()
|
||||
{
|
||||
outputTableResults.ConfigureColumns(new List<Library15Gerimovich.ColumnInfo>
|
||||
{
|
||||
new Library15Gerimovich.ColumnInfo("", 0, false, "Id"),
|
||||
new Library15Gerimovich.ColumnInfo("Name", 150, true, "Name"),
|
||||
new Library15Gerimovich.ColumnInfo("ManufacturerNameManufacturerName", 150, true, "ManufacturerName"),
|
||||
new Library15Gerimovich.ColumnInfo("DeliveryDate", 50, true, "DeliveryDate"),
|
||||
});
|
||||
/*TestObject TestOB = new TestObject(1, "Ôàìèëèÿ", "èìÿ", 10);
|
||||
TestObject TestOB2 = new TestObject(1, "Èâàíîâ", "Èâàí", 29);
|
||||
|
||||
outputTableResults.InsertValue(TestOB);
|
||||
outputTableResults.InsertValue(TestOB2);*/
|
||||
|
||||
}
|
||||
|
||||
private void LoadProducts()
|
||||
{
|
||||
var products = _productRepository.GetAllProducts();
|
||||
outputTableResults.ClearGrid();
|
||||
foreach (var product in products)
|
||||
{
|
||||
outputTableResults.InsertValue(product);
|
||||
}
|
||||
}
|
||||
|
||||
/*private void MainForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
outputTableResults.ContextMenuStrip = contextMenuStrip;
|
||||
}*/
|
||||
|
||||
private void addToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var productForm = new ProductForm(_productRepository, _manufacturerRepository);
|
||||
if (productForm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadProducts();
|
||||
}
|
||||
}
|
||||
|
||||
private void editToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
/*if (outputTableResults.SelectedItems.Count > 0)
|
||||
{*/
|
||||
|
||||
var selectedProductId = outputTableResults.GetSelectedObject<Product>().Id;
|
||||
var selectedProduct = _productRepository.GetProductById(selectedProductId);
|
||||
var productForm = new ProductForm(_productRepository, _manufacturerRepository, selectedProduct);
|
||||
if (productForm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadProducts();
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var selectedProductId = outputTableResults.GetSelectedObject<Product>().Id;
|
||||
if (MessageBox.Show("Are you sure you want to delete this product?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||||
{
|
||||
_productRepository.DeleteProduct(selectedProductId);
|
||||
LoadProducts();
|
||||
}
|
||||
}
|
||||
|
||||
private void manufacturersToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var manufacturerForm = new ManufacturerForm(_manufacturerRepository);
|
||||
manufacturerForm.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
123
Laba3/MainForm.resx
Normal file
123
Laba3/MainForm.resx
Normal file
@ -0,0 +1,123 @@
|
||||
<?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>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
39
Laba3/ManufacturerForm.Designer.cs
generated
Normal file
39
Laba3/ManufacturerForm.Designer.cs
generated
Normal file
@ -0,0 +1,39 @@
|
||||
namespace View
|
||||
{
|
||||
partial class ManufacturerForm
|
||||
{
|
||||
/// <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 = "ManufacturerForm";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
67
Laba3/ManufacturerForm.cs
Normal file
67
Laba3/ManufacturerForm.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using Data.Models;
|
||||
using Data.Repositories;
|
||||
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 View
|
||||
{
|
||||
public partial class ManufacturerForm : Form
|
||||
{
|
||||
private readonly IManufacturerRepository _manufacturerRepository;
|
||||
|
||||
public ManufacturerForm(IManufacturerRepository manufacturerRepository)
|
||||
{
|
||||
InitializeComponent();
|
||||
_manufacturerRepository = manufacturerRepository;
|
||||
LoadManufacturers();
|
||||
}
|
||||
|
||||
private void LoadManufacturers()
|
||||
{
|
||||
var manufacturers = _manufacturerRepository.GetAllManufacturers().ToList();
|
||||
dataGridView.DataSource = manufacturers;
|
||||
}
|
||||
|
||||
private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.RowIndex >= 0)
|
||||
{
|
||||
var manufacturer = dataGridView.Rows[e.RowIndex].DataBoundItem as Manufacturer;
|
||||
if (manufacturer != null)
|
||||
{
|
||||
_manufacturerRepository.UpdateManufacturer(manufacturer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void dataGridView_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
|
||||
{
|
||||
var manufacturer = e.Row.DataBoundItem as Manufacturer;
|
||||
if (manufacturer != null)
|
||||
{
|
||||
if (MessageBox.Show("Are you sure you want to delete this manufacturer?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||||
{
|
||||
_manufacturerRepository.DeleteManufacturer(manufacturer.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void dataGridView_UserAddedRow(object sender, DataGridViewRowEventArgs e)
|
||||
{
|
||||
var manufacturer = new Manufacturer { Name = "" };
|
||||
_manufacturerRepository.AddManufacturer(manufacturer);
|
||||
LoadManufacturers();
|
||||
}
|
||||
}
|
||||
}
|
120
Laba3/ManufacturerForm.resx
Normal file
120
Laba3/ManufacturerForm.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?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>
|
69
Laba3/ProductForm.Designer.cs
generated
Normal file
69
Laba3/ProductForm.Designer.cs
generated
Normal file
@ -0,0 +1,69 @@
|
||||
namespace Laba3
|
||||
{
|
||||
partial class ProductForm
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
dtpDeliveryDate = new WinFormsLibrary1.DateInputControl();
|
||||
comboBoxUserControl1 = new WinFormsLibrary1.ComboBoxUserControl();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dtpDeliveryDate
|
||||
//
|
||||
dtpDeliveryDate.Location = new Point(13, 65);
|
||||
dtpDeliveryDate.Margin = new Padding(4, 5, 4, 5);
|
||||
dtpDeliveryDate.Name = "dtpDeliveryDate";
|
||||
dtpDeliveryDate.Size = new Size(186, 110);
|
||||
dtpDeliveryDate.TabIndex = 0;
|
||||
//
|
||||
// comboBoxUserControl1
|
||||
//
|
||||
comboBoxUserControl1.Location = new Point(13, 115);
|
||||
comboBoxUserControl1.Margin = new Padding(4, 5, 4, 5);
|
||||
comboBoxUserControl1.Name = "comboBoxUserControl1";
|
||||
comboBoxUserControl1.SelectedValue = "";
|
||||
comboBoxUserControl1.Size = new Size(201, 40);
|
||||
comboBoxUserControl1.TabIndex = 1;
|
||||
//
|
||||
// ProductForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(comboBoxUserControl1);
|
||||
Controls.Add(dtpDeliveryDate);
|
||||
Name = "ProductForm";
|
||||
Text = "ProductForm";
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private WinFormsLibrary1.DateInputControl dtpDeliveryDate;
|
||||
private WinFormsLibrary1.ComboBoxUserControl comboBoxUserControl1;
|
||||
}
|
||||
}
|
96
Laba3/ProductForm.cs
Normal file
96
Laba3/ProductForm.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using Data;
|
||||
using Data.Models;
|
||||
using Data.Repositories;
|
||||
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 Laba3
|
||||
{
|
||||
public partial class ProductForm : Form
|
||||
{
|
||||
private readonly IProductRepository _productRepository;
|
||||
private readonly IManufacturerRepository _manufacturerRepository;
|
||||
private Product _product;
|
||||
private bool _isNewProduct;
|
||||
|
||||
public ProductForm(IProductRepository productRepository, IManufacturerRepository manufacturerRepository, Product product = null)
|
||||
{
|
||||
InitializeComponent();
|
||||
_productRepository = productRepository;
|
||||
_manufacturerRepository = manufacturerRepository;
|
||||
_product = product;
|
||||
_isNewProduct = product == null;
|
||||
|
||||
if (!_isNewProduct)
|
||||
{
|
||||
txtName.Text = _product.Name;
|
||||
cmbManufacturer.SelectedItem = _product.ManufacturerName;
|
||||
dtpDeliveryDate.Value = _product.DeliveryDate;
|
||||
if (_product.Image != null)
|
||||
{
|
||||
using (var ms = new MemoryStream(_product.Image))
|
||||
{
|
||||
pbImage.Image = Image.FromStream(ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnBrowse_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (var openFileDialog = new OpenFileDialog())
|
||||
{
|
||||
openFileDialog.Filter = "Image Files|*.jpg;*.jpeg;*.png;*.bmp";
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
pbImage.Image = Image.FromFile(openFileDialog.FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(txtName.Text))
|
||||
{
|
||||
MessageBox.Show("Name is required.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_isNewProduct)
|
||||
{
|
||||
_product = new Product();
|
||||
_productRepository.AddProduct(_product);
|
||||
}
|
||||
|
||||
_product.Name = txtName.Text;
|
||||
_product.ManufacturerName = cmbManufacturer.SelectedItem.ToString();
|
||||
_product.DeliveryDate = dtpDeliveryDate.Value;
|
||||
|
||||
if (pbImage.Image != null)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
pbImage.Image.Save(ms, pbImage.Image.RawFormat);
|
||||
_product.Image = ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
_productRepository.UpdateProduct(_product);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ProductForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
var manufacturers = _manufacturerRepository.GetAllManufacturers().Select(m => m.Name).ToList();
|
||||
cmbManufacturer.DataSource = manufacturers;
|
||||
}
|
||||
}
|
||||
}
|
120
Laba3/ProductForm.resx
Normal file
120
Laba3/ProductForm.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?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>
|
17
Laba3/Program.cs
Normal file
17
Laba3/Program.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace Laba3
|
||||
{
|
||||
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 MainForm());
|
||||
}
|
||||
}
|
||||
}
|
27
Laba3/View.csproj
Normal file
27
Laba3/View.csproj
Normal file
@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Components" Version="1.0.0" />
|
||||
<PackageReference Include="Library15Gerimovich" Version="1.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Models\Data.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
5
Laba3/appsettings.json
Normal file
5
Laba3/appsettings.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Host=localhost;Port=5432;Database=kop;Username=postgres;Password=postgres"
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -5,9 +5,9 @@ VisualStudioVersion = 17.10.35013.160
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library14Petrushin", "Library14Petrushin.csproj", "{64A09BF4-7D97-49DE-8AB8-E9C23B75A62D}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ExecForm1", "..\ExecForm\ExecForm1.csproj", "{6C3A0E39-ED7B-41D8-9253-023B1D35C935}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "View", "..\Laba3\View.csproj", "{F342448F-F458-45A7-B335-EAD594D6B7A4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExexForm2", "..\ExexForm2\ExexForm2.csproj", "{80D961BA-24BC-4B3E-A578-BAA90C6EED01}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data", "..\Models\Data.csproj", "{DC70937E-903F-4BAA-A774-80D01EC5B75A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -19,14 +19,14 @@ Global
|
||||
{64A09BF4-7D97-49DE-8AB8-E9C23B75A62D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{64A09BF4-7D97-49DE-8AB8-E9C23B75A62D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{64A09BF4-7D97-49DE-8AB8-E9C23B75A62D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6C3A0E39-ED7B-41D8-9253-023B1D35C935}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6C3A0E39-ED7B-41D8-9253-023B1D35C935}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6C3A0E39-ED7B-41D8-9253-023B1D35C935}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6C3A0E39-ED7B-41D8-9253-023B1D35C935}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{80D961BA-24BC-4B3E-A578-BAA90C6EED01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{80D961BA-24BC-4B3E-A578-BAA90C6EED01}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{80D961BA-24BC-4B3E-A578-BAA90C6EED01}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{80D961BA-24BC-4B3E-A578-BAA90C6EED01}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F342448F-F458-45A7-B335-EAD594D6B7A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F342448F-F458-45A7-B335-EAD594D6B7A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F342448F-F458-45A7-B335-EAD594D6B7A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F342448F-F458-45A7-B335-EAD594D6B7A4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DC70937E-903F-4BAA-A774-80D01EC5B75A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DC70937E-903F-4BAA-A774-80D01EC5B75A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DC70937E-903F-4BAA-A774-80D01EC5B75A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DC70937E-903F-4BAA-A774-80D01EC5B75A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
21
Models/ApplicationDbContext.cs
Normal file
21
Models/ApplicationDbContext.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using Data.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
public class ApplicationDbContext : DbContext
|
||||
{
|
||||
public DbSet<Product> Products { get; set; }
|
||||
public DbSet<Manufacturer> Manufacturers { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=cop;Username=postgres;Password=postgres");
|
||||
}
|
||||
}
|
||||
}
|
19
Models/Data.csproj
Normal file
19
Models/Data.csproj
Normal file
@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
78
Models/Migrations/20241029070533_Init.Designer.cs
generated
Normal file
78
Models/Migrations/20241029070533_Init.Designer.cs
generated
Normal file
@ -0,0 +1,78 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20241029070533_Init")]
|
||||
partial class Init
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Models.Manufacturer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Manufacturers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Models.Product", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("DeliveryDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<byte[]>("Image")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea");
|
||||
|
||||
b.Property<string>("ManufacturerName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
55
Models/Migrations/20241029070533_Init.cs
Normal file
55
Models/Migrations/20241029070533_Init.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Init : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Manufacturers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Manufacturers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Products",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||
Image = table.Column<byte[]>(type: "bytea", nullable: false),
|
||||
ManufacturerName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||
DeliveryDate = table.Column<DateTime>(type: "date", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Products", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Manufacturers");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Products");
|
||||
}
|
||||
}
|
||||
}
|
75
Models/Migrations/ApplicationDbContextModelSnapshot.cs
Normal file
75
Models/Migrations/ApplicationDbContextModelSnapshot.cs
Normal file
@ -0,0 +1,75 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
partial class ApplicationDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Models.Manufacturer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Manufacturers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Models.Product", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("DeliveryDate")
|
||||
.HasColumnType("date");
|
||||
|
||||
b.Property<byte[]>("Image")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea");
|
||||
|
||||
b.Property<string>("ManufacturerName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
19
Models/Models/Manufacturer.cs
Normal file
19
Models/Models/Manufacturer.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Data.Models
|
||||
{
|
||||
public class Manufacturer
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(100)]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
30
Models/Models/Product.cs
Normal file
30
Models/Models/Product.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Data.Models
|
||||
{
|
||||
public class Product
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(100)]
|
||||
public string Name { get; set; }
|
||||
|
||||
public byte[] Image { get; set; }
|
||||
|
||||
[Required]
|
||||
[MaxLength(100)]
|
||||
public string ManufacturerName { get; set; }
|
||||
|
||||
[Required]
|
||||
[Column(TypeName = "date")]
|
||||
public DateTime DeliveryDate { get; set; }
|
||||
}
|
||||
}
|
18
Models/Repositories/IManufacturerRepository.cs
Normal file
18
Models/Repositories/IManufacturerRepository.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using Data.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Data.Repositories
|
||||
{
|
||||
public interface IManufacturerRepository
|
||||
{
|
||||
IEnumerable<Manufacturer> GetAllManufacturers();
|
||||
Manufacturer GetManufacturerById(int id);
|
||||
void AddManufacturer(Manufacturer manufacturer);
|
||||
void UpdateManufacturer(Manufacturer manufacturer);
|
||||
void DeleteManufacturer(int id);
|
||||
}
|
||||
}
|
18
Models/Repositories/IProductRepository.cs
Normal file
18
Models/Repositories/IProductRepository.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using Data.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Data.Repositories
|
||||
{
|
||||
public interface IProductRepository
|
||||
{
|
||||
IEnumerable<Product> GetAllProducts();
|
||||
Product GetProductById(int id);
|
||||
void AddProduct(Product product);
|
||||
void UpdateProduct(Product product);
|
||||
void DeleteProduct(int id);
|
||||
}
|
||||
}
|
51
Models/Repositories/ManufacturerRepository.cs
Normal file
51
Models/Repositories/ManufacturerRepository.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using Data.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Data.Repositories
|
||||
{
|
||||
public class ManufacturerRepository : IManufacturerRepository
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public ManufacturerRepository(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public IEnumerable<Manufacturer> GetAllManufacturers()
|
||||
{
|
||||
return _context.Manufacturers.ToList();
|
||||
}
|
||||
|
||||
public Manufacturer GetManufacturerById(int id)
|
||||
{
|
||||
return _context.Manufacturers.Find(id);
|
||||
}
|
||||
|
||||
public void AddManufacturer(Manufacturer manufacturer)
|
||||
{
|
||||
_context.Manufacturers.Add(manufacturer);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
public void UpdateManufacturer(Manufacturer manufacturer)
|
||||
{
|
||||
_context.Manufacturers.Update(manufacturer);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
public void DeleteManufacturer(int id)
|
||||
{
|
||||
var manufacturer = _context.Manufacturers.Find(id);
|
||||
if (manufacturer != null)
|
||||
{
|
||||
_context.Manufacturers.Remove(manufacturer);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
51
Models/Repositories/ProductRepository.cs
Normal file
51
Models/Repositories/ProductRepository.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using Data.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Data.Repositories
|
||||
{
|
||||
public class ProductRepository : IProductRepository
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public ProductRepository(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public IEnumerable<Product> GetAllProducts()
|
||||
{
|
||||
return _context.Products.ToList();
|
||||
}
|
||||
|
||||
public Product GetProductById(int id)
|
||||
{
|
||||
return _context.Products.Find(id);
|
||||
}
|
||||
|
||||
public void AddProduct(Product product)
|
||||
{
|
||||
_context.Products.Add(product);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
public void UpdateProduct(Product product)
|
||||
{
|
||||
_context.Products.Update(product);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
public void DeleteProduct(int id)
|
||||
{
|
||||
var product = _context.Products.Find(id);
|
||||
if (product != null)
|
||||
{
|
||||
_context.Products.Remove(product);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user