Dynamical Theory of X-Ray Diffraction in a Crystal with a Surface Grating of Another Material