public void TestReadPlots()
        {
            using (var ds = new CruiseDAL.DAL(":memory:", true))
            {
                var unit = new CuttingUnit()
                {
                    Code = "1"
                };

                var st = new PlotStratum()
                {
                    Code   = "1",
                    Method = CruiseMethods.THREEPPNT
                };

                ds.Insert(unit);

                ds.Insert(st);

                ds.Insert(new Plot()
                {
                    CuttingUnit = unit,
                    Stratum     = st,
                    PlotNumber  = 1
                });

                st.DAL = ds;
                st.PopulatePlots(unit.CuttingUnit_CN.Value);

                st.Plots.Should().NotBeNullOrEmpty();
                st.Plots.Should().OnlyContain(x => x is Plot3PPNT);
            }
        }
        public void TestMakePlot_3ppnt()
        {
            using (var dal = new CruiseDAL.DAL(":memory:", true))
            {
                var unit = new CuttingUnit()
                {
                    Code = "01",
                    DAL  = dal
                };

                dal.Insert(unit);

                var stratum = new PlotStratum()
                {
                    Code   = "01",
                    Method = CruiseMethods.THREEPPNT,
                    DAL    = dal
                };

                dal.Insert(stratum);

                var plot = stratum.MakePlot(unit);

                plot.Should().BeOfType <Plot3PPNT>();

                plot.PlotNumber.Should().Be(1L);

                plot.CuttingUnit.Should().Be(unit);
                plot.Stratum.Should().Be(stratum);

                plot.Trees.Should().NotBeNull();
            }
        }
        //TODO make testable constructor
        public CruiseWizardPresenter(CruiseWizardView View, WindowPresenter windowPresenter, ApplicationControllerBase applicationController, DAL database)
        {
            this.View = View;
            this.WindowPresenter = windowPresenter;
            this.ApplicationController = applicationController;
            View.Presenter = this;
            _database = database;

            LoadSetupData();//load tree defaults, product codes, etc.

            LoadCruiseData();//read data from existing file

            //See if the file contains a template file record
            string templatePath = _database.ReadGlobalValue("CSM", "TemplatePath");

            if (!String.IsNullOrEmpty(templatePath))
            {
                this._fileHasTemplate = true;
                this._templateFile = new FileInfo(templatePath);
                View.SetTemplatePathTextBox(templatePath, false);
            }

            if (this.CuttingUnits.Count == 0)
            {
                this.CuttingUnits.Add(GetNewCuttingUnit());
            }
        }
Example #4
0
        public void ReadOneAllSetup(DAL db)
        {
            StringBuilder sb = new StringBuilder();
            foreach (String tableName in CruiseDAL.Schema.Schema.TABLE_NAMES)
            {
                List<ColumnInfo> columnInfos = db.GetTableInfo(tableName);
                String[] columnNames = (from ci in columnInfos
                                       where ci.IsRequired
                                       select ci.Name).ToArray();
                String[] values = (from ci in columnInfos
                                   where ci.IsRequired
                                   select (ci.DBType == "TEXT") ? "'TestStr'" :
                                   (ci.DBType == "INTEGER") ? "101010" :
                                   (ci.DBType == "REAL") ? "202.02" : "'Something'").ToArray();

                if (columnNames.Length > 0)
                {
                    sb.AppendFormat("INSERT INTO {0} ({1}) VALUES ({2}); ", tableName, string.Join(",", columnNames), string.Join(",", values));
                }
                else
                {
                    sb.AppendFormat("INSERT INTO {0} DEFAULT VALUES; ", tableName);
                }
            }

            db.Execute(sb.ToString());
        }
 public bool CheckCanExecute(DAL database)
 {
     long numDups = (long)database.ExecuteScalar(
         @"SELECT count(1) FROM (
             SELECT * FROM (
                 SELECT count(1) as cnt FROM
                 CountTree
                 GROUP BY CuttingUnit_CN, SampleGroup_CN, ifnull(TreeDefaultValue_CN,0), ifnull(Component_CN,0)
             )
             WHERE cnt > 1
         );");
     return numDups > 0;
 }
        public SaveTreesWorker(DAL datastore, ICollection<TreeVM> trees)
        {
            Debug.Assert(datastore != null);
            Debug.Assert(trees != null);

            _datastore = datastore;
            lock (((System.Collections.ICollection)trees).SyncRoot)
            {
                //create a local copy of tree collection
                TreeVM[] a = new TreeVM[trees.Count];
                trees.CopyTo(a, 0);
                _trees = a;
            }
        }
        public void Execute(DAL database)
        {
            database.Execute(
                @"BEGIN;

            ALTER TABLE CountTree RENAME TO TempCountTree;

            CREATE TABLE CountTree(
                CountTree_CN INTEGER PRIMARY KEY AUTOINCREMENT,
                SampleGroup_CN INTEGER REFERENCES SampleGroup NOT NULL,
                CuttingUnit_CN INTEGER REFERENCES CuttingUnit NOT NULL,
                Tally_CN INTEGER REFERENCES Tally,
                TreeDefaultValue_CN INTEGER REFERENCES TreeDefaultValue,
                Component_CN INTEGER REFERENCES Component,
                TreeCount INTEGER Default 0,
                SumKPI INTEGER Default 0,
                CreatedBy TEXT NOT NULL,
                CreatedDate DATETIME,
                ModifiedBy TEXT,
                ModifiedDate DATETIME,
                UNIQUE(SampleGroup_CN, CuttingUnit_CN, TreeDefaultValue_CN, Component_CN));

            INSERT INTO CountTree
            (CountTree_CN, SampleGroup_CN, CuttingUnit_CN, Tally_CN, TreeDefaultValue_CN, Component_CN,
            TreeCount, SumKPI,
            CreatedBy, CreatedDate, ModifiedBy, ModifiedDate)
                SELECT CountTree_CN, SampleGroup_CN, CuttingUnit_CN, Tally_CN, TreeDefaultValue_CN, Component_CN,
                Sum(TreeCount), Sum(SumKPI),
                CreatedBy, CreatedDate, ModifiedBy, ModifiedDate
                FROM TempCountTree
                GROUP BY SampleGroup_CN, CuttingUnit_CN,
                ifnull(TreeDefaultValue_CN, 0), ifnull(Component_CN, 0);

            DROP TABLE TempCountTree;

            CREATE TRIGGER OnNewCountTree AFTER INSERT ON CountTree BEGIN
            UPDATE CountTree SET CreatedDate = datetime(current_timestamp, 'localtime') WHERE rowID = new.rowID; END;

            CREATE TRIGGER OnUpdateCountTree UPDATE ON CountTree BEGIN
                        UPDATE CountTree SET ModifiedDate = datetime(current_timestamp, 'localtime') WHERE rowID = new.rowID; END;

            COMMIT;"
                );
        }
        public MergeTableCommandBuilder(DAL masterDB, String clientTableName)
        {
            this.ClientTableName = clientTableName;
            this.MergeTableName = "Merge" + this.ClientTableName;

            this.AllClientColumns = masterDB.GetTableInfo(clientTableName);

            this.ClientGUIDKeyField = (from ColumnInfo ci in this.AllClientColumns
                                       where ci.Name == this.ClientTableName + "_GUID"
                                       select ci).FirstOrDefault();

            this.ClientPrimaryKey = (from ColumnInfo ci in this.AllClientColumns
                                     where ci.IsPK == true
                                     select ci).FirstOrDefault() ?? new ColumnInfo() { Name = "RowID" };

            this.HasRowVersion = this.AllClientColumns.Find(x => x.Name == "RowVersion") != null;

            this.ClientUniqueFieldNames = masterDB.GetTableUniques(clientTableName).ToArray();
            InitializeCommonColumns(this.HasGUIDKey, this.HasRowVersion);
        }
 private void copyTablesToFScruise(DAL cDAL)
 {
     // copy Sale table
      //fsDAL.DirectCopy(cDAL, CruiseDAL.Schema.SALE._NAME, null, OnConflictOption.Ignore);
      //copy CuttingUnit table
      fsDAL.DirectCopy(cDAL, CruiseDAL.Schema.CUTTINGUNIT._NAME, null, OnConflictOption.Fail);
      //copy TreeDefaultValues table
      fsDAL.DirectCopy(cDAL, CruiseDAL.Schema.TREEDEFAULTVALUE._NAME, null, OnConflictOption.Ignore);
      //copy logfieldsetupdefault table
      fsDAL.DirectCopy(cDAL, CruiseDAL.Schema.LOGFIELDSETUPDEFAULT._NAME, null, OnConflictOption.Ignore);
      //copy logfieldsetup
     //         fsDAL.DirectCopy(cDAL, CruiseDAL.Schema.LOGFIELDSETUP._NAME, null, OnConflictOption.Ignore);
      //copy messagelog
      fsDAL.DirectCopy(cDAL, CruiseDAL.Schema.MESSAGELOG._NAME, null, OnConflictOption.Ignore);
      //copy reports
      fsDAL.DirectCopy(cDAL, "Reports", null, OnConflictOption.Ignore);
      //copy treefieldsetupdefault
      fsDAL.DirectCopy(cDAL, CruiseDAL.Schema.TREEFIELDSETUPDEFAULT._NAME, null, OnConflictOption.Ignore);
      //copy volumeequations
      fsDAL.DirectCopy(cDAL, CruiseDAL.Schema.VOLUMEEQUATION._NAME, null, OnConflictOption.Ignore);
      //copy treeauditvalue
      fsDAL.DirectCopy(cDAL, CruiseDAL.Schema.TREEAUDITVALUE._NAME, null, OnConflictOption.Ignore);
      //copy treedefaultvaluetreeauditvalue
      fsDAL.DirectCopy(cDAL, CruiseDAL.Schema.TREEDEFAULTVALUETREEAUDITVALUE._NAME, null, OnConflictOption.Ignore);
      //copy tally
      fsDAL.DirectCopy(cDAL, CruiseDAL.Schema.TALLY._NAME, null, OnConflictOption.Ignore);
      //copy Strata
      //fsDAL.DirectCopy(cDAL, CruiseDAL.Schema.STRATUM._NAME, null, OnConflictOption.Ignore);
      //copy cuttingUnitStratum
      //fsDAL.DirectCopy(cDAL, CruiseDAL.Schema.CUTTINGUNITSTRATUM._NAME, null, OnConflictOption.Ignore);
 }
        private void copyStratumToFScruise(DAL cdDAL)
        {
            //loop through design stratum table
             List<StratumDO> myStr = new List<StratumDO>(cdDAL.Read<StratumDO>("Stratum",null,null));
             foreach(StratumDO curStr in myStr)
             {
             // create new stratumDO
            StratumDO fsStr = new StratumDO(fsDAL);
             // copy stratum information
            fsStr.Code = curStr.Code;
            fsStr.Description = curStr.Description;
            fsStr.Method = curStr.Method;
            fsStr.BasalAreaFactor = curStr.BasalAreaFactor;
            fsStr.FixedPlotSize = curStr.FixedPlotSize;
            fsStr.KZ3PPNT = curStr.KZ3PPNT;
            fsStr.YieldComponent = curStr.YieldComponent;
            fsStr.Year = curStr.Year;
            fsStr.Month = curStr.Month;

            fsStr.Save();

             }
        }
        private void copySaleTable(DAL cDAL)
        {
            //mySale = new List<SaleDO>();
             //open sale table
             SaleDO sale = new SaleDO(cDAL.ReadSingleRow<SaleDO>("Sale", null, null));
             SaleDO fsSale = new SaleDO(fsDAL);

             fsSale.Purpose = "Timber Sale";
             fsSale.SaleNumber = sale.SaleNumber;
             fsSale.Name = sale.Name;
             fsSale.Region = sale.Region;
             fsSale.Forest = sale.Forest;
             fsSale.District = sale.District;
             fsSale.DefaultUOM = sale.DefaultUOM;
             fsSale.CalendarYear = sale.CalendarYear;
             fsSale.LogGradingEnabled = sale.LogGradingEnabled;
             fsSale.MeasurementYear = sale.MeasurementYear;
             fsSale.Remarks = sale.Remarks;

             fsSale.Save();

             logData = sale.LogGradingEnabled;

             myMeth = new List<CruiseMethodsDO>(fsDAL.Read<CruiseMethodsDO>("CruiseMethods",null,null));
             if (myMeth.Count() < 4)
             {
            myMeth.Clear();
            for (int i = 0; i < 12; i++)
            {
               CruiseMethodsDO fsMeth = new CruiseMethodsDO(fsDAL);
               addCruiseMethod(fsMeth, i);
               myMeth.Add(fsMeth);
            }
            fsDAL.Save(myMeth);
             }
        }
 public DataObject ReadSingleRow(DAL source, long rowid)
 {
     switch (this.ClientTableName)
     {
         case "Tree":
             {
                 return source.From<TreeDO>().Where("rowid = ?").Query(rowid).FirstOrDefault();
             }
         case "Log":
             {
                 return source.From<LogDO>().Where("rowid = ?").Query(rowid).FirstOrDefault();
             }
         case "Stem":
             {
                 return source.From<StemDO>().Where("rowid = ?").Query(rowid).FirstOrDefault();
             }
         case "Plot":
             {
                 return source.From<PlotDO>().Where("rowid = ?").Query(rowid).FirstOrDefault();
             }
         case "CountTree":
             {
                 return source.From<CountTreeDO>().Where("rowid = ?").Query(rowid).FirstOrDefault();
             }
         case "CuttingUnit":
             {
                 return source.From<CuttingUnitDO>().Where("rowid = ?").Query(rowid).FirstOrDefault();
             }
         case "Stratum":
             {
                 return source.From<StratumDO>().Where("rowid = ?").Query(rowid).FirstOrDefault();
             }
         case "CuttingUnitStratum":
             {
                 return source.From<CuttingUnitStratumDO>().Where("rowid = ?").Query(rowid).FirstOrDefault();
             }
         case "SampleGroup":
             {
                 return source.From<SampleGroupDO>().Where("rowid = ?").Query(rowid).FirstOrDefault();
             }
         case "SampleGroupTreeDefaultValue":
             {
                 return source.From<SampleGroupTreeDefaultValueDO>().Where("rowid = ?").Query(rowid).FirstOrDefault();
             }
         case "TreeDefaultValue":
             {
                 return source.From<TreeDefaultValueDO>().Where("rowid = ?").Query(rowid).FirstOrDefault();
             }
         default:
             {
                 throw new NotImplementedException();
             }
     }
 }
 public CountTreeVM(DAL ds)
     : base(ds)
 {
 }
        private bool openDesignFile()
        {
            //MessageBox.Show("create design file", "Information");

            // create or open DAL
            try
            {
               this.cdDAL = new DAL(dalPathDesign, canCreateNew);
               return (true);
            }
            catch (System.IO.IOException e1)
            {
               Logger.Log.E(e1);
               return (false);
            }
            catch (System.Exception e1)
            {
               Logger.Log.E(e1);
               return (false);
            }
        }
        public void getTreeFieldSetup(DAL cDAL, DAL fsDAL, StratumStatsDO myStStats)
        {
            //select from TreeFieldSetupDefault where method = stratum.method
             List<TreeFieldSetupDefaultDO> treeFieldDefaults = new List<TreeFieldSetupDefaultDO>(cDAL.Read < TreeFieldSetupDefaultDO >("TreeFieldSetupDefault", "WHERE Method = ? ORDER BY FieldOrder", myStStats.Method));
             foreach (TreeFieldSetupDefaultDO tfd in treeFieldDefaults)
             {
            TreeFieldSetupDO tfs = new TreeFieldSetupDO();
            tfs.Stratum_CN = thisStrCN;
            tfs.Field = tfd.Field;
            tfs.FieldOrder = tfd.FieldOrder;
            tfs.ColumnType = tfd.ColumnType;
            tfs.Heading = tfd.Heading;
            tfs.Width = tfd.Width;
            tfs.Format = tfd.Format;
            tfs.Behavior = tfd.Behavior;

            treeFields.Add(tfs);

             }
             fsDAL.Save(treeFields);
        }
        public int getReconData(StratumStatsDO curStrStats, SampleGroupStatsDO curSgStats, DAL rDAL, DAL fsDAL, List<PlotDO> myPlots, List<TreeDO> myTree, List<LogDO> myLogs, long? sampleGroupCN, bool first, int measHit)
        {
            TreeDO fsTree;
             LogDO fsLog;
             long? plotCN = 0;
             var myTreeList = myTree;
             var myLogList = myLogs;
             int treeCnt = 1;

             curStrStats.Stratum.CuttingUnits.Populate();
             curSgStats.TreeDefaultValueStats.Populate();
             // loop through design units
             foreach (CuttingUnitDO curUnit in curStrStats.Stratum.CuttingUnits)
             {
            // get number of plots for stratum and cutting unit
            var myPlotList = (from plt in myPlots
                              where plt.CuttingUnit_CN == curUnit.CuttingUnit_CN
                              select plt).ToList();
            // loop through plots
            foreach (PlotDO curPlot in myPlotList)
            {
               // if first time for stratum, save plots
               plotCN = savePlots(curPlot, curStrStats.Stratum_CN, first);

               foreach (TreeDefaultValueDO curTdv in curSgStats.TreeDefaultValueStats)
               {
                  if (curSgStats.MinDbh > 0 && curSgStats.MaxDbh > 0)
                  {
                     double maxDbh = curSgStats.MaxDbh + 0.0499;
                     double minDbh = curSgStats.MinDbh - 0.0500;
                     myTreeList = (from tcv in myTree
                                       where tcv.SampleGroup.PrimaryProduct == curSgStats.PrimaryProduct
                                       && tcv.Plot_CN == curPlot.Plot_CN
                                       && tcv.Species == curTdv.Species
                                       && tcv.LiveDead == curTdv.LiveDead
                                       && tcv.DBH >= minDbh
                                       && tcv.DBH <= maxDbh
                                       select tcv).ToList();
                  }
                  else
                  {
                     myTreeList = (from tcv in myTree
                                       where tcv.SampleGroup.PrimaryProduct == curSgStats.PrimaryProduct
                                       && tcv.Plot_CN == curPlot.Plot_CN
                                       && tcv.Species == curTdv.Species
                                       && tcv.LiveDead == curTdv.LiveDead
                                       select tcv).ToList();
                  }

                  foreach (TreeDO rTree in myTreeList)
                  {
                     fsTree = new TreeDO(fsDAL);
                     fsTree.Stratum_CN = thisStrCN;
                     fsTree.TreeDefaultValue_CN = curTdv.TreeDefaultValue_CN;
                     fsTree.SampleGroup_CN = sampleGroupCN;
                     fsTree.Plot_CN = plotCN;
                     fsTree.CuttingUnit_CN = curUnit.CuttingUnit_CN;
                     fsTree.TreeNumber = rTree.TreeNumber;
                     fsTree.Species = rTree.Species;
                     if (curStrStats.Method == "PCM" || curStrStats.Method == "FCM")
                     {
                        if (radioButton1.Checked)
                        {
                           // use frequency
                           // check hit
                           if (treeCnt == measHit)
                           {
                              fsTree.CountOrMeasure = "M";
                              measHit += (int)curSgStats.SamplingFrequency;
                           }
                           else
                              fsTree.CountOrMeasure = "C";

                        }
                        else if (radioButton2.Checked)
                        {
                           fsTree.CountOrMeasure = "C";
                        }
                        else
                           fsTree.CountOrMeasure = "M";
                     }
                     else
                        fsTree.CountOrMeasure = rTree.CountOrMeasure;
                     treeCnt++;
                     fsTree.TreeCount = 1;
                     fsTree.SeenDefectPrimary = rTree.SeenDefectPrimary;
                     fsTree.SeenDefectSecondary = rTree.SeenDefectSecondary;
                     fsTree.RecoverablePrimary = rTree.RecoverablePrimary;
                     fsTree.Initials = rTree.Initials;
                     fsTree.LiveDead = rTree.LiveDead;
                     fsTree.Grade = rTree.Grade;
                     fsTree.HeightToFirstLiveLimb = rTree.HeightToFirstLiveLimb;
                     fsTree.DBH = rTree.DBH;
                     fsTree.DRC = rTree.DRC;
                     fsTree.TotalHeight = rTree.TotalHeight;
                     fsTree.MerchHeightPrimary = rTree.MerchHeightPrimary;
                     fsTree.MerchHeightSecondary = rTree.MerchHeightSecondary;
                     fsTree.FormClass = rTree.FormClass;
                     fsTree.UpperStemHeight = rTree.UpperStemHeight;
                     fsTree.TopDIBPrimary = rTree.TopDIBPrimary;
                     fsTree.TopDIBSecondary = rTree.TopDIBSecondary;
                     //fsTree.CreatedBy = rTree.CreatedBy;
                     //fsTree.CreatedDate = rTree.CreatedDate;

                     fsTree.Save();
                     // save logs
                     myLogList = (from lcv in myLogs
                                  where lcv.Tree_CN == rTree.Tree_CN
                                  select lcv).ToList();

                     foreach (LogDO rLog in myLogList)
                     {
                        fsLog = new LogDO(fsDAL);
                        fsLog.Tree_CN = rLog.Tree_CN;
                        fsLog.LogNumber = rLog.LogNumber;
                        fsLog.Grade = rLog.Grade;
                        fsLog.SeenDefect = rLog.SeenDefect;
                        fsLog.PercentRecoverable = rLog.PercentRecoverable;
                        fsLog.Length = rLog.Length;
                        fsLog.ExportGrade = rLog.ExportGrade;
                        fsLog.SmallEndDiameter = rLog.SmallEndDiameter;
                        fsLog.LargeEndDiameter = rLog.LargeEndDiameter;
                        fsLog.GrossBoardFoot = rLog.GrossBoardFoot;
                        fsLog.NetBoardFoot = rLog.NetBoardFoot;
                        fsLog.GrossCubicFoot = rLog.GrossCubicFoot;
                        fsLog.NetCubicFoot = rLog.NetCubicFoot;
                        fsLog.DIBClass = rLog.DIBClass;
                        fsLog.BarkThickness = rLog.BarkThickness;
                        fsLog.Save();
                    }
                  }
               }
            }
             }
             return (0);
        }
        public void getLogFieldSetup(DAL cDAL, DAL fsDAL, StratumStatsDO myStStats)
        {
            List<LogFieldSetupDefaultDO> logFieldDefaults = new List<LogFieldSetupDefaultDO>(cDAL.Read<LogFieldSetupDefaultDO>("LogFieldSetupDefault", null, null));
             foreach (LogFieldSetupDefaultDO lfd in logFieldDefaults)
             {
            LogFieldSetupDO lfs = new LogFieldSetupDO();
            lfs.Stratum_CN = thisStrCN;
            lfs.Field = lfd.Field;
            lfs.FieldOrder = lfd.FieldOrder;
            lfs.ColumnType = lfd.ColumnType;
            lfs.Heading = lfd.Heading;
            lfs.Width = lfd.Width;
            lfs.Format = lfd.Format;
            lfs.Behavior = lfd.Behavior;

            logFields.Add(lfs);
             }
             fsDAL.Save(logFields);
        }
 public TallyVM(DAL db)
     : base(db)
 {
 }
 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;
     }
 }
Example #20
0
 public PlotVM(DAL dal)
     : base(dal)
 {
 }
 public DesignEditorStratum(DAL db)
     : base(db)
 {
 }
Example #22
0
 public TreeVM(DAL dal)
     : base((DatastoreRedux)dal)
 {
 }
        public void GoToHistPage()
        {
            // If from UnitPage - get new currentStratumStats
             currentStratumStats = (cdDAL.ReadSingleRow<StratumStatsDO>("StratumStats", "WHERE Stratum_CN = ? AND SgSet = 1", currentStratum.Stratum_CN));

             if (currentStratumStats != null)
             {
            // data already exists for stratum, delete stratum and continue?
            MessageBox.Show("Stratum data already exists for this stratum","Information");
            return;

             }

             currentStratumStats = new StratumStatsDO(cdDAL);
             currentStratumStats.Stratum = currentStratum;
             currentStratumStats.Code = currentStratum.Code;
             currentStratumStats.Description = currentStratum.Description;
             currentStratumStats.SgSet = 1;
             currentStratumStats.SgSetDescription = "";

             float totalAcres = 0;
             foreach (CuttingUnitDO cu in currentStratum.CuttingUnits)
             {
            float acres = cu.Area;
            totalAcres += acres;
             }
             currentStratumStats.TotalAcres = totalAcres;
            //         Owner.currentStratumStats.Save();

             if (openFileDialog1.ShowDialog() == DialogResult.OK)
             {
            histFile = openFileDialog1.FileName;
            //set title bar with file name
            histPage.textBoxFile.Text = openFileDialog1.SafeFileName;
            //open new cruise DAL
            if (histFile.Length > 0)
            {
               try
               {
                  hDAL = new DAL(histFile);
               }
               catch (System.IO.IOException ie)
               {
                  Logger.Log.E(ie);
               }
               catch (System.Exception ie)
               {
                  Logger.Log.E(ie);
               }
            }
            else
            {
               return;
            }

            Sale = new SaleDO(hDAL.ReadSingleRow<SaleDO>("Sale", null, null));
            string sUOM = Sale.DefaultUOM;
            if (sUOM != UOM)
            {
               MessageBox.Show("Cruise does not have same UOM.\nCannot import data.", "Warning");
               return;
            }

            //set binding list for stratum
            histStratum = new BindingList<StratumDO>(hDAL.Read<StratumDO>("Stratum", null, null));
            histPage.bindingSourceStratum.DataSource = histStratum;

            pageHost2.Display(histPage);
             }
        }
        private static string GetLastMergeDate(DAL dataBase)
        {
            //GlobalsDO globalData = dataBase.ReadSingleRow<GlobalsDO>("Globals", "WHERE Block = 'Comp' AND Key = 'LastMerge'");

            //if (globalData != null)
            //{
            //    return globalData.Value;
            //}
            return string.Empty;
        }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            dataFiles holdDF;

             holdDF = (dataFiles)e.Argument;

             //getStats.getPopulationStats(holdDF.rFile, holdDF.cdFile, holdDF.reconExists, err);

             fsDAL = new DAL(holdDF.pFile, true);

             if (holdDF.recData)
            rDAL = new DAL(holdDF.rFile, false);

             copyTablesToFScruise(holdDF.cdDAL1);

             copyStratumToFScruise(holdDF.cdDAL1);

             copyCuttingUnitStrToFScruise(holdDF.cdDAL1);

             copyPopulations(holdDF.cdDAL1, rDAL, fsDAL, holdDF.recData, holdDF.strCode);

             copySaleTable(holdDF.cdDAL1);

             //checkContrSpecies(fsDAL);
        }
 public StratumVM(DAL db)
     : base(db)
 {
 }
        public void getProductionStats(DAL cDAL, int err)
        {
            cdDAL = cDAL;

             // set up StratumStats, SampleGroupStats

             // get stratum definitions
             stratum = new List<StratumDO>(cdDAL.Read<StratumDO>("Stratum", null, null));
             removePopulations();

             // loop through stratum
             foreach (StratumDO curStr in stratum)
             {

            getPopulations(curStr);

             }
        }
 private void checkContrSpecies(DAL fsDAL)
 {
     List<TreeDefaultValueDO> treeDV = new List<TreeDefaultValueDO>(fsDAL.Read<TreeDefaultValueDO>("TreeDefaultValue", null, null));
      foreach (TreeDefaultValueDO tdv in treeDV)
      {
     if (tdv.ContractSpecies == null || tdv.ContractSpecies == "")
     {
        tdv.ContractSpecies = tdv.Species;
        tdv.Save();
     }
      }
 }
        private bool checkProcessedFile(DAL pDAL)
        {
            // get LCD file
             List<LCDDO> selectedLCD = pDAL.Read<LCDDO>("LCD", null, null);

             // if NULL, return false
             if (selectedLCD.Count == 0)
            return (false);

             // else, return true
             return (true);
        }
        private void copyCuttingUnitStrToFScruise(DAL cdDAL)
        {
            StratumDO cdStr;
             List<StratumDO> myStr = new List<StratumDO>(fsDAL.Read<StratumDO>("Stratum",null,null));
             foreach(StratumDO curStr in myStr)
             {
            cdStr = cdDAL.ReadSingleRow<StratumDO>("Stratum", "Where Code = ?", curStr.Code);
            cdStr.CuttingUnits.Populate();

            foreach (CuttingUnitDO myUnit in cdStr.CuttingUnits)
            {
               CuttingUnitStratumDO custr = new CuttingUnitStratumDO(fsDAL);
               custr.CuttingUnit_CN = myUnit.CuttingUnit_CN;
               custr.Stratum_CN = curStr.Stratum_CN;

               custr.Save();
            }
             }
        }
 private static void SetLastMergeDate(DAL db, string dateStr)
 {
     GlobalsDO data = new GlobalsDO(db)
     {
         Block = "Comp",
         Key = "LastMerge",
         Value = dateStr
     };
     data.Save(FMSC.ORM.Core.SQL.OnConflictOption.Replace);
 }
        private void copyPopulations(DAL cDAL, DAL rDAL, DAL fsDAL, bool reconData, string[] stRecCode)
        {
            StratumDO cdStr;
             TreeDefaultValueDO currentTDV = new TreeDefaultValueDO();
             List<StratumStatsDO> cdStratumStats = new List<StratumStatsDO>(cDAL.Read<StratumStatsDO>("StratumStats", "JOIN Stratum ON StratumStats.Stratum_CN = Stratum.Stratum_CN AND StratumStats.Method = Stratum.Method AND StratumStats.Used = 1 ORDER BY Stratum.Code", null));

             List<PlotDO> myPlots = new List<PlotDO>();
             List<TreeDO> myTree = new List<TreeDO>();
             List<LogDO> myLogs = new List<LogDO>();
             treeFields = new BindingList<TreeFieldSetupDO>();
             logFields = new BindingList<LogFieldSetupDO>();
             bool first;
             string method = "";
             Random rnd = new Random();
             int measHit;

             foreach (StratumStatsDO myStStats in cdStratumStats)
             {
            setRecData = false;
            first = true;

            // check if recon data is to be saved
            cdStr = fsDAL.ReadSingleRow<StratumDO>("Stratum", "Where Code = ?", myStStats.Code);
            string strCode = myStStats.Code;
            thisStrCN = (long)cdStr.Stratum_CN;
            if (reconData)
            {

               if (myStStats.Method == "PNT" || myStStats.Method == "PCM")
                  method = "PNT";
               else if (myStStats.Method == "FIX" || myStStats.Method == "FCM")
                  method = "FIX";

               foreach (string stRec in stRecCode)
               {
                  if (stRec == strCode)
                  {
                     setRecData = true;
                     myPlots = (rDAL.Read<PlotDO>("Plot", "JOIN Stratum ON Plot.Stratum_CN = Stratum.Stratum_CN WHERE Stratum.Method = ?", method));
                     if(myTree.Count == 0)
                     {
                        myTree = (rDAL.Read<TreeDO>("Tree", null, null));
                        myLogs = (rDAL.Read<LogDO>("Log", null, null));
                     }
                  }
               }
            }
               // get fsDAl stratum record
            List<SampleGroupStatsDO> mySgStats = new List<SampleGroupStatsDO>(cDAL.Read<SampleGroupStatsDO>("SampleGroupStats", "Where StratumStats_CN = ?", myStStats.StratumStats_CN));
               // loop through sample groups
            foreach (SampleGroupStatsDO sgStats in mySgStats)
            {
               measHit = 0;
               SampleGroupDO fsSg = new SampleGroupDO(fsDAL);
               // save sample group information
               fsSg.Stratum_CN = thisStrCN;
               fsSg.Code = sgStats.Code;
               fsSg.Description = sgStats.Description;
               fsSg.CutLeave = sgStats.CutLeave;
               fsSg.UOM = sgStats.UOM;
               fsSg.PrimaryProduct = sgStats.PrimaryProduct;
               fsSg.SecondaryProduct = sgStats.SecondaryProduct;
               fsSg.DefaultLiveDead = sgStats.DefaultLiveDead;
               fsSg.KZ = sgStats.KZ;
               fsSg.InsuranceFrequency = sgStats.InsuranceFrequency;
               if (myStStats.Method == "PCM" || myStStats.Method == "FCM")
               {
                  if (radioButton1.Checked)
                  {
                     fsSg.SamplingFrequency = sgStats.SamplingFrequency;
                     // find random start
                     int freq = (int)fsSg.SamplingFrequency;
                     measHit = rnd.Next(1, freq);
                     fsSg.BigBAF = 0;
                     fsSg.SmallFPS = 0;
                  }
                  else
                  {
                     fsSg.SamplingFrequency = 0;
                     fsSg.BigBAF = Convert.ToInt32(sgStats.BigBAF);
                     fsSg.SmallFPS = Convert.ToInt32(sgStats.BigFIX);
                  }
               }
               else
               {
                  fsSg.SamplingFrequency = sgStats.SamplingFrequency;
                  fsSg.BigBAF = 0;
                  fsSg.SmallFPS = 0;
               }
               // find treedefaultvalues
               sgStats.TreeDefaultValueStats.Populate();
               foreach (TreeDefaultValueDO tdv in sgStats.TreeDefaultValueStats)
               {
                  fsSg.TreeDefaultValues.Add(tdv);
               }
               fsSg.Save();
               fsSg.TreeDefaultValues.Save();
               // if recon can be saved
               if (setRecData)
               {
                  getReconData(myStStats, sgStats, rDAL, fsDAL, myPlots, myTree, myLogs, fsSg.SampleGroup_CN, first, measHit);
                 first = false;
               }
            }

            getTreeFieldSetup(cDAL,fsDAL,myStStats);
            if(logData)
               getLogFieldSetup(cDAL,fsDAL,myStStats);
             }
        }