Example #1
0
 public FormDataEntry(IApplicationController controller,
                      ApplicationSettings appSettings,
                      IDataEntryDataService dataService,
                      ISampleSelectorRepository sampleSelectorRepository) : this()
 {
     InitializeCommon(controller, appSettings, dataService, sampleSelectorRepository);
 }
        public void Ctor_Test()
        {
            using (var ds = CreateDataStore())
            {
                var unit = ds.From <CuttingUnitDO>().Query().FirstOrDefault();
                unit.Should().NotBeNull();

                var dataServ = new IDataEntryDataService(unit.Code, ds);

                dataServ.CuttingUnit.Should().NotBeNull("cutting unit required");
                dataServ.TallyHistory.Should().NotBeNull("tally history required");

                dataServ.TreeStrata.Should().NotBeNullOrEmpty("tree strata");
                dataServ.TreeStrata.Should().HaveCount(1, "only one tree strata");

                dataServ.NonPlotTrees.Should().NotBeNullOrEmpty("non plot trees");
                dataServ.NonPlotTrees.Should().HaveCount(1, "only one non plot tree");

                dataServ.PlotStrata.Should().NotBeNullOrEmpty("plot strata");

                foreach (var st in dataServ.PlotStrata)
                {
                    st.Plots.Should().NotBeNullOrEmpty();
                    foreach (var plt in st.Plots)
                    {
                        plt.Trees.Should().NotBeNullOrEmpty();
                    }
                }

                dataServ.DefaultStratum.Should().NotBeNull();
            }
        }
Example #3
0
        public ControlTreeDataGrid(IDataEntryDataService dataService
                                   , ApplicationSettings appSettings
                                   , FormDataEntryLogic dataEntryController)
            : this()
        {
            DataService         = dataService;
            DataEntryController = dataEntryController;
            AppSettings         = appSettings;

            DataGridTableStyle tableStyle = dataService.InitializeTreeColumns(this);

            _speciesColumn    = tableStyle.GridColumnStyles["TreeDefaultValue"] as EditableComboBoxColumn;
            _sgColumn         = tableStyle.GridColumnStyles["SampleGroup"] as EditableComboBoxColumn;
            _stratumColumn    = tableStyle.GridColumnStyles["Stratum"] as EditableComboBoxColumn;
            _treeNumberColumn = tableStyle.GridColumnStyles["TreeNumber"] as EditableTextBoxColumn;
            _initialsColoumn  = tableStyle.GridColumnStyles["Initials"] as EditableComboBoxColumn;
            _logsColumn       = tableStyle.GridColumnStyles["LogCountActual"] as DataGridButtonColumn;
            _kpiColumn        = tableStyle.GridColumnStyles["KPI"] as EditableTextBoxColumn;
            _errorsColumn     = tableStyle.GridColumnStyles["Errors"] as DataGridTextBoxColumn;

            Settings_CruisersChanged(null, null);//initialize initials column

            if (_logsColumn != null)
            {
                _logsColumn.Click += this.LogsClicked;
                LogColumnVisable   = DataService.EnableLogGrading;
            }
            if (_stratumColumn != null)
            {
                _stratumColumn.DataSource = dataService.TreeStrata;
            }
        }
        public void GetNextNonPlotTreeNumber_Test()
        {
            var trees = new List <Tree>();

            IDataEntryDataService.GetNextTreeNumber(trees).Should().Be(1);

            trees.Add(new Tree()
            {
                TreeNumber = 1
            });

            IDataEntryDataService.GetNextTreeNumber(trees).Should().Be(2);

            var tree = new Tree()
            {
                TreeNumber = 50
            };

            trees.Add(tree);

            IDataEntryDataService.GetNextTreeNumber(trees).Should().Be(51);

            trees.Remove(tree);

            IDataEntryDataService.GetNextTreeNumber(trees).Should().Be(2);
        }
        protected void ShowDataEntry(IDataEntryDataService dataService, ISampleSelectorRepository sampleSelectorRepository)
        {
            try
            {
                using (var dataEntryView = new FormDataEntry(this.ApplicationController
                                                             , ApplicationSettings.Instance
                                                             , dataService, sampleSelectorRepository))
                {
#if !NetCF
                    dataEntryView.ShowDialog(MainView);
#else
                    dataEntryView.ShowDialog();
#endif
                }
            }
            catch (UserFacingException e)
            {
                var exType = e.GetType();

                MessageBox.Show(e.Message, exType.Name);
            }
            finally
            {
                SaveData(dataService, sampleSelectorRepository);
            }
        }
        public void ReadUnitLevelCruisersTest()
        {
            using (var ds = CreateDataStore())
            {
                var unitLevelInitialsEmpty = IDataEntryDataService.ReadUnitLevelCruisers(ds);

                unitLevelInitialsEmpty.Should().NotBeNull();
                unitLevelInitialsEmpty.Should().BeEmpty();

                var initialsRaw      = new string[] { " ", "", "A", "AB", " C " };
                var initialsExpected = new string[] { "A", "AB", "C" };

                var cuttingUnit = ds.From <CuttingUnitDO>().Query().First();
                var stratum     = ds.From <StratumDO>().Query().First();

                long j = 0;
                foreach (var initial in initialsRaw)
                {
                    var tree = new TreeDO()
                    {
                        DAL         = ds,
                        CuttingUnit = cuttingUnit,
                        Stratum     = stratum,
                        TreeNumber  = ++j,
                        Initials    = initial
                    };

                    tree.Save();
                }

                var unitLevelInitials = IDataEntryDataService.ReadUnitLevelCruisers(ds);

                unitLevelInitials.Should().Contain(initialsExpected);
            }
        }
 public LayoutTreeBased(IDataEntryDataService dataService,
                        ISampleSelectorRepository sampleSelectorRepository,
                        ApplicationSettings appSettings,
                        FormDataEntryLogic dataEntryController)
     : this()
 {
     Initialize(dataService,
                sampleSelectorRepository,
                appSettings,
                dataEntryController,
                _leftContentPanel);
 }
Example #8
0
        public FormDataEntry(IApplicationController controller,
                             ApplicationSettings appSettings,
                             IDataEntryDataService dataService,
                             ISampleSelectorRepository sampleSelectorRepository)
        {
            InitializeComponent();
            _startupStopwatch = new System.Diagnostics.Stopwatch();
            _startupStopwatch.Start();

            InitializeCommon(controller, appSettings, dataService, sampleSelectorRepository);

            UpdateAddTreeButton();
        }
        public void IsTreeNumberAvalible_Test()
        {
            using (var ds = CreateDataStore())
            {
                var unit = ds.From <CuttingUnitDO>().Query().FirstOrDefault();
                unit.Should().NotBeNull();

                var dataServ = new IDataEntryDataService(unit.Code, ds);

                dataServ.IsTreeNumberAvalible(1).Should().BeFalse();
                dataServ.IsTreeNumberAvalible(2).Should().BeTrue();
            }
        }
        protected void Initialize(IDataEntryDataService dataService,
                                  ISampleSelectorRepository sampleSelectorRepository,
                                  ApplicationSettings appSettings,
                                  FormDataEntryLogic dataEntryController,
                                  Panel strataViewContainer)
        {
            SampleSelectorRepository = sampleSelectorRepository;
            AppSettings         = appSettings;
            StrataViewContainer = strataViewContainer;
            DataEntryController = dataEntryController;
            DataService         = dataService;

            InitializeStrataViews();
        }
Example #11
0
        public FormDataEntryLogic(IApplicationController controller,
                                  IDialogService dialogService,
                                  ISoundService soundService,
                                  IDataEntryDataService dataService,
                                  IApplicationSettings settings,
                                  IDataEntryView view,
                                  ISampleSelectorRepository sampleSelectorRepository)
        {
            this.Controller = controller;
            this.View       = view;

            _dialogService      = dialogService;
            _soundService       = soundService;
            _dataService        = dataService;
            _appSettings        = settings;
            _sampleSelectorRepo = sampleSelectorRepository;
        }
Example #12
0
        public ControlTreeDataGrid(IDataEntryDataService dataService
                                   , ApplicationSettings appSettings
                                   , FormDataEntryLogic dataEntryController) : this()
        {
            DataService         = dataService;
            DataEntryController = dataEntryController;
            AppSettings         = appSettings;

            var fontWidth = (int)Math.Ceiling(CreateGraphics().MeasureString("_", Font).Width);

            var columns = DataService.MakeTreeColumns(fontWidth);

            base.Columns.AddRange(columns.ToArray());

            _speciesColumn      = base.Columns["TreeDefaultValue"] as DataGridViewComboBoxColumn;
            _sgColumn           = base.Columns["SampleGroup"] as DataGridViewComboBoxColumn;
            _stratumColumn      = base.Columns["Stratum"] as DataGridViewComboBoxColumn;
            _treeNumberColumn   = base.Columns["TreeNumber"] as DataGridViewTextBoxColumn;
            _initialsColoumn    = base.Columns["Initials"] as DataGridViewComboBoxColumn;
            _errorMessageColumn = base.Columns["Error"] as DataGridViewTextBoxColumn;
            _logsColumn         = base.Columns["Logs"] as DataGridViewButtonColumn;

            if (_speciesColumn != null)
            {
                _speciesColumn.DataSource = DataService.GetTreeDefaultValuesAll().ToList();
            }
            if (_sgColumn != null)
            {
                _sgColumn.DataSource = DataService.TreeStrata.SelectMany(st => st.SampleGroups).ToList();
            }
            if (_stratumColumn != null)
            {
                _stratumColumn.DataSource = DataService.TreeStrata;
            }

            if (_logsColumn != null)
            {
                //cell click doesn't need to be hooked up here. see ControlTreeDataGrid_CellClick method
                _logsColumn.Visible = DataService.EnableLogGrading;
            }

            Settings_CruisersChanged(null, null);//initialize initials column
        }
Example #13
0
        public LayoutPlot(IDataEntryDataService dataService
                          , ISampleSelectorRepository sampleSelectorRepository
                          , ApplicationSettings appSettings
                          , ISoundService soundService
                          , IViewController viewController
                          , PlotStratum stratum) : this()
        {
            SampleSelectorRepository = sampleSelectorRepository;
            DataService = dataService;
            AppSettings = appSettings;

            this.ViewLogicController = new LayoutPlotLogic(stratum,
                                                           this,
                                                           dataService,
                                                           soundService,
                                                           DialogService.Instance,
                                                           AppSettings,
                                                           viewController,
                                                           sampleSelectorRepository);

            //Setup DataGrid
            _tableStyle = stratum.InitializeTreeColumns(_dataGrid);

            _speciesColumn    = _tableStyle.GridColumnStyles["TreeDefaultValue"] as EditableComboBoxColumn;
            _sgColumn         = _tableStyle.GridColumnStyles["SampleGroup"] as EditableComboBoxColumn;
            _treeNumberColumn = _tableStyle.GridColumnStyles["TreeNumber"] as EditableTextBoxColumn;
            _initialsColoumn  = _tableStyle.GridColumnStyles["Initials"] as EditableComboBoxColumn;
            _logsColumn       = _tableStyle.GridColumnStyles["LogCountActual"] as DataGridButtonColumn;
            _kpiColumn        = _tableStyle.GridColumnStyles["KPI"] as EditableTextBoxColumn;
            _errorsColumn     = _tableStyle.GridColumnStyles["Error"] as DataGridTextBoxColumn;

            if (_logsColumn != null)
            {
                _logsColumn.Click += this.LogsClicked;
                LogColumnVisable   = DataService.EnableLogGrading;
            }
            Settings_CruisersChanged(null, null);//initialize initials column

            InitializeTallyPanel();

            this.ViewLogicController.UpdateCurrentPlot();
        }
        public void SaveTallyAction()
        {
            using (var database = CreateDataStore(methods: new[] { "STR" }))
            {
                var treeCount = 1;
                var unitCode  = "01";
                var ds        = new IDataEntryDataService(unitCode, database);

                var count           = ds.TreeStrata.First().Counts.First();
                var treecountBefore = count.TreeCount;

                var tallyAction = new TallyAction(count)
                {
                    TreeCount = treeCount,
                };

                ds.SaveTallyAction(tallyAction);

                count.TreeCount.Should().Be(treeCount + treecountBefore);
            }
        }
Example #15
0
        protected void InitializeCommon(IApplicationController controller,
                                        ApplicationSettings appSettings,
                                        IDataEntryDataService dataService,
                                        ISampleSelectorRepository sampleSelectorRepository)
        {
            KeyPreview = true;

            Controller  = controller;
            DataService = dataService;
            AppSettings = appSettings;
            SampleSelectorRepository = sampleSelectorRepository;

            LogicController = new FormDataEntryLogic(Controller,
                                                     DialogService.Instance,
                                                     SoundService.Instance,
                                                     DataService,
                                                     AppSettings,
                                                     this,
                                                     sampleSelectorRepository);

            InitializePageContainer();
        }
        public void ShowDataEntry(CuttingUnit unit)
        {
            lock (_dataEntrySyncLock)
            {
                IDataEntryDataService     dataService;
                ISampleSelectorRepository sampleSelectorReop;
                try
                {
                    dataService        = new IDataEntryDataService(unit.Code, ApplicationController.DataStore);
                    sampleSelectorReop = new SampleSelectorRepository(new SamplerInfoDataservice_V2(ApplicationController.DataStore));
                }
                catch (CruiseConfigurationException e)
                {
                    MessageBox.Show(e.Message, e.GetType().Name);
                    return;
                }
                catch (UserFacingException e)
                {
                    var exType = e.GetType();
                    MessageBox.Show(e.Message, exType.Name);
                    return;
                }

                try
                {
                    ShowDataEntry(dataService, sampleSelectorReop);
                }
                catch (Exception ex)
                {
                    ReportException(ex);
                    //var timeStamp = DateTime.Now.ToString("HH_mm");

                    //var dumFilePath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "FScruiserDump" + timeStamp + ".xml");
                    //MessageBox.Show("FScruiser encountered a unexpected problem\r\n"
                    //    + "Dumping tree data to " + dumFilePath);
                    //dataService.Dump(dumFilePath);
                }
            }
        }
        void SaveData(IDataEntryDataService dataService, ISampleSelectorRepository sampleSelectorRepository)
        {
            try
            {
                sampleSelectorRepository.SaveSamplerStates();

                Exception ex;

                ex = dataService.SaveNonPlotData();
                ex = dataService.SavePlotData() ?? ex;
                if (ex != null)
                {
                    throw ex;
                }

                ApplicationController.OnLeavingCurrentUnit();
            }
            catch (FMSC.ORM.ReadOnlyException)
            {
                MessageBox.Show("File Is Read Only \r\n" + dataService.DataStore.Path);
            }
            catch (FMSC.ORM.ConstraintException ex)
            {
                MessageBox.Show("Data Constraint Failed\r\n" + ex.Message, "Error");
                if (DialogService.AskYesNo("Would you like to go back to data entry?", string.Empty))
                {
                    ShowDataEntry(dataService, sampleSelectorRepository);
                }
            }
            catch (Exception ex)
            {
                ReportException(ex);
                if (DialogService.AskYesNo("Would you like to go back to data entry?", string.Empty))
                {
                    ShowDataEntry(dataService, sampleSelectorRepository);
                }
            }
        }
Example #18
0
        public DataEntryTests()
        {
            _pathToFile = System.IO.Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.Personal)
                                                 , "testDataStore.cruise");

            if (System.IO.File.Exists(_pathToFile))
            {
                System.IO.File.Delete(_pathToFile);
            }

            _dataStore     = SetupDataStore();
            _dialogService = new DialogServiceMock();
            _soundService  = new SoundServiceMock();
            var dataService = new IDataEntryDataService("01", _dataStore);
            var appSettings = new ApplicationSettings();

            _de = new FormDataEntryLogic(_controller
                                         , _dialogService
                                         , _soundService
                                         , dataService
                                         , appSettings
                                         , _view);
        }
Example #19
0
        public static void OnTally(CountTree count,
                                   IDataEntryDataService dataService, ICollection <TallyAction> tallyHistory,
                                   IApplicationSettings appSettings, IDataEntryView view,
                                   IDialogService dialogService, ISoundService soundService,
                                   ISampleSelectorRepository sampleSelectorRepository)
        {
            TallyAction action  = null;
            SampleGroup sg      = count.SampleGroup;
            var         sampler = sampleSelectorRepository.GetSamplerBySampleGroupCode(sg.Stratum.Code, sg.Code);


            if (sampler == null)
            {
            }
            // if doing a manual tally create a tree and jump out
            else if (sampler is ExternalSampleSelectorPlaceholder)
            {
                try
                {
                    action = new TallyAction(count);
                    var newTree = dataService.CreateNewTreeEntry(count, true); //create measure tree
                    newTree.TreeCount = sg.SamplingFrequency;                  //increment tree count on tally
                    action.TreeRecord = newTree;
                }
                catch (FMSC.ORM.SQLException) //count save fail
                {
                    dialogService.ShowMessage("File error");
                }
            }
            else if (count.SampleGroup.Stratum.Is3P)//threeP sampling
            {
                action = TallyThreeP(count, sampler, sg, dataService, dialogService);
            }
            else//non 3P sampling (STR)
            {
                action = TallyStandard(count, sampler, dataService, dialogService);
            }

            //action may be null if cruising 3P and user doesn't enter a kpi
            if (action != null)
            {
                dataService.SaveTallyAction(action);
                soundService.SignalTally();

                var tree = action.TreeRecord;
                if (tree != null)
                {
                    if (tree.CountOrMeasure == "M")
                    {
                        soundService.SignalMeasureTree();
                    }
                    else if (tree.CountOrMeasure == "I")
                    {
                        soundService.SignalInsuranceTree();
                    }

                    if (appSettings.EnableCruiserPopup)
                    {
                        dialogService.AskCruiser(tree);
                        tree.TrySave();
                    }
                    else
                    {
                        var sampleType = (tree.CountOrMeasure == "M") ? "Measure Tree" :
                                         (tree.CountOrMeasure == "I") ? "Insurance Tree" : String.Empty;
                        dialogService.ShowMessage("Tree #" + tree.TreeNumber.ToString(), sampleType);
                    }

                    if (tree.CountOrMeasure == "M" && AskEnterMeasureTreeData(appSettings, dialogService))
                    {
                        view.GotoTreePage();
                        //this.View.TreeViewMoveLast();
                    }
                }
                tallyHistory.Add(action);
            }
        }
Example #20
0
        //[InlineData(0,0, "C", false, false)]//frequency of 0 is not allowed and breaks the OnTally
        public void OnTallyTest_STR(int frequency, int insuranceFreq, string resultCountMeasure, bool enableCruiserPopup, bool enterMeasureTreeData)
        {
            using (var ds = CreateDatastore(CruiseDAL.Schema.CruiseMethods.STR, frequency, insuranceFreq))
            {
                var dataService = new IDataEntryDataService("01", ds);

                var count = ds.From <CountTree>().Read().Single();

                var tallyHistory = new List <TallyAction>();

                var appSettingsMock = new Mock <IApplicationSettings>();
                appSettingsMock.Setup(x => x.EnableCruiserPopup).Returns(enableCruiserPopup);
                appSettingsMock.Setup(x => x.EnableAskEnterTreeData).Returns(enterMeasureTreeData);

                var dataEntryViewMock = new Mock <IDataEntryView>();
                var dialogServiceMock = new Mock <IDialogService>();
                dialogServiceMock.Setup(x => x.AskYesNo(It.Is <string>(s => s == "Would you like to enter tree data now?"), It.IsAny <string>(), It.IsAny <bool>()))
                .Returns(enterMeasureTreeData);

                var soundServiceMock = new Mock <ISoundService>();

                var samplerRepo = new Mock <ISampleSelectorRepository>();
                samplerRepo.Setup(x => x.GetSamplerBySampleGroupCode(It.IsAny <string>(), It.IsAny <string>()))
                .Returns(new FMSC.Sampling.SystematicSelecter(frequency, insuranceFreq, false));

                FormDataEntryLogic.OnTally(count, dataService, tallyHistory,
                                           appSettingsMock.Object,
                                           dataEntryViewMock.Object,
                                           dialogServiceMock.Object,
                                           soundServiceMock.Object,
                                           samplerRepo.Object);

                tallyHistory.Should().HaveCount(1);
                var tallyAction = tallyHistory.Single();

                var treeCount = ds.ExecuteScalar <int>("SELECT Sum(TreeCount) FROM CountTree;");
                treeCount.Should().Be(1);

                // verify SingnalTally was called
                soundServiceMock.Verify(x => x.SignalTally(It.IsAny <bool>()));

                if (resultCountMeasure == "M" || resultCountMeasure == "I")
                {
                    tallyAction.TreeRecord.Should().NotBeNull();

                    dataService.NonPlotTrees.Should().HaveCount(1);

                    var tree = ds.From <Tree>().Read().Single();
                    tree.Should().NotBeNull();
                    tree.CountOrMeasure.Should().Be(resultCountMeasure);

                    if (resultCountMeasure == "M")
                    {
                        soundServiceMock.Verify(x => x.SignalMeasureTree());
                    }
                    else
                    {
                        soundServiceMock.Verify(x => x.SignalInsuranceTree());
                    }

                    if (enterMeasureTreeData)
                    {
                        dataEntryViewMock.Verify(v => v.GotoTreePage());//verify GoToTreePage was called
                    }

                    if (enableCruiserPopup)
                    {
                        dialogServiceMock.Verify(x => x.AskCruiser(It.IsNotNull <Tree>()));
                    }
                    else
                    {
                        dialogServiceMock.Verify(x => x.ShowMessage(It.Is <string>(s => s.Contains("Tree #")), It.IsAny <string>()));
                    }
                }
            }
        }