Пример #1
0
        public override Boolean Save()
        {
            Boolean success = false;

            String childIds = String.Empty;


            try {
                if (!application.HasEnvironmentPermission(Server.EnvironmentPermissions.CareMeasureManage))
                {
                    throw new ApplicationException("PermissionDenied");
                }

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

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


                ModifiedAccountInfo = new Data.AuthorityAccountStamp(application);

                application.EnvironmentDatabase.BeginTransaction();


                careMeasureDomainId = application.CoreObjectGetIdByName("CareMeasureDomain", careMeasureDomainName);

                if (careMeasureDomainId == 0)
                {
                    CareMeasureDomain careMeasureDomain = new CareMeasureDomain(application);

                    careMeasureDomain.Name = careMeasureDomainName;

                    careMeasureDomain.Description = careMeasureDomainName;

                    careMeasureDomain.Enabled = true;

                    careMeasureDomain.Visible = true;

                    careMeasureDomain.Save();

                    careMeasureDomainId = careMeasureDomain.Id;
                }

                careMeasureClassId = application.CareMeasureClassGetIdByName(careMeasureDomainId, careMeasureClassName);

                if (careMeasureClassId == 0)
                {
                    CareMeasureClass careMeasureClass = new CareMeasureClass(application);

                    careMeasureClass.Name = careMeasureClassName;

                    careMeasureClass.Description = careMeasureClassName;

                    careMeasureClass.CareMeasureDomainId = careMeasureDomainId;

                    careMeasureClass.Enabled = true;

                    careMeasureClass.Visible = true;

                    careMeasureClass.Save();

                    careMeasureClassId = careMeasureClass.Id;
                }



                System.Data.IDbCommand sqlCommand = application.EnvironmentDatabase.CreateCommand("CareMeasure_InsertUpdate");

                sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;


                application.EnvironmentDatabase.AppendCommandParameter(sqlCommand, "@careMeasureId", Id);

                application.EnvironmentDatabase.AppendCommandParameter(sqlCommand, "@careMeasureName", Name, Server.Data.DataTypeConstants.Name);

                application.EnvironmentDatabase.AppendCommandParameter(sqlCommand, "@careMeasureDescription", Description, Server.Data.DataTypeConstants.Description);


                application.EnvironmentDatabase.AppendCommandParameter(sqlCommand, "@careMeasureClassId", careMeasureClassId);


                application.EnvironmentDatabase.AppendCommandParameter(sqlCommand, "@enabled", Enabled);

                application.EnvironmentDatabase.AppendCommandParameter(sqlCommand, "@visible", Visible);


                application.EnvironmentDatabase.AppendCommandParameter(sqlCommand, "@modifiedAuthorityName", ModifiedAccountInfo.SecurityAuthorityName, Server.Data.DataTypeConstants.Name);

                application.EnvironmentDatabase.AppendCommandParameter(sqlCommand, "@modifiedAccountId", ModifiedAccountInfo.UserAccountId, Server.Data.DataTypeConstants.UserAccountId);

                application.EnvironmentDatabase.AppendCommandParameter(sqlCommand, "@modifiedAccountName", ModifiedAccountInfo.UserAccountName, Server.Data.DataTypeConstants.Name);


                success = (sqlCommand.ExecuteNonQuery() > 0);


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

                    throw application.EnvironmentDatabase.LastException;
                }

                SetIdentity();


                foreach (CareMeasureComponent currentComponent in components)
                {
                    if (currentComponent.Id != 0)
                    {
                        childIds += currentComponent.Id.ToString() + ", ";
                    }
                }

                if (!String.IsNullOrWhiteSpace(childIds))    // DELETE ALL REMOVED CHILD IDS FROM DATABASE

                {
                    childIds += "0";

                    String deleteStatement = "DELETE FROM dbo.CareMeasureComponent WHERE CareMeasureId = " + Id.ToString() + " AND CareMeasureComponentId NOT IN (" + childIds + ")";

                    success = application.EnvironmentDatabase.ExecuteSqlStatement(deleteStatement);

                    if (!success)
                    {
                        throw new ApplicationException("Unable to propertly delete child Components from database.");
                    }
                }

                foreach (CareMeasureComponent currentComponent in components)
                {
                    currentComponent.Application = application;

                    currentComponent.CareMeasureId = id;

                    success = currentComponent.Save();

                    if (!success)
                    {
                        throw new ApplicationException("Unable to save Measure Component.");
                    }
                }


                application.EnvironmentDatabase.CommitTransaction();

                success = true;
            }

            catch (Exception applicationException) {
                success = false;

                application.EnvironmentDatabase.RollbackTransaction();

                application.SetLastException(applicationException);
            }

            return(success);
        }
Пример #2
0
        public override List <ImportExport.Result> XmlImport(System.Xml.XmlNode objectNode)
        {
            List <ImportExport.Result> response = base.XmlImport(objectNode);


            try {
                foreach (System.Xml.XmlNode currentNode in objectNode.ChildNodes)
                {
                    switch (currentNode.Name)
                    {
                    case "Properties":

                        foreach (System.Xml.XmlNode currentPropertyNode in currentNode.ChildNodes)
                        {
                            switch (currentPropertyNode.Attributes["Name"].InnerText)
                            {
                            case "CareMeasureDomainName":

                                careMeasureDomainName = currentPropertyNode.InnerText;

                                careMeasureDomainId = application.CoreObjectGetIdByName("CareMeasureDomain", careMeasureDomainName);

                                break;

                            default: break;
                            }
                        }

                        break;

                    case "Components":

                        foreach (System.Xml.XmlNode currentComponentNode in currentNode.ChildNodes)
                        {
                            CareMeasureComponent component = new CareMeasureComponent(application);

                            response.AddRange(component.XmlImport(currentComponentNode));

                            components.Add(component);
                        }

                        break;

                    case "CareMeasureClass":

                        // USES THE DOMAIN ID CAPTURED UNDER PROPERTIES

                        careMeasureClassName = currentNode.Attributes["Name"].InnerText;

                        CareMeasureClass careMeasureClass = application.CareMeasureClassGetByName(careMeasureDomainId, careMeasureClassName);

                        if (careMeasureClass == null)
                        {
                            // DOES NOT EXIST, CREATE NEW FROM IMPORT

                            careMeasureClass = new CareMeasureClass(application);

                            response.AddRange(careMeasureClass.XmlImport(currentNode));

                            careMeasureDomainId = careMeasureClass.CareMeasureDomainId;

                            careMeasureClassId = careMeasureClass.Id;


                            if (careMeasureClassId == 0)
                            {
                                throw new ApplicationException("Unable to import Care Measure Class: " + currentNode.Attributes["Name"].InnerText + ".");
                            }
                        }

                        break;
                    } // switch (currentNode.Attributes["Name"].InnerText) {
                }     // foreach (System.Xml.XmlNode currentNode in objectNode.ChildNodes) {


                // SAVE IMPORTED CLASS

                if (!Save())
                {
                    throw new ApplicationException("Unable to save Care Measure: " + Name + ".");
                }
            }

            catch (Exception importException) {
                response.Add(new ImportExport.Result(ObjectType, Name, importException));
            }

            return(response);
        }