Files
2026-04-17 14:55:32 -04:00

144 lines
6.5 KiB
C#

using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using DTS.Common.Events;
using DTS.Common.Interface;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Interactivity.InteractionRequest;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using DTS.Common.Utils;
using System.Text;
// ReSharper disable CheckNamespace
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable InconsistentNaming
namespace PedestrianAndHeadReports
{
/// <summary>
/// this class handles DB import/export functionality
/// (note that since a lot of of DataPRO objects still live in the datapro project it's functionality is limited to the xml string going back and forth right now)
/// </summary>
[Export(typeof(IHeadReportInputView))]
[Export(typeof(IHeadReportOutputView))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class HeadReportViewModel : IHeadReportViewModel
{
public IHeadReportInputView InputView { get; set; }
public IHeadReportOutputView OutputView { get; set; }
private IEventAggregator _eventAggregator { get; set; }
private IRegionManager _regionManager;
private IUnityContainer UnityContainer { get; set; }
public InteractionRequest<Notification> NotificationRequest { get; private set; }
public InteractionRequest<Confirmation> ConfirmationRequest { get; private set; }
/// <summary>
/// Creates a new instance of the TechnologyDomainEditViewModel.
/// </summary>
/// <param name="inputView"></param>
/// <param name="outputView"></param>
/// <param name="regionManager">The logical placeholder defined within the application's UI (in the shell or within views) into which views are displayed.</param>
/// <param name="eventAggregator">The EventAggregator which allows different components to publish/subscribe to events without being coupled to each other.</param>
/// <param name="unityContainer">The unityContainer.</param>
public HeadReportViewModel(IHeadReportInputView inputView, IHeadReportOutputView outputView, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)
{
InputView = inputView;
OutputView = outputView;
inputView.DataContext = this;
outputView.DataContext = this;
NotificationRequest = new InteractionRequest<Notification>();
ConfirmationRequest = new InteractionRequest<Confirmation>();
_eventAggregator = eventAggregator;
UnityContainer = unityContainer;
_regionManager = regionManager;
_eventAggregator.GetEvent<RaiseNotification>().Subscribe(OnRaiseNotification);
_eventAggregator.GetEvent<BusyIndicatorChangeNotification>().Subscribe(OnBusyIndicatorNotification, ThreadOption.PublisherThread, true);
}
#region Methods
public void Cleanup() { }
public Task CleanupAsync() { return null; }
public void Initialize() { }
public void Initialize(object parameter) { }
public void Initialize(object parameter, object model) { }
public Task InitializeAsync() { return null; }
public Task InitializeAsync(object parameter) { return null; }
public void Activated() { }
/// <summary>
/// Private Event handler for RaiseNotification event.
/// </summary>
private void OnBusyIndicatorNotification(bool eventArg) { IsBusy = eventArg; }
/// <summary>
/// Private Event handler for RaiseNotification event.
/// </summary>
private void OnRaiseNotification(NotificationContentEventArgs eventArgsWithTitle)
{
// The NotificationRequest.Raise triggers the Invoke() method of the PopupWindowAction object to show the NotificationWindow window
// Notification object expects a NotificationContentEventArgsWithoutTitle object and a Title string.
var eventArgsWithoutTitle = new NotificationContentEventArgs(eventArgsWithTitle.Message,"", eventArgsWithTitle.Image, string.Empty);
NotificationRequest.Raise(new Notification { Content = eventArgsWithoutTitle, Title = eventArgsWithTitle.Title });
}
#endregion
#region Properties
public bool IsDirty { get; private set; }
private bool _isBusy = false;
public bool IsBusy { get => _isBusy; set { _isBusy = value; OnPropertyChanged("IsBusy"); } }
private bool _isMenuIncluded = false;
public bool IsMenuIncluded { get => _isMenuIncluded; set { _isMenuIncluded = value; OnPropertyChanged("IsMenuIncluded"); } }
private bool _isNavigationIncluded = false;
public bool IsNavigationIncluded { get => _isNavigationIncluded; set { _isNavigationIncluded = value; OnPropertyChanged("IsNavigationIncluded"); } }
/// <summary>
/// Gets the HeaderInfo.
/// </summary>
public string HeaderInfo => "MainRegion";
#endregion Properties
#region Commands
/*/// <summary>
/// browse to a file to import, should be xml, maybe needs a few other criteria
/// </summary>
private DelegateCommand _importBrowseCommand;
public DelegateCommand ImportBrowseCommand { get { return _importBrowseCommand ?? ( _importBrowseCommand = new DelegateCommand(ImportBrowseMethod)); } }
private void ImportBrowseMethod()
{
using (var dlg = new System.Windows.Forms.OpenFileDialog())
{
dlg.CheckFileExists = true;
dlg.CheckPathExists = true;
dlg.Filter = Resources.StringResources.ImportFileBrowse_Filter;
dlg.FilterIndex = 0;
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
ImportFileName = dlg.FileName;
}
}
}*/
#endregion
#region properties
#endregion
///<summary>
///Occurs when a property value changes.
///</summary>
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}