public static void SetReportParameter(Microsoft.Reporting.WebForms.LocalReport localreport, System.Collections.Hashtable Para) { Microsoft.Reporting.WebForms.ReportParameterInfoCollection RPara = localreport.GetParameters(); foreach (Microsoft.Reporting.WebForms.ReportParameterInfo item in RPara) { switch (item.Name) { case "CompanyName": localreport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { new Microsoft.Reporting.WebForms.ReportParameter(item.Name, Services.GlobalVariant.GetSysCompany()["CompanyName"].ToString()) }); break; case "CompanyAddress": localreport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { new Microsoft.Reporting.WebForms.ReportParameter(item.Name, Services.GlobalVariant.GetSysCompany()["CompanyAddress"].ToString()) }); break; case "CompanyPhone": localreport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { new Microsoft.Reporting.WebForms.ReportParameter(item.Name, Services.GlobalVariant.GetSysCompany()["CompanyPhone"].ToString()) }); break; case "CompanyFax": localreport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { new Microsoft.Reporting.WebForms.ReportParameter(item.Name, Services.GlobalVariant.GetSysCompany()["CompanyFax"].ToString()) }); break; case "CompanyTaxCode": localreport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { new Microsoft.Reporting.WebForms.ReportParameter(item.Name, Services.GlobalVariant.GetSysCompany()["CompanyTaxCode"].ToString()) }); break; case "QDBTC": localreport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { new Microsoft.Reporting.WebForms.ReportParameter(item.Name, Services.GlobalVariant.GetSysOption()["QDBTC"].ToString()) }); break; case "DirectorName": localreport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { new Microsoft.Reporting.WebForms.ReportParameter(item.Name, Services.GlobalVariant.GetSysOption()["DirectorName"].ToString()) }); break; case "ChiefAccountantName": localreport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { new Microsoft.Reporting.WebForms.ReportParameter(item.Name, Services.GlobalVariant.GetSysOption()["ChiefAccountantName"].ToString()) }); break; case "ReportCreatorName": localreport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { new Microsoft.Reporting.WebForms.ReportParameter(item.Name, Services.GlobalVariant.GetSysOption()["ReportCreatorName"].ToString()) }); break; case "ReportFontSize": localreport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { new Microsoft.Reporting.WebForms.ReportParameter(item.Name, Services.GlobalVariant.GetSysOption()["ReportFontSize"].ToString()) }); break; default: if (Para[item.Name] != null) { localreport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { new Microsoft.Reporting.WebForms.ReportParameter(item.Name, Para[item.Name].ToString()) }); } break; } } }
/// <summary> /// Note: SSRS cannot render the report if required parameters are missing. /// This will load any report parameters. /// If any of the parameters were required, but they were not provided, show an error message. /// </summary> /// <param name="report">Instance of the ReportViewer control or equiv object</param> private void CheckReportParameters(WebForms.LocalReport report) { //copy-in any report parameters which were not part of the DB query try { WebForms.ReportParameterInfoCollection rdlParams = report.GetParameters(); foreach (WebForms.ReportParameterInfo rdlParam in rdlParams) { if (this._reportParameters.ContainsKey(rdlParam.Name)) { string val = this._reportParameters[rdlParam.Name].ToString(); if (string.IsNullOrEmpty(val)) { if (rdlParam.Nullable) { val = null; report.SetParameters(new WebForms.ReportParameter(rdlParam.Name, val, false)); } else { ErrorMessages.Add(new ErrorMessage("Erro on Report Parameters.", $"Report Parameter value \"{ rdlParam.Name }\" is required, but was not provided.")); } } else { report.SetParameters(new WebForms.ReportParameter(rdlParam.Name, val)); } } else if (!rdlParam.AllowBlank) { ErrorMessages.Add(new ErrorMessage("Erro on Report Parameters.", $"Report Parameter \"{ rdlParam.Name }\" is required, but was not provided.")); } } if (ErrorMessages.Any()) { OnError?.Invoke(this, new EngineErrorEventArgs(ErrorMessages)); } } catch (WebForms.LocalProcessingException ex) { ErrorMessages.Add(new ErrorMessage(ex.Message, ex.StackTrace)); Exception exIn = ex.InnerException; while (exIn != null) { ErrorMessages.Add(new ErrorMessage(exIn.Message, exIn.StackTrace)); exIn = exIn.InnerException; } OnError?.Invoke(this, new EngineErrorEventArgs(ErrorMessages)); } }
public static void InitUIReport(Microsoft.Reporting.WebForms.LocalReport localreport, string metaname) { #region Set giá trị cho tham số Report Microsoft.Reporting.WebForms.ReportParameterInfoCollection RPara = localreport.GetParameters(); var Columns = Services.GlobalMeta.GetMetaObject(metaname).GetMetaTable(); foreach (Microsoft.Reporting.WebForms.ReportParameterInfo item in RPara) { if (item.Name.Length > 6) { string FieldName = item.Name.Substring(6); if (Columns.ContainsKey(FieldName)) { if (item.Name.IndexOf("Header") == 0) { localreport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { new Microsoft.Reporting.WebForms.ReportParameter(item.Name, Columns[FieldName].Des) }); } if (item.Name.IndexOf("Format") == 0) { string Format = ""; if (Columns[FieldName].FormatValue != null) { Format = Columns[FieldName].FormatValue.ToString(); } if (Columns[FieldName].CultureInfo != null) { switch (Columns[FieldName].CultureInfo.ToString()) { case "CIFC": if (Format == "n") { //Format += Services.GlobalVariant.GetSysOption()["RoundAmountFC"].ToString(); Format = "#,##0" + SetRound(int.Parse(Services.GlobalVariant.GetSysOption()["RoundAmountFC"].ToString())); } break; case "CIUPCC": if (Format == "n") { //Format += Services.GlobalVariant.GetSysOption()["RoundUnitPrice"].ToString(); Format = "#,##0" + SetRound(int.Parse(Services.GlobalVariant.GetSysOption()["RoundUnitPrice"].ToString())); } break; case "CIUPFC": if (Format == "n") { //Format += Services.GlobalVariant.GetSysOption()["RoundUnitPriceFC"].ToString(); Format = "#,##0" + SetRound(int.Parse(Services.GlobalVariant.GetSysOption()["RoundUnitPriceFC"].ToString())); } break; default: switch (Format) { case "c": //hiện format dấu tiền tệ //Format += Services.GlobalVariant.GetSysOption()["RoundAmount"].ToString(); //Không hiện format dấu tiền tệ //Format = "n"+Services.GlobalVariant.GetSysOption()["RoundAmount"].ToString(); Format = "#,##0" + SetRound(int.Parse(Services.GlobalVariant.GetSysOption()["RoundAmount"].ToString())); break; case "n": //Format += Services.GlobalVariant.GetSysOption()["RoundQuantity"].ToString(); Format = "#,##0" + SetRound(int.Parse(Services.GlobalVariant.GetSysOption()["RoundQuantity"].ToString())); break; default: break; } break; } } else { switch (Format) { case "c": //hiện format dấu tiền tệ //Format += Services.GlobalVariant.GetSysOption()["RoundAmount"].ToString(); //Không hiện format dấu tiền tệ //Format = "n"+Services.GlobalVariant.GetSysOption()["RoundAmount"].ToString(); Format = "#,##0" + SetRound(int.Parse(Services.GlobalVariant.GetSysOption()["RoundAmount"].ToString())); break; case "n": //Format += Services.GlobalVariant.GetSysOption()["RoundQuantity"].ToString(); Format = "#,##0" + SetRound(int.Parse(Services.GlobalVariant.GetSysOption()["RoundQuantity"].ToString())); break; default: break; } } if (!string.IsNullOrEmpty(Format)) { Format = string.Format("{0};-{1};{2}", Format, Format, "#.#"); //Format = string.Format("{0};{1};'-'", Format, Format); localreport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { new Microsoft.Reporting.WebForms.ReportParameter(item.Name, Format) }); } } } } } #endregion }