예제 #1
0
        public static bool Comply(this ReportParameterInfo source, object obj)
        {
            var value = obj.GetType().GetProperty(source.Name).GetValue(obj, null).ToString();
            var temp1 = source.Values.Any(v => v.Equals(value));
            var temp2 = source.Values.All(v => v.Equals(value));

            return(temp1 && temp2);
        }
        private static IReportParameter CreateDateTimeParameter(ReportParameterInfo reportParameterInfo)
        {
            var dateTimeReportParameter = new DateTimeReportParameter(reportParameterInfo.Prompt, reportParameterInfo.Name);
            if (reportParameterInfo.Values.Any())
            {
                dateTimeReportParameter.Value = Convert.ToDateTime(
                    reportParameterInfo.Values.First(), new DateTimeFormatInfo { ShortDatePattern = "MM/dd/yyyy" });
            }

            return dateTimeReportParameter;
        }
        /// <summary>
        /// Set Parameter Value.
        /// </summary>
        /// <param name="localReport">The local report instance.</param>
        /// <param name="name">The parameter's name.</param>
        /// <param name="value">The parameter's value.</param>
        public static void SetValue(this LocalReport localReport,
                                    string name, string value)
        {
            if (null == localReport)
            {
                return;
            }

            ReportParameterInfo para = localReport.FindParameter(name);

            if (null != para)
            {
                localReport.SetParameters(new ReportParameter(para.Name, value));
            }
        }
        /// <summary>
        /// Set the ReportParameter of the specified ReportParameterInfo.
        /// </summary>
        /// <param name="report">The Report that this method extends.</param>
        /// <param name="reportParameterInfo">The ReportParameterInfor whose parameter should be added to the Report.</param>
        public static void SetParameters(this Report report, ReportParameterInfo reportParameterInfo)
        {
            if (report == null)
            {
                throw new ArgumentNullException("report", "Value cannot be null.");
            }

            if (reportParameterInfo == null)
            {
                throw new ArgumentNullException("reportParameterInfo", "Value cannot be null.");
            }

            ReportParameter reportParameter = new ReportParameter(
                reportParameterInfo.Name,
                reportParameterInfo.Values.ToArray(),
                reportParameterInfo.Visible);

            report.SetParameters(reportParameter);
        }
        private static IReportParameter CreateStringParameter(ReportParameterInfo reportParameterInfo)
        {
            var stringReportParameter = new StringReportParameter(reportParameterInfo.Prompt, reportParameterInfo.Name)
                                            {
                                                AllowMultipleValues = reportParameterInfo.MultiValue
                                            };

            if (reportParameterInfo.ValidValues != null && reportParameterInfo.ValidValues.Any())
            {
                stringReportParameter.ValidValues = reportParameterInfo.ValidValues.Select(v => v.Value).ToList();
            }

            if (reportParameterInfo.Values != null && reportParameterInfo.Values.Any())
            {
                stringReportParameter.Value = reportParameterInfo.Values.First();
            }

            return stringReportParameter;
        }
        /// <summary>
        /// Find Parameter.
        /// </summary>
        /// <param name="localReport">The local report instance.</param>
        /// <param name="name">The parameter's name.</param>
        /// <returns>Returns instance of ReportParameterInfo if found.</returns>
        private static ReportParameterInfo FindParameter(this LocalReport localReport,
                                                         string name)
        {
            ReportParameterInfo result = null;

            if (null == localReport)
            {
                return(result);
            }

            ReportParameterInfoCollection parameters = localReport.GetParameters();

            if (null != parameters && parameters.Count > 0)
            {
                result = parameters.FirstOrDefault(
                    (ReportParameterInfo para) =>
                {
                    return(string.Compare(para.Name, name, true) == 0);
                });
            }

            return(result);
        }
예제 #7
0
        private static void FindParameters(Control parent, List <ReportParameter> params1)
        {
            Type type = Assembly.GetAssembly(typeof(ReportViewer)).GetType("Microsoft.Reporting.WebForms.BaseParameterInputControl");

            foreach (Control control in parent.Controls)
            {
                if (type.IsAssignableFrom(control.GetType()))
                {
                    ReportParameterInfo propertyValue = (ReportParameterInfo)GetPropertyValue(control, "ReportParameter");
                    if (propertyValue == null)
                    {
                        continue;
                    }
                    string[] strArray = (string[])GetPropertyValue(control, "CurrentValue");
                    if ((strArray != null) && (strArray.Length > 0))
                    {
                        ReportParameter item = new ReportParameter();

                        ////item.

                        //item.Name(propertyValue.get_Name());
                        //item.get_Values().AddRange(strArray);
                        //params1.Add(item);
                        ////param = new ReportParameter();
                        ////param.Name = paramInfo.Name;
                        ////param.Values.AddRange(paramValues);
                        ////params1.Add(param);

                        item.Name = propertyValue.Name;
                        item.Values.AddRange(strArray);
                        params1.Add(item);
                    }
                }
                FindParameters(control, params1);
            }
        }
        public IReportParameter Create(ReportParameterInfo reportParameterInfo)
        {
            IReportParameter result;
            switch (reportParameterInfo.DataType)
            {
                case ParameterDataType.Boolean:
                    result = CreateBooleanParameter(reportParameterInfo);
                    break;
                case ParameterDataType.DateTime:
                    result = CreateDateTimeParameter(reportParameterInfo);
                    break;
                case ParameterDataType.Float:
                    result = CreateFloatParameter(reportParameterInfo);
                    break;
                case ParameterDataType.Integer:
                    result = CreateIntegerParameter(reportParameterInfo);
                    break;
                default:
                    result = CreateStringParameter(reportParameterInfo);
                    break;
            }

            return result;
        }
예제 #9
0
파일: Report.cs 프로젝트: Thanak1234/test
        public byte[] Export(object param, string reportPath, string type)
        {
            ReportViewer report = new ReportViewer();

            //Set Processing Mode
            report.ProcessingMode               = ProcessingMode.Remote;
            report.ServerReport.ReportPath      = reportPath;
            report.ServerReport.ReportServerUrl = new Uri(rsUri);
            List <ReportParameter>        @params = new List <ReportParameter>();
            ReportParameterInfoCollection pInfo   = default(ReportParameterInfoCollection);

            pInfo = report.ServerReport.GetParameters();

            if (param != null)
            {
                Type parameterType = param.GetType();
                var  properties    = parameterType.GetProperties();
                foreach (var property in properties)
                {
                    var attribute = property.GetAttribute <DataMemberAttribute>(true);

                    string name  = attribute.Name;
                    object value = property.GetValue(param, null);

                    ReportParameterInfo rpInfo = pInfo[name];

                    if (rpInfo == null)
                    {
                        continue;
                    }

                    if (value != null && value.ToString().ToUpper() != "NULL")
                    {
                        @params.Add(new ReportParameter(name, value.ToString(), true));
                    }
                    else
                    {
                        ReportParameter rparam = new ReportParameter(name);
                        rparam.Values.Add(null);
                        @params.Add(rparam);
                    }
                }
            }

            report.ServerReport.SetParameters(@params);

            // Process and render the report
            report.ServerReport.Refresh();

            string format     = "";
            string extension  = "";
            string deviceinfo = "";
            string mimeType   = "";
            string encoding   = "";

            string[]  streams  = null;
            Warning[] warnings = null;

            if (type.ToLower() == "xls")
            {
                format    = "EXCEL";
                extension = "xls";
            }
            else if (type.ToLower() == "pdf")
            {
                format    = "PDF";
                extension = "pdf";
            }

            return(report.ServerReport.Render(format, deviceinfo, out mimeType, out encoding, out extension, out streams, out warnings));
        }
예제 #10
0
 public ServerReportParameterInfo(ReportParameterInfo reportParameterInfo)
 {
     ReportParameterInfo = reportParameterInfo;
 }
 private static IReportParameter CreateIntegerParameter(ReportParameterInfo reportParameterInfo)
 {
     return new IntegerReportParameter(reportParameterInfo.Prompt, reportParameterInfo.Name);
 }
 private static IReportParameter CreateFloatParameter(ReportParameterInfo reportParameterInfo)
 {
     return new FloatReportParameter(reportParameterInfo.Prompt, reportParameterInfo.Name);
 }
 private static IReportParameter CreateBooleanParameter(ReportParameterInfo reportParameterInfo)
 {
     return new BooleanReportParameter(reportParameterInfo.Prompt, reportParameterInfo.Name);
 }