<%@ WebHandler Language="C#" Class="CheckPriKey" %> using System; using System.Collections.Generic; using System.Web; using System.Data; using System.IO; using eMIS.Data; using System.Data.Common; using System.Text; using System.Web.SessionState; using eMIS; using System.Text.RegularExpressions; public class CheckPriKey : IHttpHandler, IRequiresSessionState { public void ProcessRequest (HttpContext context) { string menuId = context.Request.QueryString["pid"].ToString(); string controlId = context.Request.QueryString["cid"].ToString(); string searchWord = context.Request.QueryString["sw"].ToString(); string pageType = context.Request.QueryString["pt"].ToString(); string condition = "";// context.Request.QueryString["c"]==null?"":context.Request.QueryString["c"].ToString(); string py = "1";// context.Request.QueryString["py"].ToString(); int pageIndex = int.Parse(context.Request.QueryString["pi"].ToString()); bool b = false; if (searchWord != "" && py=="1") { if (searchWord.IndexOf("'") != -1) { context.Response.Write("无"); context.Response.End(); } string f = searchWord.Substring(0, 1); System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[A-Za-z]+$"); b = reg1.IsMatch(f); } DataManager dm = new DataManager(); InstanceManager inst = new InstanceManager(context, menuId); ProgramManager program = inst.Program; DataTable elements = null; if (pageType=="0") elements = program.EditElements; else elements = program.ListElements; int i, l; ValueTagManager tag = new ValueTagManager(inst); ControlManager control = new ControlManager(inst); l = elements.Rows.Count; DataRow row=null; for (i = 0; i < l; i++) { control.Init(row, elements.Rows[i]); if (control.ControlID == controlId) { break; } } StringBuilder sb = new StringBuilder(); //string defaultCondition = control.GetDataFieldConditionSql; //inst.DefaultCondition; //if (defaultCondition == "") string defaultCondition = "1=1"; //if (pageType == "0") // defaultCondition = "1=1"; bool existUpdate = (control.UpdateField !=""); string sql; string PrimaryKey,sqlSelect; string tableName = StringHelper.GetLeftString(control.GetDataField); string fieldName = control.GetDataField; string search_sql = ""; if (!existUpdate) { PrimaryKey = fieldName; sqlSelect = "distinct " + PrimaryKey; sql = "select distinct " + fieldName + " from " + tableName + " where " + defaultCondition; } else { PrimaryKey = control.UpdateField; sqlSelect = fieldName + "," + PrimaryKey; sql = "select distinct " + fieldName + "," + control.UpdateField + " from " + tableName + " where " + defaultCondition; } if(b && py=="1") { string searchmode = control.GetParamValue("searchmode", "1"); string _sp, _qp; if (tableName.ToLower().Contains("com_yhb")) { searchmode = "3"; _sp = "SP"; _qp = "QP"; } else { _sp = fieldName+"_SP"; _qp = fieldName+"_QP"; } if (searchmode == "1") { defaultCondition += " and dbo.GetAllPY(" + fieldName + ") like '%" + searchWord + "%'"; search_sql = "dbo.GetAllPY(" + fieldName + ") like '%" + searchWord + "%'"; } else if (searchmode == "2") { defaultCondition += " and (" + _sp + " like '%" + searchWord + "%' or " + _qp + " like '%" + searchWord + "%')"; search_sql = "(" + _sp + " like '%" + searchWord + "%' or " + _qp + " like '%" + searchWord + "%')"; } else if (searchmode == "3") { defaultCondition += " and (" + _sp + " like '" + searchWord + "%' or " + _qp + " like '" + searchWord + "%')"; search_sql = "(" + _sp + " like '" + searchWord + "%' or " + _qp + " like '" + searchWord + "%')"; } //sql += " and " + control.GetDataField + "_sp like '%" + searchWord + "%'"; } else { if (searchWord != "") { defaultCondition += " and " + fieldName + " like '%" + searchWord + "%'"; search_sql = fieldName + " like '%" + searchWord + "%'"; } else { search_sql = "1"; } } //if (condition != "") // sql += " and " + condition; DataTable dt; sql = control.GetItemsDataSql(); if (sql == null) { if (condition != "") defaultCondition = defaultCondition + " and " + condition; sql = " order by " + fieldName; dt = inst.BusinessDbOperator.ExecuteProcedureTable("pagers2", pageIndex, 10, PrimaryKey, sqlSelect, StringHelper.GetLeftString(fieldName), defaultCondition, sql); } else { inst.Tag.AddValue("search", search_sql); sql = inst.Tag.ReplaceExpression(sql,""); dt = inst.BusinessDbOperator.ExecuteProcedureTable("pagers3", pageIndex, 10, sql); } //DbDataReader reader = inst.BusinessDbOperator.ExecuteReader(sql); //i = 1; l = dt.Rows.Count; sb.Append(""); int total = l/10 + ((l % 10==0)?0:1); for(i=0;i< l;i++) { sb.Append(""); } if (l == 0) { sb.Append(""); } sb.Append("
" + dt.Rows[i][0].ToString() + "
 
"+(l>=10?"":"")+""); context.Response.Write(sb.ToString()); } public bool IsReusable { get { return false; } } }