It's a natural thing in life to have ups and downs. Even within a day, something can turn around (positively or negatively). Especially when things don't go as expected, it can be really hard to escape from the negative head space, from that tiny, evil voice inside your head saying all the bad side of things you're thinking. Shouting them, even. The best way to conquer that little voice, I've found, is to, first, recognize that IT is the one talking, not your actual head and heart. Then, fight back, struggle through, whatever it takes to just keep going in spite of that little voice.
Hope for the best and do the hard work it takes to get there. Reach out to friends and loved ones when it's too hard to try alone and remember that you're never truly alone in your struggles.