public CalibrationComponentsViewModel(Instrument instrumentEquipment, CalibrationComponentsControl view)
        {
            CompositionInitializer.SatisfyImports(this);
            mInstrument = instrumentEquipment;
            Instrument = instrumentEquipment;
            this.View = view;

            AddComponentCommand = new DelegateCommand<object>(AddButtonHandler, CanAdd);
            RemoveComponentCommand = new DelegateCommand<object>(DeleteButtonHandler, CanDelete);
            EditComponentCommand = new DelegateCommand<object>(EditComponentHandler, CanModify);
            SelectComponentCommand = new DelegateCommand<object>(SelectButtonHandler, CanView);

            mDictionary = Utils.BuildDictionaryForCollection(mInstrument.CalibrationComponents.Select(x => x.Id).ToList());

            SetAllAttachmentControlsdContent();
        }
Esempio n. 2
0
        private void ViewModel_DataSourceLoaded(object obj)
        {
            DataContext = ViewModel;

            //ViewModel.Instrument = ViewModel.Instrument;

            //Components
            mComponentsControl = new InstrumentComponentsControl(ViewModel.Instrument);
            mComponentsControl.CollectionChanged += count =>
            {
                ViewModel.Instrument.GeneralEquipmentRelatedItemsCount.PropertyOrComponents = count;
                SetTabHeadersText();
            };
            ComponentsTab.Content = mComponentsControl;

            //Calibrations
            mCalibrationsControl = new CalibrationComponentsControl(ViewModel.Instrument);
            mCalibrationsControl.CollectionChanged += count =>
            {
                ViewModel.Instrument.GeneralEquipmentRelatedItemsCount.Calibrations = count;
                SetTabHeadersText();
            };
            CalibrationsTab.Content = mCalibrationsControl;

            //Issues
            mInstrumentRelatedIssuesControl = new InstrumentRelatedIssuesControl(ViewModel.Instrument);
            mInstrumentRelatedIssuesControl.CollectionChanged += count =>
            {
                ViewModel.Instrument.GeneralEquipmentRelatedItemsCount.Issues = count;
                SetTabHeadersText();
            };
            RelatedIssuesTab.Content = mInstrumentRelatedIssuesControl;

            //Attachments
            mInstrumentAttachmentsControl = new InstrumentAttachmentsControl(ViewModel.Instrument);
            mInstrumentAttachmentsControl.CollectionChanged += count =>
            {
                ViewModel.Instrument.GeneralEquipmentRelatedItemsCount.Attachments = count;
                SetTabHeadersText();
            };
            AttachmentsTab.Content = mInstrumentAttachmentsControl;

            //Documents Tab
            mDocumentsControl = new InstrumentDocumentsControl(ViewModel.Instrument);
            mDocumentsControl.CollectionChanged += count =>
            {
                ViewModel.Instrument.GeneralEquipmentRelatedItemsCount.Documents = count;
                SetTabHeadersText();
            };

            mDocumentsControl.ControlLoaded += mDocumentsControl_ControlLoaded;
            RoutedEventHandler docsloaded = null;

            docsloaded = (s1, e1) =>
            {
                //This will hook up change events on all controls
                Utils.SetUpChangeEvents((UIElement) DocumentsTab.Content, EventAggregator, ViewModel.Instrument);
                DocumentsTab.Loaded -= docsloaded;

                //GET Tab Counts --------------------------------------------------
                var cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
                cmsWebServiceClient.GetInstrumentRelatedItemsCountCompleted += (s2, e2) =>
                {
                    ViewModel.Instrument.GeneralEquipmentRelatedItemsCount = e2.Result;
                    SetTabHeadersText();
                };
                cmsWebServiceClient.GetInstrumentRelatedItemsCountAsync(ViewModel.Instrument.Id);
            };

            DocumentsTab.Loaded += docsloaded;

            //This will hook up change events on all controls
            Utils.SetUpChangeEvents(EquipmentControl.Content, EventAggregator, ViewModel.Instrument);
            Utils.SetUpChangeEvents((UIElement) ComponentsTab.Content, EventAggregator, ViewModel.Instrument);
            Utils.SetUpChangeEvents((UIElement) RelatedIssuesTab.Content, EventAggregator, ViewModel.Instrument);
            Utils.SetUpChangeEvents((UIElement) AttachmentsTab.Content, EventAggregator, ViewModel.Instrument);

            RoutedEventHandler loaded = null;
            loaded = (s1, e1) =>
            {
                //This will hook up change events on all controls
                Utils.SetUpChangeEvents((UIElement) AttachmentsTab.Content, EventAggregator, ViewModel.Instrument);
                AttachmentsTab.Loaded -= loaded;
            };

            AttachmentsTab.Loaded += loaded;
        }