private void btnObrisiIzvrseni_Click(object sender, RoutedEventArgs e) { if (dgIzvrseni.Items.Count > 0 && cmbRadniNalog.SelectedValue != null) { DataRowView red = (DataRowView)dgIzvrseni.SelectedItems[0]; int rbr = Convert.ToInt32(red[0]); try { MessageBoxResult rez = MessageBox.Show(@"Da li ste sigurni?", "Upozorenje", MessageBoxButton.YesNo, MessageBoxImage.Question); if (rez != MessageBoxResult.Yes) { return; } IzvrseniRadovi rad = IzvrseniRadovi.UcitajIzvrseneRadove(rbr, Convert.ToInt32(cmbRadniNalog.SelectedValue)); rad.Obrisi(); UcitajListuIzvrsenih(); } catch (InvalidOperationException) { MessageBox.Show("Niste izabrali red.", "Greška", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception ex) { MessageBox.Show($"Došlo je do greške prilikom pokušaja brisanja podataka: { ex.Message }.", "Greška", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void UcitajListuIzvrsenih() { tbPoruka2.Text = ""; if (cmbRadniNalog.SelectedValue == null) { return; } int id = Convert.ToInt32(cmbRadniNalog.SelectedValue); dgIzvrseni.ItemsSource = IzvrseniRadovi.ListaIzvrsenihRadova(id).DefaultView; UcitajIzvrseni(); UcitajRadniNalog(); }
private void btnObrisi_Click(object sender, RoutedEventArgs e) { if (dgPregled.Items.Count > 0) { DataRowView red = (DataRowView)dgPregled.SelectedItems[0]; int id = Convert.ToInt32(red[0]); try { MessageBoxResult rez = MessageBox.Show(@"Da li ste sigurni? Biće obrisani i svi podaci povezani sa vlasnikom.", "Upozorenje", MessageBoxButton.YesNo, MessageBoxImage.Question); if (rez != MessageBoxResult.Yes) { return; } //mora ovako da bismo isli unazad i obrisali sve povezane podatke Vlasnik vlasnik = Vlasnik.UcitajVlasnika(id); foreach (int idVozila in Vlasnik.ListaVozila(id)) { Vozilo vozilo = Vozilo.UcitajVozilo(idVozila); foreach (int idNaloga in Vozilo.ListaNaloga(idVozila)) { RadniNalog nalog = RadniNalog.UcitajNalog(idNaloga); Garancija.ObrisiSveGarancijeZaRadniNalog(idNaloga); Faktura.ObrisiSveFakture(idNaloga); NaruceniRadovi.ObrisiSveNaruceneRadove(idNaloga); Delovi.ObrisiSveDelove(idNaloga); IzvrseniRadovi.ObrisiSveIzvrseneRadove(idNaloga); nalog.Obrisi(); } vozilo.Obrisi(); } vlasnik.Obrisi(); UcitajListuVlasnika(); } catch (InvalidOperationException) { MessageBox.Show("Niste izabrali red.", "Greška", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception ex) { MessageBox.Show($"Došlo je do greške prilikom pokušaja brisanja podataka: { ex.Message }.", "Greška", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void cmbRadniNalog_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (cmbRadniNalog.SelectedValue != null) { RadniNalog nalog = RadniNalog.UcitajNalog(Convert.ToInt32(cmbRadniNalog.SelectedValue)); tbRadniNalogID.Text = $@"ID radnog naloga: { nalog.Id }"; tbVlasnik.Text = $@"Vlasnik: { nalog.Vozilo.Vlasnik.ImeVlasnika } { nalog.Vozilo.Vlasnik.PrezimeVlasnika }"; tbVozilo.Text = $@"Vozilo: { nalog.Vozilo.Model.Marka.NazivMarke } { nalog.Vozilo.Model.NazivModela }"; tbIznosDelova.Text = $@"Iznos delova: { nalog.IznosDelova().ToString("F2") }"; tbIznosRadova.Text = $@"Iznos radova: { nalog.IznosRadova().ToString("F2") }"; tbUkupno.Text = $@"Ukupan iznos: { (nalog.IznosRadova() + nalog.IznosDelova()).ToString("F2") }"; dgRadovi.ItemsSource = IzvrseniRadovi.ListaIzvrsenihRadova(nalog.Id).DefaultView; dgDelovi.ItemsSource = Delovi.ListaDelova(nalog.Id).DefaultView; } }
private void btnObrisi_Click(object sender, RoutedEventArgs e) { if (dgPregled.Items.Count > 0) { DataRowView red = (DataRowView)dgPregled.SelectedItems[0]; int id = Convert.ToInt32(red[0]); try { MessageBoxResult rez = MessageBox.Show(@"Da li ste sigurni? Biće obrisani i svi podaci povezani na radni nalog.", "Upozorenje", MessageBoxButton.YesNo, MessageBoxImage.Question); if (rez != MessageBoxResult.Yes) { return; } RadniNalog nalog = RadniNalog.UcitajNalog(id); Garancija.ObrisiSveGarancijeZaRadniNalog(id); Faktura.ObrisiSveFakture(id); NaruceniRadovi.ObrisiSveNaruceneRadove(id); Delovi.ObrisiSveDelove(id); IzvrseniRadovi.ObrisiSveIzvrseneRadove(id); nalog.Obrisi(); UcitajListuNaloga(); } catch (InvalidOperationException) { MessageBox.Show("Niste izabrali red.", "Greška", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception ex) { MessageBox.Show($"Došlo je do greške prilikom pokušaja brisanja podataka: { ex.Message }.", "Greška", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void UcitajFakturu() { if (dgPregled.Items.Count <= 0) { txtID.Text = ""; dtDatum.SelectedDate = null; dtValuta.SelectedDate = null; txtBrojFiskalnogRacuna.Text = ""; cmbRadniNalog.Text = ""; tbRadniNalogID.Text = ""; tbVlasnik.Text = ""; tbVozilo.Text = ""; tbIznosDelova.Text = ""; tbIznosRadova.Text = ""; tbUkupno.Text = ""; return; } DataRowView red = (DataRowView)dgPregled.SelectedItems[0]; int id = Convert.ToInt32(red[0]); Faktura faktura = Faktura.UcitajFakturu(id); cmbRadniNalog.SelectedValue = faktura.RadniNalog.Id; txtID.Text = id.ToString(); dtDatum.SelectedDate = faktura.Datum; dtValuta.SelectedDate = faktura.Valuta; txtBrojFiskalnogRacuna.Text = faktura.BrojFiskalnogRacuna.ToString(); tbRadniNalogID.Text = $@"ID radnog naloga: { faktura.RadniNalog.Id }"; tbVlasnik.Text = $@"Vlasnik: { faktura.RadniNalog.Vozilo.Vlasnik.ImeVlasnika } { faktura.RadniNalog.Vozilo.Vlasnik.PrezimeVlasnika }"; tbVozilo.Text = $@"Vozilo: { faktura.RadniNalog.Vozilo.Model.Marka.NazivMarke } { faktura.RadniNalog.Vozilo.Model.NazivModela }"; tbIznosDelova.Text = $@"Iznos delova: { faktura.RadniNalog.IznosDelova().ToString("F2") }"; tbIznosRadova.Text = $@"Iznos radova: { faktura.RadniNalog.IznosRadova().ToString("F2") }"; tbUkupno.Text = $@"Ukupan iznos: { (faktura.RadniNalog.IznosRadova() + faktura.RadniNalog.IznosDelova()).ToString("F2") }"; dgRadovi.ItemsSource = IzvrseniRadovi.ListaIzvrsenihRadova(faktura.RadniNalog.Id).DefaultView; dgDelovi.ItemsSource = Delovi.ListaDelova(faktura.RadniNalog.Id).DefaultView; }
private void UcitajIzvrseni() { if (dgIzvrseni.Items.Count <= 0 || cmbRadniNalog.SelectedValue == null) { txtNazivIzvrsenih.Text = ""; txtKolicina.Text = ""; txtCena.Text = ""; txtJmr.Text = ""; izvrseniRedni = 1; return; } int id = Convert.ToInt32(cmbRadniNalog.SelectedValue); DataRowView red = (DataRowView)dgIzvrseni.SelectedItems[0]; int rbr = Convert.ToInt32(red[0]); IzvrseniRadovi izvrseni = IzvrseniRadovi.UcitajIzvrseneRadove(rbr, id); izvrseniRedni = rbr; txtNazivIzvrsenih.Text = izvrseni.Naziv; txtKolicina.Text = izvrseni.Kolicina.ToString("F3"); txtJmr.Text = izvrseni.JedinicaMere; txtCena.Text = izvrseni.Cena.ToString("F2"); }
private void btnSacuvajIzvrseni_Click(object sender, RoutedEventArgs e) { if (cmbRadniNalog.SelectedValue == null) { tbPoruka2.Text = "Morate izabrati radni nalog."; return; } if (String.IsNullOrEmpty(txtNazivIzvrsenih.Text)) { tbPoruka2.Text = "Morate uneti naziv usluge."; return; } if (String.IsNullOrEmpty(txtKolicina.Text)) { tbPoruka2.Text = "Morate uneti količinu."; return; } if (String.IsNullOrEmpty(txtJmr.Text)) { tbPoruka2.Text = "Morate uneti jedinicu mere."; return; } if (String.IsNullOrEmpty(txtCena.Text)) { tbPoruka2.Text = "Morate uneti cenu."; return; } IzvrseniRadovi izvrseni = new IzvrseniRadovi(); try { izvrseni.RedniBroj = izvrseniRedni; izvrseni.Naziv = txtNazivIzvrsenih.Text; izvrseni.Kolicina = Convert.ToDouble(txtKolicina.Text); izvrseni.Cena = Convert.ToDouble(txtCena.Text); izvrseni.JedinicaMere = txtJmr.Text; izvrseni.RadniNalog = RadniNalog.UcitajNalog(Convert.ToInt32(cmbRadniNalog.SelectedValue)); } catch (Exception) { tbPoruka2.Text = "Niste uneli ispravne vrednosti."; return; } bool azuriraj = false; foreach (DataRowView red in dgIzvrseni.ItemsSource) { if (Convert.ToInt32(red[0]) == izvrseni.RedniBroj) { azuriraj = true; break; } } if (azuriraj == true) { IzvrseniRadovi stari = IzvrseniRadovi.UcitajIzvrseneRadove(izvrseniRedni, Convert.ToInt32(cmbRadniNalog.SelectedValue)); stari.Azuriraj(izvrseni); UcitajListuIzvrsenih(); return; } izvrseni.Sacuvaj(); UcitajListuIzvrsenih(); }