diff --git a/DatabaseImplement/Models/Supplier.cs b/DatabaseImplement/Models/Supplier.cs index 90f461d..247731b 100644 --- a/DatabaseImplement/Models/Supplier.cs +++ b/DatabaseImplement/Models/Supplier.cs @@ -56,7 +56,7 @@ namespace DatabaseImplement.Models public void Update(Database context, SupplierBindingModel model) { Name = model.Name; - + Deals = model.Deals; Debug.WriteLine(model.AvailibleProducts.Keys); Products = model.AvailibleProducts.Select(x => new SupplierProduct @@ -86,7 +86,7 @@ namespace DatabaseImplement.Models { var newList = new List(); var trueCount = model.AvailibleProducts.Count; - for (int i = 0; i < trueCount; i++) + for (int i = 0; i < trueCount; i++) { newList.Add(supplierProducts[i]); } @@ -97,7 +97,7 @@ namespace DatabaseImplement.Models foreach (var item in supplierProducts) { bool flag = false; - foreach(var product in model.AvailibleProducts) + foreach (var product in model.AvailibleProducts) { if (product.Value.Item1.Id == item.ProductId) { diff --git a/WinFormsApp/FormSuppliers.Designer.cs b/WinFormsApp/FormSuppliers.Designer.cs index c890be7..95de5e8 100644 --- a/WinFormsApp/FormSuppliers.Designer.cs +++ b/WinFormsApp/FormSuppliers.Designer.cs @@ -33,7 +33,7 @@ label3 = new Label(); numericUpDownDeals = new NumericUpDown(); groupBoxSupplierProducts = new GroupBox(); - buttonRefresh = new Button(); + buttonDeleteProduct = new Button(); label2 = new Label(); buttonCancel = new Button(); label1 = new Label(); @@ -41,8 +41,6 @@ numericUpDownCount = new NumericUpDown(); comboBoxProducts = new ComboBox(); dataGridViewProducts = new DataGridView(); - Column = new DataGridViewTextBoxColumn(); - Column2 = new DataGridViewTextBoxColumn(); buttonAddSupplierProduct = new Button(); textBoxName = new TextBox(); groupBoxControls = new GroupBox(); @@ -50,6 +48,9 @@ buttonUpdateSupplier = new Button(); buttonCreateSupplier = new Button(); dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + Column = new DataGridViewTextBoxColumn(); + Column2 = new DataGridViewTextBoxColumn(); groupBoxCreateSupplier.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)numericUpDownDeals).BeginInit(); groupBoxSupplierProducts.SuspendLayout(); @@ -103,7 +104,7 @@ // // groupBoxSupplierProducts // - groupBoxSupplierProducts.Controls.Add(buttonRefresh); + groupBoxSupplierProducts.Controls.Add(buttonDeleteProduct); groupBoxSupplierProducts.Controls.Add(label2); groupBoxSupplierProducts.Controls.Add(buttonCancel); groupBoxSupplierProducts.Controls.Add(label1); @@ -119,15 +120,15 @@ groupBoxSupplierProducts.TabStop = false; groupBoxSupplierProducts.Text = "Доступные товары поставщика"; // - // buttonRefresh + // buttonDeleteProduct // - buttonRefresh.Location = new Point(58, 307); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(81, 23); - buttonRefresh.TabIndex = 14; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += buttonRefresh_Click; + buttonDeleteProduct.Location = new Point(58, 307); + buttonDeleteProduct.Name = "buttonDeleteProduct"; + buttonDeleteProduct.Size = new Size(81, 23); + buttonDeleteProduct.TabIndex = 15; + buttonDeleteProduct.Text = "Удалить"; + buttonDeleteProduct.UseVisualStyleBackColor = true; + buttonDeleteProduct.Click += buttonDeleteProduct_Click; // // label2 // @@ -186,26 +187,13 @@ // dataGridViewProducts // dataGridViewProducts.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridViewProducts.Columns.AddRange(new DataGridViewColumn[] { Column, Column2 }); + dataGridViewProducts.Columns.AddRange(new DataGridViewColumn[] { ColumnId, Column, Column2 }); dataGridViewProducts.Dock = DockStyle.Top; dataGridViewProducts.Location = new Point(3, 19); dataGridViewProducts.Name = "dataGridViewProducts"; dataGridViewProducts.Size = new Size(355, 195); dataGridViewProducts.TabIndex = 8; // - // Column - // - Column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - Column.HeaderText = "Продукт"; - Column.Name = "Column"; - Column.ReadOnly = true; - // - // Column2 - // - Column2.HeaderText = "Кол-во"; - Column2.Name = "Column2"; - Column2.ReadOnly = true; - // // buttonAddSupplierProduct // buttonAddSupplierProduct.Location = new Point(58, 278); @@ -276,6 +264,25 @@ dataGridView.Size = new Size(392, 637); dataGridView.TabIndex = 4; // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; + // + // Column + // + Column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + Column.HeaderText = "Продукт"; + Column.Name = "Column"; + Column.ReadOnly = true; + // + // Column2 + // + Column2.HeaderText = "Кол-во"; + Column2.Name = "Column2"; + Column2.ReadOnly = true; + // // FormSuppliers // AutoScaleDimensions = new SizeF(7F, 15F); @@ -317,11 +324,12 @@ private Label label2; private Label label1; private NumericUpDown numericUpDownCount; - private DataGridViewTextBoxColumn Column; - private DataGridViewTextBoxColumn Column2; private Label label4; private Label label3; private NumericUpDown numericUpDownDeals; - private Button buttonRefresh; + private Button buttonDeleteProduct; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn Column; + private DataGridViewTextBoxColumn Column2; } } \ No newline at end of file diff --git a/WinFormsApp/FormSuppliers.cs b/WinFormsApp/FormSuppliers.cs index 74347e2..9702ec8 100644 --- a/WinFormsApp/FormSuppliers.cs +++ b/WinFormsApp/FormSuppliers.cs @@ -57,7 +57,7 @@ namespace WinFormsApp dataGridViewProducts.Rows.Clear(); foreach (var pc in _supplierProducts) { - dataGridViewProducts.Rows.Add(new object[] { pc.Value.Item1.Name, pc.Value.Item2 }); + dataGridViewProducts.Rows.Add(new object[] { pc.Key, pc.Value.Item1.Name, pc.Value.Item2 }); } } @@ -230,7 +230,7 @@ namespace WinFormsApp { LoadData(); _id = null; - _supplierProducts = new Dictionary; + _supplierProducts = new Dictionary(); textBoxName.Text = string.Empty; numericUpDownDeals.Value = 0; //groupBoxControls.Enabled = true; @@ -241,9 +241,28 @@ namespace WinFormsApp } } - private void buttonRefresh_Click(object sender, EventArgs e) + private void buttonDeleteProduct_Click(object sender, EventArgs e) { - LoadSupplierData(); + if (dataGridViewProducts.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление продукта из списка доступных продуктов поставщика"); + Debug.WriteLine(_supplierProducts.Keys); + Debug.WriteLine(_supplierProducts.Values); + Debug.WriteLine((Guid)dataGridView.SelectedRows[0].Cells[0].Value); + _supplierProducts?.Remove((Guid)dataGridView.SelectedRows[0].Cells[0].Value); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadSupplierData(); + } + } } } } diff --git a/WinFormsApp/FormSuppliers.resx b/WinFormsApp/FormSuppliers.resx index ab04799..2d7aaa2 100644 --- a/WinFormsApp/FormSuppliers.resx +++ b/WinFormsApp/FormSuppliers.resx @@ -117,6 +117,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + True