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

            try
            {
                string query = "SELECT id, ucenik_id, uplata_id " +
                               "FROM uplata_ucenika";
                SqlCommand cmd = new SqlCommand(query, conn);

                SqlDataReader r = cmd.ExecuteReader();

                while (r.Read())
                {
                    int id       = (int)r["id"];
                    int uplataId = (int)r["uplata_id"];
                    int ucenikId = (int)r["ucenik_id"];

                    Uplata uplata = UplataDAO.GetUplataById(Program.conn, uplataId);
                    Ucenik ucenik = UcenikDAO.GetUcenikById(Program.conn, ucenikId);

                    sveUplateIUcenici.Add(new UplataUcenika(id, uplata, ucenik));
                }
                r.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(sveUplateIUcenici);
        }
예제 #2
0
        public static UplataUcenika GetUplataByUcenikId(SqlConnection conn, int id)
        {
            UplataUcenika uplUc = null;

            try
            {
                string query = "SELECT uplata_id, ucenik_id " +
                               "FROM uplata_ucenika " +
                               "WHERE id=" + id;
                SqlCommand cmd = new SqlCommand(query, conn);

                SqlDataReader r = cmd.ExecuteReader();
                if (r.Read())
                {
                    int uplataId = (int)r["uplata_id"];
                    int ucenikId = (int)r["ucenik_id"];

                    Uplata uplata = UplataDAO.GetUplataById(Program.conn, uplataId);
                    Ucenik ucenik = UcenikDAO.GetUcenikById(Program.conn, ucenikId);

                    uplUc = new UplataUcenika(id, uplata, ucenik);
                }
                r.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(uplUc);
        }