Sell form

This commit is contained in:
ShabOl 2024-04-10 00:26:00 +04:00
parent b4c8722cd4
commit 5d703cb615
14 changed files with 404 additions and 27 deletions

View File

@ -161,7 +161,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
public bool Sale(SupplySearchModel Model)
{
if (!Model.PizzaId.HasValue || !Model.Count.HasValue)
if (!Model.RepairId.HasValue || !Model.Count.HasValue)
return false;
_logger.LogInformation("Проверка ремонтов во всех магазинах");

View File

@ -1,4 +1,4 @@
namespace PizzeriaContracts.SearchModels
namespace AutoWorkshopContracts.SearchModels
{
public class SupplySearchModel
{

View File

@ -1,7 +1,6 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.ViewModels;
using PizzeriaContracts.SearchModels;
namespace AutoWorkshopContracts.StoragesContracts
{

View File

@ -3,7 +3,6 @@ using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopFileImplement.Models;
using PizzeriaContracts.SearchModels;
namespace AutoWorkshopFileImplement.Implements
{

View File

@ -3,7 +3,6 @@ using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.StoragesContracts;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopListImplement.Models;
using PizzeriaContracts.SearchModels;
namespace AutoWorkshopListImplement.Implements
{

View File

@ -1,7 +1,6 @@
using AutoWorkshopContracts.BindingModels;
using AutoWorkshopContracts.ViewModels;
using AutoWorkshopDataModels.Models;
using System.Reflection;
namespace AutoWorkshopListImplement.Models
{
@ -52,7 +51,7 @@ namespace AutoWorkshopListImplement.Models
Address = Address,
OpeningDate = OpeningDate,
ShopRepairs = ShopRepairs,
RepairsMaxCount = Model.RepairsMaxCount,
RepairsMaxCount = RepairsMaxCount,
};
}
}

View File

@ -0,0 +1,125 @@
namespace AutoWorkshopView.Forms.Shop
{
partial class FormSellRepair
{
/// <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()
{
RepairLabel = new Label();
RepairComboBox = new ComboBox();
CountLabel = new Label();
CountTextBox = new TextBox();
SellButton = new Button();
CancelButton = new Button();
SuspendLayout();
//
// RepairLabel
//
RepairLabel.AutoSize = true;
RepairLabel.Location = new Point(10, 11);
RepairLabel.Name = "RepairLabel";
RepairLabel.Size = new Size(54, 15);
RepairLabel.TabIndex = 0;
RepairLabel.Text = "Ремонт: ";
//
// RepairComboBox
//
RepairComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
RepairComboBox.FormattingEnabled = true;
RepairComboBox.Location = new Point(94, 8);
RepairComboBox.Margin = new Padding(3, 2, 3, 2);
RepairComboBox.Name = "RepairComboBox";
RepairComboBox.Size = new Size(217, 23);
RepairComboBox.TabIndex = 1;
//
// CountLabel
//
CountLabel.AutoSize = true;
CountLabel.Location = new Point(10, 41);
CountLabel.Name = "CountLabel";
CountLabel.Size = new Size(78, 15);
CountLabel.TabIndex = 2;
CountLabel.Text = "Количество: ";
//
// CountTextBox
//
CountTextBox.Location = new Point(94, 39);
CountTextBox.Margin = new Padding(3, 2, 3, 2);
CountTextBox.Name = "CountTextBox";
CountTextBox.Size = new Size(217, 23);
CountTextBox.TabIndex = 3;
//
// SellButton
//
SellButton.Location = new Point(117, 77);
SellButton.Margin = new Padding(3, 2, 3, 2);
SellButton.Name = "SellButton";
SellButton.Size = new Size(92, 30);
SellButton.TabIndex = 4;
SellButton.Text = "Продать";
SellButton.UseVisualStyleBackColor = true;
SellButton.Click += SellButton_Click;
//
// CancelButton
//
CancelButton.Location = new Point(215, 77);
CancelButton.Margin = new Padding(3, 2, 3, 2);
CancelButton.Name = "CancelButton";
CancelButton.Size = new Size(96, 30);
CancelButton.TabIndex = 5;
CancelButton.Text = "Отмена";
CancelButton.UseVisualStyleBackColor = true;
CancelButton.Click += ButtonCancel_Click;
//
// FormSellRepair
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(325, 122);
Controls.Add(CancelButton);
Controls.Add(SellButton);
Controls.Add(CountTextBox);
Controls.Add(CountLabel);
Controls.Add(RepairComboBox);
Controls.Add(RepairLabel);
Margin = new Padding(3, 2, 3, 2);
Name = "FormSellRepair";
Text = "Продажа ремонтов";
Load += FormSellRepair_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label RepairLabel;
private ComboBox RepairComboBox;
private Label CountLabel;
private TextBox CountTextBox;
private Button SellButton;
private Button CancelButton;
}
}

View File

@ -0,0 +1,87 @@
using AutoWorkshopContracts.BusinessLogicContracts;
using AutoWorkshopContracts.BusinessLogicsContracts;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace AutoWorkshopView.Forms.Shop
{
public partial class FormSellRepair : Form
{
private readonly ILogger _logger;
private readonly IRepairLogic _repairLogic;
private readonly IShopLogic _shopLogic;
private List<RepairViewModel> _repairList = new List<RepairViewModel>();
public FormSellRepair(ILogger<FormSellRepair> Logger, IRepairLogic RepairLogic, IShopLogic ShopLogic)
{
InitializeComponent();
_logger = Logger;
_repairLogic = RepairLogic;
_shopLogic = ShopLogic;
}
private void FormSellRepair_Load(object sender, EventArgs e)
{
_repairList = _repairLogic.ReadList(null);
if (_repairList != null)
{
RepairComboBox.DisplayMember = "RepairName";
RepairComboBox.ValueMember = "Id";
RepairComboBox.DataSource = _repairList;
RepairComboBox.SelectedItem = null;
_logger.LogInformation("Загрузка ремонтов для продажи");
}
}
private void SellButton_Click(object sender, EventArgs e)
{
if (RepairComboBox.SelectedValue == null)
{
MessageBox.Show("Выберите ремонт", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание покупки");
try
{
bool Result = _shopLogic.Sale(new SupplySearchModel
{
RepairId = Convert.ToInt32(RepairComboBox.SelectedValue),
Count = Convert.ToInt32(CountTextBox.Text)
});
if (Result)
{
_logger.LogInformation("Проверка пройдена, продажа проведена");
MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
else
{
_logger.LogInformation("Проверка не пройдена");
MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка создания покупки");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
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

@ -40,13 +40,16 @@
CountColumn = new DataGridViewTextBoxColumn();
OpeningDateLabel = new Label();
OpenDateTimePicker = new DateTimePicker();
RepairsMaxCountLabel = new Label();
RepairsMaxCountNumericUp = new NumericUpDown();
((System.ComponentModel.ISupportInitialize)ViewDataGrid).BeginInit();
((System.ComponentModel.ISupportInitialize)RepairsMaxCountNumericUp).BeginInit();
SuspendLayout();
//
// NameLabel
//
NameLabel.AutoSize = true;
NameLabel.Location = new Point(10, 12);
NameLabel.Location = new Point(9, 9);
NameLabel.Name = "NameLabel";
NameLabel.Size = new Size(65, 15);
NameLabel.TabIndex = 0;
@ -54,24 +57,24 @@
//
// NameTextBox
//
NameTextBox.Location = new Point(112, 9);
NameTextBox.Location = new Point(105, 6);
NameTextBox.Margin = new Padding(3, 2, 3, 2);
NameTextBox.Name = "NameTextBox";
NameTextBox.Size = new Size(240, 23);
NameTextBox.Size = new Size(210, 23);
NameTextBox.TabIndex = 1;
//
// AddressTextBox
//
AddressTextBox.Location = new Point(112, 36);
AddressTextBox.Location = new Point(105, 33);
AddressTextBox.Margin = new Padding(3, 2, 3, 2);
AddressTextBox.Name = "AddressTextBox";
AddressTextBox.Size = new Size(240, 23);
AddressTextBox.Size = new Size(210, 23);
AddressTextBox.TabIndex = 3;
//
// AddressLabel
//
AddressLabel.AutoSize = true;
AddressLabel.Location = new Point(12, 39);
AddressLabel.Location = new Point(10, 36);
AddressLabel.Name = "AddressLabel";
AddressLabel.Size = new Size(46, 15);
AddressLabel.TabIndex = 2;
@ -79,10 +82,10 @@
//
// CancelButton
//
CancelButton.Location = new Point(395, 343);
CancelButton.Location = new Point(345, 302);
CancelButton.Margin = new Padding(3, 2, 3, 2);
CancelButton.Name = "CancelButton";
CancelButton.Size = new Size(114, 33);
CancelButton.Size = new Size(100, 25);
CancelButton.TabIndex = 5;
CancelButton.Text = "Отмена";
CancelButton.UseVisualStyleBackColor = true;
@ -90,10 +93,10 @@
//
// SaveButton
//
SaveButton.Location = new Point(276, 343);
SaveButton.Location = new Point(239, 302);
SaveButton.Margin = new Padding(3, 2, 3, 2);
SaveButton.Name = "SaveButton";
SaveButton.Size = new Size(114, 33);
SaveButton.Size = new Size(100, 25);
SaveButton.TabIndex = 6;
SaveButton.Text = "Сохранить";
SaveButton.UseVisualStyleBackColor = true;
@ -106,14 +109,14 @@
ViewDataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
ViewDataGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
ViewDataGrid.Columns.AddRange(new DataGridViewColumn[] { IdColumn, RepairNameColumn, CountColumn });
ViewDataGrid.Location = new Point(10, 108);
ViewDataGrid.Location = new Point(9, 126);
ViewDataGrid.Margin = new Padding(3, 2, 3, 2);
ViewDataGrid.Name = "ViewDataGrid";
ViewDataGrid.ReadOnly = true;
ViewDataGrid.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
ViewDataGrid.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;
ViewDataGrid.RowTemplate.Height = 29;
ViewDataGrid.Size = new Size(498, 230);
ViewDataGrid.Size = new Size(436, 172);
ViewDataGrid.TabIndex = 7;
//
// IdColumn
@ -141,25 +144,45 @@
// OpeningDateLabel
//
OpeningDateLabel.AutoSize = true;
OpeningDateLabel.Location = new Point(10, 69);
OpeningDateLabel.Location = new Point(9, 63);
OpeningDateLabel.Name = "OpeningDateLabel";
OpeningDateLabel.Size = new Size(87, 15);
OpeningDateLabel.Size = new Size(90, 15);
OpeningDateLabel.TabIndex = 8;
OpeningDateLabel.Text = "Дата открытия";
OpeningDateLabel.Text = "Дата открытия:";
//
// OpenDateTimePicker
//
OpenDateTimePicker.Location = new Point(112, 63);
OpenDateTimePicker.Location = new Point(105, 60);
OpenDateTimePicker.Margin = new Padding(3, 2, 3, 2);
OpenDateTimePicker.Name = "OpenDateTimePicker";
OpenDateTimePicker.Size = new Size(240, 23);
OpenDateTimePicker.Size = new Size(210, 23);
OpenDateTimePicker.TabIndex = 9;
//
// RepairsMaxCountLabel
//
RepairsMaxCountLabel.AutoSize = true;
RepairsMaxCountLabel.Location = new Point(9, 90);
RepairsMaxCountLabel.Name = "RepairsMaxCountLabel";
RepairsMaxCountLabel.Size = new Size(83, 15);
RepairsMaxCountLabel.TabIndex = 10;
RepairsMaxCountLabel.Text = "Вместимость:";
//
// RepairsMaxCountNumericUp
//
RepairsMaxCountNumericUp.Location = new Point(105, 87);
RepairsMaxCountNumericUp.Margin = new Padding(3, 2, 3, 2);
RepairsMaxCountNumericUp.Maximum = new decimal(new int[] { 10000, 0, 0, 0 });
RepairsMaxCountNumericUp.Name = "RepairsMaxCountNumericUp";
RepairsMaxCountNumericUp.Size = new Size(210, 23);
RepairsMaxCountNumericUp.TabIndex = 11;
//
// FormShop
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(519, 385);
ClientSize = new Size(460, 340);
Controls.Add(RepairsMaxCountNumericUp);
Controls.Add(RepairsMaxCountLabel);
Controls.Add(OpenDateTimePicker);
Controls.Add(OpeningDateLabel);
Controls.Add(ViewDataGrid);
@ -174,6 +197,7 @@
Text = "Магазин";
Load += FormShop_Load;
((System.ComponentModel.ISupportInitialize)ViewDataGrid).EndInit();
((System.ComponentModel.ISupportInitialize)RepairsMaxCountNumericUp).EndInit();
ResumeLayout(false);
PerformLayout();
}
@ -192,5 +216,7 @@
private DataGridViewTextBoxColumn CountColumn;
private Label OpeningDateLabel;
private DateTimePicker OpenDateTimePicker;
private Label RepairsMaxCountLabel;
private NumericUpDown RepairsMaxCountNumericUp;
}
}

View File

@ -3,6 +3,7 @@ using AutoWorkshopContracts.BusinessLogicsContracts;
using AutoWorkshopContracts.SearchModels;
using AutoWorkshopDataModels.Models;
using Microsoft.Extensions.Logging;
using System.Windows.Forms;
namespace AutoWorkshopView.Forms.Shop
{
@ -45,6 +46,7 @@ namespace AutoWorkshopView.Forms.Shop
NameTextBox.Text = View.ShopName;
AddressTextBox.Text = View.Address;
OpenDateTimePicker.Value = View.OpeningDate;
RepairsMaxCountNumericUp.Value = View.RepairsMaxCount;
_shopRepairs = View.ShopRepairs ?? new Dictionary<int, (IRepairModel, int)>();
LoadData();
@ -103,7 +105,8 @@ namespace AutoWorkshopView.Forms.Shop
Id = _id ?? 0,
ShopName = NameTextBox.Text,
Address = AddressTextBox.Text,
OpeningDate = OpenDateTimePicker.Value
OpeningDate = OpenDateTimePicker.Value,
RepairsMaxCount = (int)RepairsMaxCountNumericUp.Value,
};
var OperationResult = _id.HasValue ? _logic.Update(Model) : _logic.Create(Model);

View File

@ -35,6 +35,7 @@
ShopsToolStripMenuItem = new ToolStripMenuItem();
OperationToolStripMenuItem = new ToolStripMenuItem();
TransactionToolStripMenuItem = new ToolStripMenuItem();
SaleToolStripMenuItem = new ToolStripMenuItem();
DataGridView = new DataGridView();
CreateOrderButton = new Button();
TakeInWorkButton = new Button();
@ -86,7 +87,7 @@
//
// OperationToolStripMenuItem
//
OperationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { TransactionToolStripMenuItem });
OperationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { TransactionToolStripMenuItem, SaleToolStripMenuItem });
OperationToolStripMenuItem.Name = "OperationToolStripMenuItem";
OperationToolStripMenuItem.Size = new Size(75, 20);
OperationToolStripMenuItem.Text = "Операции";
@ -165,6 +166,13 @@
RefreshButton.UseVisualStyleBackColor = true;
RefreshButton.Click += RefreshButton_Click;
//
// SaleToolStripMenuItem
//
SaleToolStripMenuItem.Name = "SaleToolStripMenuItem";
SaleToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
SaleToolStripMenuItem.Text = "Продажа";
SaleToolStripMenuItem.Click += new System.EventHandler(SellToolStripMenuItem_Click);
//
// MainForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -204,5 +212,6 @@
private ToolStripMenuItem ShopsToolStripMenuItem;
private ToolStripMenuItem OperationToolStripMenuItem;
private ToolStripMenuItem TransactionToolStripMenuItem;
private ToolStripMenuItem SaleToolStripMenuItem;
}
}

View File

@ -10,6 +10,7 @@ namespace AutoWorkshopView
{
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
public MainForm(ILogger<MainForm> Logger, IOrderLogic OrderLogic)
{
InitializeComponent();
@ -185,5 +186,14 @@ namespace AutoWorkshopView
Form.ShowDialog();
}
}
private void SellToolStripMenuItem_Click(object sender, EventArgs e)
{
var Service = Program.ServiceProvider?.GetService(typeof(FormSellRepair));
if (Service is FormSellRepair Form)
{
Form.ShowDialog();
}
}
}
}

View File

@ -56,6 +56,7 @@ namespace AutoWorkshopView
Services.AddTransient<FormShop>();
Services.AddTransient<FormShops>();
Services.AddTransient<FormCreateSupply>();
Services.AddTransient<FormSellRepair>();
}
}
}