logo
small logo
  • Produkty
  • Zamów
  • Wsparcie techniczne
  • Articles
  • Customer panel Wsparcie techniczne
    • en
    • pt
    • es
    • de
    • pl
    • JP
    • ZH
  • Glówna strona
  • /
  • Articles
  • /
  • Jak przenosić listę opcji do raportu internetowego – FastReport.Net
  • FastCube – szybki OLAP Cube Engine i Pivot Grid

    29 lutego 2020

    Trudno sobie wyobrazić wykonanie analizy danych bez technologii OLAP (On-Line Analytical Processing). Jednak są różne

    read more
  • Tworzenie i wyprowadzanie kodów kreskowych ITF-14 w aplikacjach .NET

    25 lutego 2021

    ITF-14 (Interleaved Two of Five) to dwupasmowy kod numeryczny, znany również jako kod o wysokiej

    read more
  • Jak zaktualizować raport sieci Web FastReport.Core

    21 września 2020

    Czasami trzeba zaktualizować raport, na przykład, jeśli dodana została nowa wartość zmiennej lub jeśli w

    read more
  • Raporty i dokumenty PDF w Blazorze

    5 kwietnia 2021

    Microsoft udostępnił niedawno platformę webową o nazwie Blazor. Framework ten umożliwia tworzenie interaktywnych interfejsów internetowych

    read more
  • Jak zainstalować FastReport Business Graphics .NET

    18 sierpnia 2021

    Ten artykuł wyjaśnia, jak zainstalować FastReport Business Graphics .NET na Twoim komputerze i jak dodać

    read more

Jak przenosić listę opcji do raportu internetowego – FastReport.Net

15 kwietnia 2020

Podczas tworzenia raportów, często konieczne jest przeniesienie niektórych wartości z zewnątrz w celu przefiltrowania danych do raportu lub zarządzania logiką raportu. Korzystając z FastReport.Net, często spotykam się z taką potrzebą. Ze względu na to, iż pracuję głównie z raportami internetowymi, przekazuję parametry do raportu poprzez adres url. Moje raporty są przeważnie dość złożone i nie ograniczają się do jednego parametru. Dlatego istnieje potrzeba przekazania listy parametrów, czyli listy kluczowych zestawów wartości. Kluczem jest nazwa ustawienia.

Z pewnością lepiej jest rozważyć to na przykładzie. W tym przypadku, używam ASP. Ne Core Web Api app.

1
2
3
4
5
6
7
8
9
10
namespace ParametersWeb.Models
{
 public class Reports
 {
 // Report ID
 public int Id { get; set; }
 // Report File Name
 public string ReportName { get; set; }
 }
}

 ValuesController:

Wypełnij tablice raportów:

1
2
3
4
5
Reports[] reportItems = new Reports[]
 {
 new Reports { Id = 1, ReportName = "Parameters.frx" },
 new Reports { Id = 2, ReportName = "Master-Detail.frx" } 
 };

Metoda tworzenia raportu jest asynchroniczna, ponieważ wykorzystuje asynchroniczną metodę konwersji raportu w formacie html. W tym formacie, jak wiadomo, chcemy wyświetlić raport w przeglądarce:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
[HttpGet("{id}")]
 public async System.Threading.Tasks.Task<IActionResult> GetAsync(int id)
 {
 string mime = "application/html"; // MIME header with default value
 // Find report
 var parameters = HttpContext.Request.QueryString.ToString().Substring(1);
 Reports reportItem = reportItems.FirstOrDefault((p) => p.Id == id); // we get the value of the collection by id
 if (reportItem != null)
 {
 string webRootPath = _hostingEnvironment.WebRootPath; // determine the path to the wwwroot folder
 string reportPath = (webRootPath + "/App_Data/" + reportItem.ReportName); // determine the path to the report
 string dataPath = (webRootPath + "/App_Data/nwind.xml");// determine the path to the database
 using (MemoryStream stream = new MemoryStream()) // Create a stream for the report
 {
 try
 {
 using (DataSet dataSet = new DataSet())
 {
 // Fill the source by data
 dataSet.ReadXml(dataPath);
 // Turn on web mode FastReport
 Config.WebMode = true; 
 WebReport webReport = new WebReport();//create the report object
 webReport.Report.Load(reportPath); //upload the report
 webReport.Report.RegisterData(dataSet, "NorthWind"); //register the data sourcw in the report
 if (parameters != null)
 {
 string[] parameterList = parameters.Split(',');
 foreach (string item in parameterList)
 {
 string[] parameter = item.Split('=');
 webReport.Report.SetParameterValue(parameter[0], parameter[1]); //set the report parameter value
 }
 }
 // inline registration of FastReport javascript
 webReport.Inline = true;//allow to register scripts and styles in HTML-body intead of putting them in the header
 HtmlString reportHtml = await webReport.Render(); //upload the report in HTML
 byte[] streamArray = Encoding.UTF8.GetBytes(reportHtml.ToString());
 stream.Write(streamArray, 0, streamArray.Length);//write down the report in the stream 
 }
 // Get the name of the resulting report file with the necessary extension 
 var file = String.Concat(Path.GetFileNameWithoutExtension(reportPath), ".", "html"); 
 return File(stream.ToArray(), mime, file); // attachment
 }
 // Handle exceptions
 catch
 {
 return new NoContentResult();
 }
 finally
 {
 stream.Dispose();
 }
 }
 }
 else
 return NotFound();
 }

Istota tej metody jest następująca – przesyłamy wybrany szablon raportu, parsujemy z adresu url i przenosimy ich wartość do raportu. Następnie przekształcamy raport w format html i odsyłamy plik do klienta.

Nazwy parametrów, które przekazujemy do raportu, powinny wyraźnie odpowiadać parametrom w raporcie:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE html>
<html>
<head>
 <title></title>
 <meta charset="utf-8" />
 <script src="/lib/jquery/dist/jquery.min.js"></script>
</head>
<body>
 <script>
 function call() {
 $.ajax({
 type: "GET",
 url: "api/values/1?FirstParameter=Value1,SecondParameter=Value2",
 //contentType: "application/text; charset=utf-8",
 dataType: "html",
 success: function (data) {
 $('#results').html(data);
 console.log(data);
 }, //End of AJAX Success function
 failure: function (data) {
 alert(data.responseText);
 }, //End of AJAX failure function
 error: function (data) {
 alert(data.responseText);
 } //End of AJAX error function
 });
 };
 </script>
 <form method="GET" id="formx" action="javascript:void(null);" onsubmit="call()">
 <input value="Show" type="submit">
 </form>
 <div id="results" typeof="submit"></div><!—here will be the result-->
</body>
</html>

 

 

about product pobierz zamów
avatar
Dmitriy Fedyashov
Technical Writer
Fast Reports Team: Dmitriy Fedyashov - Technical Writer at Fast Reports
.NET FastReport

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Zamów
  • Pobierz
  • Dokumentacja
  • Opinie użytkowników
  • Jak odinstalować nasze produkty
  • Ticket system
  • FAQ
  • Tutorial Video
  • Forum
  • Articles
  • Our News
  • Prasa o nas
  • Partnerzy
  • Kontakty

© 1998-2022 by Fast Reports Inc.

  • Poufność