Ejemplo n.º 1
0
        /// <summary>
        /// Prompts the setting UI for the user.
        /// This method might be invoked only when the server has UI settings (HasSettings == True).
        /// </summary>
        /// <param name="data">
        /// The duct fitting and accessory pressure drop UI data.
        /// It is used as in/out param, the user can get the old values from it and also can set the new values from the setting UI back to it.
        /// </param>
        /// <returns>
        /// True if the user does change something in the UI (i.e. the user changes something in the entity in the data that was given as the argument into this method.), False otherwise.
        /// </returns>
        public bool ShowSettings(DuctFittingAndAccessoryPressureDropUIData data)
        {
            bool settingChanged = false;

            /* your configuration UI here */

            return(settingChanged);
        }
        /// <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(DuctFittingAndAccessoryPressureDropUIData data, string schemaField)
        {
            double initialValue = 0.0;

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

            foreach (DuctFittingAndAccessoryPressureDropUIDataItem 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 duct settings dialog
        /// </summary>
        /// <param name="data">
        /// The duct fitting and accessory pressure drop UI data.
        /// </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(DuctFittingAndAccessoryPressureDropUIData data, string schemaField)
        {
            string initialValue = String.Empty;

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

            foreach (DuctFittingAndAccessoryPressureDropUIDataItem uiDataItem in uiDataItems)
            {
                string tmpValue = String.Empty;

                Entity entity = uiDataItem.GetEntity();
                if (entity != null && entity.IsValid())
                {
                    tmpValue = 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 = tmpValue;
                }
                else
                {
                    if (tmpValue != 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 duct fitting and accessory pressure drop UI data. 
        /// </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 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(DuctFittingAndAccessoryPressureDropUIData data, Guid dbServerId, string schemaField, string newValue)
        {
            bool isUpdated = false;

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

             IDuctFittingAndAccessoryPressureDropServer dbServer = service.GetServer(dbServerId) as IDuctFittingAndAccessoryPressureDropServer;
             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<DuctFittingAndAccessoryPressureDropUIDataItem> uiDataItems = data.GetUIDataItems();
             foreach (DuctFittingAndAccessoryPressureDropUIDataItem 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 duct settings dialog
        /// </summary>
        /// <param name="data">
        /// The duct fitting and accessory pressure drop UI data.
        /// </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(DuctFittingAndAccessoryPressureDropUIData data, string schemaField)
        {
            string initialValue = String.Empty;

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

            Entity entity = uiDataItem.GetEntity();
            if (entity != null && entity.IsValid())
            {
               tmpValue = 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 = tmpValue;
            else
            {
               if (tmpValue != 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(DuctFittingAndAccessoryPressureDropUIData data, string schemaField)
        {
            double initialValue = 0.0;

             IList<DuctFittingAndAccessoryPressureDropUIDataItem> uiDataItems = data.GetUIDataItems();
             foreach (DuctFittingAndAccessoryPressureDropUIDataItem 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>
        /// Prompts the setting UI for the user. 
        /// This method might be invoked only when the server has UI settings (HasSettings == True).
        /// </summary>
        /// <param name="data">
        /// The duct fitting and accessory pressure drop UI data.
        /// It is used as in/out param, the user can get the old values from it and also can set the new values from the setting UI back to it.
        /// </param>
        /// <returns>
        /// True if the user does change something in the UI (i.e. the user changes something in the entity in the data that was given as the argument into this method.), False otherwise.
        /// </returns>
        public bool ShowSettings(DuctFittingAndAccessoryPressureDropUIData data)
        {
            bool settingChanged = false;

             /* your configuration UI here */

             return settingChanged;
        }
        /// <summary>
        /// Updates the entity in the duct fitting and accessory pressure drop UI data.
        /// </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 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(DuctFittingAndAccessoryPressureDropUIData data, Guid dbServerId, string schemaField, string newValue)
        {
            bool isUpdated = false;

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

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

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

            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 <DuctFittingAndAccessoryPressureDropUIDataItem> uiDataItems = data.GetUIDataItems();

            foreach (DuctFittingAndAccessoryPressureDropUIDataItem 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);
        }