public void LoadCounts(CuttingUnitDO unit) { foreach (var sg in SampleGroups) { sg.LoadCounts(unit); } }
} // end IsEmpty public static int ValidLogMethod(CuttingUnitDO cudo) { string[] logMethods = new string[33] { "401", "410", "420", "421", "422", "423", "430", "431", "432", "433", "434", "435", "440", "441", "442", "450", "451", "452", "453", "454", "460", "461", "462", "463", "464", "470", "480", "481", "482", "483", "490", "491", "492" }; int iFound = -1; if (cudo.LoggingMethod == "") { return(1); } for (int k = 0; k < 33; k++) { cudo.LoggingMethod = cudo.LoggingMethod.TrimEnd(' '); if (cudo.LoggingMethod.Equals(logMethods[k])) { iFound = k; } } // end for k loop return(iFound); } // end ValidLogMethod
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(); } }
public void LoadCounts(CuttingUnitDO unit) { var counts = new List <CountTree>(); var tallySettings = DAL.From <TallySettings>() .Where("SampleGroup_CN = @p1") .GroupBy("CountTree.SampleGroup_CN", "CountTree.TreeDefaultValue_CN", "CountTree.Tally_CN") .Read(SampleGroup_CN); foreach (TallySettings ts in tallySettings) { CountTree count = DAL.From <CountTree>() .Where("CuttingUnit_CN = @p1 AND SampleGroup_CN = @p2 AND Tally_CN = @p3") .Read(unit.CuttingUnit_CN , ts.SampleGroup_CN , ts.Tally_CN).FirstOrDefault(); if (count == null) { count = new CountTree(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 DeleteCuttingUnit(CuttingUnitDO cu) { if (cu.IsPersisted) { CuttingUnitDO.RecursiveDelete(cu); } }
} // end finishColumnHeaders ////////////////////////////////////////////////////////////////////////// private void LoadAndPrintProrated(StreamWriter strWriteOut, CuttingUnitDO cdo, reportHeaders rh, ref int pageNumb, List <ReportSubtotal> summaryList, IEnumerable <PRODO> proList) { // overloaded to properly print UC5-UC6 // pull distinct species from measured trees in Tree to get species groups for each unit for UC5 // or sample groups for UC6 ArrayList groupsToProcess = new ArrayList(); groupsToProcess = Global.BL.GetJustSpecies("Tree"); foreach (string gtp in groupsToProcess) { // pull data based on strata method and species foreach (StratumDO stratum in cdo.Strata) { currSTcn = (long)stratum.Stratum_CN; switch (stratum.Method) { case "100": // find cut trees and species to process IEnumerable <TreeCalculatedValuesDO> currentGroup = Global.BL.getTreeCalculatedValues((int)stratum.Stratum_CN, (int)cdo.CuttingUnit_CN).Where( tdo => tdo.Tree.Species == gtp && tdo.Tree.SampleGroup.CutLeave == currCL); if (currentGroup.Any()) { SumUpGroups(currentGroup, proList); } break; default: // otherwise data comes from LCD and is NOT expanded IEnumerable <LCDDO> currGroup = Global.BL.getLCDOrdered("WHERE CutLeave = ? AND Stratum = ? ORDER BY ", "Species", currCL, stratum.Code) .Where(delegate(LCDDO l) { return(l.Species == gtp); }); if (currGroup.Any()) { SumUpGroups(currGroup, cdo.Code, proList); } break; } // end switch on method } // end for loop on strata if (numTrees > 0) { // Ready to print line prtFields.Add(""); prtFields.Add(cdo.Code.PadLeft(3, ' ')); prtFields.Add(gtp.PadRight(6, ' ')); WriteCurrentGroup(strWriteOut, rh, ref pageNumb); UpdateSubtotalSummary(gtp, summaryList); UpdateUnitTotal(currentReport); unitSubtotal[0].Value1 = cdo.Code; } // endif something to print -- numTrees is not zero prtFields.Clear(); // reset summation variables numTrees = 0.0; estTrees = 0.0; currTipwood = 0.0; // end foreach loop on species } return; } // end LoadAndPrintProrated
public bool HasCruiseData(CuttingUnitDO unit) { if (unit.CuttingUnit_CN == null) { return(false); } return((Database.GetRowCount("Tree", "WHERE CuttingUnit_CN = @p1", unit.CuttingUnit_CN.Value) > 0) || (Database.GetRowCount("CountTree", "WHERE CuttingUnit_CN = @p1 AND TreeCount > 0", unit.CuttingUnit_CN.Value) > 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); }
private void CuttingUnitBindingSource_CurrentChanged(object sender, EventArgs e) { CuttingUnitDO currentUnit = CuttingUnitBindingSource.Current as CuttingUnitDO; if (currentUnit == null) { this.tableLayoutPanel2.Enabled = false; } else { this.tableLayoutPanel2.Enabled = true; this.CodeTextBox.Focus(); } }
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); }
} // end GetUnitAcres public static ArrayList buildPrintArray(CuttingUnitDO cul, string cruiseName) { ArrayList cutUnitArray = new ArrayList(); cutUnitArray.Add(" "); cutUnitArray.Add(cruiseName.PadRight(5, ' ')); cutUnitArray.Add(cul.Code.PadLeft(3, ' ')); cutUnitArray.Add(Utilities.FormatField(cul.Area, "{0,7:F2}").ToString().PadLeft(7, ' ')); cutUnitArray.Add(cul.Description ?? (" ").PadRight(25, ' ')); cutUnitArray.Add(cul.LoggingMethod ?? (" ").PadRight(3, ' ')); cutUnitArray.Add(cul.PaymentUnit ?? (" ").PadLeft(4, ' ')); return(cutUnitArray); } // end buildPrintArray
} // end GetUnitAcres public static List <string> buildPrintArray(CuttingUnitDO cul, string cruiseName) { List <string> cutUnitArray = new List <string>(); cutUnitArray.Add(" "); cutUnitArray.Add(cruiseName.PadRight(5, ' ')); cutUnitArray.Add(cul.Code.PadLeft(3, ' ')); cutUnitArray.Add(String.Format("{0,7:F2}", cul.Area).PadLeft(7, ' ')); cutUnitArray.Add(cul.Description ?? (" ").PadRight(25, ' ')); cutUnitArray.Add(cul.LoggingMethod ?? (" ").PadRight(3, ' ')); cutUnitArray.Add(cul.PaymentUnit ?? (" ").PadLeft(4, ' ')); return(cutUnitArray); } // end buildPrintArray
} // end ReturnCorrectAcres /* following code is for change to capture stratum acres and needs testing when DAL is updated -- April 2015 * public static double ReturnCorrectAcres(StratumDO cs, CPbusinessLayer bslyr) * { * double strataAcres = 0; * if (cs.Method == "100" || cs.Method == "STR" || * cs.Method == "S3P" || cs.Method == "3P") * return 1.0; * else * { * // pull units for current stratum * List<CuttingUnitStratumDO> justStratum = Global.BL.GetJustStratum(cs.Stratum_CN); * // sum area * strataAcres = justStratum.Sum(j => j.StrataArea); * if (strataAcres == 0) * { * // find acres for all units * strataAcres = unitAcres(justStratum, gbslyr); * return strataAcres; * } * else if (strataAcres > 0) * return strataAcres; * } // endif * return strataAcres; * } // end ReturnCorrectAcres */ public static double unitAcres(List <CuttingUnitStratumDO> justStratum) { double acresSum = 0; foreach (CuttingUnitStratumDO js in justStratum) { CuttingUnitDO cut = Global.BL.getCuttingUnits().FirstOrDefault(c => c.CuttingUnit_CN == js.CuttingUnit_CN); if (cut != null) { acresSum += cut.Area; } } // end foreach loop return(acresSum); } // end unitAcres
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); }
private void SaveUnits() { foreach (CuttingUnitDO unit in DataContext.AllCuttingUnits) { unit.Save(); } foreach (CuttingUnitDO unit in DataContext.DeletedCuttingUnits) { if (unit.IsPersisted) { CuttingUnitDO.RecursiveDelete(unit); } } DataContext.DeletedCuttingUnits.Clear(); }
} // end buildPrintArray // overloaded to build line for payment unit page in A01 report public static ArrayList buildPrintArray(CuttingUnitDO cud, string cruiseName, string currentStratum) { ArrayList currArray = new ArrayList(); currArray.Add(" "); currArray.Add(cruiseName.PadRight(5, ' ')); currArray.Add(cud.Code.PadLeft(3, ' ')); currArray.Add(currentStratum.PadLeft(2, ' ')); if (cud.PaymentUnit == null) { currArray.Add(" "); } else { currArray.Add(cud.PaymentUnit.PadLeft(3, ' ')); } return(currArray); } // buildPrintArray
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 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); }
public void ReadPlotsTest() { 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 plots = target.ReadPlots(cu, st, false); plots.Should().NotBeNullOrEmpty(); } }
public MappingCollectionTest() { testDB = new DAL("MappingCollectionTest" + ".cruise", true); Random rand = new Random(0); List<CuttingUnitDO> units = new List<CuttingUnitDO>(); for (int i = 1; i <= 10; i++) { CuttingUnitDO cu = new CuttingUnitDO(testDB); cu.Code = i.ToString(); cu.Area = rand.Next(9) + 1.0f; cu.Save(); units.Add(cu); } List<StratumDO> strata = new List<StratumDO>(); for (int i = 0; i <= 10; i++) { StratumDO st = new StratumDO(testDB); st.Code = i.ToString(); st.Method = "something"; st.Save(); strata.Add(st); } foreach (CuttingUnitDO cu in units) { for (int i = 0; i < cu.Area; i++) { CuttingUnitStratumDO cust = new CuttingUnitStratumDO(testDB); cust.CuttingUnit_CN = cu.CuttingUnit_CN; cust.Stratum_CN = strata[i].Stratum_CN; cust.Save(); } } testDB.FlushCache(); }
public DAL CreateDataStore(int treesToCreate, int numLogToCreate) { var ds = new DAL(); try { var stratum = new StratumDO() { DAL = ds, Code = "01", Method = "something" }; stratum.Save(); //set up the log fields int counter = 1; var logFieldSetups = CruiseDAL.Schema.LOG._ALL .Select(x => new LogFieldSetupDO() { DAL = ds, Field = x, FieldOrder = counter++, Heading = x, Stratum = stratum }) .ToList(); foreach (var lfs in logFieldSetups) { lfs.Save(); } var cuttingUnit = new CuttingUnitDO() { DAL = ds, Code = "01" }; cuttingUnit.Save(); for (int j = 0; j < treesToCreate; j++) { var tree = new TreeDO() { DAL = ds, CuttingUnit = cuttingUnit, Stratum = stratum, TreeNumber = j + 1 }; tree.Save(); for (int i = 0; i < numLogToCreate; i++) { var log = new LogDO() { DAL = ds, LogNumber = (i + 1).ToString(), Tree = tree, }; log.Save(); } } return(ds); } catch { ds.Dispose(); throw; } }
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 var sampleGroups = Database.From <DesignEditorSampleGroup>() .Read().ToList(); DataContext.AllSampleGroups = new BindingList <DesignEditorSampleGroup>(sampleGroups); DataContext.SampleGroups = new BindingList <DesignEditorSampleGroup>(sampleGroups); foreach (SampleGroupDO sg in DataContext.AllSampleGroups) { sg.TreeDefaultValues.Populate(); } DataContext.HasUnsavedChanges = false; } finally { this.View.ShowDefaultCursor(); } }
} // 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
public CuttingUnitDO GetNewCuttingUnit() { var unit = new CuttingUnitDO(_database); return(unit); }
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); }