using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Globalization;
using System.IO;

public partial class _PIE_Project : System.Web.UI.Page
{

protected System.Data.SqlClient.SqlConnection SqlConnection1;
    protected System.Data.SqlClient.SqlDataAdapter SqlDataAdapter1;
    protected System.Data.DataSet DataSet1;
    protected System.Data.DataSet DataSet2;
    string Str_sql = "";

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            P_ht.H_data P_data = new P_ht.H_data();
            P_data.sql_text1 = " SELECT [projectName], [WorkName], [PlanEndDate], [PlanStartDate] FROM [PJ_WorkPiece] ";
            Str_sql = P_data.sql_text1;
            P_data.select_tables();
            DataSet1 = P_data.DataSet8;
            Session["r1_PJ_WorkPiece"] = this.DataSet1;

this.GridView1.DataSource = DataSet1;
            this.GridView1.DataBind();

}
    }

protected void Btn_search_Click(object sender, EventArgs e)
    {
        string m_Where = "";
       
        //
        //// 正则表示式验证
        //

//
        //// check
        //
        ////  Response.Write("非标准日期");

DateTime dt1,dt2;

//
        if ((this.TextBox1.Text.Trim() != "") && (this.TextBox2.Text.Trim() != ""))
        {
            if (DateTime.TryParseExact(this.TextBox1.Text.Trim(), "yyyy-MM-dd", null, DateTimeStyles.None, out dt1))
            {
                //验证通过
            }
            else
            {
                ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
                scriptManager.RegisterStartupScript(typeof(string), "", "alert('提示: 项目开始日期不是日期格式! ');", true);
                return;
            }

if (DateTime.TryParseExact(this.TextBox2.Text.Trim(), "yyyy-MM-dd", null, DateTimeStyles.None, out dt2))
            {
                //验证通过
            }
            else
            {
                ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
                scriptManager.RegisterStartupScript(typeof(string), "", "alert('提示: 项目截止日期不是日期格式! ');", true);
                return;
            }

////
            if ((dt2 < dt1))
            {
                ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
                scriptManager.RegisterStartupScript(typeof(string), "", "alert('提示: 项目开始日期不能大于项目截止日期! ');", true);
                return;
            }
            else
            {
                m_Where += (m_Where == "" ? "" : " and ") + " PlanStartDate Between '" + this.TextBox1.Text.Trim() + "' and '" + this.TextBox2.Text.Trim() + "'";
            }
        }
        else
        {
            if ((this.TextBox1.Text.Trim() != "") && (this.TextBox2.Text.Trim() == ""))
            {
                if (DateTime.TryParseExact(this.TextBox1.Text.Trim(), "yyyy-MM-dd", null, DateTimeStyles.None, out dt1))
                {
                    //验证通过
                    m_Where += (m_Where == "" ? "" : " and ") + " PlanStartDate > '" + this.TextBox1.Text.Trim() + "' ";
                }
                else
                {
                    ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
                    scriptManager.RegisterStartupScript(typeof(string), "", "alert('提示: 项目开始日期不是日期格式! ');", true);
                    return;
                }
            }
            else
            {
                if ((this.TextBox1.Text.Trim() == "") && (this.TextBox2.Text.Trim() != ""))
                {
                    if (DateTime.TryParseExact(this.TextBox2.Text.Trim(), "yyyy-MM-dd", null, DateTimeStyles.None, out dt1))
                    {
                        //验证通过
                        m_Where += (m_Where == "" ? "" : " and ") + " PlanStartDate < '" + this.TextBox2.Text.Trim() + "' ";
                    }
                    else
                    {
                        ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
                        scriptManager.RegisterStartupScript(typeof(string), "", "alert('提示: 项目开始日期不是日期格式! ');", true);
                        return;
                    }
                }
            }
        }

// project
        if (this.TextBox3.Text.Trim() != "")
        {
            m_Where += (m_Where == "" ? "" : " and ") + " projectName like '%" + this.TextBox3.Text.Trim() + "%' ";
        }

//
        //// Select
        //
        P_ht.H_data P_data = new P_ht.H_data();
        P_data.sql_text1 = " SELECT [projectName], [WorkName], [PlanEndDate], [PlanStartDate] FROM [PJ_WorkPiece] where " + m_Where + " ";
        Str_sql = P_data.sql_text1;
        P_data.select_tables();
        DataSet1 = P_data.DataSet8;
        Session["r1_PJ_WorkPiece"] = this.DataSet1;

this.GridView1.DataSource = DataSet1;
        this.GridView1.DataBind();

}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        this.DataSet2 = new System.Data.DataSet();
        this.DataSet2 = (DataSet)Session["r1_PJ_WorkPiece"];
        this.GridView1.DataSource = this.DataSet2;
        this.GridView1.DataBind();
    }

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        int i;
        //执行循环,保证每条数据都可以更新
        for (i = -1; i < GridView1.Rows.Count; i++)
        {
            //首先判断是否是数据行
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#bcbf56'");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            }
        }
    }

protected void btn_export_Click(object sender, EventArgs e)
    {
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Charset = "";
        HttpContext.Current.Response.ContentType = "application/vnd.ms-xls";
        StringWriter stringWrite = new StringWriter();
        HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

DataGrid dg = new DataGrid();

//dg.DataSource = ds;
        this.DataSet2 = new System.Data.DataSet();
        this.DataSet2 = (DataSet)Session["r1_PJ_WorkPiece"];
        dg.DataSource = DataSet2;

dg.DataBind();
        dg.RenderControl(htmlWrite);
        //HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename="+HttpUtility.UrlEncode(excelName))
        HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename="+HttpUtility.UrlEncode("2015.xls"));
    HttpContext.Current.Response.Write(stringWrite.ToString());
        HttpContext.Current.Response.End();
    }

}

asp.net 查询,导出的更多相关文章

  1. ASP.NET MVC导出excel

    ASP.NET MVC导出excel 要在ASP.NET MVC站点上做excel导出功能,但是要导出的excel文件比较大,有几十M,所以导出比较费时,为了不影响对界面的其它操作,我就采用异步的方式 ...

  2. asp.net中导出Excel的方法

    一.asp.net中导出Excel的方法: 本文转载 在asp.net中导出Excel有两种方法,一种是将导出的文件存放在服务器某个文件夹下面,然后将文件地址输出在浏览器上:一种是将文件直接将文件输出 ...

  3. asp.net中导出Execl的方法

    一.asp.net中导出Execl的方法: 在 asp.net中导出Execl有两种方法,一种是将导出的文件存放在服务器某个文件夹下面,然后将文件地址 输出在浏览器上:一种是将文件直接将文件输出流写给 ...

  4. ASP.net中导出Excel的简单方法介绍

    下面介绍一种ASP.net中导出Excel的简单方法 先上代码:前台代码如下(这是自己项目里面写的一点代码先贴出来吧) <div id="export" runat=&quo ...

  5. 关于asp.net C# 导出Excel文件 打开Excel文件格式与扩展名指定格式不一致的解决办法

    -----转载:http://blog.csdn.net/sgear/article/details/7663502 关于asp.net C# 导出Excel文件 打开Excel文件格式与扩展名指定格 ...

  6. ASP.NET查询页面设置form的action属性只弹出一个页面,并且每次将页面设置到最前

    原文:ASP.NET查询页面设置form的action属性只弹出一个页面,并且每次将页面设置到最前 背景 当数据量大.查询条件复杂,多样多的时候,我们可能需要单独做一个查询界面,当用户选择设置了相关的 ...

  7. C# asp.net中导出Excel表时总出现"只能在执行 Render() 的过程中调用 RegisterForEventValidation

    C# asp.net中导出Excel表时总出现"只能在执行 Render() 的过程中调用 RegisterForEventValidation 后台添加以下方法:/// <summa ...

  8. asp.net2.0导出pdf文件完美解决方案【转载】

    asp.net2.0导出pdf文件完美解决方案 作者:清清月儿 PDF简介:PDF(Portable Document Format)文件格式是Adobe公司开发的电子文件格式.这种文件格式与操作系统 ...

  9. ASP.NET MVC 导出CSV文件

    ASP.NET MVC   导出CSV文件.直接贴代码 /// <summary> /// ASP.NET MVC导出CSV文件Demo1 /// </summary> /// ...

  10. asp.net MVC 导出查询结果到Excel

    首先在View视图中有一表单form,导出按钮<input class="btn export" type="button" value="导出 ...

随机推荐

  1. Dive into python 实例学python (2) —— 自省,apihelper

    apihelper.py def info(object, spacing=10, collapse=1): """Print methods and doc strin ...

  2. SQLSERVER:Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

    背景: 在最近开发中遇到一个问题,对一个数据库进行操作时,我采用64个并行的任务每个任务保证一个数据库连接对象:但是每个任务内部均包含有24个文件需要读取,在读取文件之后,我们需要快速将这24个文件批 ...

  3. mysql 插入重复值 INSERT ... ON DUPLICATE KEY UPDATE

    向数据库插入记录时,有时会有这种需求,当符合某种条件的数据存在时,去修改它,不存在时,则新增,也就是saveOrUpdate操作.这种控制可以放在业务层,也可以放在数据库层,大多数数据库都支持这种需求 ...

  4. 3n+1问题

    猜想: 对于任意大于1的自然数n,若n为奇数,则将n变为3n+1,否则变为n的一半. 经过若干次这样的变换,一定会使n变为1.例如3->10->5->16->8->2-& ...

  5. JS语法部分

    定义变量使用通用类型var:字符串(需要引号),小数,整数,布尔型(只返回对或错),日期时间 算术运算符:+  —  *  /  %(1取余数,2判断是不是整数,3将某个数值变为某个范围之内的数,4判 ...

  6. 转:python socket编程详细介绍

    Python 提供了两个基本的 socket 模块. 第一个是 Socket,它提供了标准的 BSD Sockets API. 第二个是 SocketServer, 它提供了服务器中心类,可以简化网络 ...

  7. C++向量(Vector)

    向量Vector: 向量 vector 是一种对象实体, 能够容纳许多其他类型相同的元素, 因此又被称为容器. 与string相同, vector 同属于STL(Standard Template L ...

  8. [转]gitHub客户端Desktop的安装使用总结 ---基础篇

    gitHub客户端Desktop的安装使用总结 ---基础篇 发表于2015/12/11 11:41:57  8399人阅读 分类: Android之应用实战 这段时间想把我写的东西上传到github ...

  9. android开发之如何使TabHost的TabWidget位于屏幕下方

    更改TabHost里的第一个LinearLayout为RelativeLayout.并在TabWidget中添加android:layout_alignParentBottom="true& ...

  10. linux第12天 线程

    今天主要学习了共享内存,信号量的封装,还有线程. POSIX线程库 与线程有关的函数构成了一个完整的系列,绝大多数函数的名字都是以“pthread_”打头的 要使用这些函数库,要通过引入头文<p ...