Showing posts with label Crystal Report. Show all posts
Showing posts with label Crystal Report. Show all posts

Monday, August 22, 2011

Crystal Reports in Microsoft Visual Studio 2010 and issues for depoymentment

Microsoft Visual Studio 2010 no longer includes Crystal Reports in the bundle.

In Visual Studio 2010, to create a Crystal Reports project or Web site or to import existing projects
or Web sites that were created by using older versions of Visual Studio or Crystal Reports, you must
first install a version of Crystal Reports that is compatible with Visual Studio 2010.

For more information about how to use Crystal Reports in Visual Studio 2010, visit the following SAP
Crystal Reports website:
http://www.sap.com/crystalreports/vs2010

Licensing:
Developers can use Crystal Reports for Visual Studio to do the following:


  • Design unlimited reports for use in Visual Studio applications with the integrated Crystal Reports designer.


  • Integrate the Crystal Reports run time engine into thick client Microsoft Windows applications.
    • Thick client applications with the embedded run time engine can be freely redistributed both within
      and outside the developers' own organization.


  • Integrate the Crystal Reports run time engine into Web applications.
    • Web applications with the embedded run time engine can be freely redistributed within the developers ' own organization.


Microsoft provides third-party contact information to help you find technical support. This contact information may
change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.

The following visual studio addons for using crystal are available here.
  • Standard EXE installation package which installs SAP Crystal Reports for Visual Studio into the
    Visual Studio 2010 IDE.

  • Click-Once installation package used to create self-updating Windows-based applications which
    can be installed and run with minimal user interaction..

  • Merge Modules installation package used to install components which are shared by multiple
    applications..

  • Redistributable installation (32 bit).

  • Redistributable installation (64 bit).

I hope this saves some time for you.

Wednesday, August 17, 2011

Email Exported Crystal Reports and devexpress XtraReports as pdf from C# Application


Using Devexpress Report to mail pdf:
this Code Snippet automatically send a report via e-mail. To do this, a report should first be
exported into one of the available formats. In this example, a report is exported to PDF, since
this format provides the best output quality (the PDF result is as close to a report's print result
as possible).

To do as we want first export the report to Memory Stream and add the attachment to System.Net.
MailMessage Object.. then provide the credenitials of the smtp server to send email, finally send the
email SmtpClient object.
  
private void SendExportedReportPDFAsEmail_Click(object sender, EventArgs e) 
{
     try
      {
         // Create a new report
.           EmployeeReport report = new EmployeeReport();
          // Create a new memory stream and export the report into it as PDF. 
         MemoryStream mem = new MemoryStream();
         report.ExportToPdf(mem);
          // Create a new attachment and put the PDF report into it. 
         mem.Seek(0, System.IO.SeekOrigin.Begin); 
        Attachment attachment = new Attachment(mem, "TestReport.pdf", "application/pdf"); 
         // Create a new message and attach the PDF report to it. 
         MailMessage mail = new MailMessage();
         mail.Attachments.Add(attachment);
          // Specify sender and recipient options for the e-mail message. 
         mail.From = new MailAddress("your Email Address", "Someone"); 
        mail.To.Add(new MailAddress(report.ExportOptions.Email.RecipientAddress, 
                                                                        report.ExportOptions.Email.RecipientName)); 
         // Specify other e-mail options. 
         mail.Subject = report.ExportOptions.Email.Subject; 
        mail.Body = "This is a test e-mail message sent by an application."
         // Send the e-mail message via the specified SMTP server. 
         SmtpClient smtp = new SmtpClient("smtp.yourdomain.com"); e.g. smtp.gmail.com 
        smtp.Send(mail);
        // Close the memory stream. 
         mem.Close();
         mem.Flush();
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, "Error sending a report.\n" + ex.ToString());
     }
 } 
Using Microsoft Crystal Report:
Here i am using 3 button on for exporting the document to the file system and then attach the
exported document to the email attachment.
public partial class EmployeeReportForm: Form
{
ReportDocument cryRpt;
string pdfFile = "c:\\employeedetails.pdf";
public EmployeeReportForm()
{
InitializeComponent();
}
private void LoadReport_Click(object sender, EventArgs e)

{

cryRpt = new ReportDocument();

cryRpt.Load(PUT CRYSTAL REPORT PATH HERE\\EmployeeReport.rpt");

crystalReportViewer1.ReportSource = cryRpt;

crystalReportViewer1.Refresh();

}

private void ExportReportFileAndEmail_Click(object sender, EventArgs e)

{

try

{

ExportOptions CrExportOptions ;

DiskFileDestinationOptions CrDiskFileDestinationOptions =

             new DiskFileDestinationOptions();

PdfRtfWordFormatOptions CrFormatTypeOptions =

                                            new PdfRtfWordFormatOptions();

CrDiskFileDestinationOptions.DiskFileName = pdfFile;

CrExportOptions = cryRpt.ExportOptions;

CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;

CrExportOptions.FormatOptions = CrFormatTypeOptions;

cryRpt.Export();

sendmail();

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString());

}

}

private void sendmail()

{

try {

SmtpMail.SmtpServer.Insert(0, "your hostname");

MailMessage Msg = new MailMessage();

Msg.To = "to address here";

Msg.From = "from address here";

Msg.Subject = "Crystal Report Attachment ";

Msg.Body = "Crystal Report Attachment ";

Msg.Attachments.Add(new MailAttachment(pdfFile));

System.Web.Mail.SmtpMail.Send(Msg);

}

catch (Exception ex)
{

MessageBox.Show (ex.ToString());

}

}

}

}
try to use correct smtp server details for sending email correctly..

if mail failed the use the smtp client credentials as:

smtpClient.Credentials = new System.Net.NetworkCredential("MailUser", "MailPass"); 

 smtpClient.UseDefaultCredentials = false;
 

Tuesday, February 15, 2011

crystal report bind to database

SqlConnection con = new SqlConnection("database=.;initial catalog=navodya_vidyalya; integrated security=true;");

            con.Open();

            SqlCommand adap = new SqlCommand("show", con);

            adap.CommandType = CommandType.StoredProcedure;

            adap.Parameters.AddWithValue("@name", textBox1.Text);

           SqlDataReader rd= adap.ExecuteReader();

           DataTable dt = new DataTable();

           dt.Load(rd);

crystal report data bind

SqlConnection con = new SqlConnection("database=.;initial catalog=navodya_vidyalya; integrated security=true;");

SqlDataAdapter adap = new SqlDataAdapter("select id,value from query", con);

DataSet ds = new DataSet();

adap.Fill(ds);

CrystalReport1 ob = new CrystalReport1();

ob.SetDataSource(ds.Tables[0]);

ob.SetParameterValue("manu", textBox1.Text);

crystalReportViewer1.ReportSource = ob;