如何输出在mysql中累积的数据,以便可以使用syncfusion将其导出为pdf?

时间:2019-08-24 19:20:38

标签: mysql xamarin syncfusion

enter image description here empty list from same database

我有一个列表视图,可输出我想要的mysql数据。它工作正常,但现在我想打印该数据。有2种方法可以做到excel或pdf。使用Syncfusion控件将执行pdf并将其导出到文件中。当我运行它时,我的循环语法是空的。我做了2列,但mysql的值未显示。我想念一些东西,但我不知道。

该页面应该以pdf格式显示数据。对于循环代码,我无法显示来自mysql的数据。当我运行代码时,它是空的。

"must": [{
    "term": {
        "keywords.h1": "engineering"
    }
}]

这是我的绑定或数据模型的来源

public HistoryLogPage()
    {

        InitializeComponent();
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();
        SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation);
        {

            conn.CreateTable<Post>();
            var posts = conn.Table<Post>().ToList();

            postListView.ItemsSource = posts;
            conn.Close();            
        }
    }

    //to be able to know which item was selected
    void listviewhandle_ItemSelected(object sender, SelectedItemChangedEventArgs e)
    {
        var selectedPost = postListView.SelectedItem as Post;

        if (selectedPost != null)
        {
            Navigation.PushModalAsync(new PostDetail(selectedPost));
        }
    }
    //this will print in pdf when pushed
    void filebuttonHandle_Clicked(object sender, EventArgs e)
    {

        //Create a new PDF document.
        PdfDocument doc = new PdfDocument();

        //Add a page.
        PdfPage page = doc.Pages.Add();

        //Create a PdfGrid.
        PdfGrid pdfGrid = new PdfGrid();

       //List of Columns 
         List<Post> collection = new List<Post>();
         Post post = new Post();
         var Date = post.CDateTime;
        //column2
        var rain1 = post.rain1Lbl;

        collection.Add(post);



        //Add values to list 
        List<object> data = new List<object>();
        for (int i = 0; i < collection.Count; i++)
        {
  //the line im having trouble with.....******************...
      Object row = new { Date = collection[i].CDateTime, Experiences = collection[i].rain1vol };
            data.Add(row);
        }
        //Add list to IEnumerable 
        IEnumerable<object> tableData = data;
        //Assign data source 
        pdfGrid.DataSource = tableData;


        //Draw grid to the page of PDF document.
        pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10));
        //Save the PDF document to stream.
        MemoryStream stream = new MemoryStream();
        doc.Save(stream);
        //Close the document.
        doc.Close(true);
        stream.Position = 0;

    Xamarin.Forms.DependencyService.Get<ISave().SaveAndView("Output.pdf", 
"application/pdf", stream);
}

这就是我添加到mysql中数据的方式

public class Post
{
    //private const string V = "test";
    //from settingspage to show up in history
    string rain1lbl = Settings.rain1LocationSettings;
    string rain2lbl = Settings.rain2LocationSettings;

    [PrimaryKey, AutoIncrement]
    public int ID { get; set; }

    public static bool showLabel { get; set; }  //public class model

    public string rain1Lbl
    {
        get => rain1lbl;

        set => rain1lbl = Settings.Drain1LocationSettings;

    }

    public string rain2Lbl
    {
        get => rain2lbl;

        set => rain2lbl = Settings.Drain2LocationSettings;

    }

    public string CDateTime { get; set; }

    [MaxLength(3)]
    public string rain1vol { get; set; }

    [MaxLength(3)]
    public string rain2vol { get; set; }
    }

}

2 个答案:

答案 0 :(得分:0)

首先,您应该在班级维护对职位数据的引用

cloud_firestore: ^0.12.9+1

然后您可以在构建PDF时参考

tx.send_at(item, duration)

答案 1 :(得分:0)

在对提供的代码段进行进一步分析时,我们发现您错过了向Post类变量的对象添加值的过程。请参考下面的代码片段以获取更多详细信息,

//List of Columns 
List<Post> collection = new List<Post>();
Post post = new Post();
post.CDateTime = value;
post.rain1vol = value;

collection.Add(post);

//Add values to list 
List<object> data = new List<object>();
for (int i = 0; i < collection.Count; i++)
{
 Object row = new { Date = collection[i].CDateTime, Experiences = collection[i].rain1vol };
 data.Add(row);
}
//Add list to IEnumerable 
IEnumerable<object> tableData = data;

//Assign data source 
pdfGrid.DataSource = tableData;

我们已经为该示例创建了示例,可以从下面的链接下载该示例,

Sample for export data to PDF grid