public void ApplyParameterDefaults(rws.ReportParameter[] wsReportParameters, CrcReportDefinition repDef)
        {
            // first build up a choicecollection from the defaults
            var choiceCol = new CrcParameterChoiceCollection();

            foreach (var paramLoop in wsReportParameters)
            {
                if (paramLoop.DefaultValues != null)
                {
                    var crcChoice = new CrcParameterChoice(paramLoop.Name);
                    foreach (string valString in paramLoop.DefaultValues)
                    {
                        crcChoice.Values.Add(valString);
                    }

                    choiceCol.ParameterChoiceList.Add(crcChoice);
                }
            }
            // now apply it to the repdef
            var mapper    = new CrcParameterChoiceMapper();
            var mapResult = mapper.MapParameterChoices(repDef, choiceCol);

            if (!mapResult.MappingValid)
            {
                throw new ApplicationException(string.Format("Could not map report defaults for report {0}. Problems: {1}",
                                                             repDef.DisplayName, string.Join(", ", mapResult.Complaints.ToArray())));
            }
        }
        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;
        }
Beispiel #3
0
        public CrcParameterChoiceCollection Create(string paramString)
        {
            var pcCol = new CrcParameterChoiceCollection();

            string[] clauses = paramString.Split("&".ToCharArray());
            if (clauses.Count() == 1 && string.IsNullOrEmpty(clauses[0]))
            {
                return(pcCol);
            }
            foreach (string clauseLoop in clauses)
            {
                int    isnullPos = clauseLoop.IndexOf(":isnull");
                int    equalsPos = clauseLoop.IndexOf("=");
                string pname     = null;
                string pval      = null;
                if (isnullPos > 0)
                {
                    pname = clauseLoop.Substring(0, isnullPos);
                    string boolString  = clauseLoop.Substring(isnullPos + 8);
                    bool   isNullValue = bool.Parse(boolString);
                    if (!isNullValue)
                    {
                        throw new ApplicationException(String.Format("not sure how to interpret false in clause {0}", clauseLoop));
                    }
                    else
                    {
                        pval = null;
                    }
                }
                else if (equalsPos > 0)
                {
                    pname = clauseLoop.Substring(0, equalsPos);
                    pval  = HttpUtility.UrlDecode(clauseLoop.Substring(equalsPos + 1));
                }
                else
                {
                    throw new ApplicationException(String.Format("Could not parse clause {0}", clauseLoop));
                }

                // we now have a pname and pval
                var pcExists = pcCol.ParameterChoiceList.FirstOrDefault(p => p.Name == pname);
                if (pcExists == null)
                {
                    var newPc = new CrcParameterChoice(pname);
                    pcCol.ParameterChoiceList.Add(newPc);
                    pcExists = newPc;
                }
                pcExists.Values.Add(pval);
            }
            return(pcCol);
        }
        /// <summary>
        /// applies the specified CrcParameterChoiceCollection to the specified report definition
        /// will set the ParameterChoice property of matching ParameterDefinitions as required
        /// </summary>
        /// <param name="repDefn"></param>
        /// <param name="paramChoices"></param>
        /// <returns>ParameterMapResult - if MappingValid is false, see Complaints collection</returns>
        public ParameterMapResult MapParameterChoices(CrcReportDefinition repDefn, CrcParameterChoiceCollection paramChoices)
        {
            var res = new ParameterMapResult();

            res.Complaints = new List <string>();
            string cultureForDateParsing = GetCultureForDateParsing();

            foreach (CrcParameterChoice choiceLoop in paramChoices.ParameterChoiceList)
            {
                var defnMatch = repDefn.ParameterDefinitions.FirstOrDefault(pd => pd.Name == choiceLoop.Name);
                if (defnMatch == null)
                {
                    res.Complaints.Add(String.Format("Param {0} not found", choiceLoop.Name));
                    continue;
                }
                if (defnMatch.ParameterType == CrcParameterType.Date)
                {
                    if (choiceLoop.SingleValue == null)
                    {
                        defnMatch.ParameterChoice = choiceLoop.DeepClone();
                        continue;
                    }

                    var parseResult = ParseDateStringVariousWays(choiceLoop.SingleValue, cultureForDateParsing);
                    if (parseResult.CouldParse)
                    {
                        var parsedChoice = new CrcParameterChoice(choiceLoop.Name);
                        parsedChoice.SingleValue  = parseResult.DateTime.ToString("yyyy-MM-dd");
                        defnMatch.ParameterChoice = parsedChoice;
                        continue;
                    }
                    res.Complaints.Add(String.Format("Could not parse date {0} into Param {1}",
                                                     choiceLoop.SingleValue, choiceLoop.Name));
                }
                else if (defnMatch.ParameterType == CrcParameterType.Boolean)
                {
                    if (string.IsNullOrEmpty(choiceLoop.SingleValue) || choiceLoop.SingleValue == "True" ||
                        choiceLoop.SingleValue == "False")
                    {
                        defnMatch.ParameterChoice = choiceLoop.DeepClone();
                        continue;
                    }
                    res.Complaints.Add(String.Format("Could not parse boolean {0} into Param {1}",
                                                     choiceLoop.SingleValue, choiceLoop.Name));
                }
                else if (defnMatch.ParameterType == CrcParameterType.Text)
                {
                    defnMatch.ParameterChoice = choiceLoop.DeepClone();
                    continue;
                }
                else if (defnMatch.ValidValues.Count() > 0)
                {
                    bool valuesOK = true;
                    foreach (string chosenValue in choiceLoop.Values)
                    {
                        if (defnMatch.ValidValues.FirstOrDefault(vv => vv.Value == chosenValue) == null)
                        {
                            res.Complaints.Add(String.Format("Could not apply value {0} into Param {1} because it is not a valid option",
                                                             chosenValue, choiceLoop.Name));
                            valuesOK = false;
                        }
                    }
                    if (valuesOK)
                    {
                        defnMatch.ParameterChoice = choiceLoop.DeepClone();
                        continue;
                    }
                }
            }
            res.MappingValid = (res.Complaints.Count() == 0);
            return(res);
        }