public void SetFieldSetup(StratumDO stratum, Datastore database) { string setTreeFieldCommand = String.Format("INSERT INTO TreeFieldSetup (Stratum_CN, Field, FieldOrder, ColumnType, Heading, Width, Format, Behavior) " + "Select {0} as Stratum_CN, Field, FieldOrder, ColumnType, Heading, Width, Format, Behavior " + "FROM TreeFieldSetupDefault " + "WHERE Method = '{1}';", stratum.Stratum_CN, stratum.Method); string setLogFieldCommand = String.Format(@"INSERT OR IGNORE INTO LogFieldSetup (Stratum_CN, Field, FieldOrder, ColumnType, Heading, Width, Format, Behavior) Select {0} as Stratum_CN, Field, FieldOrder, ColumnType, Heading, Width, Format, Behavior FROM LogFieldSetupDefault;", stratum.Stratum_CN); database.Execute(setTreeFieldCommand); database.Execute(setLogFieldCommand); }
public static void FixTreeAuditValueFKeyErrors(Datastore db) { if (db.HasForeignKeyErrors("TreeDefaultValueTreeAuditValue")) { db.BeginTransaction(); try { db.Execute("DELETE FROM TreeDefaultValueTreeAuditValue WHERE TreeDefaultValue_CN NOT IN (Select TreeDefaultValue_CN FROM TreeDefaultValue);"); db.Execute("DELETE FROM TreeDefaultValueTreeAuditValue WHERE TreeAuditValue_CN NOT IN (SELECT TreeAuditValue_CN FROM TreeAuditValue);"); db.CommitTransaction(); } catch { db.RollbackTransaction(); } } }
public static bool RecursiveDeletePlot(PlotDO plot) { Datastore dal = plot.DAL; string command = string.Format(@" DELETE FROM LogStock; DELETE FROM TreeCalculatedValues; DELETE FROM Log WHERE EXISTS (SELECT 1 FROM Tree WHERE Tree.Tree_CN = Log.Tree_CN AND Tree.Plot_CN = {0}); DELETE FROM Tree WHERE Plot_CN = {0};", plot.Plot_CN); dal.Execute(command); plot.Delete(); return(true); }
public static void RecursiveDeleteStratum(StratumDO stratum) { Datastore db = stratum.DAL; db.BeginTransaction(); try { string command = String.Format(@"DELETE From CuttingUnitStratum WHERE Stratum_CN = {0}; DELETE FROM Log WHERE Tree_CN IN (SELECT Tree_CN FROM Tree WHERE Tree.Stratum_CN = {0}); DELETE FROM LogStock WHERE Tree_CN IN (SELECT Tree_CN FROM Tree WHERE Tree.Stratum_CN = {0}); DELETE FROM TreeCalculatedValues WHERE Tree_CN IN (SELECT Tree_CN FROM Tree WHERE Tree.Stratum_CN = {0}); DELETE FROM Tree WHERE Stratum_CN = {0}; DELETE FROM Plot WHERE Stratum_CN = {0}; DELETE FROM TreeEstimate WHERE CountTree_CN IN (SELECT CountTree_CN FROM CountTree JOIN SampleGroup USING (SampleGroup_CN) WHERE Stratum_CN = {0}); DELETE FROM CountTree WHERE SampleGroup_CN IN (SELECT SampleGroup_CN FROM SampleGroup WHERE SampleGroup.Stratum_CN = {0}); DELETE FROM SampleGroupTreeDefaultValue WHERE SampleGroup_CN IN (SELECT SampleGroup_CN FROM SampleGroup WHERE SampleGroup.Stratum_CN = {0}); DELETE FROM SamplerState WHERE SampleGroup_CN IN (SELECT SampleGroup_CN FROM SampleGroup WHERE SampleGroup.Stratum_CN = {0}); DELETE FROM SampleGroup WHERE Stratum_CN = {0}; DELETE FROM TreeFieldSetup WHERE Stratum_CN = {0}; DELETE FROM LogFieldSetup WHERE Stratum_CN = {0}; DELETE FROM FixCNTTallyPopulation WHERE FixCNTTallyClass_CN IN (SELECT FixCNTtallyClass_CN FROM FixCNTTallyClass WHERE Stratum_CN = {0}); DELETE FROM FixCNTTallyClass WHERE Stratum_CN = {0}; DELETE FROM SampleGroupStatsTreeDefaultValue WHERE SampleGroupStats_CN IN (SELECT SampleGroupStats_CN FROM SampleGroupStats AS sgs JOIN StratumStats AS ss USING (StratumStats_CN) WHERE Stratum_CN = {0}); DELETE FROM SampleGroupStats WHERE StratumStats_CN IN (SELECT StratumStats_CN FROM StratumStats WHERE Stratum_CN = {0}); DELETE FROM StratumStats WHERE Stratum_CN = {0};", stratum.Stratum_CN); db.Execute(command); stratum.Delete(); db.CommitTransaction(); } catch (Exception e) { db.RollbackTransaction(); throw e; } }
public static void RealignTreeSpecies(Datastore datastore, long treeDefaultValue_CN) { datastore.Execute("UPDATE Tree AS t SET Species = (SELECT Species FROM TreeDefaultValue AS tdv WHERE tdv.TreeDefaultValue_CN = @p1) WHERE t.TreeDefaultValue_CN = @p1;", treeDefaultValue_CN); }