用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - c#代码库

树形数据处理和输出

2015-06-17 作者: 莫名其妙举报

[c#]代码库

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EVTBT.DAL;
using EVTBT.Core;
using System.Data;
using System.Text;


namespace Web
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        static int country = -1;
        static int product = -1;
        public string productName;
        static string result;
        static StringBuilder divresult = new StringBuilder();
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                divresult.Clear();
                country = Convert.ToInt16(Request.QueryString["country"]);
                product = Convert.ToInt16(Request.QueryString["product"]);


            }
            catch
            {
            }
            if (country != -1 || product != -1)
            {
                //获取产品表
                DataTable table = GetProductTable();
                DataSet ds = new DataSet();
                //拷贝表格准备处理
                ds.Tables.Add(table.Copy());
                //表格加入关系
                ds.Relations.Add("TreeRelation", ds.Tables[0].Columns["Id"], ds.Tables[0].Columns["ParentId"]);
                //选择因子条目
                DataRow[] top = ds.Tables[0].Select("ID='" + product + "'");
                //判断因子是否为最底层因子
                judgement(top[0]);
                if (divresult.ToString() == null || divresult.ToString()=="")
                {
                    productName = Common.NoPager2("adm_factorManagement", "", "sort_name", "", "ID='" + product + "'AND Valided=1").Tables[0].Rows[0]["sort_name"].ToString();
                }
                else
                {
                    header.InnerHtml = "";
                    compareCenter.InnerHtml = divresult.ToString();

                }

            }

            else
            {

            }

        }

        /// <summary>
        /// 最底层因子输出HTML
        /// </summary>
        /// <param name="row"></param>
        private void HTMLADD(DataRow row)
        {
            string PN = row["sort_name"].ToString();
            DataTable DTfactor = Common.NoPager2("adm_Factor", "", "ID,ProductID,FacCName", "", "ProductID='" + row["ID"].ToString() + "'AND IsPublic=1").Tables[0];
            if (DTfactor.Rows.Count > 0)
            {
                divresult.Append("<div class=\"comp_section no_border no_m_b clearfix\">  <div class=\"comparison_row block head list_head clearfix\" runat=\"server\" id=\"compareTop\">  <div style=\"width: 979px;\"> <div class=\"col-xs-4 first\" style=\"width: 195.8px;\">" + PN + "</div>  <div class=\"col-xs-4\" style=\"width: 195.8px;\">   <div>  <a >标准</a><i class=\"arrows\"></i> </div> </div> <div class=\"col-xs-4\" style=\"width: 195.8px;\">     <div>     <a >法规</a><i class=\"arrows\"></i>  </div>   </div>  <div class=\"col-xs-4\" style=\"width: 195.8px;\">  <div> <a >认证</a><i class=\"arrows\"></i> </div>  </div> </div></div></div><div class=\"comp_section clearfix\"> </div>");

                DataTable[,] factor = new DataTable[DTfactor.Rows.Count, 3];
                for (int i = 0; i < DTfactor.Rows.Count; i++)
                {
                    factor[i, 0] = Common.NoPager2("adm_Standard", "", "ID,StaNumber,StaCName AS CName,CountryID", "", "CountryID='" + country + "'AND FactorID='" + DTfactor.Rows[i]["ID"].ToString() + "'AND IsPublic=1").Tables[0];
                    factor[i, 1] = Common.NoPager2("adm_Regulation", "", "ID,RegNumber,RegCName AS CName,RegEName,CountryID", "", "CountryID='" + country + "'AND FactorID='" + DTfactor.Rows[i]["ID"].ToString() + "'AND IsPublic=1").Tables[0];
                    factor[i, 2] = Common.NoPager2("adm_Certification", "", "ID,CerName AS CName,CerIntroduction,CerOrganization,CountryID", "", "CountryID='" + country + "'AND FactorID='" + DTfactor.Rows[i]["ID"].ToString() + "'AND IsPublic=1").Tables[0];
                }



                for (int i = 0; i < DTfactor.Rows.Count; i++)
                {
                    divresult.Append("<div class=\"comp_section clearfix\" >  <div class=\"clearfix nav_btn\"> <div><div class=\"col-xs-2 name\">" + DTfactor.Rows[i]["FacCName"].ToString() + "</div> <div class=\"col-xs-9 action\"> <div class=\"pull-right\"><a href=\"#\" style=\"width: 31px; height: 31px;\"><i>-</i></a></div></div> </div> </div>  <div class=\"comparison_row block centered clearfix\"> <div class=\"col-xs-12 mobile_title visible-xs\" style=\"width: 979px;\"> 111</div><div style=\"width: 979px;\"><div class=\"col-xs-4 first\" style=\"width: 195.8px;\">" + DTfactor.Rows[i]["FacCName"].ToString() + "</div>");
                    for (int j = 0; j < 3; j++)
                    {
                        divresult.Append("<div class=\"col-xs-4\" style=\"width: 195.8px;\">");
                        foreach (DataRow dr in factor[i, j].Rows)
                        {
                            switch (j)
                            {
                                case 0: divresult.Append("<a class=\"fancybox1 fancybox.iframe\" href=\"resultdetail1.aspx?ID=" + dr["ID"].ToString() + "\"><i>" + dr["CName"].ToString() + "</a></i><br>"); break;
                                case 1: divresult.Append("<a class=\"fancybox2 fancybox.iframe\" href=\"resultdetail2.aspx?ID=" + dr["ID"].ToString() + "\"><i>" + dr["CName"].ToString() + "</a></i><br>"); break;
                                case 2: divresult.Append("<a class=\"fancybox3 fancybox.iframe\" href=\"resultdetail3.aspx?ID=" + dr["ID"].ToString() + "\"><i>" + dr["CName"].ToString() + "</a></i><br>"); break;
                            }

                        }
                        divresult.Append("</div>");


                    }
                    divresult.Append("</div></div></div>");
                }

            }
        }

        /// <summary>
        /// 判断因子是够为最底层因子
        /// </summary>
        /// <param name="DR">因子DataRow</param>
        private void judgement(DataRow DR)
        {

            DataRow[] rows = DR.GetChildRows("TreeRelation");
            //不是最底层
            if (rows.Length > 0)
            {
                //遍历非最底层因子
                ResolveSubTree(DR);
            }
            //最底层因子
            else
            {
                //最底层因子数据输出
                HTMLADD(DR);
            }

        }

        /// <summary>
        /// 非最底层因子遍历
        /// </summary>
        /// <param name="dataRow"></param>
        private void ResolveSubTree(DataRow dataRow)
        {
            DataRow[] rows = dataRow.GetChildRows("TreeRelation");

            if (rows.Length > 0)
            {

                foreach (DataRow row in rows)
                {
                    DataRow[] ChlidRows = row.GetChildRows("TreeRelation");
                    if (ChlidRows.Length > 0)
                    {
                        //遍历
                        ResolveSubTree(row);
                    }
                    else
                    {
                        //输出
                        HTMLADD(row);
                    }

                }
            }


        }


        /// <summary>
        /// 获取产品表
        /// </summary>
        /// <returns></returns>
        public DataTable GetProductTable()
        {

            DataTable ProductTable = Common.NoPager2("adm_factorManagement", "", "ID,Valided,sort_name,sort_parentID AS ParentId", "ID", "sortType=1 AND Valided=1").Tables[0];
            ProductTable.Rows[0]["ParentId"] = DBNull.Value;
            return ProductTable;
        }

    }
}


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...