コード例 #1
0
        // update 3.2.2 notes: Added table LK_District and updated initialization for LK_Forests
        public static void UpdateTo_3_2_2(CruiseDatastore ds)
        {
            // create an in-memory database
            // to migrate into
            using (var newDatastore = new CruiseDatastore_V3())
            {
                var excludeTables = new[]
                {
                    "LK_CruiseMethod",
                    "LK_District",
                    "LK_FIA",
                    "LK_Forest",
                    "LK_LoggingMethod",
                    "LK_Product",
                    "LK_Purpose",
                    "LK_Region",
                    "LK_UOM",
                    "LogField",
                    "TreeField",
                };
                // migrate contents of old db into new in-memory database
                Migrate(ds, newDatastore, excludeTables);

                // use back up rutine to replace old database with
                // migrated contents
                newDatastore.BackupDatabase(ds);
            }
        }
コード例 #2
0
        public bool EnsureCanMigrate(string cruiseID, CruiseDatastore_V3 v3db, out string errorMsg)
        {
            errorMsg = null;
            var errorMsgSb = new StringBuilder();

            //if (CheckHasTreeDefaults(cruiseID, v3db) is false)
            //{
            //    return true;
            //}
            //else
            //{
            //    errorMsg += "Cruise Has No Tree Default Values";
            //    return false;
            //}

            var subPopTdvErrors = CheckAllSubPopsHavTDV(cruiseID, v3db);

            if (subPopTdvErrors.Any())
            {
                foreach (var error in subPopTdvErrors)
                {
                    errorMsgSb.AppendLine(error);
                }
                errorMsg = errorMsgSb.ToString();
                return(false);
            }

            return(true);
        }
コード例 #3
0
        public static void UpdateTo_3_1_0(CruiseDatastore ds)
        {
            // create an in-memory database
            // to migrate into
            using (var newDatastore = new CruiseDatastore_V3())
            {
                var excludeTables = new[] { "SamplerState" };
                // migrate contents of old db into new in-memory database
                Migrate(ds, newDatastore, excludeTables);

                // use back up rutine to replace old database with
                // migrated contents
                newDatastore.BackupDatabase(ds);
            }
        }
コード例 #4
0
        public void MigrateFromV3ToV2(string cruiseID, CruiseDatastore_V3 v3db, CruiseDatastore v2db, string createdBy = null)
        {
            var v3DbAlias = "v3";

            v2db.AttachDB(v3db, v3DbAlias);

            try
            {
                var connection = v2db.OpenConnection();
                MigrateFromV3ToV2(cruiseID, connection, createdBy, v3DbAlias, v2db.ExceptionProcessor, Migrators);
            }
            finally
            {
                v3db.DetachDB(v3DbAlias);
                v2db.ReleaseConnection();
            }
        }
コード例 #5
0
        //private static bool CheckHasTreeDefaults(string cruiseID, CruiseDatastore_V3 v3db)
        //{
        //    var hasTrees = v3db.GetRowCount("Tree", "WHERE CruiseID = @p1", cruiseID) > 0;
        //    var hasTallyBySp = v3db.GetRowCount("TallyPopulation", "WHERE CruiseID = @p1 AND SpeciesCode IS NOT NULL", cruiseID) > 0;

        //    if (hasTrees || hasTallyBySp)
        //    {
        //        var hasTDV = v3db.GetRowCount("TreeDefaultValue", "WHERE CruiseID = @p1", cruiseID) > 0;
        //        return hasTDV is false;
        //    }
        //    else { return true; }
        //}

        public static IEnumerable <string> CheckAllSubPopsHavTDV(string cruiseID, CruiseDatastore_V3 v3db)
        {
            return(v3db.QueryScalar <string>(
                       @"SELECT
    'SubPopulation' AS Category,
    'Warning' AS Level,
    'SubPopulation ' || SpeciesCode || ' ' || LiveDead || ' in SG ' || SampleGroupCode || ' Stratum ' || StratumCode || ' Has No Applyable Tree Defaults' AS Message,
    SubPopulationID AS RecordID
FROM (
        SELECT
            subp.*,
            (SELECT TreeDefaultValue_CN FROM TreeDefaultValue AS tdv
            WHERE  tdv.CruiseID = subp.CruiseID
                AND SpeciesCode = subp.SpeciesCode OR SpeciesCode IS NULL
                AND PrimaryProduct = sg.PrimaryProduct OR PrimaryProduct IS NULL
            ORDER BY PrimaryProduct DESC, SpeciesCode DESC
            LIMIT 1
            ) AS TreeDefaultValue_CN
        FROM SubPopulation AS subp
        JOIN SampleGroup AS sg USING (CruiseID, StratumCode, SampleGroupCode)
        WHERE CruiseID = @p1
    )
WHERE TreeDefaultValue_CN IS NULL;", cruiseID).ToArray());
        }