Borschevskaya A.A. Lab Work 2 Hard #4

Closed
pgirl1 wants to merge 17 commits from lab2_hard into lab1_hard
11 changed files with 389 additions and 2 deletions
Showing only changes of commit 709214b6cd - Show all commits

View File

@ -83,5 +83,62 @@ namespace FurnitureAssemFileImplement.Implements
}
return null;
}
private int GetCountFurnitureAllShops(FurnitureBindingModel furniture)
{
int count = 0;
foreach (var shop in source.Shops)
Review

Значение можно получить через LINQ-запрос

Значение можно получить через LINQ-запрос
{
if (shop.Furnitures.ContainsKey(furniture.Id))
{
count += shop.Furnitures[furniture.Id].Item2;
}
}
return count;
}
public bool Sell(FurnitureBindingModel furniture, int count)
{
if (GetCountFurnitureAllShops(furniture) < count)
{
return false;
}
foreach (var shop in source.Shops)
{
if (shop.Furnitures.ContainsKey(furniture.Id))
{
if (shop.Furnitures[furniture.Id].Item2 > count)
{
shop.Furnitures[furniture.Id] = (shop.Furnitures[furniture.Id].Item1, shop.Furnitures[furniture.Id].Item2 - count);
shop.Update(new ShopBindingModel
{
Id = shop.Id,
ShopName = shop.ShopName,
MaxCount = shop.MaxCount,
Furnitures = shop.Furnitures,
Address = shop.Address,
DateOpening = shop.DateOpening,
});
break;
}
shop.Furnitures[furniture.Id] = (shop.Furnitures[furniture.Id].Item1, 0);
shop.Update(new ShopBindingModel
{
Id = shop.Id,
ShopName = shop.ShopName,
MaxCount = shop.MaxCount,
Furnitures = shop.Furnitures,
Address = shop.Address,
DateOpening = shop.DateOpening,
});
count -= shop.Furnitures[furniture.Id].Item2;
}
}
source.SaveShops();
return true;
}
}
}

View File

@ -40,6 +40,7 @@
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.пополнениеМагазинаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonSell = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@ -152,11 +153,22 @@
this.пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
this.пополнениеМагазинаToolStripMenuItem.Click += new System.EventHandler(this.ReplenishmentToolStripMenuItem_Click);
//
// buttonSell
//
this.buttonSell.Location = new System.Drawing.Point(902, 324);
this.buttonSell.Name = "buttonSell";
this.buttonSell.Size = new System.Drawing.Size(150, 25);
this.buttonSell.TabIndex = 7;
this.buttonSell.Text = "Продажа мебели";
this.buttonSell.UseVisualStyleBackColor = true;
this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1065, 450);
this.Controls.Add(this.buttonSell);
this.Controls.Add(this.ButtonRef);
this.Controls.Add(this.ButtonIssuedOrder);
this.Controls.Add(this.ButtonOrderReady);
@ -190,5 +202,6 @@
private ToolStripMenuItem изделияToolStripMenuItem;
private ToolStripMenuItem магазиныToolStripMenuItem;
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
private Button buttonSell;
}
}

View File

@ -207,5 +207,14 @@ namespace FurnitureAssembly
}
}
}
private void buttonSell_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSell));
if (service is FormSell form)
{
form.ShowDialog();
}
}
}
}

View File

@ -0,0 +1,119 @@
namespace FurnitureAssembly
{
partial class FormSell
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBoxCount = new System.Windows.Forms.TextBox();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonSell = new System.Windows.Forms.Button();
this.labelNum = new System.Windows.Forms.Label();
this.labelFurniture = new System.Windows.Forms.Label();
this.comboBoxFurniture = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(135, 84);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(160, 23);
this.textBoxCount.TabIndex = 14;
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(332, 142);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(99, 29);
this.buttonCancel.TabIndex = 13;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
//
// buttonSell
//
this.buttonSell.Location = new System.Drawing.Point(196, 142);
this.buttonSell.Name = "buttonSell";
this.buttonSell.Size = new System.Drawing.Size(99, 29);
this.buttonSell.TabIndex = 12;
this.buttonSell.Text = "Продать";
this.buttonSell.UseVisualStyleBackColor = true;
this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click);
//
// labelNum
//
this.labelNum.AutoSize = true;
this.labelNum.Location = new System.Drawing.Point(48, 87);
this.labelNum.Name = "labelNum";
this.labelNum.Size = new System.Drawing.Size(72, 15);
this.labelNum.TabIndex = 11;
this.labelNum.Text = "Количество";
//
// labelFurniture
//
this.labelFurniture.AutoSize = true;
this.labelFurniture.Location = new System.Drawing.Point(48, 46);
this.labelFurniture.Name = "labelFurniture";
this.labelFurniture.Size = new System.Drawing.Size(53, 15);
this.labelFurniture.TabIndex = 10;
this.labelFurniture.Text = "Изделие";
//
// comboBoxFurniture
//
this.comboBoxFurniture.FormattingEnabled = true;
this.comboBoxFurniture.Location = new System.Drawing.Point(135, 43);
this.comboBoxFurniture.Name = "comboBoxFurniture";
this.comboBoxFurniture.Size = new System.Drawing.Size(296, 23);
this.comboBoxFurniture.TabIndex = 9;
//
// FormSell
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(479, 214);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSell);
this.Controls.Add(this.labelNum);
this.Controls.Add(this.labelFurniture);
this.Controls.Add(this.comboBoxFurniture);
this.Name = "FormSell";
this.Text = "Продажа мебели";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private TextBox textBoxCount;
private Button buttonCancel;
private Button buttonSell;
private Label labelNum;
private Label labelFurniture;
private ComboBox comboBoxFurniture;
}
}

View File

@ -0,0 +1,116 @@
using FurnitureAssemblyBusinessLogic;
using FurnitureAssemblyContracts.BusinessLogicsContarcts;
using FurnitureAssemblyContracts.ViewModels;
using FurnitureAssemblyDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FurnitureAssembly
{
public partial class FormSell : Form
{
private readonly IShopLogic _shopLogic;
private readonly List<FurnitureViewModel>? _listFurnitures;
public int Id
{
get
{
return Convert.ToInt32(comboBoxFurniture.SelectedValue);
}
set
{
comboBoxFurniture.SelectedValue = value;
}
}
public IFurnitureModel? FurnitureModel
{
get
{
if (_listFurnitures == null)
{
return null;
}
foreach (var elem in _listFurnitures)
{
if (elem.Id == Id)
{
return elem;
}
}
return null;
}
}
public int Count
{
get
{
return Convert.ToInt32(textBoxCount.Text);
}
set
{
textBoxCount.Text = value.ToString();
}
}
public FormSell(IShopLogic shopLogic, IFurnitureLogic furnitureLogic)
{
InitializeComponent();
_shopLogic = shopLogic;
_listFurnitures = furnitureLogic.ReadList(null);
if (_listFurnitures != null)
{
comboBoxFurniture.DisplayMember = "FurnitureName";
comboBoxFurniture.ValueMember = "Id";
comboBoxFurniture.DataSource = _listFurnitures;
comboBoxFurniture.SelectedItem = null;
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void buttonSell_Click(object sender, EventArgs e)
{
if (FurnitureModel == null)
{
MessageBox.Show("Выберите изделие", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (Count <= 0)
{
MessageBox.Show("Укажите количество изделия", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!_shopLogic.Sell(new() { Id = FurnitureModel.Id }, Count))
{
MessageBox.Show("Не удалось продать изделие " + FurnitureModel.FurnitureName, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
MessageBox.Show("Продажа прошла успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -53,6 +53,7 @@ namespace FurnitureAssembly
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormReplenishmentShop>();
services.AddTransient<FormSell>();
}
}
}

View File

@ -203,5 +203,10 @@ namespace FurnitureAssemblyBusinessLogic
}
return true;
}
public bool Sell(FurnitureBindingModel furnitureBindingModel, int count)
{
return _shopStorage.Sell(furnitureBindingModel, count);
}
}
}

View File

@ -17,7 +17,7 @@ namespace FurnitureAssemblyContracts.BusinessLogicsContarcts
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool AddFurniture(ShopBindingModel model, FurnitureBindingModel furnitureModel, int count);
bool AddFurnituresAtShops(FurnitureBindingModel furnitureModel, int count);
bool Sell(FurnitureBindingModel furnitureModel, int count);
}
}

View File

@ -12,6 +12,8 @@ namespace FurnitureAssemblyContracts.StoragesContracts
ShopViewModel? GetElement(ShopSearchModel model);
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool Sell(FurnitureBindingModel furnitureBindingModel, int count);
}
}

View File

@ -109,5 +109,10 @@ namespace FurnitureAssemblyListImplement.Implements
}
return null;
}
public bool Sell(FurnitureBindingModel furnitureBindingModel, int count)
{
throw new NotImplementedException();
}
}
}