Beispiel #1
0
        public static ObservableCollection <Avion> vratiAvione()
        {
            SqlConnection cnn     = Konekcija.KreirajKoekciju();
            SqlCommand    komanda = new SqlCommand("SELECT * FROM Avion WHERE Deleted = 0", cnn);

            ObservableCollection <Avion> avioni = new ObservableCollection <Avion>();

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

                while (dr.Read())
                {
                    Avion a = new Avion();

                    a.Id = (int)dr["AvionId"];
                    int brRedovaEklase  = (int)dr["BrojRedovaEkonomskeKlase"];
                    int brSedistaEklase = (int)dr["BrojSedistaUReduEkonomskeKlase"];
                    a.puniListuEkon(brRedovaEklase, brSedistaEklase);
                    int brRedovaBiznis  = (int)dr["BrojRedovaBiznisKlase"];
                    int brSedistaBiznis = (int)dr["BrojSedistaUReduBiznisKlase"];
                    a.puniListuBiz(brRedovaBiznis, brSedistaBiznis);

                    a.AvioKompanija = AvioKompanijaDAO.vratiAvioKompaniju((int)dr["AvioKompanijaId"]);
                    a.Naziv         = dr["Naziv"].ToString();
                    a.Deleted       = Convert.ToBoolean(dr["Deleted"]);

                    if (a.AvioKompanija.Deleted || a.AvioKompanija.Naziv == null)
                    {
                        IzbirisAvio(a);
                    }
                    else
                    {
                        avioni.Add(a);
                    }
                }
            }
            catch (Exception xcp)
            {
                if (cnn.State == ConnectionState.Open)
                {
                    cnn.Close();
                }
                MessageBox.Show(xcp.Message);
                return(null);
            }

            return(avioni);
        }
Beispiel #2
0
        public static Avion vratiAvion(int id)
        {
            SqlConnection cnn     = Konekcija.KreirajKoekciju();
            SqlCommand    komanda = new SqlCommand("SELECT * FROM Avion WHERE AvionId = @AvionId AND Deleted = 0", cnn);

            komanda.Parameters.AddWithValue("AvionId", id);
            Avion a = new Avion();

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

                while (dr.Read())
                {
                    a.Id = (int)dr["AvionId"];
                    int brRedovaEklase  = (int)dr["BrojRedovaEkonomskeKlase"];
                    int brSedistaEklase = (int)dr["BrojSedistaUReduEkonomskeKlase"];
                    a.puniListuEkon(brRedovaEklase, brSedistaEklase);
                    int brRedovaBiznis  = (int)dr["BrojRedovaBiznisKlase"];
                    int brSedistaBiznis = (int)dr["BrojSedistaUReduBiznisKlase"];
                    a.puniListuBiz(brRedovaBiznis, brSedistaBiznis);

                    a.AvioKompanija = AvioKompanijaDAO.vratiAvioKompaniju((int)dr["AvioKompanijaId"]);
                    a.Naziv         = dr["Naziv"].ToString();
                    a.Deleted       = Convert.ToBoolean(dr["Deleted"]);
                }

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

            return(a);
        }