EmailExporter(Person[] people, StatementBuilder pageBuilder)
        {
            InitializeComponent();
            this.people = people;

            if (people.Length == 1)
                gridCaption.Text = "The following person will receive emails:";
            else
                gridCaption.Text = "The following " + people.Length.ToString(CultureInfo.CurrentCulture) + " people will receive emails:";

            sendPreviewButton = buttonEdit.Buttons[1];
            showPreviewButton = buttonEdit.Buttons[0];

            startDate.DateTime = new DateTime(DateTime.Today.AddDays(-80).Year, 1, 1);
            startDate.Properties.MaxValue = DateTime.Today;

            grid.DataSource = new RowListBinder(Program.Table<Person>(), (Row[])people);
            gridView.BestFitColumns();

            PageBuilder = pageBuilder;
            emailTemplate.Properties.Items.AddRange(pageBuilder.Templates.ToList());
            emailTemplate.Properties.DropDownRows = Math.Max(emailTemplate.Properties.Items.Count, 7);
            SetEnabled();
        }
        public static void Execute(Form parent, params Person[] people)
        {
            if (people == null) throw new ArgumentNullException("people");
            var originalPeople = people;
            people = people.Where(r => r.EmailAddresses.Count > 0).Distinct().ToArray();

            if (people.Length == 0) {
                if (originalPeople.Length == 1)
                    XtraMessageBox.Show(originalPeople[0].FullName + " do not have any email addresses.",
                                        "Shomrei Torah Billing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else
                    XtraMessageBox.Show("None of the people you selected have email addresses.",
                                        "Shomrei Torah Billing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            Program.Current.RefreshDatabase();

            var pageBuilder = new StatementBuilder(
                Path.Combine(Program.AppDirectory, @"Email Templates\Statements"),
                Path.Combine(Program.AppDirectory, @"Email Templates\Images")
            );
            if (!pageBuilder.Templates.Any()) {
                XtraMessageBox.Show("There are no email templates.\r\nPlese contact Schabse.",
                                    "Shomrei Torah Billing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            new EmailExporter(people, pageBuilder).Show(parent);
        }