|
 |
栏目导栏 |
|
| |
|
|
|
|
 |
资料搜索 |
|
| |
|
|
|
|
 |
热门文章 |
|
| |
|
|
|
|
 |
最新文章 |
|
| |
|
|
|
| |
| |
|
|
|
|
ASP.NET带给我们很多惊喜,强大的Web Form控件自然是其中的重要部分。这其中,最受关注的当然是Datagrid。在ASP中用HTML标记语法来输出数据的方法在Datagrid数据绑定面前显得如此繁杂。但是只使用Datagrid自身的功能,还是达不到实际的工作要求。本文就是给大家演示如何提高我们的工作效率、降低服务器的负载压力。 Pu6Linux联盟 Pu6Linux联盟 1. Datagrid的分页显示 Pu6Linux联盟 Pu6Linux联盟 当查询到的数据很多,在一屏内显示出来篇幅太长的时候,我们可以利用Datagrid的分页功能让用户通过上下页的切换来查看数据。设置方法很简单:在datagrid的属性处点击“属性生成器”,然后在“分页”栏进行如图1所示的设置,页大小的行数即决定了每页显示出几行数据记录。 Pu6Linux联盟 Pu6Linux联盟 Pu6Linux联盟 Pu6Linux联盟 Pu6Linux联盟 Pu6Linux联盟 图1 分页设置 Pu6Linux联盟 Pu6Linux联盟 2. 自定义导航栏 Pu6Linux联盟 Pu6Linux联盟 在图1的属性页中的“格式”栏中,我们可以设置“页导航”的外观样式。但是很多程序设计人员都喜欢用自己定义的导航栏,而不使用默认的上下页按钮或数字按钮(即出现1、2、3……页号的形式)。那么我们可以这样来做: Pu6Linux联盟 Pu6Linux联盟 (1) 如果要保留默认的导航栏,请不用看这一小节。如果要隐藏起默认的页导航栏。就请将PageStyle的visible属性设置为false。或在图1“页导航”中,不勾选“显示导航按钮”即可。 Pu6Linux联盟 Pu6Linux联盟 (2) 在写自定义导航栏时,主要是利用CurrentPageIndex属性来设置页: Pu6Linux联盟 Pu6Linux联盟 "第一页": Pu6Linux联盟 Pu6Linux联盟 DataGrid1.CurrentPageIndex = 0; Pu6Linux联盟 Pu6Linux联盟 "上一页": Pu6Linux联盟 Pu6Linux联盟 if (DataGrid1.CurrentPageIndex > 0) Pu6Linux联盟 Pu6Linux联盟 DataGrid1.CurrentPageIndex -= 1; Pu6Linux联盟 Pu6Linux联盟 "下一页": Pu6Linux联盟 Pu6Linux联盟 if (DataGrid1.CurrentPageIndex < (DataGrid1.PageCount - 1)) Pu6Linux联盟 Pu6Linux联盟 DataGrid1.CurrentPageIndex += 1; Pu6Linux联盟 Pu6Linux联盟 "最后一页": Pu6Linux联盟 Pu6Linux联盟 DataGrid1.CurrentPageIndex = (DataGrid1.PageCount - 1); Pu6Linux联盟 Pu6Linux联盟 (3) 需要注意的是:Web Form是一种无状态的编程方式,我们在自定义了导航栏按钮的代码后,需要再次加载Datagrid的数据源。否则将看不到页切换的效果。也就是说,我们需要在按钮的click事件中加入重新加载数据源的代码,比如我们可以将加载的代码写在如下方法SetGridSource中,在按钮Click的代码最后加入SetGridSource()这句调用代码。 Pu6Linux联盟 Pu6Linux联盟 private void SetGridSource() Pu6Linux联盟 Pu6Linux联盟 { Pu6Linux联盟 Pu6Linux联盟 SqlConnection MyConnection = new SqlConnection(YourOwnConnectionString); Pu6Linux联盟 Pu6Linux联盟 string SelectCommand = "SELECT * FROM YOURTABLE"; Pu6Linux联盟 Pu6Linux联盟 SqlDataAdapter MyCommand = new SqlDataAdapter(SelectCommand, MyConnection); Pu6Linux联盟 Pu6Linux联盟 DataSet ds = new DataSet(); Pu6Linux联盟 Pu6Linux联盟 MyCommand.Fill(ds, " YOURTABLE "); Pu6Linux联盟 Pu6Linux联盟 DataView dv = ds.Tables["YOURTABLE "].DefaultView; Pu6Linux联盟 Pu6Linux联盟 DataGrid1.DataSource = dv; Pu6Linux联盟 Pu6Linux联盟 DataGrid1.DataBind(); Pu6Linux联盟 Pu6Linux联盟 } Pu6Linux联盟 Pu6Linux联盟 或者我们可以在Page_load中写入SetGridSource里的代码,使浏览器在页切换重置时可以重新加载并绑定Datagrid的数据源。要注意的是,上述代码不能写在首次加载判断 if (!IsPostBack)语句中 Pu6Linux联盟 Pu6Linux联盟 (4) 在页面上我们一般需要显示总页数与当前页面这样的信息。与WinForm中的Datagrid不同的是,在WinForm中需要获取与数据相关的信息,只能从Datagrid的数据源,比如DataTable中去获得数据行数,某单元格的值等信息。被 WinForm中的dataset与datagrid之间的关系弄得头晕的朋友就不用再害怕了,在WebForm中,我们只要从Datagrid中就可以直接获得这些信息了。总页数是Datagrid的PageCount属性;当前页数是CurrentPageIndex属性值+1来表示,这是由于 CurrentPageIndex是从0开始计数的。 Pu6Linux联盟 Pu6Linux联盟 3. 自定义分页 Pu6Linux联盟 Pu6Linux联盟 采用Datagrid属性生成器中的分页方式,我们都会感觉到方便的欣喜。但是,用上面所说的方法,每次页切换时,都会用SELECT * FROM YOURTABLE这样的SQl语句去提取出全部的数据,而没有任何与页有关的筛选器。这大大降低了我们Web程序的效率,也增加了服务器的负担。Datagrid提供的分页特点也变得名不副实。我们希望分页能真正的实现减少每次下载的数据量的功能,就要写代码控制住每次提取的数据量大小。 Pu6Linux联盟 Pu6Linux联盟 要使用自定义分页,就要将 AllowCustomPaging 属性设置为 true。然后基于 PageSize 和 VirtualItemCount 属性的值计算要显示 DataGrid 控件中每一项所需的页数。 Pu6Linux联盟 Pu6Linux联盟 PageSize表示的是在 DataGrid 控件的单页上显示的项数,默认值为10。 Pu6Linux联盟 Pu6Linux联盟 VirtualItemCount表示的是总数目。那么页数自然是VirtualItemCount/PageSize Pu6Linux联盟 Pu6Linux联盟 (1) 当然是首先要知道一共有多少条数据,然后我们才好进行分配,写在Page_load里: Pu6Linux联盟 Pu6Linux联盟 if (!IsPostBack) Pu6Linux联盟 Pu6Linux联盟 { Pu6Linux联盟 Pu6Linux联盟 StartIndex = 0;//StartIndex是int类型的公用变量 Pu6Linux联盟 Pu6Linux联盟 SqlConnection MyConnection = new SqlConnection(YourOwnConnectionString); Pu6Linux联盟 Pu6Linux联盟 SqlCommand MyCommand = new SqlCommand("SELECT mycount = COUNT(*) FROM Table",MyConnection); Pu6Linux联盟 Pu6Linux联盟 MyConnection.Open(); Pu6Linux联盟 Pu6Linux联盟 SqlDataReader dr = MyCommand.ExecuteReader(CommandBehavior.SingleRow); Pu6Linux联盟 Pu6Linux联盟 if (dr.Read()) Pu6Linux联盟 Pu6Linux联盟 DataGrid1.VirtualItemCount = (int)dr["mycount"]; Pu6Linux联盟 Pu6Linux联盟 dr.Close(); Pu6Linux联盟 Pu6Linux联盟 MyConnection.Close(); Pu6Linux联盟 Pu6Linux联盟 SetGridSource(StartIndex, "上一页");//看看现在的形参有什么不同哦 Pu6Linux联盟 Pu6Linux联盟 } Pu6Linux联盟 Pu6Linux联盟 注:这里说一个本文研究范围之外的知识点,就是上面dr的赋值代码中,我们用的是MyCommand.ExecuteReader(CommandBehavior.SingleRow),而大家一般用的只是MyCommand.ExecuteReader(),但请记住,如果返回记录集只有一行的话,用CommandBehavior.SingleRow进行标识可以提高应用程序的执行效率。这是因为不注明的一般情况下,MyCommand执行是使用 IRowset 接口。而注明了之后,就会利用IRow 接口(如果可用)执行绑定。其中的差别请关注笔者的后续作品。 Pu6Linux联盟 Pu6Linux联盟 (2) 现在的主要变化当然在重新绑定数据源的方法SetGridSource 中。我们给该方法加入两个输入参数:当前的页面、发出控制(即判断用户点击的是“上一页”还是“下一页”等按钮)。下面的代码主要实现按钮型导航栏,有两个按钮“上一页”与“下一页”。“第一页”与“最后一页”的写法,请网友们自行实现。在如下示例中,column1为数据表之主键。每页有5行数据。 Pu6Linux联盟 Pu6Linux联盟 private void SetGridSource (int StartPosition, string GoToPage) Pu6Linux联盟 { Pu6Linux联盟 SqlConnection MyConnection = new SqlConnection(YourOwnConnectionString); Pu6Linux联盟 SqlCommand MyCommand = null; Pu6Linux联盟 switch (GoToPage) Pu6Linux联盟 { Pu6Linux联盟 case "上一页": Pu6Linux联盟 MyCommand = new Pu6Linux联盟 SqlCommand("SELECT TOP 5 * FROM Table WHERE column1 >= @ID ORDER BY column1",MyConnection); Pu6Linux联盟 if (StartPosition == 0) Pu6Linux联盟 MyCommand.Parameters.Add("@ID",SqlDbType.NVarChar, 10).Value = "";//这里参数10是ID字段的长度 Pu6Linux联盟 else Pu6Linux联盟 MyCommand.Parameters.Add("@ID",SqlDbType.NVarChar,10).Value = Pu6Linux联盟 ViewState[(DataGrid1.CurrentPageIndex + 1).ToString()]; Pu6Linux联盟 Pu6Linux联盟 break; Pu6Linux联盟 case "下一页": Pu6Linux联盟 MyCommand = new Pu6Linux联盟 SqlCommand("SELECT TOP 5 * FROM Table WHERE column1 > @ID ORDER BY column1",MyConnection);//注意:这里用的是>,不是>=哟 Pu6Linux联盟 MyCommand.Parameters.Add("@ID", SqlDbType.NVarChar,10).Value = DataGrid1.Items[4].Cells[0].Text;//Items[4]表示第5行即每页显示的最后一行 Pu6Linux联盟 break; Pu6Linux联盟 } Pu6Linux联盟 MyConnection.Open(); Pu6Linux联盟 SqlDataReader dr = MyCommand.ExecuteReader(); Pu6Linux联盟 DataGrid1.DataSource = dr; Pu6Linux联盟 DataGrid1.DataBind(); Pu6Linux联盟 dr.Close(); Pu6Linux联盟 MyConnection.Close(); Pu6Linux联盟 Pu6Linux联盟 //用ViewState来缓存刚才访问过的那一页的第一行中的主键值 Pu6Linux联盟 ViewState[(DataGrid1.CurrentPageIndex + 1).ToString()]=DataGrid1.Items[0].Cells[0].Text; Pu6Linux联盟 } Pu6Linux联盟 Pu6Linux联盟 注:如果是oracle数据库,可以在where条件中用rownum来控制上下页的条数与内容。 Pu6Linux联盟 Pu6Linux联盟 请在按扭的click事件里的最后调用SetGridSource方法,参数 Pu6Linux联盟 Pu6Linux联盟 StartPosition= DataGrid1.CurrentPageIndex *DataGrid1.PageSize; Pu6Linux联盟 Pu6Linux联盟 [参考]关于Datagrid分页的更详细的内容,可以参看华中科技大学出版社出版的章立民先生所著之《用实例学ASP.NET--使用VB.NET与ADO.NET》一书 Pu6Linux联盟 Pu6Linux联盟 ---- Pu6Linux联盟 Pu6Linux联盟 声明:本文版权与解释权归韩睿所有,如需转载,请保留完整的内容及此声明。 Pu6Linux联盟 Pu6Linux联盟 QQ: 18349592 Pu6Linux联盟 Pu6Linux联盟 E-Mail: henry7685@hotmail.com Pu6Linux联盟 Pu6Linux联盟 请访问本人专栏:http://www.csdn.net/develop/author/netauthor/Latitude/ Pu6Linux联盟 Pu6Linux联盟 作者Blog:http://blog.csdn.net/Latitude/ Pu6Linux联盟 相关文章 Pu6Linux联盟 我要学英语-我的忏悔书 Pu6Linux联盟 Henry的VB.NET之旅(十五)—动态事件处理方法 Pu6Linux联盟 Henry的VB.NET之旅(十四)—动态关联事件与处理程序 Pu6Linux联盟 Henry的VB.NET之旅(十三)—标准事件处理程序 Pu6Linux联盟 Henry的VB.NET之旅(十二)—事件驱动 Pu6Linux联盟 对该文的评论 Pu6Linux联盟 cleo ( 2003-06-09) Pu6Linux联盟 用这个试试:http://aspx.popdc.com,相信只要不是特别大的数据量,不需要使用自定义分页。 Pu6Linux联盟 zhucp ( 2003-06-03) Pu6Linux联盟 public string GetGoogleURL() 得到如下结果: Pu6Linux联盟 http://www.91code.com/upload/jszl/photos/20035316112544.gif Pu6Linux联盟 Pu6Linux联盟 Pu6Linux联盟 zhucp ( 2003-06-03) Pu6Linux联盟 using System; Pu6Linux联盟 using System.Data; Pu6Linux联盟 using System.IO; Pu6Linux联盟 using System.Runtime.InteropServices; Pu6Linux联盟 using System.Text; Pu6Linux联盟 namespace aspxdb Pu6Linux联盟 { Pu6Linux联盟 /// Pu6Linux联盟 /// 功能 : 操作 SQL Server 数据库的 DB类, 包括执行SQL ,执入返回主键ID Pu6Linux联盟 /// 得到google导航条,得到第一页,下一页,上一页,最后页, Pu6Linux联盟 /// 得到sql 语句的执行后的结果集总数,页总数,当前包数据等 Pu6Linux联盟 /// 作者:朱春平 Pu6Linux联盟 /// MSN :zhucp@msn.com QQ:6267294 EMail :zcp@chinahw.net Pu6Linux联盟 /// Pu6Linux联盟 /// Pu6Linux联盟 public class aspxdb_class Pu6Linux联盟 { Pu6Linux联盟 [DllImport("kernel32")] Pu6Linux联盟 private static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder retVal,int size,string filePath); Pu6Linux联盟 [DllImport("kernel32")] Pu6Linux联盟 private static extern void GetWindowsDirectory(StringBuilder WinDir,int count); Pu6Linux联盟 Pu6Linux联盟 Pu6Linux联盟 public System.Data.OleDb.OleDbConnection OleConnection; Pu6Linux联盟 public System.Data.OleDb.OleDbDataAdapter OleDataAdapter; Pu6Linux联盟 public System.Data.OleDb.OleDbCommand OleSelectCommand; Pu6Linux联盟 public System.Data.OleDb.OleDbCommand OleInsertCommand; Pu6Linux联盟 public System.Data.DataSet OleDataSet; Pu6Linux联盟 Pu6Linux联盟 private string ZCP_Url; Pu6Linux联盟 private string ZCP_QueryString; Pu6Linux联盟 private string ZCP_PageVName; Pu6Linux联盟 private string ZCP_FirstUrl,ZCP_PriorUrl,ZCP_NextUrl,ZCP_LastUrl; Pu6Linux联盟 Pu6Linux联盟 private int ZCP_RecordCount; Pu6Linux联盟 private int ZCP_PageCount; Pu6Linux联盟 private int ZCP_CurrentPage; Pu6Linux联盟 private int ZCP_ReturnRowCount; Pu6Linux联盟 Pu6Linux联盟 //取出Ini文件中的值 Pu6Linux联盟 private string IniReadValue(string Section,string Key) Pu6Linux联盟 { Pu6Linux联盟 StringBuilder temp = new StringBuilder(255); Pu6Linux联盟 GetWindowsDirectory(temp,255); Pu6Linux联盟 string WinPath = temp.ToString() + "\\DBConnection.Config"; Pu6Linux联盟 int i = GetPrivateProfileString(Section,Key,"",temp,255,WinPath); Pu6Linux联盟 return temp.ToString(); Pu6Linux联盟 } Pu6Linux联盟 //构造函数 Pu6Linux联盟 public aspxdb_class(string DBSymbol) Pu6Linux联盟 { Pu6Linux联盟 // TODO: 在此处添加构造函数逻辑 Pu6Linux联盟 string ConnString = IniReadValue(DBSymbol,"DBConf"); Pu6Linux联盟 Pu6Linux联盟 this.OleConnection = new System.Data.OleDb.OleDbConnection(ConnString); Pu6Linux联盟 Pu6Linux联盟 this.OleDataAdapter = new System.Data.OleDb.OleDbDataAdapter(); Pu6Linux联盟 this.OleSelectCommand = new System.Data.OleDb.OleDbCommand(); Pu6Linux联盟 this.OleInsertCommand = new System.Data.OleDb.OleDbCommand(); Pu6Linux联盟 this.OleDataSet = new System.Data.DataSet(); Pu6Linux联盟 Pu6Linux联盟 this.OleDataAdapter.SelectCommand = this.OleSelectCommand; Pu6Linux联盟 this.OleDataAdapter.InsertCommand = this.OleInsertCommand; Pu6Linux联盟 Pu6Linux联盟 this.OleSelectCommand.Connection = this.OleConnection; Pu6Linux联盟 this.OleInsertCommand.Connection = this.OleConnection; Pu6Linux联盟 } Pu6Linux联盟 //设置连接URL参数 Pu6Linux联盟 public void Set_BaseURL(string StrUrl, string StrPageVName, string StrQueryString) Pu6Linux联盟 { Pu6Linux联盟 this.ZCP_Url = StrUrl; Pu6Linux联盟 this.ZCP_PageVName = StrPageVName; Pu6Linux联盟 this.ZCP_QueryString = StrQueryString; Pu6Linux联盟 } Pu6Linux联盟 //设置参数,当前页与返回包大小 Pu6Linux联盟 public void Set_BaseParamenter(int ReturnCount, int CurrentPage) Pu6Linux联盟 { Pu6Linux联盟 this.ZCP_ReturnRowCount = ReturnCount; Pu6Linux联盟 if (CurrentPage <= 0) Pu6Linux联盟 { Pu6Linux联盟 this.ZCP_CurrentPage = 1; Pu6Linux联盟 }else Pu6Linux联盟 { Pu6Linux联盟 this.ZCP_CurrentPage = CurrentPage; Pu6Linux联盟 } Pu6Linux联盟 } Pu6Linux联盟 //查询语句,一次性查询下载所有的数据 Pu6Linux联盟 public void Query_None(string sql,string DataSetName_) Pu6Linux联盟 { Pu6Linux联盟 this.OleSelectCommand.CommandType = CommandType.Text; Pu6Linux联盟 this.OleSelectCommand.CommandText = sql; Pu6Linux联盟 this.OleConnection.Open(); Pu6Linux联盟 this.OleSelectCommand.ExecuteNonQuery(); Pu6Linux联盟 this.OleConnection.Close(); Pu6Linux联盟 if (DataSetName_.Equals("")) Pu6Linux联盟 { Pu6Linux联盟 this.OleDataAdapter.Fill(this.OleDataSet); Pu6Linux联盟 } Pu6Linux联盟 else Pu6Linux联盟 { Pu6Linux联盟 this.OleDataAdapter.Fill(this.OleDataSet,DataSetName_); Pu6Linux联盟 } Pu6Linux联盟 Pu6Linux联盟 } Pu6Linux联盟 //查询语句,下载ReturnCount条记录(起到分页) Pu6Linux联盟 public void Query_Page(string StrFields, string StrTables, string StrWhere, string StrOrder, string StrMasterKey,string DataSetName_) Pu6Linux联盟 { Pu6Linux联盟 string sql ,SQLWhere,SQLXWhere; Pu6Linux联盟 int RowPosition; Pu6Linux联盟 Pu6Linux联盟 //分析SQL Where 语句 Pu6Linux联盟 if (!StrWhere.Trim().Equals("")) Pu6Linux联盟 { Pu6Linux联盟 SQLWhere = " WHERE " + StrWhere; Pu6Linux联盟 SQLXWhere= " AND " + StrWhere; Pu6Linux联盟 }else Pu6Linux联盟 { Pu6Linux联盟 SQLWhere = ""; Pu6Linux联盟 SQLXWhere= ""; Pu6Linux联盟 } Pu6Linux联盟 sql = "SELECT COUNT(*) AS RCount FROM " + StrTables + SQLWhere; Pu6Linux联盟 this.OleSelectCommand.CommandType = CommandType.Text; Pu6Linux联盟 this.OleSelectCommand.CommandText = sql; Pu6Linux联盟 this.OleConnection.Open(); Pu6Linux联盟 this.ZCP_RecordCount = Convert.ToInt32(this.OleSelectCommand.ExecuteScalar()); Pu6Linux联盟 this.OleConnection.Close(); Pu6Linux联盟 //计算总页数 Pu6Linux联盟 this.ZCP_PageCount =(int)System.Math.Ceiling((double)this.ZCP_RecordCount / this.ZCP_ReturnRowCount); Pu6Linux联盟 //Get RowPosition Pu6Linux联盟 if (this.ZCP_CurrentPage <= 1) Pu6Linux联盟 { Pu6Linux联盟 RowPosition = 0; Pu6Linux联盟 } Pu6Linux联盟 else Pu6Linux联盟 { Pu6Linux联盟 RowPosition = this.ZCP_ReturnRowCount * (this.ZCP_CurrentPage - 1); Pu6Linux联盟 } Pu6Linux联盟 if (this.ZCP_CurrentPage >= this.ZCP_PageCount) Pu6Linux联盟 { Pu6Linux联盟 RowPosition = this.ZCP_ReturnRowCount * (this.ZCP_CurrentPage - 1); Pu6Linux联盟 } Pu6Linux联盟 RowPosition = this.ZCP_ReturnRowCount * (this.ZCP_CurrentPage - 1) ; Pu6Linux联盟 if (RowPosition < 0)RowPosition = 0; Pu6Linux联盟 Pu6Linux联盟 Pu6Linux联盟 //Get CurrentPage Data Package Pu6Linux联盟 sql = "SELECT TOP " + this.ZCP_ReturnRowCount.ToString() + " " + StrFields + " FROM "; Pu6Linux联盟 sql = sql + StrTables + " WHERE " + StrMasterKey + " NOT IN (SELECT TOP " + RowPosition.ToString(); Pu6Linux联盟 sql = sql + " " + StrMasterKey + " FROM " + StrTables + SQLWhere + " " + StrOrder; Pu6Linux联盟 sql = sql + ") " + SQLXWhere + " " + StrOrder; Pu6Linux联盟 Pu6Linux联盟 this.OleSelectCommand.CommandText = sql; Pu6Linux联盟 this.OleConnection.Open(); Pu6Linux联盟 this.OleSelectCommand.ExecuteNonQuery(); Pu6Linux联盟 this.OleConnection.Close(); Pu6Linux联盟 if (DataSetName_.Equals("")) Pu6Linux联盟 { Pu6Linux联盟 this.OleDataAdapter.Fill(this.OleDataSet); Pu6Linux联盟 }else Pu6Linux联盟 { Pu6Linux联盟 this.OleDataAdapter.Fill(this.OleDataSet,DataSetName_); Pu6Linux联盟 } Pu6Linux联盟 //--------------------- Calculate URL String -------------------------------- Pu6Linux联盟 //Get First Url Pu6Linux联盟 this.ZCP_FirstUrl = ZCP_Url + "?" + ZCP_PageVName + "=1" + ZCP_QueryString; Pu6Linux联盟 //Get Last Url Pu6Linux联盟 this.ZCP_LastUrl = ZCP_Url + "?" + ZCP_PageVName + "=" + ZCP_PageCount.ToString() + ZCP_QueryString; Pu6Linux联盟 //Get Prior Url Pu6Linux联盟 if ((this.ZCP_CurrentPage - 1) > 0) Pu6Linux联盟 { Pu6Linux联盟 this.ZCP_PriorUrl = ZCP_Url + "?" + ZCP_PageVName + "=" + Convert.ToString((ZCP_CurrentPage-1)) + ZCP_QueryString; Pu6Linux联盟 }else Pu6Linux联盟 { Pu6Linux联盟 this.ZCP_PriorUrl = this.ZCP_FirstUrl; Pu6Linux联盟 } Pu6Linux联盟 //Get Next Url Pu6Linux联盟 if ((this.ZCP_CurrentPage + 1) < this.ZCP_PageCount) Pu6Linux联盟 { Pu6Linux联盟 this.ZCP_NextUrl = ZCP_Url +"?" + ZCP_PageVName + "=" + Convert.ToSingle(ZCP_CurrentPage + 1) + ZCP_QueryString; Pu6Linux联盟 }else Pu6Linux联盟 { Pu6Linux联盟 this.ZCP_NextUrl = this.ZCP_LastUrl; Pu6Linux联盟 } Pu6Linux联盟 Pu6Linux联盟 } Pu6Linux联盟 //执行sql 语句的函数 Pu6Linux联盟 public int Exec_SQL(string sql) Pu6Linux联盟 { Pu6Linux联盟 int icount; Pu6Linux联盟 this.OleInsertCommand.CommandType = CommandType.Text; Pu6Linux联盟 this.OleInsertCommand.CommandText = sql; Pu6Linux联盟 this.OleConnection.Open(); Pu6Linux联盟 icount = this.OleInsertCommand.ExecuteNonQuery(); Pu6Linux联盟 this.OleConnection.Close(); Pu6Linux联盟 return icount; Pu6Linux联盟 } Pu6Linux联盟 //执行sql insert into 语句 Pu6Linux联盟 public int Exec_SQL_Insert(string sql) Pu6Linux联盟 { Pu6Linux联盟 int AutoID; Pu6Linux联盟 this.OleInsertCommand.CommandType = CommandType.Text; Pu6Linux联盟 this.OleInsertCommand.CommandText = sql + " " + "SELECT @@IDENTITY as IAutoID"; Pu6Linux联盟 this.OleConnection.Open(); Pu6Linux联盟 AutoID = Convert.ToInt32(this.OleInsertCommand.ExecuteScalar()); Pu6Linux联盟 this.OleConnection.Close(); Pu6Linux联盟 return AutoID; Pu6Linux联盟 } Pu6Linux联盟 //得到记录数 Pu6Linux联盟 public int GetRecordCount() Pu6Linux联盟 { Pu6Linux联盟 return this.ZCP_RecordCount; Pu6Linux联盟 } Pu6Linux联盟 //得到页总数 Pu6Linux联盟 public int GetPageCount() Pu6Linux联盟 { Pu6Linux联盟 return this.ZCP_PageCount; Pu6Linux联盟 } Pu6Linux联盟 //得到第一页URL Pu6Linux联盟 public string GetFirstURL() Pu6Linux联盟 { Pu6Linux联盟 return this.ZCP_FirstUrl; Pu6Linux联盟 } Pu6Linux联盟 //得到上一页URL Pu6Linux联盟 public string GetPrevURL() Pu6Linux联盟 { Pu6Linux联盟 return this.ZCP_PriorUrl; Pu6Linux联盟 } Pu6Linux联盟 //得到下一页URL Pu6Linux联盟 public string GetNextURL() Pu6Linux联盟 { Pu6Linux联盟 return this.ZCP_NextUrl; Pu6Linux联盟 } Pu6Linux联盟 //得到最后页URL Pu6Linux联盟 public string GetLastURL() Pu6Linux联盟 { Pu6Linux联盟 return this.ZCP_LastUrl; Pu6Linux联盟 } Pu6Linux联盟 //得到GoogleURL Pu6Linux联盟 public string GetGoogleURL() Pu6Linux联盟 { Pu6Linux联盟 string GoogleUrls = "",JS="",tmpStr; Pu6Linux联盟 int i,PNumber; Pu6Linux联盟 Pu6Linux联盟 if (this.ZCP_PageCount <= 1) return ""; Pu6Linux联盟 Pu6Linux联盟 //Url Number degression Pu6Linux联盟 PNumber = this.ZCP_CurrentPage; Pu6Linux联盟 for(i = 1 ; i <= 5 ; i++) Pu6Linux联盟 { Pu6Linux联盟 tmpStr = ""; Pu6Linux联盟 PNumber = PNumber - 1; Pu6Linux联盟 if (PNumber > 0) Pu6Linux联盟 { Pu6Linux联盟 tmpStr = tmpStr + " Pu6Linux联盟 tmpStr = tmpStr + ZCP_Url + "?" + ZCP_PageVName + "=" + PNumber.ToString() + ZCP_QueryString; Pu6Linux联盟 tmpStr = tmpStr + " style=\"TEXT-DECORATION: none\">"; Pu6Linux联盟 tmpStr = tmpStr + PNumber.ToString() + " "; Pu6Linux联盟 GoogleUrls = tmpStr + GoogleUrls; Pu6Linux联盟 }else Pu6Linux联盟 { Pu6Linux联盟 break; Pu6Linux联盟 } Pu6Linux联盟 } Pu6Linux联盟 Pu6Linux联盟 //First URL Pu6Linux联盟 GoogleUrls = "9 " + GoogleUrls; Pu6Linux联盟 Pu6Linux联盟 Pu6Linux联盟 //Current URL Pu6Linux联盟 if (this.ZCP_CurrentPage > 0) Pu6Linux联盟 { Pu6Linux联盟 GoogleUrls = GoogleUrls + "" + ZCP_CurrentPage.ToString() + " "; Pu6Linux联盟 } Pu6Linux联盟 Pu6Linux联盟 //Url Number increase Pu6Linux联盟 PNumber = this.ZCP_CurrentPage; Pu6Linux联盟 for(i = 1 ; i <= 5 ; i++) Pu6Linux联盟 { Pu6Linux联盟 PNumber = PNumber + 1; Pu6Linux联盟 if (PNumber <= this.ZCP_PageCount) Pu6Linux联盟 { Pu6Linux联盟 GoogleUrls = GoogleUrls + " Pu6Linux联盟 GoogleUrls = GoogleUrls + ZCP_Url + "?" + ZCP_PageVName + "=" + PNumber.ToString() + ZCP_QueryString; Pu6Linux联盟 GoogleUrls = GoogleUrls + " style=\"TEXT-DECORATION: none\">"; Pu6Linux联盟 GoogleUrls = GoogleUrls + PNumber.ToString() + " "; Pu6Linux联盟 }else Pu6Linux联盟 { Pu6Linux联盟 break; Pu6Linux联盟 } Pu6Linux联盟 } Pu6Linux联盟 // Last Url Pu6Linux联盟 GoogleUrls = GoogleUrls + ":"; Pu6Linux联盟 GoogleUrls = GoogleUrls + ""; Pu6Linux联盟 //GoogleUrls = GoogleUrls + ""; Pu6Linux联盟 tmpStr = ZCP_Url + "?" + ZCP_QueryString + "&" + ZCP_PageVName + "=" ; Pu6Linux联盟 JS = ""; Pu6Linux联盟 JS = JS + "function Go_Url_Button_Click(){"; Pu6Linux联盟 JS = JS + "if (document.all.TN_Pages.value == \"\") return;"; Pu6Linux联盟 JS = JS + "if (document.all.TN_Pages.value>" + ZCP_PageCount.ToString() + ") return;"; Pu6Linux联盟 JS = JS + "var i,j,strTemp=\"0123456789\";"; Pu6Linux联盟 JS = JS + "var NUM = document.all.TN_Pages.value;"; Pu6Linux联盟 JS = JS + "if ( NUM.length== 0)return;"; Pu6Linux联盟 JS = JS + "for (i=0;i Pu6Linux联盟 JS = JS + "j=strTemp.indexOf(NUM.charAt(i));"; Pu6Linux联盟 JS = JS + "if (j==-1) return;}"; Pu6Linux联盟 JS = JS + "var tmp_url =\"" + tmpStr + "\" + document.all.TN_Pages.value;"; Pu6Linux联盟 JS = JS + "window.location.href = tmp_url;}"; Pu6Linux联盟 JS = JS + ""; Pu6Linux联盟 GoogleUrls = GoogleUrls + JS; Pu6Linux联盟 return GoogleUrls; Pu6Linux联盟 } Pu6Linux联盟 //到得当前包 Pu6Linux联盟 public System.Data.DataSet GetDataSet() Pu6Linux联盟 { Pu6Linux联盟 return this.OleDataSet; Pu6Linux联盟 } Pu6Linux联盟 Pu6Linux联盟 public void DestroySelf() Pu6Linux联盟 { Pu6Linux联盟 try Pu6Linux联盟 { Pu6Linux联盟 this.OleDataSet.Clear(); Pu6Linux联盟 this.OleConnection.Close(); Pu6Linux联盟 } Pu6Linux联盟 catch(System.Data.OleDb.OleDbException) Pu6Linux联盟 { Pu6Linux联盟 ; Pu6Linux联盟 } Pu6Linux联盟 } Pu6Linux联盟 Pu6Linux联盟 } Pu6Linux联盟 } Pu6Linux联盟
Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论 |
|
|
|
|
|