private void button_kaydet_Click(object sender, EventArgs e) { if (textBox_plaka.BackColor == Color.Red) { toolStripStatusLabel_kayit_durum.Text = "Eksik alanları kontrol ediniz."; return; } if (textBox_koltuk_sayisi.Text.Length == 0) { textBox_koltuk_sayisi.BackColor = Color.Red; toolStripStatusLabel_kayit_durum.Text = "Eksik alanları kontrol ediniz."; return; } Otobusler otobus = new Otobusler(); otobus.Plaka = textBox_plaka.Text; otobus.KoltukSayisi = Convert.ToByte(textBox_koltuk_sayisi.Text); otobus.MarkaID = (comboBox_marka.SelectedItem as Markalar).ID; otobus.AktifMi = checkBox_aktifMi.Checked; try { ctx.Otobuslers.InsertOnSubmit(otobus); ctx.SubmitChanges(); toolStripStatusLabel_kayit_durum.Text = "Yeni otobüs başarı ile eklendi."; textBox_plaka.Text = ""; textBox_koltuk_sayisi.Text = ""; textBox_koltuk_sayisi.BackColor = Color.White; } catch (Exception ex) { Form_ana_ekran.HataKaydi(ex); toolStripStatusLabel_kayit_durum.Text = "Ekleme başarısız."; } }
private void dataGridView_otobusler_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (e.RowIndex < 0) { button_guncelle.Enabled = false; return; } button_guncelle.Enabled = true; int otobus_id = Convert.ToInt32(dataGridView_otobusler.Rows[e.RowIndex].Cells[0].Value); otobus = ctx.Otobuslers.Where(o => o.ID == otobus_id).Select(o => o).First(); label_otobusID.Text = otobus_id.ToString(); textBox_plaka.Text = otobus.Plaka; label_koltukSayisi.Text = otobus.KoltukSayisi.ToString(); label_marka.Text = ctx.Markalars.Where(m => m.ID == otobus.MarkaID).Select(m => m.MarkaAd).First(); checkBox_aktifMi.Checked = otobus.AktifMi; }