一次蛋碎的优化

前台easyui 的菜单脚本

    <script type="text/javascript">

        var _menus = null;

        $(function () {

            $.ajax({

                url: 'HttpHandler/Index_Handler.ashx?Method=GetSysTree', //&RoleId=' + GetCookie("RoleInfo").substring(7, 8),

                type: "POST",

                dataType: "text",

                success: function (json) {

                    _menus = json;

                    _menus = eval('(' + _menus + ')');

                    var firstMenuName = "basic";



                    //在页面上去除手机管理功能菜单

                    var b = [];

                    for (var i = 0; i < _menus.basic.length; i++) {

                        if (_menus.basic[i].menuname != "手机管理") {

                            b.push(_menus.basic[i]);

                        }

                    }

                    _menus.basic = b;



                    addNav(_menus[firstMenuName]); //首次加载basic 左侧菜单

                    InitLeftMenu();

                }

            });

            setInterval(RefSession, 5000);

        });

 后台Index_Handler.ashx

 

         //<summary>

         //根据权限获得树节点

         //</summary>

        public void GetSysTree()

        {

            JC_USEREntity _user = (JC_USEREntity)Session["jztuser"];

            string rst = jcuser.GetFunctionItemByPid(_user.RoleId.ToString()).ToString();

            Response.Write("{" + rst + "}");

        }

后台
数据访问层

/// <summary>

        /// 根据父ID获取其下所有功能模块信息

        /// </summary>

        /// <param name="pid"></param>

        /// <returns></returns>

        public StringBuilder GetFunctionItemByPid(string _roleid)

        {

            OracleHelper helper = new OracleHelper();

            StringBuilder jsonData = new StringBuilder();

            try

            {

                #region 丢弃的代码

                string _sql = "";

                _sql = "select  distinct r.RoleId,f.funid,f.funname,f.paraidid,f.funurl,f.sid  from xt_role r,xt_rolefun rf, xt_fun f  where r.roleid=rf.roleid and rf.funid=f.funid and r.roleid='" + _roleid + "' and f.paraidid =0  and rf.companycode='" + useEntity.CompanyCode + "' and f.companycode='SHWLGS' order by f.SID";

                DataSet ds1 = helper.ExecuteDataSet(_sql);

                jsonData.Append("basic: [");

                #region 1

                if (ds1.Tables[0].Rows.Count > 0)

                {

                    for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)

                    {

                        jsonData.Append("{ \"menuid\": \"" + ds1.Tables[0].Rows[i]["paraidid"] + "\",\"icon\": \"icon-sys\", \"menuname\": \"" + ds1.Tables[0].Rows[i]["funname"] + "\"");

                        #region 2

                        _sql = "select  distinct r.RoleId,f.funid,f.funname,f.paraidid,f.funurl,f.sid  from  jc_user u,xt_role r,xt_rolefun rf, xt_fun f  where r.roleid=rf.roleid and rf.funid=f.funid  and  r.roleid='" + _roleid + "' and f.paraidid='" + ds1.Tables[0].Rows[i]["funid"] + "'  and r.companycode='" + useEntity.CompanyCode + "'   and rf.companycode='" + useEntity.CompanyCode + "' and f.companycode='SHWLGS' order by f.sid";

                        DataSet ds2 = helper.ExecuteDataSet(_sql);

                        if (ds2.Tables[0].Rows.Count > 0)

                        {

                            jsonData.Append(",");

                            jsonData.Append("\"menus\":[");

                            for (int j = 0; j < ds2.Tables[0].Rows.Count; j++)

                            {

                                jsonData.Append("{\"menuid\":\"" + ds2.Tables[0].Rows[j]["funid"] + "\", \"menuname\": \"" + ds2.Tables[0].Rows[j]["funname"] + "\", \"icon\": \"icon-nav\", ");

                                #region 3

                                _sql = "select  distinct r.RoleId,f.funid,f.funname,f.paraidid,f.funurl,f.sid  from xt_role r,xt_rolefun rf, xt_fun f  where r.roleid=rf.roleid and rf.funid=f.funid  and   r.roleid='" + _roleid + "'  and f.paraidid='" + ds2.Tables[0].Rows[j]["funid"] + "'  and r.companycode='" + useEntity.CompanyCode + "'   and rf.companycode='" + useEntity.CompanyCode + "' and f.companycode='SHWLGS'  order by f.sid";

                                DataSet ds3 = helper.ExecuteDataSet(_sql);

                                if (ds3.Tables[0].Rows.Count > 0)

                                {

                                    jsonData.Append("\"menus\":[");

                                    for (int k = 0; k < ds3.Tables[0].Rows.Count; k++)

                                    {

                                        jsonData.Append("{\"menuid\":\"" + ds3.Tables[0].Rows[k]["funid"] + "\", \"menuname\": \"" + ds3.Tables[0].Rows[k]["funname"] + "\", \"icon\": \"icon-nav\", \"url\": \"" + ds3.Tables[0].Rows[k]["funurl"] + "\"},");

                                    }

                                    jsonData.Remove(jsonData.Length - 1, 1);

                                    jsonData.Append(" ]");

                                }

                                #endregion

                                jsonData.Append("},");

                            }

                            jsonData.Remove(jsonData.Length - 1, 1);

                            jsonData.Append("]");

                        }

                        #endregion

                        jsonData.Append("},");

                    }

                    jsonData.Remove(jsonData.Length - 1, 1);

                }

                #endregion

                jsonData.Append("]"); 

                #endregion





                return jsonData;

            }

            catch (Exception ex)

            {

                throw ex;

            }

            finally

            {

                helper.CloseCon();

            }

        }

 

你可能感兴趣的:(优化)