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.Drawing;using System.Collections;using Telerik.Web.UI;using System.IO;using System.Web.Services;namespace My_Workshop.A4f{ public partial class DataSource : System.Web.UI.Page { public AllClass AllClass = new AllClass(); SqlConnection con = AllClass.dbConnection(); //获取页码 public void getcnt() { AllClass.SearchDef Def = new AllClass.SearchDef(); Def.AssPat = this.RadAssPat; Def.Business = this.RadBusi; Def.ProSeries = this.RadPro; Def.PtoTyp = this.RadPtoTyp; Def.Disposal = this.RadDisposal1; Def.DefMat = this.RadDefMat; Def.STimd = this.TxtSTim.Text; Def.OTimd = this.TxtOTim.Text; Def.ProCode = this.RadProCode; Def.Modul = this.RadModul; Def.CusCode = this.RadCusCode; Def.CityOffice = this.RadCityOffice; Def.PlantCode = this.RadPlantCode; Def.OilWay = this.RadOilWay.Text; Def.AssPlant = this.RadAssPlant1; Def.AssPatCod = this.RadPat; Def.STima = this.TxtSTima.Text; Def.OTima = this.TxtOTima.Text; string sc = "select count(*) from tbDef where(1=1) " + AllClass.getwdd(Def); ViewState["cnt"] = AllClass.ExecuteScalar(sc, con).ToString(); } //显示 public void show(int currentpage) { AllClass.SearchDef Def = new AllClass.SearchDef(); Def.AssPat = this.RadAssPat; Def.Business = this.RadBusi; Def.ProSeries = this.RadPro; Def.PtoTyp = this.RadPtoTyp; Def.Disposal = this.RadDisposal1; Def.DefMat = this.RadDefMat; Def.STimd = this.TxtSTim.Text; Def.OTimd = this.TxtOTim.Text; Def.ProCode = this.RadProCode; Def.Modul = this.RadModul; Def.CusCode = this.RadCusCode; Def.CityOffice = this.RadCityOffice; Def.PlantCode = this.RadPlantCode; Def.OilWay = this.RadOilWay.Text; Def.AssPlant = this.RadAssPlant1; Def.AssPatCod = this.RadPat; Def.STima = this.TxtSTima.Text; Def.OTima = this.TxtOTima.Text; int pagesize = this.RadDataPager1.PageSize; string sw = AllClass.getwdd(Def); string s = "select top " + pagesize + "DefID,MendDat,Business,OilSystem,CusNam,AssDat,AssPlant,DefMat,ProSeries,AssPatCod,AssPat,Disposal,Modul,PlantNam from tbDef where DefID not in(select top " + pagesize * (currentpage) + " DefID from tbDef where(1=1) " + sw + "order by DefID desc)" + AllClass.getwdd(Def) + "order by DefID desc"; AllClass.showdata0(s, con, this.RadGrid2); } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { ((Label)(this.Page.Master.FindControl("LblSitMap"))).Text = "故障明细管理"; this.TxtOTim.Text = DateTime.Now.ToString("yyyy-MM-dd"); this.TxtSTim.Text = DateTime.Now.ToString("yyyy-01-01"); DataTable dtt = new DataTable(); this.RadGrid2.MasterTableView.NoMasterRecordsText = "欢迎您!"; this.RadGrid2.DataSource = dtt; this.RadGrid2.DataBind(); dtt.Dispose(); } } protected void tb_ButtonClick(object sender, Telerik.Web.UI.RadToolBarEventArgs e) { switch (e.Item.Text) { case "查询": getcnt(); show(this.RadDataPager1.CurrentPageIndex); break; default: break; } } protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem) { e.Item.Attributes.Add("OnDblClick", "window.radopen('DataView/DefDetail.aspx?DefID=" + this.RadGrid2.MasterTableView.DataKeyValues[e.Item.ItemIndex]["DefID"]+ "', 'RadWindow1');"); } } protected void RadDataPager1_TotalRowCountRequest(object sender, RadDataPagerTotalRowCountRequestEventArgs e) { e.TotalRowCount = Convert.ToInt32(ViewState["cnt"]); } protected void RadDataPager1_PageIndexChanged(object sender, RadDataPagerPageIndexChangeEventArgs e) { show(e.NewPageIndex); } string GenerateButtonText(string argument) { return String.Format("<span>{0}</span>", int.Parse(argument) + 1); } protected void RadDataPager1_FieldCreated(object sender, RadDataPagerFieldCreatedEventArgs e) { if (e.Item.Field is RadDataPagerButtonField && (e.Item.Field as RadDataPagerButtonField).FieldType == PagerButtonFieldType.Numeric) foreach (IButtonControl ctrl in e.Item.Controls) ctrl.Text = GenerateButtonText(ctrl.CommandArgument); } }}public void showdata0(string s, SqlConnection con, RadGrid gv) { DataTable dt = AllClass.dt(s, con); gv.DataSource = dt; gv.DataBind(); dt.Dispose(); }