// ...#... public bool SacuvajSlozen(IDomenskiObjekat objekat) { SqlCommand command = new SqlCommand($"INSERT INTO {objekat.VratiImeKlase()} OUTPUT {objekat.VratiImePrimarnogKljuca()} VALUES ({objekat.VratiVrednostiAtributa()})", connection, transaction); int id = (int)command.ExecuteScalar(); foreach (IDomenskiObjekat o in objekat.VratiSlabeObjekte()) { // smanjiti robu sa update preko where uslova za korisnika i naziv robe // na primer UPDATE Roba SET KolicinaRobe = KolicinaRobe - 100 WHERE NazivRobe = 'Secer' AND KorisnikRobe = 2 AND RazmenaUlozeneRobe IS NULL SqlCommand command3 = new SqlCommand($"UPDATE {o.VratiImeKlase()} SET KolicinaRobe = KolicinaRobe - {((Roba)o).KolicinaRobe} WHERE NazivRobe = '{((Roba)o).NazivRobe}' AND KorisnikRobe = {((Roba)o).KorisnikRobe.KorisnikID} AND RazmenaUlozeneRobe IS NULL", connection, transaction); var i = command3.ExecuteNonQuery(); SqlCommand command2 = new SqlCommand($"INSERT INTO {o.VratiImeKlase()} VALUES ({o.VratiVrednostiAtributa()}, {id})", connection, transaction); command2.ExecuteScalar(); } IDomenskiObjekat trazenaRoba = objekat.VratiPoddomen(3); if (Izmeni(trazenaRoba) != 1) { throw new Exception(); } return(true); }
public IDomenskiObjekat VratiJedan(IDomenskiObjekat objekat) { IDomenskiObjekat rezultat; SqlCommand command = new SqlCommand($"SELECT * FROM {objekat.VratiImeKlase()} WHERE {objekat.VratiUslovPoIDu()}", connection, transaction); SqlDataReader reader = command.ExecuteReader(); rezultat = objekat.VratiObjekat(reader); reader.Close(); int broj = 1; while (rezultat.VratiPoddomen(broj) != null) { rezultat.PostaviPoddomen(VratiJedan(rezultat.VratiPoddomen(broj)), broj); broj++; } return(rezultat); }
public List <IDomenskiObjekat> VratiSve(IDomenskiObjekat objekat, string operacija) { SqlCommand command = new SqlCommand($"SELECT * FROM {objekat.VratiImeKlase()} WHERE {objekat.VratiSlozenUslov(operacija)}", connection, transaction); SqlDataReader reader = command.ExecuteReader(); List <IDomenskiObjekat> rezultat = objekat.VratiListu(reader); reader.Close(); int broj = 1; foreach (IDomenskiObjekat rez in rezultat) { broj = 1; while (rez.VratiPoddomen(broj) != null) { rez.PostaviPoddomen(VratiJedan(rez.VratiPoddomen(broj)), broj); broj++; } } return(rezultat); }
// ...#.... public int Obrisi(IDomenskiObjekat objekat) { SqlCommand command = new SqlCommand($"DELETE FROM {objekat.VratiImeKlase()} WHERE {objekat.VratiUslovPoIDu()}", connection, transaction); return(command.ExecuteNonQuery()); }
// ...#... public int Izmeni(IDomenskiObjekat objekat) { SqlCommand command = new SqlCommand($"UPDATE {objekat.VratiImeKlase()} SET {objekat.PostaviVrednostiAtributa()} WHERE {objekat.VratiUslovPoIDu()}", connection, transaction); return(command.ExecuteNonQuery()); }
// ...#... public int SacuvajIUzvratiID(IDomenskiObjekat objekat) { SqlCommand command = new SqlCommand($"INSERT INTO {objekat.VratiImeKlase()} OUTPUT {objekat.VratiImePrimarnogKljuca()} VALUES({objekat.VratiVrednostiAtributa()})", connection, transaction); return((int)command.ExecuteScalar()); }
// ...#... public int Sacuvaj(IDomenskiObjekat objekat) { SqlCommand command = new SqlCommand($"INSERT INTO {objekat.VratiImeKlase()} VALUES ({objekat.VratiVrednostiAtributa()})", connection, transaction); return(command.ExecuteNonQuery()); }