导航

HTML ajax控件 目录树

Posted on 2009-08-07 11:53  pcajax  阅读(1513)  评论(0编辑  收藏  举报

  /// <summary>
        /// 目录树
        /// </summary>
        /// <param name="categoryid">目录ID,传0时,删除目录</param>
        /// <param name="questionid">问题ID,传0时,删除问题</param>
        /// <param name="gameID">游戏ID</param>
        /// <param name="ishavequestion">是不有问题存在</param>
        /// <param name="issuance">是否发布</param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod]
        public static string MenuAndQuestionTree(int categoryid,int questionid,int gameID,int ishavequestion,int issuance)
        {
            //当category==0时,不删除
            if (categoryid != 0)
            {
                BllAccess.GetKbsCategory.DeleteCategory(categoryid);
            }

            //当questionid==0时,不删除
            if (questionid != 0)
            {
                BllAccess.GetKbsQuestion.DeleteQuestion(questionid);
            }
            DataTable dtTable = null;
            DataTable dtTable1 = null;
            DataTable dtTable2 = null;
            DataTable dtQuestion = null;
            if (-1 == issuance)//知识库,所有的
            {
                 dtTable = BllAccess.GetKbsCategory.GetCategorys(gameID, ENUM_KBS_CategoryIssuance.All);//目录中所有项,
                 dtTable1 = BllAccess.GetKbsCategory.GetCategorys(gameID, 1, ENUM_KBS_CategoryIssuance.All);//一级目录
                 dtTable2 = BllAccess.GetKbsCategory.GetCategorys(gameID, 2, ENUM_KBS_CategoryIssuance.All);//二级目录
                 dtQuestion = BllAccess.GetKbsQuestion.GetQuestions(0, ENUM_KBS_CategoryIssuance.All);//所有问题
            }
            else //系统自助后台,所有没有发布的
            {
                 dtTable = BllAccess.GetKbsCategory.GetCategorys(gameID, ENUM_KBS_CategoryIssuance.Yes);
                 dtTable1 = BllAccess.GetKbsCategory.GetCategorys(gameID, 1, ENUM_KBS_CategoryIssuance.Yes);
                 dtTable2 = BllAccess.GetKbsCategory.GetCategorys(gameID, 2, ENUM_KBS_CategoryIssuance.Yes);
                 dtQuestion = BllAccess.GetKbsQuestion.GetQuestions(0, ENUM_KBS_CategoryIssuance.All);
            }


            if (dtTable != null)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<div style=\"border:solid 1px red;width:300px;float:left;\">");
                sb.Append("<div style=\"text-align:left;margin-left:0px;\"><img src=\"/Images/folder1.gif\" alt=\"menubutton\"><a href=\"#\" onclick=\"$('#bigdiv').toggle();\">" + BllAccess.ConfigService.GetGame(gameID).Game_Name + "</a></div>");
                sb.Append("<div id=\"bigdiv\">");
               
                if (dtTable != null)
                {
                    for (int intIndex = 0; intIndex < dtTable1.Rows.Count; intIndex++)
                    {
                        string strText = dtTable1.Rows[intIndex][KBS_Category.n_.CategoryName].ToString();
                        string strValue = dtTable1.Rows[intIndex][KBS_Category.n_.CategoryID].ToString();
                        sb.Append("<div style=\"text-align:left;margin-left:10px;\"><img src=\"/Images/folder1.gif\" alt=\"menubutton\"><a href=\"#\" onclick=\"GetMenuTreeID(1" + strValue + ",menu1div" + intIndex + ");\">" + strText + "</a></div>");
                        int tree1CategoryID = int.Parse(dtTable1.Rows[intIndex]["CategoryID"].ToString());

                       
                        if (dtTable2 != null)
                        {
                            sb.Append("<div id=\"menu1div"+intIndex+"\">");
                            for (int intIndex2 = 0; intIndex2 < dtTable2.Rows.Count; intIndex2++)
                            {
                                if (tree1CategoryID == int.Parse(dtTable2.Rows[intIndex2]["ParentCategoryID"].ToString()))
                                {
                                    string strText2 = dtTable2.Rows[intIndex2][KBS_Category.n_.CategoryName].ToString();
                                    string strValue2 = dtTable2.Rows[intIndex2][KBS_Category.n_.CategoryID].ToString();

                                    //在下面替换
                                    string strSecondMenuTemp = string.Empty;
                                    string strQuestion = string.Empty;
                                    strSecondMenuTemp = "<div style=\"text-align:left;margin-left:20px;\"><img src=\"/Images/folder1.gif\" alt=\"menubutton\"><a href=\"#\" onclick=\"GetMenuTreeID(2" + strValue2 + ",0);\">" + strText2 + "</a></div>";

                                    if (1 == ishavequestion && dtQuestion!=null)//有问题,且dtQuestion不为null时
                                    {
                                        for (int intQuestion = 0; intQuestion < dtQuestion.Rows.Count; intQuestion++)
                                        {
                                            int intLeve2CategoryID = int.Parse(dtTable2.Rows[intIndex2][KBS_Category .n_ .CategoryID].ToString());

                                           
                                            if (intLeve2CategoryID == int.Parse(dtQuestion.Rows[intQuestion][KBS_Question.n_.CategoryID].ToString()))
                                            {
                                                //有问题,且dtQuestion不为null时,
                                                strSecondMenuTemp = "<div style=\"text-align:left;margin-left:20px;\"><img src=\"/Images/folder1.gif\" alt=\"menubutton\"><a href=\"#\" onclick=\"GetMenuTreeID(2" + strValue2 + ",divQuestion" + intQuestion + ");\">" + strText2 + "</a></div>";

                                                strQuestion+="<div id=\"divQuestion" + intQuestion + "\" >";
                                                string strTextQuestion = dtQuestion.Rows[intQuestion][KBS_Question.n_.Question].ToString();
                                                string strValueQuestion = dtQuestion.Rows[intQuestion][KBS_Question.n_.QuestionID].ToString();
                                                strQuestion += "<div style=\"text-align:left;margin-left:30px;\"><img src=\"/Images/folder2.gif\" alt=\"menubutton\"><a href=\"#\" onclick=\"GetMenuTreeID(3" + strValueQuestion + ",0);\">" + strTextQuestion + "</a></div>";
                                                strQuestion+="</div>";
                                            }
                                        }
                                    }
                                  
                                    sb.Append(strSecondMenuTemp);
                                    sb.Append(strQuestion);
                                }
                            }
                            sb.Append("</div>");
                        }

                    }
                }
                sb.Append("</div>");
                sb.Append("</div>");
                return sb.ToString();
            }


            return "";

        }