?? depsgrid.cs
字號:
namespace Employee_Directory
{
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public class DepsGrid : System.Web.UI.Page
{
//部門管理窗口自定義控件的聲名
protected CCUtility Utility;
//數據表格表單、變量等的聲名
protected System.Web.UI.HtmlControls.HtmlTableRow deps_no_records;
protected string deps_sSQL;
protected string deps_sCountSQL;
protected int deps_CountPage;
protected CCPager deps_Pager;protected System.Web.UI.WebControls.LinkButton deps_insert;
protected System.Web.UI.WebControls.Repeater deps_Repeater;
protected int i_deps_curpage=1;
//定義各表單事件保護字符串
protected string deps_FormAction="DepsRecord.aspx?";
//初始化事件對象
public DepsGrid()
{
this.Init += new System.EventHandler(Page_Init);
}
//AdminMenu中的自定義包含控件結束
public void ValidateNumeric(object source, ServerValidateEventArgs args) {
try{
Decimal temp=Decimal.Parse(args.Value);
args.IsValid=true;
}catch{
args.IsValid=false; }
}
//定義登錄窗口顯示控件過程
//初始化頁面過程,創建一個Utility實例,并調用其相應的各方法
protected void Page_Load(object sender, EventArgs e)
{
Utility=new CCUtility(this);
Utility.CheckSecurity(3);
// 完成窗口安全驗證
if (!IsPostBack){
Page_Show(sender, e);
}
}
//頁面關閉過程
protected void Page_Unload(object sender, EventArgs e)
{
if(Utility!=null) Utility.DBClose();
}
//窗口中控件定義事件處理過程
protected void Page_Init(object sender, EventArgs e)
{
InitializeComponent();
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.Unload += new System.EventHandler(this.Page_Unload);
deps_insert.Click += new System.EventHandler (this.deps_insert_Click);
deps_Pager.NavigateCompleted+=new NavigateCompletedHandler(this.deps_pager_navigate_completed);
}
//定義整體顯示頁面過程
protected void Page_Show(object sender, EventArgs e)
{
deps_Bind();
}
// DepsGrid Show end
//完成表單初始化
//定義每一頁顯示的部門記錄數
const int deps_PAGENUM = 20;
//查詢數據庫中部門記錄數據集合
ICollection deps_CreateDataSource() {
deps_sSQL = "";
deps_sCountSQL = "";
string sWhere = "", sOrder = "";
bool HasParam = false;
//記錄顯示的排序方式
sOrder = " order by d.name Asc";
if(Utility.GetParam("Formdeps_Sorting").Length>0&&!IsPostBack)
{ViewState["SortColumn"]=Utility.GetParam("Formdeps_Sorting");
ViewState["SortDir"]="ASC";}
if(ViewState["SortColumn"]!=null) sOrder = " ORDER BY " + ViewState["SortColumn"].ToString()+" "+ViewState["SortDir"].ToString();
System.Collections.Specialized.StringDictionary Params =new System.Collections.Specialized.StringDictionary();
deps_sSQL = "select [d].[dep_id] as d_dep_id, " +
"[d].[name] as d_name " +
" from [deps] d ";
//組合Sql語句
deps_sSQL = deps_sSQL + sWhere + sOrder;
if (deps_sCountSQL.Length== 0) {
int iTmpI = deps_sSQL.ToLower().IndexOf("select ");
int iTmpJ = deps_sSQL.ToLower().LastIndexOf(" from ")-1;
deps_sCountSQL = deps_sSQL.Replace(deps_sSQL.Substring(iTmpI + 7, iTmpJ-6), " count(*) ");
iTmpI = deps_sCountSQL.ToLower().IndexOf(" order by");
if (iTmpI > 1) deps_sCountSQL = deps_sCountSQL.Substring(0, iTmpI);
}
//數據聯結
OleDbDataAdapter command = new OleDbDataAdapter(deps_sSQL, Utility.Connection);
DataSet ds = new DataSet();
command.Fill(ds, (i_deps_curpage - 1) * deps_PAGENUM, deps_PAGENUM,"deps");
OleDbCommand ccommand = new OleDbCommand(deps_sCountSQL, Utility.Connection);
int PageTemp=(int)ccommand.ExecuteScalar();
deps_Pager.MaxPage=(PageTemp%deps_PAGENUM)>0?(int)(PageTemp/deps_PAGENUM)+1:(int)(PageTemp/deps_PAGENUM);
bool AllowScroller=deps_Pager.MaxPage==1?false:true;
DataView Source;
Source = new DataView(ds.Tables[0]);
if (ds.Tables[0].Rows.Count == 0){
deps_no_records.Visible = true;
AllowScroller=false;}
else
{deps_no_records.Visible = false;
AllowScroller=AllowScroller&&true;}
deps_Pager.Visible=AllowScroller;
return Source;
//顯示完成
}
//定義導航頁
protected void deps_pager_navigate_completed(Object Src, int CurrPage)
{
i_deps_curpage=CurrPage;
deps_Bind();
}
//綁定數據
void deps_Bind() {
deps_Repeater.DataSource = deps_CreateDataSource();
deps_Repeater.DataBind();
}
//插入按鈕事件
void deps_insert_Click(Object Src, EventArgs E) {
string sURL = deps_FormAction+"";
Response.Redirect(sURL);
}
//正反排序事件
protected void deps_SortChange(Object Src, EventArgs E) {
if(ViewState["SortColumn"]==null || ViewState["SortColumn"].ToString()!=((LinkButton)Src).CommandArgument){
ViewState["SortColumn"]=((LinkButton)Src).CommandArgument;
ViewState["SortDir"]="ASC";
}else{
ViewState["SortDir"]=ViewState["SortDir"].ToString()=="ASC"?"DESC":"ASC";
}
deps_Bind();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -