Hi,
I want to develope a dll with the below code using .net class library project. I am not able to get some references. What are the name spaces i have to use in class library. Especially i am using crystal report viewer and set its visibility to false because i dont want to open the report with viewer instead i want to export it to pdf.
Please go thorugh the belwo code and respond me asap.
Thanks,
Raj
private void GenerateReport()
{
try
{
WriteError(
"Report Generation Started ......" + DateTime.Today.ToString("dd-mm-yy"));
Form1 form = new Form1();
form.Visible =
false;
ConnectionInfo crConnectionInfo = new ConnectionInfo();
ReportDocument rd = new ReportDocument();
WriteError(
"1");
rd.Load(
@"c:\Agreements.rpt");
WriteError(
"2");
crConnectionInfo.ServerName =
"BG4WS0268";
crConnectionInfo.DatabaseName =
"TestUMDB";
crConnectionInfo.IntegratedSecurity =
true;
// crConnectionInfo.UserID = "spdev";
// crConnectionInfo.Password = "spdev";
crDatabase = rd.Database;
crTables = crDatabase.Tables;
WriteError(
"3");
//ParameterField f1 = CrystalReportViewer1.ParameterFieldInfo[0];
//ParameterDiscreteValue v1 = new ParameterDiscreteValue();
// ParameterValues pv = new ParameterValues();
for (int i = 0; i < crTables.Count; i++)
{
crTable = crTables;
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
crTable.Location = crConnectionInfo.DatabaseName +
".dbo." +
crTable.Location.Substring(crTable.Location.LastIndexOf(
".") + 1);
}
WriteError(
"After FOR loop - 1");
crystalReportViewer1.ReportSource = rd;
WriteError(
"After FOR loop - 2");
crystalReportViewer1.Visible =
false;
string Directtoy = @"c:\Reports";
string FileName = "Agreements" + DateTime.Today.ToString("dd-mm-yy") + ".pdf";
if (!Directory.Exists(Directtoy))
{
Directory.CreateDirectory(Directtoy);
}
WriteError(
"After IF statement - 1");
rd.ExportToDisk(
ExportFormatType.PortableDocFormat, Directtoy + "/" + FileName);
WriteError(
"4");
form.Visible =
false;
form.Width = 0;
form.Height = 0;
sendmail(
"Your Report has been created under below path. <br/> The Path is Directtoy" + " / " + FileName);
WriteError(
"Report Generated Succesfully and a Email has been sent on" + DateTime.Today.ToString("dd-mm-yy"));
this.Close();
}
catch (Exception ex)
{
WriteError(ex.Message);
sendmail(ex.Message);
}
}
private static void WriteError(string errorMessage)
{
try
{
string Directtoy = @"c:\Errors";
string FileName = DateTime.Today.ToString("dd-mm-yy") + ".txt";
if (!Directory.Exists(Directtoy))
{
Directory.CreateDirectory(Directtoy);
}
// File.Create(Directtoy+ "/" + FileName);
using (StreamWriter w = File.AppendText(Directtoy + "/" + FileName))
{
w.WriteLine(
"\r\nLog Entry : ");
w.WriteLine(
"{0}", DateTime.Now.ToString(CultureInfo.InvariantCulture));
string err = "Error in: Creating Report" +
". Error Message:" + errorMessage;
w.WriteLine(err);
w.WriteLine(
"__________________________");
w.Flush();
w.Close();
}
}
catch (Exception ex)
{
WriteError(ex.Message);
}
}
private void sendmail(string body)
{
System.Web.Mail.
MailMessage message = new System.Web.Mail.MailMessage();
message.From =
"yagnaraja.mj@sonata-software.com";
message.To =
"yagnaraja.mj@sonata-software.com";
//message.To.Add(new MailAddress("sujitharaj.k@sonata-software.com"));
message.To =
"ashwini.k@sonata-software.com";
// message.Cc = "mallikarjunarao.av@sonata-software.com";
message.Subject =
"Report Generated Successfully";
message.Body = body;
message.BodyFormat =
MailFormat.Html;
// System.Web.Mail.MailAttachment attach = new MailAttachment(@"c:\\Agreements.pdf");
// message.Attachments.Add(attach);
SmtpMail.SmtpServer = "NANDIMSG.SONATA.LOCAL";
SmtpMail.Send(message);
}