69 lines
2.2 KiB
C#
69 lines
2.2 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
using System.Collections.Generic;
|
|
using System.Web;
|
|
using System.Text;
|
|
using WebLib;
|
|
|
|
namespace Education.Utility
|
|
{
|
|
public partial class GetLookUp : FormBase
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
DbCommand cmd = DAC.NewCommand();
|
|
DbDataAdapter da = DAC.NewDataAdapter();
|
|
cmd.Connection = conn;
|
|
da.SelectCommand = cmd;
|
|
|
|
// 從 Request 中取出參數
|
|
string lookupConfigName = Server.UrlDecode(DAC.GetString(Request["NAME"]));
|
|
string whereKey = DAC.GetString(Request["WHERE_KEY"]);
|
|
string langId = DAC.GetString(Request["LANGID"]);
|
|
string addWhere = DAC.GetString(Request["ADD_WHERE"]);
|
|
|
|
// 從設定檔中取得SQL
|
|
LookupList pickup = LookupList.GetInstance();
|
|
pickup.LookupConfigName = lookupConfigName;
|
|
string sql = pickup.GetLookupSQL();
|
|
string[] keyFields = pickup.GetKeyFields();
|
|
|
|
// 將傳入的KEY代入SQL
|
|
foreach (string keyField in keyFields)
|
|
{
|
|
if (addWhere.Length == 0)
|
|
cmd.CommandText = String.Format(sql, keyField, "");
|
|
else
|
|
cmd.CommandText = String.Format(sql, keyField, " AND " + addWhere);
|
|
cmd.Parameters.Clear();
|
|
cmd.Parameters.Add(DAC.NewParameter("VALUE", whereKey + "%"));
|
|
|
|
// 取回資料
|
|
DataTable table = new DataTable();
|
|
//conn.Open();
|
|
da.Fill(table);
|
|
//conn.Close();
|
|
|
|
// 若無資料,則找尋下一個 KEY
|
|
if (table.Rows.Count == 0)
|
|
{
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
// 輸出儲存下拉資料物件的 JSON 表示法字串
|
|
Response.Write(pickup.GetLookupJSON(table, langId));
|
|
Response.End();
|
|
return;
|
|
}
|
|
}
|
|
Response.End();
|
|
}
|
|
|
|
protected override bool IsSetMasterPage()
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
} |