To recover Windows 7, you can follow the instructions at Ubuntu boots to grub rescue : Use the Windows Repair Disk to boot into a command prompt on Windows 7 and then run the following commands:
bootrec.exe /FixMbr
Then, to recover Ubuntu, you can follow the instructions at Ubuntu boots to grub rescue :
Boot from a liveCD or a LiveUSB.
Confirm the partition number of your main partition. GParted can help you here. I'm going to assume in this answer that it's /dev/sda2, but make sure you use the correct partition number for your system!
Mount your partition after making sure your hard drive IS /dev/sda2:
sudo mount /dev/sda2 /mnt # make sure that sda2 is correct!
Bind mount some other necessary stuff:
for i in /sys/proc/run/dev; do sudo mount --bind "$i" "/mnt$i"; done
chroot into your Ubuntu install:
sudo chroot /mnt
At this point, you're in your install, not the live CD, and running as root. Update grub:
update-grub
If you get errors, go to step 7. (Otherwise, 7 is optional.)
Depending on your situation, you might have to reinstall grub:
grub-install /dev/sda
update-grub
I'm not sure if this is necessary, but it doesn't hurt.
If everything worked without errors, then you're all set:
exit
sudo reboot
At this point, you should be able to boot normally.