示例#1
0
        /// <summary>
        /// Create a conformance change annotation
        /// </summary>
        private void CreateConformanceChange(Feature feature, Constraint constraint)
        {
            #region Conformance Change
            // 1. Validate the constraint is against a property
            ClassContent pFeature = feature as ClassContent;
            if (pFeature == null)
            {
                Trace.WriteLine(String.Format("Delta: Conformance constraint cannot be applied against a '{1}' named '{0}'", feature.Name, feature.GetType().Name), "error");
                return;
            }

            // 2. Validate the conformance old value is in fact a match
            ConstraintValue <String> stConstraint = constraint.Value as ConstraintValue <string>;
            if (stConstraint == null || stConstraint.Original.ToLower() != pFeature.Conformance.ToString().ToLower())
            {
                Trace.WriteLine(String.Format("Delta: Conformance constraint cannot be applied because the original value of '{0}' does not match the actual original property conformance of '{1}'",
                                              stConstraint.Original.ToLower(), pFeature.Conformance.ToString().ToLower()), "error");
                return;
            }

            // Map the SCREAMING CAPS to ScreamingCaps
            string friendlyValue = String.Format("{0}{1}", stConstraint.New[0], stConstraint.New.Substring(1).ToLower());
            if (friendlyValue == "Not_allowed")
            {
                friendlyValue = "NotAllowed";
            }
            // 3. Verify a constraint for the same jurisdication has not already been added
            if (feature.Annotations.Exists(o => o is ConformanceConstraintAnnotation && (o as ConformanceConstraintAnnotation).RealmCode == this.m_deltaSet.Realm.Code))
            {
                Trace.WriteLine(String.Format("Delta: Conformance constraint has already been applied to '{0}'", feature.Name), "error");
                return;
            }

            feature.Annotations.Add(
                new ConformanceConstraintAnnotation()
            {
                NewValue   = (Property.ConformanceKind)Enum.Parse(typeof(Property.ConformanceKind), friendlyValue),
                ChangeType = ChangeType.Edit,
                RealmCode  = this.m_deltaSet.Realm.Code,
                RealmName  = this.m_deltaSet.MetaData.Description
            }
                );
            #endregion
        }
        public override Boolean Save()
        {
            Boolean useTransaction = (application.EnvironmentDatabase.OpenTransactions == 0); // NO NESTED TRANSACTIONS

            Boolean success = false;

            StringBuilder sqlStatement = new StringBuilder();

            String childIds = String.Empty;


            if (!application.HasEnvironmentPermission(Server.EnvironmentPermissions.CareLevelManage))
            {
                throw new ApplicationException("Permission Denied.");
            }

            Dictionary <String, String> validationResponse = Validate();

            if (validationResponse.Count != 0)
            {
                foreach (String validationKey in validationResponse.Keys)
                {
                    throw new ApplicationException("Invalid [" + validationKey + "]: " + validationResponse[validationKey]);
                }
            }

            modifiedAccountInfo = new Mercury.Server.Data.AuthorityAccountStamp(application.Session);

            try {
                if (useTransaction)
                {
                    application.EnvironmentDatabase.BeginTransaction();
                }

                sqlStatement = new StringBuilder();

                sqlStatement.Append("EXEC dbo.CareLevelActivity_InsertUpdate ");

                sqlStatement.Append(Id.ToString() + ", ");

                sqlStatement.Append("'" + NameSql + "', ");

                sqlStatement.Append("'" + DescriptionSql + "', ");

                sqlStatement.Append(CareLevelId.ToString() + ", ");


                sqlStatement.Append(((Int32)ActivityType).ToString() + ", ");

                sqlStatement.Append(Reoccurring.ToString() + ", ");

                sqlStatement.Append(((Int32)InitialAnchorDate).ToString() + ", ");

                sqlStatement.Append(((Int32)AnchorDate).ToString() + ", ");


                sqlStatement.Append(((Int32)ScheduleType).ToString() + ", ");

                sqlStatement.Append(ScheduleValue.ToString() + ", ");

                sqlStatement.Append(((Int32)ScheduleQualifier).ToString() + ", ");

                sqlStatement.Append(ConstraintValue.ToString() + ", ");

                sqlStatement.Append(((Int32)ConstraintQualifier).ToString() + ", ");


                sqlStatement.Append(((Int32)PerformActionDate).ToString() + ", ");

                if (Action == null)
                {
                    sqlStatement.Append("NULL, NULL, NULL, ");
                }

                else
                {
                    sqlStatement.Append(Action.Id.ToString() + ", ");

                    sqlStatement.Append("'" + Action.ActionParametersXmlSqlParsedString + "', ");

                    sqlStatement.Append("'" + Action.Description + "', ");
                }


                sqlStatement.Append(modifiedAccountInfo.AccountInfoSql);


                success = application.EnvironmentDatabase.ExecuteSqlStatement(sqlStatement.ToString(), 0);

                if (!success)
                {
                    application.SetLastException(application.EnvironmentDatabase.LastException);

                    throw application.EnvironmentDatabase.LastException;
                }

                SetIdentity();

                if (!success)
                {
                    application.SetLastException(application.EnvironmentDatabase.LastException);

                    throw application.EnvironmentDatabase.LastException;
                }


                String deleteStatement = "DELETE FROM CareLevelActivityThreshold WHERE CareLevelActivityId = " + Id.ToString();

                success = application.EnvironmentDatabase.ExecuteSqlStatement(deleteStatement);


                foreach (Activity.ActivityThreshold currentThreshold in Thresholds)
                {
                    currentThreshold.ActivityId = Id;

                    currentThreshold.Application = application;


                    sqlStatement = new StringBuilder();

                    sqlStatement.Append("EXEC dbo.CareLevelActivityThreshold_InsertUpdate ");

                    sqlStatement.Append(currentThreshold.Id.ToString() + ", ");

                    sqlStatement.Append("'" + currentThreshold.Name.Replace("'", "''") + "', ");

                    sqlStatement.Append("'" + currentThreshold.Description.Replace("'", "''") + "', ");

                    sqlStatement.Append(Id.ToString() + ", ");


                    sqlStatement.Append(currentThreshold.RelativeDateValue.ToString() + ", ");

                    sqlStatement.Append(((Int32)currentThreshold.RelativeDateQualifier).ToString() + ", ");

                    sqlStatement.Append(((Int32)currentThreshold.Status).ToString() + ", ");


                    if (Action == null)
                    {
                        sqlStatement.Append("NULL, NULL, NULL, ");
                    }

                    else
                    {
                        sqlStatement.Append(Action.Id.ToString() + ", ");

                        sqlStatement.Append("'" + Action.ActionParametersXmlSqlParsedString + "', ");

                        sqlStatement.Append("'" + Action.Description + "', ");
                    }


                    sqlStatement.Append(modifiedAccountInfo.AccountInfoSql);


                    success = application.EnvironmentDatabase.ExecuteSqlStatement(sqlStatement.ToString(), 0);

                    if (!success)
                    {
                        application.SetLastException(application.EnvironmentDatabase.LastException);

                        throw application.EnvironmentDatabase.LastException;
                    }

                    currentThreshold.SetIdentity();
                }


                success = true;

                if (useTransaction)
                {
                    application.EnvironmentDatabase.CommitTransaction();
                }
            }

            catch (Exception applicationException) {
                success = false;

                if (useTransaction)
                {
                    application.EnvironmentDatabase.RollbackTransaction();
                }

                application.SetLastException(applicationException);
            }

            return(success);
        }