public virtual CrystalDecisions.CrystalReports.Engine.ReportDocument CreateReport()
        {
            OutstandingCrystalReport rpt = new OutstandingCrystalReport();

            rpt.Site = this.Site;
            return(rpt);
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            if (nameBox.Text == "")
            {
                MessageBox.Show("Please select name first");
                this.Enabled = true;
                listView1.Items.Clear();
                return;
            }
            if (File.Exists(Path.Combine(".\\Outstanding_Report.pdf")))
            {
                File.Delete(Path.Combine(".\\Outstanding_Report.pdf"));
            }

            ReportDataSet outstandingDataSet = new ReportDataSet();
            //DataSet1 expDataSet = new DataSet1();
            DataTable tempDataTable = outstandingDataSet.Tables.Add("Items");

            tempDataTable.Columns.Add("from");
            tempDataTable.Columns.Add("to");
            tempDataTable.Columns.Add("date");
            tempDataTable.Columns.Add("name");
            tempDataTable.Columns.Add("file_no");
            tempDataTable.Columns.Add("slip_no");
            tempDataTable.Columns.Add("remarks");
            tempDataTable.Columns.Add("amount", Type.GetType("System.Double"));
            tempDataTable.Columns.Add("total_amount", Type.GetType("System.Double"));
            tempDataTable.Columns.Add("total_received", Type.GetType("System.Double"));
            tempDataTable.Columns.Add("total_balance", Type.GetType("System.Double"));
            tempDataTable.Columns.Add("received", Type.GetType("System.Double"));
            tempDataTable.Columns.Add("companyntnno");
            tempDataTable.Columns.Add("companystrno");

            //adding values
            DataRow row = tempDataTable.NewRow();

            row["from"]         = dateTimeFrom.Text;
            row["to"]           = dateTimeTo.Text;
            row["name"]         = nameBox.Text;
            row["companyntnno"] = Sqlite.ntnnumber;
            row["companystrno"] = Sqlite.strnumber;

            int j = 0;

            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (j == 0)
                {
                    j++;
                }
                else
                {
                    row = tempDataTable.NewRow();
                }
                row["date"]           = listView1.Items[i].SubItems[0].Text;
                row["file_no"]        = listView1.Items[i].SubItems[2].Text;
                row["slip_no"]        = listView1.Items[i].SubItems[3].Text;
                row["remarks"]        = listView1.Items[i].SubItems[4].Text;
                row["amount"]         = listView1.Items[i].SubItems[5].Text == "" ? 0 : Convert.ToDouble(listView1.Items[i].SubItems[5].Text);
                row["received"]       = listView1.Items[i].SubItems[6].Text == "" ? 0 : Convert.ToDouble(listView1.Items[i].SubItems[6].Text);
                row["total_amount"]   = Convert.ToDouble(total_amount.Text);
                row["total_received"] = Convert.ToDouble(total_Rec.Text);
                row["total_balance"]  = Convert.ToDouble(total_bal.Text);

                tempDataTable.Rows.Add(row);
            }

            OutstandingCrystalReport crystalReport = new OutstandingCrystalReport();

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

            //if we are dealing with databaser
            //crystalReport.Load("C:\\Users\\moheb\\Desktop\\labaratory_data\\labaratory_data\\CrystalReport1.rpt");

            //if want to show view crystal viewer
            //crystalReportViewer1.ReportSource = crystalReport;
            //crystalReportViewer1.Refresh();

            try
            {
                ExportOptions CrExportOptions;
                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                PdfRtfWordFormatOptions    CrFormatTypeOptions          = new PdfRtfWordFormatOptions();
                CrDiskFileDestinationOptions.DiskFileName = ".\\Outstanding_Report.pdf";
                CrExportOptions = crystalReport.ExportOptions;
                {
                    CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                    CrExportOptions.ExportFormatType      = ExportFormatType.PortableDocFormat;
                    CrExportOptions.DestinationOptions    = CrDiskFileDestinationOptions;
                    CrExportOptions.FormatOptions         = CrFormatTypeOptions;
                }
                crystalReport.Export();

                //opens the pdf stored
                System.Diagnostics.Process.Start(@".\\Outstanding_Report.pdf");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                this.Enabled = true;
            }
        }