private void SampleGroups_TDVGridView_SelectionChanging(object sender, FMSC.Controls.SelectionChangingEventArgs e)
 {
     try
     {
         SampleGroupDO      sg  = this.SampleGroupBindingSource.Current as SampleGroupDO;
         TreeDefaultValueDO tdv = e.Item as TreeDefaultValueDO;
         if (e.IsRemoving == false)
         {
             return;
         }                                      // we don't care if they are adding
         if (sg == null || tdv == null)
         {
             e.Cancel = true; return;
         }
         if (!ViewPresenter.CanRemoveTreeDefault(sg, tdv))
         {
             throw new UserFacingException("Can't remove this species because it has tree data or tree counts.", null);
         }
     }
     catch (Exception ex)
     {
         this.ExceptionHandler.Handel(ex);
         e.Cancel = true;
     }
 }
        public void ReadLogsTest()
        {
            using (var ds = new CruiseDAL.DAL(readTestFile))
            {
                var wp            = Mock.Of <WindowPresenter>();
                var appController = Mock.Of <ApplicationControllerBase>();
                var target        = new DataEditorView(wp, appController);

                var cu = new CuttingUnitDO()
                {
                    rowID = 1
                };
                var st = new StratumDO()
                {
                    rowID = 1
                };
                var sg = new SampleGroupDO()
                {
                    rowID = 1
                };
                var tdv = new TreeDefaultValueDO()
                {
                    rowID = 1
                };

                var logs = target.ReadLogs(cu, st, sg, tdv, false);

                logs.Should().NotBeNullOrEmpty();
            }
        }
Beispiel #3
0
        public bool AllSampleGroupValid(out string errorMsg)
        {
            bool allSgValid = true;
            var  errorSB    = new System.Text.StringBuilder();

            errorSB.AppendLine("Sample Group Errors Found");

            foreach (StratumVM st in Strata)
            {
                IList <SampleGroupDO> sgList = st.SampleGroups;

                if (st.SampleGroups.Count() == 0)
                {
                    allSgValid = false;
                    errorSB.AppendLine($"Stratum {st.Code} has no Sample Groups");
                }

                foreach (SampleGroupDO sg in sgList)
                {
                    string error;
                    if (!SampleGroupDO.ValidateSetup(sg, st, out error))
                    {
                        allSgValid = false;
                        errorSB.AppendLine(error);
                    }
                }
            }

            errorMsg = (!allSgValid) ? errorSB.ToString() : null;
            return(allSgValid);
        }
Beispiel #4
0
 bool ShowEditSampleGroup(SampleGroupDO sg, bool allowEdit)
 {
     using (FormEditSampleGroup view = new FormEditSampleGroup())
     {
         return(view.ShowDialog(sg, allowEdit) == DialogResult.OK);
     }
 }
Beispiel #5
0
 public void DeleteSampleGroup(SampleGroupDO sg)
 {
     if (sg.IsPersisted)
     {
         SampleGroupDO.RecutsiveDeleteSampleGroup(sg);
     }
 }
Beispiel #6
0
        private void BuildTDVList(SampleGroupDO sg)
        {
            this._speciesSelectPanel.SuspendLayout();
            this._speciesSelectPanel.Controls.Clear();

            if (sg != null)
            {
                List <TreeDefaultValueDO> treeDefaults = this.Controller.DataStore.From <TreeDefaultValueDO>()
                                                         .Where("PrimaryProduct = ?")
                                                         .Read(sg.PrimaryProduct).ToList();
                foreach (TreeDefaultValueDO tdv in treeDefaults)
                {
                    CheckBox cb = new CheckBox();
                    cb.Dock = DockStyle.Top;
                    cb.Text = String.Format("{0}-{1}",
                                            tdv.Species,
                                            tdv.LiveDead);

                    sg.TreeDefaultValues.Populate();
                    if (sg.TreeDefaultValues.Contains(tdv))
                    {
                        cb.Checked = true;
                    }
                    cb.Tag = tdv;
                    this._speciesSelectPanel.Controls.Add(cb);
                }
            }
            this._speciesSelectPanel.ResumeLayout();
        }
Beispiel #7
0
        protected void SaveSampleGroups(bool tryToSaveAll)
        {
            foreach (StratumVM s in Strata)
            {
                //s.DAL = myDatabase;
                //s.Save();

                //SetFieldSetup(s, myDatabase);

                //s.CuttingUnits.Save();

                //set the strata foreign key on all sample groups and save
                foreach (SampleGroupDO sg in s.SampleGroups)
                {
                    try
                    {
                        sg.Stratum = s;
                        string error;
                        if (!SampleGroupDO.ValidateSetup(sg, s, out error))
                        {
                            continue;
                        }

                        if (sg.Code == "<Blank>")
                        {
                            sg.Code = " ";
                        }
                        if (sg.DAL == null)
                        {
                            sg.DAL = _database;
                        }
                        sg.Save();

                        //ensure all tree defaults in sampleGroup are save to the database
                        foreach (TreeDefaultValueDO tdv in sg.TreeDefaultValues)
                        {
                            if (tdv.IsPersisted == true)
                            {
                                continue;
                            }
                            if (tdv.DAL == null)
                            {
                                tdv.DAL = _database;
                            }                                            //just in case, but should already be set
                            tdv.Save();
                        }

                        sg.TreeDefaultValues.Save();
                    }
                    catch
                    {
                        if (!tryToSaveAll)
                        {
                            throw;
                        }
                    }
                }
            }
        }
Beispiel #8
0
 public bool HasCruiseData(SampleGroupDO sg)
 {
     if (sg.SampleGroup_CN == null)
     {
         return(false);
     }
     return((Database.GetRowCount("Tree", "WHERE SampleGroup_CN = @p1", sg.SampleGroup_CN.Value) > 0) ||
            (Database.GetRowCount("CountTree", "WHERE SampleGroup_CN = @p1 AND TreeCount > 0", sg.SampleGroup_CN.Value) > 0));
 }
Beispiel #9
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);
        }
Beispiel #10
0
        public static string GetDescriptionShort(this SampleGroupDO sampleGroup)
        {
            if (sampleGroup == null)
            {
                return("--");
            }
            string code = (string.IsNullOrEmpty(sampleGroup.Code)) ? "<blank>" : sampleGroup.Code;

            return(sampleGroup.Code + " " + sampleGroup.Description);
        }
Beispiel #11
0
        public bool CanRemoveTreeDefault(SampleGroupDO sampleGroup, TreeDefaultValueDO tdv)
        {
            if (sampleGroup.IsPersisted == false || tdv.IsPersisted == false)
            {
                return(true);
            }
            bool hasTreeCounts = this.Database.GetRowCount("CountTree", "WHERE TreeCount > 0 AND TreeDefaultValue_CN = @p1 AND SampleGroup_CN = @p2", tdv.TreeDefaultValue_CN, sampleGroup.SampleGroup_CN) > 0;
            bool hasTrees      = this.Database.GetRowCount("Tree", "WHERE TreeDefaultValue_CN = @p1 AND SampleGroup_CN = @p2", tdv.TreeDefaultValue_CN, sampleGroup.SampleGroup_CN) > 0;

            return(!(hasTreeCounts || hasTrees));
        }
        private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            SampleGroupDO curSG = CurrentSampleGroup;

            if (curSG == null)
            {
                return;
            }
            SampleGroupBindingSource.Remove(curSG);
            Presenter.DeleteSampleGroup(curSG);
        }
Beispiel #13
0
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);

            if (this.DialogResult == DialogResult.Cancel)
            {
                this.SampleGroup.SetValues(this._initialState);
                return;
            }

            this.EndEdit();
            if (this.AllowEdit)
            {
                if (SampleGroupDO.CanChangeSamplerType(this.SampleGroup) && this._systematicOpt_ChB.Checked)// if systematic option checked, set SampleSelectorType to Systematic
                {
                    this.SampleGroup.SampleSelectorType = CruiseDAL.Schema.CruiseMethods.SYSTEMATIC_SAMPLER_TYPE;
                }
                if (FormEditSampleGroup.CanEditTallyMode(this.SampleGroup))
                {
                    if (this._tallyBySg_RB.Checked)
                    {
                        //TallyMethod = existing tallyMethod - TallyBySpecies + TallyBySampleGroup
                        this.SampleGroup.TallyMethod = (this.SampleGroup.TallyMethod & ~CruiseDAL.Enums.TallyMode.BySpecies)
                                                       | CruiseDAL.Enums.TallyMode.BySampleGroup;
                    }
                    else if (this._tallyBySpecies_RB.Checked)
                    {
                        //TallyMethod = existing tallyMethod - TallyBySampleGroup + TallyBySpecies
                        this.SampleGroup.TallyMethod = (this.SampleGroup.TallyMethod & ~CruiseDAL.Enums.TallyMode.BySampleGroup)
                                                       | CruiseDAL.Enums.TallyMode.BySpecies;
                    }
                }
            }

            this.SampleGroup.Validate();
            if (this.SampleGroup.HasErrors())
            {
                MessageBox.Show(this.SampleGroup.Error);
                e.Cancel = true;
                return;
            }

            try
            {
                this.SampleGroup.Save();
            }
            catch
            {
                MessageBox.Show("Unable to save sample group, make sture values are entered correctly");
                e.Cancel = true;
                return;
            }
        }
Beispiel #14
0
        private void SaveSampleGroups()
        {
            var db = Database;

            foreach (SampleGroupDO sg in DataContext.AllSampleGroups)
            {
                var isNewSg = (sg.IsPersisted == false);
                if (sg.Code == "<blank>")
                {
                    sg.Code = " ";
                }
                sg.Save();
                var sg_cn = sg.SampleGroup_CN.Value;

                var tdvCollection = sg.TreeDefaultValues;

                if (!isNewSg)
                {
                    foreach (var tdv in tdvCollection.ToBeDeleted)
                    {
                        if (tdv.IsPersisted == false)
                        {
                            continue;
                        }

                        var tdv_cn    = tdv.TreeDefaultValue_CN.Value;
                        var treeCount = db.ExecuteScalar <int>("SELECT ifnull(sum(TreeCount), 0) FROM CountTree WHERE SampleGroup_CN = @p1 AND TreeDefaultValue_CN = @p2;",
                                                               sg_cn, tdv_cn);
                        if (treeCount > 0)
                        {
                            throw new UserFacingException($"Could Not Remove Tree Default from Sample Group {sg.Code} because it has tree counts");
                        }
                        else
                        {
                            db.Execute("DELETE FROM CountTree WHERE SampleGroup_CN = @p1 AND TreeDefaultValue_CN =  @p2", sg_cn, tdv_cn);
                        }
                    }
                }

                tdvCollection.Save();
            }

            foreach (SampleGroupDO sg in DataContext.DeletedSampleGroups)
            {
                if (sg.IsPersisted)
                {
                    SampleGroupDO.RecutsiveDeleteSampleGroup(sg);
                }
            }

            DataContext.DeletedSampleGroups.Clear();
        }
Beispiel #15
0
 /// <summary>
 /// gets called when a value gets changed on a sample group
 /// </summary>
 /// <param name="sg"></param>
 /// <param name="propName"></param>
 public void HandleSampleGroupValueChanged(SampleGroupDO sg, string propName)
 {
     if (sg == null)
     {
         return;
     }
     //if value changed was sampling frequency or insurance frequency, reset the sampler state
     if ((propName == CruiseDAL.Schema.SAMPLEGROUP.SAMPLINGFREQUENCY ||
          propName == CruiseDAL.Schema.SAMPLEGROUP.INSURANCEFREQUENCY))
     {
         sg.SampleSelectorState = string.Empty;
     }
 }
Beispiel #16
0
        public DialogResult ShowDialog(SampleGroupDO sampleGroup, bool allowEdit)
        {
            bool isNew = !sampleGroup.IsPersisted;

            this.SampleGroup = sampleGroup;
            this.AllowEdit   = allowEdit;

            //TODO insted of reseting values from initial state could just reread from database
            this._initialState.SetValues(sampleGroup);

            if (isNew)
            {
                this.Text = "New Sample Group";
            }
            else if (allowEdit)
            {
                this.Text = "Edit Sample Group";
            }
            else
            {
                this.Text = "View Sample Group";
            }

            if ((this.SampleGroup.TallyMethod & CruiseDAL.Enums.TallyMode.BySampleGroup) == CruiseDAL.Enums.TallyMode.BySampleGroup)
            {
                this._tallyBySg_RB.Checked = true;
            }
            else if ((this.SampleGroup.TallyMethod & CruiseDAL.Enums.TallyMode.BySpecies) == CruiseDAL.Enums.TallyMode.BySpecies)
            {
                this._tallyBySpecies_RB.Checked = true;
            }
            this._systematicOpt_ChB.Checked = (sampleGroup.SampleSelectorType == CruiseDAL.Schema.CruiseMethods.SYSTEMATIC_SAMPLER_TYPE);
            this._systematicOpt_ChB.Enabled = this._tallyBySg_RB.Enabled = this._tallyBySpecies_RB.Enabled = CanEditTallyMode(sampleGroup);

            //if (isNew || allowEdit)
            //{
            //    StratumDO st = sampleGroup.Stratum;
            //    this._bigBaf_TB.Enabled = SampleGroupDO.CanEnableBigBAF(st);
            //    this._samplingFreq_TB = SampleGroupDO.CanEnableFrequency(st);
            //    this._insuranceFreq_TB.Enabled = SampleGroupDO.CanEnableIFreq(st);
            //    this._kz_TB.Enabled = SampleGroupDO.CanEnableKZ(st);

            //}

            return(base.ShowDialog());
        }
 private void SampleGroupDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex < 0 || e.RowIndex > SampleGroupBindingSource.Count)
     {
         return;
     }
     try
     {
         SampleGroupDO sg = this.SampleGroupBindingSource[e.RowIndex] as SampleGroupDO;
         if (sg == null)
         {
             return;
         }
         String propName = this.SampleGroupDataGridView.Columns[e.ColumnIndex].DataPropertyName;
         this.ViewPresenter.HandleSampleGroupValueChanged(sg, propName);
     }
     catch (ArgumentOutOfRangeException) { }
 }
Beispiel #18
0
        protected void OnAllowEditChanged()
        {
            this._codeTB.Enabled  = _allowEdit;
            this._pProdCB.Enabled = _allowEdit;

            //this._cutLeaveCB.Enabled = _allowEdit;
            //this._defaultLD_CB.Enabled = _allowEdit;
            StratumDO st = this.SampleGroup.Stratum;

            this._bigBaf_TB.Enabled        = _allowEdit && SampleGroupDO.CanEnableBigBAF(st);
            this._kz_TB.Enabled            = _allowEdit && SampleGroupDO.CanEnableKZ(st);
            this._samplingFreq_TB.Enabled  = _allowEdit && SampleGroupDO.CanEnableFrequency(st);
            this._insuranceFreq_TB.Enabled = _allowEdit && SampleGroupDO.CanEnableIFreq(st);

            this._tallyBySg_RB.Enabled      = this._tallyBySpecies_RB.Enabled = _allowEdit && FormEditSampleGroup.CanEditTallyMode(this.SampleGroup);
            this._systematicOpt_ChB.Enabled = _allowEdit && ((this.SampleGroup.Stratum.Method == CruiseDAL.Schema.CruiseMethods.STR) &&
                                                             SampleGroupDO.CanChangeSamplerType(this.SampleGroup));
        }
Beispiel #19
0
        SampleGroupDO CreateNewSampleGroup(StratumDO stratum)
        {
            SampleGroupDO newSG = new SampleGroupDO();

            newSG.DAL     = Controller.DataStore;
            newSG.Stratum = stratum;
            newSG.UOM     = Controller.DataStore.ExecuteScalar("Select DefaultUOM FROM Sale;") as String;
            //newSG.UOM = this.DataStore.ReadSingleRow<SaleDO>("Sale", false, null).DefaultUOM;

            if (ShowEditSampleGroup(newSG, true))
            {
                return(newSG);
            }
            else
            {
                return(null);
            }
        }
Beispiel #20
0
 private static bool CanEditTallyMode(SampleGroupDO sg)
 {
     if (!StratumDO.CanDefineTallys(sg.Stratum))
     {
         return(false);
     }
     if (sg.DAL != null && sg.IsPersisted)
     {
         if (sg.DAL.GetRowCount("Tree", "WHERE SampleGroup_CN = ?", sg.SampleGroup_CN) > 0)
         {
             return(false);
         }
         else if (sg.DAL.GetRowCount("CountTree", "WHERE SampleGroup_CN = ? AND TreeCount > 0", sg.SampleGroup_CN) > 0)
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #21
0
 public bool CanEditSampleGroupField(SampleGroupDO sampleGroup, String fieldName)
 {
     if (sampleGroup.IsPersisted == false)
     {
         return(true);
     }
     if (HasCruiseData(sampleGroup) == false)
     {
         return(true);
     }
     if (IsSupervisor == true)
     {
         return(true);
     }
     if (Strings.EDITABLE_SG_FIELDS.Contains(fieldName))
     {
         return(true);
     }
     return(false);
 }
        }         //  end CheckAllUOMandCutLeave

        public List <string> buildPrintArray(SampleGroupDO sg)
        {
            var sgArray = new List <string>();

            sgArray.Add("");
            sgArray.Add(sg.Stratum.Code.PadLeft(2, ' '));
            sgArray.Add(sg.Code.PadLeft(2, ' '));
            sgArray.Add(String.Format("{0,4:F0}", sg.SamplingFrequency).PadLeft(4, ' '));
            sgArray.Add(String.Format("{0,4:F0}", sg.KZ).PadLeft(4, ' '));
            sgArray.Add(String.Format("{0,4:F0}", sg.BigBAF).PadLeft(4, ' '));
            //sgArray.Add(Utilities.FormatField(sg.SmallFPS, "{0,4:F0}").ToString().PadLeft(4, ' '));
            sgArray.Add("    ");
            if (sg.Description == null)
            {
                sgArray.Add(" ".PadRight(25, ' '));
            }
            else
            {
                sgArray.Add(sg.Description.PadRight(25, ' '));
            }
            return(sgArray);
        } //  end buildPrintArray
Beispiel #23
0
        }         //  end CheckAllUOMandCutLeave

        public static ArrayList buildPrintArray(SampleGroupDO sg)
        {
            ArrayList sgArray = new ArrayList();

            sgArray.Add("");
            sgArray.Add(sg.Stratum.Code.PadLeft(2, ' '));
            sgArray.Add(sg.Code.PadLeft(2, ' '));
            sgArray.Add(Utilities.FormatField(sg.SamplingFrequency, "{0,4:F0}").ToString().PadLeft(4, ' '));
            sgArray.Add(Utilities.FormatField(sg.KZ, "{0,4:F0}").ToString().PadLeft(4, ' '));
            sgArray.Add(Utilities.FormatField(sg.BigBAF, "{0,4:F0}").ToString().PadLeft(4, ' '));
            //sgArray.Add(Utilities.FormatField(sg.SmallFPS, "{0,4:F0}").ToString().PadLeft(4, ' '));
            sgArray.Add("    ");
            if (sg.Description == null)
            {
                sgArray.Add(" ".PadRight(25, ' '));
            }
            else
            {
                sgArray.Add(sg.Description.PadRight(25, ' '));
            }
            return(sgArray);
        } //  end buildPrintArray
Beispiel #24
0
        public SampleGroupDO GetNewSampleGroup(StratumDO stratum, SampleGroupDO newSampleGroup)
        {
            if (newSampleGroup == null)
            {
                newSampleGroup = new SampleGroupDO(_database);
            }

            newSampleGroup.CutLeave        = "C";
            newSampleGroup.DefaultLiveDead = "L";
            newSampleGroup.Code            = "<Blank>";
            newSampleGroup.Stratum         = stratum;

            if (stratum.Method == CruiseDAL.Schema.CruiseMethods.FIXCNT)
            {
                newSampleGroup.UOM = "03";
            }
            else
            {
                newSampleGroup.UOM = Sale.DefaultUOM;
            }

            return(newSampleGroup);
        }
Beispiel #25
0
        public bool HandleSampleGroupChanging(SampleGroupDO newSG)
        {
            if (newSG == null)
            {
                return(false);
            }
            if (SampleGroup != null &&
                SampleGroup.SampleGroup_CN == newSG.SampleGroup_CN)
            {
                return(true);
            }

            if (SampleGroup != null)
            {
#if NetCF
                if (!DialogService.AskYesNo("You are changing the Sample Group of a tree, are you sure you want to do this?"
                                            , "!"
                                            , true))
                {
                    return(false);
                }
#endif

                ((CruiseDatastore)DAL).LogMessage(String.Format("Tree Sample Group Changed (Cu:{0} St:{1} Sg:{2} -> {3} Tdv_CN:{4} T#: {5}",
                                                                CuttingUnit.Code,
                                                                Stratum.Code,
                                                                (SampleGroup != null) ? SampleGroup.Code : "?",
                                                                newSG.Code,
                                                                (TreeDefaultValue != null) ? TreeDefaultValue.TreeDefaultValue_CN.ToString() : "?",
                                                                TreeNumber), "high");
                return(true);
            }
            else
            {
                return(true);
            }
        }
        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);
        }
Beispiel #27
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;
            }
        }
 public DesignEditorSampleGroup(SampleGroupDO sg) : base(sg)
 {
 }
Beispiel #29
0
 public static string GetSampleGroupDescription(this SampleGroupDO sampleGroup)
 {
     return("");
 }
Beispiel #30
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