예제 #1
0
        /// <summary>
        /// Checks for problems in the source project
        /// </summary>
        protected void CheckForProblems()
        {
            IDbDriver driver = SourceProject.CollectedData.GetDatabase();

            if (driver == null)
            {
                ExportInfo.Succeeded = false;
                ExportInfo.AddError("Data driver is null.", "999999");
                throw new InvalidOperationException("Data driver cannot be null");
            }

            // Check #1 - Make sure the base table exists and that it has a Global Record Id field, Record status field, and Unique key field.
            DataTable dt = driver.GetTableData(SourceForm.TableName, "GlobalRecordId, RECSTATUS, UniqueKey");

            if (dt == null)
            {
                ExportInfo.Succeeded = false;
                ExportInfo.AddError("Source table is null.", "999998");
                throw new InvalidOperationException("Source table cannot be null");
            }
            else if (dt.Columns.Count == 0)
            {
                ExportInfo.Succeeded = false;
                ExportInfo.AddError("Source table has zero columns.", "999997");
                throw new InvalidOperationException("Source table cannot have zero columns");
            }
            else if (dt.Columns.Count == 1)
            {
                ExportInfo.Succeeded = false;
                ExportInfo.AddError("Source table has only one column.", "999996");
                throw new InvalidOperationException("Source table cannot have only one column");
            }

            int baseTableRowCount = dt.Rows.Count;

            // Check #2a - Make sure GlobalRecordId is a string.
            if (!dt.Columns[0].DataType.ToString().Equals("System.String"))
            {
                ExportInfo.Succeeded = false;
                ExportInfo.AddError(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_INVALID_GUID_COLUMN, "101000");
                throw new ApplicationException(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_INVALID_GUID_COLUMN);
            }

            // Check #2b - Make sure RECSTATUS is a number
            if (!(dt.Columns[1].DataType.ToString().Equals("System.Byte") || dt.Columns[1].DataType.ToString().Equals("System.Int16") || dt.Columns[1].DataType.ToString().Equals("System.Int32")))
            {
                ExportInfo.Succeeded = false;
                ExportInfo.AddError(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_INVALID_RECSTATUS_COLUMN, "101001");
                throw new ApplicationException(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_INVALID_RECSTATUS_COLUMN);
            }

            // Check #3 - Make sure GlobalRecordId values haven't been replaced with something that isn't actually a GUID.
            //      For performance reasons only the first few values are checked.
            if (baseTableRowCount >= 1)
            {
                string      value = dt.Rows[0][0].ToString();
                System.Guid guid  = new Guid(value);

                if (baseTableRowCount >= 30)
                {
                    for (int i = 0; i < 30; i++)
                    {
                        value = dt.Rows[i][0].ToString();
                        guid  = new Guid(value);
                    }
                }
            }

            // Check #4a - See if global record ID values are distinct on the base table.
            Query     selectDistinctQuery = driver.CreateQuery("SELECT DISTINCT [GlobalRecordId] FROM [" + SourceForm.TableName + "]");
            DataTable distinctTable       = driver.Select(selectDistinctQuery);

            if (distinctTable.Rows.Count != baseTableRowCount)
            {
                ExportInfo.Succeeded = false;
                ExportInfo.AddError(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_GUID_NOT_UNIQUE, "101002");
                throw new ApplicationException(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_GUID_NOT_UNIQUE);
            }

            // Check #4b - See if global record ID values are distinct on each page table.
            foreach (Page page in SourceForm.Pages)
            {
                selectDistinctQuery = driver.CreateQuery("SELECT DISTINCT [GlobalRecordId] FROM [" + page.TableName + "]");
                distinctTable       = driver.Select(selectDistinctQuery);
                if (distinctTable.Rows.Count != baseTableRowCount)
                {
                    ExportInfo.Succeeded = false;
                    ExportInfo.AddError(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_GUID_NOT_UNIQUE_PAGE, "101003");
                    throw new ApplicationException(string.Format(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_GUID_NOT_UNIQUE_PAGE, page.TableName));
                }
            }

            // Check #5 - Make sure RECSTATUS has valid values.
            selectDistinctQuery = driver.CreateQuery("SELECT DISTINCT [RecStatus] FROM [" + SourceForm.TableName + "]");
            distinctTable       = driver.Select(selectDistinctQuery);
            foreach (DataRow row in distinctTable.Rows)
            {
                if (!row[0].ToString().Equals("1") && !row[0].ToString().Equals("0"))
                {
                    ExportInfo.Succeeded = false;
                    ExportInfo.AddError(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_RECSTATUS_VALUES_INVALID, "101004");
                    throw new ApplicationException(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_RECSTATUS_VALUES_INVALID);
                }
            }

            // Check #7 - Should never get here because the UI should prevent it, but do a check just in case
            if (SourceForm.IsRelatedView == true)
            {
                ExportInfo.Succeeded = false;
                ExportInfo.AddError(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_RELATED_FORM, "101005");
                throw new ApplicationException(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_RELATED_FORM);
            }

            distinctTable       = null;
            selectDistinctQuery = null;
            driver.Dispose();
            driver = null;
        }
예제 #2
0
        /// <summary>
        /// Checks for problems in the source project
        /// </summary>
        protected override void CheckForProblems()
        {
            IDbDriver driver = SourceProject.CollectedData.GetDatabase();

            if (driver == null)
            {
                ExportInfo.Succeeded = false;
                ExportInfo.AddError("Data driver is null.", "999999");
                throw new InvalidOperationException("Data driver cannot be null");
            }

            int rows = 0;

            foreach (View form in SourceForm.Project.Views)
            {
                Query selectDistinctQuery = driver.CreateQuery("SELECT GlobalRecordId, COUNT(GlobalRecordId) AS n FROM " + form.TableName + " GROUP BY GlobalRecordId HAVING COUNT(GlobalRecordId) > 1");
                rows = driver.Select(selectDistinctQuery).Rows.Count;

                if (rows > 0)
                {
                    ExportInfo.Succeeded = false;
                    ExportInfo.AddError(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_GUID_NOT_UNIQUE, "101002");
                    throw new InvalidOperationException(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_GUID_NOT_UNIQUE);
                }

                foreach (Page page in form.Pages)
                {
                    Query deleteQuery = driver.CreateQuery("DELETE FROM " + form.Name + " WHERE GlobalRecordId NOT IN (SELECT GlobalRecordId from " + page.TableName + ")");
                    rows = driver.ExecuteNonQuery(deleteQuery);
                    if (rows > 0)
                    {
                        // report ??
                    }

                    Query pageDeleteQuery = driver.CreateQuery("DELETE FROM " + page.TableName + " WHERE GlobalRecordId NOT IN (SELECT GlobalRecordId from " + form.Name + ")");
                    rows = driver.ExecuteNonQuery(deleteQuery);
                    if (rows > 0)
                    {
                        // report ??
                    }

                    Query selectDistinctPageQuery = driver.CreateQuery("SELECT GlobalRecordId, COUNT(GlobalRecordId) AS n FROM " + page.TableName + " GROUP BY GlobalRecordId HAVING COUNT(GlobalRecordId) > 1");
                    rows = driver.Select(selectDistinctPageQuery).Rows.Count;

                    if (rows > 0)
                    {
                        ExportInfo.Succeeded = false;
                        ExportInfo.AddError(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_GUID_NOT_UNIQUE, "101002");
                        throw new InvalidOperationException(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_GUID_NOT_UNIQUE);
                    }
                }
            }

            // Check #7 - Should never get here because the UI should prevent it, but do a check just in case
            if (SourceForm.IsRelatedView == true)
            {
                ExportInfo.Succeeded = false;
                ExportInfo.AddError(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_RELATED_FORM, "101005");
                throw new InvalidOperationException(ImportExportSharedStrings.ERROR_PACKAGER_CHECK_RELATED_FORM);
            }

            driver.Dispose();
            driver = null;
        }