Esempio n. 1
0
        /// <summary>
        /// Generate instances based on the settings in the pattern control
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event parameters</param>
        protected void btnTestPattern_Click(object sender, EventArgs e)
        {
            Recurrence r = new Recurrence();
            rpRecurrence.GetRecurrence(r);

            // Make the textbox match the pattern control and use it's event handler
            txtRRULE.Text = r.ToString();
            btnTest_Click(sender, e);
        }
Esempio n. 2
0
        /// <summary>
        /// Generate instances for the specified recurrence pattern
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event parameters</param>
        protected void btnTest_Click(object sender, EventArgs e)
        {
            DateTimeCollection dc;
            DateTime dt;
            int start;
            double elapsed;

            try
            {
                lblCount.Text = lblDescription.Text = String.Empty;

                if(!DateTime.TryParse(txtStartDate.Text, CultureInfo.CurrentCulture, DateTimeStyles.None, out dt))
                {
                    lblCount.Text = "Invalid date/time or RRULE format";
                    return;
                }

                // Define the recurrence rule by parsing the text
                Recurrence r = new Recurrence(txtRRULE.Text);
                r.StartDateTime = dt;

                // Synch the pattern control to the RRULE if not called by the pattern's test button
                if(sender != btnTestPattern)
                    rpRecurrence.SetRecurrence(r);

                // Use some limitations to prevent overloading the server or timing out the page if possible
                if(r.Frequency > RecurFrequency.Hourly && (r.MaximumOccurrences == 0 || r.MaximumOccurrences > 5000))
                {
                    r.MaximumOccurrences = 5000;
                    txtRRULE.Text = r.ToString();
                }

                if(r.MaximumOccurrences != 0)
                {
                    if(r.MaximumOccurrences > 5000)
                    {
                        r.MaximumOccurrences = 5000;
                        txtRRULE.Text = r.ToString();
                    }
                }
                else
                    if(r.Frequency == RecurFrequency.Hourly)
                    {
                        if(r.RecurUntil > r.StartDateTime.AddYears(5))
                        {
                            r.RecurUntil = r.StartDateTime.AddYears(5);
                            txtRRULE.Text = r.ToString();
                        }
                    }
                    else
                        if(r.RecurUntil > r.StartDateTime.AddYears(50))
                        {
                            r.RecurUntil = r.StartDateTime.AddYears(50);
                            txtRRULE.Text = r.ToString();
                        }

                // Time the calculation
                start = System.Environment.TickCount;
                dc = r.InstancesBetween(r.StartDateTime, DateTime.MaxValue);
                elapsed = (System.Environment.TickCount - start) / 1000.0;

                // Bind the results to the list box
                lbResults.DataSource = dc;
                lbResults.DataBind();

                lblCount.Text = String.Format("Found {0:N0} instances in {1:N2} " +
                    "seconds ({2:N2} instances/second)", dc.Count, elapsed, dc.Count / elapsed);

                // Show a description of the pattern
                lblDescription.Text = r.ToDescription();
            }
            catch(Exception ex)
            {
                lblCount.Text = ex.Message;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Edit the recurrence pattern using the recurrence editor dialog box
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnDesign_Click(object sender, EventArgs e)
        {
            using(RecurrencePropertiesDlg dlg = new RecurrencePropertiesDlg())
            {
                try
                {
                    Recurrence r = new Recurrence(txtRRULE.Text);
                    r.StartDateTime = dtpStartDate.Value;

                    dlg.SetRecurrence(r);

                    if(dlg.ShowDialog() == DialogResult.OK)
                    {
                        dlg.GetRecurrence(r);
                        txtRRULE.Text = r.ToString();
                    }
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }