Compare commits
2 Commits
b5d3ccbe9a
...
c700d5dc29
Author | SHA1 | Date | |
---|---|---|---|
c700d5dc29 | |||
a253a606bd |
@ -6,6 +6,7 @@ using SoftwareInstallationDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -73,29 +74,48 @@ namespace SoftwareInstallationFileImplement
|
||||
|
||||
public bool SellPackage(IPackageModel model, int quantity)
|
||||
{
|
||||
if (source.Shops.Select(x => x.ShopPackages.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < quantity)
|
||||
|
||||
var package = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (package == null || !CheckCount(model, quantity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
foreach (var Shop in source.Shops.Where(x => x.ShopPackages.ContainsKey(model.Id)))
|
||||
foreach (var shop in source.Shops)
|
||||
{
|
||||
int QuantityInCurrentShop = Shop.ShopPackages[model.Id].Item2;
|
||||
if (QuantityInCurrentShop <= quantity)
|
||||
var packages = shop.ShopPackages;
|
||||
foreach (var elem in packages.Where(x => x.Value.Item1.Id == package.Id))
|
||||
{
|
||||
Shop.ShopPackages.Remove(model.Id);
|
||||
quantity -= QuantityInCurrentShop;
|
||||
var selling = Math.Min(elem.Value.Item2, quantity);
|
||||
packages[elem.Value.Item1.Id] = (elem.Value.Item1, elem.Value.Item2 - selling);
|
||||
quantity -= selling;
|
||||
|
||||
if (quantity <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
Shop.ShopPackages[model.Id] = (Shop.ShopPackages[model.Id].Item1, QuantityInCurrentShop - quantity);
|
||||
quantity = 0;
|
||||
}
|
||||
if (quantity == 0)
|
||||
|
||||
shop.Update(new ShopBindingModel
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = shop.Name,
|
||||
Address = shop.Address,
|
||||
DateOpening = shop.DateOpening,
|
||||
ShopPackages = packages,
|
||||
PackageMaxCount = shop.PackageMaxCount
|
||||
});
|
||||
}
|
||||
source.SaveShops();
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public bool CheckCount(IPackageModel model, int quantity)
|
||||
{
|
||||
int store = source.Shops
|
||||
.Select(x => x.ShopPackages
|
||||
.Select(y => (y.Value.Item1.Id == model.Id ? y.Value.Item2 : 0))
|
||||
.Sum()).Sum();
|
||||
return store >= quantity;
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
|
@ -35,13 +35,13 @@
|
||||
textBoxAddress = new TextBox();
|
||||
openingDatePicker = new DateTimePicker();
|
||||
dataGridView = new DataGridView();
|
||||
PackageName = new DataGridViewTextBoxColumn();
|
||||
Price = new DataGridViewTextBoxColumn();
|
||||
Count = new DataGridViewTextBoxColumn();
|
||||
buttonSave = new Button();
|
||||
buttonCancel = new Button();
|
||||
labelNumeric = new Label();
|
||||
numericUpDown = new NumericUpDown();
|
||||
Price = new DataGridViewTextBoxColumn();
|
||||
PackageName = new DataGridViewTextBoxColumn();
|
||||
Count = new DataGridViewTextBoxColumn();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)numericUpDown).BeginInit();
|
||||
SuspendLayout();
|
||||
@ -97,27 +97,12 @@
|
||||
// dataGridView
|
||||
//
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Columns.AddRange(new DataGridViewColumn[] { PackageName, Price, Count });
|
||||
dataGridView.Columns.AddRange(new DataGridViewColumn[] { Price, PackageName, Count });
|
||||
dataGridView.Location = new Point(12, 128);
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.Size = new Size(601, 242);
|
||||
dataGridView.TabIndex = 6;
|
||||
//
|
||||
// PackageName
|
||||
//
|
||||
PackageName.HeaderText = "Изделие";
|
||||
PackageName.Name = "PackageName";
|
||||
//
|
||||
// Price
|
||||
//
|
||||
Price.HeaderText = "Цена";
|
||||
Price.Name = "Price";
|
||||
//
|
||||
// Count
|
||||
//
|
||||
Count.HeaderText = "Количество";
|
||||
Count.Name = "Count";
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(384, 376);
|
||||
@ -155,6 +140,21 @@
|
||||
numericUpDown.Size = new Size(131, 23);
|
||||
numericUpDown.TabIndex = 13;
|
||||
//
|
||||
// Price
|
||||
//
|
||||
Price.HeaderText = "Номер";
|
||||
Price.Name = "Price";
|
||||
//
|
||||
// PackageName
|
||||
//
|
||||
PackageName.HeaderText = "Изделие";
|
||||
PackageName.Name = "PackageName";
|
||||
//
|
||||
// Count
|
||||
//
|
||||
Count.HeaderText = "Количество";
|
||||
Count.Name = "Count";
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
@ -191,10 +191,10 @@
|
||||
private DataGridView dataGridView;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
private DataGridViewTextBoxColumn PackageName;
|
||||
private DataGridViewTextBoxColumn Price;
|
||||
private DataGridViewTextBoxColumn Count;
|
||||
private Label labelNumeric;
|
||||
private NumericUpDown numericUpDown;
|
||||
private DataGridViewTextBoxColumn PackageName;
|
||||
private DataGridViewTextBoxColumn Count;
|
||||
private DataGridViewTextBoxColumn Price;
|
||||
}
|
||||
}
|
@ -117,21 +117,12 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="PackageName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Price.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="PackageName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Price.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
|
Loading…
Reference in New Issue
Block a user