Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Wednesday, 1 August 2018

Export html to PDF and Excel


using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using GisSolution.App_Code;
using System.Web;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.tool.xml;
using iTextSharp.text.html.simpleparser;

namespace Application
{
    public partial class ParcelPoints : Page
    {
        string BQP_CODE;
        const string query = "select رقم_الطلب, NO_POINT,COORDINATE_X,COORDINATE_Y from IDENTIFY_SUR_POINTS where BQP_CODE='{0}'";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid();
                ScriptManager scriptManager = ScriptManager.GetCurrent(Page);
                scriptManager.RegisterPostBackControl(btnExport);
                scriptManager.RegisterPostBackControl(btnExportToPDF);
            }
        }
        private void BindGrid()
        {
            //if (string.IsNullOrEmpty(hf_BQP_CODE.Value))
            BQP_CODE = Request.QueryString["BQP_CODE"];
            hf_BQP_CODE.Value = BQP_CODE;
            if (!string.IsNullOrEmpty(BQP_CODE))
            {
                DBConnection dataAccess = new DBConnection();
                using (DataTable dt = dataAccess.GetData(string.Format(query, BQP_CODE)))
                {
                    GV_ParcelsPoints.DataSource = dt;
                    GV_ParcelsPoints.DataBind();
                }

            }
        }
        protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GV_ParcelsPoints.PageIndex = e.NewPageIndex;
            BindGrid();
        }
        protected void ExportToExcel(object sender, EventArgs e)
        {

            if (!string.IsNullOrEmpty(hf_BQP_CODE.Value))
            {
                DBConnection dataAccess = new DBConnection();
                ExportToExcel(dataAccess.GetData(string.Format(query, hf_BQP_CODE.Value)), string.Format(@"Parcel_{0}_Points_{1}", hf_BQP_CODE.Value,DateTime.Now));
            }
        }
        protected void btnExportToPDF_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(hf_BQP_CODE.Value))
            {
                DBConnection dataAccess = new DBConnection();
                ExportGridToPDF(dataAccess.GetData(string.Format(query, hf_BQP_CODE.Value)), string.Format(@"Parcel_{0}_Points_{1}", hf_BQP_CODE.Value, DateTime.Now));
            }
        }


        protected void ExportToExcel(DataTable tblData, string fileName)
        {
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + fileName + ".xls");
            HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.Charset = "UTF-8";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
            HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
            StringWriter stringWrite = new StringWriter();
            HtmlTextWriter htmlWrite =
            new HtmlTextWriter(stringWrite);
            DataGrid grdExcel = new DataGrid();
            grdExcel.AllowPaging = false;
            grdExcel.DataSource = tblData;
            grdExcel.DataBind();
            foreach (DataGridItem i in grdExcel.Items)
            {
                foreach (TableCell tc in i.Cells)
                    tc.Attributes.Add("class", "text");
            }
            grdExcel.RenderControl(htmlWrite);
            HttpContext.Current.Response.Write("");
            string style = @" ";
            HttpContext.Current.Response.Write(style);
            HttpContext.Current.Response.Write(stringWrite.ToString());
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }
        private void ExportGridToPDF(DataTable tblData, string fileName)
        {
            Response.ContentType = "application/pdf; charset=utf-8\"";
            Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GV_ParcelsPoints.AllowPaging = false;
            BindGrid();
            int cc=GV_ParcelsPoints.Rows.Count;
            GV_ParcelsPoints.RenderControl(hw);
            StringReader sr = new StringReader(sw.ToString());
            Document pdfDoc = new Document(PageSize.A4, 7f, 7f, 7f, 0f);
            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
            PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            pdfDoc.Open();
            htmlparser.Parse(sr);
            pdfDoc.Close();
            Response.Write(pdfDoc);
            Response.End();
        }

        //Confirms that an HtmlForm control is rendered for the
        //specified ASP.NET server control at run time.
        public override void VerifyRenderingInServerForm(Control control)
        { }

    }
}

Tuesday, 9 August 2016

HTML inside Tooltip

<!DOCTYPE html>
<html>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>

<style>
    .tooltip {
        position: relative;
        display: inline-block;
        border-bottom: 1px dotted black;
    }

        .tooltip .tooltiptext {
            display:none;
            min-width: 120px;
            background-color: black;
            color: #fff;
            text-align: center;
            border-radius: 6px;
            padding: 10px;
            position: absolute;
            z-index: 1;
            top: -50px;
            margin-left:7px;
        }

            .tooltip  .tooltipPointer {
                display:none;
                content: "";
                position: absolute;
                top: 12px;
                left: 97%;
                margin-top: -5px;
                border-width: 5px;
                border-style: solid;
                border-color: transparent black transparent transparent;
                /*left: 100%;//for rtl
                border-color: transparent rgba(0, 0, 0, 0.08) transparent rgb(0, 0, 0);*/
            }

        /*.tooltip:hover .tooltiptext {
            visibility: visible;
        }*/
</style>
<body style="text-align:center;">
    <div style="height:300px">
        <h1>Yesssssssssssss my tooltip</h1>
    </div>
    <h2>Right Tooltip w/ Left Arrow</h2>

    <div class="tooltip" style="float:left">
        Hover over me
        <span class="tooltipPointer"></span>
        <div class="tooltiptext">
            <div id="listHolder">
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-0" value="GT_BUILDINGS_MARK_MB">معالم رئيسية -ابنية</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-30" value="ii_oracle_maps_internal_others">طبقة نتيجة البحث</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-0" value="GT_BUILDINGS_MARK_MB">معالم رئيسية -ابنية</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-30" value="ii_oracle_maps_internal_others">طبقة نتيجة البحث</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-0" value="GT_BUILDINGS_MARK_MB">معالم رئيسية -ابنية</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-30" value="ii_oracle_maps_internal_others">طبقة نتيجة البحث</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-0" value="GT_BUILDINGS_MARK_MB">معالم رئيسية -ابنية</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-30" value="ii_oracle_maps_internal_others">طبقة نتيجة البحث</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-0" value="GT_BUILDINGS_MARK_MB">معالم رئيسية -ابنية</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-30" value="ii_oracle_maps_internal_others">طبقة نتيجة البحث</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-0" value="GT_BUILDINGS_MARK_MB">معالم رئيسية -ابنية</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-30" value="ii_oracle_maps_internal_others">طبقة نتيجة البحث</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-0" value="GT_BUILDINGS_MARK_MB">معالم رئيسية -ابنية</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-30" value="ii_oracle_maps_internal_others">طبقة نتيجة البحث</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-0" value="GT_BUILDINGS_MARK_MB">معالم رئيسية -ابنية</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-30" value="ii_oracle_maps_internal_others">طبقة نتيجة البحث</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-0" value="GT_BUILDINGS_MARK_MB">معالم رئيسية -ابنية</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-30" value="ii_oracle_maps_internal_others">طبقة نتيجة البحث</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-0" value="GT_BUILDINGS_MARK_MB">معالم رئيسية -ابنية</label><br>
                <label class="LayersLabel"><input type="radio"  name="theme-choices" id="radio-choice-30" value="ii_oracle_maps_internal_others">طبقة نتيجة البحث</label><br>
            </div>
        </div>
    </div>
    <div style="float:left"> Same shit different day </div>

    <script type="text/javascript">
    $(document).ready(function () {
        var w = $('.tooltip').width();
        var float = $('.tooltip').css('float');
        var tooltipHolder = $('.tooltiptext');
        $(tooltipHolder).css('left', w);

        $('.tooltip').click(function () {
            if ($(tooltipHolder).html().trim().length < 5) {
                $('.tooltiptext').css('display', 'none');
                $('.tooltipPointer').css('display', 'none');
               
            } else {
                calculateTooltipDim();
                $('.tooltiptext').css('display', 'block');
                $('.tooltipPointer').css('display', 'block');
            }

        });
        $('.tooltiptext').hover(
            // mouse-over
            function () { },
            // mouse-out
            function () {
                $(this).css('display', 'none');
                $('.tooltipPointer').css('display', 'none');
            });
        $('.tooltip').hover(
            // mouse-over
            function () { },
            // mouse-out
            function () {});       
    });
    function calculateTooltipDim() {
        var tooltipHolder = $('.tooltiptext');
        var $element = $('.tooltip');
        var val = (($(tooltipHolder).height()+2) - ($(document).height() - $element.offset().top - $element.height()));
        $(tooltipHolder).css('top', val * -1);
    }
    </script>

</body>
</html>