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 { } } /// /// 最底层因子输出HTML /// /// 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("
" + PN + "
"); 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("
" + DTfactor.Rows[i]["FacCName"].ToString() + "
111
" + DTfactor.Rows[i]["FacCName"].ToString() + "
"); for (int j = 0; j < 3; j++) { divresult.Append("
"); foreach (DataRow dr in factor[i, j].Rows) { switch (j) { case 0: divresult.Append("" + dr["CName"].ToString() + "
"); break; case 1: divresult.Append("" + dr["CName"].ToString() + "
"); break; case 2: divresult.Append("" + dr["CName"].ToString() + "
"); break; } } divresult.Append("
"); } divresult.Append("
"); } } } /// /// 判断因子是够为最底层因子 /// /// 因子DataRow private void judgement(DataRow DR) { DataRow[] rows = DR.GetChildRows("TreeRelation"); //不是最底层 if (rows.Length > 0) { //遍历非最底层因子 ResolveSubTree(DR); } //最底层因子 else { //最底层因子数据输出 HTMLADD(DR); } } /// /// 非最底层因子遍历 /// /// 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); } } } } /// /// 获取产品表 /// /// 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; } } }