두 개의 클래스, ShoppingBasket 및 OrderItem, Form1 클래스가 있습니다. ShoppingBasket에서 사용하려는 OrderItem에 네 개의 속성이 있습니다. 어떻게해야합니까?폼에서 정보를 가져와 클래스의 속성에 할당 한 다음 다른 클래스의 메서드에서 사용해야합니다. 방법?
저는 ProductName에 대해 textBox1, Quantity에 대해서는 numericUpDown1, LatestPrice에 대해서는 textBox2를가집니다. Add 버튼을 누르면 listBox1에 추가 할 것입니다. 이렇게하려면 OrderItem 클래스에있는 속성을 어떻게 든 사용해야합니다. ProductName, Quantity, LatestPrice 및 TotalOrder (Quantity x LatestPrice가됩니다). 그런 다음 ShoppingBasket 클래스에있는 AddProduct 메서드에서 이러한 속성을 사용해야합니다.
도움을 주시면 감사하겠습니다.
를 Form1 :
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void addButton_Click(object sender, EventArgs e)
{
ShoppingBasket addButtonShoppingBasket = new ShoppingBasket();
addButtonShoppingBasket.AddProduct(textBox1.Text, Convert.ToDecimal(textBox2.Text), Convert.ToInt32(numericUpDown1.Value));
}
}
쇼핑 바구니 :
public class ShoppingBasket
{
public ShoppingBasket()
{
}
public void AddProduct(string productName, decimal latestProductValue, int quantity)
{
}
}
OrderItem에 : 당신이 ShoppingBasket
에 OrderItem
에 대한 컨테이너를 추가해야합니다 모든
public class OrderItem
{
public OrderItem(string productName, decimal latestPrice, int quantity)
{
ProductName = productName;
LatestPrice = latestPrice;
Quantity = quantity;
TotalOrder = latestPrice * quantity;
}
public string ProductName { get; set; }
public decimal LatestPrice { get; set; }
public int Quantity { get; set; }
public decimal TotalOrder { get; set; }
}
예))))) –