Esempio n. 1
0
    public void generatePDFforPO(int Borderid, string Bpoid)
    {
        string ID             = Encrypt_Decrypt.Decrypt(Session["sOrderID"].ToString().Trim(), true);
        string imageFilePath1 = Server.MapPath("~/images/logo2.jpg");
        string ss             = "<img src='" + imageFilePath1 + "' height='100%' width='100%' />";
        string strpdf         = "<table align='left' style='font-family:Verdana;font-size:9px;width: 885px'><tr><td align='left'>" + ss + "</td><td align='right'>" + lblMainAddress.Text + "</td></tr></table>";

        strpdf += "<table align='center' style='font-family:Verdana;font-size:9px;width:885px'><tr>";
        strpdf += "<td colspan='6'><table align='center' style='font-family: Verdana; width: 885px'><tr><td colspan='6' align='center' style='font-family:Verdana;font-size:xx-large;'>Purchase Order  -  " + ID + "  " + lblOrgType.Text + "</td></tr></table></td></tr><tr>";
        strpdf += "<td colspan='6'><table width='100%' border='1'><tr><td width='50%' align='center' rowspan='5' colspan='2'>" + txtCompanyAddress.Text + "</td><td width='50%' align='center' bgcolor='#CCCC99' colspan='2'>Purchase Order INFO</td></tr><tr align='center'>";
        strpdf += "<td bgcolor='#CCCC99'>PO Number</td><td>" + lblBPO.Text + "</td></tr><tr align='center'><td bgcolor='#CCCC99'>Date</td><td>" + lblDate.Text + "</td></tr><tr align='center'><td bgcolor='#CCCC99'>TIN</td><td>" + lblTIN.Text + "</td></tr></table></td><tr>";
        strpdf += "<td colspan='6' align='center'>Details of Overseas PO received</td></tr><tr>";
        strpdf += "<td colspan='6'><table width='100%'border='1'><tr align='center'><td bgcolor='#CCCC99'>Overseas PO/<br />Intent Number</td><td align='center'>" + lblPO.Text + "</td><td align='center' bgcolor='#CCCC99'>Date</td><td align='center'>" + lblPODate.Text + "</td><td style='width:90px' bgcolor='#CCCC99'>Destination Country</td><td>" + lblDestCountry.Text + "</td></tr></table></td></tr><tr>";
        strpdf += "<td colspan='6' align='center'>Please arrange the shipment as per the Terms & Conditions mentioned</td></tr><tr>";
        strpdf += "<td colspan='6'><table width='100%' border='1'><tr bgcolor='#CCCC99'><td align='center' style='width:20px'>S.No</td><td align='center'>Product Name</td><td align='center'>Quantity<br/>(KG)</td><td align='center'>Packing<br/>(25 KG)</td><td align='center'>Packing <br/>(180 KG)</td><td align='center'>Price/KG<br/>(INR)</td><td align='center'>Amount<br/>(INR)</td></tr><tr>";
        foreach (GridViewRow gvr in gvPurchaseOrder.Rows)
        {
            var lblQuantity         = gvr.FindControl("lblQuantity") as Label;
            var lblPacking25        = gvr.FindControl("lblPacking25") as Label;
            var lblPacking180       = gvr.FindControl("lblPacking180") as Label;
            var lblPOUPPrice        = gvr.FindControl("lblPOUPPrice") as Label;
            var lblTotalPriceAmount = gvr.FindControl("lblTotalPriceAmount") as Label;
            strpdf += "<td align='center' style='width:20px'>" + (gvr.Cells[0].FindControl("lblsnnumber") as Label).Text + "</td><br/><td align='center'>" + gvr.Cells[2].Text + "</td><br/><td align='center'>" + lblQuantity.Text + "</td><br/><td align='center'>" + lblPacking25.Text + "</td><br/><td align='center'>" + lblPacking180.Text + "</td><br/><td align='center'>" + lblPOUPPrice.Text + "</td><br/><td align='right'>" + lblTotalPriceAmount.Text + "</td><br/></tr><tr>";
        }
        strpdf += "<td colspan='3' align='center' bgcolor='#CCCC99'>&nbsp;Total No of Drums </td><td align='center'>" + lblDrum25.Text + "</td><td align='center'>" + lblDrum180.Text + "</td><td></td><td rowspan='2' align='right' bgcolor='#FFCC99'>" + lblTotalprice.Text + "</td></tr><tr>";
        //strpdf += "<td colspan='3' align='center' bgcolor='#CCCC99'>&nbsp;Total No of Drums </td><td colspan='3'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + lblDrum25.Text + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + lblDrum180.Text + "</td><td rowspan='2' align='right' bgcolor='#FFB6C1'>" + lblTotalprice.Text + "</td></tr><tr>";
        strpdf += "<td colspan='2' align='center' bgcolor='#CCCC99'>Total Amount in Words</td><td colspan='4'>&nbsp;" + lblAmount_word.Text + "&nbsp;Only</td></tr></table></td></tr><tr>";
        strpdf += "<td colspan='6'></td></tr><tr>";
        //strpdf += "<td colspan='6'><table width='100%' border='1'><tr><td align='center'>Organic Premium @ Rs " + lblOrgPreimum.Text + " / Kg will be transferred to the societies handling ICS </td></tr></td></tr></table><tr>";

        strpdf += "<td colspan='6'><table width='100%' border='1'><tr><td align='center' width='35%' bgcolor='#CCCC99'>Price Terms</td><td align='center' width='35%'>" + lblpriceterm.Text + "</td><td align='center' width='30%' bgcolor='#CCCC99'>Address for Delivery</td></tr><tr>";
        strpdf += "<td align='center'bgcolor='#CCCC99'>Payment Terms</td><td align='center'> " + lblPayTer.Text + "</td><td align='center' rowspan='6'> " + lblAddressDelivery.Text + "</td></tr><tr>";
        strpdf += "<td align='center'bgcolor='#CCCC99'>Additional Taxes & Duties</td><td align='center'>" + lblTax.Text + " </td></tr><tr>";
        strpdf += "<td align='center'bgcolor='#CCCC99'>Additional Mandy Tax</td><td align='center'>" + lblMandyTax.Text + "</td></tr><tr>";
        strpdf += "<td align='center' bgcolor='#CCCC99'>Mode of Transport</td><td align='center'>convenient mode</td></tr><tr>";
        strpdf += "<td align='center' bgcolor='#CCCC99'>Place of Delivery</td><td align='center'>" + lblplacedelivery.Text + "</td></tr><tr>";
        strpdf += "<td align='center' bgcolor='#CCCC99'>Sales Tax Terms</td><td align='center'>" + lblSalesTax.Text + "</td></tr></table></td></tr><tr>";
        strpdf += "<td colspan='6' align='center'>E-mail the below mentioned documents IMMEDIATELY after dispatching the Shipment</td></tr><tr>";
        strpdf += "<td colspan='4' align='left'><table width='100%'border='1'><tr bgcolor='#CCCC99'><td align='center'>S.No</td><td align='center'>Report&nbsp; Name</td><td align='center'>Date Of Email</td></tr><tr>";
        foreach (GridViewRow gvr in gvReports.Rows)
        {
            if ((gvr.Cells[3].FindControl("cbReport") as CheckBox).Checked)
            {
                strpdf += "<td align='center' style='width:20px'>" + (gvr.Cells[0].FindControl("lblsno") as Label).Text + "</td><td align='center'>" + gvr.Cells[2].Text + "</td><td align='center'>" + (gvr.Cells[4].FindControl("txtReportDate") as TextBox).Text + "</td></tr>";
            }
        }
        strpdf += "</table></td><td colspan='2' align='right'><table align='right'><tr><td><br/><br/><br/><br/><h5>Authorized Signatory<br/>&nbsp;<b>Mudar India Exports</b></h5></td></tr></table></td></tr></table>";

        Document document = new Document();

        try
        {
            string Pdf_path = string.Empty;
            Pdf_path = mu.createfolder(Encrypt_Decrypt.Decrypt(Session["sOrderID"].ToString().Trim(), true),
                                       MudarUser.OrderPDF) ? WebConfigurationManager.AppSettings["orderpdf"].ToString() + Encrypt_Decrypt.Decrypt(Session["sOrderID"].ToString().Trim(), true) + "/" + Borderid.ToString() + "_" + "BR" + ".pdf" : WebConfigurationManager.AppSettings["orderpdf"].ToString() + "/" + Borderid.ToString() + "_" + Bpoid.ToString() + ".pdf";

            //writer - have our own path!!!
            PdfWriter.GetInstance(document, new FileStream(Server.MapPath(Pdf_path), FileMode.Create));
            document.Open();

            //Here is where your HTML source goes................
            String htmlText = strpdf.ToString();


            //make an arraylist ....with STRINGREADER since its no IO reading file...

            List <IElement> htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(htmlText), null);


            Paragraph mypara = new Paragraph();//make an emtphy paragraph as "holder"
            mypara.IndentationLeft = 36;
            mypara.InsertRange(0, htmlarraylist);
            document.Add(mypara);
            document.Close();
            orderobj.BranchOrderDetails_UPD(Borderid, Pdf_path, 1, "bhanu");
        }
        catch (Exception exx)
        {
            Response.Write("<br>____________________________________<br>");
            Response.Write("<br>Error: " + exx + "<br>");
            Response.Write("<br>StackTrace: " + exx.StackTrace + "<br>");
            Response.Write("<br>strPDFDocument: " + strpdf.ToString() + "<br>");
            Response.Write("<br>strSelectUserListBuilder: " + strpdf.ToString() + "<br>");

            //Console.Error.WriteLine(exx.StackTrace);
            //Console.Error.WriteLine(exx.StackTrace);
        }
        finally
        {
            //document.Close();
        }
    }