Exemple #1
0
        DAL SetupDataStore()
        {
            var dataStore = new DAL(_pathToFile, true);

            var sale = new SaleDO(dataStore)
            {
                LogGradingEnabled = false,
                SaleNumber        = "12345",
                Region            = "01",
                Forest            = "01",
                District          = "01"
            };

            sale.Save();

            var unit = new CuttingUnitDO(dataStore)
            {
                Code = "01"
            };

            unit.Save();

            var stratum = new StratumDO(dataStore)
            {
                Code   = "01",
                Method = CruiseMethods.STR
            };

            stratum.Save();
            unit.Strata.Add(stratum);
            unit.Strata.Save();

            var sg = new SampleGroupDO(dataStore)
            {
                Code           = "01",
                CutLeave       = "C",
                UOM            = "1",
                PrimaryProduct = "01"
            };

            sg.Stratum            = stratum;
            sg.SamplingFrequency  = 5;
            sg.InsuranceFrequency = 0;

            sg.Save();

            var countTree = new CountTreeDO(dataStore)
            {
                SampleGroup = sg,
                CuttingUnit = unit
            };

            countTree.Save();

            return(dataStore);
        }
        public int OutputLocalVolume(string fileName)
        {
            //  first, does text file exists?  Can' write local volume if it hasn't been created
            string outFile = System.IO.Path.ChangeExtension(fileName, "out");

            if (!File.Exists(outFile))
            {
                MessageBox.Show("Local Volume Reports are added to the text output file.\nThat file does not exist.  Please create the output file and rerun Local Volume.",
                                "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(-1);
            }   //  endif file doesn't exists

            //  Pull regression results table
            IEnumerable <RegressionDO> resultsList = Global.BL.getRegressionResults();

            if (!resultsList.Any())
            {
                MessageBox.Show("No regression results.\nCannot produce reports.", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(-1);
            }   //  endif
            // Initialize report title
            ReportTitle.Append("LOCAL VOLUME TABLE REPORT - ");
            //  need sale info to complete the heading
            SaleDO sale = Global.BL.getSale().First();

            currSale     = sale.SaleNumber;
            currSaleName = sale.Name;
            currDate     = DateTime.Now.ToString();


            // first primary
            List <RegressionDO> justPrimary = resultsList.Where(rr => rr.rVolType == "Primary").ToList();

            //  create page one
            writePageOne(outFile, justPrimary);
            // separate secondary list
            List <RegressionDO> justSecondary = resultsList.Where(rr => rr.rVolType == "Secondary").ToList();

            if (justSecondary.Count > 0)
            {
                ReportTitle.Replace("Primary", "Secondary");
                writePageOne(outFile, justPrimary, justSecondary);
            }   //  endif secondary

            //  create page two -- primary
            ReportTitle.Replace("Secondary", "Primary");
            writePageTwo(outFile, justPrimary, 1);
            if (justSecondary.Count > 0)
            {
                //  and secondary
                writePageTwo(outFile, justSecondary, 2);
            }   //  endif secondary

            return(0);
        }   //  end OutputLocalVolume
        }   //  end MoreThanOne

        public static int BlankSaleNum(IEnumerable <SaleDO> saleList)
        {
            SaleDO sale = saleList.First();

            if (sale.SaleNumber == "" || sale.SaleNumber == null)
            {
                return(8);       //  returns error number for blank field
            }
            else
            {
                return(-1);
            }
        } //  end BlankSaleNum
Exemple #4
0
        protected String AskSavePath(SaleDO sale)
        {
            bool createSaleFolder = false;

            if (ApplicationController.UserSettings.CreateSaleFolder == null)
            {
                using (var dialog = new CreateSaleFolderDialog())
                {
                    createSaleFolder = (dialog.ShowDialog() == DialogResult.Yes);
                    if (dialog.RememberSelection)
                    {
                        ApplicationController.UserSettings.CreateSaleFolder = createSaleFolder;
                        //ApplicationState.GetHandle().Save();
                    }
                }
            }
            else
            {
                createSaleFolder = ApplicationController.UserSettings.CreateSaleFolder.Value;
            }

            using (var saveFileDialog = new System.Windows.Forms.SaveFileDialog())
            {
                var purposeShort = Strings.PURPOSE_SHORT_MAP.GetValueOrDefault(sale.Purpose, string.Empty);

                saveFileDialog.AutoUpgradeEnabled = true;
                saveFileDialog.CustomPlaces.Add(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\CruiseFiles");
                saveFileDialog.InitialDirectory = ApplicationController.UserSettings.CruiseSaveLocation;
                saveFileDialog.DefaultExt       = "cruise";
                saveFileDialog.FileName         = $"{ sale.SaleNumber} {sale.Name} {purposeShort}.cruise";
                saveFileDialog.Filter           = "Cruise files(*.cruise)|*.cruise";
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    string userPath = saveFileDialog.FileName;
                    string dir      = System.IO.Path.GetDirectoryName(userPath);
                    ApplicationController.UserSettings.CruiseSaveLocation = dir;

                    if (createSaleFolder)
                    {
                        dir += $"\\{sale.SaleNumber}{sale.Name}\\";
                        if (!System.IO.Directory.Exists(dir))
                        {
                            System.IO.Directory.CreateDirectory(dir);
                        }
                        return(dir + System.IO.Path.GetFileName(userPath));
                    }
                    return(userPath);
                }
                return(null);
            }
        }
Exemple #5
0
        private bool ShowWizardDialog(DAL database, out SaleDO sale)
        {
            CruiseWizardView      view   = new CruiseWizardView();
            CruiseWizardPresenter p      = new CruiseWizardPresenter(view, this, this.ApplicationController, database);
            DialogResult          result = view.ShowDialog((IWin32Window)this.ApplicationController.MainWindow);

            sale = p.Sale;
            if (result == DialogResult.OK)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void CountTest()
        {
            DataObjectFactory DOFactory = new DataObjectFactory(_DAL);
            ObjectCache target = new ObjectCache(DOFactory);

            target.GetByID<SaleDO>(1);

            Assert.Equal(1, target.Count);

            var tempSale = new SaleDO { rowID = 2 };
            target.Add( tempSale, ObjectCache.AddBehavior.THROWEXCEPTION);

            Assert.Equal(2, target.Count);

            target.Remove(tempSale);

            Assert.Equal(1, target.Count);

            //target.Clear();

            //Assert.AreEqual(0, target.Count);
        }
        public void AddTest()
        {
            ObjectCache target = new ObjectCache(_DOFactory);

            var tempSale = new SaleDO { rowID = 1 };

            Assert.Equal(true, target.Add(tempSale, ObjectCache.AddBehavior.DONT_OVERWRITE));
            tempSale = new SaleDO { rowID = 1 };
            Assert.Equal(false, target.Add(tempSale, ObjectCache.AddBehavior.DONT_OVERWRITE));
            tempSale = new SaleDO { rowID = 1 };
            Assert.Equal(true, target.Add(tempSale, ObjectCache.AddBehavior.OVERWRITE));
            tempSale = new SaleDO { rowID = 1 };
            try
            {
                target.Add(tempSale, ObjectCache.AddBehavior.THROWEXCEPTION);
                Assert.True(false);
            }
            catch (Exception e)
            {
                //TODO proper exception type not defined, for AddBehavior.THROW_EXCEPTION
            }
        }
Exemple #8
0
        public void createGraphs()
        {
            List <TreeDO>    tList       = Global.BL.getTrees().ToList();
            List <LCDDO>     lcdList     = Global.BL.getLCD().ToList();
            List <StratumDO> sList       = Global.BL.getStratum().ToList();
            List <LCDDO>     justSpecies = Global.BL.getLCDOrdered("WHERE CutLeave = ?", "GROUP BY Species", "C", "").ToList();
            //  pull salename and number to put in graph title
            //  also need it to create subfolder for graphs
            SaleDO sale         = Global.BL.getSale().First();
            string currSaleName = sale.Name;

            if (currSaleName.Length > 25)
            {
                currSaleName = currSaleName.Remove(25, currSaleName.Length);
            }
            string currSaleNumber = sale.SaleNumber;

            // pull data needed and call appropriate graph routine for report
            switch (currentReport)
            {
            case "GR01":
                foreach (LCDDO js in justSpecies)
                {
                    //  pull all trees for each species
                    List <TreeDO> justTrees = tList.FindAll(td => td.Species == js.Species && td.CountOrMeasure == "M");
                    currTitle.Append("DBH AND TOTAL HEIGHT BY ");
                    if (justTrees.Count == 0)
                    {
                        noDataForGraph(js.Species, "Species");
                        break;
                    }
                    else
                    {
                        currTitle.Append(js.Species);
                        currTitle.Append("\nSale number: ");
                        currTitle.Append(currSaleNumber);
                        currTitle.Append("   Sale name:  ");
                        currTitle.Append(currSaleName);
                        gf.currTitle    = currTitle.ToString();
                        gf.currXtitle   = "DBH";
                        gf.currYtitle   = "TOTAL HEIGHT";
                        gf.graphNum     = 1;
                        gf.currSP       = js.Species;
                        gf.fileName     = fileName;
                        gf.chartType    = "SCATTER";
                        gf.treeList     = justTrees;
                        gf.currSaleName = currSaleName;
                        gf.ShowDialog();
                    }       //  endif no data
                    currTitle.Remove(0, currTitle.Length);
                    justTrees.Clear();
                }       //  end foreach loop
                break;

            case "GR02":
                if (lcdList.Count == 0)
                {
                    MessageBox.Show("No data found for report.\nTry processing the cruise again.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }       //  endif no data
                //  total expansion factor for each species to get data for the sale
                foreach (LCDDO js in justSpecies)
                {
                    List <LCDDO> speciesGroup = lcdList.FindAll(
                        delegate(LCDDO l)
                    {
                        return(l.Species == js.Species);
                    });
                    expandData(speciesGroup, "EXPFAC", sList, js.Species);
                }       //  end foreach justSpecies
                currTitle.Remove(0, currTitle.Length);
                currTitle.Append("SPECIES DISTRIBUTION FOR THE SALE");
                currTitle.Append("\nSale number: ");
                currTitle.Append(currSaleNumber);
                currTitle.Append("   Sale name:  ");
                currTitle.Append(currSaleName);
                gf.currTitle    = currTitle.ToString();
                gf.currXtitle   = "";
                gf.currYtitle   = "";
                gf.graphNum     = 2;
                gf.chartType    = "PIE";
                gf.lcdList      = speciesTotal;
                gf.fileName     = fileName;
                gf.currSaleName = currSaleName;
                gf.ShowDialog();

                break;

            case "GR03":
                speciesTotal.Clear();
                //  total net CUFT volume for sawtimber only
                foreach (LCDDO js in justSpecies)
                {
                    List <LCDDO> speciesGroup = lcdList.FindAll(
                        delegate(LCDDO l)
                    {
                        return(l.Species == js.Species && l.PrimaryProduct == "01");
                    });
                    expandData(speciesGroup, "VOL", sList, js.Species);
                }       //  end foreach justSpecies
                currTitle.Remove(0, currTitle.Length);
                currTitle.Append("VOLUME BY SPECIES -- SAWTIMBER ONLY");
                currTitle.Append("\nSale number: ");
                currTitle.Append(currSaleNumber);
                currTitle.Append("   Sale name:  ");
                currTitle.Append(currSaleName);
                gf.currTitle    = currTitle.ToString();
                gf.currXtitle   = "";
                gf.currYtitle   = "";
                gf.graphNum     = 3;
                gf.chartType    = "PIE";
                gf.lcdList      = speciesTotal;
                gf.fileName     = fileName;
                gf.currSaleName = currSaleName;
                gf.ShowDialog();
                break;

            case "GR04":
                speciesTotal.Clear();
                //  total net CUFT volume for sawtimber only
                foreach (LCDDO jp in
                         Global.BL.getLCDOrdered("WHERE CutLeave = ?", "GROUP BY PrimaryProduct", "C", ""))
                {
                    List <LCDDO> productGroup = lcdList.FindAll(
                        delegate(LCDDO l)
                    {
                        return(l.PrimaryProduct == jp.PrimaryProduct);
                    });
                    expandData(productGroup, "VOL", sList, jp.PrimaryProduct);
                }       //  end foreach justSpecies
                currTitle.Remove(0, currTitle.Length);
                currTitle.Append("VOLUME BY PRODUCT");
                currTitle.Append("\nSale number: ");
                currTitle.Append(currSaleNumber);
                currTitle.Append("   Sale name:  ");
                currTitle.Append(currSaleName);
                gf.currTitle    = currTitle.ToString();
                gf.currXtitle   = "";
                gf.currYtitle   = "";
                gf.graphNum     = 4;
                gf.chartType    = "PIE";
                gf.lcdList      = speciesTotal;
                gf.fileName     = fileName;
                gf.currSaleName = currSaleName;
                gf.ShowDialog();
                break;

            case "GR05":
                //  per request from Region 10, give option to use 16 or 32 foot logs
                //  for this graph --  July 2017
                int          whichLength = 16;
                selectLength getLength   = new selectLength();
                getLength.ShowDialog();
                if (getLength.lengthSelected == 0)
                {
                    whichLength = 16;
                }
                else
                {
                    whichLength = getLength.lengthSelected;
                }
                //  pull by species for separate graphs
                List <LogStockDO> logsTotal = new List <LogStockDO>();
                //List<LogStockDO> lsList = Global.BL.getLogStock();
                //  need to expand also
                foreach (LCDDO js in justSpecies)
                {
                    // pull all logs
                    IEnumerable <LogStockDO> justSelectLogs = Global.BL.getLogStock()
                                                              .Where(lsd => lsd.Length == whichLength && lsd.Tree.Species == js.Species);
                    if (!justSelectLogs.Any())
                    {
                        MessageBox.Show("Graph cannot be created.\nNo logs found.", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        break;
                    }       //  endif
                    logsTotal = LoadLogs(justSelectLogs, js.Species, sList);
                    currTitle.Remove(0, currTitle.Length);
                    if (whichLength == 16)
                    {
                        currTitle.Append("NUMBER OF 16-FOOT LOGS BY DIB CLASS -- ");
                    }
                    else if (whichLength == 32)
                    {
                        currTitle.Append("NUMBER OF 32-FOOT LOGS BY DIB CLASS -- ");
                    }
                    currTitle.Append(js.Species);
                    currTitle.Append("\nSale number: ");
                    currTitle.Append(currSaleNumber);
                    currTitle.Append("   Sale name:  ");
                    currTitle.Append(currSaleName);
                    gf.currTitle    = currTitle.ToString();
                    gf.currXtitle   = "DIB CLASS";
                    gf.currYtitle   = "NUMBER OF LOGS";
                    gf.graphNum     = 5;
                    gf.chartType    = "BAR";
                    gf.logStockList = logsTotal;
                    gf.currSP       = js.Species;
                    gf.fileName     = fileName;
                    gf.currSaleName = currSaleName;
                    gf.ShowDialog();
                }       //  end foreach loop on species
                break;

            case "GR06":
                //  pull just measured and cut trees
                justMeasured = tList.FindAll(
                    delegate(TreeDO td)
                {
                    return(td.CountOrMeasure == "M" && td.SampleGroup.CutLeave == "C");
                });
                //  expand data and group by DBH class
                expandData(justMeasured, sList);
                currTitle.Remove(0, currTitle.Length);
                currTitle.Append("DIAMETER DISTRIBUTION FOR THE SALE");
                currTitle.Append("\nSale number: ");
                currTitle.Append(currSaleNumber);
                currTitle.Append("   Sale name:  ");
                currTitle.Append(currSaleName);
                gf.currTitle    = currTitle.ToString();
                gf.currXtitle   = "DBH";
                gf.currYtitle   = "NUMBER OF TREES";
                gf.graphNum     = 6;
                gf.chartType    = "BAR";
                gf.treeList     = treesByDBH;
                gf.fileName     = fileName;
                gf.currSaleName = currSaleName;
                gf.ShowDialog();
                break;

            case "GR07":
                //  need by species
                foreach (LCDDO js in justSpecies)
                {
                    //  need species, measured and cut trees
                    justMeasured = tList.FindAll(
                        delegate(TreeDO td)
                    {
                        return(td.CountOrMeasure == "M" && td.SampleGroup.CutLeave == "C" &&
                               td.Species == js.Species);
                    });
                    //  expand data
                    expandData(justMeasured, sList);
                    //  load
                    currTitle.Remove(0, currTitle.Length);
                    currTitle.Append("DIAMETER DISTRIBUTION FOR SPECIES ");
                    currTitle.Append(js.Species);
                    currTitle.Append("\nSale number: ");
                    currTitle.Append(currSaleNumber);
                    currTitle.Append("   Sale name:  ");
                    currTitle.Append(currSaleName);
                    gf.currTitle    = currTitle.ToString();
                    gf.currXtitle   = "DBH";
                    gf.currYtitle   = "NUMBER OF TREES";
                    gf.graphNum     = 7;
                    gf.chartType    = "BAR";
                    gf.treeList     = treesByDBH;
                    gf.currSP       = js.Species;
                    gf.fileName     = fileName;
                    gf.currSaleName = currSaleName;
                    gf.ShowDialog();
                    treesByDBH.Clear();
                }       //  end foreach species
                break;

            case "GR08":
                //  need by stratum
                foreach (StratumDO s in sList)
                {
                    //  need measured and cut trees for each stratum
                    justMeasured = tList.FindAll(
                        delegate(TreeDO td)
                    {
                        return(td.CountOrMeasure == "M" && td.SampleGroup.CutLeave == "C" &&
                               td.Stratum.Code == s.Code);
                    });
                    //  expand data
                    expandData(justMeasured, sList);
                    //  load
                    currTitle.Remove(0, currTitle.Length);
                    currTitle.Append("DIAMETER DISTRIBUTION BY STRATUM ");
                    currTitle.Append(s.Code);
                    currTitle.Append("\nSale number: ");
                    currTitle.Append(currSaleNumber);
                    currTitle.Append("   Sale name:  ");
                    currTitle.Append(currSaleName);
                    gf.currTitle    = currTitle.ToString();
                    gf.currXtitle   = "DBH";
                    gf.currYtitle   = "NUMBER OF TREES";
                    gf.graphNum     = 8;
                    gf.chartType    = "BAR";
                    gf.treeList     = treesByDBH;
                    gf.currSP       = s.Code;
                    gf.fileName     = fileName;
                    gf.currSaleName = currSaleName;
                    gf.ShowDialog();
                    treesByDBH.Clear();
                }       //  end foreach stratum
                break;

            case "GR09":
                //  need values from TreEstimate table
                //  if that table is empty, it means no 3P strata or the file was created
                //  prior to March 2015 when the table was implemented.
                //List<TreeEstimateDO> treeEstimates = Global.BL.getTreeEstimates();
                if (!Global.BL.getTreeEstimates().Any())
                {
                    MessageBox.Show("No estimate data is available for GR09.\nCannot produce this graph.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }       //  endif
                //List<TreeDO> uniqueSpecies = Global.BL.GetUniqueSpecies();
                List <CountTreeDO> cList = Global.BL.getCountTrees().ToList();
                List <CreateTextFile.ReportSubtotal> graphData = new List <CreateTextFile.ReportSubtotal>();
                foreach (TreeDO u in Global.BL.GetUniqueSpecies())
                {
                    //  pull all tree default value for current species
                    //  accumulate all count tree cn in TreeEstimate for this species
                    foreach (CountTreeDO c in cList.FindAll(ct => ct.TreeDefaultValue_CN == u.TreeDefaultValue_CN))
                    {
                        List <TreeEstimateDO> justEst = Global.BL.getTreeEstimates().Where(
                            te => te.CountTree_CN == c.CountTree_CN).ToList();
                        if (justEst.Count > 0)
                        {
                            buildKPIdata(justEst, graphData);
                        }
                    }       //  end foreach loop
                    //  reset categories based on Ken's logic
                    List <CreateTextFile.ReportSubtotal> categoryData = new List <CreateTextFile.ReportSubtotal>();
                    if (graphData.Count > 0)
                    {
                        resetCategories(graphData, categoryData);
                        //  load
                        currTitle.Remove(0, currTitle.Length);
                        currTitle.Append("KPI DISTRIBUTION BY SPECIES -- ");
                        currTitle.Append(u.Species);
                        currTitle.Append("\nSale number: ");
                        currTitle.Append(currSaleNumber);
                        currTitle.Append("   Sale name:  ");
                        currTitle.Append(currSaleName);
                        gf.currTitle    = currTitle.ToString();
                        gf.currXtitle   = "KPI";
                        gf.currYtitle   = "NUMBER OF TREES";
                        gf.graphNum     = 9;
                        gf.chartType    = "BAR";
                        gf.graphData    = categoryData;
                        gf.currSP       = u.Species;
                        gf.fileName     = fileName;
                        gf.currSaleName = currSaleName;
                        gf.ShowDialog();
                        graphData.Clear();
                        categoryData.Clear();
                    }   //  endif
                }       //  end foreach loop
                break;

            case "GR10":
                List <CreateTextFile.ReportSubtotal> dataToGraph = new List <CreateTextFile.ReportSubtotal>();
                //  need to loop by stratum
                foreach (StratumDO s in sList)
                {
                    if (s.BasalAreaFactor > 0)
                    {
                        //  Pull plots for this stratum
                        double numplots = Global.BL.GetStrataPlots(s.Code).Count();

                        //  Pull tree data for this stratum
                        List <TreeDO> treeList = Global.BL.getTrees().ToList();
                        //  Pull stratum from LCD to get species in the stratum
                        //  Then find number of trees for the stratum and each species in the stratum
                        foreach (LCDDO js in Global.BL.getLCD().Where(ld => ld.Stratum == s.Code))
                        {
                            List <TreeDO> justTrees = treeList.FindAll(
                                delegate(TreeDO td)
                            {
                                return(td.Stratum.Code == s.Code && td.Species == js.Species &&
                                       td.SampleGroup.CutLeave == "C" && td.LiveDead == js.LiveDead);
                            });

                            //  Load into graphData --  see if species is already in the list
                            int nthRow = dataToGraph.FindIndex(
                                delegate(CreateTextFile.ReportSubtotal cr)
                            {
                                return(cr.Value1 == js.Species);
                            });
                            if (nthRow < 0)
                            {
                                CreateTextFile.ReportSubtotal rs = new CreateTextFile.ReportSubtotal();
                                rs.Value1 = js.Species;
                                rs.Value3 = (s.BasalAreaFactor * justTrees.Count) / numplots;
                                dataToGraph.Add(rs);
                            }
                            else if (nthRow >= 0)
                            {
                                dataToGraph[nthRow].Value3 += (s.BasalAreaFactor * justTrees.Count) / numplots;
                            }   //  endif
                        }       //  end foreach loop

                        //  load graphData
                        if (dataToGraph.Count > 0)
                        {
                            currTitle.Remove(0, currTitle.Length);
                            currTitle.Append("BAF PER ACRE BY SPECIES FOR STRATUM ");
                            currTitle.Append(s.Code);
                            currTitle.Append("\nSale Number:  ");
                            currTitle.Append(currSaleNumber);
                            currTitle.Append("\n");
                            currTitle.Append("   Sale Name:  ");
                            currTitle.Append(currSaleName);

                            gf.currTitle    = currTitle.ToString();
                            gf.currXtitle   = "";
                            gf.currYtitle   = "";
                            gf.graphNum     = 10;
                            gf.chartType    = "PIE";
                            gf.currSP       = s.Code;
                            gf.graphData    = dataToGraph;
                            gf.fileName     = fileName;
                            gf.currSaleName = currSaleName;
                            gf.ShowDialog();
                            dataToGraph.Clear();
                        } //  endif
                    }     //  endif on basal area factor
                }         //  end foreach loop on stratum
                break;

            case "GR11":
                //  pull data by sample group
                //List<SampleGroupDO> sgList = Global.BL.getSampleGroups();
                float numPlots = 0;
                //  find all trees for each group
                foreach (SampleGroupDO sg in Global.BL.getSampleGroups())
                {
                    if (sg.Stratum.BasalAreaFactor > 0)
                    {
                        //  find all strata for this group in LCD
                        //List<LCDDO> lList = Global.BL.getLCD();
                        //List<LCDDO> justStrata = Global.BL.getLCD().Where(l => l.SampleGroup == sg.Code);
                        //  find number of plots for the strata
                        string currST = "*";
                        foreach (LCDDO js in Global.BL.getLCD().Where(l => l.SampleGroup == sg.Code))
                        {
                            if (currST != js.Stratum)
                            {
                                //List<PlotDO> pList = Global.BL.GetStrataPlots(js.Stratum);
                                numPlots += Global.BL.GetStrataPlots(js.Stratum).Count();
                                currST    = js.Stratum;
                            }   //  endif
                        }       //  end foreach loop

                        // now find all trees for the sample group
                        justMeasured = tList.FindAll(
                            delegate(TreeDO td)
                        {
                            return(td.SampleGroup_CN == sg.SampleGroup_CN &&
                                   td.CountOrMeasure == "M" &&
                                   td.SampleGroup.CutLeave == "C" &&
                                   td.Stratum_CN == sg.Stratum_CN);
                        });

                        //  load DIB classes
                        LoadDIBclass(justMeasured);

                        //  Accumulate number of trees for each class
                        foreach (TreeDO jm in justMeasured)
                        {
                            //  find class to update
                            int nthRow = findDIBindex(treesByDBH, jm.DBH);
                            if (nthRow >= 0)
                            {
                                treesByDBH[nthRow].TreeCount++;
                            }
                        }       //  end foreach loop

                        //  Calculate
                        foreach (TreeDO tbd in treesByDBH)
                        {
                            //  Calculate value for each DIB class
                            tbd.TreeCount = (float)((sg.Stratum.BasalAreaFactor * tbd.TreeCount) / numPlots);
                        }       //  end foreach loop

                        //  load dat6a for gtraph
                        currTitle.Remove(0, currTitle.Length);
                        currTitle.Append("BAF PER ACRE FOR SAMPLE GROUP ");
                        currTitle.Append(sg.Code);
                        currTitle.Append("\nSaleNumber: ");
                        currTitle.Append(currSaleNumber);
                        currTitle.Append("\nSale name: ");
                        currTitle.Append(currSaleName);
                        gf.currTitle    = currTitle.ToString();
                        gf.currXtitle   = "DBH Class";
                        gf.currYtitle   = "Basal Area Factor";
                        gf.graphNum     = 11;
                        gf.chartType    = "BAR";
                        gf.currSP       = sg.Code;
                        gf.treeList     = treesByDBH;
                        gf.fileName     = fileName;
                        gf.currSaleName = currSaleName;
                        gf.ShowDialog();
                    } //  endif
                }     //  end foreach loop
                break;
            }         //  end switch on report
            return;
        }             //  end createGraphs
 public SaleVM(SaleDO sale)
     : base(sale)
 {
 }
Exemple #10
0
        }   //  end LogError6

        public static StringBuilder GetIdentifier(string tableName, long CNtoFind)
        {
            StringBuilder ident = new StringBuilder();

            switch (tableName)
            {
            case "Sale":
                SaleDO sale = Global.BL.getSale().FirstOrDefault(sd => sd.Sale_CN == CNtoFind);
                if (sale != null)
                {
                    ident.Append("Sale number = ");
                    ident.Append(sale.SaleNumber);
                }
                else
                {
                    ident.Append("Sale number not found");
                }
                break;

            case "Stratum":
                StratumDO strat = Global.BL.getStratum().FirstOrDefault(sdo => sdo.Stratum_CN == CNtoFind);
                if (strat != null)
                {
                    ident.Append(strat.Code);
                }
                else
                {
                    ident.Append("Stratum code not found");
                }
                break;

            case "Cutting Unit":
                CuttingUnitDO cudo = Global.BL.getCuttingUnits().FirstOrDefault(cu => cu.CuttingUnit_CN == CNtoFind);
                if (cudo != null)
                {
                    ident.Append("   ");
                    ident.Append(cudo.Code.PadLeft(3, ' '));
                }
                else
                {
                    ident.Append("Cutting unit not found");
                }
                break;

            case "Tree":
                TreeDO tdo = Global.BL.getTrees().FirstOrDefault(td => td.Tree_CN == CNtoFind);
                if (tdo != null)
                {
                    ident.Append(tdo.Stratum.Code.PadRight(3, ' '));
                    ident.Append(tdo.CuttingUnit.Code.PadLeft(3, ' '));
                    if (tdo.Plot == null)
                    {
                        ident.Append("     ");
                    }
                    else if (tdo.Plot_CN == 0)
                    {
                        ident.Append("     ");
                    }
                    else
                    {
                        ident.Append(tdo.Plot.PlotNumber.ToString().PadLeft(5, ' '));
                    }
                    ident.Append(tdo.TreeNumber.ToString().PadLeft(5, ' '));
                    ident.Append(" --- ");
                    if (tdo.Species == null)
                    {
                        ident.Append("       ");
                    }
                    else
                    {
                        ident.Append(tdo.Species.PadRight(7, ' '));
                    }
                    if (tdo.SampleGroup == null)
                    {
                        ident.Append("   ");
                    }
                    else
                    {
                        if (tdo.SampleGroup.Code == "" || tdo.SampleGroup.Code == " " ||
                            tdo.SampleGroup.Code == "<Blank>" || tdo.SampleGroup.Code == null)
                        {
                            ident.Append("   ");
                        }
                        else
                        {
                            ident.Append(tdo.SampleGroup.Code.PadRight(3, ' '));
                        }
                        ident.Append(tdo.SampleGroup.PrimaryProduct.PadRight(3, ' '));
                    }       //  endif
                }
                else
                {
                    ident.Append("Tree not found");
                }
                break;

            case "Log":
                LogDO log = Global.BL.getLogs().FirstOrDefault(ld => ld.Log_CN == CNtoFind);
                if (log != null)
                {
                    ident.Append(log.Tree.Stratum.Code.PadRight(3, ' '));
                    ident.Append(log.Tree.CuttingUnit.Code.PadLeft(3, ' '));
                    if (log.Tree.Plot == null)
                    {
                        ident.Append("     ");
                    }
                    else
                    {
                        ident.Append(log.Tree.Plot.PlotNumber.ToString().PadLeft(5, ' '));
                    }
                    ident.Append(log.Tree.TreeNumber.ToString().PadLeft(5, ' '));
                    ident.Append(log.LogNumber.PadLeft(3, ' '));
                }
                else
                {
                    ident.Append("Log not found");
                }
                break;

            case "Volume Equation":
                if (CNtoFind == 0)
                {
                    CNtoFind = 1;
                }
                //List<VolumeEquationDO> vList = Global.BL.getVolumeEquations();
                VolumeEquationDO ve = Global.BL.getVolumeEquations().ElementAt((int)CNtoFind - 1);
                ident.Append("-- --- ---- ---- --- ");
                ident.Append(ve.Species.PadRight(7, ' '));
                ident.Append("-- ");
                ident.Append(ve.PrimaryProduct.PadRight(3, ' '));
                ident.Append(ve.VolumeEquationNumber.PadRight(10, ' '));

                //ident.Append("-- --- ---- ---- --- ");
                //ident.Append(vList[(int)CNtoFind-1].Species.PadRight(7, ' '));
                //ident.Append("-- ");
                //ident.Append(vList[(int)CNtoFind-1].PrimaryProduct.PadRight(3, ' '));
                //ident.Append(vList[(int)CNtoFind-1].VolumeEquationNumber.PadRight(10,' '));
                break;

            case "Value Equation":
                if (CNtoFind == 0)
                {
                    CNtoFind = 1;
                }
                ValueEquationDO veq = Global.BL.getValueEquations().ElementAt((int)CNtoFind - 1);
                ident.Append("-- --- ---- ---- --- ");
                ident.Append(veq.Species.PadRight(7, ' '));
                ident.Append("-- ");
                ident.Append(veq.PrimaryProduct.PadRight(3, ' '));
                ident.Append(veq.ValueEquationNumber.PadRight(10, ' '));
                //List<ValueEquationDO> veList = Global.BL.getValueEquations();
                //ident.Append("-- --- ---- ---- --- ");
                //ident.Append(veList[(int)CNtoFind-1].Species.PadRight(7, ' '));
                //ident.Append("-- ");
                //ident.Append(veList[(int)CNtoFind-1].PrimaryProduct.PadRight(3,' '));
                //ident.Append(veList[(int)CNtoFind-1].ValueEquationNumber.PadRight(10,' '));
                break;

            case "Quality Adjustment":
                if (CNtoFind == 0)
                {
                    CNtoFind = 1;
                }
                QualityAdjEquationDO qe = Global.BL.getQualAdjEquations().ElementAt((int)CNtoFind - 1);
                ident.Append("-- --- ---- ---- --- ");
                ident.Append(qe.Species.PadRight(7, ' '));
                ident.Append("-- -- ");
                ident.Append(qe.QualityAdjEq.PadRight(10, ' '));
                //List<QualityAdjEquationDO> qList = Global.BL.getQualAdjEquations();
                //ident.Append("-- --- ---- ---- --- ");
                //ident.Append(qList[(int)CNtoFind-1].Species.PadRight(7, ' '));
                //ident.Append("-- -- ");
                //ident.Append(qList[(int)CNtoFind-1].QualityAdjEq.PadRight(10,' '));
                break;

            case "SampleGroup":
                SampleGroupDO sg = Global.BL.getSampleGroups().FirstOrDefault(sgd => sgd.SampleGroup_CN == CNtoFind);
                if (sg != null)
                {
                    ident.Append(sg.Stratum.Code.PadRight(3, ' '));
                    ident.Append("--- ---- ---- --- ------ ");
                    ident.Append(sg.Code.PadRight(3, ' '));
                    ident.Append(sg.PrimaryProduct.PadRight(3, ' '));
                }
                else
                {
                    ident.Append("Sample Group not found");
                }
                break;
            } //  end switch
            return(ident);
        }     //  end GetIdentifier
Exemple #11
0
 public void UpdateSale(SaleDO obj)
 {
     salePage.SaleDOBindingSource.DataSource = obj;
 }
Exemple #12
0
        private CruiseDAL.DAL CreateDatastore(string cruiseMethod, int freqORkz, int insuranceFreq)
        {
            var ds = new CruiseDAL.DAL();

            try
            {
                var sale = new SaleDO()
                {
                    DAL               = ds,
                    SaleNumber        = "12345",
                    Region            = "1",
                    Forest            = "1",
                    District          = "1",
                    Purpose           = "something",
                    LogGradingEnabled = true
                };
                sale.Save();

                var stratum = new StratumDO()
                {
                    DAL    = ds,
                    Code   = "01",
                    Method = cruiseMethod
                };
                stratum.Save();

                var cuttingUnit = new CuttingUnitDO()
                {
                    DAL  = ds,
                    Code = "01"
                };
                cuttingUnit.Save();

                var cust = new CuttingUnitStratumDO()
                {
                    DAL         = ds,
                    CuttingUnit = cuttingUnit,
                    Stratum     = stratum
                };
                cust.Save();

                var sampleGroup = new SampleGroupDO()
                {
                    DAL                = ds,
                    Stratum            = stratum,
                    Code               = "01",
                    PrimaryProduct     = "01",
                    UOM                = "something",
                    CutLeave           = "something",
                    InsuranceFrequency = insuranceFreq
                };

                if (CruiseMethods.THREE_P_METHODS.Contains(cruiseMethod))
                {
                    sampleGroup.KZ = freqORkz;
                }
                else
                {
                    sampleGroup.SamplingFrequency = freqORkz;
                }

                sampleGroup.Save();

                var tally = new TallyDO()
                {
                    DAL         = ds,
                    Hotkey      = "A",
                    Description = "something"
                };
                tally.Save();

                var count = new CountTreeDO()
                {
                    DAL         = ds,
                    CuttingUnit = cuttingUnit,
                    SampleGroup = sampleGroup,
                    Tally       = tally
                };
                count.Save();

                return(ds);
            }
            catch
            {
                ds.Dispose();
                throw;
            }
        }
        DAL CreateDataStore(string salePurpose = null, string saleRegion = "01", IEnumerable <string> methods = null)
        {
            methods = methods ?? new string[] { CruiseMethods.STR, CruiseMethods.FIX };

            var ds = new DAL();

            var sale = new SaleDO()
            {
                DAL        = ds,
                SaleNumber = "12345",
                Region     = saleRegion,
                Forest     = "11",
                District   = "something",
                Purpose    = salePurpose
            };

            sale.Save();

            var cuttingUnit = new CuttingUnitDO()
            {
                DAL  = ds,
                Code = "01"
            };

            cuttingUnit.Save();

            var tdv = new TreeDefaultValueDO()
            {
                DAL            = ds,
                Species        = "something",
                PrimaryProduct = "something",
                LiveDead       = "L"
            };

            tdv.Save();

            int counter = 0;

            foreach (var method in methods)
            {
                var stratum = new StratumDO()
                {
                    DAL    = ds,
                    Code   = counter++.ToString("d2"),
                    Method = method
                };
                stratum.Save();
                stratum.CuttingUnits.Add(cuttingUnit);
                stratum.CuttingUnits.Save();

                var sg = new SampleGroupDO()
                {
                    DAL            = ds,
                    Code           = 1.ToString("d2"),
                    Stratum        = stratum,
                    CutLeave       = "C",
                    UOM            = "something",
                    PrimaryProduct = "something"
                };
                sg.Save();
                sg.TreeDefaultValues.Add(tdv);
                sg.TreeDefaultValues.Save();

                if (CruiseMethods.PLOT_METHODS.Contains(method))
                {
                    var plot = new PlotDO()
                    {
                        DAL = ds, Stratum = stratum, CuttingUnit = cuttingUnit, PlotNumber = 1
                    };
                    plot.Save();

                    var tree = new TreeDO()
                    {
                        DAL              = ds,
                        CuttingUnit      = cuttingUnit,
                        Stratum          = stratum,
                        Plot             = plot,
                        SampleGroup      = sg,
                        TreeDefaultValue = tdv,
                        TreeNumber       = 1
                    };
                    tree.Save();
                }
                else
                {
                    var tree = new TreeDO()
                    {
                        DAL              = ds,
                        CuttingUnit      = cuttingUnit,
                        Stratum          = stratum,
                        SampleGroup      = sg,
                        TreeDefaultValue = tdv,
                        TreeNumber       = 1
                    };
                    tree.Save();
                }

                var countTree = new CountTree()
                {
                    CuttingUnit_CN      = cuttingUnit.CuttingUnit_CN,
                    SampleGroup_CN      = sg.SampleGroup_CN,
                    TreeDefaultValue_CN = tdv.TreeDefaultValue_CN,
                };

                ds.Save(countTree);
            }

            return(ds);
        }
Exemple #14
0
        }     //  end onRegionSelectedIndexChanged

        private void onAdditional(object sender, EventArgs e)
        {
            if (regionList.SelectedItem.ToString() == "10")
            {
                //  get correct password before continuing
                PasswordProtect pp = new PasswordProtect();
                pp.ShowDialog();
                if (pp.passwordResponse != "OK")
                {
                    Close();
                    return;
                }   //  endif

                string currentSale    = " ";
                string currentSaleNum = " ";
                if (templateFlag != 1)
                {
                    SaleDO sale = Global.BL.getSale().First();
                    currentSale    = sale.Name;
                    currentSaleNum = sale.SaleNumber;
                }   //  endif
                List <LogMatrixDO> checkMatrix = new List <LogMatrixDO>();
                try
                {
                    // is it empty?
                    checkMatrix = Global.BL.getLogMatrix("R008").ToList();
                    if (checkMatrix.Count == 0)
                    {
                        //  load default matrix for both reports
                        checkMatrix.Clear();
                        checkMatrix = loadDefaultMatrix(currentSale, currentSaleNum);
                        //  save default matrix
                        Global.BL.SaveLogMatrix(checkMatrix, "");
                    }   //  endif
                }
                catch
                {
                    //   need to create the table and load the default
                    int iDone = Global.BL.CreateNewTable("LogMatrix");
                    checkMatrix = loadDefaultMatrix(currentSale, currentSaleNum);
                    //  save default matrix
                    Global.BL.SaveLogMatrix(checkMatrix, "");
                }   //  endif

                //  see if log matrix table needs to be updated
                List <LogMatrixDO> reportMatrix = new List <LogMatrixDO>();
                DialogResult       dr           = MessageBox.Show("Reports R008 and R009 use a log matrix.\nDo you want to update the matrix now?\nNOTE: If the Log Matrix does not exist, the default matrix is used.", "QUESTION", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    DialogResult d8 = MessageBox.Show("The log matrix is different for each report.\nUpdate R008?", "QUESTION", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (d8 == DialogResult.Yes)
                    {
                        reportMatrix = Global.BL.getLogMatrix("R008").ToList();
                        LogMatrixUpdate lmu = new LogMatrixUpdate();
                        lmu.reportMatrix   = reportMatrix;
                        lmu.currSaleName   = currentSale;
                        lmu.currSaleNumber = currentSaleNum;
                        lmu.currReport     = "R008";
                        lmu.setupDialog();
                        lmu.ShowDialog();
                        reportMatrix = lmu.reportMatrix;
                        Global.BL.SaveLogMatrix(reportMatrix, "R008");

                        //  need to update R009?
                        DialogResult d9 = MessageBox.Show("Update R009?", "QUESTION", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (d9 == DialogResult.Yes)
                        {
                            //  retrieve R009 matrix and update
                            reportMatrix = Global.BL.getLogMatrix("R009").ToList();
                            LogMatrixUpdate lmx = new LogMatrixUpdate();
                            lmx.reportMatrix   = reportMatrix;
                            lmx.currSaleNumber = currentSale;
                            lmx.currSaleNumber = currentSaleNum;
                            lmx.currReport     = "R009";
                            lmx.setupDialog();
                            lmx.ShowDialog();
                            int rtnResult = lmx.returnValue;
                            if (rtnResult == 1)
                            {
                                reportMatrix = lmx.reportMatrix;
                                Global.BL.SaveLogMatrix(reportMatrix, "R009");
                            }   //  endif
                        }       //  endif
                    }
                    else if (d8 == DialogResult.No)
                    {
                        DialogResult d9 = MessageBox.Show("Update R009?", "QUESTION", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (d9 == DialogResult.Yes)
                        {
                            //  retrieve R009 matrix and update
                            reportMatrix = Global.BL.getLogMatrix("R009").ToList();
                            LogMatrixUpdate lmx = new LogMatrixUpdate();
                            lmx.reportMatrix   = reportMatrix;
                            lmx.currSaleNumber = currentSale;
                            lmx.currSaleNumber = currentSaleNum;
                            lmx.currReport     = "R009";
                            lmx.setupDialog();
                            lmx.ShowDialog();
                            int rtnResult = lmx.returnValue;
                            if (rtnResult == 1)
                            {
                                reportMatrix = lmx.reportMatrix;
                                Global.BL.SaveLogMatrix(reportMatrix, "R009");
                            } //  endif
                        }     //  endif
                    }         //  endif
                }             //  endif
            }                 //  endif

            if (availableReports.Items[0].ToString().Substring(0, 2) == "EX")
            {
                // not yet tested --  January 2012
                MessageBox.Show("Under Construction", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information);
                additionalData.Enabled = false;
                //additionalData.Enabled = true;
                return;

/*
 *              //  display dialog for capturing export grade values
 *              //  first need region number
 *              string currentRegion = "";
 *              currentRegion = Global.BL.findSingleField("Region", "Sale");
 *
 *              //  need dialog object
 *              ExportDialog ed = new ExportDialog();
 *              //  Then does the ExportValues table exist?  Need to fill list with defaults for all regions or Region 10
 *              bool tableExists = Global.BL.doesTableExist("ExportValues");
 *              if (tableExists == false)
 *              {
 *                  //  need to create the table
 *                  int nResult = Global.BL.CreateNewTable("ExportValues");
 *                  //  then get defaults to load into dialog for user to update
 *                  exportGrades eg = new exportGrades();
 *                  //  sort list first
 *                  List<exportGrades> egSortList = eg.createDefaultList(currentRegion, "sort");
 *                  List<exportGrades> egGradeList = eg.createDefaultList(currentRegion, "grade");
 *
 *                  ed.setupDialog(egSortList, egGradeList);
 *              }
 *              else if (tableExists == true)
 *              {
 *                  //  just get data in the table for display
 *                  List<exportGrades> egList = Global.BL.GetExportGrade();
 *                  List<exportGrades> dummyList = new List<exportGrades>();
 *                  ed.setupDialog(egList,dummyList);
 *              }   //  endif tableExists
 *              ed.fileName = fileName;
 *              ed.tableExists = tableExists;
 *              ed.ShowDialog();
 *
 *              additionalData.Enabled = false;
 */
            }
        }   //  end onAdditional
        public void WriteTest()
        {
            DAL dal = new DAL("WriteTest.cruise", true);
            dal.Create();

            SaleDO sale = new SaleDO(dal);
            sale.SaleNumber = "12345";
            sale.Region = "01";
            sale.Forest = "02";
            sale.Save();

            SaleDO saleRead = dal.ReadSingleRow<SaleDO>("Sale", "WHERE SaleNumber = '12345'");
            //Assert.IsTrue(object.ReferenceEquals(sale, saleRead));
            long saleID = sale.GetID();
            long saleReadID = saleRead.GetID();
            Assert.True(saleReadID == saleID);
            //Assert.IsNotNull(saleRead.CreatedDate);
            //DateTime time;
            //DateTime.TryParse(saleRead.CreatedDate, out time);
            //Assert.IsTrue(DateTime.Compare(time.Date, DateTime.Today) == 0);

            sale.SaleNumber = "54321";
            sale.Save();

            saleRead = dal.ReadSingleRow<SaleDO>("Sale", "WHERE SaleNumber = '54321'");
            //Assert.IsTrue(object.ReferenceEquals(sale, saleRead));
            //Assert.IsNotNull(saleRead.ModifiedDate);
            //DateTime.TryParse(saleRead.ModifiedDate, out time);
            //Assert.IsTrue(DateTime.Compare(time.Date, DateTime.Today) == 0);
        }