protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ReportViewer1.Reset(); string id = Request.QueryString["id"]; int DebitNoteId = Decode(id); SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["RetailManagementConnectionString"].ConnectionString); SqlDataAdapter adp2 = new SqlDataAdapter("select * from DebitNotes where Id=" + DebitNoteId, con); DebitNotesDS ds2 = new DebitNotesDS(); con.Open(); adp2.Fill(ds2); ReportDataSource rds1 = new ReportDataSource("DataSet2", GetDs1(DebitNoteId)); ReportDataSource rds = new ReportDataSource("DataSet1", GetDs(DebitNoteId)); ReportDataSource rds2 = new ReportDataSource("DataSet3", GetDs2()); ReportDataSource rds3 = new ReportDataSource("DataSet4", GetDs3()); ReportViewer1.LocalReport.DataSources.Add(rds1); ReportViewer1.LocalReport.DataSources.Add(rds); ReportViewer1.LocalReport.DataSources.Add(rds2); ReportViewer1.LocalReport.DataSources.Add(rds3); ReportViewer1.LocalReport.ReportPath = "ReportEngine/DebitNotePrePrinted.rdlc"; double grandtotal = Convert.ToDouble(ds2.Tables[1].Rows[0]["GrandTotal"]); string Words = NumberToWords(grandtotal); ReportParameter parameter = new ReportParameter("AmountInWords", (Words + " Only")); ReportViewer1.LocalReport.SetParameters(parameter); ReportViewer1.LocalReport.Refresh(); Warning[] warnings; string[] streamIds; string mimetype = string.Empty; string encoding = string.Empty; string extension = string.Empty; string title = "Retail Bill"; byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimetype, out encoding, out extension, out streamIds, out warnings); Response.Buffer = true; Response.Clear(); Response.ContentType = "application/pdf"; Response.BinaryWrite(bytes); Response.End(); string filename = "DebitNotePrePrinted.pdf"; string path = Server.MapPath("C"); FileStream file = new FileStream(path + "/" + filename, FileMode.OpenOrCreate, FileAccess.ReadWrite); file.Write(bytes, 0, bytes.Length); file.Dispose(); Response.Write(string.Format("<script>window.open('{0}','_blank');</script>", "DebitNotePrePrinted.aspx?file=" + filename)); } }
private DataTable GetDs1(int DId) { // SqlConnection con = new SqlConnection("Data Source=MARY-PC;Initial Catalog=A To Z Life Style(India) Pvt Ltd Retail 01-04-2016 To 31-03-2017;Integrated Security=True"); SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["RetailManagementConnectionString"].ConnectionString); SqlDataAdapter adp2 = new SqlDataAdapter("select * from DebitNotes where Id=" + DId, con); DebitNotesDS ds2 = new DebitNotesDS(); con.Open(); adp2.Fill(ds2); //find Challan no using primary key string DebitNoteNo = ds2.Tables[1].Rows[0]["DebitNoteNo"].ToString(); string purchasereturnno = ds2.Tables[1].Rows[0]["PurchaseReturnNo"].ToString(); Session["DebitNoteNo"] = DebitNoteNo; Session["PurchaseReturnNo"] = purchasereturnno; return(ds2.Tables[1]); }