コード例 #1
0
        /// <summary>
        /// Brskanje baze po uporabniškem imenu
        /// </summary>
        /// <param name="uporabniskoIme">Brska se po parametru 'Uporabnik'</param>
        /// <returns>Eneg uporabnika ali prazno listo</returns>
        public static List <Uporabnik> Brskaj(int idUporabnika = -1, string uporabniskoIme = "")
        {
            SqlConnection con = new SqlConnection(Nastavitve.GetConnectionString());
            SqlCommand    cmd = new SqlCommand();

            string where = " 1 = 1 ";
            if (uporabniskoIme != "")
            {
                where += " AND (Uporabnik = '" + uporabniskoIme + "')";
            }
            if (idUporabnika != -1)
            {
                where += " AND (Id = " + idUporabnika + ")";
            }
            //                       0   1      2       3        4            5           6
            string select = "SELECT Id, Ime, Priimek, Email, Uporabnik, TipUporabnika, Kovanc " +
                            "FROM [StackDB].[dbo].[tblUporabnik] WHERE" + where;

            cmd.CommandText = select;
            cmd.Connection  = con;

            List <Uporabnik> lista = new List <Uporabnik>();

            try
            {
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    int           id          = reader.GetInt32(0);
                    string        ime         = reader.IsDBNull(1) ? "" : reader.GetString(1).Trim();
                    string        priimek     = reader.IsDBNull(2) ? "" : reader.GetString(2).Trim();
                    string        email       = reader.IsDBNull(3) ? "" : reader.GetString(3).Trim();
                    string        uporabnisko = reader.GetString(4).Trim();
                    TipUporabnika tip         = (TipUporabnika)reader.GetInt32(5);
                    int           kovanc      = reader.GetInt32(6);

                    Uporabnik uporabnik = new Uporabnik(id, ime, priimek, email, uporabnisko, tip, kovanc);
                    lista.Add(uporabnik);
                }
                reader.Close();
                return(lista);
            }
            catch (TimeoutException tEx)
            {
                // Zapisivanje u log
                return(null);
            }
            catch (Exception ex)
            {
                // log
                return(null);
            }
            finally
            {
                con.Close();
            }
        }
コード例 #2
0
 public Uporabnik(int id, string ime, string priimek, string email, string uporabnisko, TipUporabnika tip, int kovanc)
 {
     Id          = id;
     Ime         = ime;
     Priimek     = priimek;
     Email       = email;
     Uporabnisko = uporabnisko;
     Tip         = tip;
     Kovanc      = kovanc;
 }