Esempio n. 1
0
        public static ObservableCollection<Karta> vratiKarte()
        {
            SqlConnection cnn = Konekcija.KreirajKoekciju();
            SqlCommand komanda = new SqlCommand("SELECT * FROM Karta WHERE Deleted = 0", cnn);

            ObservableCollection<Karta> karte = new ObservableCollection<Karta>();

            try
            {
                cnn.Open();
                SqlDataReader dr = komanda.ExecuteReader();

                while (dr.Read())
                {
                    Karta k = new Karta();

                    k.KartaId = (int)dr["KartaId"];
                    k.Let = LetDAO.vratiLet((int)dr["LetId"]);
                    Sediste s = new Sediste();
                    s.Id = 1;
                    s.Red = (int)dr["BrojReda"];
                    s.SedisteURedu = (int)dr["BrojSedista"];
                    EtipSedista tip;
                    Enum.TryParse(dr["Klasa"].ToString(), out tip);
                    s.tipSedista = tip;
                    s.Deleted = false;
                    k.Sediste = s;
                    k.Korisnik = KorisnikDAO.vratiKorisnika((int)dr["KorisnikId"]);
                    k.Kapija = dr["Kapija"].ToString();
                    k.Cena = (decimal)dr["Cena"];
                    k.Deleted = Convert.ToBoolean(dr["Deleted"]);

                    if (k.Let.Deleted || k.Let.Sifra == null)
                    {
                        IzbrisiKartu(k);
                       
                    }
                    else
                    {
                        karte.Add(k);
                    }
                    
                }
                cnn.Close();
            }
            catch (Exception xcp)
            {
                if (cnn.State == ConnectionState.Open)
                {
                    cnn.Close();
                }
                MessageBox.Show(xcp.Message);
                return null;
            }
            return karte;
        }
Esempio n. 2
0
        public static List<Karta> VratiKarteULetu(Let let)
        {
            SqlConnection cnn = Konekcija.KreirajKoekciju();
            SqlCommand komanda = new SqlCommand("SELECT * FROM Karta WHERE LetId = @LetID AND Deleted = 0", cnn);

            komanda.Parameters.AddWithValue("@LetID", let.Id);
            List<Karta> karte = new List<Karta>();


            try
            {
                cnn.Open();
                SqlDataReader dr = komanda.ExecuteReader();

                while (dr.Read())
                {
                    Karta k = new Karta();
                    k.KartaId = (int)dr["KartaId"];
                    k.Let = LetDAO.vratiLet((int)dr["LetId"]);
                    Sediste s = new Sediste();
                    s.Id = 1;
                    s.Red = (int)dr["BrojReda"];
                    s.SedisteURedu = (int)dr["BrojSedista"];
                    EtipSedista tip;
                    Enum.TryParse(dr["Klasa"].ToString(), out tip);
                    s.tipSedista = tip;
                    s.Deleted = false;
                    k.Sediste = s;
                    k.Korisnik = KorisnikDAO.vratiKorisnika((int)dr["KorisnikId"]);
                    k.Kapija = dr["Kapija"].ToString();
                    k.Cena = (decimal)dr["Cena"];
                    k.Deleted = Convert.ToBoolean(dr["Deleted"]);

                    karte.Add(k);
                }
            }
            catch (Exception xcp)
            {
                if (cnn.State == ConnectionState.Open)
                {
                    cnn.Close();
                }
                MessageBox.Show(xcp.Message);
                return null;
            }

            return karte;


        }