We solve the integral \( I = \int x^{2} e^{x} \sin x \, dx \) using the complex-exponential trick. We note that \( e^{x} \sin x = \Im\big( e^{(1+i)x} \big) \).
First compute:
\[ \int x^{2} e^{(1+i)x} \, dx \]Using the formula \( \int x^{2} e^{ax} \, dx = e^{ax} \left( \frac{x^{2}}{a} - \frac{2x}{a^{2}} + \frac{2}{a^{3}} \right) + C \) for \( a \neq 0 \), and substituting \( a = 1+i \), we have:
\[ \frac{1}{1+i} = \frac{1-i}{2}, \quad \frac{1}{(1+i)^{2}} = -\frac{i}{2}, \quad \frac{1}{(1+i)^{3}} = -\frac{1+i}{4}. \]Therefore:
\[ \int x^{2} e^{(1+i)x} \, dx = e^{(1+i)x} \left( \frac{1-i}{2} x^{2} + i x - \frac{1+i}{2} \right) + C. \]Separate real and imaginary parts:
\[ \frac{1-i}{2}x^{2} + i x - \frac{1+i}{2} = \underbrace{\frac{x^{2}-1}{2}}_{U} + i \underbrace{\frac{-x^{2} + 2x - 1}{2}}_{V}. \]Multiplying by \( e^{(1+i)x} = e^{x}(\cos x + i \sin x) \), the imaginary part is \( e^{x}(U \sin x + V \cos x) \).
Substituting \( U \) and \( V \), we obtain:
\[ I = \frac{e^{x}}{2} \left[ (x^{2} - 1)\sin x + (-x^{2} + 2x - 1)\cos x \right] + C. \]Final boxed answer:
\[ \boxed{ \int x^{2} e^{x} \sin x \, dx = \frac{e^{x}}{2} \left[ (x^{2} - 1)\sin x + (-x^{2} + 2x - 1)\cos x \right] + C } \]