<div id="setBtn_dd" class="easyui-window" data-options="iconCls:'icon-save',buttons:'#setBtn_dlg-buttons',closed:true,modal:true,380,height:380">
<form id="setBtn_ff" method="post" autocomplete="off" style="margin-top: 30px">
<table class="tb1">
<tr hidden="hidden">
<td class="td1">MenuID:</td>
<td class="td2">
<input id="setBtn_MenuID" class="easyui-validatebox textbox" type="text" name="menuId" style=" 200px; height: 30px;" /></td>
</tr>
<tr>
<td class="td1">菜单名称:</td>
<td class="td2">
<input id="setBtn_MenuName" class="easyui-validatebox textbox" type="text" name="menuName" data-options="required:'true',validType:'maxLength[100]'" style=" 200px; height: 30px;" disabled="disabled" /></td>
</tr>
<tr>
<td class="td1">按钮:</td>
<td class="td2">
<select id="combotree_setBtn" class="easyui-combotree" name="combotree_setBtn" data-options="validType:'maxLength[100]',multiple:true" style=" 200px; height: 30px;" /></td>
</tr>
</table>
<div id="setBtn_dlg-buttons">
<a id="setBtn_ddok" href="javascript:void(0)" onclick="javascript:saveMenuBtn();" class="easyui-linkbutton" data-options="iconCls:'icon icon-ok'">保存</a>
<a id="setBtn_ddcancel" href="javascript:void(0)" onclick="javascript:$('#setBtn_dd').window('close');" class="easyui-linkbutton" data-options="iconCls:'icon icon-cancel'">取消</a>
</div>
</form>
</div>
$("#z-toolbar").on("click", "#btnSetMenuButton", function () {
var row = $('#tbMenu').datagrid('getSelected');
if (row == null) {
$.messager.alert('警告', '请选择至少一行数据', 'warning');
return;
}
$.ajax({
type: 'post',
dataType: "json",
url: '/Handlers/MenuHandler.ashx?action=IsExistSon&menuId=' + encodeURI(row.menuId), //判断是否有下级
success: function (data) {
if (data.Success) {
$('#setBtn_dd').dialog({
closed: false,
title: '分配按钮',
onBeforeOpen: function () {
//加载时选中已经分配好的按钮
$.ajax({
type: 'post',
dataType: "json",
url: '/Handlers/MenuButtonHandler.ashx?action=LoadMenuButton&menuId=' + encodeURI(row.menuId),
success: function (mb_data) {
if (mb_data.Success) {
$('#combotree_setBtn').combotree('setValues', mb_data.Message);
}
}
})
}
});
//向combotree绑定值
$('#combotree_setBtn').combotree(
{
url: "/Handlers/ButtonHandler.ashx?action=GetButtonTree"
});
$('#setBtn_ff').form('load', row);
} else {
$.messager.show({
title: '错误',
msg: data.Message
});
}
}
})
})
private void GetButtonTree(HttpContext context)
{
string where = "1=1";
List<Model_tb_button> btnList = new BLL_Button().GetButtonTable(where);
StringBuilder sbStr = new StringBuilder();
sbStr.Append("[{"id":0, "text": "全选", "children":[");
if (btnList != null && btnList.Count > 0)
{
foreach (var item in btnList)
{
sbStr.Append("{"id":" + item.btnId + ", "text":"" + item.btnName + "", "iconCls":"" + item.btnIcon + ""},");
}
sbStr.Remove(sbStr.Length - 1, 1);
}
sbStr.Append("]}]");
Response.WriteJson(context, sbStr);
}
BLL
public List<Model_tb_button> GetButtonTable(string where)
{
DataSet ds = this.dal.GetButtonTable(where);
return ModelHandler<Model_tb_button>.FillModel(ds.Tables[0]);
}
DLL
public DataSet GetButtonTable(string where)
{
StringBuilder sbSql = new StringBuilder();
sbSql.Append("SELECT btnId AS id, btnName AS text, btnIcon AS iconCls, * FROM dbo.tb_button ");
if (!string.IsNullOrEmpty(where))
{
sbSql.Append(" WHERE " + where);
}
return DbHelperSQL.Query(sbSql.ToString());
}
Model
[Serializable]
public partial class Model_tb_button
{
public Model_tb_button()
{ }
#region Model
private int _btnid;
private string _btnname;
private string _btncode;
private string _btnicon;
private DateTime? _createtime;
private string _createby;
private DateTime? _updatetime;
private string _updateby;
/// <summary>
///
/// </summary>
public int btnId
{
set { _btnid = value; }
get { return _btnid; }
}
/// <summary>
///
/// </summary>
public string btnName
{
set { _btnname = value; }
get { return _btnname; }
}
/// <summary>
///
/// </summary>
public string btnCode
{
set { _btncode = value; }
get { return _btncode; }
}
/// <summary>
///
/// </summary>
public string btnIcon
{
set { _btnicon = value; }
get { return _btnicon; }
}
/// <summary>
///
/// </summary>
public DateTime? createTime
{
set { _createtime = value; }
get { return _createtime; }
}
/// <summary>
///
/// </summary>
public string createBy
{
set { _createby = value; }
get { return _createby; }
}
/// <summary>
///
/// </summary>
public DateTime? updateTime
{
set { _updatetime = value; }
get { return _updatetime; }
}
/// <summary>
///
/// </summary>
public string updateBy
{
set { _updateby = value; }
get { return _updateby; }
}
#endregion Model
}