This example demonstrates how NOV Schedule handles 100,000 appointments with different categories (colors).

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Dom;
using Nevron.Nov.Globalization;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Schedule;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NAppointmentsStressTestExample";
// Create the NOV example and its controls
NWidget exampleContent = CreateExampleContent();
NWidget exampleControls = CreateExampleControls();
if (exampleControls != null)
{
exampleControls.PreferredWidth = 300;
}
// Place the example and its controls in a pair box
NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
pairBox.FillMode = ENStackFillMode.First;
pairBox.FitMode = ENStackFitMode.First;
pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);
// Host the example in the form
NNovWidgetHost host = new NNovWidgetHost(pairBox);
host.Dock = DockStyle.Fill;
Controls.Add(host);
}
#endregion
#region Example
public NWidget CreateExampleContent()
{
// Create a simple schedule
NScheduleViewWithRibbon scheduleViewWithRibbon = new NScheduleViewWithRibbon();
m_ScheduleView = scheduleViewWithRibbon.View;
m_ScheduleView.Document.PauseHistoryService();
try
{
InitSchedule(m_ScheduleView.Content);
}
finally
{
m_ScheduleView.Document.ResumeHistoryService();
}
// Return the commanding widget
return scheduleViewWithRibbon;
}
public NWidget CreateExampleControls()
{
return null;
}
public string GetExampleDescription()
{
return String.Format(NCultureInfo.EnglishUS, @"
This example demonstrates how NOV Schedule handles {0:N0} appointments with different categories (colors).
", TotalAppointments);
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Schedule Appointments", "https://www.nevron.com/docs/openvision/schedule-appointments.html"),
("Schedule View", "https://www.nevron.com/docs/openvision/schedule-view.html"),
};
}
#endregion
#region Implementation
private void InitSchedule(NSchedule schedule)
{
m_Random = new Random();
int totalDays = TotalAppointments / AppointmentsPerDay;
DateTime date = DateTime.Today.AddDays(-totalDays / 2);
// Generate the random appointments
NAppointmentCollection appointments = schedule.Appointments;
for (int i = 0; i < totalDays; i++)
{
AddRandomAppointments(appointments, date);
date = date.AddDays(1);
}
// Switch the schedule to week view
schedule.ViewMode = ENScheduleViewMode.Week;
}
///
/// Adds some random appointments for the given date.
///
///
///
private void AddRandomAppointments(NAppointmentCollection appointments, DateTime date)
{
int lastRnd = -1;
for (int i = 0; i < AppointmentsPerDay; i++)
{
// Generate random subject
int rnd;
do
{
rnd = m_Random.Next(0, AppointmentSubjects.Length);
}
while (rnd == lastRnd);
string subject = AppointmentSubjects[rnd];
// Generate random start hour from 0 to 24
double startHour = m_Random.NextDouble() * 24;
// Generate random duration from 0.5 to 2.5 hours
double duration = 0.5 + m_Random.NextDouble() * 2;
// Create and add the appointment
NAppointment appointment = new NAppointment(subject, date.AddHours(startHour),
date.AddHours(startHour + duration));
appointment.Category = CategoryColors[rnd / 2];
appointments.Add(appointment);
lastRnd = rnd;
}
}
#endregion
#region Event Handlers
#endregion
#region Fields
private NScheduleView m_ScheduleView;
private Random m_Random;
#endregion
#region Static Methods
#endregion
#region Constants
private const int AppointmentsPerDay = 20;
private const int TotalAppointments = 100000;
private static readonly string[] AppointmentSubjects = new string[] {
"Travel to Work",
"Travel back home",
"Conference",
"Lunch",
"Meeting with Fiends",
"Reading the News",
"Video Presentation",
"Web Meeting",
"Gym Workout",
"Jogging",
"Family Dinner",
"House Cleaning"
};
private static readonly string[] CategoryColors = new string[]
{
NCategory.Color.Orange,
NCategory.Color.Red,
NCategory.Color.Blue,
NCategory.Color.Green,
NCategory.Color.Purple,
NCategory.Color.Yellow,
};
#endregion
#region Nested Types
#endregion
}
}