예제 #1
0
        public static List <ClanKnjige> GetAll(SqlConnection conn)
        {
            List <ClanKnjige> sviCK = new List <ClanKnjige>();

            try
            {
                string query = "SELECT * " +
                               "FROM clan_knjige "
                ;
                SqlCommand cmd = new SqlCommand(query, conn);

                SqlDataReader r = cmd.ExecuteReader();
                while (r.Read())
                {
                    int id       = (int)r["id"];
                    int clanId   = (int)r["clan_id"];
                    int knjigaId = (int)r["knjiga_id"];

                    Clan   clan   = ClanDAO.GetClanById(Program.conn, clanId);
                    Knjiga knjiga = KnjigaDAO.GetKnjigaById(Program.conn, knjigaId);

                    sviCK.Add(new ClanKnjige(id, clan, knjiga));
                }
                r.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(sviCK);
        }
예제 #2
0
        public static ClanKnjige GetClanKnjigaById(SqlConnection conn, int id)
        {
            ClanKnjige clanKnjige = null;

            try
            {
                string query = "SELECT clan_id,knjiga_id " +
                               "FROM clan_knjige " +
                               "WHERE id = " + id;
                SqlCommand cmd = new SqlCommand(query, conn);

                SqlDataReader r = cmd.ExecuteReader();
                if (r.Read())
                {
                    int clanId   = (int)r["clan_id"];
                    int knjigaId = (int)r["knjiga_id"];

                    Clan   clan   = ClanDAO.GetClanById(Program.conn, clanId);
                    Knjiga knjiga = KnjigaDAO.GetKnjigaById(Program.conn, knjigaId);

                    clanKnjige = new ClanKnjige(id, clan, knjiga);
                }
                r.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(clanKnjige);
        }