Müdavim Girişi

E-Posta
Parola

Ücretsiz Kayıt Ol


Online Müdavimler (0 Kişi)
  • Online Kişi Bulunmadı

Yazar Hakkında
x
İsmail Kocacan
İsmail Kocacan is experienced on many development platforms and continues to learn technologies. Since the age of 16-17, dealing with software technologies. And continuous learning, teaching, research, continues to develop.
Hiyerarşik Tasarım(Kategorileme) Windows Form Uygulaması

Bu makalemizde de C# programlama dilini kullanarak daha önce yazmis oldugum hiyerarsik verileri tutma ile ilgili bir makale vardi. O makalenin Windows Form’daki uygulamasi olacak. Yine Treeview Nesnesi kullanicaz. Ve Projemize 2 tane Form ekliyoruz. FrmMain de Agaç Yapisi olacak, FrmKayit Formunda da Kategoriler Tablosuna Nasil Kayit Girmeliyiz. Onun uygulamasi olacak

FrmMain. cs

namespace HiyerarsiTestx
{
    using System;
    using System.Data;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    public partial class FrmMain : Form
    {
      public static SqlConnection sconnx = new SqlConnection("server=.\\SQLExpress; database=KOBAY; integrated security=sspi");
      public static SqlCommand scommx = new SqlCommand();
      public static DataTable dtx = new DataTable();
        
        public FrmMain()
        {
            InitializeComponent();
            sconnx.Open();
            scommx.Connection = sconnx;
            this.KategorileriGetir();
        }
 
        public void KategorileriGetir()
        {
            scommx.CommandText = "select * from Kategoriler where UstKategoriNo=0";
            dtx.Load(scommx.ExecuteReader());
 
            foreach (DataRow rowItem in dtx.Rows)
            {
                string KategoriAd = rowItem["KategoriAd"].ToString();
                string KategoriNo = rowItem["KategoriNo"].ToString();
                treeView1.Nodes.Add(KategoriNo, KategoriAd);
            }
        }
 
 
        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            this.Secilenin_Altindakileri_Getir();
        }
 
        private void Secilenin_Altindakileri_Getir()
        {
                string KategoriNox = treeView1.SelectedNode.Name;
                dtx.Clear();
                scommx.CommandText = "select * from Kategoriler where UstKategoriNo=" + KategoriNox;
                dtx.Load(scommx.ExecuteReader());
 
                treeView1.SelectedNode.Nodes.Clear();
                foreach (DataRow rowItem in dtx.Rows)
                {
                    string KategoriAd = rowItem["KategoriAd"].ToString();
                    string KategoriNo = rowItem["KategoriNo"].ToString();
                    treeView1.SelectedNode.Nodes.Add(KategoriNo, KategoriAd);
                }
        }
 
        private void btnKategoriEkle_Click(object sender, EventArgs e)
        {
            FrmKayit objfrmx = new FrmKayit();
            objfrmx.Show();
        }
    }
}
 

 
FrmKayit. cs

namespace HiyerarsiTestx
{
    using System;
    using System.Data;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    public partial class FrmKayit : Form
    {
        SqlCommand scommx = new SqlCommand();
        DataTable dtx = new DataTable();
        public FrmKayit()
        {
            InitializeComponent();
            scommx.Connection = FrmMain.sconnx;
        }
 
        private void FrmKayit_Shown(object sender, EventArgs e)
        {
            this.KategorileriGetir();
        }
 
 
        private void KategorileriGetir()
        {
            scommx.CommandText = "select * from Kategoriler";
            dtx.Clear();
            dtx.Load(scommx.ExecuteReader());
            cmbCategoryName.Items.Clear();
            cmbdegerler.Items.Clear();
            cmbCategoryName.Items.Add("AnaKategori");
            cmbdegerler.Items.Add("0");
            foreach (DataRow rowItemx in dtx.Rows)
            {
                string KategoriAd = rowItemx["KategoriAd"].ToString();
                string KategoriNo = rowItemx["KategoriNo"].ToString();
               cmbCategoryName.Items.Add(KategoriAd);
                cmbdegerler.Items.Add(KategoriNo);
            }
        }
 
 
        private void btnKaydet_Click(object sender, EventArgs e)
        {
            scommx.CommandText = "insert into Kategoriler(KategoriAd,UstKategoriNo) values (@KategoriAd,@UstKategoriNo)";
            scommx.Parameters.AddWithValue("@KategoriAd", textBox1.Text.Trim());
            scommx.Parameters.AddWithValue("@UstKategoriNo", int.Parse(cmbdegerler.Text.Trim()));
            scommx.ExecuteNonQuery();
            scommx.Parameters.Clear();
            textBox1.Text = string.Empty;
            cmbCategoryName.SelectedIndex = 0;
            MessageBox.Show("Kaydedildi", "bilgi", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            this.Close();
        }
 
        private void cmbCategoryName_SelectedIndexChanged(object sender, EventArgs e)
        {
            cmbdegerler.SelectedIndex = cmbCategoryName.SelectedIndex;
        }
 
        private void btnCansel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
Sonuç Olarak;

 

Uygulamaya Ait Kaynak Kodlari Buradan indirebilirsiniz
Gördügünüz gibi istediginiz kadar kategori ekleyebilirsiniz. Ve Agacinizi olusturabilirsiniz. Ha bu arada agaci sulamayi unutmayin
 
ismailkocacan@gmail.com
Ismail Kocacan

Kategori : C#.Net & Vb.Net | 28.09.2010 14:49:00  | 1281 defa okundu  | 1 Yorum |

Yazara Ait Diğer Makaleler(51) Makaleye Yapılan Yorumlar Yorum Yazıcam
| 08.05.2011 21:02:00
çok yararlı bir çalışma olmuş....
Ara
 
Anket
Hangi VeriTabanı Yönetim Sistemini Kullanıyorsunuz ?