动态生成树型结构方法

动态生成树型结构方法

 

一个分类体系,比如将所有列车第一分类,车厢作为第二级别分类,车厢里面的排作为第三级分类……等等,这样就可以统一在一个表里面实现,比如:  
0001列车一  
00010001列车一车厢一  
000100010001列车一车厢一排一  
000100010002列车一车厢一排二  
00010002列车一车厢二  
000100020001列车一车厢二排一  
0002列车二  
00020001列车二车厢一  
.....  

 

    protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDataBase(); //调用BindDataBase方法
tb.ShowLines = true;//显示连接父节点与子节点间的线条
tb.ExpandDepth = 1;//控件显示时所展开的层数


}
l1.Text = "层次" + tb.SelectedValue;

    }

    #region 计算id编码的节点的层次  001 为一层 001001为二层

 

    private int levelCount(string str)
{
//string delimStr = "_";
//char[] delimiter = delimStr.ToCharArray();
//string[] split = null;
//split = str.Split(delimiter);
//return split.Length;
int deepth = str.Length / 3;
return deepth;
}
#endregion

    #region 将数据库的数据存入DataSet


private DataSet GetFuncAll()
{
SqlConnection sqlCon = new SqlConnection();
//实例化SqlConnection对象连接数据库的字符串
sqlCon.ConnectionString = @"server=JONKIKY/SQLEXPRESS;uid=sa;pwd=123456;database=treetext;Trusted_Connection=True";
//实例化SqlDataAdapter对象

        SqlDataAdapter da = new SqlDataAdapter("select * from  Func order by FuncID asc", sqlCon);

        DataSet ds = new DataSet();
da.Fill(ds, "Func");
return ds;
}

    #endregion

    #region 生成树tewwview

    public void BindDataBase()
{
DataSet ds = GetFuncAll(); //得到数据库的数据

        TreeNode tree2 = null;
TreeNode tree3 = null;
//  TreeNode NodeLast= null;
int LevelLast = 0;  //当前节点所在的层次
int nLevel;     //得到的节点的层次
string sTitle;  //节点的内容
TreeNode tree1 = new TreeNode("技能交换"); //Root根节点
this.tb.Nodes.Add(tree1);

        for (int i = 0; i < ds.Tables["Func"].Rows.Count; i++)
{

            nLevel = levelCount(ds.Tables["Func"].Rows[i]["FuncID"].ToString());
sTitle = Convert.ToString(ds.Tables["Func"].Rows[i]["FuncTitle"]) + ds.Tables["Func"].Rows[i]["FuncID"].ToString() + "*" + nLevel + "*" + LevelLast;

            //写入节点的级别与上一个节点级别相同 加入兄弟节点
if (nLevel == LevelLast)
{
tree3 = new TreeNode(sTitle);
tree3.Text = ds.Tables["Func"].Rows[i]["FuncTitle"].ToString();
tree3.Value = ds.Tables["Func"].Rows[i]["FuncID"].ToString();
tree2.Parent.ChildNodes.Add(tree3);
tree2 = tree3;

            }
//写入节点的级别大于上一个节点级别大一个级别
else if (nLevel > LevelLast)
{
//写入节点是根节点
if ((tree1.Value == "技能交换") && (tree2 == null))
{
tree2 = new TreeNode(sTitle);
tree2.Text = ds.Tables["Func"].Rows[i]["FuncTitle"].ToString();
tree2.Value = ds.Tables["Func"].Rows[i]["FuncID"].ToString();
tree1.ChildNodes.Add(tree2);

                }
else//写入节点不是是根节点
{

                    tree3 = new TreeNode(sTitle);
tree3.Text = ds.Tables["Func"].Rows[i]["FuncTitle"].ToString();
tree3.Value = ds.Tables["Func"].Rows[i]["FuncID"].ToString();
tree2.ChildNodes.Add(tree3);

                    tree2 = tree3;//定位到该节点!!!!!!!!!!!!

                }

            }
else
{   //写入节点的级别小于上一个节点级别小一个或多个级别
while (nLevel < LevelLast)
{
tree2 = tree2.Parent;//寻找其父节点
LevelLast = LevelLast - 1;
}
//写入节点是根节点
if (tree2.Parent.Value == "技能交换")
{
tree2 = new TreeNode(sTitle);
tree2.Text = ds.Tables["Func"].Rows[i]["FuncTitle"].ToString();
tree2.Value = ds.Tables["Func"].Rows[i]["FuncID"].ToString();
tree1.ChildNodes.Add(tree2);
}
else
//写入节点不是根节点
{
tree3 = new TreeNode(sTitle);
tree3.Text = ds.Tables["Func"].Rows[i]["FuncTitle"].ToString();
tree3.Value = ds.Tables["Func"].Rows[i]["FuncID"].ToString();
tree2.Parent.ChildNodes.Add(tree3);
tree2 = tree3;
}

            }
LevelLast = nLevel; //获取当前的节点层次

        }

    }
#endregion


protected void tb_SelectedNodeChanged(object sender, EventArgs e)
{

    }

    private bool check()
{
if ((content.Text == null) || (tb.SelectedValue == null))
{
return false;
}
else
{
return true;
}
}

    protected void add_Click(object sender, EventArgs e)
{
string skillname = content.Text.ToString();
string rootid = tb.SelectedValue;


SqlConnection sqlCon = new SqlConnection();
//实例化SqlConnection对象连接数据库的字符串
sqlCon.ConnectionString = @"server=JONKIKY/SQLEXPRESS;uid=sa;pwd=123456;database=treetext;Trusted_Connection=True";
sqlCon.Open();

        if (check())
{

            string cmdtxt2 = "select * from func where funcid like '" + rootid + "'+'___'";

            SqlCommand com = new SqlCommand(cmdtxt2, sqlCon);

            SqlDataReader read = com.ExecuteReader();
int i = 0;
while (read.Read())
{
i++;
}

            i = i + 1;
string t = string.Format("{0:D3}", i);
string addid = rootid + t;
read.Close();
string cmdtxt = "insert into func (FuncID,FuncTitle)";
cmdtxt += "values('" + addid + "','" + skillname + "')";
SqlCommand com2 = new SqlCommand(cmdtxt, sqlCon);
int read2 = com2.ExecuteNonQuery();
Response.Write(i);
sqlCon.Close();
if (read2 == -1)
{
Response.Write("<script language=javascript>alert('添加失败2');location='javascript:history.go(-1)'</script>");
}
else
{

                Response.Write("<script language=javascript>alert('添加成功');location='Default.aspx'</script>");
}


}
else
{
Response.Write("<script language=javascript>alert('添加失败没');location='javascript:history.go(-1)'</script>");
}


}
protected void delete_Click(object sender, EventArgs e)
{
string skillname = content.Text.ToString();
string rootid = tb.SelectedValue;
SqlConnection sqlCon = new SqlConnection();
//实例化SqlConnection对象连接数据库的字符串
sqlCon.ConnectionString = @"server=JONKIKY/SQLEXPRESS;uid=sa;pwd=123456;database=treetext;Trusted_Connection=True";
sqlCon.Open();

        if (check())
{

            string cmdtxt2 = "delete from func where funcid ='" + rootid + "'";

            SqlCommand com = new SqlCommand(cmdtxt2, sqlCon);
int result = com.ExecuteNonQuery();

            if (result == -1)
{
Response.Write("<script language=javascript>alert('删除失败2');location='javascript:history.go(-1)'</script>");
}
else
{

                Response.Write("<script language=javascript>alert('删除成功');location='Default.aspx'</script>");
}


}

        else
{
Response.Write("<script language=javascript>alert('删除失败没');location='javascript:history.go(-1)'</script>");
}

    }
protected void alter_Click(object sender, EventArgs e)
{
string skillname = content.Text.ToString();
string rootid = tb.SelectedValue;
SqlConnection sqlCon = new SqlConnection();
//实例化SqlConnection对象连接数据库的字符串
sqlCon.ConnectionString = @"server=JONKIKY/SQLEXPRESS;uid=sa;pwd=123456;database=treetext;Trusted_Connection=True";
sqlCon.Open();

        if (check())
{

            string cmdtxt2 = "update func";
cmdtxt2 += " set FuncTitle= '" + skillname + "'";
cmdtxt2 += " where funcid ='" + rootid + "'";

            SqlCommand com = new SqlCommand(cmdtxt2, sqlCon);
int result = com.ExecuteNonQuery();

            if (result == -1)
{
Response.Write("<script language=javascript>alert('修改失败2');location='javascript:history.go(-1)'</script>");
}
else
{

                Response.Write("<script language=javascript>alert('修改成功');location='Default.aspx'</script>");
}


}

        else
{
Response.Write("<script language=javascript>alert('修改失败没');location='javascript:history.go(-1)'</script>");
}


}


}

内容概要:本文介绍了一个关于超声谐波成像中幅度调制聚焦超声所引起全场位移和应变的分析模型,并提供了基于Matlab的代码实现。该模型旨在精确模拟和分析在超声谐波成像过程中,由于幅度调制聚焦超声作用于生物组织时产生的力学效应,包括全场的位移与应变分布,从而为医学成像和治疗提供理论支持和技术超声谐波成像中幅度调制聚焦超声引起的全场位移和应变的分析模型(Matlab代码实现)手段。文中详细阐述了模型构建的物理基础、数学推导过程以及Matlab仿真流程,具有较强的理论深度与工程应用价值。; 适合人群:具备一定声学、生物医学工程或力学背景,熟悉Matlab编程,从事医学成像、超声技术或相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于超声弹性成像中的力学建模与仿真分析;②支持高强度聚焦超声(HIFU)治疗中的组织响应预测;③作为教学案例帮助理解超声与组织相互作用的物理机制;④为相关科研项目提供可复用的Matlab代码框架。; 阅读建议:建议读者结合超声物理和连续介质力学基础知识进行学习,重点关注模型假设、偏微分方程的数值求解方法及Matlab实现细节,建议动手运行并修改代码以加深理解,同时可拓展应用于其他超声成像或治疗场景的仿真研究。
### 关于PAT Basic Level Practice的测试点及题目解析 #### 题目难度分级 PAT(Programming Ability Test)是由浙江大学举办的计算机程序设计能力考试,分为不同级别。其中乙级即Basic Level主要面向初学者,考察基本编程技能[^1]。 #### 测试点特点 对于PAT Basic Level中的某些特定题目而言,其测试点设置较为严格。例如,在处理字符串匹配类问题时,需要注意算法逻辑中何时应当终止循环以防止不必要的重复计算;而在涉及数值运算的问题里,则可能因为边界条件而增加复杂度[^3]。 #### 编程语言的选择影响 值得注意的是,尽管大部分简单题目可以作为学习某种新语言的良好实践材料,但在实际操作过程中可能会遇到由于所选语言特性而导致难以通过全部测试点的情况。比如Java在面对部分效率敏感型试题时表现不佳,这可能是由于该语言本身的执行速度相对较慢以及内存管理方式等因素造成的。因此有时不得不转而采用其他更适合解决此类问题的语言版本来完成解答[^2]。 ```cpp #include<bits/stdc++.h> using namespace std; int a[100000]; int c=1; void getPrime(){ int flag=0; for(int i=2;i<105000;i++){ flag=1; for(int j=2;j<=sqrt(i);j++){ if(i%j==0){ flag=0; break; } } if(flag==1) a[c++]=i; } } int main(){ int m,n,i,t=1; scanf("%d %d",&m,&n); getPrime(); for(i=m;i<=n;i++){ if(t%10==1){ printf("%d",a[i]); t++; }else{ printf(" %d",a[i]); t++; } if((t-1)%10==0) printf("\n"); } return 0; } ``` 上述C++代码展示了如何实现一个简单的质数打印功能,并且针对输出格式进行了特殊处理以满足特定要求。这段代码很好地体现了编写高效解决方案的重要性,尤其是在应对像PAT这样的在线评测系统时[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值