private void button1_Click(object sender, EventArgs e) { if (EmptyControl()) { MessageBox.Show("Boş alan bırakmayınız.."); } else if (eTCTB.Text.Trim().Length != 11) { MessageBox.Show("Lütfen 11 haneli TC Kimlik numarasını doğru bir değer girin!"); } else { using (OtodelContext otodelContext = new OtodelContext()) { otodelContext.Employees.Add(new Employee { EmployeeID = eTCTB.Text, EmployeeMail = eEmailTB.Text, Password = ePasswordTB.Text, FirstName = eFirstNameTB.Text, LastName = eLastNameTB.Text, EmployeeRank = eRankCB.Text }); otodelContext.SaveChanges(); GetEmployees(); MessageBox.Show("Kayıt başarılı!"); } } }
private void CAddBT_Click(object sender, EventArgs e) { if (EmptyControl()) { using (OtodelContext otodelContext = new OtodelContext()) { if (otodelContext.Customers.Find(CTCTB.Text.Trim()) == null) { otodelContext.Customers.Add(new Customer { CustomerID = CTCTB.Text, FirstName = CFirstNameTB.Text, LastName = CLastNameTB.Text, Phone = CPhoneTB.Text, Gender = CGenderMRB.Checked ? true : false }); otodelContext.SaveChanges(); GetCustomers(); MessageBox.Show("Kayıt başarılı!"); } else { MessageBox.Show("Bu TC Kimlik numarasında bir kayıt zaten oluşturulmuş!"); } } } else { MessageBox.Show("Boş alan bırakmayınız!"); } }
private void CDeleteBT_Click(object sender, EventArgs e) { if (CTCTB.Text.Trim() == "") { MessageBox.Show("Lütfen silmek istediğiniz kullanıcının TC Kimlik numarasını girin!"); } else { using (OtodelContext otodelContext = new OtodelContext()) { Customer customer = otodelContext.Customers.Find(CTCTB.Text); if (customer == null) { MessageBox.Show("Bu TC Kimlik numarasında bir kullanıcı bulunamadı!"); } else { DialogResult dialogResult = MessageBox.Show( String.Format("{0} TC Kimlik numaralı kişiyi silmek istiyor musunuz?", CTCTB.Text.Trim(), CFirstNameTB.Text, CLastNameTB.Text), "Kullanıcı siliniyor!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning ); if (dialogResult == DialogResult.Yes) { otodelContext.Customers.Remove(customer); otodelContext.SaveChanges(); GetCustomers(); MessageBox.Show("Silme başarılı!"); } } } } }
private void CUpdateBT_Click(object sender, EventArgs e) { if (EmptyControl()) { using (OtodelContext otodelContext = new OtodelContext()) { Customer customer = otodelContext.Customers.Find(CTCTB.Text); if (customer == null) { MessageBox.Show("Bu TC Kimlik numarasında bir kullanıcı bulunamadı!"); } else { customer.FirstName = CFirstNameTB.Text; customer.LastName = CLastNameTB.Text; customer.Phone = CPhoneTB.Text; customer.Gender = CGenderFRB.Checked ? false : true; otodelContext.SaveChanges(); GetCustomers(); MessageBox.Show("Güncelleme başarılı!"); } } } else { MessageBox.Show("Boş alan bırakmayınız!"); } }
public void GetExpeditions(string expeditionSearch = "") { listView1.Items.Clear(); listView1.View = View.Details; listView1.FullRowSelect = true; listView1.GridLines = true; using (var otodelContext = new OtodelContext()) { var ExpeditionResult = from expeditions in otodelContext.Expeditions join citiesTO in otodelContext.Cities on expeditions.CityTakeOff_CityID equals citiesTO.CityID join citiesCT in otodelContext.Cities on expeditions.CityToGo_CityID equals citiesCT.CityID join buses in otodelContext.Buses on expeditions.Bus.BusPlate equals buses.BusPlate select new { expeditions, citiesTO, citiesCT, buses }; foreach (var expedition in ExpeditionResult) { ListViewItem listViewItem = new ListViewItem(); listViewItem.Text = expedition.expeditions.ExpeditionID; listViewItem.SubItems.Add(expedition.expeditions.TakeOffTime.ToString()); listViewItem.SubItems.Add(expedition.expeditions.CameTime.ToString()); listViewItem.SubItems.Add(expedition.expeditions.Price.ToString()); listViewItem.SubItems.Add(expedition.expeditions.ExpeditionDate.ToString()); listViewItem.SubItems.Add(expedition.expeditions.Bus.BusPlate.ToString()); listViewItem.SubItems.Add(expedition.citiesTO.CityName.ToString()); listViewItem.SubItems.Add(expedition.citiesCT.CityName.ToString()); listView1.Items.Add(listViewItem); } } }
private void button3_Click(object sender, EventArgs e) { if (eTCTB.Text.Trim() == "" || eTCTB.Text.Trim().Length != 11) { MessageBox.Show("Doğru bir TC Kimlik numarası girin"); } else { using (OtodelContext otodelContext = new OtodelContext()) { Employee employee = otodelContext.Employees.Find(eTCTB.Text.Trim()); if (employee is null) { MessageBox.Show("Böyle bir personel bulunamadı"); } else { DialogResult ds = MessageBox.Show(employee.EmployeeID + " numaralı " + employee.FirstName + " " + employee.LastName + " bilgilerini silmek ister misiniz?", "Personel siliniyor", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (ds == DialogResult.Yes) { otodelContext.Employees.Remove(employee); otodelContext.SaveChanges(); GetEmployees(); MessageBox.Show("Silme işlemi başarılı"); } } } } }
private void button2_Click(object sender, EventArgs e) { if (EmptyControl()) { MessageBox.Show("Boş alan bırakmayınız.."); } else if (eTCTB.Text.Trim().Length != 11) { MessageBox.Show("Lütfen 11 haneli TC Kimlik numarasını doğru bir değer girin!"); } else { using (OtodelContext otodelContext = new OtodelContext()) { Employee employee = otodelContext.Employees.Find(eTCTB.Text); if (employee is null) { MessageBox.Show("Böyle bir personel bulunamadı"); } else { employee.EmployeeMail = eEmailTB.Text.Trim(); employee.Password = ePasswordTB.Text.Trim(); employee.FirstName = eFirstNameTB.Text.Trim(); employee.LastName = eLastNameTB.Text.Trim(); employee.EmployeeRank = eRankCB.Text; otodelContext.SaveChanges(); GetEmployees(); MessageBox.Show("Güncelleme başarılı!"); } } } }
private void DeleteExpeditionBTN_Click(object sender, EventArgs e) { using (var otodelContext = new OtodelContext()) { if (HiddenExpeditionIDLB.Text.Trim() == "") { MessageBox.Show("Sefer seçilmemiş!"); } else { var TicketsResult = from tickets in otodelContext.Tickets join expedition in otodelContext.Expeditions on tickets.Expedition.ExpeditionID equals expedition.ExpeditionID where expedition.ExpeditionID == HiddenExpeditionIDLB.Text select tickets; if (TicketsResult.Count() > 0) { DialogResult dialogResult = MessageBox.Show( String.Format("{0} numaralı {1} - {2} sefere ait biletler bulunmakta!!! Eğer bu seferi silerseniz, biletler de silinecek. Hala devam etmek istiyor musunuz?", HiddenExpeditionIDLB.Text, TOTimeCitiesCB.SelectedItem, CTCitiesCB.SelectedItem), "Sefere ait bilet var!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning ); if (dialogResult == DialogResult.Yes) { Expedition expedition = otodelContext.Expeditions.Find(HiddenExpeditionIDLB.Text); foreach (var ticketResult in TicketsResult) { otodelContext.Tickets.Remove(ticketResult); } otodelContext.Expeditions.Remove(expedition); otodelContext.SaveChanges(); HiddenExpeditionIDLB.Text = ""; GetExpeditions(); MessageBox.Show("Silme işlemi başarılı!"); } } else { DialogResult dialogResult = MessageBox.Show( String.Format("{0} numaralı {1} - {2} seferi silmek istediğinize emin misiniz?", HiddenExpeditionIDLB.Text, TOTimeCitiesCB.SelectedItem, CTCitiesCB.SelectedItem), "Dikkat!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning ); if (dialogResult == DialogResult.Yes) { Expedition expedition = otodelContext.Expeditions.Find(HiddenExpeditionIDLB.Text); otodelContext.Expeditions.Remove(expedition); otodelContext.SaveChanges(); HiddenExpeditionIDLB.Text = ""; GetExpeditions(); MessageBox.Show("Silme işlemi başarılı!"); } } } } }
private void listView1_DoubleClick(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0) { using (OtodelContext otodelContext = new OtodelContext()) { Customer customer = otodelContext.Customers.Find(CTCTB.Text.Trim()); TicketForm ticketForm = new TicketForm(customer); ticketForm.ShowDialog(); } } }
private void BDeleteBT_Click(object sender, EventArgs e) { try { if (BPlakaTB.Text.Trim() != "") { using (var otodelContext = new OtodelContext()) { Bus bus = otodelContext.Buses.Find(BPlakaTB.Text); if (bus == null) { MessageBox.Show("Bu plakada araç bulunamadı!"); } else { var ExpeditionsResult = from expeditions in otodelContext.Expeditions join buses in otodelContext.Buses on expeditions.Bus.BusPlate equals buses.BusPlate where buses.BusPlate == BPlakaTB.Text && expeditions.CameTime > DateTime.Now select new { expeditions, buses }; DialogResult dialogResult; if (ExpeditionsResult.Count() > 0) { MessageBox.Show("Bu aracın mensubu olduğu seferler mevcut. Önce bu seferleri silmelisiniz!"); } else { dialogResult = MessageBox.Show(String.Format("{0} plakalı aracı silmek istediğinize emin misiniz?", BPlakaTB.Text), "Otobüs siliniyor!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { otodelContext.Buses.Remove(bus); otodelContext.SaveChanges(); MessageBox.Show("Silme işlemi başarılı!"); } } GetBusData(); } } } else { MessageBox.Show("Seçim işlemi yapmadınız!!"); } } catch (Exception error) { MessageBox.Show(error.Message); } }
private void UpdateExpeditionBTN_Click(object sender, EventArgs e) { if (HiddenExpeditionIDLB.Text.Trim() != "") { if (BusPlateCB.SelectedIndex == -1 || BPriceTB.Text.Trim() == "") { MessageBox.Show("Boş alan bırakmayınız!"); } else { string TakeOffTimeStr = TOTimeCB.Value.Day + "/" + TOTimeCB.Value.Month + "/" + TOTimeCB.Value.Year + " " + TOTimeHCB.Text + ":" + TOTimeMCB.Text + ":00"; string CameTimeStr = CTCB.Value.Day + "/" + CTCB.Value.Month + "/" + CTCB.Value.Year + " " + CTHCB.Text + ":" + CTMCB.Text + ":00"; DateTime TakeOffTime = DateTime.Parse(TakeOffTimeStr); DateTime CameTime = DateTime.Parse(CameTimeStr); if (DateDiffControl(TakeOffTime, CameTime)) { using (var otodelContext = new OtodelContext()) { Expedition expedition = otodelContext.Expeditions.Find(HiddenExpeditionIDLB.Text); expedition.Bus = otodelContext.Buses.Find(BusPlateCB.Text); expedition.CameTime = CameTime; expedition.CityToGo_CityID = otodelContext.Cities.Find(((ComboBoxItem)CTCitiesCB.SelectedItem).key).CityID; expedition.TakeOffTime = TakeOffTime; expedition.Price = float.Parse(BPriceTB.Text); expedition.ExpeditionDate = TakeOffTime; expedition.CityTakeOff_CityID = otodelContext.Cities.Find(((ComboBoxItem)TOTimeCitiesCB.SelectedItem).key).CityID; otodelContext.SaveChanges(); MessageBox.Show("Günceleme başarılı!"); GetExpeditions(); } } else { MessageBox.Show("Varış zamanı, kalkış zamanından önce olamaz!"); } } } else { MessageBox.Show("Seçim yapmadınız!"); } }
private void button1_Click(object sender, EventArgs e) { using (OtodelContext otodelContext = new OtodelContext()) { Customer customer = otodelContext.Customers.Find(_ticketModel.Customer.CustomerID); Expedition expedition = otodelContext.Expeditions.Find(_ticketModel.Expedition.ExpeditionID); otodelContext.Tickets.Add(new Ticket { Expedition = expedition, Customer = customer, SeatNo = _ticketModel.SeatNo, TicketDate = expedition.TakeOffTime, }); otodelContext.SaveChanges(); //Print ticket MessageBox.Show("Bilet kaydı başarılı!"); _ticketForm.RowCleaner(); _ticketForm.GetBusSeats(_ticketModel.BusPlate); this.Close(); } }
public void GetComboBoxValues() { /*Zamanlar*/ for (int hours = 0; hours < 24; hours++) { TOTimeHCB.Items.Add(hours.ToString().Length == 1 ? "0" + hours.ToString() : hours.ToString()); CTHCB.Items.Add(hours.ToString().Length == 1 ? "0" + hours.ToString() : hours.ToString()); } for (int minute = 0; minute < 60; minute++) { TOTimeMCB.Items.Add(minute.ToString().Length == 1 ? "0" + minute.ToString() : minute.ToString()); CTMCB.Items.Add(minute.ToString().Length == 1 ? "0" + minute.ToString() : minute.ToString()); } /*Zamanlar*/ /*other combos*/ using (var otodelContext = new OtodelContext()) { /*Şehirleri çekiyor*/ var CityResult = from cities in otodelContext.Cities select cities; foreach (var city in CityResult) { TOTimeCitiesCB.Items.Add(new ComboBoxItem(city.CityID, city.CityName)); CTCitiesCB.Items.Add(new ComboBoxItem(city.CityID, city.CityName)); } /*Şehirler çekildi*/ /*Otobüsler çekiliyor*/ var BusPlateResult = from plates in otodelContext.Buses select plates.BusPlate; foreach (var busPlate in BusPlateResult) { BusPlateCB.Items.Add(busPlate); } /*Otobüsler çekiliyor*/ } /*other combos*/ }
private void AddExpeditionBTN_Click(object sender, EventArgs e) { if (BusPlateCB.SelectedIndex != -1 || BPriceTB.Text.Trim() != "") { string TakeOffTimeStr = TOTimeCB.Value.Day + "/" + TOTimeCB.Value.Month + "/" + TOTimeCB.Value.Year + " " + TOTimeHCB.Text + ":" + TOTimeMCB.Text + ":00"; string CameTimeStr = CTCB.Value.Day + "/" + CTCB.Value.Month + "/" + CTCB.Value.Year + " " + CTHCB.Text + ":" + CTMCB.Text + ":00"; DateTime TakeOffTime = DateTime.Parse(TakeOffTimeStr); DateTime CameTime = DateTime.Parse(CameTimeStr); if (DateDiffControl(TakeOffTime, CameTime)) { Random rand = new Random(); using (var otodelContext = new OtodelContext()) { otodelContext.Expeditions.Add(new Expedition { ExpeditionID = ((ComboBoxItem)TOTimeCitiesCB.SelectedItem).key + ((ComboBoxItem)CTCitiesCB.SelectedItem).key + BusPlateCB.Text.Substring(0, 2) + rand.Next(10000, 99999), Bus = otodelContext.Buses.Find(BusPlateCB.Text), CameTime = CameTime, CityToGo_CityID = otodelContext.Cities.Find(((ComboBoxItem)CTCitiesCB.SelectedItem).key).CityID, TakeOffTime = TakeOffTime, Price = float.Parse(BPriceTB.Text), ExpeditionDate = TakeOffTime, CityTakeOff_CityID = otodelContext.Cities.Find(((ComboBoxItem)TOTimeCitiesCB.SelectedItem).key).CityID }); otodelContext.SaveChanges(); GetExpeditions(); MessageBox.Show("Kayıt başarılı!"); } } else { MessageBox.Show("Varış zamanı, Kalkış zamanından önce olamaz!"); } } else { MessageBox.Show("Boş alan bırakmayınız!"); } }
/*Fonksiyonlar*/ public void GetCustomers(string customerID = "") { listView1.Items.Clear(); listView1.View = View.Details; listView1.FullRowSelect = true; listView1.GridLines = true; using (OtodelContext otodelContext = new OtodelContext()) { var CustomerResult = from customers in otodelContext.Customers where customers.CustomerID.Contains(customerID) select customers; foreach (Customer customer in CustomerResult) { ListViewItem listViewItem = new ListViewItem(); listViewItem.Text = customer.CustomerID; listViewItem.SubItems.Add(customer.FirstName); listViewItem.SubItems.Add(customer.LastName); listViewItem.SubItems.Add(customer.Phone); listViewItem.SubItems.Add(customer.Gender ? "Erkek" : "Kadın"); listView1.Items.Add(listViewItem); } } }
/*Functions*/ /*Events*/ private void BAddBT_Click(object sender, EventArgs e) { if (BPlakaTB.Text.Trim() != "" || BSeatCountTB.Text != "") { using (OtodelContext otodelContext = new OtodelContext()) { try { int test = int.Parse(BSeatCountTB.Text); otodelContext.Buses.Add(new Bus { BusPlate = BPlakaTB.Text, Power = BPowerCHB.Checked, TV = BTvCHB.Checked, SeatCount = int.Parse(BSeatCountTB.Text), Wifi = BWifiCHB.Checked, SeatType = TPTRB.Checked ? false : true }); otodelContext.SaveChanges(); GetBusData(); } catch (FormatException formatException) { MessageBox.Show("Koltuk sayısı sayısal veri almak zorundadır!"); } catch (DbUpdateException error) { MessageBox.Show("Bu plakada bir araç zaten mevcut!"); } } } else { MessageBox.Show("Koltuk sayısı ve Plaka boş kalamaz!"); } }
private void GetEmployees() { listView1.Items.Clear(); listView1.View = View.Details; listView1.FullRowSelect = true; listView1.GridLines = true; using (OtodelContext otodelContext = new OtodelContext()) { var EmployeeResult = from employees in otodelContext.Employees where employees.EmployeeRank != "Gelistirici" select employees; foreach (Employee employee in EmployeeResult) { ListViewItem listViewItem = new ListViewItem(); listViewItem.Text = employee.EmployeeID; listViewItem.SubItems.Add(employee.EmployeeMail); listViewItem.SubItems.Add(employee.Password); listViewItem.SubItems.Add(employee.FirstName); listViewItem.SubItems.Add(employee.LastName); listViewItem.SubItems.Add(employee.EmployeeRank); listView1.Items.Add(listViewItem); } } }
/*Functions*/ private void GetBusData(string busPlate = "") { listView1.Items.Clear(); listView1.View = View.Details; listView1.FullRowSelect = true; listView1.GridLines = true; using (OtodelContext otodelContext = new OtodelContext()) { var BusesResult = from buses in otodelContext.Buses where buses.BusPlate.Contains(busPlate) select buses; foreach (var Bus in BusesResult) { ListViewItem listViewItem = new ListViewItem(); listViewItem.Text = Bus.BusPlate; listViewItem.SubItems.Add(Bus.SeatCount.ToString()); listViewItem.SubItems.Add(Bus.Wifi ? "Var" : "Yok"); listViewItem.SubItems.Add(Bus.TV ? "Var" : "Yok"); listViewItem.SubItems.Add(Bus.Power ? "Var" : "Yok"); listViewItem.SubItems.Add(Bus.SeatType ? "2+1" : "2+2"); listView1.Items.Add(listViewItem); } } }
private void BUpdateBT_Click(object sender, EventArgs e) { try { if (BPlakaTB.Text.Trim() != "") { using (var otodelContext = new OtodelContext()) { var ticketResult = from tickets in otodelContext.Tickets join expedition in otodelContext.Expeditions on tickets.Expedition.ExpeditionID equals expedition.ExpeditionID join busses in otodelContext.Buses on expedition.Bus.BusPlate equals busses.BusPlate select tickets; if (ticketResult.Count() > 0 && int.Parse(BSeatCountTB.Text) < int.Parse(HiddenSeatCount.Text)) { MessageBox.Show("Bu otobüslerin çıkacağı seferler için bilet kesilmiş. Koltuk sayısı olduğu sayıdan daha küçük bir adete dönüştürülemez! Önce seferi iptal edin!"); } else { Bus bus = otodelContext.Buses.Find(BPlakaTB.Text); if (bus == null) { MessageBox.Show("Bu araç bulunamadı!"); } else { if (BSeatCountLB.Text.Trim() != "") { bus.SeatCount = int.Parse(BSeatCountTB.Text); bus.Power = BPowerCHB.Checked; bus.TV = BTvCHB.Checked; bus.Wifi = BWifiCHB.Checked; bus.SeatType = TPTRB.Checked ? false : true; otodelContext.SaveChanges(); MessageBox.Show("Günceleme başarılı!"); GetBusData(); } else { MessageBox.Show("Koltuk adedi boş kalamaz!"); } } } } } else { MessageBox.Show("Seçim işlemi yapmadınız!!"); } } catch (InvalidOperationException InOpException) { MessageBox.Show("Araç plakaları değiştirilemez!"); } catch (FormatException formatException) { MessageBox.Show("Araç koltukları, sayısal değer almak zorundadır!"); } catch (Exception error) { MessageBox.Show(error.Message); } }