📄 wx_searcher.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Datamodel;
using OWC;
namespace Sbgl.Admin
{
/* ****************************************************
重庆杰诺软件开发工作室
QQ:83898700
EMAIL:gimao@163.com
url:www.gisii.com
***************************************************** */
/// <summary>
/// Wx_Searcher 的摘要说明。
/// </summary>
public partial class Wx_Searcher : System.Web.UI.Page
{
protected int CountRows;
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!IsPostBack)
{
string sql = "Select id as bm,bmnr as nr from h_sblb";
DDL_BindData(sql,DDL_Sblb);
}
}
private void DDL_BindData(string strSQL,DropDownList DDL)
{
//DDL的函数过程!
CreateDb mydb = new CreateDb();
DBManager my = mydb.Createdb();
my.OpenConn();
DDL.DataSource =my.ExeCommand(strSQL).ExecuteReader();
DDL.DataTextField = "nr";
DDL.DataValueField = "bm";
DDL.DataBind();
DDL.Items.Insert(0,new ListItem("全部", ""));
my.CloseConn();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected void Ok_Click(object sender, System.EventArgs e)
{
BindDataGrid();
ShowStats();
}
private void BindDataGrid()
{
string sql="select a.id as id,b.sn as 设备型号,c.bmnr as 设备类别,a.wxr as 维修人,a.wxfy as 维修费用 from h_wxjl a,h_sb_info b,h_Sblb c where a.sbbh=b.id and b.sblbid=c.id";
if(Classid.Value!="")
{
sql+=" and b.classid="+Convert.ToInt32(Classid.Value);
}
if(DDL_Sblb.SelectedValue!="")
{
sql+=" and b.sblbid="+Convert.ToInt32(DDL_Sblb.SelectedValue)+"";
}
if(fyq.Text.ToString()!="")
{
sql+=" and a.wxfy>="+Convert.ToInt32(fyq.Text)+"";
}
if(fyz.Text.ToString()!="")
{
sql+=" and a.wxfy<="+Convert.ToInt32(fyz.Text)+"";
}
if(wxsjq.Text.ToString()!="")
{
sql+=" and a.kssj<'"+Convert.ToDateTime(wxsjq.Text)+"'";
}
if(wxsjz.Text.ToString()!="")
{
sql+=" and a.jssj<'"+Convert.ToDateTime(wxsjz.Text)+"'";
}
DataSet myds =new DataSet();
CreateDb mydb = new CreateDb();
DBManager my = mydb.Createdb();
my.OpenConn();
CountRows = my.ExecuteCreateDataSet(sql).Fill(myds);
if (CountRows>0)
{
DataGrid1.DataSource = myds.DefaultViewManager.DataSet;
DataGrid1.DataBind();
}
else
{
Response.Write("没有相应的数据");
}
// Close the connection when done with it.
my.CloseConn();
}
private void ShowStats()
{
if (CountRows==0)
{
btnFirst.Visible = false;
btnPrev.Visible = false;
btnNext.Visible = false;
btnLast.Visible = false;
btnGoto.Visible = false;
txtIndex.Visible =false;
lblTotal.Visible = false;
DataGrid1.Visible =false;
}
else
{
btnFirst.Visible = true;
btnPrev.Visible = true;
btnNext.Visible = true;
btnLast.Visible = true;
btnGoto.Visible = true;
txtIndex.Visible =true;
lblTotal.Visible = true;
DataGrid1.Visible = true;
btnFirst.Enabled=true;
btnPrev.Enabled=true;
btnLast.Enabled=true;
btnNext.Enabled=true;
if(DataGrid1.CurrentPageIndex==0)
{
btnFirst.Enabled=false;
btnPrev.Enabled=false;
}
if(DataGrid1.CurrentPageIndex==(DataGrid1.PageCount - 1))
{
btnLast.Enabled=false;
btnNext.Enabled=false;
}
lblTotal.Text = "共计:" +CountRows.ToString() + "条设备信息,共"+ DataGrid1.PageCount.ToString()+"页";
txtIndex.Text = (DataGrid1.CurrentPageIndex + 1).ToString();
}
}
public void PagerButtonClick(Object sender, CommandEventArgs e)
{
//由外部分页 UI 使用
String arg = e.CommandArgument.ToString();
switch(arg)
{
case "Last":
DataGrid1.CurrentPageIndex = (DataGrid1.PageCount - 1);
break;
case "First":
DataGrid1.CurrentPageIndex = 0;
break;
case "Next":
if (DataGrid1.CurrentPageIndex < (DataGrid1.PageCount - 1)) DataGrid1.CurrentPageIndex ++;
break;
case "Prev":
if (DataGrid1.CurrentPageIndex > 0) DataGrid1.CurrentPageIndex --;
break;
}
BindDataGrid();
ShowStats();
}
protected void btnGoto_Click(object sender, System.EventArgs e)
{
int gotoIndex = System.Convert.ToInt32(txtIndex.Text) - 1;
if(gotoIndex >= 0 && gotoIndex <=(DataGrid1.PageCount - 1))
{
DataGrid1.Visible = true;
DataGrid1.CurrentPageIndex = gotoIndex;
BindDataGrid();
ShowStats();
}
else DataGrid1.Visible = false;
}
protected void DDL_Sblb_SelectedIndexChanged(object sender, System.EventArgs e)
{
BindDataGrid();
ShowStats();
}
protected void Button2_Click(object sender, System.EventArgs e)
{
string sql="select a.id as id,b.sn as 设备型号,c.bmnr as 设备类别,a.wxr as 维修人,a.wxgs as 维修工时,a.wxfy as 维修费用,a.gzyy as 故障原因,a.kssj as 开始时间,a.jssj as 结束时间,a.bz as 备注 from h_wxjl a,h_sb_info b,h_Sblb c where a.sbbh=b.id and b.sblbid=c.id";
if(Classid.Value!="")
{
sql+=" and b.classid="+Convert.ToInt32(Classid.Value);
}
if(DDL_Sblb.SelectedValue!="")
{
sql+=" and b.sblbid="+Convert.ToInt32(DDL_Sblb.SelectedValue)+"";
}
if(fyq.Text.ToString()!="")
{
sql+=" and a.wxfy>="+Convert.ToInt32(fyq.Text)+"";
}
if(fyz.Text.ToString()!="")
{
sql+=" and a.wxfy<="+Convert.ToInt32(fyz.Text)+"";
}
if(wxsjq.Text.ToString()!="")
{
sql+=" and a.kssj<'"+Convert.ToDateTime(wxsjq.Text)+"'";
}
if(wxsjz.Text.ToString()!="")
{
sql+=" and a.jssj<'"+Convert.ToDateTime(wxsjz.Text)+"'";
}
CreateDb mydb = new CreateDb();
DBManager my = mydb.Createdb();
my.OpenConn();
IDataReader dr=my.ExecuteCreateReader(my.ExeCommand(sql));
int FieldNumber = dr.FieldCount;
if(FieldNumber == 0)
Response.End();
SpreadsheetClass xlsheet = new SpreadsheetClass();
for(int i=0;i<FieldNumber;i++)
{
xlsheet.ActiveSheet.Cells[1,i+1]=dr.GetName(i).ToString();
}
/// xlsheet.ActiveSheet.Cells[1,FieldNumber+1]="详细配置";
int j=2;
while(dr.Read())
{
for(int i=0;i<FieldNumber;i++)
{
xlsheet.ActiveSheet.Cells[j,i+1]=dr.GetValue(i).ToString();
}
j=j+1;
}
try
{
xlsheet.ActiveSheet.Export(Server.MapPath("test.xls"),OWC.SheetExportActionEnum.ssExportActionNone);
Response.Write("<script lanuage=javascript>");
Response.Write("window.open('test.xls');");
Response.Write("</script>");
}
catch(Exception er)
{
throw (er);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -