مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

aaarmin4

عضویت از 1394/09/06

اعمال فیلتر بر روی داده ها و نمایش فیلتر شده در گزارش ساخته شده با استیمول

  • شنبه 28 فروردین 1395
  • 13:20
تشکر میکنم

سلام جناب مهندس.یک برنامه دارم با اعمال فیلترداده ها فیلتر میشه حالا میخوام تو گزارش هم داده های فیلتر شده رو بیاره   همه داد های جدول بانک رو میاره فرمودید به صورت QueryString بفرستم به همین شکل هستش کدش به شکل زیره ولی بازم کل بانک رو میاره میشه راهنمایی بفرمایید مشکل حل بشه

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System.Text;
using System.Drawing;
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using System.Web.UI.HtmlControls;
using iTextSharp.text.html;
using System.Drawing.Text;
using Stimulsoft.Report;
using System.Data.OleDb;
using System.Text;
using System.Xml;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;

 

public partial class _gozaresh : System.Web.UI.Page
{
    DataView dv = new DataView();

    protected void Page_Load(object sender, EventArgs e)
    {
        Label11.Text = DateTime.Now.ToString();
       

        if (Session["Karbar"] == null)
        {
            Response.Redirect("/Enter_Page.aspx");
        }
        try
        {

            //اگر کاربری وارد شود نام کاربر در بالای سایت نمایش داده میشود
            if (Session["Login"] != null)
            {
                Label10.Text = Session["Login"].ToString();
                Label10.Visible = true;
               
            }
            else
            {
                Label10.Text = "کاربر مهمان خوش آمدید.";
            }

            //اگر کاربر از مسئولان دانشگاه باشد لینک مدیریت فعال میشود
            if (Session["Type"].ToString() == "1")
            {
                Button1.Visible = true;
            }
            else
            {
                Button1.Visible = false;
            }
    }
    
     catch (Exception) { }


    }

    public override void VerifyRenderingInServerForm(Control control)
    {
        //base.VerifyRenderingInServerForm(control);
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {

        int count = 0;
        string cmd = "select * from View_amar_ebtedaii_cls ";

        if (DropDownList1.SelectedIndex != 0)
        {
            count++;
            cmd += "where " + DropDownList1.SelectedValue.ToString() + "= '" + DropDownList5.SelectedValue.ToString() + "'";
        }
        if (DropDownList2.SelectedIndex != 0)
        {
            if (count == 0)
            {
                cmd += "where " + DropDownList2.SelectedValue.ToString() + "= '" + DropDownList6.Text.ToString() + "'";
                count++;
            }
            else
            {
                cmd += " and " + DropDownList2.SelectedValue.ToString() + "='" + DropDownList6.Text.ToString() + "'";
            }
        }
        if (DropDownList3.SelectedIndex != 0)
        {
            if (count == 0)
            {
                cmd += "where " + DropDownList3.SelectedValue.ToString() + "='" + DropDownList7.Text.ToString() + "'";
                count++;
            }
            else
            {
                cmd += " and " + DropDownList3.SelectedValue.ToString() + "='" + DropDownList7.Text.ToString() + "'";
            }
        }
        if (DropDownList4.SelectedIndex != 0)
        {
            if (count == 0)
            {
                cmd += "where " + DropDownList4.SelectedValue.ToString() + "='" + DropDownList8.Text.ToString() + "'";
                count++;
            }
            else
            {
                cmd += " and " + DropDownList4.SelectedValue.ToString() + "='" + DropDownList8.Text.ToString() + "'";
            }
        }


        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["amarwebConnectionString"].ToString());
        ConfigurationManager.ConnectionStrings["amarwebConnectionString"].ToString();
        SqlCommand sqlCmd = new SqlCommand(cmd, con);

        ////Data Source=amar;Initial Catalog=amarweb;Integrated Security=True
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
        da.Fill(ds);
        GridView1.DataSourceID = null;
        GridView1.DataSource = ds;
        GridView1.DataBind();
        DropDownList5.Text = "";
        DropDownList6.Text = "";
        DropDownList7.Text = "";
        DropDownList8.Text = "";
        DropDownList1.SelectedIndex = 0;

        DropDownList2.SelectedIndex = 0;

        DropDownList3.SelectedIndex = 0;

        DropDownList4.SelectedIndex = 0;


    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }

    protected void Button2_Click(object sender, EventArgs e)
    {

        GridView1.AllowPaging = true;

        GridView1.DataBind();

        StringWriter sw = new StringWriter();

        HtmlTextWriter hw = new HtmlTextWriter(sw);

        GridView1.RenderControl(hw);

        string gridHTML = sw.ToString().Replace("\"", "'")

            .Replace(System.Environment.NewLine, "");

        StringBuilder sb = new StringBuilder();

        sb.Append("<script type = 'text/javascript'>");

        sb.Append("window.onload = new function(){");

        sb.Append("var printWin = window.open('', '', 'right=0");

        sb.Append(",top=0,width=1000,height=600,status=0');");

        sb.Append("printWin.document.write(\"");

        sb.Append(gridHTML);

        sb.Append("\");");

        sb.Append("printWin.document.close();");

        sb.Append("printWin.focus();");

        sb.Append("printWin.print();");

        sb.Append("printWin.close();};");

        sb.Append("</script>");

        ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());

        GridView1.AllowPaging = true;

        GridView1.DataBind();

}
   protected void btnPdf_Click(object sender, EventArgs e)
    {
Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=report.pdf");
        Response.Charset = "";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        HtmlForm hf = new HtmlForm();
        GridView1.Parent.Controls.Add(hf);
        hf.Attributes["runat"] = "server";
        hf.Controls.Add(GridView1);
        hf.RenderControl(hw);
        string Tahoma_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
        BaseFont bf = BaseFont.CreateFont(Tahoma_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A4, 10f, 250f, 10f, -10f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=report.xls");
        Response.Charset = "";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/vnd.xls";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
        Panel2.RenderControl(htmlWrite);
        Response.Buffer = true;
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        Response.Write(stringWrite.ToString());
        Response.End();
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename=gvtocsv.csv");
        Response.Charset = "";
        Response.ContentType = "application/text";
        StringBuilder sBuilder = new System.Text.StringBuilder();
        for (int index = 0; index < GridView1.Columns.Count; index++)
        {
            sBuilder.Append(GridView1.Columns[index].HeaderText + ',');
        }
        sBuilder.Append("\r\n");
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            for (int k = 0; k < GridView1.HeaderRow.Cells.Count; k++)
            {
                sBuilder.Append(GridView1.Rows[i].Cells[k].Text.Replace(",", "") + ",");
            }
            sBuilder.Append("\r\n");
        }
        Response.Output.Write(sBuilder.ToString());
        Response.Flush();
        Response.End();
    }
    protected void btnExportGridviewPDF(object sender, EventArgs e)
    {
        GridView1.AllowPaging = false;
        GridView1.DataBind();

        BaseFont bf = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\tahoma.ttf", BaseFont.IDENTITY_H, true);
        iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL);
        iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(GridView1.Columns.Count);
        int[] widths = new int[GridView1.Columns.Count];
        for (int x = 0; x < GridView1.Columns.Count; x++)
        {
            widths[x] = (int)GridView1.Columns[x].ItemStyle.Width.Value;
            string cellText = Server.HtmlDecode(GridView1.HeaderRow.Cells[x].Text);
            iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new Phrase(12, cellText, font));
            
            cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
            table.AddCell(cell);
        }
        table.SetWidths(widths);

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            if (GridView1.Rows[i].RowType == DataControlRowType.DataRow)
            {
                for (int j = 0; j < GridView1.Columns.Count; j++)
                {
                    string cellText = Server.HtmlDecode(GridView1.Rows[i].Cells[j].Text);
                    iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new Phrase(12, cellText, font));
                    //Set Color of Alternating row
                    if (i % 2 != 0)
                    {
                                           }
                    cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
                    table.AddCell(cell);
                }
            }
        }

        //Create the PDF Document
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        pdfDoc.Add(table);
        pdfDoc.Close();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Write(pdfDoc);
        Response.End();
    }
    protected void btnExportGridviewPDF_Click(object sender, EventArgs e)
    {
        GridView1.AllowPaging = false;
        GridView1.DataBind();

        BaseFont bf = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\tahoma.ttf", BaseFont.IDENTITY_H, true);
        iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL);
        iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(GridView1.Columns.Count);
        int[] widths = new int[GridView1.Columns.Count];
        for (int x = 0; x < GridView1.Columns.Count; x++)
        {
            widths[x] = (int)GridView1.Columns[x].ItemStyle.Width.Value;
            string cellText = Server.HtmlDecode(GridView1.HeaderRow.Cells[x].Text);
            iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new Phrase(12, cellText, font));
            //cell.BackgroundColor = new Color(System.Drawing.ColorTranslator.FromHtml("#008000"));
            cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
            table.AddCell(cell);
        }
        table.SetWidths(widths);

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            if (GridView1.Rows[i].RowType == DataControlRowType.DataRow)
            {
                for (int j = 0; j < GridView1.Columns.Count; j++)
                {
                    string cellText = Server.HtmlDecode(GridView1.Rows[i].Cells[j].Text);
                    iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new Phrase(12, cellText, font));
                    //Set Color of Alternating row
                    if (i % 2 != 0)
                    {
                        //cell.BackgroundColor = new Color(System.Drawing.ColorTranslator.FromHtml("#C2D69B"));
                    }
                    cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
                    table.AddCell(cell);
                }
            }
        }

        //Create the PDF Document
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        pdfDoc.Add(table);
        pdfDoc.Close();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Write(pdfDoc);
        Response.End();
    }

    protected void btnExport_Click(object sender, EventArgs e)
    {
        string attachment = "attachment; filename=Article.pdf";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/pdf";
        StringWriter stw = new StringWriter();
        HtmlTextWriter htextw = new HtmlTextWriter(stw);
        //dvText.RenderControl(htextw);
        Document document = new Document();
        PdfWriter.GetInstance(document, Response.OutputStream);
        document.Open();
        StringReader str = new StringReader(stw.ToString());
        HTMLWorker htmlworker = new HTMLWorker(document);
        htmlworker.Parse(str);
        document.Close();
        Response.Write(document);
        Response.End();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Session["ctrl"] = Panel2;
        ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('Print.aspx','PrintMe','height=500px,width=1000px,scrollbars=1');</script>");

    }


    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        try
        {
            Document pdfDoc = new Document(PageSize.A4.Rotate(), 0, 0, 5, 0);
            PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream);
            pdfDoc.Open();
            pdfDoc.Add(new Paragraph("This is Landscape Page"));

            pdfDoc.SetPageSize(new iTextSharp.text.Rectangle(850f, 1100f));
            pdfDoc.NewPage();
            pdfDoc.Add(new Paragraph("This is Portrait Page"));
            pdfWriter.CloseStream = false;
            pdfDoc.Close();
            Response.Buffer = true;
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=Test.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
        }
        catch (Exception ex)
        {
        }  
    }
    protected void Button5_Click1(object sender, EventArgs e)
    {
        string appDirectory = HttpContext.Current.Server.MapPath(string.Empty);

        dv = DataBase.SelectSQL("select * from View_amar_ebtedaii_cls");

        // Load report
        StiReport report = new StiReport();
        report.Load(appDirectory + "\\Report.mrt");
        report.RegData("tbl", dv);

        // View report
        StiWebViewer1.Report = report;

        report.UnloadReportAppDomain();

    }

 

 


    protected void Button6_Click(object sender, EventArgs e)
    {
        dv = DataBase.SelectSQL("select * View_amar_ebtedaii_cls");

        if (dv.Table.Rows.Count > 0)
        {

            GridView1.DataSource = dv;
            GridView1.DataBind();

        }
        else
        {
            Button6.Text = "اطلاعاتی یافت نشد";
        }
    }
    }

    
    
   

پاسخ های این پرسش

تعداد پاسخ ها : 3 پاسخ
کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • شنبه 28 فروردین 1395
  • 13:22

برای درج کد از کلید کد در ادیتور استفاده کنید

کاربر سایت

aaarmin4

عضویت از 1394/09/06

  • شنبه 28 فروردین 1395
  • 15:42
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System.Text;
using System.Drawing;
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using System.Web.UI.HtmlControls;
using iTextSharp.text.html;
using System.Drawing.Text;
using Stimulsoft.Report;
using System.Data.OleDb;
using System.Text;
using System.Xml;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;



public partial class _gozaresh : System.Web.UI.Page
{
    DataView dv = new DataView();

    protected void Page_Load(object sender, EventArgs e)
    {
        Label11.Text = DateTime.Now.ToString();
       

        if (Session["Karbar"] == null)
        {
            Response.Redirect("/Enter_Page.aspx");
        }
        try
        {

            //اگر کاربری وارد شود نام کاربر در بالای سایت نمایش داده میشود
            if (Session["Login"] != null)
            {
                Label10.Text = Session["Login"].ToString();
                Label10.Visible = true;
               
            }
            else
            {
                Label10.Text = "کاربر مهمان خوش آمدید.";
            }

            //اگر کاربر از مسئولان دانشگاه باشد لینک مدیریت فعال میشود
            if (Session["Type"].ToString() == "1")
            {
                Button1.Visible = true;
            }
            else
            {
                Button1.Visible = false;
            }
    }
    
     catch (Exception) { }


    }

    public override void VerifyRenderingInServerForm(Control control)
    {
        //base.VerifyRenderingInServerForm(control);
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {

        int count = 0;
        string cmd = "select * from View_amar_ebtedaii_cls ";

        if (DropDownList1.SelectedIndex != 0)
        {
            count++;
            cmd += "where " + DropDownList1.SelectedValue.ToString() + "= '" + DropDownList5.SelectedValue.ToString() + "'";
        }
        if (DropDownList2.SelectedIndex != 0)
        {
            if (count == 0)
            {
                cmd += "where " + DropDownList2.SelectedValue.ToString() + "= '" + DropDownList6.Text.ToString() + "'";
                count++;
            }
            else
            {
                cmd += " and " + DropDownList2.SelectedValue.ToString() + "='" + DropDownList6.Text.ToString() + "'";
            }
        }
        if (DropDownList3.SelectedIndex != 0)
        {
            if (count == 0)
            {
                cmd += "where " + DropDownList3.SelectedValue.ToString() + "='" + DropDownList7.Text.ToString() + "'";
                count++;
            }
            else
            {
                cmd += " and " + DropDownList3.SelectedValue.ToString() + "='" + DropDownList7.Text.ToString() + "'";
            }
        }
        if (DropDownList4.SelectedIndex != 0)
        {
            if (count == 0)
            {
                cmd += "where " + DropDownList4.SelectedValue.ToString() + "='" + DropDownList8.Text.ToString() + "'";
                count++;
            }
            else
            {
                cmd += " and " + DropDownList4.SelectedValue.ToString() + "='" + DropDownList8.Text.ToString() + "'";
            }
        }


        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["amarwebConnectionString"].ToString());
        ConfigurationManager.ConnectionStrings["amarwebConnectionString"].ToString();
        SqlCommand sqlCmd = new SqlCommand(cmd, con);

        ////Data Source=amar;Initial Catalog=amarweb;Integrated Security=True
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
        da.Fill(ds);
        GridView1.DataSourceID = null;
        GridView1.DataSource = ds;
        GridView1.DataBind();
        DropDownList5.Text = "";
        DropDownList6.Text = "";
        DropDownList7.Text = "";
        DropDownList8.Text = "";
        DropDownList1.SelectedIndex = 0;

        DropDownList2.SelectedIndex = 0;

        DropDownList3.SelectedIndex = 0;

        DropDownList4.SelectedIndex = 0;


    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }

    protected void Button2_Click(object sender, EventArgs e)
    {

        GridView1.AllowPaging = true;

        GridView1.DataBind();

        StringWriter sw = new StringWriter();

        HtmlTextWriter hw = new HtmlTextWriter(sw);

        GridView1.RenderControl(hw);

        string gridHTML = sw.ToString().Replace("\"", "'")

            .Replace(System.Environment.NewLine, "");

        StringBuilder sb = new StringBuilder();

        sb.Append("<script type = 'text/javascript'>");

        sb.Append("window.onload = new function(){");

        sb.Append("var printWin = window.open('', '', 'right=0");

        sb.Append(",top=0,width=1000,height=600,status=0');");

        sb.Append("printWin.document.write(\"");

        sb.Append(gridHTML);

        sb.Append("\");");

        sb.Append("printWin.document.close();");

        sb.Append("printWin.focus();");

        sb.Append("printWin.print();");

        sb.Append("printWin.close();};");

        sb.Append("</script>");

        ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());

        GridView1.AllowPaging = true;

        GridView1.DataBind();

}
   protected void btnPdf_Click(object sender, EventArgs e)
    {
Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=report.pdf");
        Response.Charset = "";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        HtmlForm hf = new HtmlForm();
        GridView1.Parent.Controls.Add(hf);
        hf.Attributes["runat"] = "server";
        hf.Controls.Add(GridView1);
        hf.RenderControl(hw);
        string Tahoma_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF");
        BaseFont bf = BaseFont.CreateFont(Tahoma_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A4, 10f, 250f, 10f, -10f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=report.xls");
        Response.Charset = "";
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.ContentType = "application/vnd.xls";
        System.IO.StringWriter stringWrite = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
        Panel2.RenderControl(htmlWrite);
        Response.Buffer = true;
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        Response.Write(stringWrite.ToString());
        Response.End();
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename=gvtocsv.csv");
        Response.Charset = "";
        Response.ContentType = "application/text";
        StringBuilder sBuilder = new System.Text.StringBuilder();
        for (int index = 0; index < GridView1.Columns.Count; index++)
        {
            sBuilder.Append(GridView1.Columns[index].HeaderText + ',');
        }
        sBuilder.Append("\r\n");
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            for (int k = 0; k < GridView1.HeaderRow.Cells.Count; k++)
            {
                sBuilder.Append(GridView1.Rows[i].Cells[k].Text.Replace(",", "") + ",");
            }
            sBuilder.Append("\r\n");
        }
        Response.Output.Write(sBuilder.ToString());
        Response.Flush();
        Response.End();
    }
    protected void btnExportGridviewPDF(object sender, EventArgs e)
    {
        GridView1.AllowPaging = false;
        GridView1.DataBind();

        BaseFont bf = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\tahoma.ttf", BaseFont.IDENTITY_H, true);
        iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL);
        iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(GridView1.Columns.Count);
        int[] widths = new int[GridView1.Columns.Count];
        for (int x = 0; x < GridView1.Columns.Count; x++)
        {
            widths[x] = (int)GridView1.Columns[x].ItemStyle.Width.Value;
            string cellText = Server.HtmlDecode(GridView1.HeaderRow.Cells[x].Text);
            iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new Phrase(12, cellText, font));
            
            cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
            table.AddCell(cell);
        }
        table.SetWidths(widths);

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            if (GridView1.Rows[i].RowType == DataControlRowType.DataRow)
            {
                for (int j = 0; j < GridView1.Columns.Count; j++)
                {
                    string cellText = Server.HtmlDecode(GridView1.Rows[i].Cells[j].Text);
                    iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new Phrase(12, cellText, font));
                    //Set Color of Alternating row
                    if (i % 2 != 0)
                    {
                                           }
                    cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
                    table.AddCell(cell);
                }
            }
        }

        //Create the PDF Document
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        pdfDoc.Add(table);
        pdfDoc.Close();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Write(pdfDoc);
        Response.End();
    }
    protected void btnExportGridviewPDF_Click(object sender, EventArgs e)
    {
        GridView1.AllowPaging = false;
        GridView1.DataBind();

        BaseFont bf = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\tahoma.ttf", BaseFont.IDENTITY_H, true);
        iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 10, iTextSharp.text.Font.NORMAL);
        iTextSharp.text.pdf.PdfPTable table = new iTextSharp.text.pdf.PdfPTable(GridView1.Columns.Count);
        int[] widths = new int[GridView1.Columns.Count];
        for (int x = 0; x < GridView1.Columns.Count; x++)
        {
            widths[x] = (int)GridView1.Columns[x].ItemStyle.Width.Value;
            string cellText = Server.HtmlDecode(GridView1.HeaderRow.Cells[x].Text);
            iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new Phrase(12, cellText, font));
            //cell.BackgroundColor = new Color(System.Drawing.ColorTranslator.FromHtml("#008000"));
            cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
            table.AddCell(cell);
        }
        table.SetWidths(widths);

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            if (GridView1.Rows[i].RowType == DataControlRowType.DataRow)
            {
                for (int j = 0; j < GridView1.Columns.Count; j++)
                {
                    string cellText = Server.HtmlDecode(GridView1.Rows[i].Cells[j].Text);
                    iTextSharp.text.pdf.PdfPCell cell = new iTextSharp.text.pdf.PdfPCell(new Phrase(12, cellText, font));
                    //Set Color of Alternating row
                    if (i % 2 != 0)
                    {
                        //cell.BackgroundColor = new Color(System.Drawing.ColorTranslator.FromHtml("#C2D69B"));
                    }
                    cell.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
                    table.AddCell(cell);
                }
            }
        }

        //Create the PDF Document
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        pdfDoc.Add(table);
        pdfDoc.Close();
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Write(pdfDoc);
        Response.End();
    }

    protected void btnExport_Click(object sender, EventArgs e)
    {
        string attachment = "attachment; filename=Article.pdf";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/pdf";
        StringWriter stw = new StringWriter();
        HtmlTextWriter htextw = new HtmlTextWriter(stw);
        //dvText.RenderControl(htextw);
        Document document = new Document();
        PdfWriter.GetInstance(document, Response.OutputStream);
        document.Open();
        StringReader str = new StringReader(stw.ToString());
        HTMLWorker htmlworker = new HTMLWorker(document);
        htmlworker.Parse(str);
        document.Close();
        Response.Write(document);
        Response.End();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Session["ctrl"] = Panel2;
        ClientScript.RegisterStartupScript(this.GetType(), "onclick", "<script language=javascript>window.open('Print.aspx','PrintMe','height=500px,width=1000px,scrollbars=1');</script>");

    }


    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        try
        {
            Document pdfDoc = new Document(PageSize.A4.Rotate(), 0, 0, 5, 0);
            PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, HttpContext.Current.Response.OutputStream);
            pdfDoc.Open();
            pdfDoc.Add(new Paragraph("This is Landscape Page"));

            pdfDoc.SetPageSize(new iTextSharp.text.Rectangle(850f, 1100f));
            pdfDoc.NewPage();
            pdfDoc.Add(new Paragraph("This is Portrait Page"));
            pdfWriter.CloseStream = false;
            pdfDoc.Close();
            Response.Buffer = true;
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=Test.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
        }
        catch (Exception ex)
        {
        }  
    }
    protected void Button5_Click1(object sender, EventArgs e)
    {
        string appDirectory = HttpContext.Current.Server.MapPath(string.Empty);

        dv = DataBase.SelectSQL("select * from View_amar_ebtedaii_cls");

        // Load report
        StiReport report = new StiReport();
        report.Load(appDirectory + "\\Report.mrt");
        report.RegData("tbl", dv);

        // View report
        StiWebViewer1.Report = report;

        report.UnloadReportAppDomain();

    }






    protected void Button6_Click(object sender, EventArgs e)
    {
        dv = DataBase.SelectSQL("select * View_amar_ebtedaii_cls");

        if (dv.Table.Rows.Count > 0)
        {

            GridView1.DataSource = dv;
            GridView1.DataBind();

        }
        else
        {
            Button6.Text = "اطلاعاتی یافت نشد";
        }
    }
    }

    
    
    

 

کاربر سایت

aaarmin4

عضویت از 1394/09/06

  • شنبه 28 فروردین 1395
  • 21:15

جناب مهندس امکانش هست بررسی بفرمایید

کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)