TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Goran Bibic
484
2.9k
196k
Itext pdf print after selection index changed in combobox?
Jul 3 2018 2:21 AM
Itext pdf print after selection index changed in combobox
After selection index changed have new values in datagrid print empty
Have header no have datagrid
Simle pdf document
private
void
pdfButton_Click(object sender, EventArgs e)
{
//Creating iTextSharp Table from the DataTable data
PdfPTable pdfTable =
new
PdfPTable(prijava_radnikaDataGridView.ColumnCount);
pdfTable.DefaultCell.Padding = 3;
pdfTable.WidthPercentage = 100;
pdfTable.HorizontalAlignment = Element.ALIGN_CENTER;
pdfTable.DefaultCell.BorderWidth = 1;
float
[] widths =
new
float
[] { 18f, 40f, 35f, 35f};
pdfTable.SetWidths(widths);
BaseFont bfCalibri = BaseFont.CreateFont(
"c:\\windows\\fonts\\calibri.ttf"
, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
iTextSharp.text.Font calibri =
new
iTextSharp.text.Font(bfCalibri, 10, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.WHITE);
iTextSharp.text.Font calibri2 =
new
iTextSharp.text.Font(bfCalibri, 9);
//Adding Header row
foreach (DataGridViewColumn column in prijava_radnikaDataGridView.Columns)
{
PdfPCell cell =
new
PdfPCell(
new
Phrase(column.HeaderText, calibri));
cell.BackgroundColor =
new
BaseColor(89, 135, 178);
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
pdfTable.AddCell(cell);
}
//Adding DataRow
foreach (DataGridViewRow row in prijava_radnikaDataGridView.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
pdfTable.AddCell(
new
PdfPCell(
new
Phrase(cell.Value.ToString(), calibri2)));
}
}
//Exporting to PDF
string folderPath =
"C:\\PDFs\\"
;
if
(!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
using
(FileStream stream =
new
FileStream(folderPath +
"Izvještaj nabavke po dobavljacima.pdf"
, FileMode.Create))
{
iTextSharp.text.Font calibriTitle =
new
iTextSharp.text.Font(bfCalibri, 14);
iTextSharp.text.Font calibriSubTitle =
new
iTextSharp.text.Font(bfCalibri, 10);
iTextSharp.text.Font calibrinaslov =
new
iTextSharp.text.Font(bfCalibri, 16);
Document pdfDoc =
new
Document(PageSize.A4, 27f, 10f, 10f, 30f);
// PdfWriter.GetInstance(pdfDoc, stream);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
pdfDoc.Add(
new
ListItem(
" "
));
pdfDoc.Add(
new
ListItem(
" "
));
pdfDoc.Add(
new
ListItem(
" Izvještaj nabavke po dobavljacima"
, calibrinaslov));
pdfDoc.Add(
new
ListItem(
" "
));
pdfDoc.Add(
new
ListItem(
" "
));
pdfDoc.Close();
stream.Close();
System.Diagnostics.Process.Start(folderPath +
"Izvještaj nabavke po dobavljacima.pdf"
);
}
}
Datagrid creted on this way
private
void
radni_sati_radnika_zbirno()
{
using
(SqlConnection openCon =
new
SqlConnection(cs))
{
string saveStaff =
" declare @filterDate date; SELECT [radnik] as Radnik, "
// + "DATEADD(DAY, DATEDIFF(DAY, 0, vrijemeprijave), 0) AS [Datum] , "
+
"SUM(cast((CASE WHEN DATEPART(WEEKDAY, vrijemeprijave) in (1, 7) then 0 else (CASE WHEN(DATEDIFF(SECOND, vrijemeprijave, vrijemeodjave) / 3600) > 8 THEN 8 ELSE(DATEDIFF(SECOND, vrijemeprijave, vrijemeodjave) / 3600) END) end)as float)) AS 'radni_sati',"
+
"SUM(cast((CASE WHEN DATEPART(WEEKDAY, vrijemeodjave) in (1, 7) then(DATEDIFF(SECOND, vrijemeprijave, vrijemeodjave) / 3600) else(case when(DATEDIFF(SECOND, vrijemeprijave, vrijemeodjave) / 3600) > 8 then((DATEDIFF(SECOND, vrijemeprijave, vrijemeodjave) / 3600) - 8) ELSE 0 END) end)as float)) AS 'Prekovremeni'"
+
"from [prijava_radnika]"
+
"where MONTH([vrijemeprijave]) = '"
+ mjeseccomboBox.Text.ToString() +
"' "
+
"group by [radnik]"
;
openCon.Open();
using
(SqlDataAdapter querySaveStaff =
new
SqlDataAdapter(saveStaff, cs))
{
DataTable dt =
new
DataTable();
DataColumn column =
new
DataColumn();
column.DataType = System.Type.GetType(
"System.Int32"
);
column.ColumnName =
"redni_broj"
;
column.AutoIncrement =
true
;
column.AutoIncrementSeed = 1;
column.AutoIncrementStep = 1;
dt.Columns.Add(column);
int
index = -1;
foreach (DataRow row in dt.Rows)
{
row.SetField(column, ++index);
}
querySaveStaff.Fill(dt);
prijava_radnikaDataGridView.DataSource = dt;
prijava_radnikaDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
prijava_radnikaDataGridView.Columns[
"redni_broj"
].FillWeight = 150;
prijava_radnikaDataGridView.Columns[
"radnik"
].FillWeight = 350;
//radnik
prijava_radnikaDataGridView.Columns[
"radni_sati"
].FillWeight = 150;
//radni sati
prijava_radnikaDataGridView.Columns[
"Prekovremeni"
].FillWeight = 150;
//prekovremeni
prijava_radnikaDataGridView.Update();
prijava_radnikaDataGridView.Refresh();
}
}
}
Reply
Answers (
1
)
sum of value not showing
How can we send sharepoint list item's data to Maximo?