Ejemplo n.º 1
0
        public static int update(Prostor Prostor)
        {
            Database db = new Database();

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

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

            db.Close();
            return(ret);
        }
Ejemplo n.º 2
0
        private static Collection <Prostor> Read(SqlDataReader reader, bool withItemsCount = false)
        {
            Collection <Prostor> prostory = new Collection <Prostor>();

            while (reader.Read())
            {
                Prostor prostor = new Prostor();
                int     i       = -1;
                prostor.idSpr      = reader.GetInt32(++i);
                prostor.vzdalenost = reader.GetDouble(++i);

                prostory.Add(prostor);
            }
            return(prostory);
        }
Ejemplo n.º 3
0
        public static Prostor select(int idSpr)
        {
            Database db = new Database();

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

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

            Collection <Prostor> prostory = Read(reader);
            Prostor prostor = null;

            if (prostory.Count == 1)
            {
                prostor = prostory[0];
            }
            reader.Close();
            db.Close();
            return(prostor);
        }
Ejemplo n.º 4
0
        static void SprTest()
        {
            Prostor spr = new Prostor
            {
                idSpr      = 1,
                vzdalenost = 10
            };

            Console.WriteLine("Testovani funkce prostoru Insert - Vypis poctu prvku - update - select - delete - Vypis poctu prvku.\n"
                              + spr.vzdalenost);

            ProstorTable.insert(spr);

            int count = ProstorTable.select().Count;

            spr.vzdalenost = 50;

            ProstorTable.update(spr);

            spr.vzdalenost = 0;

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

            spr = ProstorTable.select(1);

            Console.WriteLine(spr.vzdalenost);

            ProstorTable.delete(1);

            count = ProstorTable.select().Count;

            ProstorTable.insert(spr);


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


            Console.ReadKey();
        }
Ejemplo n.º 5
0
 private static void PrepareCommand(SqlCommand command, Prostor Prostor)
 {
     command.Parameters.AddWithValue("@idSpr", Prostor.idSpr);
     command.Parameters.AddWithValue("@vzdalenost", Prostor.vzdalenost);
 }