public List<Racun> getAll() { DataSet data = manager.ExecuteSqlCommandToDataSet("SELECT * FROM Racun r, Uposlenik u WHERE r.Fakturisao = u.ID AND r.Odobrio = u.ID "); //čitamo rezultate List<Racun> racuni = new List<Racun>(); foreach (DataRow dataRow in data.Tables[0].Rows) { Racun racun = new Racun( Convert.ToInt32(dataRow["RacunId"]), Convert.ToInt32(dataRow["Sifra"]), Convert.ToDateTime(dataRow["Vrijeme"]), new Menadzer( Convert.ToString(dataRow["Telefon"]), Convert.ToString(dataRow["Ime"]), Convert.ToString(dataRow["Prezime"]), Convert.ToString(dataRow["Jmbg"]), Convert.ToInt32(dataRow["UposlenikId"]), Convert.ToDouble(dataRow["Koeficijent"]) ), new ProdavacHrane(Convert.ToString(dataRow["Pult"]), Convert.ToString(dataRow["Ime"]), Convert.ToString(dataRow["Prezime"]), Convert.ToString(dataRow["Jmbg"]), Convert.ToInt32(dataRow["UposlenikId"]), Convert.ToDouble(dataRow["Koeficijent"])), new List<PrehrambeniProdukt>() ); } return racuni; }
/// <summary> /// Konstruktor koji prima instancu klase Racun /// </summary> /// <param name="r"></param> public Racun(Racun r) { this.Id = r.Id; this.Sifra =r.Sifra; this.Vrijeme = r.Vrijeme; this.Menadzer = r.Menadzer; this.Prodavac = r.Prodavac; this.Produkti = r.Produkti; }
private void Button_Click_1(object sender, RoutedEventArgs e) { // public Racun(int sifra, DateTime vrijeme, Menadzer menadzer, ProdavacHrane prodavac, List<PrehrambeniProdukt> produkti) sifra++; MenadzerDAO m = new MenadzerDAO(); ProdavacHraneDAO pk = new ProdavacHraneDAO(); Menadzer menadzer = m.getById(id); ProdavacHrane prodavac = pk.getById(id); double cijena = 0; foreach (PrehrambeniProdukt p in kprodukti) { cijena += p.Cijena; } if (true == rb1.IsChecked) { cijena = cijena - cijena * 5 / 100; } Racun r = new Racun(sifra, DateTime.Now, menadzer, prodavac, kprodukti); RacunDAO rdao = new RacunDAO(); kprodukti.Clear(); string Datum = Convert.ToDateTime(Datump.SelectedDate).ToString("dd.MM.yyyy"); string s = " RACUN " + Environment.NewLine + "Datum: " + Datum + Environment.NewLine + "Cijena: " + cijena; MessageBox.Show(s); }
public Racun getById(int id) { DataSet data = manager.ExecuteSqlCommandToDataSet("SELECT * FROM Racun r, ProdavacHrane ph WHERE r.RacunId = " + id + " and r.ProdavacID = ph.PrehrambeniProduktID "); DataSet data2 = manager.ExecuteSqlCommandToDataSet("SELECT * FROM PrehrambeniProdukt ph, RacunProdukt rp, Racun r WHERE rp.RacunId = " + id + " AND rp.ProduktID = ph.Id "); List<PrehrambeniProdukt> lista = new List<PrehrambeniProdukt>(); foreach (DataRow dataRow in data2.Tables[0].Rows) { PrehrambeniProdukt ph = new PrehrambeniProdukt( Convert.ToInt32(dataRow["PrehrambeniProduktID"]), Convert.ToString(dataRow["Tip"]), Convert.ToDouble(dataRow["Cijena"]) ); lista.Add(ph); } foreach (DataRow dataRow in data.Tables[0].Rows) { Racun racun = new Racun( Convert.ToInt32(dataRow["RacunId"]), Convert.ToInt32(dataRow["Sifra"]), Convert.ToDateTime(dataRow["Vrijeme"]), new Menadzer( Convert.ToString(dataRow["Telefon"]), Convert.ToString(dataRow["Ime"]), Convert.ToString(dataRow["Prezime"]), Convert.ToString(dataRow["Jmbg"]), Convert.ToInt32(dataRow["UposlenikId"]), Convert.ToDouble(dataRow["Koeficijent"]) ), new ProdavacHrane(Convert.ToString(dataRow["Pult"]), Convert.ToString(dataRow["Ime"]), Convert.ToString(dataRow["Prezime"]), Convert.ToString(dataRow["Jmbg"]), Convert.ToInt32(dataRow["UposlenikId"]), Convert.ToDouble(dataRow["Koeficijent"])), lista ); return racun; } return null; }
public long create(Racun racun) { string exec = "INSERT INTO racun VALUES(" + racun.Prodavac + ", " + racun.Menadzer + "," + racun.Sifra + " ," + racun.Vrijeme + ")"; return manager.ExecuteSqlCommandToIntForCreate(exec); }