Example #1
0
        private void OnCleanOldWorkpieceInfosCommand()
        {
            AskDialogService.Show("是否确定清空数据?").Subscribe(
                args =>
            {
                if (args.IsCanceled)
                {
                    return;
                }

                if (!args.Data)
                {
                    return;
                }

                var thisMonthFirstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
                //                    var lastSixMonthFirstDay = DateTime.Now.AddMonths(-6); // 6 month earlier
                var lastSixMonthFirstDay = DateTime.Now.AddMonths(+1);
                ReportingDomainService.CleanOldWorkpieceInfos(lastSixMonthFirstDay);

                UpdateCommandStates();

                MessageDialogService.Show("历史数据已经成功删除");
            });
        }
Example #2
0
        public void Init()
        {
            DefectInfosCollectionView = DefectInfos.GetDefaultCollectionView();

            // Init SurfaceMonitors
            SurfaceMonitors = new List <SurfaceMonitorViewModel>();

            int surfaceCount = 0;

            surfaceCount = 2;

            for (int i = 0; i < surfaceCount; i++)
            {
                var sm = new SurfaceMonitorViewModel
                {
                    Index                      = i,
                    SurfaceTypeIndex           = i,
                    DisplayDefectInfo          = true,
                    DisplayAllDefectInfos      = false,
                    DisplayMeasurementInfo     = true,
                    DisplayAllMeasurementInfos = false,
                };
                SurfaceMonitors.Add(sm);
            }

            //

            CreateWorkpieceInfoCommand = new DelegateCommand(
                () =>
            {
                var dialog = new OpenFileDialog()
                {
                    Multiselect = false,
                    Title       = "Select Image File",
                };

                var ret = dialog.ShowDialog();

                if (ret != true)
                {
                    return;
                }

                var fn = dialog.FileName;

                var di = ServiceLocator.GetInstance <WorkpieceInfo>();
                //di.StoreImage(fn);
                di.InspectDateTime = DateTime.Now;
                di.IsReject        = true;

                InspectionDomainService.AddWorkpieceInfo(di);
            });

            DeleteWorkpieceInfoCommand = new DelegateCommand <WorkpieceInfoEntryViewModel>(
                (di) =>
            {
                if (di == null)
                {
                    MessageBox.Show("Please select a WorkpieceInfo!");
                    return;
                }

                InspectionDomainService.DeleteWorkpieceInfo(di.Id);
            },
                (x) => { return(SelectedWorkpieceInfo != null); });

            SelectWorkpieceInfoCommand = new DelegateCommand <WorkpieceInfoEntryViewModel>(
                (workpieceInfoEntry) =>
            {
                //           var deferRefresh=  DefectInfosCollectionView.DeferRefresh();
                DefectInfosCollectionView.Filter = null;
                _defectInfos.Clear();

                foreach (var surfaceMonitor in SurfaceMonitors)
                {
                    surfaceMonitor.Reset();
                }

                HideAll();

                UpdateCommandStates();

                if (workpieceInfoEntry == null)
                {
                    return;
                }

                var id            = workpieceInfoEntry.Id;
                var workpieceInfo = InspectionDomainService.GetWorkpieceInfoById(id);
                var defVms        = workpieceInfo.DefectInfos.Select(x => x.ToViewModel());
                _defectInfos.AddRange(defVms);

                for (int i = 0; i < workpieceInfo.StoredImageInfo.Count; i++)
                {
                    var sii = workpieceInfo.StoredImageInfo[i];
                    var bs  = sii.LoadImage();

                    var surfaceMonitor          = SurfaceMonitors[sii.SurfaceTypeIndex];
                    surfaceMonitor.BitmapSource = bs;

                    var ds = _defectInfos.Where(x => x.SurfaceTypeIndex == surfaceMonitor.SurfaceTypeIndex).ToList();

                    if (ds.IsEmpty())
                    {
                        surfaceMonitor.DefectInfos  = null;
                        surfaceMonitor.InspectState = InspectState.InspectedWithAccepted;
                    }
                    else
                    {
                        surfaceMonitor.DefectInfos  = ds;
                        surfaceMonitor.InspectState = InspectState.InspectedWithRejected;
                    }
                }

                //            deferRefresh.Dispose();
                DefectInfosCollectionView.Filter = null;
                DefectInfosCollectionView.Refresh();

                UpdateCommandStates();
            });

            EventAggregator
            .GetEvents <WorkpieceInfoAddedDomainEvent>()
            .Subscribe(evt =>
            {
                var entryVm = evt.WorkpieceInfo.ToEntry().ToViewModel();
                WorkpieceInfoEntries.Add(entryVm);

                UpdateCommandStates();
            });

            EventAggregator
            .GetEvents <WorkpieceInfoRemovedDomainEvent>()
            .Subscribe(evt =>
            {
                var s = WorkpieceInfoEntries.SingleOrDefault(x => x.Id == evt.Id);
                if (s != null)
                {
                    WorkpieceInfoEntries.Remove(s);
                }

                UpdateCommandStates();
            });

            CreateDefectInfoCommand = new DelegateCommand(
                () =>
            {
                if (SelectedWorkpieceInfo == null)
                {
                }
                else
                {
                    var index      = DefectInfos.Count;
                    var defectInfo = new DefectInfo {
                        Width = 200, Height = 200, X = index * 100, Y = index * 100
                    };

                    InspectionDomainService.AddDefectInfo(SelectedWorkpieceInfo.Id, defectInfo);
                }
            },
                () => { return(SelectedWorkpieceInfo != null); });

            DeleteDefectInfoCommand = new DelegateCommand <DefectInfoViewModel>(
                (di) =>
            {
                if (SelectedWorkpieceInfo == null)
                {
                    return;
                }

                if (SelectedDefectInfo == null)
                {
                    return;
                }

                InspectionDomainService.DeleteDefectInfo(SelectedWorkpieceInfo.Id, SelectedDefectInfo.Id);
            },
                (x) => { return(SelectedDefectInfo != null); });



            CleanOldWorkpieceInfosCommand = new DelegateCommand(OnCleanOldWorkpieceInfosCommand);

            SelectDefectInfoCommand = new DelegateCommand <DefectInfoViewModel>(
                (di) =>
            {
                if (di != null)
                {
                    CroppedRegionRect = new Rect(di.X, di.Y, di.Width, di.Height);
                }

                UpdateCommandStates();
            });

            CreateMonithReportCommand = new DelegateCommand(
                () =>
            {
                var report = ReportingDomainService.GetMonthReport(SelectedMonthReportDateTime.Year,
                                                                   SelectedMonthReportDateTime.Month);

                if (report == null)
                {
                    MessageDialogService.Show("没有数据,无法生成报表");
                    return;
                }

                PreviewReportingDialogService
                .Show(report)
                .Subscribe(args =>
                {
                    if (args.IsCanceled)
                    {
                        return;
                    }

                    ReportingDomainService.ExportReport(args.Data);
                });
            });

            QueryMonthRecordsCommand = new DelegateCommand(
                () =>
            {
                var dis = ReportingDomainService.GetWorkpieceInfoEntriesByMonth(SelectedMonthReportDateTime.Year,
                                                                                SelectedMonthReportDateTime.Month);
                WorkpieceInfoEntries.Clear();
                WorkpieceInfoEntries.AddRange(dis.Select(x => x.ToViewModel()));
            });

            CreateDayReportCommand = new DelegateCommand(
                () =>
            {
                var report = ReportingDomainService.GetDayReport(SelectedDayReportDateTime.Year,
                                                                 SelectedDayReportDateTime.Month,
                                                                 SelectedDayReportDateTime.Day);

                if (report == null)
                {
                    MessageDialogService.Show("没有数据,无法生成报表");
                    return;
                }

                PreviewReportingDialogService
                .Show(report)
                .Subscribe(args =>
                {
                    if (args.IsCanceled)
                    {
                        return;
                    }

                    ReportingDomainService.ExportReport(args.Data);
                });
            });

            QueryDayRecordsCommand = new DelegateCommand(
                () =>
            {
                var dis = ReportingDomainService.GetWorkpieceInfoEntriesByDay(SelectedDayReportDateTime.Year,
                                                                              SelectedDayReportDateTime.Month,
                                                                              SelectedDayReportDateTime.Day);
                WorkpieceInfoEntries.Clear();
                WorkpieceInfoEntries.AddRange(dis.Select(x => x.ToViewModel()));
            });


            ZoomInCommand = new DelegateCommand(
                () =>
            {
                if (SelectedSurfaceMonitor != null)
                {
                    SelectedSurfaceMonitor.ZoomIn();
                }
                _isZoomFitDisplayAreaEnabled = false;
                _isZoomActualEnabled         = false;
            },
                () => SelectedSurfaceMonitor != null);

            ZoomOutCommand = new DelegateCommand(
                () =>
            {
                if (SelectedSurfaceMonitor != null)
                {
                    SelectedSurfaceMonitor.ZoomOut();
                }
                _isZoomFitDisplayAreaEnabled = false;
                _isZoomActualEnabled         = false;
            },
                () => SelectedSurfaceMonitor != null);

            ZoomFitCommand = new DelegateCommand(
                () =>
            {
                _isZoomFitDisplayAreaEnabled = !_isZoomFitDisplayAreaEnabled;
                if (_isZoomFitDisplayAreaEnabled)
                {
                    if (SelectedSurfaceMonitor != null)
                    {
                        SelectedSurfaceMonitor.ZoomFitDisplayArea();
                    }
                }
                else
                {
                    if (SelectedSurfaceMonitor != null)
                    {
                        SelectedSurfaceMonitor.ZoomFit();
                    }
                }
                _isZoomActualEnabled = false;
            },
                () => SelectedSurfaceMonitor != null);

            ZoomActualCommand = new DelegateCommand(
                () =>
            {
                _isZoomActualEnabled = !_isZoomActualEnabled;
                if (_isZoomActualEnabled)
                {
                    if (SelectedSurfaceMonitor != null)
                    {
                        SelectedSurfaceMonitor.ZoomActual();
                    }
                }
                else
                {
                    if (SelectedSurfaceMonitor != null)
                    {
                        SelectedSurfaceMonitor.ZoomFit();
                    }
                }

                _isZoomFitDisplayAreaEnabled = false;
            },
                () => SelectedSurfaceMonitor != null);



            SaveImageToFileCommand = new DelegateCommand(
                OnSaveImageToFileCommand,
                () => SelectedSurfaceMonitor != null);

            EventAggregator
            .GetEvents <DefectInfoAddedDomainEvent>()
            .Subscribe(evt =>
            {
                if (SelectedWorkpieceInfo == null)
                {
                    return;
                }

                if (SelectedWorkpieceInfo.Id != evt.WorkpieceInfoId)
                {
                    return;
                }

                _defectInfos.Add(evt.DefectInfo.ToViewModel());

                UpdateCommandStates();
            });


            EventAggregator
            .GetEvents <DefectInfoRemovedDomainEvent>()
            .Subscribe(evt =>
            {
                if (SelectedDefectInfo != null && SelectedDefectInfo.Id == evt.DefectInfoId)
                {
                    SelectedDefectInfo = null;
                }

                var di = _defectInfos.SingleOrDefault(x => x.Id == evt.DefectInfoId);
                if (di != null)
                {
                    _defectInfos.Remove(di);
                }

                UpdateCommandStates();
            });

            EventAggregator.GetEvents <ReportExportFailedEvent>()
            .Subscribe(evt => { MessageBox.Show("导出失败!" + "\n\n" + evt.Exception.Message); });

            EventAggregator.GetEvents <ReportExportSuccessfulEvent>()
            .Subscribe(evt => { MessageBox.Show("导出成功!" + "\n\n" + evt.FileName); });


            var thisMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

            MonthReportDateTimes.Add(thisMonth);
            for (int i = 0; i < 5; i++)
            {
                MonthReportDateTimes.Add(thisMonth.AddMonths(-i - 1));
            }

            SelectedMonthReportDateTime        = thisMonth;
            SelectedDayReportYearMonthDateTime = thisMonth;
        }