예제 #1
0
        /// <summary>
        /// React on is enabled click for CheckBoxCellTemplate. Converts template state
        /// to restriction value.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        private void _IsEnabled_Click(object sender, RoutedEventArgs e)
        {
            RestrictionDataWrapper    selectedItem = xceedGrid.CurrentItem as RestrictionDataWrapper;
            IVrpSolver                solver       = App.Current.Solver;
            ICollection <Restriction> restrictions = solver.SolverSettings.Restrictions;
            Restriction               restriction  = _FindRestriction(selectedItem.Restriction.Name, restrictions);

            restriction.IsEnabled = selectedItem.IsEnabled;
        }
예제 #2
0
        /// <summary>
        /// Updates value.
        /// </summary>
        /// <param name="wrapper">Restriction data wrapper.</param>
        /// <param name="solverSettings">Solver settings.</param>
        /// <param name="attribute">Network attribute.</param>
        private void _UpdateValue(RestrictionDataWrapper wrapper, SolverSettings solverSettings,
                                  NetworkAttribute attribute)
        {
            Debug.Assert(null != wrapper);
            Debug.Assert(null != attribute);
            Debug.Assert(null != solverSettings);

            // Update restriction usage parameter if it exist.
            if (wrapper.RestrictionUsageParameter != null &&
                wrapper.RestrictionUsageParameter.Name != null)
            {
                _UpdateParameterIfNeeded(solverSettings, attribute,
                                         wrapper.RestrictionUsageParameter.Name, wrapper.RestrictionUsageParameter.Value);
            }

            // Update all other parameters.
            foreach (Parameter parameter in wrapper.Parameters)
            {
                if (!string.IsNullOrEmpty(parameter.Name))
                {
                    _UpdateParameterIfNeeded(solverSettings, attribute, parameter.Name, parameter.Value);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Inits grid source.
        /// </summary>
        /// <param name="maxParametersCount">Maximum number of attribute parameters.</param>
        /// <param name="collectionSource">Data grid collection source.</param>
        private void _InitGridSource(int maxParametersCount,
                                     DataGridCollectionViewSource collectionSource)
        {
            IVrpSolver                solver             = App.Current.Solver;
            SolverSettings            solverSettings     = solver.SolverSettings;
            NetworkDescription        networkDescription = solver.NetworkDescription;
            ICollection <Restriction> restrictions       = solverSettings.Restrictions;

            var restrictionWrappers = new List <RestrictionDataWrapper>();

            var networkAttributes = networkDescription.NetworkAttributes;

            foreach (NetworkAttribute attribute in networkAttributes)
            {
                if (attribute.UsageType == NetworkAttributeUsageType.Restriction)
                {
                    Restriction restriction = _FindRestriction(attribute.Name, restrictions);
                    if (restriction.IsEditable)
                    {
                        Debug.Assert(null != attribute.Parameters);

                        // Create collection of all non "restriction usage" attribute parameters.
                        IList <NetworkAttributeParameter> attrParams;
                        if (attribute.RestrictionUsageParameter != null)
                        {
                            attrParams = attribute.Parameters.Where(
                                param => param.Name != attribute.RestrictionUsageParameter.Name).ToList();
                        }
                        else
                        {
                            attrParams = attribute.Parameters.ToList();
                        }

                        var parameters = new Parameters(maxParametersCount);
                        for (int index = 0; index < maxParametersCount; ++index)
                        {
                            string value = null;
                            if (index < attrParams.Count())
                            {
                                NetworkAttributeParameter param = attrParams.ElementAt(index);
                                value             = _GetParameterValue(attribute.Name, param.Name, solverSettings);
                                parameters[index] = new Parameter(param.Name, value);
                            }
                            else
                            {
                                parameters[index] = new Parameter();
                            }
                        }

                        // Create wrapper for restriction.
                        var wrapper = new RestrictionDataWrapper(restriction.IsEnabled,
                                                                 restriction.NetworkAttributeName,
                                                                 restriction.Description, parameters);

                        // If attribute has restriction usage parameter - add this parameter
                        // to wrapper.
                        if (attribute.RestrictionUsageParameter != null)
                        {
                            var restrictionUsageParameterValue = _GetParameterValue(attribute.Name,
                                                                                    attribute.RestrictionUsageParameter.Name, solverSettings);
                            var restrictionParameter = new Parameter(attribute.RestrictionUsageParameter.Name,
                                                                     restrictionUsageParameterValue);
                            wrapper.RestrictionUsageParameter = restrictionParameter;
                        }

                        restrictionWrappers.Add(wrapper);
                    }
                }
            }

            collectionSource.Source = restrictionWrappers;
        }