温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:某市人口普查系统源码
当前文件路径:RenKouPuCha/Code/SearchSat.aspx.cs

1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.Data.SqlClient; 12
13
public partial class Code_Search : System.Web.UI.Page 14
{ 15
private DataSet _ds = new DataSet(); 16
protected CCUtility _utility = new CCUtility(); 17
private string _target = ""; //指标 18
private string _area = ""; //乡镇 19
private DataTable generalTb = new DataTable("GeneralTable"); 20
protected void Page_Load(object sender, EventArgs e) 21
{ 22
if (!Page.IsPostBack) 23
{ 24
if (Session["UserID"] == null || Session["RoleID"] == null) 25
{ 26
Response.Redirect("Login.aspx"); 27
} 28
else 29
{ 30
BindData(); 31
} 32
} 33
} 34
public override void VerifyRenderingInServerForm(Control control) 35
{ 36
//base.VerifyRenderingInServerForm(control); 37
} 38
39
//绑定数据源 40
private void BindData() 41
{ 42
CreateData(); 43
_ds.Tables.Add(generalTb); 44
dg.DataSource = _ds.Tables["GeneralTable"].DefaultView; 45
dg.DataBind(); 46
Session.Add("GeneralTable", generalTb); 47
} 48
protected void Menu1_MenuItemClick(object sender, MenuEventArgs e) 49
{ 50
this.MultiView1.ActiveViewIndex= int.Parse(e.Item.Value); 51
} 52
53
统计部分 170
171
# region 查询部分 172
173
//查询模块 174
private string _modeS = ""; 175
private string _nameS = ""; 176
private string _ageMin=""; 177
private string _ageMax=""; 178
private string _professionS = ""; 179
private string _edgLevelS = ""; 180
private string _inMin="", _inMax=""; 181
private string _marriageS = ""; 182
private string _idFieldS = ""; 183
protected void searchButton_Click(object sender, EventArgs e) 184
{ 185
_modeS = modeDropD.SelectedValue; 186
_nameS = nameTextB.Text; 187
_ageMin = minageTextB.Text; 188
_ageMax = maxTextBox.Text; 189
_professionS = professionTextB.Text; 190
_edgLevelS = edgLevelTextB.Text; 191
_inMin = incomMinextB.Text; 192
_inMax = incomMaxTextB.Text; 193
_marriageS = marriageTextB.Text; 194
_idFieldS = idFieldTextB.Text; 195
string sql; 196
if (_modeS == "精确查询") 197
sql=ExactSearch(); 198
else 199
sql=BlurSearch(); 200
if (sql == "") 201
Response.Write("<script>alert('请输入关键字!')</script>"); 202
else 203
{ 204
_utility.DBOpen(); 205
SqlCommand cmd = new SqlCommand(sql, _utility.Connection); 206
SqlDataAdapter da = new SqlDataAdapter(); 207
da.SelectCommand = cmd; 208
da.Fill(_ds, "SearchResult"); 209
Session.Add("Set", _ds); 210
Response.Redirect("SrchResult.aspx"); 211
} 212
} 213
214
//精确查询 215
private string ExactSearch() 216
{ 217
string sql; 218
if (_nameS == "" && _ageMin == "" && _professionS == "" &&_edgLevelS == "" && _inMin == "" && _marriageS == "" &&_idFieldS == "" && _edgLevelS == "") 219
{ 220
sql =""; 221
} 222
else 223
{ 224
sql = "Select idField as 身份证号码,nameField as 姓名,age as 年龄,profession as 职业,sex as 性别,edgLevel as 最高学历,"; 225
sql+="nation as 国家,polity as 政治面貌,marriage as 婚否,incom as 年收入 from tRkry where "; 226
if (_nameS != "") 227
{ 228
sql+= "namefield='" + _nameS+"'" + " and "; 229
} 230
if (_ageMin != "") 231
{ 232
sql += "age=" + Convert.ToInt32(_ageMin) + " and "; 233
} 234
if (_professionS != "") 235
{ 236
sql += "profession='" + _professionS + "'" + " and "; 237
} 238
if (_edgLevelS != "") 239
{ 240
sql += "edgLevel='" + _edgLevelS + "'" + " and "; 241
} 242
if (_inMin != "") 243
{ 244
sql += "incom=" + Convert.ToInt32(_inMin) + " and "; 245
} 246
if (_marriageS != "") 247
{ 248
sql += "marriage='" + _marriageS + "'" + " and "; 249
} 250
if(_idFieldS!="") 251
{ 252
sql += "idField='" + _idFieldS + "'" + " and "; 253
} 254
sql=sql.Remove(sql.LastIndexOf(" and ")); 255
} 256
return sql; 257
} 258
//模糊查询 259
private string BlurSearch() 260
{ 261
string sql; 262
if (_nameS == "" && _ageMin == "" && _professionS == "" && _edgLevelS == "" && _inMin == "" && _marriageS == "" && _idFieldS == "" && _edgLevelS == "") 263
{ 264
sql = "Select idField as 身份证号码,nameField as 姓名,age as 年龄,profession as 职业,sex as 性别,edgLevel as 最高学历,"; 265
sql += "





}