Exemplo n.º 1
0
        /// <summary>
        /// Dohvaca sve tipove vozila
        /// </summary>
        /// /// <returns>
        /// List<tip_vozila> ili null
        /// </returns>
        public static List <tip_vozila> getAllTipVozila()
        {
            List <tip_vozila> filler = new List <tip_vozila>();

            using (SqlConnection c = new SqlConnection(CONNECTION_STRING))
            {
                c.Open();
                using (SqlDataAdapter a = new SqlDataAdapter("select * from tip_vozila", c))
                {
                    DataTable t = new DataTable();
                    a.Fill(t);
                    if (t.Rows.Count > 0)
                    {
                        foreach (DataRow dr in t.Rows)
                        {
                            tip_vozila tv = new tip_vozila
                            {
                                id  = Convert.ToInt16(dr["id"]),
                                tip = Convert.ToString(dr["tip"])
                            };
                            filler.Add(tv);
                        }
                        return(filler);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Dohvaca tip vozila
 /// </summary>
 /// <param int="ID">Tip vozila ID</param>
 /// /// <returns>
 /// <c>tip_vozila</c> ili null
 /// </returns>
 public static tip_vozila getTipVozila(int ID)
 {
     if (!Validators.validID(ID))
     {
         return(null);
     }
     using (SqlConnection c = new SqlConnection(CONNECTION_STRING))
     {
         c.Open();
         using (SqlDataAdapter a = new SqlDataAdapter("select * from tip_vozila where id=@ID", c))
         {
             a.SelectCommand.Parameters.Add(new SqlParameter
             {
                 ParameterName = "@ID",
                 Value         = ID,
                 SqlDbType     = SqlDbType.Int
             });
             DataTable t = new DataTable();
             a.Fill(t);
             if (t.Rows.Count > 0)
             {
                 tip_vozila tv = new tip_vozila
                 {
                     id  = Convert.ToInt16(t.Rows[0]["id"]),
                     tip = Convert.ToString(t.Rows[0]["tip"])
                 };
                 return(tv);
             }
             else
             {
                 return(null);
             }
         }
     }
 }