Example #1
0
        public BatchMainViewModel(IEventAggregator eventAggregator,
                                  IDataService <LabDbEntities> labDbData,
                                  MaterialService materialService,
                                  IReportingService reportingService)
        {
            _labDbData        = labDbData;
            _eventAggregator  = eventAggregator;
            _isPrintMenuOpen  = false;
            _materialService  = materialService;
            _reportingService = reportingService;

            CreateBatchCommand = new DelegateCommand(
                () =>
            {
                _materialService.CreateBatch();
            },
                () => Thread.CurrentPrincipal.IsInRole(UserRoleNames.BatchEdit));

            OpenPrintMenuCommand = new DelegateCommand(
                () =>
            {
                IsPrintMenuOpen = true;
            });

            OpenSampleLogViewCommand = new DelegateCommand(
                () =>
            {
                _materialService.ShowSampleLogDialog();
            },
                () => Thread.CurrentPrincipal.IsInRole(UserRoleNames.SampleEdit));

            QuickOpenCommand = new DelegateCommand(
                () =>
            {
                _eventAggregator.GetEvent <BatchVisualizationRequested>()
                .Publish(_batchNumber);
            });

            PrintBatchQueryCommand = new DelegateCommand <IQueryPresenter <Batch, LabDbEntities> >(
                query =>
            {
                IEnumerable <Batch> tempQuery = _labDbData.RunQuery(query.Query);
                _reportingService.PrintBatchReport(tempQuery);
            });

            PrintStatusListCommand = new DelegateCommand(
                () =>
            {
                _reportingService.PrintBatchReport(_labDbData.RunQuery(new LatestNBatchesQuery(50)));
            });

            SearchNewBatchesCommand = new DelegateCommand(
                () =>
            {
                ICollection <Tuple <string, string, string> > fileList = _materialService.GetNewBatchesFromFile();

                ICollection <Batch> parsedBatches = ParseBatches(fileList);

                Views.NewBatchSearchResultDialog dialog = new Views.NewBatchSearchResultDialog()
                {
                    ParsedBatches = parsedBatches
                };

                if (dialog.ShowDialog() == true)
                {
                }
            });

            _refresh = new DelegateCommand(
                () =>
            {
                _eventAggregator.GetEvent <BatchStatusListRefreshRequested>()
                .Publish();
            });
        }