CourseWorkKnapsack/forms/ParametersForm.cs

65 lines
1.8 KiB
C#
Raw Normal View History

2024-05-20 02:52:44 +04:00
using ProjectKnapsack.classes;
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;
using static ProjectKnapsack.classes.KnapsackParameters;
namespace ProjectKnapsack.forms;
public partial class ParametersForm : Form
{
public ParametersForm()
{
InitializeComponent();
}
private void okButton_Click(object sender, EventArgs e)
{
// После ввода всех предметов закрываем форму и передаем список предметов в основную форму
this.DialogResult = DialogResult.OK;
this.Close();
}
private void cancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void addItemButton_Click(object sender, EventArgs e)
{
itemsDataGridView.Rows.Add("", 0, 0); // Добавляем новую строку в DataGridView
}
public KnapsackParameters Parameters
{
get
{
var items = new List<Item>();
foreach (DataGridViewRow row in itemsDataGridView.Rows)
{
if (row.IsNewRow) continue;
var item = new Item
{
Name = row.Cells["Name"].Value?.ToString(),
Weight = Convert.ToInt32(row.Cells["Weight"].Value),
Value = Convert.ToInt32(row.Cells["Value"].Value)
};
items.Add(item);
}
return new KnapsackParameters
{
Capacity = (int)capacityNumericUpDown.Value,
Items = items
};
}
}
}