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 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); }
public void WriteTest() { DAL dal = new DAL("WriteTest.cruise", true); dal.Create(); SaleDO sale = new SaleDO(dal); sale.SaleNumber = "12345"; sale.Region = "01"; sale.Forest = "02"; sale.Save(); SaleDO saleRead = dal.ReadSingleRow<SaleDO>("Sale", "WHERE SaleNumber = '12345'"); //Assert.IsTrue(object.ReferenceEquals(sale, saleRead)); long saleID = sale.GetID(); long saleReadID = saleRead.GetID(); Assert.True(saleReadID == saleID); //Assert.IsNotNull(saleRead.CreatedDate); //DateTime time; //DateTime.TryParse(saleRead.CreatedDate, out time); //Assert.IsTrue(DateTime.Compare(time.Date, DateTime.Today) == 0); sale.SaleNumber = "54321"; sale.Save(); saleRead = dal.ReadSingleRow<SaleDO>("Sale", "WHERE SaleNumber = '54321'"); //Assert.IsTrue(object.ReferenceEquals(sale, saleRead)); //Assert.IsNotNull(saleRead.ModifiedDate); //DateTime.TryParse(saleRead.ModifiedDate, out time); //Assert.IsTrue(DateTime.Compare(time.Date, DateTime.Today) == 0); }