In the past, a man raised a lot of sheep, but did not build a sheep pen for them.
One night, a lot of wolves ran down the hill and ate ten of his sheep. He regretted not building a sheep pen like he should have. Only after his sheep were eaten did he construct a sheep pen.
The meaning of this idiom is that events have already happened, and only then are they remedied.