Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How to make column headers in table appear bold while datas in table appear regular from c# windows forms with sql server2008 using iTextSharp

$
0
0

Hi my name is vishal

For past 10 days i have been breaking my head on how to make column headers in table appear bold while datas in table appear regular from c# windows forms with sql server2008 using iTextSharp.

Given below is my code in c# on how i export datas from different tables in sql server to PDF report using iTextSharp:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Diagnostics;
using System.IO;
namespace DRRS_CSharp
{
    public partial class frmPDF : Form
    {
        public frmPDF()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
Document doc = new Document(PageSize.A4.Rotate());
            var writer = PdfWriter.GetInstance(doc, new FileStream("AssignedDialyzer.pdf", FileMode.Create));
            doc.SetMargins(50, 50, 50, 50);
            doc.SetPageSize(new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.LETTER.Width, iTextSharp.text.PageSize.LETTER.Height));
            doc.Open();
            PdfPTable table = new PdfPTable(6);
            table.TotalWidth =530f;
            table.LockedWidth = true;
            PdfPCell cell = new PdfPCell(new Phrase("Institute/Hospital:AIIMS,NEW DELHI", FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.BOLD, BaseColor.BLACK)));
            cell.Colspan = 6;
            cell.HorizontalAlignment = 0;
            table.AddCell(cell);
            Paragraph para=new Paragraph("DCS Clinical Record-Assigned Dialyzer",FontFactory.GetFont("Arial",16,iTextSharp.text.Font.BOLD,BaseColor.BLACK));
            para.Alignment = Element.ALIGN_CENTER;
            iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance("logo5.png");
            png.ScaleToFit(105f, 105f);
            png.Alignment = Element.ALIGN_RIGHT;
            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
            SqlCommand cmd = new SqlCommand("Select d.dialyserID,r.errorCode,r.dialysis_date,pn.patient_first_name,pn.patient_last_name,d.manufacturer,d.dialyzer_size,r.start_date,r.end_date,d.packed_volume,r.bundle_vol,r.disinfectant,t.Technician_first_name,t.Technician_last_name from dialyser d,patient_name pn,reprocessor r,Techniciandetail t where pn.patient_id=d.patient_id and r.dialyzer_id=d.dialyserID and t.technician_id=r.technician_id and d.deleted_status=0 and d.closed_status=0 and pn.status=1 and r.errorCode<106 and r.reprocessor_id in (Select max(reprocessor_id) from reprocessor where dialyzer_id=d.dialyserID) order by pn.patient_first_name,pn.patient_last_name", conn);
            conn.Open();
SqlDataReader dr;
            dr = cmd.ExecuteReader();
table.AddCell("Reprocessing Date");
            table.AddCell("Patient Name");
            table.AddCell("Dialyzer(Manufacturer,Size)");
            table.AddCell("No.of Reuse");
            table.AddCell("Verification");
            table.AddCell("DialyzerID");
while (dr.Read())
            {
                table.AddCell(dr[2].ToString());
                table.AddCell(dr[3].ToString() +"_"+ dr[4].ToString());
                table.AddCell(dr[5].ToString() + "-" + dr[6].ToString());
                table.AddCell("@count".ToString());
                table.AddCell(dr[12].ToString() + "-" + dr[13].ToString());
                table.AddCell(dr[0].ToString());
                 }
dr.Close();
                    table.SpacingBefore = 15f;
                    doc.Add(para);
                    doc.Add(png);
                    doc.Add(table);
                    doc.Close();
                    System.Diagnostics.Process.Start("AssignedDialyzer.pdf");
                    if (MessageBox.Show("Do you want to save changes to AssignedDialyzer.pdf before closing?", "DRRS", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                    {
                        var writer2 = PdfWriter.GetInstance(doc, new FileStream("AssignedDialyzer.pdf", FileMode.Create));
                    }
                    else if (MessageBox.Show("Do you want to save changes to AssignedDialyzer.pdf before closing?", "DRRS", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation) == DialogResult.No)
                    {
                    this.Close();
                    }
}
 

The above code executes well with no problem at all!

As you can see the file to which i create and save and open my pdf report is AssignedDialyzer.pdf.

The column headers of table in pdf report from c# windows forms using iTextSharp are"Reprocessing Date","Patient Name","Dialyzer(Manufacturer,Size)","No.of Reuse","Verification" and"DialyzerID".

However the problem i am facing is after execution and opening of document is mycolumn headers in table in pdf report from c# and datas in it all appear in bold.

I have browsed through net regarding to solve this problem but with no success.

What i want is my pdf report from c# should be similar to following format which i was able to accomplish in vb6,adodb with MS access using iTextSharp.:

Given below is report which i have achieved from vb6,adodb with MS access using iTextSharp

I know that there has to be another way to solve my problem.I have browsed many articles in net regarding exporting sql datas to above format but with no success!

Is there is any another way to solve to my problem on exporting sql datas from c# windows forms using iTextSharp to above format given in the picture/image above?!

If so Then Can anyone tell me what modifications must i do in my c# code given above so that my pdf report from c# windows forms using iTextSharp will look similar to image/picture(pdf report) which i was able to accomplish fromvb6,adodb with ms access using iTextSharp?

I have approached Sound Forge.Net for help but with no success.

I hope anyone/someone truly understands what i am trying to ask!

I know i have to do lot of modifications in my c# code to achieve this level of perfection but i dont know how to do it.

Can anyone help me please! Any help/guidance in solving this problem would be greatly appreciated.

I hope i get a reply in terms of solving this problem.


vishal


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>