C# Öğrenci Sınıf Yönetimi

Discussion in 'Programlama' started by ......, Aug 5, 2009.

  1. ......

    ...... Misafir

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Configuration;
    using System.Text;
    using System.Windows.Forms;
    using mysqlBaglantiNesnesi;
    using System.Data.SqlClient;
    using MySql.Data.MySqlClient;
    
    namespace OgrenciSinifYonetimi
    {
        public partial class OgrenciEkle : Form
        {
            mySqlBaglanti myBaglanti;
            string BaglantiMetni;
            string sqlText;
            MySqlConnection myCon;
            string secilenId;
            public OgrenciEkle()
            {
                InitializeComponent();
            }
    
            private void OgrenciEkle_Load(object sender, EventArgs e)
            {
                BaglantiMetni = ConfigurationSettings.AppSettings["baglantiMetni"];
                myBaglanti = new mySqlBaglanti(BaglantiMetni);
                myCon= new MySqlConnection(BaglantiMetni);
                ogrenciListesi();
            }
    
            private void yeniKayitButton_Click(object sender, EventArgs e)
            {
                sqlText = string.Format("INSERT INTO ogrenci(ogrenciad,ogrenciveliad,yas) VALUES('{0}','{1}','{2}');", textBox1.Text, textBox2.Text, comboBox1.Text);
                myBaglanti.baglantiAc();
                myBaglanti.SorguYaz(sqlText);
                myBaglanti.baglantiKapat();
                textTemizle();
                ogrenciListesi();
            }
    
            void textTemizle()
            {
                textBox1.Text = "";
                textBox2.Text = "";
                comboBox1.Text = "";
            }
    
    
            void ogrenciListesi()
            {
              sqlText="SELECT * FROM ogrenci";
              MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(sqlText, myCon);
              DataTable myDataTable = new DataTable();
              myDataAdapter.Fill(myDataTable);
              dataGrid1.DataSource = myDataTable;
            }
    
            private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
            {
               secilenId = dataGrid1[dataGrid1.CurrentRowIndex, 0].ToString();
               textBox1.Text=dataGrid1[dataGrid1.CurrentRowIndex,1].ToString();
               textBox2.Text = dataGrid1[dataGrid1.CurrentRowIndex, 2].ToString();
               comboBox1.Text = dataGrid1[dataGrid1.CurrentRowIndex, 3].ToString();
            }
    
            private void KaydetButton_Click(object sender, EventArgs e)
            {
                sqlText = string.Format("Update ogrenci Set ogrenciad='{0}',ogrenciveliad='{1}',yas='{2}' WHERE ogrenciid={3}", textBox1.Text, textBox2.Text, comboBox1.Text,secilenId);
                myBaglanti.baglantiAc();
                myBaglanti.SorguYaz(sqlText);
                myBaglanti.baglantiKapat();
                textTemizle();
                ogrenciListesi();
            }
    
            private void silButton_Click(object sender, EventArgs e)
            {
                sqlText = string.Format("DELETE FROM ogrenci WHERE ogrenciid={0}",secilenId);
                myBaglanti.baglantiAc();
                myBaglanti.SorguYaz(sqlText);
                myBaglanti.baglantiKapat();
                textTemizle();
                ogrenciListesi();
            }
        }
    }
     

Share This Page