27 Nisan 2020 Pazartesi

Eczane Programı Projesi Cevap Anahtarı

        OleDbConnection bağlantı = new OleDbConnection("Provider=Microsoft.Ace.OleDb.12.0;Data Source=Eczane.accdb");
        DataTable Tablo = new DataTable();
        OleDbCommand Komut = new OleDbCommand();

        private void Listele()
        {
            OleDbDataAdapter Kayıt = new OleDbDataAdapter("Select * From İlaçlar", bağlantı);
            Tablo.Clear();
            Kayıt.Fill(Tablo);
            dataGridView1.DataSource = Tablo;
        }

        private void Okuma()
        {
            OleDbDataReader oku;
            comboBox1.Items.Clear();

            bağlantı.Open();
            OleDbCommand Komut = new OleDbCommand();
            Komut.Connection = bağlantı;
            Komut.CommandText = "Select * From İlaçlar";

            oku = Komut.ExecuteReader();
            while (oku.Read())
            {
                comboBox1.Items.Add(oku["HastaAdıSoyadı"].ToString());
                comboBox2.Items.Add(oku["DoktorAdıSoyadı"].ToString());
            }
            bağlantı.Close();
        }

        private void Temizle()
        {
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            textBox4.Clear();
        }  
        private void Form1_Load(object sender, EventArgs e)
        {
            Listele();
            Okuma();
            //Hücreleri satır satır seçmek için
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bağlantı.Open();
            Komut.Connection = bağlantı;

            Komut.CommandText = "INSERT INTO İlaçlar (BarkodNo, İlaçAdı, Fiyatı, KullanımYeri, KullanımŞekli, HastaAdıSoyadı, DoktorAdıSoyadı) VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "', '" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "')";

            Komut.ExecuteNonQuery();
            bağlantı.Close();
            Listele();
            Okuma();
            Temizle();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bağlantı.Open();
            Komut.Connection = bağlantı;

            Komut.CommandText = "DELETE From İlaçlar WHERE BarkodNo='"+ dataGridView1.CurrentRow.Cells[0].Value.ToString() + "'";

            Komut.ExecuteNonQuery();
            bağlantı.Close();
            Listele();
            Okuma();
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            textBox1.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            textBox2.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
            textBox3.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
            textBox4.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
            textBox5.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
            textBox6.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString();
            textBox7.Text = dataGridView1.CurrentRow.Cells[6].Value.ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            bağlantı.Open();

            Komut.Connection = bağlantı;

            Komut.CommandText = "UPDATE İlaçlar SET BarkodNo='"+ textBox1.Text + "', İlaçAdı='" + textBox2.Text +"', Fiyatı='" + textBox3.Text + "', KullanımYeri='" +textBox4.Text + "', KullanımŞekli='" + textBox5.Text +"', HastaAdıSoyadı='" + textBox6.Text + "', DoktorAdıSoyadı='" +textBox7.Text + "' WHERE BarkodNo='"+dataGridView1.CurrentRow.Cells[0].Value.ToString()+"'";

            Komut.ExecuteNonQuery();
            bağlantı.Close();
            Listele();
            Okuma();
        }

        private void textBox8_TextChanged(object sender, EventArgs e)
        {
            OleDbDataAdapter Kayıt = new OleDbDataAdapter ("Select * From İlaçlar WHERE İlaçAdı Like '%" + textBox8.Text + "%'", bağlantı);

            Tablo.Clear();
            Kayıt.Fill(Tablo);
            dataGridView1.DataSource = Tablo;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            OleDbDataAdapter Kayıt = new OleDbDataAdapter("Select * From İlaçlar WHERE HastaAdıSoyadı='" + comboBox1.Text + "'", bağlantı);

            Tablo.Clear();
            Kayıt.Fill(Tablo);
            dataGridView1.DataSource = Tablo;
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            OleDbDataAdapter Kayıt = new OleDbDataAdapter("Select * From İlaçlar WHERE DoktorAdıSoyadı='" + comboBox2.Text + "'", bağlantı);

            Tablo.Clear();
            Kayıt.Fill(Tablo);
            dataGridView1.DataSource = Tablo;
        }

Hiç yorum yok:

Yorum Gönder