I want print button on each row inside Gridview. When I click on print button in any row. It must generate invoice in following format.
Invoice Number: R-0004
Invoice Date:06-07-2023 Customer Name: Customer
Invoice Details
-------------------------------------------------------------
S.I Product Name Quantity Price Total
1 ABC 1 350 350
2 SKY 2 250 500
---------------------------------------------------------------
Total Payment : 850
Page 1
<%@ Page Title="Print Bill" Language="C#" MasterPageFile="~/Inventory.master" AutoEventWireup="true"
CodeFile="frmSaleReciept.aspx.cs" Inherits="frmSaleReciept" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$("[src*=plus]").live("click", function () {
$(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
$(this).attr("src", "images/minus.png");
});
$("[src*=minus]").live("click", function () {
$(this).attr("src", "images/plus.png");
$(this).closest("tr").next().remove();
});
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=btnReci]").click(function () {
$("[id*=hfGridHtml]").val($(".Container").html());
});
});
</script>
<div class="Container" >
<div class="modal-body">
<div class="form-group">
<div class="row">
<div class="col-sm-3">
<label class="control-label" style="margin-top: 10px;">
Reciept No.</label>
<asp:TextBox ID="txtANote" runat="server" class="form-control" placeholder="Recipet No"></asp:TextBox>
</div>
<br />
<div class="col-sm-6">
<asp:Button ID="btnCust" Text="Get Data" runat="server" Class="btn btn-info" onclick="btnCust_Click"
/>
<asp:Button ID="btnReci" Text="Reciept" runat="server" Class="btn btn-danger"
onclick="btnReci_Click" />
</div>
</div>
</div>
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" CssClass="table table-striped table-bordered table-hover"
RowStyle-Wrap="false" HeaderStyle-Wrap="false" DataKeyNames="InvoiceNo"
OnRowDataBound="OnRowDataBound"
onselectedindexchanged="gvCustomers_SelectedIndexChanged">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img alt="" style="cursor: pointer" src="images/plus.png" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" CssClass="table table-striped table-bordered table-hover"
RowStyle-Wrap="false" HeaderStyle-Wrap="false">
<Columns>
<asp:TemplateField HeaderText="Sr. No." ItemStyle-Width="100">
<ItemTemplate>
<asp:Label ID="lblRowNumber" Text='<%# Container.DataItemIndex + 1 %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="150px" DataField="InvoiceNo" HeaderText="Invoice No" />
<asp:BoundField ItemStyle-Width="150px" DataField="BrandID" HeaderText="Product Code" />
<asp:BoundField ItemStyle-Width="150px" DataField="BrandName" HeaderText="Product Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="Qty" HeaderText="Quantity" />
<asp:BoundField ItemStyle-Width="150px" DataField="Price" HeaderText="Price" />
<asp:BoundField ItemStyle-Width="150px" DataField="InvoiceDate" HeaderText="Sale Date" />
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="150px" DataField="InvoiceNo" HeaderText="Invoice No." />
<asp:BoundField ItemStyle-Width="150px" DataField="InvoiceDate" HeaderText="Sold Date" />
<asp:BoundField ItemStyle-Width="150px" DataField="GrandTotal" HeaderText="Grand Total" />
<asp:BoundField ItemStyle-Width="150px" DataField="TotalPayment" HeaderText="Paid" />
<asp:BoundField ItemStyle-Width="150px" DataField="PaymentDue" HeaderText="Due" />
<asp:BoundField ItemStyle-Width="150px" DataField="CName" HeaderText="Customer" />
<asp:BoundField ItemStyle-Width="150px" DataField="CPhone" HeaderText="Phone No." />
</Columns>
</asp:GridView>
<br />
<br />
</div>
</div>
</asp:Content>
protected void btnReci_Click(object sender, EventArgs e)
{
GetInvoice();
}
private void GetInvoice()
{
int i = 0;
string Inv = null;
string Date = null;
string GTotal = null;
string TPayment = null;
string Name = null;
string Phone = null;
string Status = null;
int j = 0;
string si = null;
string Invo = null;
string Code = null;
string PName = null;
string Qty = null;
string Price = null;
string SDate = null;
int rc = 0;
Response.ContentType = "application/pdf";
//Response.AddHeader("content-disposition", "attachment;filename=" + txtANote.Text.Trim() + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Document doc = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.GetInstance(doc, Response.OutputStream);
try
{
doc.Open();
BaseFont bf = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\ARIALUNI.TTF", BaseFont.IDENTITY_H, true);
iTextSharp.text.Font boldFont = new iTextSharp.text.Font(bf, 9, iTextSharp.text.Font.NORMAL);
iTextSharp.text.Font headFont = new iTextSharp.text.Font(bf, 12, iTextSharp.text.Font.NORMAL);
iTextSharp.text.Font bodyFont = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL);
con = new SqlDbConnect();
con.SqlQuery("select logo,SystemName,Address,Phone,Email FROM tblSystem");
con.RdrEx();
while (con.Rdr.Read())
{
PdfPTable table10 = new PdfPTable(2);
table10.DefaultCell.Padding = 10f;
table10.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
table10.DefaultCell.Border = 0;
table10.HorizontalAlignment = Element.ALIGN_CENTER;
table10.TotalWidth = 500f;
table10.LockedWidth = true;
float[] widths1 = new float[] { 0.5f, 0.5f }; //{ 0.7f, 3f };
table10.SetWidths(widths1);
//table1.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
Byte[] bytes = (Byte[])con.Rdr[0];
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(bytes);
image.ScaleAbsolute(35f, 30f);
PdfPCell bottom10 = new PdfPCell((image));
bottom10.Padding = 5f;
bottom10.BackgroundColor = iTextSharp.text.Color.WHITE;
bottom10.Border = 0;
bottom10.HorizontalAlignment = 0;
table10.AddCell(bottom10);
PdfPTable nested10 = new PdfPTable(1);
float[] width = new float[] { 0.2f };
nested10.SetWidths(width);
nested10.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
nested10.DefaultCell.Padding = 7f;
nested10.DefaultCell.HorizontalAlignment = 1;
nested10.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
nested10.DefaultCell.Border = 0;
nested10.AddCell(new Phrase("", headFont));
nested10.AddCell(new Phrase("", headFont));
nested10.AddCell(new Phrase("", headFont));
//nested1.AddCell(new Phrase("Email: " + con.Rdr[4].ToString() + "\t Phone No: " + con.Rdr[3].ToString(), FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12)));
PdfPCell nesthousing10 = new PdfPCell(nested10);
nesthousing10.Colspan = 2;
nesthousing10.Padding = 0f;
nesthousing10.Border = 0;
table10.AddCell(nesthousing10);
doc.Add(table10);
Paragraph p = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(1.0F, 100.0F, iTextSharp.text.Color.BLACK, Element.ALIGN_LEFT, 1)));
doc.Add(p);
}
con.conClose();
con = new SqlDbConnect();
con.SqlQuery("select QrCode,SystemName,Address,Phone,Email FROM tblSystem");
con.RdrEx();
while (con.Rdr.Read())
{
PdfPTable table1 = new PdfPTable(2);
table1.DefaultCell.Padding = 10f;
table1.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
table1.DefaultCell.Border = 0;
table1.HorizontalAlignment = Element.ALIGN_CENTER;
table1.TotalWidth = 500f;
table1.LockedWidth = true;
float[] widths1 = new float[] { 0.5f, 0.5f }; //{ 0.7f, 3f };
table1.SetWidths(widths1);
table1.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
Byte[] bytes = (Byte[])con.Rdr[0];
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(bytes);
image.ScaleAbsolute(120f, 100f);
PdfPCell bottom1 = new PdfPCell((image));
bottom1.Padding = 5f;
bottom1.BackgroundColor = iTextSharp.text.Color.WHITE;
bottom1.Border = 0;
bottom1.HorizontalAlignment = 2;
table1.AddCell(bottom1);
PdfPTable nested1 = new PdfPTable(1);
float[] width = new float[] { 0.2f };
nested1.SetWidths(width);
nested1.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
nested1.DefaultCell.Padding = 7f;
nested1.DefaultCell.HorizontalAlignment = 2;
nested1.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
nested1.DefaultCell.Border = 0;
nested1.AddCell(new Phrase(con.Rdr[1].ToString(), headFont));
nested1.AddCell(new Phrase(con.Rdr[2].ToString(), headFont));
nested1.AddCell(new Phrase("", headFont));
//nested1.AddCell(new Phrase("Email: " + con.Rdr[4].ToString() + "\t Phone No: " + con.Rdr[3].ToString(), FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12)));
PdfPCell nesthousing1 = new PdfPCell(nested1);
nesthousing1.Colspan = 2;
nesthousing1.Padding = 0f;
nesthousing1.Border = 0;
table1.AddCell(nesthousing1);
doc.Add(table1);
}
con.conClose();
DataTable dt = new DataTable("GridView_Data");
foreach (GridViewRow row in gvCustomers.Rows)
{
Inv = row.Cells[1].Text;
Date = row.Cells[2].Text;
GTotal = row.Cells[3].Text;
TPayment = row.Cells[4].Text;
Name = row.Cells[5].Text;
Phone = row.Cells[6].Text;
PdfPTable table = new PdfPTable(6);
table.DefaultCell.Padding = 10f;
table.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
table.DefaultCell.BorderColor = new iTextSharp.text.Color(191, 208, 247);
table.HorizontalAlignment = Element.ALIGN_CENTER;
table.DefaultCell.HorizontalAlignment = 1;
table.TotalWidth = 500f;
table.LockedWidth = true;
table.SpacingBefore = 5f;
float[] width315 = new float[] { 0.01f, 0.09f, 0.03f, 0.03f, 0.03f, 0.03f };
table.SetWidths(width315);
table.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
// table.DefaultCell.Border = PdfPCell.NO_BORDER;
// table.DefaultCell.CellEvent = new RoundedBorder();
PdfPTable nested = new PdfPTable(4);
float[] width31 = new float[] { 0.1f, 0.1f, 0.1f, 0.1f };
nested.SetWidths(width31);
nested.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
nested.DefaultCell.BorderColor = new iTextSharp.text.Color(191, 208, 247);
nested.DefaultCell.Padding = 5f;
nested.DefaultCell.Border = 0;
nested.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
nested.AddCell(new Phrase("فاتورتہ ضریبیتہ", headFont));
nested.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase(Inv, FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 14)));
nested.AddCell(new Phrase("Tax Invoice", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12)));
//nested.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("", headFont));
nested.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase("شرکتہ رحماء للخدمات الطبیتہ ۰۵۰۷۵۳۰۵۳۰", headFont));
nested.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA, 8)));
//nested.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("311251208600003", FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("#TIN", headFont));
nested.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase("تاریخ الفاتورتہ:", headFont));
nested.AddCell(new Phrase(Date, FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase(":Invoice Date", headFont));
nested.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase("تاریخ الاستحقاق:", headFont));
nested.AddCell(new Phrase(Date, FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase(":Due Date", headFont));
nested.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase("تاریخ التوصیل:", headFont));
nested.AddCell(new Phrase(Date, FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase(":Delievery Date", headFont));
PdfPCell nesthousing = new PdfPCell(nested);
nesthousing.BackgroundColor = iTextSharp.text.Color.WHITE;
nesthousing.BorderColor = new iTextSharp.text.Color(191, 208, 247);
nesthousing.Colspan = 6;
nesthousing.Padding = 0f;
// nesthousing.Border = PdfPCell.NO_BORDER;
// nesthousing.CellEvent = new RoundedBorder();
table.AddCell(nesthousing);
GridView gvResult = (row.FindControl("gvOrders") as GridView);
PdfPCell head1 = new PdfPCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
head1.BackgroundColor = new iTextSharp.text.Color(191, 208, 247);
head1.BorderColor = new iTextSharp.text.Color(191, 208, 247);
head1.Indent = 10;
head1.HorizontalAlignment = 1;
head1.Colspan = 6;
head1.Padding = 3;
//head1.Border = PdfPCell.NO_BORDER;
// head1.CellEvent = new RoundedBorder();
table.AddCell(head1);
PdfPTable nested14 = new PdfPTable(6);
nested14.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
nested14.DefaultCell.BorderColor = new iTextSharp.text.Color(191, 208, 247);
nested14.DefaultCell.Padding = 3f;
nested14.DefaultCell.Border = 0;
nested14.DefaultCell.HorizontalAlignment = 1;
float[] width3156 = new float[] { 0.01f, 0.09f, 0.03f, 0.03f, 0.03f, 0.03f };
nested14.SetWidths(width3156);
nested14.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
//nested14.AddCell(new Phrase("Taxes", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
//nested14.AddCell(new Phrase("Amount", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested14.AddCell(new Phrase("Total Price-السعر الاجمالی", bodyFont));
nested14.AddCell(new Phrase("Amount-مبلغ", bodyFont));
nested14.AddCell(new Phrase("Unit Price-سعر الواحدتہ", bodyFont));
nested14.AddCell(new Phrase("Quantity-الکمیتہ", bodyFont));
nested14.AddCell(new Phrase("Description-الوصف", bodyFont));
nested14.AddCell(new Phrase("S.I", bodyFont));
PdfPCell nesthousing14 = new PdfPCell(nested14);
nesthousing14.BackgroundColor = iTextSharp.text.Color.WHITE;
nesthousing14.BorderColor = new iTextSharp.text.Color(191, 208, 247);
nesthousing14.Colspan = 6;
nesthousing14.Padding = 3f;
// nesthousing14.Border = PdfPCell.NO_BORDER;
// nesthousing14.CellEvent = new RoundedBorder();
table.AddCell(nesthousing14);
for (j = 0; j < gvResult.Rows.Count; j++)
{
si = gvResult.Rows[j].Cells[0].Text;
rc = gvResult.Rows.Count;
PName = gvResult.Rows[j].Cells[3].Text;
Qty = gvResult.Rows[j].Cells[4].Text;
Price = gvResult.Rows[j].Cells[5].Text;
int num = 1;
int result = j + num;
table.AddCell(new Phrase(Price.ToString(), bodyFont));
table.AddCell(new Phrase(Price.ToString(), bodyFont));
table.AddCell(new Phrase(Price.ToString(), bodyFont));
table.AddCell(new Phrase(Qty + ".00 Units", bodyFont));
table.AddCell(new Phrase(PName.ToString(), bodyFont));
table.AddCell(new Phrase("" + result, bodyFont));
}
PdfPCell head7 = new PdfPCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
head7.Indent = 10;
head7.HorizontalAlignment = 1;
head7.Colspan = 6;
head7.Padding = 10;
head7.Border = 0;
table.AddCell(head7);
doc.Add(table); //
PdfPTable table21 = new PdfPTable(2);
table21.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
table21.DefaultCell.BorderColor = new iTextSharp.text.Color(191, 208, 247);
table21.DefaultCell.Padding = 7f;
table21.DefaultCell.Border = 1;
table21.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
table21.AddCell(new Phrase(TPayment.ToString() + ".00 SR", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table21.AddCell(new Phrase("الاجمالی الفرعی / Subtotal", headFont));
table21.AddCell(new Phrase(TPayment.ToString() + ".00 SR", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
table21.AddCell(new Phrase("المجموع / Total", headFont));
table21.AddCell(new Phrase("رقم اشارتہ الدفعتہ" , headFont));
table21.AddCell(new Phrase("" + Inv.ToString(), FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
doc.Add(table21);
doc.NewPage();
// doc.Add(table);
}
doc.Close();
}
catch (Exception e)
{
Response.Write(e.Message.ToString());
}
finally
{
Response.Write(doc);
Response.End();
}
}