您目前尚未登陆,请选择【登陆】或【注册
首页->其他源码->学生管理信息系统+留言板>>EmpsGrid.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:学生管理信息系统+留言板
当前文件:文件类型 StudentSys/EmpsGrid.cs打开代码结构图
普通视图
		            
1namespace StudentSys 2{ 3 4 using System; 5 using System.Collections; 6 using System.ComponentModel; 7 using System.Data; 8 using System.Data.OleDb; 9 using System.Drawing; 10 using System.Web; 11 using System.Web.SessionState; 12 using System.Web.UI; 13 using System.Web.UI.WebControls; 14 using System.Web.UI.HtmlControls; 15 using StudentSys.Module; 16 17 public class EmpsGrid : System.Web.UI.Page 18 19 { 20 21//职工管理窗口定义控件的声名 22 protected CCUtility Utility; 23 24 //表格表单,变量等的声名 25 protected System.Web.UI.HtmlControls.HtmlTableRow emps_no_records; 26 protected string emps_sSQL; 27 protected string emps_sCountSQL; 28 protected int emps_CountPage; 29 protected CCPager emps_Pager;protected System.Web.UI.WebControls.LinkButton emps_insert; 30 protected System.Web.UI.WebControls.Repeater emps_Repeater; 31 protected int i_emps_curpage=1; 32 33 //查询表单、变量等的声名 34 protected System.Web.UI.WebControls.Button Search_search_button; 35 protected System.Web.UI.WebControls.TextBox Search_emp_login; 36 protected System.Web.UI.WebControls.TextBox Search_name; 37 protected System.Web.UI.WebControls.DropDownList Search_manmonth; 38 39 //定义各表单事件保护字符串 40 protected string emps_FormAction="EmpsRecord.aspx?"; 41 protected String[] emps_emp_level_lov = "0;;3;Admin".Split(new Char[] {';'});protected String[] emps_manmonth_lov = "0;;1;Yes".Split(new Char[] {';'}); 42 protected string Search_FormAction="EmpsGrid.aspx?"; 43 protected System.Web.UI.WebControls.Label SearchForm_Title; 44 protected System.Web.UI.WebControls.Label InfoForm_Title; 45 protected System.Web.UI.WebControls.Label emps_Column_emp_id; 46 protected System.Web.UI.WebControls.LinkButton emps_Column_emp_login; 47 protected System.Web.UI.WebControls.LinkButton emps_Column_name; 48 protected System.Web.UI.WebControls.LinkButton emps_Column_emp_level; 49 protected System.Web.UI.WebControls.LinkButton emps_Column_manmonth; 50 protected System.Web.UI.WebControls.Label Label1; 51 protected String[] Search_manmonth_lov = ";All;0;No;1;Yes".Split(new Char[] {';'}); 52 53//初始化事件 54 public EmpsGrid() 55 { 56 this.Init += new System.EventHandler(Page_Init); 57 } 58 59// EmpsGrid中的自定义包含控件结束 60 61 public void ValidateNumeric(object source, ServerValidateEventArgs args) { 62 try{ 63 Decimal temp=Decimal.Parse(args.Value); 64 args.IsValid=true; 65 }catch{ 66 args.IsValid=false; } 67 } 68//定义登录窗口显示控件过程 69//初始化页面过程,创建一个Utility实例,并调用其相应的各方法 70 protected void Page_Load(object sender, EventArgs e) 71 { 72 Utility=new CCUtility(this); 73 Utility.CheckSecurity(3); 74 // 完成窗口安全验证 75 76 if (!IsPostBack){ 77 Page_Show(sender, e); 78 } 79 } 80//页面关闭过程 81 82//窗口中控件定义事件处理过程 83 protected void Page_Unload(object sender, EventArgs e) 84 { 85 if(Utility!=null) Utility.DBClose(); 86 } 87 88//窗口中控件定义事件处理过程 89 protected void Page_Init(object sender, EventArgs e) 90 { 91 InitializeComponent(); 92 } 93 private void InitializeComponent() 94 { 95 this.Search_search_button.Click += new System.EventHandler(this.Search_search_Click); 96 this.emps_insert.Click += new System.EventHandler(this.emps_insert_Click); 97 this.Unload += new System.EventHandler(this.Page_Unload); 98 this.Load += new System.EventHandler(this.Page_Load); 99 100 } 101 102//定义整体显示页面过程 103 protected void Page_Show(object sender, EventArgs e) 104 { 105 emps_Bind(); 106 Search_Show(); 107 108 } 109 110 111 112// EmpsGrid Show end 113//完成表单初始化 114 115 //定义表格每页显示学生记录条数 116 const int emps_PAGENUM = 10; 117 118 //创建数据库种职工数据记录的数据源集合 119 ICollection emps_CreateDataSource() 120 { 121 122 //开始定义查询数据Sql字符串 123 emps_sSQL = ""; 124 emps_sCountSQL = ""; 125 string sWhere = "", sOrder = ""; 126 bool HasParam = false; 127 128 //建立排序方式 129 sOrder = " order by e.emp_login Asc"; 130 if(Utility.GetParam("Formemps_Sorting").Length>0&&!IsPostBack) 131 { 132 ViewState["SortColumn"]=Utility.GetParam("Formemps_Sorting"); 133 ViewState["SortDir"]="ASC"; 134 } 135 if(ViewState["SortColumn"]!=null) sOrder = " ORDER BY " + ViewState["SortColumn"].ToString()+" "+ViewState["SortDir"].ToString(); 136 137 //建立学生属性 138 System.Collections.Specialized.StringDictionary Params =new System.Collections.Specialized.StringDictionary(); 139 140 141 if(!Params.ContainsKey("emp_login")){ 142 string temp=Utility.GetParam("emp_login"); 143 Params.Add("emp_login",temp);} 144 145 if(!Params.ContainsKey("manmonth")){ 146 string temp=Utility.GetParam("manmonth"); 147 if (Utility.IsNumeric(null,temp) && temp.Length>0) { temp = CCUtility.ToSQL(temp, CCUtility.FIELD_TYPE_Number);} else {temp = "";} 148 Params.Add("manmonth",temp);} 149 150 if(!Params.ContainsKey("name")){ 151 string temp=Utility.GetParam("name"); 152 Params.Add("name",temp);} 153 154 if (Params["emp_login"].Length>0) { 155 HasParam = true; 156 sWhere +="e.[emp_login] like '%" + Params["emp_login"].Replace( "'", "''") + "%'"; 157 } 158 if (Params["manmonth"].Length>0) { 159 if (sWhere.Length >0) sWhere +=" and "; 160 HasParam = true; 161 sWhere +="e.[manmonth]=" + Params["manmonth"]; 162 } 163 if (Params["name"].Length>0) { 164 if (sWhere.Length >0) sWhere +=" and "; 165 HasParam = true; 166 sWhere +="e.[name] like '%" + Params["name"].Replace( "'", "''") + "%'"; 167 } 168 169 170 if(HasParam) 171 sWhere = " WHERE (" + sWhere + ")"; 172 173 //定制Sql语句 174 175 emps_sSQL = "select [e].[emp_id] as e_emp_id, " + 176 "[e].[emp_level] as e_emp_level, " + 177 "[e].[emp_login] as e_emp_login, " + 178 "[e].[manmonth] as e_manmonth, " + 179 "[e].[name] as e_name " + 180 " from [emps] e "; 181 182 //装配出完整的Sql语句 183 emps_sSQL = emps_sSQL + sWhere + sOrder; 184 if (emps_sCountSQL.Length== 0) { 185 int iTmpI = emps_sSQL.ToLower().IndexOf("select "); 186 int iTmpJ = emps_sSQL.ToLower().LastIndexOf(" from ")-1; 187 emps_sCountSQL = emps_sSQL.Replace(emps_sSQL.Substring(iTmpI + 7, iTmpJ-6), " count(*) "); 188 iTmpI = emps_sCountSQL.ToLower().IndexOf(" order by"); 189 if (iTmpI > 1) emps_sCountSQL = emps_sCountSQL.Substring(0, iTmpI); 190 } 191 192 193 //联结数据库,读取数据 194 OleDbDataAdapter command = new OleDbDataAdapter(emps_sSQL, Utility.Connection); 195 DataSet ds = new DataSet(); 196 197 command.Fill(ds, (i_emps_curpage - 1) * emps_PAGENUM, emps_PAGENUM,"emps"); 198 OleDbCommand ccommand = new OleDbCommand(emps_sCountSQL, Utility.Connection); 199 int PageTemp=(int)ccommand.ExecuteScalar(); 200 emps_Pager.MaxPage=(PageTemp%emps_PAGENUM)>0?(int)(PageTemp/emps_PAGENUM)+1:(int)(PageTemp/emps_PAGENUM); 201 bool AllowScroller=emps_Pager.MaxPage==1?false:true; 202 203 DataView Source; 204 Source = new DataView(ds.Tables[0]); 205 206 if (ds.Tables[0].Rows.Count == 0){ 207 emps_no_records.Visible = true; 208 AllowScroller=false;} 209 else 210 {emps_no_records.Visible = false; 211 AllowScroller=AllowScroller&&true;} 212 213 emps_Pager.Visible=AllowScroller; 214 return Source; 215 216 } 217 218 //显示哪一页的数据 219 protected void emps_pager_navigate_completed(Object Src, int CurrPage) 220 { 221 i_emps_curpage=CurrPage; 222 emps_Bind(); 223 } 224 225 //绑定数据 226 void emps_Bind() 227 { 228 emps_Repeater.DataSource = emps_CreateDataSource(); 229 emps_Repeater.DataBind(); 230 } 231 232 //加入新职工记录过程 233 void emps_insert_Click(Object Src, EventArgs E) { 234 string sURL = emps_FormAction+"emp_login=" + Server.UrlEncode(Utility.GetParam("emp_login")) + "&manmonth=" + Server.UrlEncode(Utility.GetParam("manmonth")) + "&name=" + Server.UrlEncode(Utility.GetParam("name")) + "&"; 235 Response.Redirect(sURL); 236 } 237 //职工记录排序方式改变 238 protected void emps_SortChange(Object Src, EventArgs E) { 239 if(ViewState["SortColumn"]==null || ViewState["SortColumn"].ToString()!=((LinkButton)Src).CommandArgument){ 240 ViewState["SortColumn"]=((LinkButton)Src).CommandArgument; 241 ViewState["SortDir"]="ASC"; 242 }else{ 243 ViewState["SortDir"]=ViewState["SortDir"].ToString()=="ASC"?"DESC":"ASC"; 244 } 245 emps_Bind(); 246 } 247 248 249//查询显示过程 250void Search_Show() { 251 Utility.buildListBox(Search_manmonth.Items,Search_manmonth_lov,null,""); 252 253 254 string s; 255 256 s=Utility.GetParam("emp_login"); 257 Search_emp_login.Text = s; 258 259 s=Utility.GetParam("name"); 260 Search_name.Text = s; 261 262 s=Utility.GetParam("manmonth"); 263 264 try {Search_manmonth.SelectedIndex=Search_manmonth.Items.IndexOf(Search_manmonth.Items.FindByValue(s)); 265 }catch{} 266} 267 268//查询过程事件 269void Search_search_Click(Object Src, EventArgs E) { 270 string sURL = Search_FormAction + "emp_login="+Search_emp_login.Text+"&" 271 + "name="+Search_name.Text+"&" 272 + "manmonth="+Search_manmonth.SelectedItem.Value+"&" 273 ; 274 sURL += ""; 275 Response.Redirect(sURL); 276} 277 278