public List <Izdavac> GetAllIzdavac() { var result = new List <Izdavac>(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = SELECT; reader = cmd.ExecuteReader(); while (reader.Read()) { result.Add(new Izdavac() { IdIzdavac = reader.GetInt32(0), IdMjesto = reader.GetInt32(1), Naziv = reader.GetString(2), Adresa = reader.GetString(3) }); } } catch (Exception ex) { throw new DataAccessException("Exception in MySqlIzdavac", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }
public Izdavac GetIzdavacByID(int IdIzdavac) { var result = new Izdavac(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM `Izdavac` WHERE IdIzdavac=@IdIzdavac"; cmd.Parameters.AddWithValue("@IdAutor", IdIzdavac); reader = cmd.ExecuteReader(); reader.Read(); result = new Izdavac() { IdIzdavac = reader.GetInt32(0), IdMjesto = reader.GetInt32(1), Naziv = reader.GetString(2), Adresa = reader.GetString(3) }; } catch (Exception ex) { throw new DataAccessException("Exception in MySqlIzdavac", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }
public int GetUkupanBrojPozajmicaByKnjigaId(int IdKnjiga) { MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; int count = 0; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "SELECT COUNT(*) FROM `Pozajmica` WHERE IdKnjiga=@IdKnjiga AND JeRazduzena=0;"; cmd.Parameters.AddWithValue("@IdKnjiga", IdKnjiga); reader = cmd.ExecuteReader(); reader.Read(); count = reader.GetInt32(0); } catch (Exception ex) { throw new DataAccessException("Exception in MySqlPozajmica", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(count); }
public Tema GetTemaByOsobaId(int id) { var tema = new Tema(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = SELECT; cmd.Parameters.AddWithValue("@IdOsoba", id); reader = cmd.ExecuteReader(); reader.Read(); tema.IdTema = reader.GetInt32(0); tema.IdOsoba = reader.GetInt32(1); tema.Stil = reader.GetInt32(2); } catch (Exception ex) { throw new DataAccessException("Exception in MySqlTema", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(tema); }
public int GetBrojAutora() { var count = 0; MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "SELECT COUNT(*) FROM `Autor`"; reader = cmd.ExecuteReader(); reader.Read(); count = reader.GetInt32(0); } catch (Exception ex) { throw new DataAccessException("Exception in MySqlAutor", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(count); }
public void PozajmicaRazduzi(int id) { MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; int count = 0; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "UPDATE Pozajmica SET JeRazduzena=1 WHERE IdPozajmica=@IdPozajmica"; cmd.Parameters.AddWithValue("@IdPozajmica", id); reader = cmd.ExecuteReader(); reader.Read(); } catch (Exception ex) { throw new DataAccessException("Exception in MySqlPozajmica", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } }
public Pozajmica GetPozajmicaByClanID(int IdClan) { var result = new Pozajmica(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM `Pozajmica` WHERE IdClan=@IdClan"; cmd.Parameters.AddWithValue("@IdClan", IdClan); reader = cmd.ExecuteReader(); reader.Read(); result = new Pozajmica() { IdPozajmica = reader.GetInt32(0), IdClan = reader.GetInt32(1), IdBibliotekar = reader.GetInt32(2), DatumPozajmljivanja = reader.GetDateTime(3), JeRazduzena = reader.GetBoolean(4), Opis = reader.GetString(5) }; } catch (Exception ex) { throw new DataAccessException("Exception in MySqlPozajmica", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }
public int GetUkupanBrojKasnihPozajmica() { MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; int count = 0; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "SELECT COUNT(*) FROM `Pozajmica` WHERE DATE_ADD(DatumPozajmljivanja, INTERVAL @NumberOfDays DAY) < CURDATE() AND JeRazduzena=false;"; cmd.Parameters.AddWithValue("@NumberOfDays", DUZINA_POZAJMICE); reader = cmd.ExecuteReader(); reader.Read(); count = reader.GetInt32(0); } catch (Exception ex) { throw new DataAccessException("Exception in MySqlPozajmica", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(count); }
public void PozajmicaProduzi(int id) { MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; int count = 0; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "UPDATE Pozajmica SET DatumPozajmljivanja=DATE_ADD(DatumPozajmljivanja, INTERVAL @NumberOfDays DAY) WHERE IdPozajmica=@IdPozajmica"; cmd.Parameters.AddWithValue("@NumberOfDays", PRODUZAVANJE); cmd.Parameters.AddWithValue("@IdPozajmica", id); reader = cmd.ExecuteReader(); reader.Read(); } catch (Exception ex) { throw new DataAccessException("Exception in MySqlPozajmica", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } }
public Bibliotekar GetBibliotekarById(int id) { var result = new Bibliotekar(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM `Bibliotekar` WHERE IdBibliotekar=@IdBibliotekar"; cmd.Parameters.AddWithValue("@IdBibliotekar", id); reader = cmd.ExecuteReader(); reader.Read(); result = new Bibliotekar() { IdBibliotekar = reader.GetInt32(0), KorisnickoIme = reader.GetString(1), Lozinka = reader.GetString(2) }; } catch (Exception ex) { throw new DataAccessException("Exception in MySqlBibliotekar", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }
public List <Bibliotekar> GetAllBibliotekar() { var result = new List <Bibliotekar>(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = SELECT; reader = cmd.ExecuteReader(); while (reader.Read()) { result.Add(new Bibliotekar() { IdBibliotekar = reader.GetInt32(0), KorisnickoIme = reader.GetString(1), Lozinka = reader.GetString(2) }); } } catch (Exception ex) { throw new DataAccessException("Exception in MySqlBibliotekar", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }
public int GetBrojKopijaById(int id) { var count = 0; MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "SELECT SUM(UkupanBrojKopija) FROM `Knjiga` WHERE IdKnjiga=@IdKnjiga"; cmd.Parameters.AddWithValue("@IdKnjiga", id); reader = cmd.ExecuteReader(); reader.Read(); count = reader.GetInt32(0); } catch (Exception ex) { throw new DataAccessException("Exception in MySqlKnjiga", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(count); }
public int GetUkupanBrojPozajmica() { MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; int count = 0; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "SELECT COUNT(*) FROM `Pozajmica` WHERE JeRazduzena=false;"; reader = cmd.ExecuteReader(); reader.Read(); count = reader.GetInt32(0); } catch (Exception ex) { throw new DataAccessException("Exception in MySqlPozajmica", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(count); }
public float GetPozajmicaCijena(int id) { MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; float sum = 0; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "SELECT SUM(DATEDIFF(CURDATE(),DATE_ADD(DatumPozajmljivanja, INTERVAL 30 DAY)))*@CijenaPoDanu AS Iznos FROM `Pozajmica` WHERE (DATE_ADD(DatumPozajmljivanja, INTERVAL 30 DAY) < CURDATE()) AND JeRazduzena=false;"; cmd.Parameters.AddWithValue("@NumberOfDays", DUZINA_POZAJMICE); cmd.Parameters.AddWithValue("@CijenaPoDanu", CIJENA_PO_DANU); reader = cmd.ExecuteReader(); reader.Read(); try { sum = reader.GetFloat(0); } catch (Exception exc) { sum = 0; } } catch (Exception ex) { throw new DataAccessException("Exception in MySqlPozajmica", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(sum); }
public Autor GetAutorByID(int IdAutor) { var result = new Autor(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM `Autor` WHERE IdAutor=@IdAutor"; cmd.Parameters.AddWithValue("@IdAutor", IdAutor); reader = cmd.ExecuteReader(); reader.Read(); result = new Autor() { IdAutor = reader.GetInt32(0), IdMjesto = reader.GetInt32(1), Ime = reader.GetString(2), Prezime = reader.GetString(3), DatumRodjenja = reader.GetDateTime(4) }; } catch (Exception ex) { throw new DataAccessException("Exception in MySqlAutor", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }
public Mjesto GetMjestoByNaziv(string naziv) { var result = new Mjesto(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM `Mjesto` WHERE Naziv=@Naziv"; cmd.Parameters.AddWithValue("@Naziv", naziv); reader = cmd.ExecuteReader(); reader.Read(); result = new Mjesto() { IdMjesto = reader.GetInt32(0), Naziv = reader.GetString(1), PostanskiBroj = reader.GetString(2) }; } catch (Exception ex) { throw new DataAccessException("Exception in MySqlMjesto", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }
public List <Zanr> GetAllZanr() { List <Zanr> result = new List <Zanr>(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = SELECT; reader = cmd.ExecuteReader(); while (reader.Read()) { result.Add(new Zanr() { Naziv = reader.GetString(0), Opis = reader.GetString(1) }); } } catch (Exception ex) { throw new DataAccessException("Exception in MySqlZanr", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }
public Administrator GetAdminrByUsername(string korisnickoIme) { var result = new Administrator(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM `Administrator` WHERE KorisnickoIme=@KorisnickoIme"; cmd.Parameters.AddWithValue("@KorisnickoIme", korisnickoIme); reader = cmd.ExecuteReader(); reader.Read(); result = new Administrator() { IdAdministrator = reader.GetInt32(0), KorisnickoIme = reader.GetString(1), Lozinka = reader.GetString(2) }; } catch (Exception ex) { throw new DataAccessException("Exception in MySqlBibliotekar", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }
public List <Autor> GetAllAutor() { var result = new List <Autor>(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = SELECT; reader = cmd.ExecuteReader(); while (reader.Read()) { result.Add(new Autor() { IdAutor = reader.GetInt32(0), IdMjesto = reader.GetInt32(1), Ime = reader.GetString(2), Prezime = reader.GetString(3), DatumRodjenja = reader.GetDateTime(4) }); } } catch (Exception ex) { throw new DataAccessException("Exception in MySqlAutor", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }
public List <Clan> GetAllClan() { var result = new List <Clan>(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = SELECT; reader = cmd.ExecuteReader(); while (reader.Read()) { result.Add(new Clan() { IdClan = reader.GetInt32(0), DatumUclanjivanja = reader.GetDateTime(1), DatumObnavljanjaClanstva = reader.GetDateTime(2) }); } } catch (Exception ex) { throw new DataAccessException("Exception in MySqlClan", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }
public Clan GetClanByID(int IdClan) { var result = new Clan(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM `Clan` WHERE IdClan=@IdClan"; cmd.Parameters.AddWithValue("@IdClan", IdClan); reader = cmd.ExecuteReader(); reader.Read(); result = new Clan() { IdClan = reader.GetInt32(0), DatumUclanjivanja = reader.GetDateTime(1), DatumObnavljanjaClanstva = reader.GetDateTime(2) }; } catch (Exception ex) { throw new DataAccessException("Exception in MySqlClan", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }
public DataTable GetObavjestenjeJoin(int idBibliotekar) { var table = new DataTable(); //Define columns var Ime = new DataColumn("Ime", typeof(string)); var Prezime = new DataColumn("Prezime", typeof(string)); var IdBibliotekar = new DataColumn("IdBibliotekar", typeof(int)); var Naslov = new DataColumn("Naslov", typeof(string)); var Datum = new DataColumn("Datum", typeof(string)); var Tekst = new DataColumn("Tekst", typeof(string)); var ZaSve = new DataColumn("ZaSve", typeof(int)); //Add columns to a table table.Columns.Add(Ime); table.Columns.Add(Prezime); table.Columns.Add(IdBibliotekar); table.Columns.Add(Naslov); table.Columns.Add(Datum); table.Columns.Add(Tekst); table.Columns.Add(ZaSve); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = JOIN; cmd.Parameters.AddWithValue("@IdBibliotekar", idBibliotekar); reader = cmd.ExecuteReader(); while (reader.Read()) { var row = table.NewRow(); row[0] = reader.GetString(0); row[1] = reader.GetString(1); row[2] = reader.GetInt32(2); row[3] = reader.GetString(3); row[4] = reader.GetDateTime(4).ToShortDateString(); row[5] = reader.GetString(5); row[6] = reader.GetInt32(6); table.Rows.Add(row); } } catch (Exception ex) { throw new DataAccessException("Exception in MySqlKnjiga", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(table); }
public List <Knjiga> GetAllKnjigaByNaslov(string naslov) { var result = new List <Knjiga>(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM `Knjiga` WHERE Naslov LIKE @Naslov "; cmd.Parameters.AddWithValue("@Naslov", naslov + "%"); reader = cmd.ExecuteReader(); while (reader.Read()) { result.Add(new Knjiga() { IdKnjiga = reader.GetInt32(0), NazivZanra = reader.GetString(1), IdIzdavac = reader.GetInt32(2), Naslov = reader.GetString(3), DatumObjavljivanja = reader.GetDateTime(4), ISBN = reader.GetString(5), UkupanBrojKopija = reader.GetInt32(6), BrojStranica = reader.GetInt32(7), Jezik = reader.GetString(8), Opis = reader.GetString(9) }); } } catch (Exception ex) { throw new DataAccessException("Exception in MySqlKnjiga", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }
public List <Knjiga> GetAllKnjiga() { var result = new List <Knjiga>(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = SELECT; reader = cmd.ExecuteReader(); while (reader.Read()) { result.Add(new Knjiga() { IdKnjiga = reader.GetInt32(0), NazivZanra = reader.GetString(1), IdIzdavac = reader.GetInt32(2), IdAutor = reader.GetInt32(3), Naslov = reader.GetString(4), DatumObjavljivanja = reader.GetDateTime(5), ISBN = reader.GetString(6), UkupanBrojKopija = reader.GetInt32(7), BrojStranica = reader.GetInt32(8), Jezik = reader.GetString(9), Opis = reader.GetString(10) }); } } catch (Exception ex) { throw new DataAccessException("Exception in MySqlKnjiga", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }
public void DeleteOsobaById(int IdOsoba) { MySqlConnection conn = null; MySqlCommand cmd; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = DELETE; cmd.Parameters.AddWithValue("@IdOsoba", IdOsoba); cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new DataAccessException("Exception in MySqlOsoba", ex); } finally { MySqlUtil.CloseQuietly(conn); } }
public List <Osoba> GetAllOsoba() { var result = new List <Osoba>(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = SELECT; reader = cmd.ExecuteReader(); while (reader.Read()) { result.Add(new Osoba() { IdOsoba = reader.GetInt32(0), NazivMjesta = reader.GetString(1), Ime = reader.GetString(2), Prezime = reader.GetString(3), Adresa = reader.GetString(4), BrojTelefona = reader.GetString(5), Email = reader.GetString(6), DatumRodjenja = reader.GetDateTime(7) }); } } catch (Exception ex) { throw new DataAccessException("Exception in MySqlOsoba", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }
public void UpdateClanstvo(int id) { MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "update Clan set DatumObnavljanjaClanstva=DATE_ADD(CURDATE(), INTERVAL 1 YEAR) where IdClan=@IdClan;"; cmd.Parameters.AddWithValue("@IdClan", id); reader = cmd.ExecuteReader(); } catch (Exception ex) { throw new DataAccessException("Exception in MySqlClan", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } }
private void UpdateTema(Tema tema) { MySqlConnection connection = null; MySqlCommand cmd; try { connection = MySqlUtil.GetConnection(); cmd = connection.CreateCommand(); cmd.CommandText = UPDATE; cmd.Parameters.AddWithValue("@IdOsoba", tema.IdOsoba); cmd.Parameters.AddWithValue("@Stil", tema.Stil); cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new DataAccessException("Exception in MySqlTema", ex); } finally { MySqlUtil.CloseQuietly(connection); } }
private void UpdateZanr(Zanr zanr) { MySqlConnection conn = null; MySqlCommand cmd; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = UPDATE; cmd.Parameters.AddWithValue("@Naziv", zanr.Naziv); cmd.Parameters.AddWithValue("@Opis", zanr.Opis); cmd.ExecuteNonQuery(); } catch (Exception ex) { throw new DataAccessException("Exception in MySqlZanr", ex); } finally { MySqlUtil.CloseQuietly(conn); } }
public Osoba GetOsobaByID(int IdOsoba) { var result = new Osoba(); MySqlConnection conn = null; MySqlCommand cmd; MySqlDataReader reader = null; try { conn = MySqlUtil.GetConnection(); cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM `Osoba` WHERE IdOsoba=@IdOsoba"; cmd.Parameters.AddWithValue("@IdOsoba", IdOsoba); reader = cmd.ExecuteReader(); reader.Read(); result = new Osoba() { IdOsoba = reader.GetInt32(0), NazivMjesta = reader.GetString(1), Ime = reader.GetString(2), Prezime = reader.GetString(3), Adresa = reader.GetString(4), BrojTelefona = reader.GetString(5), Email = reader.GetString(6), DatumRodjenja = reader.GetDateTime(7) }; } catch (Exception ex) { throw new DataAccessException("Exception in MySqlOsoba", ex); } finally { MySqlUtil.CloseQuietly(reader, conn); } return(result); }