/// <summary>
        /// Gets the initial value for the settings dialog
        /// </summary>
        /// <param name="data">
        /// The duct fitting and accessory pressure drop UI data.
        /// </param>
        /// <param name="dbServerId">
        /// The corresponding DB server Id of the UI server.
        /// </param>
        /// <param name="schemaField">
        /// The schema field which is used to get the initial value.
        /// </param>
        /// <returns>
        /// The initial numeric value which will be shown in the settings dialog.
        /// </returns>
        public static double GetInitialNumericValue(PipeFittingAndAccessoryPressureDropUIData data, string schemaField)
        {
            double initialValue = 0.0;

            IList <PipeFittingAndAccessoryPressureDropUIDataItem> uiDataItems = data.GetUIDataItems();

            foreach (PipeFittingAndAccessoryPressureDropUIDataItem uiDataItem in uiDataItems)
            {
                string value = String.Empty;

                Entity entity = uiDataItem.GetEntity();
                if (entity != null && entity.IsValid())
                {
                    value = entity.Get <string>(schemaField);
                }
                else
                {
                    return(double.NaN);
                }

                if (CalculationUtility.IsNumeric(value))
                {
                    double dValue = Convert.ToDouble(value);
                    if (uiDataItems.IndexOf(uiDataItem) == 0) // The first element
                    {
                        initialValue = dValue;
                    }
                    else
                    {
                        if (!dValue.Equals(initialValue)) // If all elements don't have the same old values, the settings dialog will show empty initial value.
                        {
                            initialValue = double.NaN;
                            break;
                        }
                    }
                }
            }

            return(initialValue);
        }
        /// <summary>
        /// Gets the initial value for the settings dialog
        /// </summary>
        /// <param name="data">
        /// The pipe fitting and accessory pressure drop UI data.
        /// </param>
        /// <param name="dbServerId">
        /// The corresponding DB server Id of the UI server.
        /// </param>
        /// <param name="schemaField">
        /// The schema field which is used to get the initial value.
        /// </param>
        /// <returns>
        /// The initial value which will be shown in the settings dialog.
        /// </returns>
        public static string GetInitialValue(PipeFittingAndAccessoryPressureDropUIData data, string schemaField)
        {
            string initialValue = String.Empty;

            IList <PipeFittingAndAccessoryPressureDropUIDataItem> uiDataItems = data.GetUIDataItems();

            foreach (PipeFittingAndAccessoryPressureDropUIDataItem uiDataItem in uiDataItems)
            {
                string tableName = String.Empty;

                Entity entity = uiDataItem.GetEntity();
                if (entity != null && entity.IsValid())
                {
                    tableName = entity.Get <string>(schemaField);
                }
                else // If only one entity is null or invalid, the initial value should be empty.
                {
                    return(String.Empty);
                }

                if (uiDataItems.IndexOf(uiDataItem) == 0) // The first element
                {
                    initialValue = tableName;
                }
                else
                {
                    if (tableName != initialValue) // If all elements don't have the same old values, the settings dialog will show empty initial value.
                    {
                        initialValue = String.Empty;
                        break;
                    }
                }
            }

            return(initialValue);
        }
        /// <summary>
        /// Updates the entity in the pipe fitting and accessory pressure drop UI data. 
        /// </summary>
        /// <param name="data">
        /// The pipe fitting and accessory pressure drop UI data.
        /// </param>
        /// <param name="dbServerId">
        /// The corresponding DB server Id of the UI server.
        /// </param>
        /// <param name="schemaField">
        /// The schema field to be updated.
        /// </param>
        /// <param name="newValue">
        /// The new value to be set to the schema field.
        /// </param>
        /// <returns>
        /// True if the entity in the UI data is updated, false otherwise.
        /// </returns>
        public static bool UpdateEntities(PipeFittingAndAccessoryPressureDropUIData data, Guid dbServerId, string schemaField, string newValue)
        {
            bool isUpdated = false;

             ExternalService service = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.PipeFittingAndAccessoryPressureDropService);
             if (service == null)
            return isUpdated;

             IPipeFittingAndAccessoryPressureDropServer dbServer = service.GetServer(dbServerId) as IPipeFittingAndAccessoryPressureDropServer;
             if (dbServer == null)
             {
            return isUpdated;
             }

             Schema schema = dbServer.GetDataSchema();
             if (schema == null)
            return isUpdated;

             Field field = schema.GetField(schemaField);
             if (field == null)
            return isUpdated;

             Entity entity = new Entity(schema);
             entity.Set<string>(field, newValue);

             IList<PipeFittingAndAccessoryPressureDropUIDataItem> uiDataItems = data.GetUIDataItems();
             foreach (PipeFittingAndAccessoryPressureDropUIDataItem uiDataItem in uiDataItems)
             {

            Entity oldEntity = uiDataItem.GetEntity();
            if (oldEntity == null && entity == null)
            {
               continue;
            }

            if (oldEntity == null || entity == null)
            {
               uiDataItem.SetEntity(entity);
               isUpdated = true;
               continue;
            }

            if ((!oldEntity.IsValid()) && (!entity.IsValid()))
            {
               continue;
            }

            if ((!oldEntity.IsValid()) || (!entity.IsValid()))
            {
               uiDataItem.SetEntity(entity);
               isUpdated = true;
               continue;
            }

            string oldValue = oldEntity.Get<string>(schemaField);
            if (oldValue != newValue)
            {
               uiDataItem.SetEntity(entity);
               isUpdated = true;
               continue;
            }
             }

             return isUpdated;
        }
        /// <summary>
        /// Gets the initial value for the settings dialog
        /// </summary>
        /// <param name="data">
        /// The pipe fitting and accessory pressure drop UI data.
        /// </param>
        /// <param name="dbServerId">
        /// The corresponding DB server Id of the UI server.
        /// </param>
        /// <param name="schemaField">
        /// The schema field which is used to get the initial value.
        /// </param>
        /// <returns>
        /// The initial value which will be shown in the settings dialog.
        /// </returns>
        public static string GetInitialValue(PipeFittingAndAccessoryPressureDropUIData data, string schemaField)
        {
            string initialValue = String.Empty;

             IList<PipeFittingAndAccessoryPressureDropUIDataItem> uiDataItems = data.GetUIDataItems();
             foreach (PipeFittingAndAccessoryPressureDropUIDataItem uiDataItem in uiDataItems)
             {
            string tableName = String.Empty;

            Entity entity = uiDataItem.GetEntity();
            if (entity != null && entity.IsValid())
            {
               tableName = entity.Get<string>(schemaField);
            }
            else // If only one entity is null or invalid, the initial value should be empty.
            {
               return String.Empty;
            }

            if (uiDataItems.IndexOf(uiDataItem) == 0) // The first element
               initialValue = tableName;
            else
            {
               if (tableName != initialValue) // If all elements don't have the same old values, the settings dialog will show empty initial value.
               {
                  initialValue = String.Empty;
                  break;
               }
            }

             }

             return initialValue;
        }
        /// <summary>
        /// Gets the initial value for the settings dialog
        /// </summary>
        /// <param name="data">
        /// The duct fitting and accessory pressure drop UI data.
        /// </param>
        /// <param name="dbServerId">
        /// The corresponding DB server Id of the UI server.
        /// </param>
        /// <param name="schemaField">
        /// The schema field which is used to get the initial value.
        /// </param>
        /// <returns>
        /// The initial numeric value which will be shown in the settings dialog.
        /// </returns>
        public static double GetInitialNumericValue(PipeFittingAndAccessoryPressureDropUIData data, string schemaField)
        {
            double initialValue = 0.0;

             IList<PipeFittingAndAccessoryPressureDropUIDataItem> uiDataItems = data.GetUIDataItems();
             foreach (PipeFittingAndAccessoryPressureDropUIDataItem uiDataItem in uiDataItems)
             {
            string value = String.Empty;

            Entity entity = uiDataItem.GetEntity();
            if (entity != null && entity.IsValid())
            {
               value = entity.Get<string>(schemaField);
            }
            else
            {
               return double.NaN;
            }

            if (CalculationUtility.IsNumeric(value))
            {
               double dValue = Convert.ToDouble(value);
               if (uiDataItems.IndexOf(uiDataItem) == 0) // The first element
               {
                  initialValue = dValue;
               }
               else
               {
                  if (!dValue.Equals(initialValue)) // If all elements don't have the same old values, the settings dialog will show empty initial value.
                  {
                     initialValue = double.NaN;
                     break;
                  }
               }
            }
             }

             return initialValue;
        }
        /// <summary>
        /// Updates the entity in the pipe fitting and accessory pressure drop UI data.
        /// </summary>
        /// <param name="data">
        /// The pipe fitting and accessory pressure drop UI data.
        /// </param>
        /// <param name="dbServerId">
        /// The corresponding DB server Id of the UI server.
        /// </param>
        /// <param name="schemaField">
        /// The schema field to be updated.
        /// </param>
        /// <param name="newValue">
        /// The new value to be set to the schema field.
        /// </param>
        /// <returns>
        /// True if the entity in the UI data is updated, false otherwise.
        /// </returns>
        public static bool UpdateEntities(PipeFittingAndAccessoryPressureDropUIData data, Guid dbServerId, string schemaField, string newValue)
        {
            bool isUpdated = false;

            ExternalService service = ExternalServiceRegistry.GetService(ExternalServices.BuiltInExternalServices.PipeFittingAndAccessoryPressureDropService);

            if (service == null)
            {
                return(isUpdated);
            }

            IPipeFittingAndAccessoryPressureDropServer dbServer = service.GetServer(dbServerId) as IPipeFittingAndAccessoryPressureDropServer;

            if (dbServer == null)
            {
                return(isUpdated);
            }

            Schema schema = dbServer.GetDataSchema();

            if (schema == null)
            {
                return(isUpdated);
            }

            Field field = schema.GetField(schemaField);

            if (field == null)
            {
                return(isUpdated);
            }

            Entity entity = new Entity(schema);

            entity.Set <string>(field, newValue);

            IList <PipeFittingAndAccessoryPressureDropUIDataItem> uiDataItems = data.GetUIDataItems();

            foreach (PipeFittingAndAccessoryPressureDropUIDataItem uiDataItem in uiDataItems)
            {
                Entity oldEntity = uiDataItem.GetEntity();
                if (oldEntity == null && entity == null)
                {
                    continue;
                }

                if (oldEntity == null || entity == null)
                {
                    uiDataItem.SetEntity(entity);
                    isUpdated = true;
                    continue;
                }

                if ((!oldEntity.IsValid()) && (!entity.IsValid()))
                {
                    continue;
                }

                if ((!oldEntity.IsValid()) || (!entity.IsValid()))
                {
                    uiDataItem.SetEntity(entity);
                    isUpdated = true;
                    continue;
                }

                string oldValue = oldEntity.Get <string>(schemaField);
                if (oldValue != newValue)
                {
                    uiDataItem.SetEntity(entity);
                    isUpdated = true;
                    continue;
                }
            }

            return(isUpdated);
        }