コード例 #1
0
        public List <IOpstiDomenskiObjekat> SelectAll(IOpstiDomenskiObjekat odo)
        {
            komanda.CommandText = $"Select * from {odo.VratiImeTabele()}";
            komanda.CommandType = System.Data.CommandType.Text;
            OleDbDataReader citac = komanda.ExecuteReader();
            List <IOpstiDomenskiObjekat> lista = odo.VratiListu(citac);

            citac.Close();
            return(lista);
        }
コード例 #2
0
        public List <IOpstiDomenskiObjekat> VratiSve(IOpstiDomenskiObjekat odo)
        {
            List <IOpstiDomenskiObjekat> lista;

            komanda.CommandText = $"SELECT * FROM {odo.VratiImeTabele()}";
            komanda.CommandType = CommandType.Text;
            OleDbDataReader citac = komanda.ExecuteReader();

            lista = odo.VratiListu(citac);
            citac.Close();
            return(lista);
        }
コード例 #3
0
        public IOpstiDomenskiObjekat VratiPrvog(IOpstiDomenskiObjekat odo)
        {
            IOpstiDomenskiObjekat objekat;

            komanda.CommandText = $"SELECT * FROM {odo.VratiImeTabele()} WHERE {odo.VratiKljucIUslov()}";
            komanda.CommandType = CommandType.Text;
            OleDbDataReader citac = komanda.ExecuteReader();

            objekat = odo.VratiObjekat(citac);
            citac.Close();
            return(objekat);
        }
コード例 #4
0
 public bool Azuriraj(IOpstiDomenskiObjekat odo)
 {
     try
     {
         string       upit    = "UPDATE " + odo.VratiImeTabele() + " SET " + odo.VratiVrednostiZaAzuriranje() + " WHERE " + odo.VratiKljucniAtribut();
         OleDbCommand komanda = new OleDbCommand(upit, konekcija, transakcija);
         komanda.ExecuteNonQuery();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
コード例 #5
0
 public bool Obrisi(IOpstiDomenskiObjekat odo)
 {
     try
     {
         string upit = "DELETE FROM " + odo.VratiImeTabele() + " WHERE " + odo.VratiKljucniAtribut();
         komanda = new OleDbCommand(upit, konekcija, transakcija);
         komanda.ExecuteNonQuery();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #6
0
        public int SelectMax(IOpstiDomenskiObjekat odo)
        {
            komanda.CommandText = $"Select max({odo.VratiKljucZaMax()}) from {odo.VratiImeTabele()}";
            komanda.CommandType = System.Data.CommandType.Text;
            var res = komanda.ExecuteScalar();

            if (res != DBNull.Value)
            {
                return(Convert.ToInt32(res) + 1);
            }
            else
            {
                return(11);
            }
        }
コード例 #7
0
        public List <IOpstiDomenskiObjekat> VratiSveObjektePoUslovu(IOpstiDomenskiObjekat odo)
        {
            try
            {
                string upit = "SELECT * FROM " + odo.VratiImeTabele() + " WHERE " + odo.VratiUslovZaObjekat();
                komanda = new OleDbCommand(upit, konekcija, transakcija);
                OleDbDataReader citac = komanda.ExecuteReader();

                return(odo.VratiListu(citac));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #8
0
 public bool Unesi(IOpstiDomenskiObjekat odo)
 {
     try
     {
         // string upit = "INSERT INTO " + odo.VratiImeTabele() + " VALUES " + odo.VratiVrednostiZaInsert();
         string upit = $"Insert into {odo.VratiImeTabele()} {odo.VratiKoloneZaInsert()} values {odo.VratiVrednostiZaInsert()}";
         komanda = new OleDbCommand(upit, konekcija, transakcija);
         komanda.ExecuteNonQuery();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
コード例 #9
0
        public bool Obrisi(IOpstiDomenskiObjekat odo)
        {
            komanda.CommandText = $"DELETE FROM {odo.VratiImeTabele()} WHERE {odo.VratiKljucIUslov()}";
            komanda.CommandType = CommandType.Text;
            int rezultat = komanda.ExecuteNonQuery();

            if (rezultat == 1)
            {
                return(true);
            }
            else
            {
                throw new Exception();
            }
        }
コード例 #10
0
        //public List<IOpstiDomenskiObjekat> VratiSveKljuc(IOpstiDomenskiObjekat odo)
        //{
        //    List<IOpstiDomenskiObjekat> lista;
        //    komanda.CommandText = $"SELECT * FROM {odo.VratiImeTabele()} WHERE {odo.VratiKljucIUslov()}";
        //    komanda.CommandType = CommandType.Text;
        //    OleDbDataReader citac = komanda.ExecuteReader();
        //    lista = odo.VratiListu(citac);
        //    citac.Close();
        //    return lista;
        //}

        public bool Izmeni(IOpstiDomenskiObjekat odo)
        {
            komanda.CommandText = $"UPDATE {odo.VratiImeTabele()} SET {odo.VratiZaIzmenu()} " +
                                  $"WHERE {odo.VratiKljucIUslov()}";
            komanda.CommandType = CommandType.Text;
            int rezultat = komanda.ExecuteNonQuery();

            if (rezultat == 1)
            {
                return(true);
            }
            else
            {
                throw new Exception();
            }
        }
コード例 #11
0
        public object Ubaci(IOpstiDomenskiObjekat odo)
        {
            komanda.CommandText = $"INSERT INTO {odo.VratiImeTabele()} ({odo.VratiKoloneZaInsert()}) " +
                                  $"VALUES ({odo.VratiVrednostiZaInsert()})";
            komanda.CommandType = CommandType.Text;
            int rezultat = komanda.ExecuteNonQuery();

            if (rezultat == 1)
            {
                komanda.CommandText = "SELECT @@IDENTITY";
                object id = komanda.ExecuteScalar();
                return(id);
            }
            else
            {
                throw new Exception();
            }
        }
コード例 #12
0
        public object UnesiIVratiID(IOpstiDomenskiObjekat odo)
        {
            string upit = $"Insert into {odo.VratiImeTabele()} {odo.VratiKoloneZaInsert()} values {odo.VratiVrednostiZaInsert()}";

            komanda = new OleDbCommand(upit, konekcija, transakcija);

            int rezultat = komanda.ExecuteNonQuery();

            if (rezultat == 1)
            {
                komanda.CommandText = "SELECT @@IDENTITY";
                object id = komanda.ExecuteScalar();
                return(id);
            }
            else
            {
                throw new Exception();
            }
        }
コード例 #13
0
 public void Update(IOpstiDomenskiObjekat odo)
 {
     komanda.CommandText = $"Update {odo.VratiImeTabele()} set {odo.VratiVrednostZaUpdate()} where {odo.VratiKljucIUslov()}";
     komanda.CommandType = System.Data.CommandType.Text;
     komanda.ExecuteNonQuery();
 }
コード例 #14
0
 public int Insert(IOpstiDomenskiObjekat odo)
 {
     komanda.CommandText = $"Insert into {odo.VratiImeTabele()} values ({odo.VratiVrednostiZaInsert()})";
     komanda.CommandType = System.Data.CommandType.Text;
     return(komanda.ExecuteNonQuery());
 }
コード例 #15
0
 public void Delete(IOpstiDomenskiObjekat odo)
 {
     komanda.CommandText = $"Delete from {odo.VratiImeTabele()} where {odo.VratiKljucIUslov()}";
     komanda.CommandType = System.Data.CommandType.Text;
     komanda.ExecuteNonQuery();
 }
コード例 #16
0
        public int vratiMaxID(IOpstiDomenskiObjekat odo)
        {
            try
            {
                string upit = "Select Max(" + odo.VratiNazivKljucnogAtributa() + ") as MaxBroj from " + odo.VratiImeTabele();
                komanda = new OleDbCommand(upit, konekcija, transakcija);
                OleDbDataReader citac = komanda.ExecuteReader();

                if (citac.Read())
                {
                    try
                    {
                        int rezultat = Convert.ToInt32(citac["MaxBroj"]);
                        return(rezultat + 1);
                    }
                    catch
                    {
                    }
                }
                return(1);
            }
            catch (Exception ex)
            {
                throw ex;
                // return 1;
            }
        }