Доделал

This commit is contained in:
RozhVan 2024-11-15 18:27:06 +04:00
parent 812b5f5e22
commit e6926c9455
31 changed files with 2152 additions and 69 deletions

View File

@ -0,0 +1,14 @@
namespace GasStation.Entities.Enums;
public enum ProductType
{
None = 0 ,
Gas92 = 1 ,
Gas95 = 2 ,
Diesel = 3,
Oil = 4
}

View File

@ -6,14 +6,20 @@ public class Product
{ {
public int Id { get; private set; } public int Id { get; private set; }
public Gasmen Gasman { get; private set; } public int Cost { get; private set; }
public static Product CreateProduct(int id, Gasmen gasman) public Gasmen Gasmen { get; private set; }
public ProductType ProductType { get; private set; }
public static Product CreateProduct(int id, int cost ,Gasmen gasmen, ProductType productType)
{ {
return new Product return new Product
{ {
Id = id, Id = id,
Gasman = gasman Cost = cost,
Gasmen = gasmen,
ProductType = productType
}; };
} }
} }

View File

@ -30,13 +30,13 @@
{ {
menuStrip1 = new MenuStrip(); menuStrip1 = new MenuStrip();
справочникиToolStripMenuItem = new ToolStripMenuItem(); справочникиToolStripMenuItem = new ToolStripMenuItem();
GasmanToolStripMenuItem = new ToolStripMenuItem();
SupplierToolStripMenuItem = new ToolStripMenuItem();
ProductToolStripMenuItem = new ToolStripMenuItem();
операцииToolStripMenuItem = new ToolStripMenuItem(); операцииToolStripMenuItem = new ToolStripMenuItem();
SupplyToolStripMenuItem = new ToolStripMenuItem();
SellingToolStripMenuItem = new ToolStripMenuItem();
отчётыToolStripMenuItem = new ToolStripMenuItem(); отчётыToolStripMenuItem = new ToolStripMenuItem();
заправщикToolStripMenuItem = new ToolStripMenuItem();
поставщикToolStripMenuItem = new ToolStripMenuItem();
товарToolStripMenuItem = new ToolStripMenuItem();
поставкаToolStripMenuItem = new ToolStripMenuItem();
продажаToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.SuspendLayout(); menuStrip1.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
@ -51,54 +51,59 @@
// //
// справочникиToolStripMenuItem // справочникиToolStripMenuItem
// //
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заправщикToolStripMenuItem, поставщикToolStripMenuItem, товарToolStripMenuItem }); справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { GasmanToolStripMenuItem, SupplierToolStripMenuItem, ProductToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(94, 20); справочникиToolStripMenuItem.Size = new Size(94, 20);
справочникиToolStripMenuItem.Text = "Справочники"; справочникиToolStripMenuItem.Text = "Справочники";
// //
// GasmanToolStripMenuItem
//
GasmanToolStripMenuItem.Name = "GasmanToolStripMenuItem";
GasmanToolStripMenuItem.Size = new Size(180, 22);
GasmanToolStripMenuItem.Text = "Заправщик";
GasmanToolStripMenuItem.Click += GasmanToolStripMenuItem_Click;
//
// SupplierToolStripMenuItem
//
SupplierToolStripMenuItem.Name = "SupplierToolStripMenuItem";
SupplierToolStripMenuItem.Size = new Size(180, 22);
SupplierToolStripMenuItem.Text = "Поставщик";
SupplierToolStripMenuItem.Click += SupplierToolStripMenuItem_Click;
//
// ProductToolStripMenuItem
//
ProductToolStripMenuItem.Name = "ProductToolStripMenuItem";
ProductToolStripMenuItem.Size = new Size(180, 22);
ProductToolStripMenuItem.Text = "Товар";
ProductToolStripMenuItem.Click += ProductToolStripMenuItem_Click;
//
// операцииToolStripMenuItem // операцииToolStripMenuItem
// //
операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { поставкаToolStripMenuItem, продажаToolStripMenuItem }); операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SupplyToolStripMenuItem, SellingToolStripMenuItem });
операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; операцииToolStripMenuItem.Name = "операцииToolStripMenuItem";
операцииToolStripMenuItem.Size = new Size(75, 20); операцииToolStripMenuItem.Size = new Size(75, 20);
операцииToolStripMenuItem.Text = "Операции"; операцииToolStripMenuItem.Text = "Операции";
// //
// SupplyToolStripMenuItem
//
SupplyToolStripMenuItem.Name = "SupplyToolStripMenuItem";
SupplyToolStripMenuItem.Size = new Size(180, 22);
SupplyToolStripMenuItem.Text = "Поставка";
SupplyToolStripMenuItem.Click += SupplyToolStripMenuItem_Click;
//
// SellingToolStripMenuItem
//
SellingToolStripMenuItem.Name = "SellingToolStripMenuItem";
SellingToolStripMenuItem.Size = new Size(180, 22);
SellingToolStripMenuItem.Text = "Продажа";
SellingToolStripMenuItem.Click += SellingToolStripMenuItem_Click;
//
// отчётыToolStripMenuItem // отчётыToolStripMenuItem
// //
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
отчётыToolStripMenuItem.Size = new Size(60, 20); отчётыToolStripMenuItem.Size = new Size(60, 20);
отчётыToolStripMenuItem.Text = "Отчёты"; отчётыToolStripMenuItem.Text = "Отчёты";
// //
// заправщикToolStripMenuItem
//
заправщикToolStripMenuItem.Name = аправщикToolStripMenuItem";
заправщикToolStripMenuItem.Size = new Size(180, 22);
заправщикToolStripMenuItem.Text = "Заправщик";
//
// поставщикToolStripMenuItem
//
поставщикToolStripMenuItem.Name = "поставщикToolStripMenuItem";
поставщикToolStripMenuItem.Size = new Size(180, 22);
поставщикToolStripMenuItem.Text = "Поставщик";
//
// товарToolStripMenuItem
//
товарToolStripMenuItem.Name = оварToolStripMenuItem";
товарToolStripMenuItem.Size = new Size(180, 22);
товарToolStripMenuItem.Text = "Товар";
//
// поставкаToolStripMenuItem
//
поставкаToolStripMenuItem.Name = "поставкаToolStripMenuItem";
поставкаToolStripMenuItem.Size = new Size(180, 22);
поставкаToolStripMenuItem.Text = "Поставка";
//
// продажаToolStripMenuItem
//
продажаToolStripMenuItem.Name = "продажаToolStripMenuItem";
продажаToolStripMenuItem.Size = new Size(180, 22);
продажаToolStripMenuItem.Text = "Продажа";
//
// FormGasStation // FormGasStation
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
@ -123,10 +128,10 @@
private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem операцииToolStripMenuItem; private ToolStripMenuItem операцииToolStripMenuItem;
private ToolStripMenuItem отчётыToolStripMenuItem; private ToolStripMenuItem отчётыToolStripMenuItem;
private ToolStripMenuItem заправщикToolStripMenuItem; private ToolStripMenuItem GasmanToolStripMenuItem;
private ToolStripMenuItem поставщикToolStripMenuItem; private ToolStripMenuItem SupplierToolStripMenuItem;
private ToolStripMenuItem товарToolStripMenuItem; private ToolStripMenuItem ProductToolStripMenuItem;
private ToolStripMenuItem поставкаToolStripMenuItem; private ToolStripMenuItem SupplyToolStripMenuItem;
private ToolStripMenuItem продажаToolStripMenuItem; private ToolStripMenuItem SellingToolStripMenuItem;
} }
} }

View File

@ -1,10 +1,77 @@
using GasStation.Forms;
using Unity;
namespace GasStation namespace GasStation
{ {
public partial class FormGasStation : System.Windows.Forms.Form public partial class FormGasStation : System.Windows.Forms.Form
{ {
public FormGasStation() private readonly IUnityContainer _container;
public FormGasStation(IUnityContainer container)
{ {
InitializeComponent(); InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
}
private void GasmanToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormGasmen>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè äîáàâëåíèè", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void SupplierToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormSuppliers>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè äîáàâëåíèè", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ProductToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormProducts>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè äîáàâëåíèè", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void SupplyToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormSupplies>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè äîáàâëåíèè", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void SellingToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormSellings>().ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Îøèáêà ïðè äîáàâëåíèè", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} }
} }
} }

View File

@ -48,11 +48,11 @@
// labelNumber // labelNumber
// //
labelNumber.AutoSize = true; labelNumber.AutoSize = true;
labelNumber.Location = new Point(52, 94); labelNumber.Location = new Point(34, 89);
labelNumber.Name = "labelNumber"; labelNumber.Name = "labelNumber";
labelNumber.Size = new Size(45, 15); labelNumber.Size = new Size(101, 15);
labelNumber.TabIndex = 1; labelNumber.TabIndex = 1;
labelNumber.Text = "Номер"; labelNumber.Text = "Номер телефона";
// //
// textBoxName // textBoxName
// //

View File

@ -24,7 +24,7 @@ namespace GasStation.Forms
try try
{ {
var gasman = _gasmanRepository.ReadGasmanByID(value); var gasman = _gasmanRepository.ReadGasmanByID(value);
if (gasman != null) if (gasman == null)
{ {
throw new InvalidDataException(nameof(gasman)); throw new InvalidDataException(nameof(gasman));
} }

146
GasStation/Forms/FormProduct.Designer.cs generated Normal file
View File

@ -0,0 +1,146 @@
namespace GasStation.Forms
{
partial class FormProduct
{
/// <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()
{
label1 = new Label();
label2 = new Label();
label3 = new Label();
numericUpDownCost = new NumericUpDown();
comboBoxProduct = new ComboBox();
checkedListBoxGasman = new CheckedListBox();
buttonSave = new Button();
buttonCancel = new Button();
((System.ComponentModel.ISupportInitialize)numericUpDownCost).BeginInit();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(43, 29);
label1.Name = "label1";
label1.Size = new Size(70, 15);
label1.TabIndex = 0;
label1.Text = "Заправщик";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(43, 132);
label2.Name = "label2";
label2.Size = new Size(39, 15);
label2.TabIndex = 1;
label2.Text = "Товар";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(47, 202);
label3.Name = "label3";
label3.Size = new Size(67, 15);
label3.TabIndex = 2;
label3.Text = "Стоимость";
//
// numericUpDownCost
//
numericUpDownCost.Location = new Point(193, 202);
numericUpDownCost.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
numericUpDownCost.Name = "numericUpDownCost";
numericUpDownCost.Size = new Size(156, 23);
numericUpDownCost.TabIndex = 3;
numericUpDownCost.Value = new decimal(new int[] { 1, 0, 0, 0 });
//
// comboBoxProduct
//
comboBoxProduct.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxProduct.FormattingEnabled = true;
comboBoxProduct.Location = new Point(194, 132);
comboBoxProduct.Name = "comboBoxProduct";
comboBoxProduct.Size = new Size(155, 23);
comboBoxProduct.TabIndex = 4;
//
// checkedListBoxGasman
//
checkedListBoxGasman.FormattingEnabled = true;
checkedListBoxGasman.Location = new Point(194, 29);
checkedListBoxGasman.Name = "checkedListBoxGasman";
checkedListBoxGasman.Size = new Size(155, 76);
checkedListBoxGasman.TabIndex = 5;
//
// buttonSave
//
buttonSave.Location = new Point(47, 269);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(75, 23);
buttonSave.TabIndex = 6;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(269, 269);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(80, 23);
buttonCancel.TabIndex = 7;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormProduct
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(401, 314);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(checkedListBoxGasman);
Controls.Add(comboBoxProduct);
Controls.Add(numericUpDownCost);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormProduct";
Text = "Товар";
((System.ComponentModel.ISupportInitialize)numericUpDownCost).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private Label label3;
private NumericUpDown numericUpDownCost;
private ComboBox comboBoxProduct;
private CheckedListBox checkedListBoxGasman;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,94 @@
using GasStation.Entities.Enums;
using GasStation.Repositories;
using GasStation.Entities;
namespace GasStation.Forms
{
public partial class FormProduct : Form
{
private readonly IProductRepository _productRepository;
private int? _productId;
public FormProduct(IProductRepository productRepository)
{
InitializeComponent();
_productRepository = productRepository ??
throw new ArgumentNullException(nameof(productRepository));
foreach (var elem in Enum.GetValues(typeof(Gasmen)))
{
checkedListBoxGasman.Items.Add(elem);
}
}
public int ID
{
set
{
try
{
var product = _productRepository.ReadProductByID(value);
if (product == null)
{
throw new InvalidDataException(nameof(product));
}
foreach(Gasmen elem in Enum.GetValues(typeof(Gasmen)))
{
if ((elem & product.Gasmen) != 0)
{
checkedListBoxGasman.SetItemChecked(checkedListBoxGasman.Items.IndexOf(elem), true);
}
}
checkedListBoxGasman.SelectedItem = product.Gasmen;
comboBoxProduct.SelectedItem = product.ProductType;
_productId = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (checkedListBoxGasman.CheckedItems.Count == 0)
{
throw new Exception("Имеются незаполненые поля");
}
if (_productId.HasValue)
{
_productRepository.UpdateProduct(CreateProduct(_productId.Value));
}
else
{
_productRepository.CreateProduct(CreateProduct(0));
}
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private Product CreateProduct(int id)
{
Gasmen gasmen = Gasmen.None;
foreach (var elem in checkedListBoxGasman.CheckedItems)
{
gasmen |= (Gasmen)elem;
}
return Product.CreateProduct(id, Convert.ToInt32(numericUpDownCost.Value), gasmen, (ProductType)comboBoxProduct.SelectedItem!);
}
}
}

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

122
GasStation/Forms/FormProducts.Designer.cs generated Normal file
View File

@ -0,0 +1,122 @@
namespace GasStation.Forms
{
partial class FormProducts
{
/// <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()
{
panel1 = new Panel();
buttonUpd = new Button();
buttonDel = new Button();
buttonAdd = new Button();
dataGridViewData = new DataGridView();
panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
SuspendLayout();
//
// panel1
//
panel1.Controls.Add(buttonUpd);
panel1.Controls.Add(buttonDel);
panel1.Controls.Add(buttonAdd);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(657, 0);
panel1.Name = "panel1";
panel1.Size = new Size(143, 450);
panel1.TabIndex = 1;
//
// buttonUpd
//
buttonUpd.Location = new Point(35, 343);
buttonUpd.Name = "buttonUpd";
buttonUpd.Size = new Size(75, 69);
buttonUpd.TabIndex = 3;
buttonUpd.Text = "Редактировать";
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// buttonDel
//
buttonDel.Location = new Point(33, 188);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(77, 73);
buttonDel.TabIndex = 2;
buttonDel.Text = "Удалить";
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonAdd
//
buttonAdd.Location = new Point(32, 30);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(75, 73);
buttonAdd.TabIndex = 1;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridViewData
//
dataGridViewData.AllowUserToAddRows = false;
dataGridViewData.AllowUserToDeleteRows = false;
dataGridViewData.AllowUserToResizeColumns = false;
dataGridViewData.AllowUserToResizeRows = false;
dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewData.Dock = DockStyle.Fill;
dataGridViewData.Location = new Point(0, 0);
dataGridViewData.MultiSelect = false;
dataGridViewData.Name = "dataGridViewData";
dataGridViewData.ReadOnly = true;
dataGridViewData.RowHeadersVisible = false;
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewData.Size = new Size(657, 450);
dataGridViewData.TabIndex = 2;
//
// FormProducts
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(dataGridViewData);
Controls.Add(panel1);
Name = "FormProducts";
Text = "Товары";
Load += FormProducts_Load;
panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel1;
private Button buttonUpd;
private Button buttonDel;
private Button buttonAdd;
private DataGridView dataGridViewData;
}
}

View File

@ -0,0 +1,104 @@
using GasStation.Repositories;
using Unity;
namespace GasStation.Forms
{
public partial class FormProducts : Form
{
private readonly IUnityContainer _container;
private readonly IProductRepository _productRepository;
public FormProducts(IUnityContainer container, IProductRepository productRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_productRepository = productRepository ??
throw new ArgumentNullException(nameof(productRepository));
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormProduct>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIDFromSelectedRow(out var findID))
{
return;
}
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
try
{
_productRepository.DeleteProduct(findID);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка удаления", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (!TryGetIDFromSelectedRow(out var findID))
{
return;
}
try
{
var form = _container.Resolve<FormProduct>();
form.ID = findID;
form.ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private bool TryGetIDFromSelectedRow(out int id)
{
id = 0;
if (dataGridViewData.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["ID"].Value);
return true;
}
private void FormProducts_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridViewData.DataSource = _productRepository.ReadProduct();
}
}

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

147
GasStation/Forms/FormSelling.Designer.cs generated Normal file
View File

@ -0,0 +1,147 @@
namespace GasStation.Forms
{
partial class FormSelling
{
/// <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()
{
label1 = new Label();
label2 = new Label();
numericUpDownCount = new NumericUpDown();
label3 = new Label();
comboBoxGasman = new ComboBox();
comboBoxProduct = new ComboBox();
buttonSave = new Button();
buttonCancel = new Button();
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(47, 35);
label1.Name = "label1";
label1.Size = new Size(70, 15);
label1.TabIndex = 0;
label1.Text = "Заправщик";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(47, 98);
label2.Name = "label2";
label2.Size = new Size(39, 15);
label2.TabIndex = 1;
label2.Text = "Товар";
//
// numericUpDownCount
//
numericUpDownCount.Location = new Point(149, 164);
numericUpDownCount.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
numericUpDownCount.Name = "numericUpDownCount";
numericUpDownCount.Size = new Size(120, 23);
numericUpDownCount.TabIndex = 2;
numericUpDownCount.Value = new decimal(new int[] { 1, 0, 0, 0 });
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(47, 172);
label3.Name = "label3";
label3.Size = new Size(46, 15);
label3.TabIndex = 3;
label3.Text = "Кол-во";
//
// comboBoxGasman
//
comboBoxGasman.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxGasman.FormattingEnabled = true;
comboBoxGasman.Location = new Point(147, 27);
comboBoxGasman.Name = "comboBoxGasman";
comboBoxGasman.Size = new Size(121, 23);
comboBoxGasman.TabIndex = 4;
//
// comboBoxProduct
//
comboBoxProduct.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxProduct.FormattingEnabled = true;
comboBoxProduct.Location = new Point(148, 90);
comboBoxProduct.Name = "comboBoxProduct";
comboBoxProduct.Size = new Size(121, 23);
comboBoxProduct.TabIndex = 5;
//
// buttonSave
//
buttonSave.Location = new Point(47, 238);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(75, 23);
buttonSave.TabIndex = 6;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(194, 238);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 23);
buttonCancel.TabIndex = 7;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormSelling
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(336, 297);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(comboBoxProduct);
Controls.Add(comboBoxGasman);
Controls.Add(label3);
Controls.Add(numericUpDownCount);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormSelling";
Text = "Продажа";
((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label label1;
private Label label2;
private NumericUpDown numericUpDownCount;
private Label label3;
private ComboBox comboBoxGasman;
private ComboBox comboBoxProduct;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,51 @@
using GasStation.Entities;
using GasStation.Repositories;
using GasStation.Repositories.Implementations;
namespace GasStation.Forms
{
public partial class FormSelling : Form
{
private readonly ISellingRepository _sellingRepository;
public FormSelling(ISellingRepository sellingRepository, IGasmanRepository gasmanRepository, IProductRepository productRepository)
{
InitializeComponent();
_sellingRepository = sellingRepository ??
throw new ArgumentNullException(nameof(sellingRepository));
comboBoxGasman.DataSource = gasmanRepository.ReadGasman();
comboBoxGasman.DisplayMember = "GasmanName";
comboBoxGasman.ValueMember = "ID";
comboBoxProduct.DataSource = productRepository.ReadProduct();
comboBoxProduct.DisplayMember = "ProductName";
comboBoxProduct.ValueMember = "ID";
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (comboBoxGasman.SelectedIndex < 0 ||
comboBoxProduct.SelectedIndex < 0)
{
throw new Exception("Имеются незаполненые поля");
}
_sellingRepository.CreateSelling(Selling.CreateSelling(0, (int)comboBoxGasman.SelectedValue!,
(int)comboBoxProduct.SelectedValue!, Convert.ToInt32(numericUpDownCount.Value)));
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
}
}

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

View File

@ -0,0 +1,96 @@
namespace GasStation.Forms
{
partial class FormSellings
{
/// <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()
{
panel1 = new Panel();
buttonAdd = new Button();
dataGridViewData = new DataGridView();
panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
SuspendLayout();
//
// panel1
//
panel1.Controls.Add(buttonAdd);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(657, 0);
panel1.Name = "panel1";
panel1.Size = new Size(143, 450);
panel1.TabIndex = 2;
//
// buttonAdd
//
buttonAdd.Location = new Point(35, 166);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(75, 73);
buttonAdd.TabIndex = 1;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridViewData
//
dataGridViewData.AllowUserToAddRows = false;
dataGridViewData.AllowUserToDeleteRows = false;
dataGridViewData.AllowUserToResizeColumns = false;
dataGridViewData.AllowUserToResizeRows = false;
dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewData.Dock = DockStyle.Fill;
dataGridViewData.Location = new Point(0, 0);
dataGridViewData.MultiSelect = false;
dataGridViewData.Name = "dataGridViewData";
dataGridViewData.ReadOnly = true;
dataGridViewData.RowHeadersVisible = false;
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewData.Size = new Size(657, 450);
dataGridViewData.TabIndex = 3;
//
// FormSellings
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(dataGridViewData);
Controls.Add(panel1);
Name = "FormSellings";
Text = "Продажи";
Load += FormSellings_Load;
panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel1;
private Button buttonAdd;
private DataGridView dataGridViewData;
}
}

View File

@ -0,0 +1,49 @@
using GasStation.Repositories;
using Unity;
namespace GasStation.Forms
{
public partial class FormSellings : Form
{
private readonly IUnityContainer _container;
private readonly ISellingRepository _sellingRepository;
public FormSellings(IUnityContainer container, ISellingRepository sellingRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_sellingRepository = sellingRepository ??
throw new ArgumentNullException(nameof(sellingRepository));
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormSelling>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridViewData.DataSource = _sellingRepository.ReadSelling();
private void FormSellings_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

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

View File

@ -28,19 +28,12 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
textBoxSupplierName = new TextBox();
labelSupplier = new Label(); labelSupplier = new Label();
buttonSave = new Button(); buttonSave = new Button();
buttonCancel = new Button(); buttonCancel = new Button();
comboBoxSupplierName = new ComboBox();
SuspendLayout(); SuspendLayout();
// //
// textBoxSupplierName
//
textBoxSupplierName.Location = new Point(100, 12);
textBoxSupplierName.Name = "textBoxSupplierName";
textBoxSupplierName.Size = new Size(290, 23);
textBoxSupplierName.TabIndex = 0;
//
// labelSupplier // labelSupplier
// //
labelSupplier.AutoSize = true; labelSupplier.AutoSize = true;
@ -70,15 +63,24 @@
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click; buttonCancel.Click += ButtonCancel_Click;
// //
// comboBoxSupplierName
//
comboBoxSupplierName.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSupplierName.FormattingEnabled = true;
comboBoxSupplierName.Location = new Point(100, 12);
comboBoxSupplierName.Name = "comboBoxSupplierName";
comboBoxSupplierName.Size = new Size(290, 23);
comboBoxSupplierName.TabIndex = 4;
//
// FormSupplier // FormSupplier
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(438, 122); ClientSize = new Size(438, 122);
Controls.Add(comboBoxSupplierName);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonSave); Controls.Add(buttonSave);
Controls.Add(labelSupplier); Controls.Add(labelSupplier);
Controls.Add(textBoxSupplierName);
Name = "FormSupplier"; Name = "FormSupplier";
StartPosition = FormStartPosition.CenterParent; StartPosition = FormStartPosition.CenterParent;
Text = "FormSupplier"; Text = "FormSupplier";
@ -87,10 +89,9 @@
} }
#endregion #endregion
private TextBox textBoxSupplierName;
private Label labelSupplier; private Label labelSupplier;
private Button buttonSave; private Button buttonSave;
private Button buttonCancel; private Button buttonCancel;
private ComboBox comboBoxSupplierName;
} }
} }

View File

@ -16,12 +16,12 @@ namespace GasStation.Forms
try try
{ {
var supplier = _suppliarRepository.ReadSupplierByID(value); var supplier = _suppliarRepository.ReadSupplierByID(value);
if (supplier != null) if (supplier == null)
{ {
throw new InvalidDataException(nameof(supplier)); throw new InvalidDataException(nameof(supplier));
} }
textBoxSupplierName.Text = supplier.ProductName; comboBoxSupplierName.DataSource = supplier.ProductName;
_supplierId = value; _supplierId = value;
} }
catch (Exception ex) catch (Exception ex)
@ -43,7 +43,7 @@ namespace GasStation.Forms
{ {
try try
{ {
if (string.IsNullOrWhiteSpace(textBoxSupplierName.Text)) if (comboBoxSupplierName.SelectedIndex < 1)
{ {
throw new Exception("Имеются незаполненые поля"); throw new Exception("Имеются незаполненые поля");
} }
@ -64,7 +64,7 @@ namespace GasStation.Forms
} }
} }
private Supplier CreateSupplier(int id) => Supplier.CreateSupplier(id, textBoxSupplierName.Text); private Supplier CreateSupplier(int id) => Supplier.CreateSupplier(id, comboBoxSupplierName.Text);
private void ButtonCancel_Click(object sender, EventArgs e) => Close(); private void ButtonCancel_Click(object sender, EventArgs e) => Close();
} }

108
GasStation/Forms/FormSupplies.Designer.cs generated Normal file
View File

@ -0,0 +1,108 @@
namespace GasStation.Forms
{
partial class FormSupplies
{
/// <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()
{
panel1 = new Panel();
buttonDel = new Button();
buttonAdd = new Button();
dataGridViewData = new DataGridView();
panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
SuspendLayout();
//
// panel1
//
panel1.Controls.Add(buttonDel);
panel1.Controls.Add(buttonAdd);
panel1.Dock = DockStyle.Right;
panel1.Location = new Point(630, 0);
panel1.Name = "panel1";
panel1.Size = new Size(170, 450);
panel1.TabIndex = 1;
//
// buttonDel
//
buttonDel.Location = new Point(45, 296);
buttonDel.Name = "buttonDel";
buttonDel.Size = new Size(77, 73);
buttonDel.TabIndex = 1;
buttonDel.Text = "Удалить";
buttonDel.UseVisualStyleBackColor = true;
buttonDel.Click += ButtonDel_Click;
//
// buttonAdd
//
buttonAdd.Location = new Point(47, 41);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(75, 73);
buttonAdd.TabIndex = 0;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// dataGridViewData
//
dataGridViewData.AllowUserToAddRows = false;
dataGridViewData.AllowUserToDeleteRows = false;
dataGridViewData.AllowUserToResizeColumns = false;
dataGridViewData.AllowUserToResizeRows = false;
dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewData.Dock = DockStyle.Fill;
dataGridViewData.Location = new Point(0, 0);
dataGridViewData.MultiSelect = false;
dataGridViewData.Name = "dataGridViewData";
dataGridViewData.ReadOnly = true;
dataGridViewData.RowHeadersVisible = false;
dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridViewData.Size = new Size(630, 450);
dataGridViewData.TabIndex = 2;
//
// FormSupplies
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(dataGridViewData);
Controls.Add(panel1);
Name = "FormSupplies";
Load += FormSupplies_Load;
panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
ResumeLayout(false);
}
#endregion
private Panel panel1;
private Button buttonDel;
private Button buttonAdd;
private DataGridView dataGridViewData;
}
}

View File

@ -0,0 +1,84 @@
using GasStation.Repositories;
using Unity;
namespace GasStation.Forms
{
public partial class FormSupplies : Form
{
private readonly IUnityContainer _container;
private readonly ISupplyRepository _supplyRepository;
public FormSupplies(IUnityContainer container, ISupplyRepository supplyRepository)
{
InitializeComponent();
_container = container ??
throw new ArgumentNullException(nameof(container));
_supplyRepository = supplyRepository ??
throw new ArgumentNullException(nameof(supplyRepository));
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
try
{
_container.Resolve<FormSupply>().ShowDialog();
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (!TryGetIDFromSelectedRow(out var findID))
{
return;
}
if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
try
{
_supplyRepository.DeleteSupply(findID);
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка удаления", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void LoadList() => dataGridViewData.DataSource = _supplyRepository.ReadSupply();
private void FormSupplies_Load(object sender, EventArgs e)
{
try
{
LoadList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private bool TryGetIDFromSelectedRow(out int id)
{
id = 0;
if (dataGridViewData.SelectedRows.Count < 1)
{
MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["ID"].Value);
return true;
}
}
}

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

148
GasStation/Forms/FormSupply.Designer.cs generated Normal file
View File

@ -0,0 +1,148 @@
namespace GasStation.Forms
{
partial class FormSupply
{
/// <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()
{
buttonSave = new Button();
buttonCancel = new Button();
labelSupplier = new Label();
groupBoxSupply = new GroupBox();
dataGridViewSupply = new DataGridView();
ColumnProduct = new DataGridViewComboBoxColumn();
ColumnCount = new DataGridViewTextBoxColumn();
comboBoxSupplier = new ComboBox();
groupBoxSupply.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridViewSupply).BeginInit();
SuspendLayout();
//
// buttonSave
//
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonSave.Location = new Point(21, 290);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(89, 24);
buttonSave.TabIndex = 1;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonCancel.Location = new Point(221, 290);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(92, 24);
buttonCancel.TabIndex = 2;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// labelSupplier
//
labelSupplier.AutoSize = true;
labelSupplier.Location = new Point(21, 23);
labelSupplier.Name = "labelSupplier";
labelSupplier.Size = new Size(70, 15);
labelSupplier.TabIndex = 5;
labelSupplier.Text = "Поставщик";
//
// groupBoxSupply
//
groupBoxSupply.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
groupBoxSupply.Controls.Add(dataGridViewSupply);
groupBoxSupply.Location = new Point(21, 62);
groupBoxSupply.Name = "groupBoxSupply";
groupBoxSupply.Size = new Size(292, 185);
groupBoxSupply.TabIndex = 6;
groupBoxSupply.TabStop = false;
groupBoxSupply.Text = "Поставки";
//
// dataGridViewSupply
//
dataGridViewSupply.AllowUserToResizeColumns = false;
dataGridViewSupply.AllowUserToResizeRows = false;
dataGridViewSupply.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewSupply.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewSupply.Columns.AddRange(new DataGridViewColumn[] { ColumnProduct, ColumnCount });
dataGridViewSupply.Dock = DockStyle.Fill;
dataGridViewSupply.Location = new Point(3, 19);
dataGridViewSupply.Name = "dataGridViewSupply";
dataGridViewSupply.RowHeadersVisible = false;
dataGridViewSupply.Size = new Size(286, 163);
dataGridViewSupply.TabIndex = 0;
//
// ColumnProduct
//
ColumnProduct.HeaderText = "Товар";
ColumnProduct.Name = "ColumnProduct";
ColumnProduct.Resizable = DataGridViewTriState.True;
ColumnProduct.SortMode = DataGridViewColumnSortMode.Automatic;
//
// ColumnCount
//
ColumnCount.HeaderText = "Кол-во";
ColumnCount.Name = "ColumnCount";
//
// comboBoxSupplier
//
comboBoxSupplier.FormattingEnabled = true;
comboBoxSupplier.Location = new Point(97, 23);
comboBoxSupplier.Name = "comboBoxSupplier";
comboBoxSupplier.Size = new Size(216, 23);
comboBoxSupplier.TabIndex = 7;
//
// FormSupply
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(435, 380);
Controls.Add(comboBoxSupplier);
Controls.Add(groupBoxSupply);
Controls.Add(labelSupplier);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Name = "FormSupply";
Text = "Поставки";
groupBoxSupply.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridViewSupply).EndInit();
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonSave;
private Button buttonCancel;
private Label labelSupplier;
private GroupBox groupBoxSupply;
private DataGridView dataGridViewSupply;
private ComboBox comboBoxSupplier;
private DataGridViewComboBoxColumn ColumnProduct;
private DataGridViewTextBoxColumn ColumnCount;
}
}

View File

@ -0,0 +1,63 @@
using GasStation.Repositories;
using GasStation.Entities;
namespace GasStation.Forms
{
public partial class FormSupply : Form
{
private readonly ISupplyRepository _supplyRepository;
public FormSupply(ISupplyRepository supplyRepository, ISupplierRepository supplierRepository, IProductRepository productRepository)
{
InitializeComponent();
_supplyRepository = supplyRepository ??
throw new ArgumentNullException(nameof(supplyRepository));
comboBoxSupplier.DataSource = supplierRepository.ReadSupplier();
comboBoxSupplier.DisplayMember = "SupplierName";
comboBoxSupplier.ValueMember = "ID";
ColumnProduct.DataSource = productRepository.ReadProduct();
ColumnProduct.DisplayMember = "Cost";
ColumnProduct.ValueMember = "ID";
}
private void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (dataGridViewSupply.RowCount < 1 ||
comboBoxSupplier.SelectedIndex < 0)
{
throw new Exception("Имеются незаполненые поля");
}
_supplyRepository.CreateSupply(Supply.CreateSupply(0, (int)comboBoxSupplier.SelectedValue!, 0, CreateListSellingFromDataGrid()));
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
private List<SupplySupply> CreateListSellingFromDataGrid()
{
var list = new List<SupplySupply>();
foreach (DataGridViewRow row in dataGridViewSupply.Rows)
{
if (row.Cells["ColumnProduct"].Value == null || row.Cells["ColumnCount"].Value == null)
{
continue;
}
list.Add(SupplySupply.CreateSupply(0, Convert.ToInt32(row.Cells["ColumnCount"].Value)));
}
return list;
}
}
}

View File

@ -0,0 +1,132 @@
<?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="ColumnProduct.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnProduct.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -27,6 +27,7 @@ internal static class Program
container.RegisterType<ISellingRepository,SellingRepository>(); container.RegisterType<ISellingRepository,SellingRepository>();
container.RegisterType<ISupplierRepository, SupplierRepository>(); container.RegisterType<ISupplierRepository, SupplierRepository>();
container.RegisterType<ISupplyRepository, SupplyRepository>(); container.RegisterType<ISupplyRepository, SupplyRepository>();
container.RegisterType<IProductRepository, ProductRepository>();
return container; return container;
} }

View File

@ -0,0 +1,16 @@
using GasStation.Entities;
namespace GasStation.Repositories;
public interface IProductRepository
{
IEnumerable<Product> ReadProduct();
Product ReadProductByID(int id);
void CreateProduct(Product product);
void UpdateProduct(Product product);
void DeleteProduct(int id);
}

View File

@ -6,7 +6,7 @@ public interface ISupplyRepository
{ {
IEnumerable<Supply> ReadSupply(DateTime? supplyDate = null, int? supplierID = null, int? productID = null); IEnumerable<Supply> ReadSupply(DateTime? supplyDate = null, int? supplierID = null, int? productID = null);
void CreateSelling(Supply supply); void CreateSupply(Supply supply);
void DeleteSelling(int id); void DeleteSupply(int id);
} }

View File

@ -0,0 +1,29 @@
using GasStation.Entities;
using GasStation.Entities.Enums;
namespace GasStation.Repositories.Implementations;
public class ProductRepository : IProductRepository
{
public void CreateProduct(Product product)
{
}
public void DeleteProduct(int id)
{
}
public IEnumerable<Product> ReadProduct()
{
return [];
}
public Product ReadProductByID(int id)
{
return Product.CreateProduct(0, 0, Gasmen.None, ProductType.None);
}
public void UpdateProduct(Product product)
{
}
}

View File

@ -4,11 +4,11 @@ namespace GasStation.Repositories.Implementations;
public class SupplyRepository : ISupplyRepository public class SupplyRepository : ISupplyRepository
{ {
public void CreateSelling(Supply supply) public void CreateSupply(Supply supply)
{ {
} }
public void DeleteSelling(int id) public void DeleteSupply(int id)
{ {
} }