private void btDodajVoz_Click(object sender, RoutedEventArgs e) { Vozilo vozilo = new Vozilo(); vozilo.ShowDialog(); btVozila_Click(sender, e); }
private void btIzmeniVoz_Click(object sender, RoutedEventArgs e) { try { izmeni = true; Vozilo vozilo = new Vozilo(); konekcija.Open(); DataRowView dataRowView = (DataRowView)dgAdmin.SelectedItems[0]; forma = dataRowView; string select = "select * from Vehicle where Vehicle_ID = " + dataRowView["ID"]; SqlCommand command = new SqlCommand(select, konekcija); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { vozilo.cbMake.Text = reader["Make"].ToString(); vozilo.txtModel.Text = reader["Model"].ToString(); vozilo.chAir.IsChecked = Convert.ToBoolean(reader["Air"]); vozilo.cbType.Text = reader["Type"].ToString(); vozilo.cbTransmission.Text = reader["GearBox"].ToString(); vozilo.txtFuel.Text = reader["Consum"].ToString(); vozilo.txtPrice.Text = reader["Price"].ToString(); if (reader["Seats"].ToString() == "2") { vozilo.rbSeats2.IsChecked = true; } else if (reader["Seats"].ToString() == "4") { vozilo.rbSeats4.IsChecked = true; } else { vozilo.rbSeats5.IsChecked = true; } } vozilo.ShowDialog(); } catch (ArgumentOutOfRangeException) { var msg = new CustomMaterialMessageBox { Width = 300, Height = 150, TxtMessage = { Text = "You didnt select a row.", Foreground = Brushes.BlueViolet }, TxtTitle = { Text = "Vehicle", Foreground = Brushes.White, Background = Brushes.BlueViolet }, BtnCopyMessage = { Width = 0, Height = 0, Content = null }, BtnCancel = { Width = 0, Height = 0, Content = null }, BtnOk = { Background = Brushes.BlueViolet, }, TitleBackgroundPanel = { Background = Brushes.BlueViolet }, BorderBrush = Brushes.BlueViolet }; msg.Show(); } finally { if (konekcija != null) { konekcija.Close(); } btVozila_Click(sender, e); izmeni = false; } }