private void btnIzvestaj_Click(object sender, RoutedEventArgs e) { // Create excel workbook and sheet Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); excel.Visible = true; Workbook workbook = excel.Workbooks.Add(System.Reflection.Missing.Value); Worksheet sheet1 = (Worksheet)workbook.Sheets[1]; // Insert document headers sheet1.Range[sheet1.Cells[1, 1], sheet1.Cells[1, 3]].Merge(); sheet1.Cells[1, 1].HorizontalAlignment = XlHAlign.xlHAlignCenter; sheet1.Cells[1, 1].Font.Bold = true; sheet1.Cells[1, 1] = "Podaci o Servisima"; // Insert row headers sheet1.Rows[3].Font.Bold = true; sheet1.Cells[3, 1] = "Ime"; sheet1.Cells[3, 2] = "Prezime"; sheet1.Cells[3, 3] = "Vrsta Servisa"; Servisi = new Servis().ucitajServise(); for (int i = 0; i < Servisi.Count; i++) { sheet1.Cells[i + 4, 1] = Servisi[i].Vlasnik.Ime; sheet1.Cells[i + 4, 2] = Servisi[i].Vlasnik.Prezime; sheet1.Cells[i + 4, 3] = Servisi[i].Vrsta.Naziv; } // Set additional options sheet1.Columns.AutoFit(); }
public frmServis() { InitializeComponent(); this.DataContext = this; Servisi = new Servis().ucitajServise(); }
public ObservableCollection <Servis> ucitajServise() { ObservableCollection <Servis> servisi = new ObservableCollection <Servis>(); string queryString = @"SELECT auto.AutoId, auto.Naziv AS NazivAuta, auto.Godiste, auto.Sifra, servis.ServisId, servis.Datum, vlasnik.VlasnikId, vlasnik.RedniBroj, vlasnik.Ime, vlasnik.Prezime, vrsta.VrstaId, vrsta.Naziv AS VrstaServisa FROM T_AUTO auto, T_SERVIS servis, T_AUTO_SERVIS ass, T_VLASNIK vlasnik, T_VRSTA vrsta WHERE auto.AutoId=ass.AutoId AND servis.ServisId=ass.ServisId AND servis.VlasnikId=vlasnik.VlasnikId AND servis.VrstaId=vrsta.VrstaId ORDER BY servis.ServisId;"; using (SqlConnection connection = new SqlConnection(_connectionString)) { SqlCommand command = connection.CreateCommand(); command.CommandText = queryString; connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { int prethodniIdServis = 0; Servis servis = new Servis(); while (reader.Read()) { int idServis = Int32.Parse(reader["ServisId"].ToString()); if (idServis != prethodniIdServis) { prethodniIdServis = idServis; servis = new Servis(); servisi.Add(servis); servis.ID = idServis; Vrsta vrsta = new Vrsta(); vrsta.ID = Int32.Parse(reader["VrstaId"].ToString()); vrsta.Naziv = reader["VrstaServisa"].ToString(); servis.Vrsta = vrsta; Vlasnik vlasnik = new Vlasnik(); vlasnik.ID = Int32.Parse(reader["VlasnikId"].ToString()); vlasnik.RedniBroj = reader["RedniBroj"].ToString(); vlasnik.Ime = reader["Ime"].ToString(); vlasnik.Prezime = reader["Prezime"].ToString(); servis.Vlasnik = vlasnik; servis.Datum = DateTime.Parse(reader["Datum"].ToString()); servis.Autos = new ObservableCollection <Auto>(); } Auto auto = new Auto(); auto.ID = Int32.Parse(reader["AutoId"].ToString()); auto.Naziv = reader["NazivAuta"].ToString(); auto.Godiste = Int32.Parse(reader["Godiste"].ToString()); auto.Sifra = reader["Sifra"].ToString(); servis.Autos.Add(auto); //servis.Auto = auto; } } } return(servisi); }
public ServisAddEdit(Servis servis) { InitializeComponent(); this.DataContext = this; VlasniciFromDB = new Vlasnik().ucitajVlasnike(); VrsteFromDB = new Vrsta().ucitajVrste(); Autos = new Auto().ucitajAuto(); CurrentServis = servis; CurrentServis.Vlasnik = VlasniciFromDB.FirstOrDefault(x => x.ID == servis.Vlasnik?.ID); CurrentServis.Vrsta = VrsteFromDB.FirstOrDefault(x => x.ID == servis.Vrsta?.ID); foreach (var item in servis.Autos ?? new ObservableCollection <Auto>()) { Autos.FirstOrDefault(x => x.ID == item.ID).Selektovan = true; } }
private void Refresh(Servis servis) { Servisi = new Servis().ucitajServise(); }
private void btnDelete_Click(object sender, RoutedEventArgs e) { CurrentServis.obrisiServis(); Servisi = new Servis().ucitajServise(); }