public string GetReports()
        {
            var db     = new Context();
            var result = new List <ReportModel>();

            var report     = db.Report.ToList();
            var resources  = db.Resource.ToList();
            var facilities = db.Facility.ToList();

            foreach (var f in facilities)
            {
                if (f.Status)
                {
                    var rep = new ReportModel();
                    rep.FacilityId   = f.Id;
                    rep.FacilityName = f.Name;
                    foreach (var r in report)
                    {
                        foreach (var re in resources)
                        {
                            if (re.Status)
                            {
                                if (re.Id == r.ResourceId && re.FacilityId == f.Id)
                                {
                                    var res = new ResourceReportModel();
                                    res.ReportId        = r.Id;
                                    res.ResourceId      = r.ResourceId;
                                    res.ResourceName    = r.Resource.Name;
                                    res.MissingQuantity = r.MissingQuantity;
                                    res.QuantityChange  = r.QuantityChange;
                                    res.Status          = string.Empty;

                                    if (r.Verify)
                                    {
                                        res.Status   = "Verified";
                                        res.Verified = true;
                                    }

                                    if (r.MissingQuantity.HasValue)
                                    {
                                        if (r.Missing)
                                        {
                                            res.Status  = "Missing";
                                            res.Missing = true;
                                        }
                                    }

                                    rep.ResourceReport.Add(res);
                                }
                            }
                        }
                    }
                    result.Add(rep);
                }
            }

            var response = JsonConvert.SerializeObject(result);

            return(response);
        }
예제 #2
0
        public ResourceReportViewModel(BaseViewModel parentViewModel, ResourceReportModel dataModel, IDialogService dialogService, Func <ISaveFileDialog> saveFileDialogFactory)
            : base(parentViewModel)
        {
            Contract.Requires(dialogService != null);
            Contract.Requires(saveFileDialogFactory != null);

            _dialogService         = dialogService;
            _saveFileDialogFactory = saveFileDialogFactory;
            _dataModel             = dataModel;
            // Will bubble property change events from the Model to the ViewModel.
            _dataModel.PropertyChanged += (sender, e) => OnPropertyChanged(e.PropertyName);
        }
예제 #3
0
        public bool Load(string[] args)
        {
            // Fetch the game version and store, so it can be retrieved during crash if the toolbox makes it this far.
            GlobalSettings.Default.SEVersion = SpaceEngineersConsts.GetSEVersion();

            // Test the Space Engineers version to make sure users are using an version that is new enough for SEToolbox to run with!
            // This is usually because a user has not updated a manual install of a Dedicated Server, or their Steam did not update properly.
            if (GlobalSettings.Default.SEVersion < GlobalSettings.GetAppVersion(true))
            {
                MessageBox.Show(string.Format(Res.DialogOldSEVersionMessage, SpaceEngineersConsts.GetSEVersion(), GlobalSettings.Default.SEBinPath, GlobalSettings.GetAppVersion()), Res.DialogOldSEVersionTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                Application.Current.Shutdown();
                return(false);
            }

            //string loadWorld = null;

            //foreach (var arg in args)
            //{
            //    if (arg.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0 && !File.Exists(arg))
            //        continue;

            //    string file = Path.GetFileName(arg);
            //    if (file.Equals("Sandbox.sbc", StringComparison.InvariantCultureIgnoreCase)
            //        || file.Equals("SANDBOX_0_0_0_.sbs", StringComparison.InvariantCultureIgnoreCase))
            //        loadWorld = Path.GetDirectoryName(arg);
            //}

            // Force pre-loading of any Space Engineers resources.
            SpaceEngineersCore.LoadDefinitions();

            // Load the Space Engineers assemblies, or dependant classes after this point.
            var explorerModel = new ExplorerModel();

            if (args.Any(a => a.ToUpper() == "/WR" || a.ToUpper() == "-WR"))
            {
                ResourceReportModel.GenerateOfflineReport(explorerModel, args);
                Application.Current.Shutdown();
                return(false);
            }

            var eViewModel = new ExplorerViewModel(explorerModel);
            var eWindow    = new WindowExplorer(eViewModel);

            //if (allowClose)
            //{
            eViewModel.CloseRequested += (sender, e) =>
            {
                SaveSettings(eWindow);
                Application.Current.Shutdown();
            };
            //}
            eWindow.Loaded += (sender, e) =>
            {
                Splasher.CloseSplash();
                if (GlobalSettings.Default.WindowLeft.HasValue)
                {
                    eWindow.Left = GlobalSettings.Default.WindowLeft.Value;
                }
                if (GlobalSettings.Default.WindowTop.HasValue)
                {
                    eWindow.Top = GlobalSettings.Default.WindowTop.Value;
                }
                if (GlobalSettings.Default.WindowWidth.HasValue)
                {
                    eWindow.Width = GlobalSettings.Default.WindowWidth.Value;
                }
                if (GlobalSettings.Default.WindowHeight.HasValue)
                {
                    eWindow.Height = GlobalSettings.Default.WindowHeight.Value;
                }
                if (GlobalSettings.Default.WindowState.HasValue)
                {
                    eWindow.WindowState = GlobalSettings.Default.WindowState.Value;
                }
            };
            eWindow.ShowDialog();

            return(true);
        }
예제 #4
0
 public ResourceReportViewModel(BaseViewModel parentViewModel, ResourceReportModel dataModel)
     : this(parentViewModel, dataModel, ServiceLocator.Resolve <IDialogService>(), ServiceLocator.Resolve <ISaveFileDialog>)
 {
 }
예제 #5
0
        public bool Load(string[] args)
        {
            // Fetch the game version and store, so it can be retrieved during crash if the toolbox makes it this far.
            Version gameVersion = SpaceEngineersConsts.GetSEVersion();
            bool    newVersion  = GlobalSettings.Default.SEVersion != gameVersion;

            GlobalSettings.Default.SEVersion = gameVersion;

            // Test the Space Engineers version to make sure users are using an version that is new enough for SEToolbox to run with!
            // This is usually because a user has not updated a manual install of a Dedicated Server, or their Steam did not update properly.
            if (GlobalSettings.Default.SEVersion < GlobalSettings.GetAppVersion(true))
            {
                MessageBox.Show(string.Format(Res.DialogOldSEVersionMessage, SpaceEngineersConsts.GetSEVersion(), GlobalSettings.Default.SEBinPath, GlobalSettings.GetAppVersion()), Res.DialogOldSEVersionTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                Application.Current.Shutdown();
                return(false);
            }

            // the /B argument indicates the SEToolboxUpdate had started SEToolbox after fetching updated game binaries.
            if (newVersion && args.Any(a => a.Equals("/B", StringComparison.OrdinalIgnoreCase) || a.Equals("-B", StringComparison.OrdinalIgnoreCase)))
            {
                // Reset the counter used to indicate if the game binaries have updated.
                GlobalSettings.Default.TimesStartedLastGameUpdate = null;
            }

            //string loadWorld = null;

            //foreach (var arg in args)
            //{
            //    if (arg.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0 && !File.Exists(arg))
            //        continue;

            //    string file = Path.GetFileName(arg);
            //    if (file.Equals("Sandbox.sbc", StringComparison.InvariantCultureIgnoreCase)
            //        || file.Equals("SANDBOX_0_0_0_.sbs", StringComparison.InvariantCultureIgnoreCase))
            //        loadWorld = Path.GetDirectoryName(arg);
            //}

            // Force pre-loading of any Space Engineers resources.
            SpaceEngineersCore.LoadDefinitions();

            // Load the Space Engineers assemblies, or dependant classes after this point.
            var explorerModel = new ExplorerModel();

            if (args.Any(a => a.ToUpper() == "/WR" || a.ToUpper() == "-WR"))
            {
                ResourceReportModel.GenerateOfflineReport(explorerModel, args);
                Application.Current.Shutdown();
                return(false);
            }

            var eViewModel = new ExplorerViewModel(explorerModel);
            var eWindow    = new WindowExplorer(eViewModel);

            //if (allowClose)
            //{
            eViewModel.CloseRequested += (sender, e) =>
            {
                SaveSettings(eWindow);
                Application.Current.Shutdown();
            };
            //}
            eWindow.Loaded += (sender, e) =>
            {
                Splasher.CloseSplash();

                double left   = GlobalSettings.Default.WindowLeft ?? eWindow.Left;
                double top    = GlobalSettings.Default.WindowTop ?? eWindow.Top;
                double width  = GlobalSettings.Default.WindowWidth ?? eWindow.Width;
                double height = GlobalSettings.Default.WindowHeight ?? eWindow.Height;

                System.Drawing.Rectangle windowRect = new System.Drawing.Rectangle((int)left, (int)top, (int)width, (int)height);
                bool isInsideDesktop = false;

                foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
                {
                    try
                    {
                        isInsideDesktop |= screen.Bounds.IntersectsWith(windowRect);
                    }
                    catch
                    {
                        // some virtual screens have been know to cause issues.
                    }
                }
                if (isInsideDesktop)
                {
                    eWindow.Left   = left;
                    eWindow.Top    = top;
                    eWindow.Width  = width;
                    eWindow.Height = height;
                    if (GlobalSettings.Default.WindowState.HasValue)
                    {
                        eWindow.WindowState = GlobalSettings.Default.WindowState.Value;
                    }
                }
            };

            if (!GlobalSettings.Default.TimesStartedTotal.HasValue)
            {
                GlobalSettings.Default.TimesStartedTotal = 0;
            }
            GlobalSettings.Default.TimesStartedTotal++;
            if (!GlobalSettings.Default.TimesStartedLastReset.HasValue)
            {
                GlobalSettings.Default.TimesStartedLastReset = 0;
            }
            GlobalSettings.Default.TimesStartedLastReset++;
            if (!GlobalSettings.Default.TimesStartedLastGameUpdate.HasValue)
            {
                GlobalSettings.Default.TimesStartedLastGameUpdate = 0;
            }
            GlobalSettings.Default.TimesStartedLastGameUpdate++;
            GlobalSettings.Default.Save();

            eWindow.ShowDialog();

            return(true);
        }
예제 #6
0
        public bool Load(string[] args)
        {
            // Fetch the game version and store, so it can be retrieved during crash if the toolbox makes it this far.
            Version gameVersion = SpaceEngineersConsts.GetSEVersion();
            bool    newVersion  = GlobalSettings.Default.SEVersion != gameVersion;

            GlobalSettings.Default.SEVersion = gameVersion;

            // Test the Space Engineers version to make sure users are using an version that is new enough for SEToolbox to run with!
            // This is usually because a user has not updated a manual install of a Dedicated Server, or their Steam did not update properly.
            if (GlobalSettings.Default.SEVersion < GlobalSettings.GetAppVersion(true))
            {
                MessageBox.Show(string.Format(Res.DialogOldSEVersionMessage, SpaceEngineersConsts.GetSEVersion(), GlobalSettings.Default.SEBinPath, GlobalSettings.GetAppVersion()), Res.DialogOldSEVersionTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                Application.Current.Shutdown();
                return(false);
            }

            // the /B argument indicates the SEToolboxUpdate had started SEToolbox after fetching updated game binaries.
            if (newVersion && args.Any(a => a.Equals("/B", StringComparison.OrdinalIgnoreCase) || a.Equals("-B", StringComparison.OrdinalIgnoreCase)))
            {
                // Reset the counter used to indicate if the game binaries have updated.
                GlobalSettings.Default.TimesStartedLastGameUpdate = null;
            }

            // Force pre-loading of any Space Engineers resources.
            SpaceEngineersCore.LoadDefinitions();

            // Load the Space Engineers assemblies, or dependant classes after this point.
            var explorerModel = new ExplorerModel();

            if (args.Any(a => a.ToUpper() == "/WR" || a.ToUpper() == "-WR"))
            {
                ResourceReportModel.GenerateOfflineReport(explorerModel, args);
                Application.Current.Shutdown();
                return(false);
            }

            var eViewModel = new ExplorerViewModel(explorerModel);
            var eWindow    = new WindowExplorer(eViewModel);

            //if (allowClose)
            //{
            eViewModel.CloseRequested += (sender, e) =>
            {
                SaveSettings(eWindow);
                Application.Current.Shutdown();
            };
            //}
            eWindow.Loaded += (sender, e) =>
            {
                Splasher.CloseSplash();
                if (GlobalSettings.Default.WindowLeft.HasValue)
                {
                    eWindow.Left = GlobalSettings.Default.WindowLeft.Value;
                }
                if (GlobalSettings.Default.WindowTop.HasValue)
                {
                    eWindow.Top = GlobalSettings.Default.WindowTop.Value;
                }
                if (GlobalSettings.Default.WindowWidth.HasValue)
                {
                    eWindow.Width = GlobalSettings.Default.WindowWidth.Value;
                }
                if (GlobalSettings.Default.WindowHeight.HasValue)
                {
                    eWindow.Height = GlobalSettings.Default.WindowHeight.Value;
                }
                if (GlobalSettings.Default.WindowState.HasValue)
                {
                    eWindow.WindowState = GlobalSettings.Default.WindowState.Value;
                }
            };

            if (!GlobalSettings.Default.TimesStartedTotal.HasValue)
            {
                GlobalSettings.Default.TimesStartedTotal = 0;
            }
            GlobalSettings.Default.TimesStartedTotal++;
            if (!GlobalSettings.Default.TimesStartedLastReset.HasValue)
            {
                GlobalSettings.Default.TimesStartedLastReset = 0;
            }
            GlobalSettings.Default.TimesStartedLastReset++;
            if (!GlobalSettings.Default.TimesStartedLastGameUpdate.HasValue)
            {
                GlobalSettings.Default.TimesStartedLastGameUpdate = 0;
            }
            GlobalSettings.Default.TimesStartedLastGameUpdate++;
            GlobalSettings.Default.Save();

            eWindow.ShowDialog();

            return(true);
        }