Wednesday, November 18, 2015

PDF Display


   Document mydoc = new Document(PageSize.A4);
   PdfPTable table1 = new PdfPTable(5);
   Paragraph emptyparagraph = new Paragraph(" ");
   BaseFont bf = BaseFont.CreateFont("c:/windows/fonts/Tahoma.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
 
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpContext context = HttpContext.Current;
        HttpResponse response = context.Response;
        HttpSessionState Session = HttpContext.Current.Session;
     
     
        string destinationfilename = string.Empty;
            try
            {
                destinationfilename = HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"] + "documents\\" + Guid.NewGuid().ToString() + ".pdf";
         

                    printitem(destinationfilename);
                 //   StampPageNo(destinationfilename);
                    byte[] bytearray = File.ReadAllBytes(destinationfilename);

                    response.ClearHeaders();
                    Response.Buffer = true;
                    response.AppendHeader("Content-disposition", string.Format("attachment;filename={0}", "studentmarks.pdf"));
                    Response.ContentType = "application/pdf";

                    response.OutputStream.Write(bytearray, 0, bytearray.Length);

                   // File.Delete(destinationfilename);

                    Response.Flush();
                    Response.Close();
            }
            catch (Exception ex)
            {
             
            }
            finally
            {
             
            }
    }
 
    public void printitem(string destinationfilename)
    {
        Document mydoc = new Document(PageSize.A4);
        FileStream indexfile = null;
        PdfWriter wr1 = null;

        indexfile = new FileStream(destinationfilename, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
        wr1 = PdfWriter.GetInstance(mydoc, indexfile);

        string currentdate = DateTime.Now.ToString("dd/MM/yyyy");
        Phrase footPower = new Phrase("Report Run Date : " + HttpUtility.HtmlDecode(currentdate) + new String(' ', 125), FontFactory.GetFont("Tahoma", 7));
        HeaderFooter footerPower = new HeaderFooter(footPower, false);
        footerPower.Border = iTextSharp.text.Rectangle.TOP_BORDER;
        footerPower.Alignment = Element.ALIGN_CENTER;

        mydoc.Footer = footerPower;

        mydoc.Open();

     
     


        // Add Header
     

        DataTable dt;
        DataSet ds=new DataSet();
        SqlConnection SCCON = new SqlConnection(HttpContext.Current.Session["constr"].ToString());
        SCCON.Open();
        //  string staffcode = Guid.NewGuid().ToString();
        SqlCommand SC = new SqlCommand("SELECT FLDMARK1,FLDMARK2,FLDMARK3,FLDMARK4,FLDMARK5 FROM SM.TBLERMARKDETAILS where FLDSTUDENTID='" + Session["SID"].ToString() + "' AND FLDSEMESTER=" + int.Parse(Request.Form["cmbsemester"]), SCCON);
        SqlDataAdapter da = new SqlDataAdapter(SC);
        da.Fill(ds);
        dt = ds.Tables[0];
        SCCON.Close();

        PdfPTable pltable = new PdfPTable(2);
        float[] widths1 = { 10,10 };
        pltable.SetWidths(widths1);
        //table.SetTotalWidth(widths1);

        pltable.AddCell(Generatecell(1, "Name : ", 9, true, 1,false,0,true));

        pltable.AddCell(Generatecell(1,Session["SNAME"].ToString(), 9, true, 1));

        pltable.AddCell(Generatecell(1, "Semester : ", 9, true, 1,false,0,true));

        pltable.AddCell(Generatecell(1, Request.Form["cmbsemester"], 9, true, 1));
     
            pltable.AddCell(Generatecell(1,"Semester " + Request.Form["cmbsemester"]+" - Mark 1", 9, true, 1));
     
            pltable.AddCell(Generatecell(1, dt.Rows[0]["FLDMARK1"].ToString(), 9, true, 1));
            pltable.AddCell(Generatecell(1, "Semester " + Request.Form["cmbsemester"] + " - Mark 2", 9, true, 1));
            pltable.AddCell(Generatecell(1, dt.Rows[0]["FLDMARK2"].ToString(), 9, true, 1));
            pltable.AddCell(Generatecell(1, "Semester " + Request.Form["cmbsemester"] + " - Mark 3", 9, true, 1));
               pltable.AddCell(Generatecell(1, dt.Rows[0]["FLDMARK3"].ToString(), 9, true, 1));
               pltable.AddCell(Generatecell(1, "Semester " + Request.Form["cmbsemester"] + " - Mark 4", 9, true, 1));
        pltable.AddCell(Generatecell(1, dt.Rows[0]["FLDMARK4"].ToString(), 9, true, 1));
        pltable.AddCell(Generatecell(1, "Semester " + Request.Form["cmbsemester"] + " - Mark 5", 9, true, 1));
            pltable.AddCell(Generatecell(1, dt.Rows[0]["FLDMARK5"].ToString(), 9, true, 1));
     
     
           
         
            mydoc.Add(pltable);

//Attachment Start Here
       
     
    mydoc.Close();
    wr1.Close();
    indexfile.Close();
    }

    public PdfPCell Generatecell(int align, string text, int fontsize, bool bold, int border)
    {
        PdfPCell returncell = new PdfPCell();
        returncell.AddElement(Generateparagraph(align, text, fontsize, bold));
        if (border == 0)
        {
            returncell.Border = 0;
        }

        return returncell;
    }


    public PdfPCell Generatecell(int align, string text, int fontsize, bool bold, int border, bool colspan, int noofcols, bool header)
    {
        PdfPCell returncell = new PdfPCell();
        returncell.AddElement(Generateparagraph(align, text, fontsize, bold));
        if (border == 0)
        {
            returncell.Border = 0;

        }
        if (colspan == true)
        {
            returncell.Colspan = noofcols;

        }
        if (header == true)
        {
            returncell.BackgroundColor = Color.LIGHT_GRAY;
        }
        return returncell;
    }

    public Paragraph Generateparagraph(int align, string text, int fontsize, bool bold)
    {
        Paragraph para = new Paragraph();



        //  BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN,BaseFont.CP1252,BaseFont.NOT_EMBEDDED);

        if (bold == false)
            para = new Paragraph(string.IsNullOrEmpty(text) ? " " : StripTagsRegex(HttpUtility.HtmlDecode(text)), new Font(bf, fontsize));
        else if (bold == true)
            para = new Paragraph(string.IsNullOrEmpty(text) ? " " : StripTagsRegex(HttpUtility.HtmlDecode(text)), new Font(bf, fontsize, Font.BOLD));
        if (align == 1)
        {
            para.Alignment = Element.ALIGN_LEFT;
        }
        else if (align == 2)
        {
            para.Alignment = Element.ALIGN_CENTER;
        }
        else if (align == 3)
        {
            para.Alignment = Element.ALIGN_RIGHT;
        }

        return para;
    }

    public Paragraph AddEmptyParagraph()
    {
        Paragraph para = new Paragraph(" ");
        return para;
    }

    public PdfPTable Generatetable(int columns, float[] widths)
    {
        PdfPTable returntable = new PdfPTable(columns);
        returntable.WidthPercentage = 100f;
        returntable.SetTotalWidth(widths);
        return returntable;
    }
    private static string StripTagsRegex(string source)
    {
        return Regex.Replace(source, "<.*?>", string.Empty);
    }


Sunday, November 8, 2015

Security

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link href="Style/StyleSheet1.css" type="text/css" rel="stylesheet" />
<script src="Script/jquery-2.1.4.js" type="text/javascript"></script>
<script src="Script/jquery-2.1.4.min.js" type="text/javascript"></script>
<script src="Script/highcharts.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#body').highcharts({


chart: {
plotBackgroundColor: '#e2e2e2',
plotBorderWidth: null,
plotShadow: null,
backgroundColor: '#e2e2e2',
type: 'column'


},
credits: {
enabled: false


},
title: {
text: 'E2 Vulnerability Trending as of October 5th'


},

xAxis: {
categories: [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct'

],
crosshair: true


},
yAxis: {
min: 0,
title: {
text: 'Rainfall (mm)'


}
},
tooltip: {
headerFormat: '{point.key}'
,
pointFormat: ' {series.name}: ' +
'{point.y:.1f}
', footerFormat: '
', shared: true,
useHTML: true


},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: 'Joe',


data: [14, 36, 22, 19, 0, 0, 2, 4, 5, 0]

}, {
name: 'Sastry',


data: [0, 0, 0, 306, 188, 40, 0, 17, 0, 4],
color: '#B00000'

}]
});
});

</script>
</head>
<body>
<header style="background-color:black;" id="head1">
<div >
<table>
<tr>
<td>
<img src="Images/american-express.png" />



</td>
<td>
<h1>CTO - Application Security Vulnerabilities - E2</h1>
</td>
<td>



</td>
</tr>

</table>



</div>




</header>



<p style="text-align:center;"><b>As of Oct 5th, CTO has only 1 open vulerability which is a Medium risk and is scheduled to be remediated on 10/9. *</b></p>
<div id="body" style="height: 285px; max-width: 605px; margin: 0 auto;">
</div>
<br />
<table align="center" style="width:95%;border-collapse:collapse;border:thin;">
<thead>
<tr>
<th class="thclass">Application</th>
<th class="thclass">Application Director</th>
<th class="thclass">Application Name</th>
<th class="thclass">Application VP1</th>
<th class="thclass">Application VP2</th>
<th class="thclass">Vuln Type</th>
<th class="thclass">Vulnerability ID</th>
<th class="thclass">Date First Found</th>
<th class="thclass">Vulnerability Risk</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tdclass">James</td>
<td class="tdclass">Matman</td>
<td class="tdclass">Chief Sandwich Eater</td>
<td class="tdclass">Application VP1</td>
<td class="tdclass">Application VP2</td>
<td class="tdclass">Vuln Type</td>
<td class="tdclass">Vulnerability ID</td>
<td class="tdclass">Date First Found</td>
<td class="tdclass">Vulnerability Risk</td>
</tr>



</tbody>
</table>
<p style="text-align:center;"><b>As of Oct 5th, CTO has only 1 open vulerability which is a Medium risk and is scheduled to be remediated on 10/9. *</b></p>
<footer>
<div class="content-wrapper">
<div class="float-left">
<p>AXP Internal</p>
</div>
</div>
</footer>



</body>
</html>