Example #1
0
        public virtual CrystalDecisions.CrystalReports.Engine.ReportDocument CreateReport()
        {
            LedgerCrystalReport rpt = new LedgerCrystalReport();

            rpt.Site = this.Site;
            return(rpt);
        }
Example #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            listView1.Items.Clear();
            SQLiteConnection scn = new SQLiteConnection(@"data source = main.db");

            scn.Open();
            SQLiteCommand sq;
            float         totalReceived = 0, totalAmount = 0, totalBalance = 0, total = 0, received = 0;

            SQLiteDataReader dr;

            if (nameBox.Text == "")
            {
                sq = new SQLiteCommand("select payer,sum(amount) as total,sum(received) as received from pay group by payer", scn);
            }
            else
            {
                sq = new SQLiteCommand("select payer,sum(amount) as total,sum(received) as received from pay where payer='" + nameBox.Text + "' group by payer", scn);
            }
            dr = sq.ExecuteReader();
            while (dr.Read())
            {
                total    = Convert.ToSingle(dr["total"].ToString());
                received = Convert.ToSingle(dr["received"].ToString());
                listView1.Items.Add(new ListViewItem(new[] { dr["payer"].ToString(),
                                                             dr["total"].ToString(),
                                                             dr["received"].ToString(),
                                                             (total - received).ToString() }));
                totalAmount   += float.Parse(dr["total"].ToString());
                totalReceived += float.Parse(dr["received"].ToString());
                totalBalance  += total - received;
            }
            total_amount.Text  = totalAmount.ToString();
            total_Rec.Text     = totalReceived.ToString();
            total_balance.Text = (totalAmount - totalReceived).ToString();

            LedgerDataSet ledDataSet = new LedgerDataSet();
            //DataSet1 expDataSet = new DataSet1();
            DataTable tempDataTable = ledDataSet.Tables.Add("Items");

            tempDataTable.Columns.Add("Name");
            tempDataTable.Columns.Add("Amount", Type.GetType("System.Int32"));
            tempDataTable.Columns.Add("Received", Type.GetType("System.Int32"));
            tempDataTable.Columns.Add("Balance", Type.GetType("System.Int32"));
            tempDataTable.Columns.Add("TotalAmount", Type.GetType("System.Int32"));
            tempDataTable.Columns.Add("TotalReceived", Type.GetType("System.Int32"));
            tempDataTable.Columns.Add("TotalBalance", Type.GetType("System.Int32"));

            //adding values
            DataRow row;

            for (int i = 0; i < listView1.Items.Count; i++)
            {
                row                  = tempDataTable.NewRow();
                row["Name"]          = listView1.Items[i].SubItems[0].Text;
                row["Amount"]        = Math.Round(Convert.ToDouble(listView1.Items[i].SubItems[1].Text));
                row["Received"]      = Math.Round(Convert.ToDouble(listView1.Items[i].SubItems[2].Text));
                row["Balance"]       = Math.Round(Convert.ToDouble(listView1.Items[i].SubItems[3].Text));
                row["TotalAmount"]   = Math.Round(Convert.ToDouble(total_amount.Text));
                row["TotalReceived"] = Math.Round(Convert.ToDouble(total_Rec.Text));
                row["TotalBalance"]  = Math.Round(Convert.ToDouble(total_balance.Text));
                tempDataTable.Rows.Add(row);
            }

            LedgerCrystalReport crystalReport = new LedgerCrystalReport();

            crystalReport.SetDataSource(ledDataSet.Tables[1]);

            try
            {
                ExportOptions CrExportOptions;
                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                PdfRtfWordFormatOptions    CrFormatTypeOptions          = new PdfRtfWordFormatOptions();
                CrDiskFileDestinationOptions.DiskFileName = ".\\Ledger_Report.pdf";
                CrExportOptions = crystalReport.ExportOptions;
                {
                    CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                    CrExportOptions.ExportFormatType      = ExportFormatType.PortableDocFormat;
                    CrExportOptions.DestinationOptions    = CrDiskFileDestinationOptions;
                    CrExportOptions.FormatOptions         = CrFormatTypeOptions;
                }
                crystalReport.Export();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }