kursta yapmıstım bende buna dikkat et burada
bitane ClassSamle9
bide Form1.cs var(:
Form1.cs içindeki kos;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ClassSamle9
{
public partial class Form1 : Form
{
Chart _chart = new Chart();
public Form1()
{
InitializeComponent();
}
private void label3_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("Ürün Adı Boş Bırakılamaz!", "Eksik alan", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (textBox2.Text == "")
{
MessageBox.Show("Ürün Fiyatı Boş Bırakılamaz", "Eksik Alan", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (textBox3.Text == "")
{
MessageBox.Show("Ürün Miktarı Boş Bırakılamaz", "Eksik Alan", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
_chart.Add(textBox1.Text,int.Parse(textBox3.Text), decimal.Parse(textBox2.Text) );
textBox4.Text = _chart.GrandTotal().ToString();
listView1.Items.Clear();
foreach (Product _p in _chart)
{
ListViewItem _li = new ListViewItem(_p.Name);
_li.SubItems.Add(_p.Price.ToString());
_li.SubItems.Add(_p.Amount.ToString());
_li.SubItems.Add(_p.LineTotal().ToString());
listView1.Items.Add(_li);
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = null;
textBox2.Text = null;
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
}
}
ClassSample9 içindeki kodlar bunlar işine yarayacagına eminim.
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ClassSamle9
{
class Product
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private decimal _price;
public decimal Price
{
get { return _price; }
set { _price = value; }
}
private int _amount;
public int Amount
{
get { return _amount; }
set { _amount = value; }
}
public decimal LineTotal()
{
return _price * _amount;
}
public Product(string Name)
{
_name = Name;
}
public Product (string Name,int Amount,decimal Price)
{
_name=Name;
_price=Price;
_amount=Amount;
}
}
class Chart :CollectionBase
{
public void Add (Product ProductIstance)
{
this.List.Add(ProductIstance);
}
public Product Add(string Name,int Amount,decimal Price)
{
Product _temp = new Product( Name,Amount,Price);
this.List.Add(_temp);
return _temp;
}
public decimal GrandTotal()
{
decimal _total = 0;
foreach(Product _p in this.List)
_total+=_p.LineTotal();
return _total;
}
}
}