自己写的PAGE分页库配件(C#+javascript)
来源:互联网 发布:开眼数据怎么样 编辑:程序博客网 时间:2024/05/05 04:06
using System;
using System.Data;
using System.Configuration;
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.Data;
using System.Data.SqlClient;
namespace Tool
{
public class MySelfPage
{
private String sql = null;
private int now = 1;
private int count = 10;
private String div = null;
private DataTable dt = null;
private String px = null;
private String connectionString = "Data Source=LENOVO-7E01A231;Initial Catalog=Hrms;Integrated Security=True";
private int allCount;
private int allpage;
private String aspx;
public MySelfPage()
{
}
public void SetPageInfo(String sql,int now,int count,String px,String aspx)
{
this.sql = sql;
this.now = now;
this.count = count;
this.px = px;
this.aspx = aspx;
DoWantToDO();
}
public DataTable BackDataTable()
{
return dt;
}
public String Function()
{
int down = now+1;
int up = now - 1;
String str =
"<script language='javascript'>" +
"function downpage()" +
"{";
if (down >= allpage + 1)
{
down = allpage;
str = str + "alert('已经是最后一页了!');";
}
str = str + "location.href='"+aspx+"?now=" + down + "';"+
"}"+"function uppage()" +
"{" ;
if (up == 0)
{
up = 1;
str = str + "alert('已经是第一页了!');";
}
str = str +
"location.href='"+aspx+"?now=" + up + "';" +
"}"+
"</script>";
return str;
}
public String BackInnerHtml()
{
String pageStr = "";
int[] pages = new int[20];
for(int i=0;i<pages.Length;i++)
{
if (now == 1)
{
if (i < 10)
{
pages[i] = now + i;
}
else
{
pages[i] = 0;
}
}
else
{
if (now<=11)
{
if (i < 10 + now-1)
{
pages[i] = now + i - now + 1;
}
else
{
pages[i] = 0;
}
}
else
{
pages[i] = now+9 - 20 + i+1;
if (pages[i] == allpage)
{
break;
}
}
}
}
for (int i = 0; i < pages.Length; i++)
{
if (pages[i] != 0)
{
if (pages[i] == now)
{
pageStr = pageStr + "<a href='"+aspx+"?now=" + pages[i] + "'><font color = 'red' size='5'>" + pages[i] + "</font></a>";
}
else
{
pageStr = pageStr + "<a href='"+aspx+"?now=" + pages[i] + "'>" + pages[i] + "</a>";
}
if (i != pages.Length - 1&&pages[i]!=allpage)
{
pageStr = pageStr + ",";
}
}
}
div = "第" + now + "页,共" + allpage + "页 <a href='"+aspx+"?now=0'>首页</a> ";
if(pages[0]!=1)
{
div = div +"......";
}
div = div + pageStr;
if (now != allpage)
{
div = div + "......";
}
div = div + "<a href='"+aspx+"?now=" + allpage + "'> 尾页</a> " +
"<input type='button' id='up' value='上一页' onclick='uppage()'> " +
" <input type='button' id='down1' value='下一页' onclick='downpage()'> ";
return div;
}
private void CreateAllCount()
{
String str = "select count(*) from (" + sql + ") as a";
allCount = (int)DoSql(str).Rows[0][0];
}
private void CreateAllPage()
{
if (allCount % count == 0)
{
allpage = allCount / count;
}
else
{
allpage = allCount / count + 1;
}
}
private void DoWantToDO()
{
//得到总条数
CreateAllCount();
//得到总页数
CreateAllPage();
String str = "";
if (now == 0)
{
now = 1;
}
if (now > allpage)
{
now = allpage;
}
if (now != allpage||allCount%count==0)
{
str = "select * from(" +
"select top " + count + " * from(" +
"select top " + count * now + " * from(" + sql + ") as b) as a order by " + px + " desc)" +
"as c order by " + px + " asc";
}
if (now == allpage)
{
if (allCount % count != 0)
{
int top = allCount % count;
str = "select * from (" +
"select top " + count + " * from(" + sql + ") as a order by " + px + " desc" +
")as a order by " + px + " asc";
}
}
dt = DoSql(str); ;
}
private DataTable DoSql(String str)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = connectionString;
SqlDataAdapter adapter = new SqlDataAdapter(str,con);
DataTable table = new DataTable();
adapter.Fill(table);
return table;
}
}
}
- 自己写的PAGE分页库配件(C#+javascript)
- 自己写的分页
- 自己写的Javascript
- 自己写的分页代码
- 自己写的一个分页
- 自己写的数据分页
- 自己写的分页条
- 自己写的freemarker分页
- 自己写的分页类
- 写自己的分页控件
- 写一个自己的javascript库
- 写一个自己的javascript库
- javascript写的dom分页
- 自己写的DataList分页控件(源码)
- 自己写的javascript五子棋
- [C#]写自己的类库
- C调用自己写的动态库
- 自己写的实现分页的控件
- -------------------------------标记 已从原先的博客转移了部分文章(下面要开始转第三页第2篇)
- 一个BUG
- Building ARM ELF EABI--Step by Step
- Date && DateFormat && Calendar的简单使用
- 程序之旅群
- 自己写的PAGE分页库配件(C#+javascript)
- LUA相关工具资源
- 点击button按钮后,启动一个实现鼠标拖动另一个button的线程 (JFrame/C# WinForm)
- javascript中confirm,alert,ptompt的用法
- C# 操作 XML 数据库类型、Oracle XMLType
- oracle9i日常操作总结
- 数据库挂马解决的SQL代码
- New关键字的几种用法
- 心情不好