From 35856195e8cc13cc5087854c81d1dd789e1924a3 Mon Sep 17 00:00:00 2001 From: m1aksim1 Date: Sat, 18 Mar 2023 00:29:38 +0400 Subject: [PATCH] fix --- .../ShopLogic.cs | 12 ++--- .../BindingModels/ShopBindingModel.cs | 2 +- .../ViewModels/ShopViewModel.cs | 2 +- .../IShopModel.cs | 2 +- .../SoftwareInstallationListImplement/Shop.cs | 8 ++-- .../FormAddPackageInShop.Designer.cs | 32 ++++++------- .../FormAddPackageInShop.cs | 30 ++++++------ .../FormShop.Designer.cs | 48 +++++++++---------- .../SoftwareInstallationView/FormShop.cs | 24 +++------- .../SoftwareInstallationView/FormShop.resx | 9 ++++ .../SoftwareInstallationView/FormViewShops.cs | 2 +- 11 files changed, 82 insertions(+), 89 deletions(-) diff --git a/SoftwareInstallation/SoftwareInstallationBusinessLogic/ShopLogic.cs b/SoftwareInstallation/SoftwareInstallationBusinessLogic/ShopLogic.cs index 7c54e22..1958036 100644 --- a/SoftwareInstallation/SoftwareInstallationBusinessLogic/ShopLogic.cs +++ b/SoftwareInstallation/SoftwareInstallationBusinessLogic/ShopLogic.cs @@ -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; } diff --git a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ShopBindingModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ShopBindingModel.cs index 7923811..39ffccd 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ShopBindingModel.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/BindingModels/ShopBindingModel.cs @@ -11,7 +11,7 @@ namespace SoftwareInstallationContracts.BindingModels public DateTime DateOpening { get; set; } = DateTime.Now; - public Dictionary Pastries + public Dictionary Packages { get; set; diff --git a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ShopViewModel.cs b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ShopViewModel.cs index 16ebf6a..e95f4fc 100644 --- a/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ShopViewModel.cs +++ b/SoftwareInstallation/SoftwareInstallationContracts/ViewModels/ShopViewModel.cs @@ -15,7 +15,7 @@ namespace SoftwareInstallationContracts.ViewModels [DisplayName("Время открытия")] public DateTime DateOpening { get; set; } = DateTime.Now; - public Dictionary Pastries + public Dictionary Packages { get; set; diff --git a/SoftwareInstallation/SoftwareInstallationDataModels/IShopModel.cs b/SoftwareInstallation/SoftwareInstallationDataModels/IShopModel.cs index d7a0513..6e1a918 100644 --- a/SoftwareInstallation/SoftwareInstallationDataModels/IShopModel.cs +++ b/SoftwareInstallation/SoftwareInstallationDataModels/IShopModel.cs @@ -7,6 +7,6 @@ namespace SoftwareInstallationDataModels string Name { get; } string Address { get; } DateTime DateOpening { get; } - Dictionary Pastries { get; } + Dictionary Packages { get; } } } diff --git a/SoftwareInstallation/SoftwareInstallationListImplement/Shop.cs b/SoftwareInstallation/SoftwareInstallationListImplement/Shop.cs index ba18c06..0aca083 100644 --- a/SoftwareInstallation/SoftwareInstallationListImplement/Shop.cs +++ b/SoftwareInstallation/SoftwareInstallationListImplement/Shop.cs @@ -13,7 +13,7 @@ namespace SoftwareInstallationListImplement public DateTime DateOpening { get; private set; } - public Dictionary Pastries + public Dictionary 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, }; } diff --git a/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.Designer.cs index fe10656..9cc9fb8 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.Designer.cs @@ -28,11 +28,11 @@ /// 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; diff --git a/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.cs b/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.cs index d64f927..905a6a3 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormAddPackageInShop.cs @@ -21,7 +21,7 @@ namespace SoftwareInstallationView private readonly IShopLogic _shopLogic; private readonly IPackageLogic _packageLogic; private readonly List? _listShops; - private readonly List? _listPastries; + private readonly List? _listPackages; public FormAddPackageInShop(ILogger 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 ); diff --git a/SoftwareInstallation/SoftwareInstallationView/FormShop.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormShop.Designer.cs index b60d0e6..024d9ae 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormShop.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormShop.Designer.cs @@ -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; + } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormShop.cs b/SoftwareInstallation/SoftwareInstallationView/FormShop.cs index 188449a..85e4904 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormShop.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormShop.cs @@ -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(); } - } + } } diff --git a/SoftwareInstallation/SoftwareInstallationView/FormShop.resx b/SoftwareInstallation/SoftwareInstallationView/FormShop.resx index 18dd2ed..34d94db 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormShop.resx +++ b/SoftwareInstallation/SoftwareInstallationView/FormShop.resx @@ -66,4 +66,13 @@ True + + True + + + True + + + True + \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallationView/FormViewShops.cs b/SoftwareInstallation/SoftwareInstallationView/FormViewShops.cs index 4c2bd8b..1612a8e 100644 --- a/SoftwareInstallation/SoftwareInstallationView/FormViewShops.cs +++ b/SoftwareInstallation/SoftwareInstallationView/FormViewShops.cs @@ -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; }