谁来帮我写点注释
刚刚找个源码正是我想要的
可是有点看不懂
希望有人帮忙写的注释
private void Form1_Load(object sender, System.EventArgs e)
{
this.lvwSchool.Columns.Add("学号",80,HorizontalAlignment.Center);
this.lvwSchool.Columns.Add("姓名",100,HorizontalAlignment.Center);
this.lvwSchool.Columns.Add("成绩",105,HorizontalAlignment.Center);
this.lvwSchool.View = View.Details;
cnn = new SqlConnection("server = .; uid = sa; pwd = ; database = school");
adp = new SqlDataAdapter();
cmm = new SqlCommand("select xh from Class1",cnn);
dsxh = new DataSet("school");
adp.SelectCommand = cmm;
adp.Fill(dsxh,"Class1");
TreeNode node1 = new TreeNode(dsxh.DataSetName);
this.tvwSchool.Nodes.Add(node1);
node1 = new TreeNode(dsxh.Tables["Class1"].TableName);
this.tvwSchool.Nodes[0].Nodes.Add(node1);
foreach(DataRow r in dsxh.Tables["Class1"].Rows)
{
node1 = new TreeNode(r["xh"].ToString());
this.tvwSchool.Nodes[0].Nodes[0].Nodes.Add(node1);
}
cmm = new SqlCommand("select xh from Class2",cnn);
adp.SelectCommand = cmm;
adp.Fill(dsxh,"Class2");
TreeNode node2 = new TreeNode(dsxh.Tables["Class2"].TableName);
this.tvwSchool.Nodes[0].Nodes.Add(node2);
foreach(DataRow r in dsxh.Tables["Class2"].Rows)
{
node2 = new TreeNode(r["xh"].ToString());
this.tvwSchool.Nodes[0].Nodes[1].Nodes.Add(node2);
}
}
private void tvwSchool_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
this.lvwSchool.Items.Clear();
if(tvwSchool.SelectedNode.Parent != null && tvwSchool.SelectedNode.Nodes.Count != 0)
{
string bj = tvwSchool.SelectedNode.Text;
cmm = new SqlCommand("select * from " + bj + "",cnn);
ds = new DataSet("school");
adp.SelectCommand = cmm;
adp.Fill(ds,"Class");
for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
lstItem = new ListViewItem(ds.Tables[0].Rows[i][0].ToString());
for(int j = 0; j < ds.Tables[0].Columns.Count - 1; j++)
{
lstItem.SubItems.Add(ds.Tables[0].Rows[i][j + 1].ToString());
}
lvwSchool.Items.Add(lstItem);
}
}
else if(tvwSchool.SelectedNode.Parent != null && tvwSchool.SelectedNode.Nodes.Count == 0)
{
string xh = tvwSchool.SelectedNode.Text;
string bj = tvwSchool.SelectedNode.Parent.Text;
cmm = new SqlCommand("select * from " + bj +" where xh = '" + xh +"'",cnn);
adp.SelectCommand = cmm;
ds = new DataSet("school");
adp.Fill(ds,"Class");
for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
lstItem = new ListViewItem(ds.Tables[0].Rows[i][0].ToString());
for(int j = 0; j < ds.Tables[0].Columns.Count - 1; j++)
{
lstItem.SubItems.Add(ds.Tables[0].Rows[i][j + 1].ToString());
}
lvwSchool.Items.Add(lstItem);
}
}