Beispiel #1
0
        public static int update(Zakaznik Zakaznik)
        {
            Database db = new Database();

            db.Connect();
            SqlCommand command = db.CreateCommand(SQL_UPDATE);

            PrepareCommand(command, Zakaznik);
            int ret = db.ExecuteNonQuery(command);

            db.Close();
            return(ret);
        }
Beispiel #2
0
        private static Collection <Zakaznik> Read(SqlDataReader reader, bool withItemsCount = false)
        {
            Collection <Zakaznik> zakaznici = new Collection <Zakaznik>();

            while (reader.Read())
            {
                Zakaznik zakaznik = new Zakaznik();
                int      i        = -1;
                zakaznik.idZak          = reader.GetInt32(++i);
                zakaznik.Jmeno          = reader.GetString(++i);
                zakaznik.Prijmeni       = reader.GetString(++i);
                zakaznik.email          = reader.GetString(++i);
                zakaznik.Datum_narozeni = reader.GetDateTime(++i).Date;

                zakaznici.Add(zakaznik);
            }
            return(zakaznici);
        }
Beispiel #3
0
        static void ZakTest()
        {
            Zakaznik zak = new Zakaznik
            {
                idZak          = 1,
                Jmeno          = "Frank",
                Prijmeni       = "Castle",
                email          = "*****@*****.**",
                Datum_narozeni = new DateTime(1985, 6, 25)
            };

            Console.WriteLine("Testovani funkce zakaznika Insert - Vypis poctu prvku - update - select - delete - Vypis poctu prvku.\n"
                              + zak.Jmeno + " " + zak.Prijmeni);

            ZakaznikTable.Insert(zak);

            int count = ZakaznikTable.select().Count;

            zak.Jmeno    = "Franta";
            zak.Prijmeni = "Hrad";

            ZakaznikTable.update(zak);

            zak.Jmeno    = "a";
            zak.Prijmeni = "b";

            Console.WriteLine("#C: " + count);

            zak = ZakaznikTable.select(1);

            Console.WriteLine(zak.Jmeno + " " + zak.Prijmeni);

            ZakaznikTable.delete(1);

            count = ZakaznikTable.select().Count;

            ZakaznikTable.Insert(zak);

            //Console.WriteLine("Vypis nejpopularnejsich zbrani pro kazdeho zakaznika: \n" + ZakaznikTable.NejpopularnejsiZbrane());

            Console.WriteLine("#C: " + count + "\n" + "Test pro tabulku zakaznik ukoncen, stisknutim libovolne klavesy pokracujte k dalsimu testu.");

            Console.ReadKey();
        }
Beispiel #4
0
        public static Zakaznik select(int idZak)
        {
            Database db = new Database();

            db.Connect();
            SqlCommand command = db.CreateCommand(SQL_SELECT_ID);

            command.Parameters.AddWithValue("@idZak", idZak);
            SqlDataReader reader = db.Select(command);

            Collection <Zakaznik> zakaznici = Read(reader);
            Zakaznik zakaznik = null;

            if (zakaznici.Count == 1)
            {
                zakaznik = zakaznici[0];
            }
            reader.Close();
            db.Close();
            return(zakaznik);
        }