Ejemplo n.º 1
0
        private string SelectListAsString(CrcParameterDefinition paramDefn, int truncateListLimit)
        {
            StringBuilder sb    = new StringBuilder();
            int           count = 0;

            foreach (var valLoop in paramDefn.ParameterChoice.Values)
            {
                var vvMatch = paramDefn.ValidValues.FirstOrDefault(vv => vv.Value == valLoop);
                if (vvMatch == null)
                {
                    throw new ApplicationException(string.Format("Param {0}: {1} is not a valid value", paramDefn.Name, valLoop));
                }

                if (sb.Length > 0)
                {
                    sb.Append(", ");
                }
                sb.Append(vvMatch.Label);
                count += 1;
                if (truncateListLimit > 0 && count > truncateListLimit)
                {
                    sb.AppendFormat(" ... (and {0} others)", paramDefn.ParameterChoice.Values.Count() - count);
                    break;
                }
            }
            return(sb.ToString());
        }
Ejemplo n.º 2
0
 public void RefreshParameter(CrcParameterDefinition paramDefn, rws.ItemParameter latestParamDetails)
 {
     logger.DebugFormat("Updating {0} with {1} valid values", paramDefn.Name,
                        (latestParamDetails.ValidValues != null) ? latestParamDetails.ValidValues.Count().ToString() : "null");
     UpdateValidValues(paramDefn, latestParamDetails.ValidValues);
     if (!IsChoiceValid(paramDefn))
     {
         logger.DebugFormat("Param {0} choices are now invalid so applying {1} default values", paramDefn.Name,
                            (latestParamDetails.DefaultValues != null) ? latestParamDetails.DefaultValues.Count().ToString() : "null");
         UpdateDefaultValues(paramDefn, latestParamDetails.DefaultValues);
     }
 }
Ejemplo n.º 3
0
        public void UpdateDefaultValues(CrcParameterDefinition paramDefn, string[] newDefaultValues)
        {
            var newChoice = new CrcParameterChoice(paramDefn.Name);

            if (newDefaultValues != null)
            {
                foreach (string sloop in newDefaultValues)
                {
                    newChoice.Values.Add(sloop);
                }
            }
            paramDefn.ParameterChoice = newChoice;
        }
Ejemplo n.º 4
0
 public void UpdateValidValues(CrcParameterDefinition paramDefn, rws.ValidValue[] newValidValues)
 {
     paramDefn.ValidValues.Clear();
     if (newValidValues != null)
     {
         foreach (var valLoop in newValidValues)
         {
             paramDefn.ValidValues.Add(new CrcValidValue()
             {
                 Value = valLoop.Value, Label = valLoop.Label
             });
         }
     }
 }
Ejemplo n.º 5
0
        public bool IsChoiceValid(CrcParameterDefinition paramDefn)
        {
            if (paramDefn.ParameterChoice == null)
            {
                return(true);
            }

            foreach (string valLoop in paramDefn.ParameterChoice.Values)
            {
                var match = paramDefn.ValidValues.FirstOrDefault(vv => vv.Value == valLoop);
                if (match == null)
                {
                    return(false);
                }
            }
            return(true);
        }
 private void AddEmptyEquivalent(CrcParameterDefinition crcParam, string emptyEquiv)
 {
     if (crcParam.ParameterType == CrcParameterType.MultiSelect ||
         crcParam.ParameterType == CrcParameterType.Select)
     {
         // add if valid value
         if (crcParam.ValidValues.FirstOrDefault(vv => vv.Value == emptyEquiv) != null)
         {
             crcParam.EmptyEquivalentValues.Add(emptyEquiv);
         }
     }
     else
     {
         // just add
         crcParam.EmptyEquivalentValues.Add(emptyEquiv);
     }
 }
        public void AddParameterDefinitions(rws.ReportParameter[] wsReportParameters, CrcReportDefinition repDef, CrcExtraConfiguration extraConfig, CrcReportConfig reportConfig)
        {
            List <string> showByDefault = new List <string>();

            if (reportConfig != null)
            {
                showByDefault = reportConfig.GetParamsToShowByDefault();
            }
            List <string> defaultEmptyEquivalents = new List <string>();

            if (extraConfig != null && extraConfig.DefaultEmptyEquivalentValues != null)
            {
                defaultEmptyEquivalents = extraConfig.DefaultEmptyEquivalentValues;
            }

            foreach (var paramLoop in wsReportParameters)
            {
                CrcReportConfig.CrcParamConfig paramConfig = null;
                // get extra config for parameter, if there is any
                if (reportConfig != null)
                {
                    paramConfig = reportConfig.CrcParamConfigs.FirstOrDefault(p => p.ParamName == paramLoop.Name);
                }

                var crcParam = new CrcParameterDefinition();
                crcParam.Name       = paramLoop.Name;
                crcParam.id         = "param_" + paramLoop.Name.Replace(" ", "_");
                crcParam.AllowNull  = paramLoop.Nullable;
                crcParam.AllowBlank = paramLoop.AllowBlank;

                if (string.IsNullOrEmpty(paramLoop.Prompt))
                {
                    // if Prompt is null or empty, it means Parameter is 'Hidden' in SSRS
                    crcParam.Hidden      = true;
                    crcParam.DisplayName = paramLoop.Name;
                }
                else
                {
                    crcParam.DisplayName = paramLoop.Prompt;
                }
                if (string.IsNullOrEmpty(crcParam.DisplayName))
                {
                    crcParam.DisplayName = crcParam.Name;
                }
                // if PromptUser is false then Parameter is 'Internal' in SSRS
                if (!paramLoop.PromptUser)
                {
                    crcParam.Hidden = true;
                }
                if (paramLoop.Type == rws.ParameterTypeEnum.DateTime)
                {
                    crcParam.ParameterType = CrcParameterType.Date;
                }
                else if ((paramLoop.ValidValues != null && paramLoop.ValidValues.Count() > 0) ||
                         paramLoop.ValidValuesQueryBased)
                {
                    if (paramLoop.MultiValue)
                    {
                        crcParam.ParameterType = CrcParameterType.MultiSelect;
                    }
                    else
                    {
                        crcParam.ParameterType = CrcParameterType.Select;
                    }
                }
                else if (paramLoop.Type == rws.ParameterTypeEnum.Boolean)
                {
                    crcParam.ParameterType = CrcParameterType.Boolean;
                }
                else
                {
                    crcParam.ParameterType = CrcParameterType.Text;
                }


                if (paramLoop.ValidValues != null)
                {
                    foreach (var valLoop in paramLoop.ValidValues)
                    {
                        crcParam.ValidValues.Add(new CrcValidValue()
                        {
                            Value = valLoop.Value, Label = valLoop.Label
                        });
                    }
                    if (crcParam.ValidValues.Count() > 10)
                    {
                        crcParam.AllowListSearch = true;
                    }
                }


                // check config for dependencies
                if (paramConfig != null && paramConfig.DependantParams != null && paramConfig.DependantParams.Count() > 0)
                {
                    logger.DebugFormat("Param {0} has extraconfig dependancies: {1}",
                                       paramLoop.Name, string.Join(", ", paramConfig.DependantParams.ToArray()));
                    foreach (string dpname in paramConfig.DependantParams)
                    {
                        crcParam.DependantParameterNames.Add(dpname);
                    }
                }



                foreach (string sloop in defaultEmptyEquivalents)
                {
                    AddEmptyEquivalent(crcParam, sloop);
                }

                // check for specific empty equivalents for this parameter
                if (paramConfig != null && paramConfig.EmptyEquivalentValues != null)
                {
                    foreach (string sloop in paramConfig.EmptyEquivalentValues)
                    {
                        AddEmptyEquivalent(crcParam, sloop);
                    }
                }



                if (showByDefault.Contains(crcParam.Name))
                {
                    crcParam.AlwaysShow = true;
                }

                repDef.ParameterDefinitions.Add(crcParam);
            }
        }