Пример #1
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;
        }
Пример #2
0
        private void BuildMoveComponentRevisionHistory(InstrumentComponentsControl componentsControl)
        {
            if (componentsControl == null || componentsControl.Model == null || componentsControl.Model.MovedComponents == null)
            {
                return;
            }

            foreach (var movedComponent in componentsControl.Model.MovedComponents)
            {
                var rv = new InstrumentRevisionHistory();
                rv.Date = DateTime.Now;
                rv.UserId = CMS.User.Id;
                rv.InstrumentId = ViewModel.Instrument.Id;
                rv.Description = string.Format("Moved Component {0} to Intrument {1}.", movedComponent.Name, movedComponent.Instrument.Name);
                ViewModel.Instrument.InstrumentRevisionHistories.Add(rv);
            }
        }