public static int Update(Pracoviste pracoviste, MyDatabase pDb = null)
        {
            MyDatabase db;

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

            SqlCommand command = db.CreateCommand(SQL_UPDATE);

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

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

            return(ret);
        }
        private static Collection <Pracoviste> Read(SqlDataReader reader)
        {
            Collection <Pracoviste> pracovisteC = new Collection <Pracoviste>();

            while (reader.Read())
            {
                int        i          = -1;
                Pracoviste pracoviste = new Pracoviste();
                pracoviste.ID_pracoviste = reader.GetInt32(++i);
                int ix = i++;
                pracoviste.ID_nadrizenehoPracoviste = reader.IsDBNull(ix) ? (int?)reader.GetInt32(ix) : null;
                pracoviste.Nazev = reader.GetString(++i);

                pracovisteC.Add(pracoviste);
            }
            return(pracovisteC);
        }
        public static Pracoviste Select(int id, MyDatabase pDb = null)
        {
            MyDatabase db;

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

            SqlCommand command = db.CreateCommand(SQL_SELECT_ID);

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

            Collection <Pracoviste> pracovisteC = Read(reader);
            Pracoviste pracoviste = null;

            if (pracovisteC.Count == 1)
            {
                pracoviste = pracovisteC[0];
            }
            reader.Close();

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

            if (pracoviste == null)
            {
                Console.WriteLine("Pracoviste neexistuje");
            }

            return(pracoviste);
        }
 private static void PrepareCommand(SqlCommand command, Pracoviste pracoviste)
 {
     command.Parameters.AddWithValue("@ID_pracoviste", pracoviste.ID_pracoviste);
     command.Parameters.AddWithValue("@ID_nadrizenehoPracoviste", (object)pracoviste.ID_nadrizenehoPracoviste ?? DBNull.Value);
     command.Parameters.AddWithValue("@Nazev", pracoviste.Nazev);
 }