bool _ContainsArray; // true if any of the parameters is an array reference public QueryParameters(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) { _ContainsArray = false; QueryParameter q; _Items = new List<QueryParameter>(); // Loop thru all the child nodes foreach(XmlNode xNodeLoop in xNode.ChildNodes) { if (xNodeLoop.NodeType != XmlNodeType.Element) continue; switch (xNodeLoop.Name) { case "QueryParameter": q = new QueryParameter(r, this, xNodeLoop); break; default: q=null; // don't know what this is // don't know this element - log it OwnerReport.rl.LogError(4, "Unknown QueryParameters element '" + xNodeLoop.Name + "' ignored."); break; } if (q != null) _Items.Add(q); } if (_Items.Count == 0) OwnerReport.rl.LogError(8, "For QueryParameters at least one QueryParameter is required."); else _Items.TrimExcess(); }
private string ParameterValue(Report rpt, QueryParameter qp) { if (!qp.IsArray) { // handle non-array string svalue = qp.Value.EvaluateString(rpt, null); if (svalue == null) svalue = "null"; else switch (qp.Value.Expr.GetTypeCode()) { case TypeCode.Char: case TypeCode.DateTime: case TypeCode.String: // need to double up on "'" and then surround by ' svalue = svalue.Replace("'", "''"); svalue = "'" + svalue + "'"; break; } return svalue; } StringBuilder sb = new StringBuilder(); ArrayList ar = qp.Value.Evaluate(rpt, null) as ArrayList; if (ar == null) return null; bool bFirst = true; foreach (object v in ar) { if (!bFirst) sb.Append(", "); if (v == null) { sb.Append("null"); } else { string sv = v.ToString(); if (v is string || v is char || v is DateTime) { // need to double up on "'" and then surround by ' sv = sv.Replace("'", "''"); sb.Append("'"); sb.Append(sv); sb.Append("'"); } else sb.Append(sv); } bFirst = false; } return sb.ToString(); }