Bruce Xiao 的程序生活

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

void InitMenu(){
   //初始化菜單
   MenuItem menuFirst;
   DataSet dsPermit;
   UserInfo ui ;

   DataSet dsF=func.GetDataTable("select * from cqsSystemTree where F_Parent='000' and isValid=1 order by showSort");
   foreach (DataRow myrow in dsF.Tables[0].Rows){
    //如果沒有主菜單下的任何一個子菜單權限則不顯示此菜單
    if (Session["uID"] != null){
     ui = new UserInfo(Request.Cookies["LoginID"].Value);
     if (ui.Role == "C"){
      dsPermit = func.GetDataTable("select * from cqsUserPermit where uid="+ Session["uID"] +" and F_SysCode like '"+ myrow["F_SysCode"].ToString() +"%' ");
      if (dsPermit.Tables[0].Rows.Count ==0){
       continue;
      }
     }
    }
    menuFirst=new MenuItem();
    menuFirst.Text=myrow["F_SysNameEN"].ToString();

    DataSet dsLen=func.GetDataTable("select isnull(max(len(f_sysnamech)),0) as ls from cqsSystemTree where f_parent='"+myrow["F_SysCode"].ToString()+"' and isValid=1");
    int len=Convert.ToInt32(dsLen.Tables[0].Rows[0]["ls"].ToString());

    //如果沒有主菜單下的任何一個子菜單權限則不顯示此菜單,只針對 C 用戶
    if (Session["uID"] != null){
     ui = new UserInfo(Request.Cookies["LoginID"].Value);
     MenuItem menuSecond;
     MenuItem menuThird;
     DataSet dsS=func.GetDataTable("select * from cqsSystemTree where F_Parent='"+ myrow["F_SysCode"].ToString() +"' and isValid=1 order by showSort");
     foreach (DataRow myrow2 in dsS.Tables[0].Rows){
      menuSecond=new MenuItem();
      menuSecond.Text=myrow2["F_SysNameEN"].ToString();

      //如果沒有主菜單下的任何一個子菜單權限則不顯示此菜單,只針對 C 用戶
      if (ui.Role == "C") {
       dsPermit = func.GetDataTable("select * from cqsUserPermit where uid="+ Session["uID"] +" and F_SysCode like '"+ myrow2["F_SysCode"].ToString() +"%' ");
       if (dsPermit.Tables[0].Rows.Count ==0){
        continue;
       }
      }

      DataSet dsT=func.GetDataTable("select * from cqsSystemTree where F_Parent='"+ myrow2["F_SysCode"].ToString() +"' and isValid=1 order by showSort");
      if (dsT.Tables[0].Rows.Count>0){
       menuSecond.Text +="&nbsp;&nbsp;" + func.ReplicateChar("&nbsp;",len-menuSecond.Text.Length) + "<img src ='../Images/arrow1.gif' align ='right' >";
       menuSecond.Style.Add("backgroup","");
       foreach (DataRow myrow3 in dsT.Tables[0].Rows) {
        //如果沒有主菜單下的任何一個子菜單權限則不顯示此菜單,只針對 C 用戶
        if (ui.Role == "C") {
         dsPermit = func.GetDataTable("select * from cqsUserPermit where uid="+ Session["uID"] +" and F_SysCode like '"+ myrow3["F_SysCode"].ToString() +"%' ");
         if (dsPermit.Tables[0].Rows.Count ==0){
          continue;
         }
        }

        menuThird=new MenuItem();
        menuThird.Text=myrow3["F_SysNameEN"].ToString();
        if (myrow3["F_URL"].ToString()=="") {
         menuThird.NavigateUrl ="../ErrorMsg.aspx?MsgID=M0002"; 
        }
        else {
         menuThird.NavigateUrl=myrow3["F_URL"].ToString() + "&F_SysCode="+ myrow3["f_sysCode"].ToString();
        }
        menuThird.Target="right";
        menuSecond.Items.Add(menuThird);
       }
      } else {
       if (myrow2["F_Url"].ToString()=="") {
        menuSecond.NavigateUrl ="../ErrorMsg.aspx?MsgID=M0002";
       }
       else {
        menuSecond.NavigateUrl=myrow2["F_Url"].ToString() + "&F_SysCode="+ myrow2["f_sysCode"].ToString();
       }
      
       menuSecond.Target="right";
      }
      menuFirst.Items.Add(menuSecond);
     }
    }
    Menu1.Items.Add(menuFirst);
   }
  }

posted on 2006-12-26 18:30  Bruce Xiao  阅读(260)  评论(0编辑  收藏  举报