Exemple #1
0
        public static void RecursiveDelete(CuttingUnitDO unit)
        {
            var    dal           = unit.DAL;
            string commandFormat =
                @"Delete From CuttingUnitStratum WHERE CuttingUnit_CN = {0};
DELETE FROM Log WHERE EXISTS (SELECT 1 FROM Tree WHERE Tree.Tree_CN = Log.Tree_CN AND Tree.CuttingUnit_CN = {0});
DELETE FROM LogStock WHERE EXISTS (SELECT 1 FROM Tree WHERE Tree.Tree_CN = LogStock.Tree_CN AND Tree.CuttingUnit_CN = {0});
DELETE FROM TreeCalculatedValues WHERE EXISTS (SELECT 1 FROM Tree WHERE Tree.Tree_CN = TreeCalculatedValues.Tree_CN AND Tree.CuttingUnit_CN = {0});
DELETE FROM Tree WHERE CuttingUnit_CN = {0};
DELETE FROM Plot WHERE CuttingUnit_CN = {0};
DELETE FROM CountTree WHERE CuttingUnit_CN = {0};";

            dal.BeginTransaction();
            try
            {
                dal.Execute(String.Format(commandFormat, unit.CuttingUnit_CN));
                unit.Delete();

                dal.CommitTransaction();
            }
            catch (Exception e)
            {
                dal.RollbackTransaction();
                throw e;
            }
        }
        public void ReadCountsTest()
        {
            IWindowPresenter wp = new WindowPresenterStub() { Database = new CruiseDAL.DAL(readTestFile) };
            PrivateObject param0 = new PrivateObject( new DataEditorView(wp));
            DataEditorView_Accessor target = new DataEditorView_Accessor(param0);

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

            List<CountTreeDO> expected = null; // TODO: Initialize to an appropriate value
            List<CountTreeDO> actual;
            actual = target.ReadCounts(cu, st, sg);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
 public void DeleteCuttingUnit(CuttingUnitDO cu)
 {
     if (cu.IsPersisted)
     {
         CuttingUnitDO.RecursiveDelete(cu);
     }
 }
        public void ReadLogsTest()
        {
            IWindowPresenter wp = new WindowPresenterStub() { Database = new CruiseDAL.DAL(readTestFile) };
            PrivateObject param0 = new PrivateObject(new DataEditorView(wp));
            DataEditorView_Accessor target = new DataEditorView_Accessor(param0);

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

            List<LogVM> actual;
            actual = target.ReadLogs(cu, st, sg, tdv);

            Assert.Inconclusive("Verify the correctness of this test method.");
        }
        public void ReadTreesTest()
        {
            IWindowPresenter wp = new WindowPresenterStub() { Database = new CruiseDAL.DAL(readTestFile) };
            PrivateObject param0 = new PrivateObject(new DataEditorView(wp));
            DataEditorView_Accessor target = new DataEditorView_Accessor(param0);

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

            List<TreeVM> actual;
            actual = target.ReadTrees(cu, st, sg, tdv);

            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.Count > 0);
        }
 public bool CanEditCuttingUnitField(CuttingUnitDO unit, String fieldName)
 {
     if (unit.IsPersisted == false) { return true; }
     if (HasCruiseData(unit) == false) { return true; }
     if (IsSupervisor == true) { return true; }
     if (Strings.EDITABLE_UNIT_FILEDS.Contains(fieldName)) { return true; }
     return false;
 }
 private void buttonAddUnit_Click(object sender, EventArgs e)
 {
     CuttingUnitDO newUnit = new CuttingUnitDO(Owner.cdDAL);
        Owner.cdCuttingUnits.Add(newUnit);
        bindingSourceUnit.DataSource = Owner.cdCuttingUnits;
 }
		public CuttingUnitDO(CuttingUnitDO obj) : this()
		{
		    SetValues(obj);
		}
 protected List<LogVM> ReadLogs(CuttingUnitDO cu, StratumDO st, SampleGroupDO sg, TreeDefaultValueDO tdv)
 {
     var selectionList = new List<string>();
     var selectionArgs = new List<string>();
     if (cu != null)
     {
         selectionList.Add(String.Format("Tree.{0} = ?", CruiseDAL.Schema.TREE.CUTTINGUNIT_CN));
         selectionArgs.Add(cu.CuttingUnit_CN.ToString());
     }
     if (st != null)
     {
         selectionList.Add(String.Format("Tree.{0} = ?", CruiseDAL.Schema.TREE.STRATUM_CN));
         selectionArgs.Add(st.Stratum_CN.ToString());
     }
     if (sg != null)
     {
         selectionList.Add(String.Format("Tree.{0} = ?", CruiseDAL.Schema.TREE.SAMPLEGROUP_CN));
         selectionArgs.Add(sg.SampleGroup_CN.ToString());
     }
     if (tdv != null)
     {
         selectionList.Add(String.Format("Tree.{0} = ?", CruiseDAL.Schema.TREE.TREEDEFAULTVALUE_CN));
         selectionArgs.Add(tdv.TreeDefaultValue_CN.ToString());
     }
     if (selectionList.Count > 0)
     {
         String selection = "WHERE " + String.Join(" AND ", selectionList.ToArray());
         //return DAL.Read<LogDO>(CruiseDAL.Schema.LOG._NAME, "INNER JOIN Tree USING Tree_CN " + selection, selectionArgs.ToArray());
         return Database.Read<LogVM>(CruiseDAL.Schema.LOG._NAME, selection, selectionArgs.ToArray());//since we are using LogVM we don't need to join tree, it already joins Tree
     }
     else
     {
         return Database.Read<LogVM>(CruiseDAL.Schema.LOG._NAME, null, null);
     }
 }
        protected List<CountTreeDO> ReadCounts(CuttingUnitDO cu, StratumDO st, SampleGroupDO sg)
        {
            var selectionList = new List<string>();
            var selectionArgs = new List<string>();
            if (cu != null)
            {
                selectionList.Add(String.Format("CountTree.{0} = ?", CruiseDAL.Schema.COUNTTREE.CUTTINGUNIT_CN));
                selectionArgs.Add(cu.CuttingUnit_CN.ToString());
            }
            if (st != null)
            {
                selectionList.Add(String.Format("SampleGroup.{0} = ?", CruiseDAL.Schema.SAMPLEGROUP.STRATUM_CN));
                selectionArgs.Add(st.Stratum_CN.ToString());
            }
            if (sg != null)
            {
                selectionList.Add(String.Format("CountTree.{0} = ?", CruiseDAL.Schema.COUNTTREE.SAMPLEGROUP_CN));
                selectionArgs.Add(sg.SampleGroup_CN.ToString());
            }

            if (selectionList.Count > 0)
            {
                String selection = String.Join(" AND ", selectionList.ToArray());
                return Database.Read<CountTreeDO>(CruiseDAL.Schema.COUNTTREE._NAME, "JOIN SampleGroup ON CountTree.SampleGroup_CN = SampleGroup.SampleGroup_CN WHERE " + selection, selectionArgs.ToArray());
            }
            else
            {
                return Database.Read<CountTreeDO>(CruiseDAL.Schema.COUNTTREE._NAME, null, null);
            }
        }
        protected void LoadDesignData()
        {
            this.DataContext = new DesignEditorDataContext();

            this.View.ShowWaitCursor();

            try
            {
                //initialize sale
                DataContext.Sale = Database.From<SaleVM>()
                    .Read().FirstOrDefault() ?? new SaleVM(Database);

                //initialize cuttingunits
                var units = Database.From<CuttingUnitDO>()
                    .Read().ToList();

                foreach (CuttingUnitDO cu in units)
                {
                    cu.Strata.Populate();
                }
                DataContext.AllCuttingUnits = new BindingList<CuttingUnitDO>(units);
                DataContext.CuttingUnits = new BindingList<CuttingUnitDO>(units);

                BindingList<CuttingUnitDO> filterUnits = new BindingList<CuttingUnitDO>(units.ToList());
                _anyUnitOption = new CuttingUnitDO();
                _anyUnitOption.Code = "ANY";
                filterUnits.Insert(0, _anyUnitOption);
                DataContext.CuttingUnitFilterSelectionList = filterUnits;

                //initialize strata
                var strata = Database.From<DesignEditorStratum>()
                    .Read().ToList();

                foreach (StratumDO st in strata)
                {
                    st.CuttingUnits.Populate();
                }
                DataContext.AllStrata = new BindingList<DesignEditorStratum>(strata);
                DataContext.Strata = new BindingList<DesignEditorStratum>(strata);

                BindingList<DesignEditorStratum> filterStrata = new BindingList<DesignEditorStratum>(strata.ToList());
                _anyStratumOption = new DesignEditorStratum();
                _anyStratumOption.Code = "ANY";
                filterStrata.Insert(0, _anyStratumOption);
                DataContext.StrataFilterSelectionList = filterStrata;

                //initialize TreeDefault
                var tdvList = Database.From<TreeDefaultValueDO>()
                    .Read().ToList();

                DataContext.AllTreeDefaults = new BindingList<TreeDefaultValueDO>(tdvList);

                //initialize sample groups
                List<SampleGroupDO> sampleGroups = Database.From<SampleGroupDO>()
                    .Read().ToList();

                DataContext.AllSampleGroups = new BindingList<SampleGroupDO>(sampleGroups);
                DataContext.SampleGroups = new BindingList<SampleGroupDO>(sampleGroups);

                foreach (SampleGroupDO sg in DataContext.AllSampleGroups)
                {
                    sg.TreeDefaultValues.Populate();
                }

                DataContext.HasUnsavedChanges = false;
            }
            finally
            {
                this.View.ShowDefaultCursor();
            }
        }
 public bool HasCruiseData(CuttingUnitDO unit)
 {
     if (unit.CuttingUnit_CN == null) { return false; }
     return (Database.GetRowCount("Tree", "WHERE CuttingUnit_CN = ?", unit.CuttingUnit_CN.Value) > 0)
         || (Database.GetRowCount("CountTree", "WHERE CuttingUnit_CN = ? AND TreeCount > 0", unit.CuttingUnit_CN.Value) > 0);
 }
 public CuttingUnitDO GetNewCuttingUnit()
 {
     if (DataContext.AllCuttingUnits == null) { return null; }
     CuttingUnitDO newUnit = new CuttingUnitDO(this.Database);
     DataContext.AllCuttingUnits.Add(newUnit);
     //Data.CuttingUnits.Add(newUnit);
     DataContext.OnDataModified();
     //newUnit.DAL = Database;
     return newUnit;
 }
 public void FilterStrata(CuttingUnitDO filterBy)
 {
     if (DataContext.AllStrata == null) { return; }
     if (filterBy.Code != "ANY")
     {
         var strata = (from st in DataContext.AllStrata
                       where st.CuttingUnits.Contains(filterBy)
                       select st).ToList();
         DataContext.Strata = new BindingList<DesignEditorStratum>(strata);
     }
     else
     {
         DataContext.Strata = DataContext.AllStrata;
     }
     View.UpdateStrata(DataContext.Strata);
 }
        public void DeleteCuttingUnit(CuttingUnitDO unit)
        {
            System.Diagnostics.Debug.Assert(DataContext != null);

            if (!CanEditCuttingUnitField(unit, null))
            {
                throw new UserFacingException("Can not delete unit because it contains cruise data", null);
            }

            DataContext.CuttingUnits.Remove(unit);
            DataContext.AllCuttingUnits.Remove(unit);
            DataContext.DeletedCuttingUnits.Add(unit);

            DataContext.CuttingUnitFilterSelectionList.Remove(unit);
        }
 public CuttingUnitDO GetNewCuttingUnit()
 {
     CuttingUnitDO unit = new CuttingUnitDO(this._database);
     return unit;
 }
        protected List<PlotDO> ReadPlots(CuttingUnitDO cu, StratumDO st)
        {
            var selectionList = new List<string>();
            var selectionArgs = new List<string>();
            if (cu != null)
            {
                selectionList.Add(String.Format("{0} = ?", CruiseDAL.Schema.TREE.CUTTINGUNIT_CN));
                selectionArgs.Add(cu.CuttingUnit_CN.ToString());
            }
            if (st != null)
            {
                selectionList.Add(String.Format("{0} = ?", CruiseDAL.Schema.TREE.STRATUM_CN));
                selectionArgs.Add(st.Stratum_CN.ToString());
            }

            if (selectionList.Count > 0)
            {
                String selection = "WHERE " + String.Join(" AND ", selectionList.ToArray());
                return Database.Read<PlotDO>(CruiseDAL.Schema.PLOT._NAME, selection, selectionArgs.ToArray());
            }
            else
            {
                return Database.Read<PlotDO>(CruiseDAL.Schema.PLOT._NAME, null, null);
            }
        }
        protected List<TreeVM> ReadTrees(CuttingUnitDO cu, StratumDO st, SampleGroupDO sg, TreeDefaultValueDO tdv)
        {
            var selectionList = new List<string>();
            var selectionArgs = new List<string>();
            if (cu != null)
            {
                selectionList.Add(CruiseDAL.Schema.TREE.CUTTINGUNIT_CN + " = ?");
                selectionArgs.Add(cu.CuttingUnit_CN.ToString());
            }
            if (st != null)
            {
                selectionList.Add("Tree." + CruiseDAL.Schema.TREE.STRATUM_CN + " = ?");
                selectionArgs.Add(st.Stratum_CN.ToString());
            }
            if (sg != null)
            {
                selectionList.Add(CruiseDAL.Schema.TREE.SAMPLEGROUP_CN + " = ?");
                selectionArgs.Add(sg.SampleGroup_CN.ToString());
            }
            if (tdv != null)
            {
                selectionList.Add(CruiseDAL.Schema.TREE.TREEDEFAULTVALUE_CN + " = ?");
                selectionArgs.Add(tdv.TreeDefaultValue_CN.ToString());
            }

            if (selectionList.Count > 0)
            {
                String selection = "WHERE " + String.Join(" AND ", selectionList.ToArray());
                return Database.Read<TreeVM>(CruiseDAL.Schema.TREE._NAME, selection + " ORDER BY TreeNumber, Plot_CN", selectionArgs.ToArray());
            }
            else
            {
                return Database.Read<TreeVM>(CruiseDAL.Schema.TREE._NAME, "ORDER BY TreeNumber, Plot_CN", null);
            }
        }
		public void SetValues(CuttingUnitDO obj)
		{
			if(obj == null) { return; }
			Code = obj.Code;
			Area = obj.Area;
			Description = obj.Description;
			LoggingMethod = obj.LoggingMethod;
			PaymentUnit = obj.PaymentUnit;
			TallyHistory = obj.TallyHistory;
		}
        private void ResetViewFilters()
        {
            _CuttingUnitFilter = ANY_OPTION_CUTTINGUNIT;
            _stratumFilter = ANY_OPTION_STRATUM;
            _sampleGroupFilter = ANY_OPTION_SAMPLEGROUP;
            _treeDefaultValueFilter = ANY_OPTION_TREEDEFAULT;

            OnCuttingUnitFilterChanged();
            OnStratumFilterChanged();
            PopulateData();
        }
        public void LoadCounts(CuttingUnitDO unit)
        {
            var counts = new List<CountTreeVM>();
            var tallySettings = DAL.From<TallySettingsDO>()
                .Where("SampleGroup_CN = ?")
                .GroupBy("CountTree.SampleGroup_CN", "CountTree.TreeDefaultValue_CN", "CountTree.Tally_CN")
                .Read(SampleGroup_CN);

            foreach (TallySettingsDO ts in tallySettings)
            {
                CountTreeVM count = DAL.From<CountTreeVM>()
                    .Where("CuttingUnit_CN = ? AND SampleGroup_CN = ? AND Tally_CN = ?")
                    .Read(unit.CuttingUnit_CN
                    , ts.SampleGroup_CN
                    , ts.Tally_CN).FirstOrDefault();
                if (count == null)
                {
                    count = new CountTreeVM(DAL);
                    count.CuttingUnit = unit;
                    count.SampleGroup_CN = ts.SampleGroup_CN;
                    count.TreeDefaultValue_CN = ts.TreeDefaultValue_CN;
                    count.Tally_CN = ts.Tally_CN;

                    count.Save();
                }

                count.SampleGroup = this;

                counts.Add(count);
            }

            Counts = counts;
        }
 public void LoadCounts(CuttingUnitDO unit)
 {
     foreach (var sg in SampleGroups)
     {
         sg.LoadCounts(unit);
     }
 }