المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : separate PDFs from the report



C# Programming
12-16-2009, 09:30 PM
I am using the code at the botoom to generate the monthly contracts invoices and save every invoice as a separate PDF I am generating all invoices to have the same GUID so it will be easier to retrieve all but it will be more than one invoice so for example they will all have same GUID but I will have 5 or 6 companies. I want to use the same code below to generate the separate PDFs using the invoice_number as file name.


private void generate_invoices()
{
this.Cursor = Cursors.WaitCursor;

// sql_connection = new SqlConnection("Data Source=.\\JASSIMSQL;initial catalog=takhlees;integrated security=true");
sql_connection = new SqlConnection(public_var.sql_server_connection);

try
{
sql_connection.Open();

sql_command = new SqlCommand("sp_get_account_book_by_book_guid", sql_connection);
sql_command.CommandType = CommandType.StoredProcedure;
// sql_command.Parameters.Add("@accounts_date", SqlDbType.DateTime).Value = current_date.ToShortDateString();
// sql_command.Parameters.Add("@account_number", SqlDbType.Int).Value = dateCurrentDate.SelectionRange.Start;
sql_command.Parameters.Add("@book_guid", SqlDbType.UniqueIdentifier).Value = book_guid;

DataSet data_set = new dsReports();

reportTICS.Reset();

sql_reader = sql_command.ExecuteReader();

data_set.Tables[0].Load(sql_reader);

// reportViewer1.LocalReport.ReportEmbeddedResource = "The_Internet_Cafe_System.ReportDaily.rdlc";
reportTICS.LocalReport.ReportEmbeddedResource = "dsReports_sp_get_account_book_by_book_guid";
// reportTICS.LocalReport.ReportPath = TICS_registry_current_user_reports.GetValue("ReportsFolder").ToString() + "\\" + TICS_registry_current_user_reports.GetValue("DailyReportFile").ToString();
reportTICS.LocalReport.ReportPath = @"C:\Users\Jassim\Documents\Visual Studio 2008\Projects\Takhlees\Takhlees\envoice.rdlc";

ReportDataSource rds = new ReportDataSource();
rds.Name = "dsReports_sp_get_account_book_by_book_guid";
rds.Value = data_set.Tables[0];
reportTICS.LocalReport.DataSources.Add(rds);

ReportDataSource rds2 = new ReportDataSource();
rds2.Name = "dsReports_sp_get_account_book_by_account_number";
rds2.Value = data_set.Tables[0];
reportTICS.LocalReport.DataSources.Add(rds2);

// ReportParameter report_date_parameter = new ReportParameter("paramDate", dateCurrentDate.SelectionRange.Start.ToShortDateString());
// reportTICS.LocalReport.SetParameters(new ReportParameter[] { report_date_parameter });

// ReportParameter header_parameter = new ReportParameter("paramHeader", "DAILY REPORT FOR " + dateCurrentDate.SelectionRange.Start.ToString("dd MMM yyyy"));
// reportTICS.LocalReport.SetParameters(new ReportParameter[] { header_parameter });

// ReportParameter footer_parameter = new ReportParameter("paramFooter", "Developed by: " + jassim_rahma_registry.GetValue("DeveloperName").ToString());
// reportTICS.LocalReport.SetParameters(new ReportParameter[] { footer_parameter });

// ReportParameter website_parameter = new ReportParameter("paramWebsite", jassim_rahma_registry.GetValue("DeveloperWebsite").ToString());
// reportTICS.LocalReport.SetParameters(new ReportParameter[] { website_parameter });

// ReportParameter cafe_name_parameter = new ReportParameter("paramCafeName", TICS_registry_current_user.GetValue("CafeName").ToString());
// reportTICS.LocalReport.SetParameters(new ReportParameter[] { cafe_name_parameter });

reportTICS.LocalReport.*******();

reportTICS.*******Report();

if (chkSaveInvoice.Checked == true)
{
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;

byte[] bytes = reportTICS.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);

string file_path = "c:\\temp\\envoice\\" + DateTime.Now.ToString("dd MMM yyyy");
System.IO.Directory.CreateDirectory(file_path);

// string file_namr = "c:\\temp\\envoice\\" + data_set.Tables[0].Rows.Count.ToString() + ".pdf";
string file_namr = file_path + "\\" + System.Guid.NewGuid() + ".pdf";

using (System.IO.FileStream fs = new System.IO.FileStream(file_namr, System.IO.FileMode.Create))
{
fs.Write(bytes, 0, bytes.Length);
}

Process.Start(file_path);
}

// this.Text = TICS_registry_current_user_reports.GetValue("DailyReportTitle").ToString();

// event_log.create_event("Daily Report was generated for " + dateCurrentDate.SelectionRange.Start.ToString("dd MMM yyyy"), EventLogEntryType.Information, 1000);

// sql_reader.Close();
// sql_connection.Close();

progressInvoice.Minimum = 0;
progressInvoice.Maximum = data_set.Tables[0].Rows.Count;
}
catch (Exception exp)
{
event_log.create_event("Problem preparing or viewing daily report." + Environment.NewLine + Environment.NewLine + exp.Message + Environment.NewLine + Environment.NewLine + exp.Data + Environment.NewLine + Environment.NewLine + exp.StackTrace + Environment.NewLine + Environment.NewLine + exp.InnerException, EventLogEntryType.Error, 9999);
MessageBox.Show("Problem preparing or viewing daily report!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
finally
{
if (sql_reader != null) sql_reader.Close();
if (sql_connection != null)
{
if (sql_connection.State == ConnectionState.Open)
sql_connection.Close();
}
}

this.Cursor = Cursors.Default;
}