Date and Time Request Popups
v7
In the process of using the plugin, it may be necessary to request the date and time from the user. To do this, dialog popups can be shown using the methods IViewManager.ShowDateNumpadPopup, IViewManager.ShowDateTimePopup, and IViewManager.ShowCalendarPopup.
How does it look in SyrveFront?
In some cases, the plugin has access to an instance of the IViewManager class during its operation. It is available, for example, when handling a button click:
PluginContext.Operations.AddButtonToPluginsMenu("Sample Plugin", x =>
{
var viewManager = x.vm;
});
or when certain events are triggered:
PluginContext.Notifications.BeforeOrderBill.Subscribe(x =>
{
var viewManager = x.vm;
});
More details about this class can be found in the article “Dialog Windows”.
In such cases, dialog windows can be shown using IViewManager. Let’s consider all the methods for requesting the date and time from the user. For example, we will create a button using the method IOperationService.AddButtonToPluginsMenu, as shown above, and when it is clicked, we will display the dialog windows.
Option 1: Date Numpad Popup
You can request only the date using a simple dialog with a numeric keypad:
PluginContext.Operations.AddButtonToPluginsMenu("Sample Plugin", x =>
{
var dateNumpadPopupResult = x.vm.ShowDateNumpadPopup(DateTime.Today, "Date Numpad");
});
Thus, when the button is clicked, a date selection window will be shown:

The method IViewManager.ShowDateNumpadPopup(DateTime selectedDate, string title) takes 2 arguments:
DateTime selectedDate— the date that will be selected when the window is shown.string title— the title of the window.
The method will return the date selected by the user if they click “OK”, or null if they click “Cancel”.
Option 2: Date-Time Popup
You can request the date and time using a dialog:
PluginContext.Operations.AddButtonToPluginsMenu("Sample Plugin", x =>
{
var dateTimePopupResult = x.vm.ShowDateTimePopup(DateTime.Now, "Date-Time", DateTime.Today, DateTime.Today.AddMonths(6));
});
When the button is clicked, a date and time selection window will be shown:

If you click on the current date, a calendar will be shown, allowing you to quickly switch to another day:

The method IViewManager.ShowDateTimePopup(DateTime selectedDate, [CanBeNull] string title, DateTime minDate, DateTime maxDate) takes 4 arguments:
DateTime selectedDate— the date and time that will be selected when the window is shown.string title— the title of the window.DateTime minDate— the minimum date and time that can be selected. This property also affects the calendar.DateTime maxDate— the maximum date and time that can be selected. This property also affects the calendar.
The method will return the date and time selected by the user if they click “OK”, or null if they click “Cancel”.
Option 3: Calendar Popup
To select a date, you can use a calendar window:
PluginContext.Operations.AddButtonToPluginsMenu("Sample Plugin", x =>
{
var dateCalendarPopupResult = x.vm.ShowCalendarPopup(DateTime.Today, "Calendar", DateTime.Today, DateTime.Today.AddMonths(6));
});
When the button is clicked, a window will be shown:

The method IViewManager.ShowCalendarPopup(DateTime selectedDate, [CanBeNull] string title, DateTime minDate, DateTime maxDate) takes 4 arguments:
DateTime selectedDate— the date that will be selected when the window is shown.string title— the title of the window.DateTime minDate— the minimum date that can be selected.DateTime maxDate— the maximum date that can be selected.
The method will return the date selected by the user if they click “OK”, or null if they click “Cancel”.