Untitled

mail@pastecode.io avatar
unknown
csharp
4 years ago
4.9 kB
70
Indexable
Never
namespace OtoGaleriOtomasyonu
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        OleDbConnection vt_baglantisi = new OleDbConnection("Provider= Microsoft.ACE.OleDb.12.0;Data Source=" + Application.StartupPath + "\\VT_OtoGaleri.accdb");
        private void btn_Kapat_Click(object sender, EventArgs e)
        {
            this.Close();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            KAYIT_LISTELE();

            string[] markalar = { "TOYOTA", "FORD", "VOLKSWAGEN" };
            cmb_Marka.Items.AddRange(markalar);

            cmb_KasaTipi.Items.Add("SEDAN");
            cmb_KasaTipi.Items.Add("HATCHBACK");
        }

        private void cmb_Marka_SelectedIndexChanged(object sender, EventArgs e)
        {
            cmb_Model.Items.Clear();
            string marka = cmb_Marka.SelectedItem.ToString();
            if (marka == "TOYOTA")
            {
                string[] model = { "AURIS", "YARIS", "COROLLA" };
                cmb_Model.Items.AddRange(model);
            }
            else if (marka == "FORD")
            {
                string[] model = { "FOCUS", "MONDEO", "RANGER" };
                cmb_Model.Items.AddRange(model);
            }
            else if (marka == "VOLKSWAGEN")
            {
                string[] model = { "GOLF", "PASSAT", "TUAREG" };
                cmb_Model.Items.AddRange(model);
            }
        }
        private void KAYIT_LISTELE()
        {
            try
            {
                vt_baglantisi.Open();
                OleDbDataAdapter listele = new OleDbDataAdapter("SELECT *FROM araclar", vt_baglantisi);
                DataSet dsHafiza = new DataSet();
                listele.Fill(dsHafiza);
                dgw_Araclar.DataSource = dsHafiza.Tables[0];
                vt_baglantisi.Close();
            }
            catch (Exception hataMsj)
            {
                MessageBox.Show(hataMsj.Message);
                vt_baglantisi.Close();
            }
        }

        private void btn_Kaydet_Click(object sender, EventArgs e)
        {
            try
            {
                vt_baglantisi.Open();
                OleDbDataAdapter kaydet = new OleDbDataAdapter("INSERT INTO araclar (ruhsatNo, marka, model, yakit_tipi, kasa_tipi, km, fiyat  )" +
                " VALUES ('" + txt_RuhsatNo.Text + "','" + cmb_Marka.SelectedItem.ToString() + "','" + cmb_Model.SelectedItem.ToString()
                + "','" + cmb_YakitTipi.SelectedItem.ToString() + "','" + cmb_KasaTipi.SelectedItem.ToString() + "','" + txt_Km.Text + "','" + txt_Fiyat.Text + "')", vt_baglantisi);
                DataSet dsHafiza = new DataSet();
                kaydet.Fill(dsHafiza);
                vt_baglantisi.Close();
                MessageBox.Show("Kayıt işlemi başarılı...");
                txt_RuhsatNo.Clear();
                txt_Km.Clear();
                txt_Fiyat.Clear();
                KAYIT_LISTELE();
            }
            catch (Exception hataMsj)
            {
                MessageBox.Show(hataMsj.Message);
                vt_baglantisi.Close();
            }
        }

        private void btn_Sil_Click(object sender, EventArgs e)
        {
            try
            {
                vt_baglantisi.Open();
                OleDbDataAdapter sil = new OleDbDataAdapter("DELETE FROM araclar WHERE ruhsatNo='"+txt_RuhsatNo.Text+"'", vt_baglantisi);
                DataSet dsHafiza = new DataSet();
                sil.Fill(dsHafiza);
                vt_baglantisi.Close();
                MessageBox.Show("Araç Veri Tabanından Silindi");
                KAYIT_LISTELE();
                
            }
            catch (Exception hataMsj)
            {
                MessageBox.Show(hataMsj.Message);
                vt_baglantisi.Close();
            }
        }

        private void btn_FiyatGuncelle_Click(object sender, EventArgs e)
        {
            try
            {
                vt_baglantisi.Open();
                OleDbDataAdapter guncelle = new OleDbDataAdapter("UPDATE araclar SET fiyat='"+txt_Fiyat.Text+"' WHERE ruhsatNo='"+txt_RuhsatNo+"'", vt_baglantisi);
                DataSet dsHafiza = new DataSet();
                guncelle.Fill(dsHafiza);
                vt_baglantisi.Close();
                MessageBox.Show("Araç Fiyat Bilgisi Veri Tabanında Guncellendi","İşlem Başarılı", MessageBoxButtons.OK, MessageBoxIcon.Information );
                KAYIT_LISTELE();
            }
            catch (Exception hataMsj)
            {
                MessageBox.Show(hataMsj.Message);
                vt_baglantisi.Close();
            }
        }
    }
}