公共下拉框調用方法
<script>
var ndata = { id: "新聞要聞類", type: "gettype" }
getcomboboxdata("ashprama/getjsondata_for_combobox.ashx", ndata, "#cc", "TYPENAME", "TYPEVALUE", "", "000000");
</script>
///下拉框公共組件
//urlstring爲獲取數據地址
//nadata格式如: ndata = { id: "新聞要聞類", type: "gettype" }
//comboboxid爲comboboxid
//comboboxvalue爲值
//comboboxtext顯示值
//comboboxgroup爲分組值
//defaultvalue爲默認值,如爲空則默認選擇中第一個
function getcomboboxdata(urlstring, ndata, comboboxid, comboboxvalue, comboboxtext, comboboxgroup, defaultvalue) {
$.ajax({
type: "POST",
url:urlstring,
data: ndata,
contenttype: "json",
success: function (msg) {
LoadData(msg, comboboxid, comboboxvalue, comboboxtext, comboboxgroup, defaultvalue)
}
})
}
function LoadData(data,comboboxid,comboboxvalue,comboboxtext,comboboxgroup,defaultvalue) {
$(comboboxid).combobox({
data: eval(data),
valueField: comboboxvalue,
textField: comboboxtext,
groupField: comboboxgroup,
onLoadSuccess: function () {//設置默認值
var val = $(this).combobox("getData");
var setval = defaultvalue;
if (setval != "") { setval = defaultvalue }
else { setval = val[0].TYPENAME }
$(this).combobox("select", setval);
}
});
}
public void ProcessRequest(HttpContext context)
{
string id = context.Request["id"];
string gettype = context.Request["type"];
DataTable dt = new DataTable();
string strJson = "";
switch (gettype)
{
case "getdepat"://取部門
{
dt = comm_data.getcommdata(1, 0, "qg_emplyee", "DISTINCT t.depatment", "", "");
break;
}
case "getemplyee"://取人員
{
dt = comm_data.getcommdata(1, 0, "qg_emplyee", " t.user_name,t.depatment", "t.depatment='" + id + "'", "");
break;
}
case "getmenu"://取菜單
{
if (id == "leaf")//如果爲取菜單的葉子
{
OracleParameter[] pan = {
new OracleParameter("v_cur", OracleDbType.RefCursor)
};
pan[0].Direction = ParameterDirection.Output;
dt = dataconnection.ExecuteDataTableByProc("QG_GETMENULEAF", pan);
}
if (id == "all")//不爲葉子,即找出用戶菜單
{
string currentuser = context.Session["UserID"].ToString();
string usermenuid = getusermenuid(currentuser);
if (usermenuid != "nousername") //即有權限
{
usermenuid = getmenuparentid() + usermenuid;
usermenuid = usermenuid.Replace(",", "','");
usermenuid = "menuid in ('" + usermenuid + "')";
dt = comm_data.getcommdata(1, 0, "qg_menu", "t.menunum,t.menuname,t.menuparent,t.menupre,t.menuid", usermenuid, "t.menunum desc");
}
else
{
dt = null;
}
}
break;
}
case "gettype"://即取字典表
{
string wherestring = "";
if (id != "" || id != null)
wherestring = "t.type_type='" + id + "'";
dt = comm_data.getcommdata(1, 0, "qg_type", "t.*",wherestring , "");
break;
}
}
if (dt != null)
{ strJson = Newtonsoft.Json.JsonConvert.SerializeObject(dt); }
context.Response.Write(strJson);
}
private string getmenuparentid()
{
string yy = "";
DataTable dt = new DataTable();
try
{
OracleParameter[] pan = {
new OracleParameter("v_cur", OracleDbType.RefCursor)
};
pan[0].Direction = ParameterDirection.Output;
dt = dataconnection.ExecuteDataTableByProc("QG_GETUSERMENU", pan);
if (dt.Rows.Count != 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
yy = yy + dt.Rows[i]["menuid"].ToString() + ",";
}
}
}
catch (Exception err)
{
yy = err.ToString();
}
return yy;
}
private string getusermenuid(string userid)
{
string yy = "";
DataTable dt = new DataTable();
try
{
dt = comm_data.gettablebypruce("qg_sysuser", " username='" + userid + "'", "");
if (dt.Rows.Count != 0)
{
yy = dt.Rows[0]["job"].ToString();
}
else
{
yy = "nousername";
}
}
catch (Exception err)
{
yy = err.ToString();
}
return yy;
}