There are several things you can try. First, if you go into the orders menu, there should be an option to keep them inside--by default, it says something like "Dwarves Go Outdoors." However, I think the better option is #2...
Use the Burrows screen (the [w] key) and designate a "safe area" where you want all your dwarves to be limited to. Making a burrow selection is similar to designating tiles for digging, etc. except you can make it span multiple z-levels. This way makes it very quick to designate your entire fortress. After you've designated your safety burrow, you have to create a new "alert level" for your fortress, and assign your safety burrow to it. Pressing [m] gets you into the military screen, and then [a] gets you into the alert screen. Press [c] to create the new alert, and then select it and press [shift]+[N] to name it. I named mine "Emergency." Make sure your "Emergency" burrow is selected, move your cursor to the right-most pane in the screen where it shows your newly-created safety burrow, and press [Enter]. This makes it so that any dwarves who are under the "Emergency" alert will be limited to the safety burrow. Now you just have to add your civilians to this alert. Move your cursor all the way to the left, highlight the "Emergency" alert, and press [Enter]. Now, a small marker should appear next to "Emergency." It should say [CIV]. This means that your civilians are all on "Emergency" alert status and they will stay in the burrow you designated. To reverse this, select the "Inactive" alert status and press [Enter]. Your civilians will perform activities as normal again.