我ASP.NET考试了 可是这些代码看不懂 请朋友们帮忙翻译下!
using System;using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace SMS.Web
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
CreateGroupNode(new SMS.BLL.Group());
CreateWordMenu(new SMS.BLL.Word());
}
}
private void CreateWordMenu(SMS.BLL.Word obj)
{
DataTable dt = new DataTable();
dt = obj.GetAllList().Tables[0];
foreach (DataRow row in dt.Rows)
{
CreateMenuItem(row);
}
}
private void CreateGroupNode(SMS.BLL.Group obj)
{
DataTable dt = new DataTable();
dt = obj.GetAllList().Tables[0];
foreach (DataRow row in dt.Rows)
{
CreateOneGroupNode(row);
}
}
private void CreateMenuItem(DataRow row)
{
MenuItem mnu = new MenuItem();
mnu.Text = row["title"].ToString();
mnu.Value = row["content"].ToString();
mnuWord.Items.Add(mnu);
}
private void CreateOneGroupNode(DataRow row)
{
TreeNode node = new TreeNode();
node.Text = row["GroupName"].ToString();
TreeView1.Nodes.Add(node);
}
protected void btnAddGroup_Click(object sender, EventArgs e)
{
TreeNode node = new TreeNode();
node.Text = txtGroupName.Text.Trim();
TreeView1.Nodes.Add(node);
SMS.BLL.Group myGroup = new SMS.BLL.Group();
SMS.Model.Group myModel = new SMS.Model.Group();
myModel.GroupName = txtGroupName.Text.Trim();
myGroup.Add(myModel);
}
protected void btnAddFriend_Click(object sender, EventArgs e)
{
if (IsRootNode(TreeView1.SelectedNode))
CreateFriendNode();
}
private void CreateFriendNode()
{
string name = txtName.Text.Trim();
string phone = txtPhone.Text.Trim();
TreeNode selectedNode = TreeView1.SelectedNode;
AddSubNodeToRoot(selectedNode, name, phone);
SaveSubNodeInfo(selectedNode, name, phone);
}
private static void SaveSubNodeInfo(TreeNode selectedNode, string name, string phone)
{
SMS.BLL.Friend myFriend = new SMS.BLL.Friend();
SMS.Model.Friend myModel = new SMS.Model.Friend();
myModel.GroupName = selectedNode.Text;
myModel.Name = name;
myModel.Phone = phone;
myFriend.Add(myModel);
}
private static void AddSubNodeToRoot(TreeNode selectedNode, string name, string phone)
{
TreeNode node = new TreeNode();
node.Text = name;
node.Value = phone;
selectedNode.ChildNodes.Add(node);
}
private bool IsSubNode(TreeNode selectedNode)
{
return GetNodeType(selectedNode, 1);
}
private bool IsRootNode(TreeNode selectedNode)
{
return GetNodeType(selectedNode, 0);
}
private bool GetNodeType(TreeNode selectedNode, int depth)
{
if (selectedNode != null)
if (TreeView1.SelectedNode.Depth == depth)
{
return true;
}
return false;
}