公共下拉框调用方法
<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;
}