Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I think this should be simple but I just don't know where to start. I have a listview full of items from a SQLite db and I want to send that to the printer or save as PDF.

Any help would be appreciated.

What I have tried:

Here is the listview item source:
private void fillRcvStats()
        {
            var RcvTotals = new ObservableCollection<Rcv>();
            var db = new SqliteConnection("Filename=VollyStats.db");
            db.Open();
            string str = "SELECT Players.FirstName, COUNT(distinct SetNum), COUNT(distinct MID)," +
                " SUM(CASE WHEN TouchQ = '1' THEN 1 ELSE 0 END), SUM(CASE WHEN TouchQ = '2' THEN 1 ELSE 0 END)," +
                " SUM(CASE WHEN TouchQ = 'Error' THEN 1 ELSE 0 END)" +
                " FROM Stats  inner join Players on Stats.PlyrID = Players.PlyrID " + DMID + " TouchT = 'Receive' GROUP BY Players.FirstName";
            SqliteCommand cmd = new SqliteCommand(str, db);

            SqliteDataReader reader = cmd.ExecuteReader();
            RcvTotals.Clear();
            while (reader.Read())
            {
                string RPLYR = reader.GetValue(0).ToString();
                int RSP = int.Parse(reader.GetValue(1).ToString());
                int RMP = int.Parse(reader.GetValue(2).ToString());
                int R1 = int.Parse(reader.GetValue(3).ToString());
                int R2 = int.Parse(reader.GetValue(4).ToString());
                int RERR = int.Parse(reader.GetValue(5).ToString());
                int TR = (R1 + R2);
                int R_S = (R1 + R2) / RSP;
                int R_M = (R1 + R2) / RMP;

                RcvTotals.Add(new Rcv(RPLYR, RSP, R1, R2, TR, RERR, R_S, R_M));
            }
            reader.Close();
            db.Close();
            RCVLV.ItemsSource = RcvTotals;
        }
Posted
Updated 13-Jan-19 12:52pm
Comments
Maciej Los 14-Jan-19 6:50am    
What's your issue?

First of all, don't concatenate values into a SQL string. This leaves you wide open to SQL injections. Instead, use SqliteParameter.

What comes to creating the PDF, perhaps you could use GitHub - itext/itextsharp: .NET port of the iText library[^]
 
Share this answer
 
Comments
Member 14087194 13-Jan-19 13:24pm    
Thank you for the info on the SQL injection, I learned what it means and am now changing a lot of code.

Still have not figured out the printing....
Wendelius 13-Jan-19 13:36pm    
Would it be possible just to save the data into PDF and then print the PDF?

An alternative for itextsharp could be pdfsharp. Have a look at Home of PDFsharp and MigraDoc Foundation - PDFsharp & MigraDoc[^] for instructions on printing see PDF Generation and Printing in .NET[^]
string _fileName = "";

_fileName = GetSaveDialogFileName(defFileName, ".pdf", "Pdf documents (.pdf)|*.pdf");
                   if (_fileName == "")
                       return;

public static string GetSaveDialogFileName(string defaultFileName, string defaultExt, string filter)
       {
           string saveFileName = "";
           Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
           dlg.FileName = defaultFileName; // Default file name
           dlg.DefaultExt = defaultExt;
           dlg.Filter = filter;
           if (dlg.ShowDialog() == true)
               saveFileName = dlg.FileName;

           return saveFileName;
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900