protected void BtnExport_Click(object sender, EventArgs e)
    {
        try
        {
            if (TxtFromDate.Text != string.Empty && TxtToDate.Text != string.Empty)
            {
                DateTime fromdate = Convert.ToDateTime(TxtFromDate.Text.ToString());
                DateTime Todate   = Convert.ToDateTime(TxtToDate.Text.ToString());

                if (fromdate <= Todate)
                {
                    DataSet   ds        = new DataSet();
                    DateTime  StartDate = Convert.ToDateTime(TxtFromDate.Text);
                    DateTime  EndDate   = Convert.ToDateTime(TxtToDate.Text);
                    DataTable dt1       = ClsReportPurchaseOrder.Report_PurchaseOrderDetails(StartDate, EndDate);
                    if (dt1.Rows.Count > 0)
                    {
                        DataTable dt2 = ClsReportPurchaseOrder.Report_PurchaseOrderSummary(StartDate, EndDate);

                        ds.Tables.Add(dt1);
                        ds.Tables.Add(dt2);

                        ds.Tables[0].TableName = "Purchase Order Details";
                        ds.Tables[1].TableName = "Purchase Order Summary";

                        ExcelHelper.ToExcel(ds, "Purchase_Order_Register.xls", Page.Response);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('No Records Found...');</script>", false);
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Todate Should be Greater than or equal to Fromdate');</script>", false);
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Please Select Date...');</script>", false);
            }
        }
        catch (Exception ex)
        { }
    }
Пример #2
0
    protected void btnReport_Click(object sender, EventArgs e)
    {
        int      value      = Convert.ToInt32(ddlPonumber.SelectedItem.Value.ToString());
        DataRow  dr         = ClsReportPurchaseOrder.Report_PurchaseOrder(value).Rows[0];;
        Document document   = new Document(PageSize.A4, 88f, 88f, 10f, 10f);
        Font     NormalFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, Color.BLACK);

        using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
        {
            PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
            Phrase    phrase = null;

            PdfPCell  cell  = null;
            PdfPTable table = null;
            Color     color = null;

            document.Open();

            //Header Table
            table             = new PdfPTable(2);
            table.TotalWidth  = 500f;
            table.LockedWidth = true;
            table.SetWidths(new float[] { 0.3f, 0.7f });

            //Company Logo
            cell = ImageCell("~/img/INDECOMMIMG.bmp", 30f, PdfPCell.ALIGN_CENTER);
            table.AddCell(cell);

            //Company Name and Address
            phrase = new Phrase();
            phrase.Add(new Chunk("Microsoft Northwind Traders Company\n\n", FontFactory.GetFont("Arial", 16, Font.BOLD, Color.RED)));
            phrase.Add(new Chunk("107, Park site,\n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)));
            phrase.Add(new Chunk("Salt Lake Road,\n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)));
            phrase.Add(new Chunk("Seattle, USA", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)));
            cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
            cell.VerticalAlignment = PdfCell.ALIGN_TOP;
            table.AddCell(cell);

            //Separater Line
            color = new Color(System.Drawing.ColorTranslator.FromHtml("#A9A9A9"));
            DrawLine(writer, 25f, document.Top - 79f, document.PageSize.Width - 25f, document.Top - 79f, color);
            DrawLine(writer, 25f, document.Top - 80f, document.PageSize.Width - 25f, document.Top - 80f, color);
            document.Add(table);

            table = new PdfPTable(2);
            table.HorizontalAlignment = Element.ALIGN_LEFT;
            table.SetWidths(new float[] { 0.3f, 1f });
            table.SpacingBefore = 20f;

            //Employee Details
            cell         = PhraseCell(new Phrase("Purchase Order", FontFactory.GetFont("Arial", 12, Color.BLACK)), PdfPCell.ALIGN_CENTER);
            cell.Colspan = 2;
            table.AddCell(cell);
            cell               = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
            cell.Colspan       = 2;
            cell.PaddingBottom = 30f;
            table.AddCell(cell);

            ////Photo

            //cell = ImageCell(string.Format("~/photos/{0}.jpg", dr["EmployeeId"]), 25f, PdfPCell.ALIGN_CENTER);
            //table.AddCell(cell);

            ////Name
            //phrase = new Phrase();
            //phrase.Add(new Chunk(dr["TitleOfCourtesy"] + " " + dr["FirstName"] + " " + dr["LastName"] + "\n", FontFactory.GetFont("Arial", 10, Font.BOLD, Color.BLACK)));
            //phrase.Add(new Chunk("(" + dr["Title"].ToString() + ")", FontFactory.GetFont("Arial", 8, Font.BOLD, Color.BLACK)));
            //cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
            //cell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;
            //table.AddCell(cell);
            //document.Add(table);

            //DrawLine(writer, 160f, 80f, 160f, 690f, Color.BLACK);
            //DrawLine(writer, 115f, document.Top - 200f, document.PageSize.Width - 100f, document.Top - 200f, Color.BLACK);

            //table = new PdfPTable(2);
            //table.SetWidths(new float[] { 0.5f, 2f });
            //table.TotalWidth = 340f;
            //table.LockedWidth = true;
            //table.SpacingBefore = 20f;
            //table.HorizontalAlignment = Element.ALIGN_RIGHT;

            //Employee Id
            table.AddCell(PhraseCell(new Phrase("Location:", FontFactory.GetFont("Arial", 8, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_LEFT));
            table.AddCell(PhraseCell(new Phrase("000" + dr["Location"], FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT));
            cell               = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
            cell.Colspan       = 2;
            cell.PaddingBottom = 10f;
            table.AddCell(cell);


            //Address
            table.AddCell(PhraseCell(new Phrase("Address:", FontFactory.GetFont("Arial", 8, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_LEFT));
            phrase = new Phrase(new Chunk(dr["Location"] + "\n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)));
            phrase.Add(new Chunk(dr["Location"] + "\n", FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)));
            phrase.Add(new Chunk(dr["Location"] + " " + dr["Location"] + " " + dr["Location"], FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)));
            table.AddCell(PhraseCell(phrase, PdfPCell.ALIGN_LEFT));
            cell               = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
            cell.Colspan       = 2;
            cell.PaddingBottom = 10f;
            table.AddCell(cell);

            //Date of Birth
            table.AddCell(PhraseCell(new Phrase("Date of Birth:", FontFactory.GetFont("Arial", 8, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_LEFT));
            table.AddCell(PhraseCell(new Phrase(Convert.ToDateTime(dr["PO Date"]).ToString("dd MMMM, yyyy"), FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT));
            cell               = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
            cell.Colspan       = 2;
            cell.PaddingBottom = 10f;
            table.AddCell(cell);

            //Phone
            table.AddCell(PhraseCell(new Phrase("Phone Number:", FontFactory.GetFont("Arial", 8, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_LEFT));
            table.AddCell(PhraseCell(new Phrase(dr["Location"] + " Ext: " + dr["Location"], FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_LEFT));
            cell               = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
            cell.Colspan       = 2;
            cell.PaddingBottom = 10f;
            table.AddCell(cell);

            //Addtional Information
            table.AddCell(PhraseCell(new Phrase("Addtional Information:", FontFactory.GetFont("Arial", 8, Font.BOLD, Color.BLACK)), PdfPCell.ALIGN_LEFT));
            table.AddCell(PhraseCell(new Phrase(dr["Location"].ToString(), FontFactory.GetFont("Arial", 8, Font.NORMAL, Color.BLACK)), PdfPCell.ALIGN_JUSTIFIED));
            document.Add(table);
            document.Close();
            byte[] bytes = memoryStream.ToArray();
            memoryStream.Close();
            Response.Clear();
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "attachment; filename=PurchaseOrder.pdf");
            Response.ContentType = "application/pdf";
            Response.Buffer      = true;
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.BinaryWrite(bytes);
            Response.End();
            Response.Close();
        }
    }
Пример #3
0
    protected void btnExport_Click(object sender, EventArgs e)
    {
        try
        {
            if (ddlPonumber.SelectedIndex != 0)
            {
                string MainCategory = ClsPurchaseInvoice.Get_MainCategory_BasedOn_POID(Convert.ToInt64(ddlPonumber.SelectedValue.ToString()));
                if (MainCategory != "Support")
                {
                    Panel1.Visible = true;
                    value          = Convert.ToInt32(ddlPonumber.SelectedValue.ToString());
                    if (value != -1)
                    {
                        DataTable dt = ClsReportPurchaseOrder.Report_PurchaseOrder(value);
                        lbl_Ponumber.Text     = dt.Rows[0]["PO Number"].ToString();
                        lbl_PoDate.Text       = Convert.ToDateTime(dt.Rows[0]["PO Date"]).ToString("dd-MM-yyyy");
                        lbl_PO_RaisedTO.Text  = dt.Rows[0]["PO_Raise_TO"].ToString();
                        lbl_Bill_Address.Text = dt.Rows[0]["BillingAddress"].ToString();
                        lbl_Ship_Address.Text = dt.Rows[0]["ShippingAddress"].ToString();
                        //lbl_Footer_Address1.Text = dt.Rows[0]["BillingAddress"].ToString();
                        lbl_Term4.Text  = "4. Warranty :" + dt.Rows[0]["Warranty"].ToString();
                        lblBillGST.Text = dt.Rows[0]["GST"].ToString();
                        lblBillPAN.Text = dt.Rows[0]["PAN"].ToString();
                        lblSPA.Text     = dt.Rows[0]["SPANumber"].ToString();
                        // lblShipGST.Text= dt.Rows[0]["GST"].ToString();
                        lblShipPAN.Text = dt.Rows[0]["PAN"].ToString();

                        DataTable DT1        = ClsPurchaseInvoice.Get_PurchaseOrderForInvoice(value);
                        int       CategoryID = 0;
                        //foreach (DataRow row in DT1.Rows)
                        //{
                        //for (int i = 0; i < DT1.Rows.Count - 1; i++)
                        //{
                        //    CategoryID = Convert.ToInt32(DT1.Rows[i]["catagoryid"].ToString());

                        //if (CategoryID == 33)
                        //{
                        //GetSalesManager();
                        GetSalesManagerAMC1();
                        //lbl_Term3.Text = "";
                        //}
                        //else
                        //{
                        //    GetSalesManager();

                        //}
                        // }
                        //if (CategoryID == 33)
                        //{

                        //foreach (GridViewRow row in GridView1.Rows)
                        //{
                        //    foreach (TableCell cell in row.Cells)
                        //    {
                        //        row.Cells[0].Width = 10;
                        //    }
                        //}


                        Response.ContentType = "application/pdf";
                        Response.AddHeader("content-disposition", "attachment;filename=PO.pdf");
                        Response.Cache.SetCacheability(HttpCacheability.NoCache);
                        StringWriter   sw = new StringWriter();
                        HtmlTextWriter hw = new HtmlTextWriter(sw);
                        GridView1.HeaderRow.Style.Add("width", "10%");
                        GridView1.HeaderRow.Style.Add("font-size", "10px");
                        GridView1.Style.Add("font-size", "8px");
                        Panel1.RenderControl(hw);

                        StringReader sr = new StringReader(sw.ToString());

                        Document   pdfDoc     = new Document(PageSize.A4, 20f, 20f, 100f, 100f);
                        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                        PdfWriter  pdfWriter  = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                        pdfWriter.PageEvent = new Comman.ITextEvents();
                        pdfDoc.Open();

                        htmlparser.Parse(sr);
                        pdfDoc.Close();
                        Response.Write(pdfDoc);
                        // Response.End();
                        HttpContext.Current.Response.Flush();
                        HttpContext.Current.Response.SuppressContent = true;
                        HttpContext.Current.ApplicationInstance.CompleteRequest();
                        Panel1.Visible = false;
                        GetMasterList();
                        #region old code
                        //}
                        //else
                        //{
                        //    Response.ContentType = "application/pdf";
                        //    Response.AddHeader("content-disposition", "attachment;filename=PO.pdf");
                        //    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                        //    StringWriter sw = new StringWriter();
                        //    HtmlTextWriter hw = new HtmlTextWriter(sw);
                        //    GvwSaleseOrderDetails.HeaderRow.Style.Add("width", "10%");
                        //    GvwSaleseOrderDetails.HeaderRow.Style.Add("font-size", "10px");
                        //    GvwSaleseOrderDetails.Style.Add("font-size", "8px");
                        //    Panel1.RenderControl(hw);

                        //    StringReader sr = new StringReader(sw.ToString());
                        //    Document pdfDoc = new Document(PageSize.A4, 20f, 20f, 20f, 20f);
                        //    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                        //    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                        //    pdfDoc.Open();
                        //    htmlparser.Parse(sr);
                        //    pdfDoc.Close();
                        //    Response.Write(pdfDoc);
                        //    // Response.End();
                        //    HttpContext.Current.Response.Flush();
                        //    HttpContext.Current.Response.SuppressContent = true;
                        //    HttpContext.Current.ApplicationInstance.CompleteRequest();
                        //    Panel1.Visible = false;
                        //    GetMasterList();
                        //}
                        #endregion
                    }
                    else
                    {
                        Panel1.Visible = false;
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Please Select PO Number.');</script>", false);
                    }
                }
                else
                {
                    Panel2.Visible = true;
                    value          = Convert.ToInt32(ddlPonumber.SelectedValue.ToString());
                    if (value != -1)
                    {
                        DataTable dt = ClsReportPurchaseOrder.Report_PurchaseOrder(value);
                        lbl_PonumberSupport.Text      = dt.Rows[0]["PO Number"].ToString();
                        lbl_PoDateSupport.Text        = Convert.ToDateTime(dt.Rows[0]["PO Date"]).ToString("dd-MM-yyyy");
                        lbl_PO_RaisedTO.Text          = dt.Rows[0]["PO_Raise_TO"].ToString();
                        lbl_Bill_Address_Support.Text = dt.Rows[0]["BillingAddress"].ToString();
                        lbl_Ship_Address_Support.Text = dt.Rows[0]["ShippingAddress"].ToString();
                        lblSPA.Text       = dt.Rows[0]["SPANumber"].ToString();
                        lblSupBilGST.Text = dt.Rows[0]["GST"].ToString();
                        lblSupBilPAN.Text = dt.Rows[0]["PAN"].ToString();

                        //lbl_Footer_Address1.Text = dt.Rows[0]["BillingAddress"].ToString();

                        DataTable DT1 = ClsPurchaseInvoice.Get_PurchaseOrderForInvoice(value);
                        foreach (DataRow row in DT1.Rows)
                        {
                            int CategoryID = Convert.ToInt32(DT1.Rows[0]["catagoryid"].ToString());

                            if (CategoryID == 5 || CategoryID == 20 || CategoryID == 30 || CategoryID == 31 || CategoryID == 32 || CategoryID == 33 || CategoryID == 42)
                            {
                                //GetSalesManagerSupport();
                                GetSalesManagerAMC();

                                lbl_Term3.Text = "";
                            }
                            else
                            {
                                GetSalesManagerSupport();
                            }
                        }
                        Response.ContentType = "application/pdf";
                        Response.AddHeader("content-disposition", "attachment;filename=PO.pdf");
                        Response.Cache.SetCacheability(HttpCacheability.NoCache);
                        StringWriter   sw = new StringWriter();
                        HtmlTextWriter hw = new HtmlTextWriter(sw);
                        GridView3.HeaderRow.Style.Add("width", "10%");
                        GridView3.HeaderRow.Style.Add("font-size", "10px");
                        GridView3.Style.Add("font-size", "8px");

                        Panel2.RenderControl(hw);

                        StringReader sr         = new StringReader(sw.ToString());
                        Document     pdfDoc     = new Document(PageSize.A4, 20f, 20f, 130f, 100f);
                        HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);
                        PdfWriter    pdfWriter  = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                        pdfWriter.PageEvent = new Comman.ITextEvents();
                        pdfDoc.Open();
                        htmlparser.Parse(sr);
                        pdfDoc.Close();
                        Response.Write(pdfDoc);
                        // Response.End();
                        HttpContext.Current.Response.Flush();
                        HttpContext.Current.Response.SuppressContent = true;
                        HttpContext.Current.ApplicationInstance.CompleteRequest();
                        Panel2.Visible = false;
                        GetMasterList();
                    }
                    else
                    {
                        Panel2.Visible = false;
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Please Select PO Number.');</script>", false);
                    }
                }
            }
            else
            {
                Panel1.Visible = false;
                ScriptManager.RegisterStartupScript(this, typeof(Page), "Alert", "<script>alert('Please Select PO Number.');</script>", false);
            }
        }
        catch (Exception ex)
        {
        }
        //ddlPonumber.SelectedItem.Value = "-1";
    }