⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sb_search.aspx.cs

📁 该系统采用asp+sql的实验室管理系统
💻 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 Data_Contrl;
using OWC;

namespace Sbgl.Admin
{
	/* ****************************************************	
				   重庆杰诺软件开发工作室

	QQ:83898700
	EMAIL:gimao@163.com
	url:www.gisii.com
	***************************************************** */
	/// <summary>
	/// Sb_Search 的摘要说明。
	/// </summary>
	public partial class Sb_Search : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox fyq;
		protected System.Web.UI.HtmlControls.HtmlGenericControl WdTable;
		private int CountRows;
		private string sql;
		public string sb;
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if (!IsPostBack)
			{
				string[] strsql;
				strsql = new string[2];
				strsql[0] = "Select id as bm,bmnr as nr From h_sbzl";
				strsql[1] = "Select id as bm,bmnr as nr from h_sblb";
				DropDownList[] ddl;
				ddl = new DropDownList[2];
				ddl[0] = DDL_Sbzl;
				ddl[1] = DDL_Sblb;
				for(int i= 0;i<=1;i++) 
				{
					DDL_BindData(strsql[i],ddl[i]);
				}
			}

		    sb=Request["pxzd"]==null?"":Request["pxzd"].ToString();
			Class_Name.Text=Request["UserName"]==null?"":Request["UserName"].ToString();
			Classid.Value=Request["classid"]==null?"":Request["classid"].ToString();
			BindDataGrid();    
			ShowStats();  
		}
		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

		private void BindDataGrid()
		{


			 sql="select a.id as id,b.bmnr as sbzl,c.bmnr as sblb,a.class_name as class_name,a.syr as syr,a.sn as sn,a.sbzt as sbzt,a.sysj as sysj,a.jz as jz from h_sb_info a,h_sbzl b,H_sblb c where b.id=a.sbzlid and c.id=a.sblbid";
			if(Classid.Value!="")
			{
				Tree_Contrl zgjg= new Tree_Contrl();
				sql+=" and a.Classid in ("+zgjg.Treeinit(Convert.ToInt32(Classid.Value.ToString()))+"0)";
			}
			if(DDL_Sbzl.SelectedValue!="")
			{
				sql+=" and a.sbzlid="+Convert.ToInt32(DDL_Sbzl.SelectedValue)+"";
			}
			if(DDL_Sblb.SelectedValue!="")
			{
				sql+=" and a.sblbid="+Convert.ToInt32(DDL_Sblb.SelectedValue)+"";
			}
			if(sbzt.Value!="")
			{
				sql+=" and a.sbzt='"+sbzt.Value+"'";
			}
			if(wxsjq.Text.ToString()!=""&&wxsjz.Text.ToString()!="")
			{
				sql+=" and a.sysj between '"+Convert.ToDateTime(wxsjq.Text)+"' and '"+Convert.ToDateTime(wxsjz.Text)+"'";
			}
			if (sb=="")
			{
				sql+=" order by id desc";
			}
			else
			{
				sql+=" order by "+sb+" desc";
			}
			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("没有相应的数据");
			}
			
			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();  
	
		}
		private void Ok_Click(object sender, System.EventArgs e)
		{
			    pxzd1.Value=Request.Form["pxzd"]==null?"":Request.Form["pxzd"].ToString();
				BindDataGrid();    
				ShowStats();  
		}

		private 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;
		}

		private void DDL_Sbzl_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string sbzl_my = DDL_Sbzl.SelectedValue;
			if(sbzl_my!="")
			{
				string strsql = "Select id as bm,bmnr as nr from h_sblb where zlid="+Convert.ToInt32(sbzl_my)+"";
				DDL_BindData(strsql,DDL_Sblb);
			}
			else
			{
				string strsql = "Select id as bm,bmnr as nr from h_sblb";
				DDL_BindData(strsql,DDL_Sblb);
			}
			BindDataGrid();    
			ShowStats();  
		}

		protected void DDL_Sblb_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			BindDataGrid();    
			ShowStats();  
		}

		protected void Button2_Click(object sender, System.EventArgs e)
		{
			sql="select a.id as 编号,b.bmnr as 设备类别,c.bmnr as 设备种类,a.class_name as 部门,a.syr as 使用人,a.sn as 型号,a.jz as jz,a.sbzt as 设备状态,a.sysj as 使用时间,a.cgsj as 采购时间,a.ccrq as 出厂时间,a.bz as 备注 from h_sb_info a,h_sbzl b,H_sblb c where b.id=a.sbzlid and c.id=a.sblbid";
			if(Classid.Value!="")
			{
				Tree_Contrl zgjg= new Tree_Contrl();
				sql+=" and a.Classid in ("+zgjg.Treeinit(Convert.ToInt32(Classid.Value.ToString()))+"0)";
			}
			if(DDL_Sbzl.SelectedValue!="")
			{
				sql+=" and a.sbzlid="+Convert.ToInt32(DDL_Sbzl.SelectedValue)+"";
			}
			if(DDL_Sblb.SelectedValue!="")
			{
				sql+=" and a.sblbid="+Convert.ToInt32(DDL_Sblb.SelectedValue)+"";
			}
			if(sbzt.Value!="")
			{
				sql+=" and a.sbzt='"+sbzt.Value+"'";
			}
			if(wxsjq.Text.ToString()!=""&&wxsjz.Text.ToString()!="")
			{
				sql+=" and a.sysj between '"+Convert.ToDateTime(wxsjq.Text)+"' and '"+Convert.ToDateTime(wxsjz.Text)+"'";
			}
			pxzd1.Value=Request.Form["pxzd"]==null?"":Request.Form["pxzd"].ToString();
			if (sb=="")
			{
				sql+=" order by a.id desc";
			}
			else
			{
				sql+=" order by "+sb+" desc";
			}
			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();
				///	xlsheet.ActiveSheet.Cells[j,FieldNumber+1]+="";
				}
				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);
			}

		}

		protected void my_ok_Click(object sender, System.EventArgs e)
		{
		
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -