fix
This commit is contained in:
parent
47eb037c61
commit
35856195e8
@ -52,7 +52,7 @@ namespace SoftwareInstallationBusinessLogic
|
||||
public bool Create(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
model.Pastries = new();
|
||||
model.Packages = new();
|
||||
if (_shopStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
@ -123,8 +123,7 @@ namespace SoftwareInstallationBusinessLogic
|
||||
{
|
||||
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(count));
|
||||
}
|
||||
_logger.LogInformation("AddPackageInShop. ShopName:{ShopName}.Id:{ Id}",
|
||||
model.Name, model.Id);
|
||||
_logger.LogInformation("AddPackageInShop. ShopName:{ShopName}.Id:{ Id}", model.Name, model.Id);
|
||||
var element = _shopStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
@ -133,9 +132,8 @@ namespace SoftwareInstallationBusinessLogic
|
||||
}
|
||||
_logger.LogInformation("AddPackageInShop find. Id:{Id}", element.Id);
|
||||
|
||||
|
||||
var prevCount = element.Pastries.GetValueOrDefault(package.Id, (package, 0)).Item2;
|
||||
element.Pastries[package.Id] = (package, prevCount + count);
|
||||
var prevCount = element.Packages.GetValueOrDefault(package.Id, (package, 0)).Item2;
|
||||
element.Packages[package.Id] = (package, prevCount + count);
|
||||
_logger.LogInformation(
|
||||
"AddPackageInShop. Has been added {count} {package} in {ShopName}",
|
||||
count, package.PackageName, element.Name);
|
||||
@ -146,7 +144,7 @@ namespace SoftwareInstallationBusinessLogic
|
||||
Address = element.Address,
|
||||
Name = element.Name,
|
||||
DateOpening = element.DateOpening,
|
||||
Pastries = element.Pastries
|
||||
Packages = element.Packages
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace SoftwareInstallationContracts.BindingModels
|
||||
|
||||
public DateTime DateOpening { get; set; } = DateTime.Now;
|
||||
|
||||
public Dictionary<int, (IPackageModel, int)> Pastries
|
||||
public Dictionary<int, (IPackageModel, int)> Packages
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -15,7 +15,7 @@ namespace SoftwareInstallationContracts.ViewModels
|
||||
[DisplayName("Время открытия")]
|
||||
public DateTime DateOpening { get; set; } = DateTime.Now;
|
||||
|
||||
public Dictionary<int, (IPackageModel, int)> Pastries
|
||||
public Dictionary<int, (IPackageModel, int)> Packages
|
||||
{
|
||||
get;
|
||||
set;
|
||||
|
@ -7,6 +7,6 @@ namespace SoftwareInstallationDataModels
|
||||
string Name { get; }
|
||||
string Address { get; }
|
||||
DateTime DateOpening { get; }
|
||||
Dictionary<int, (IPackageModel, int)> Pastries { get; }
|
||||
Dictionary<int, (IPackageModel, int)> Packages { get; }
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace SoftwareInstallationListImplement
|
||||
|
||||
public DateTime DateOpening { get; private set; }
|
||||
|
||||
public Dictionary<int, (IPackageModel, int)> Pastries
|
||||
public Dictionary<int, (IPackageModel, int)> Packages
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
@ -33,7 +33,7 @@ namespace SoftwareInstallationListImplement
|
||||
Name = model.Name,
|
||||
Address = model.Address,
|
||||
DateOpening = model.DateOpening,
|
||||
Pastries = new()
|
||||
Packages = new()
|
||||
};
|
||||
}
|
||||
public void Update(ShopBindingModel? model)
|
||||
@ -45,14 +45,14 @@ namespace SoftwareInstallationListImplement
|
||||
Name = model.Name;
|
||||
Address = model.Address;
|
||||
DateOpening = model.DateOpening;
|
||||
Pastries = model.Pastries;
|
||||
Packages = model.Packages;
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Address = Address,
|
||||
Pastries = Pastries,
|
||||
Packages = Packages,
|
||||
DateOpening = DateOpening,
|
||||
};
|
||||
}
|
||||
|
@ -28,11 +28,11 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.comboBoxShop = new System.Windows.Forms.ComboBox();
|
||||
this.textBoxShop = new System.Windows.Forms.ComboBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.comboBoxPackage = new System.Windows.Forms.ComboBox();
|
||||
this.textBoxPackage = new System.Windows.Forms.ComboBox();
|
||||
this.numericUpDownCount = new System.Windows.Forms.NumericUpDown();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
@ -41,11 +41,11 @@
|
||||
//
|
||||
// comboBoxShop
|
||||
//
|
||||
this.comboBoxShop.FormattingEnabled = true;
|
||||
this.comboBoxShop.Location = new System.Drawing.Point(214, 17);
|
||||
this.comboBoxShop.Name = "comboBoxShop";
|
||||
this.comboBoxShop.Size = new System.Drawing.Size(222, 23);
|
||||
this.comboBoxShop.TabIndex = 3;
|
||||
this.textBoxShop.FormattingEnabled = true;
|
||||
this.textBoxShop.Location = new System.Drawing.Point(214, 17);
|
||||
this.textBoxShop.Name = "comboBoxShop";
|
||||
this.textBoxShop.Size = new System.Drawing.Size(222, 23);
|
||||
this.textBoxShop.TabIndex = 3;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
@ -76,11 +76,11 @@
|
||||
//
|
||||
// comboBoxPackage
|
||||
//
|
||||
this.comboBoxPackage.FormattingEnabled = true;
|
||||
this.comboBoxPackage.Location = new System.Drawing.Point(214, 44);
|
||||
this.comboBoxPackage.Name = "comboBoxPackage";
|
||||
this.comboBoxPackage.Size = new System.Drawing.Size(222, 23);
|
||||
this.comboBoxPackage.TabIndex = 6;
|
||||
this.textBoxPackage.FormattingEnabled = true;
|
||||
this.textBoxPackage.Location = new System.Drawing.Point(214, 44);
|
||||
this.textBoxPackage.Name = "comboBoxPackage";
|
||||
this.textBoxPackage.Size = new System.Drawing.Size(222, 23);
|
||||
this.textBoxPackage.TabIndex = 6;
|
||||
//
|
||||
// numericUpDownCount
|
||||
//
|
||||
@ -124,10 +124,10 @@
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.numericUpDownCount);
|
||||
this.Controls.Add(this.comboBoxPackage);
|
||||
this.Controls.Add(this.textBoxPackage);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.comboBoxShop);
|
||||
this.Controls.Add(this.textBoxShop);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Name = "FormAddPackageInShop";
|
||||
this.Text = "форма добавления пакета в магазин";
|
||||
@ -139,11 +139,11 @@
|
||||
|
||||
#endregion
|
||||
|
||||
private ComboBox comboBoxShop;
|
||||
private ComboBox textBoxShop;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private Label label3;
|
||||
private ComboBox comboBoxPackage;
|
||||
private ComboBox textBoxPackage;
|
||||
private NumericUpDown numericUpDownCount;
|
||||
private Button buttonSave;
|
||||
private Button buttonCancel;
|
||||
|
@ -21,7 +21,7 @@ namespace SoftwareInstallationView
|
||||
private readonly IShopLogic _shopLogic;
|
||||
private readonly IPackageLogic _packageLogic;
|
||||
private readonly List<ShopViewModel>? _listShops;
|
||||
private readonly List<PackageViewModel>? _listPastries;
|
||||
private readonly List<PackageViewModel>? _listPackages;
|
||||
|
||||
public FormAddPackageInShop(ILogger<FormAddPackageInShop> logger, IShopLogic shopLogic, IPackageLogic packageLogic)
|
||||
{
|
||||
@ -32,30 +32,30 @@ namespace SoftwareInstallationView
|
||||
_listShops = shopLogic.ReadList(null);
|
||||
if (_listShops != null)
|
||||
{
|
||||
comboBoxShop.DisplayMember = "Name";
|
||||
comboBoxShop.ValueMember = "Id";
|
||||
comboBoxShop.DataSource = _listShops;
|
||||
comboBoxShop.SelectedItem = null;
|
||||
textBoxShop.DisplayMember = "Name";
|
||||
textBoxShop.ValueMember = "Id";
|
||||
textBoxShop.DataSource = _listShops;
|
||||
textBoxShop.SelectedItem = null;
|
||||
}
|
||||
|
||||
_listPastries = packageLogic.ReadList(null);
|
||||
if (_listPastries != null)
|
||||
_listPackages = packageLogic.ReadList(null);
|
||||
if (_listPackages != null)
|
||||
{
|
||||
comboBoxPackage.DisplayMember = "PackageName";
|
||||
comboBoxPackage.ValueMember= "Id";
|
||||
comboBoxPackage.DataSource = _listPastries;
|
||||
comboBoxPackage.SelectedItem = null;
|
||||
textBoxPackage.DisplayMember = "PackageName";
|
||||
textBoxPackage.ValueMember= "Id";
|
||||
textBoxPackage.DataSource = _listPackages;
|
||||
textBoxPackage.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (comboBoxShop.SelectedValue == null)
|
||||
if (textBoxShop.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (comboBoxPackage.SelectedValue == null)
|
||||
if (textBoxPackage.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
@ -65,14 +65,14 @@ namespace SoftwareInstallationView
|
||||
{
|
||||
var package = _packageLogic.ReadElement(new()
|
||||
{
|
||||
Id = (int)comboBoxPackage.SelectedValue
|
||||
Id = (int)textBoxPackage.SelectedValue
|
||||
});
|
||||
if (package == null)
|
||||
{
|
||||
throw new Exception("Не найдено изделие. Дополнительная информация в логах.");
|
||||
}
|
||||
var resultOperation = _shopLogic.AddPackage(
|
||||
model: new() { Id = (int)comboBoxShop.SelectedValue },
|
||||
model: new() { Id = (int)textBoxShop.SelectedValue },
|
||||
package: package,
|
||||
count: (int)numericUpDownCount.Value
|
||||
);
|
||||
|
@ -29,7 +29,6 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.comboBoxShop = new System.Windows.Forms.ComboBox();
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.PackageName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.Price = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
@ -37,9 +36,10 @@
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.textBoxAddress = new System.Windows.Forms.TextBox();
|
||||
this.textBoxDateOpening = new System.Windows.Forms.TextBox();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.textBoxShop = new System.Windows.Forms.TextBox();
|
||||
this.textBoxDateOpening = new System.Windows.Forms.DateTimePicker();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -52,15 +52,6 @@
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "Название магазина:";
|
||||
//
|
||||
// comboBoxShop
|
||||
//
|
||||
this.comboBoxShop.FormattingEnabled = true;
|
||||
this.comboBoxShop.Location = new System.Drawing.Point(12, 27);
|
||||
this.comboBoxShop.Name = "comboBoxShop";
|
||||
this.comboBoxShop.Size = new System.Drawing.Size(141, 23);
|
||||
this.comboBoxShop.TabIndex = 1;
|
||||
this.comboBoxShop.SelectedIndexChanged += new System.EventHandler(this.ComboBoxShop_SelectedIndexChanged);
|
||||
//
|
||||
// dataGridView
|
||||
//
|
||||
this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
@ -108,9 +99,9 @@
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(386, 9);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(100, 15);
|
||||
this.label3.Size = new System.Drawing.Size(87, 15);
|
||||
this.label3.TabIndex = 4;
|
||||
this.label3.Text = "Время открытия:";
|
||||
this.label3.Text = "Дата открытия";
|
||||
//
|
||||
// textBoxAddress
|
||||
//
|
||||
@ -119,13 +110,6 @@
|
||||
this.textBoxAddress.Size = new System.Drawing.Size(221, 23);
|
||||
this.textBoxAddress.TabIndex = 5;
|
||||
//
|
||||
// textBoxDateOpening
|
||||
//
|
||||
this.textBoxDateOpening.Location = new System.Drawing.Point(386, 27);
|
||||
this.textBoxDateOpening.Name = "textBoxDateOpening";
|
||||
this.textBoxDateOpening.Size = new System.Drawing.Size(209, 23);
|
||||
this.textBoxDateOpening.TabIndex = 6;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
@ -148,19 +132,33 @@
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
|
||||
//
|
||||
// textBoxShop
|
||||
//
|
||||
this.textBoxShop.Location = new System.Drawing.Point(13, 27);
|
||||
this.textBoxShop.Name = "textBoxShop";
|
||||
this.textBoxShop.Size = new System.Drawing.Size(140, 23);
|
||||
this.textBoxShop.TabIndex = 9;
|
||||
//
|
||||
// textBoxDateOpening
|
||||
//
|
||||
this.textBoxDateOpening.Location = new System.Drawing.Point(386, 27);
|
||||
this.textBoxDateOpening.Name = "textBoxDateOpening";
|
||||
this.textBoxDateOpening.Size = new System.Drawing.Size(200, 23);
|
||||
this.textBoxDateOpening.TabIndex = 10;
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(607, 317);
|
||||
this.Controls.Add(this.textBoxDateOpening);
|
||||
this.Controls.Add(this.textBoxShop);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.textBoxDateOpening);
|
||||
this.Controls.Add(this.textBoxAddress);
|
||||
this.Controls.Add(this.label3);
|
||||
this.Controls.Add(this.label2);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
this.Controls.Add(this.comboBoxShop);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Name = "FormShop";
|
||||
this.Text = "Просмотр изделий магазина";
|
||||
@ -174,16 +172,16 @@
|
||||
#endregion
|
||||
|
||||
private Label label1;
|
||||
private ComboBox comboBoxShop;
|
||||
private DataGridView dataGridView;
|
||||
private Label label2;
|
||||
private Label label3;
|
||||
private TextBox textBoxAddress;
|
||||
private TextBox textBoxDateOpening;
|
||||
private Button buttonCancel;
|
||||
private Button buttonSave;
|
||||
private DataGridViewTextBoxColumn PackageName;
|
||||
private DataGridViewTextBoxColumn Price;
|
||||
private DataGridViewTextBoxColumn Count;
|
||||
}
|
||||
private TextBox textBoxShop;
|
||||
private DateTimePicker textBoxDateOpening;
|
||||
}
|
||||
}
|
@ -51,27 +51,20 @@ namespace SoftwareInstallationView
|
||||
_logger = logger;
|
||||
_listShops = logic.ReadList(null);
|
||||
_logic = logic;
|
||||
if (_listShops != null)
|
||||
{
|
||||
comboBoxShop.DisplayMember = "Name";
|
||||
comboBoxShop.ValueMember = "Id";
|
||||
comboBoxShop.DataSource = _listShops;
|
||||
comboBoxShop.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadData(bool extendDate = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
var model = GetShop(extendDate ? Id : Convert.ToInt32(comboBoxShop.SelectedValue));
|
||||
var model = GetShop(extendDate ? Id : Convert.ToInt32(null));
|
||||
if (model != null)
|
||||
{
|
||||
comboBoxShop.Text = model.Name;
|
||||
textBoxShop.Text = model.Name;
|
||||
textBoxAddress.Text = model.Address;
|
||||
textBoxDateOpening.Text = Convert.ToString(model.DateOpening);
|
||||
dataGridView.Rows.Clear();
|
||||
foreach (var el in model.Pastries.Values)
|
||||
foreach (var el in model.Packages.Values)
|
||||
{
|
||||
dataGridView.Rows.Add(new object[]{el.Item1.PackageName, el.Item1.Price, el.Item2 });
|
||||
}
|
||||
@ -86,14 +79,9 @@ namespace SoftwareInstallationView
|
||||
}
|
||||
}
|
||||
|
||||
private void ComboBoxShop_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
LoadData(false);
|
||||
}
|
||||
|
||||
private void ButtonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(comboBoxShop.Text))
|
||||
if (string.IsNullOrEmpty(textBoxShop.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните название", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
@ -111,7 +99,7 @@ namespace SoftwareInstallationView
|
||||
DateTime.TryParse(textBoxDateOpening.Text, out var dateTime);
|
||||
ShopBindingModel model = new()
|
||||
{
|
||||
Name = comboBoxShop.Text,
|
||||
Name = textBoxShop.Text,
|
||||
Address = textBoxAddress.Text,
|
||||
DateOpening = dateTime
|
||||
};
|
||||
@ -153,5 +141,5 @@ namespace SoftwareInstallationView
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,4 +66,13 @@
|
||||
<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>
|
||||
</root>
|
@ -28,7 +28,7 @@ namespace SoftwareInstallationView
|
||||
dataGridView.DataSource = list;
|
||||
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["Pastries"].Visible = false;
|
||||
dataGridView.Columns["Packages"].Visible = false;
|
||||
dataGridView.Columns["Name"].AutoSizeMode =
|
||||
DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user