27 Haziran 2013 Perşembe
Kaydol:
Kayıt Yorumları
(
Atom
)
/////////////////////////////////////////////////////////////////////////////////
///Form1.cs
/////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace oop_personel_listeleme
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//context menü item kullanarak listeye sağ tıklayarak seçili personeli
//güncelleme
private void guncelleMenuItem_Click(object sender, EventArgs e)
{
if (lstPersoneller.SelectedItem == null) return;
Personeller personel = (Personeller)lstPersoneller.SelectedItem;
Form2 güncellemeFormu = new Form2();
güncellemeFormu.personel = personel;
this.Hide();
güncellemeFormu.ShowDialog();//f yi aç ve f kapanmadan burada bekle
this.Show();
ListeyiGoster();
}
//listeye eklenen personelleri bir arraylist içinde saklayalım
ArrayList personelListesi = new ArrayList();
//Kaydet butonuna tıklanınca girilen kişiyi personel listesine ve listbox ekleyalim
private void btnKaydet_Click(object sender, EventArgs e)
{
Personeller personel = new Personeller(txtAd.Text, txtSoyad.Text, byte.Parse(txtYas.Text));
personelListesi.Add(personel);
ListeyiGoster();
KutulariTemizle();
}
// listeye eklenen personelleri listbox da gösterelim.
private void ListeyiGoster()
{
lstPersoneller.Items.Clear();
lstPersoneller.Items.AddRange(personelListesi.ToArray());
}
//Kaydet butonuna basıldıktan sonra textbox kutucuklarını temizleyelim
private void KutulariTemizle()
{
foreach (Control item in groupBox1.Controls)
{
if (item is TextBox)
{
TextBox t = (TextBox)item;
t.Clear();
}
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////
///Form2.cs
/////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace oop_personel_listeleme
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public Personeller personel= null;
private void Form2_Load(object sender, EventArgs e)
{
txtAd.Text = personel.Ad;
txtSoyad.Text = personel.Soyad;
txtYas.Text = personel.Yas.ToString();
}
private void btnVazgec_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnKaydet_Click(object sender, EventArgs e)
{
if (personel != null)
{
personel.Ad = txtAd.Text;
personel.Soyad = txtSoyad.Text;
personel.Yas = byte.Parse(txtYas.Text);
this.Close();
}
}
}
}
/////////////////////////////////////////////////////////////////////////////////
///Personeller.cs
/////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace oop_personel_listeleme
{
//internal ya da public
//internal içinde bulunduğun namesace de erişilebilir anlamındadır
public class Personeller
{
//public private internal
//private içinde bulunduğun class içinde erişilebilir
//fields - alanlar :
private string ad;
private string soyad;
private byte yas;
//Properties - özellikler :
public string Ad
{
get { return ad; }
set { ad = value; }
}
public string Soyad
{
get { return this.soyad; }
set { this.soyad = value; }
}
public byte Yas
{
get { return this.yas; }
set { this.yas = value; }
}
public Personeller(string isim,string soyisim,byte yasi)
{
//constructor 1
this.Ad = isim;
this.Soyad = soyisim;
this.Yas = yasi;
}
public Personeller()
{
//constructor 2
}
public Personeller(Personeller personel)
{
//constructor 3
this.Ad = personel.Ad;
this.Soyad = personel.Soyad;
this.Yas = personel.Yas;
}
public override string ToString()
{
return this.Ad + " " + this.Soyad;
}
}
}
Hiç yorum yok :
Yorum Gönder