Exemplo n.º 1
0
        private void scheduleButton_Click(object sender, EventArgs e)
        {
            DialogResult result = ScheduleDialog.ShowDialog("Scheduling Parameters", ref interval, ref additionalInfo);

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                string message = "Please Click the Save Button to store the Settings";
                okButton.Text         = "Save Scheduling &Settings";
                okButton.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                MessageBox.Show(message, "Information",
                                MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                scheduleLabel.Text = GetDisplaySchedule(interval, additionalInfo);
            }
        }
Exemplo n.º 2
0
        ///
        public static DialogResult ShowDialog(string caption, ref RunInterval interval, ref string additionalInfo)
        {
            ScheduleDialog dialog = new ScheduleDialog();

            // interval = RunInterval.None;
            // additionalInfo = "";
            if (interval != RunInterval.None && !String.IsNullOrEmpty(additionalInfo))
            {
                int index = dialog.intervalComboBox.FindString(interval.ToString());
                if (index != -1)
                {
                    dialog.intervalComboBox.SelectedIndex = index;
                }

                switch (interval)
                {
                case RunInterval.Hourly:
                    dialog.addInfoDateTimePicker1.Value = DateTime.ParseExact(additionalInfo,
                                                                              "mm:ss", CultureInfo.InvariantCulture);
                    break;

                case RunInterval.Daily:
                    dialog.addInfoDateTimePicker1.Value = DateTime.ParseExact(additionalInfo,
                                                                              "HH:mm", CultureInfo.InvariantCulture);

                    // dialog.addInfoComboBox.SelectedIndex = dialog.addInfoComboBox.FindString(additionalInfo);
                    break;

                case RunInterval.Weekly:
                    string day = additionalInfo.Substring(0, additionalInfo.IndexOf(" at "));
                    dialog.addInfoComboBox.SelectedIndex = dialog.addInfoComboBox.FindString("Every " + day.Trim());
                    string time = additionalInfo.Substring(additionalInfo.IndexOf(" at ") + " at ".Length - 1);
                    dialog.addInfoDateTimePicker1.Value = DateTime.ParseExact(time.Trim(),
                                                                              "HH:mm", CultureInfo.InvariantCulture);
                    break;

                case RunInterval.Fortnightly:
                    day = additionalInfo.Substring(0, additionalInfo.IndexOf(" at "));
                    dialog.addInfoComboBox.SelectedIndex = dialog.addInfoComboBox.FindString("Alternate " + day.Trim());
                    time = additionalInfo.Substring(additionalInfo.IndexOf(" at ") + " at ".Length - 1);
                    dialog.addInfoDateTimePicker1.Value = DateTime.ParseExact(time.Trim(),
                                                                              "HH:mm", CultureInfo.InvariantCulture);
                    break;

                case RunInterval.Monthly:
                    // dialog.addInfoComboBox.SelectedIndex = dialog.addInfoComboBox.FindString(additionalInfo);
                    day = additionalInfo.Substring(additionalInfo.IndexOf("On ") + "On ".Length,
                                                   additionalInfo.IndexOf(" @ ") - " @ ".Length);
                    time = additionalInfo.Substring(additionalInfo.IndexOf(" @ ") + " @ ".Length);
                    DateTime t = Convert.ToDateTime(
                        new DateTime(DateTime.Today.Year, DateTime.Today.Month, Convert.ToInt32(day)).ToShortDateString()
                        + " " + time);
                    dialog.addInfoDateTimePicker1.MinDate = DateTime.Now.AddDays(-1);
                    dialog.addInfoDateTimePicker1.Value   = t;
                    dialog.addInfoDateTimePicker1.MaxDate = DateTime.Now.AddDays(1);
                    break;

                case RunInterval.Yearly:
                    dialog.addInfoDateTimePicker1.MinDate = DateTime.Now.AddYears(-1);
                    dialog.addInfoDateTimePicker1.Value   = DateTime.ParseExact(additionalInfo,
                                                                                "dd-MMM @ hh:mm", CultureInfo.InvariantCulture);
                    dialog.addInfoDateTimePicker1.MaxDate = DateTime.Now.AddYears(1);
                    break;

                default:
                    // do nothing
                    break;
                }
            }
            // Set the members of the new instance
            // according to the value of the parameters
            if (string.IsNullOrEmpty(caption))
            {
                dialog.Text = Application.ProductName;
            }
            else
            {
                dialog.Text = caption;
            }

            // Declare a variable to hold the result to be
            // returned on exitting the method
            DialogResult result = DialogResult.None;

            // Loop round until the user enters
            // some valid data, or cancels.
            while (result == DialogResult.None)
            {
                result = dialog.ShowDialog();
                if (result == DialogResult.OK)
                {
                    bool success = dialog.Validate(out interval, out additionalInfo);
                    if (success)
                    {
                        result = DialogResult.OK;
                    }
                    else
                    {
                        result = DialogResult.None;
                    }
                }
                else
                {
                    result = DialogResult.Cancel;
                }
            }

            // Trash the dialog if it is hanging around.
            dialog.Dispose();

            // Send back the result.
            return(result);
        }