Misfortune depends on fortune, and fortune depends on misfortune: from Chapter 58 of Laozi: "Misfortune depends on fortune, and fortune depends on misfortune." It means that misfortune and happiness are interdependent and can be transformed into each other. Metaphorically, bad things can have good results, and good things can also have bad results.
On the dialectical relationship between fortunes and gains and losses, China made a brilliant summary of many famous sayings, such as:
An old frontiersman loses his horse—a blessing in disguise.
Misfortune depends on happiness, and happiness lies in misfortune.
There is always a ray of light behind the dark clouds, and joy begets sorrow.