Beispiel #1
0
        // funkce 5.2
        public static int UpravaStatu(Staty Stat, Database pDb = null)
        {
            Database db;

            if (pDb == null)
            {
                db = new Database();
                db.Connect();
            }
            else
            {
                db = (Database)pDb;
            }

            SqlCommand command = db.CreateCommand(SQL_UPDATE);

            command.Parameters.AddWithValue("@id", Stat.ID);
            command.Parameters.AddWithValue("@nazev", Stat.Nazev);
            command.Parameters.AddWithValue("@narodnost", Stat.Narodnost);
            int ret = db.ExecuteNonQuery(command);

            if (pDb == null)
            {
                db.Close();
            }

            return(ret);
        }
Beispiel #2
0
        private static Collection <Staty> CteniStatu(SqlDataReader reader)
        {
            Collection <Staty> Staty = new Collection <Staty>();

            while (reader.Read())
            {
                int   i    = -1;
                Staty Stat = new Staty();
                Stat.ID        = reader.GetInt32(++i);
                Stat.Nazev     = reader.GetString(++i);
                Stat.Narodnost = reader.GetString(++i);

                Staty.Add(Stat);
            }
            return(Staty);
        }
Beispiel #3
0
        static void Funkce5(Database db)
        {
            db.BeginTransaction();
            Console.WriteLine("");
            Console.WriteLine("Funkce 5 --------------------------");
            Console.WriteLine("");

            Staty Stat = new Staty();

            Stat.Narodnost = "Česká";
            Stat.Nazev     = "Česká Republika";
            EvidenceStatu.VlozeniStatu(Stat, db);   // funkce 5.1

            Stat.Nazev = "Česko";
            EvidenceStatu.UpravaStatu(Stat, db);    // funkce 5.2

            Console.WriteLine();
            Console.WriteLine("Vypis vsech statu (funkce 5.4):");
            Collection <Staty> Staty = EvidenceStatu.VypisStatu(db); // funkce 5.4

            foreach (Staty Polozka in Staty)
            {
                Console.WriteLine(Polozka.ID + "\t" + Polozka.Narodnost + "\t" + Polozka.Nazev);
            }

            EvidenceStatu.SmazaniStatu(30, db);    // funkce 5.3

            Console.WriteLine();
            Console.WriteLine("Vypis tymu z GB (funkce 5.5):");
            Collection <Tymy> Tymy = EvidenceStatu.VypisTymu(2, db); // funkce 5.5

            foreach (Tymy Polozka in Tymy)
            {
                Console.WriteLine(Polozka.ID + "\t" + Polozka.Nazev);
            }

            Console.WriteLine();
            Console.WriteLine("Vypis jezdcu z GB (funkce 5.6):");
            Collection <Jezdci> Jezdci = EvidenceStatu.VypisJezdcu(2, db); // funkce 5.6

            foreach (Jezdci Polozka in Jezdci)
            {
                Console.WriteLine(Polozka.ID + "\t" + Polozka.Jmeno + "\t" + Polozka.Prijmeni);
            }

            db.EndTransaction();
        }
Beispiel #4
0
        // funkce 5.1
        public static int VlozeniStatu(Staty Stat, Database pDb = null)
        {
            Database db;

            if (pDb == null)
            {
                db = new Database();
                db.Connect();
                db.BeginTransaction();
            }
            else
            {
                db = (Database)pDb;
            }

            SqlCommand    command_count = db.CreateCommand(SQL_SELECT_MAX_ID);
            SqlDataReader reader        = db.Select(command_count);

            int id_next = 0;

            while (reader.Read())
            {
                int i = -1;
                id_next = reader.GetInt32(++i);
            }
            id_next++;
            reader.Close();

            SqlCommand command = db.CreateCommand(SQL_INSERT);

            command.Parameters.AddWithValue("@id", id_next);
            command.Parameters.AddWithValue("@nazev", Stat.Nazev);
            command.Parameters.AddWithValue("@narodnost", Stat.Narodnost);
            int ret = db.ExecuteNonQuery(command);

            if (pDb == null)
            {
                db.EndTransaction();
                db.Close();
            }

            return(ret);
        }