温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:人事管理系统(课程设计)源码
当前文件:
Mispersonal/App_Code/tree.cs,打开代码结构图
Mispersonal/App_Code/tree.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Web; 4
using System.Web.Security; 5
using System.Web.UI; 6
using System.Web.UI.WebControls; 7
using System.Web.UI.WebControls.WebParts; 8
using System.Web.UI.HtmlControls; 9
using System.Data.SqlClient; 10
11
namespace Tree 12
{ 13
/// <summary> 14
/// tree 的摘要说明。 15
/// </summary> 16
17
public class tree : System.Web.UI.Page 18
{ 19
private string tablename = "Tb_Tree"; 20
int current = 0; 21
int len = 0; 22
string[] arrPowerName; 23
string ConnectionString; 24
public tree() 25
{ 26
ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["Mispersonalconn"]; 27
len = GetRecordCount(); 28
arrPowerName = new string[len]; 29
} 30
private void Page_Load(object sender, System.EventArgs e) 31
{ 32
33
GetPowerName(0); 34
//CloseDbConnection(); 35
//ResponseArray(); 36
// 在此处放置用户代码以初始化页面 37
} 38
private void GetPowerName(int _ParentId) 39
{ 40
int Id; 41
string PowerName; 42
string sql = "select Id,PowerName,Layer from " + tablename + " where ParentId=" + _ParentId; 43
try 44
{ 45
SqlConnection conn = new SqlConnection(ConnectionString); 46
conn.Open(); 47
SqlCommand cmd = new SqlCommand(sql, conn); 48
SqlDataReader dr = cmd.ExecuteReader(); 49
while (dr.Read()) 50
{ 51
for (int j = 0; j < int.Parse(dr["Layer"].ToString()); j++) 52
{ 53
Response.Write(" "); 54
} 55
PowerName = dr["PowerName"].ToString(); 56
Response.Write(PowerName + "<br>"); 57
arrPowerName[current++] = PowerName; 58
Id = int.Parse(dr["Id"].ToString()); 59
GetPowerName(Id); 60
} 61
dr.Close(); 62
conn.Close(); 63
} 64
catch (Exception ex) 65
{ 66
Response.Write(ex.ToString()); 67
} 68
} 69
private void ResponseArray() 70
{ 71
int i; 72
for (i = 0; i < len; i++) 73
{ 74
Response.Write(arrPowerName[i] + "<br>"); 75
} 76
} 77
private void CloseDbConnection() 78
{ 79
//conn.Close(); 80
} 81
private int GetRecordCount() 82
{ 83
SqlConnection conn = new SqlConnection(ConnectionString); 84
string sql = "select count(id) from " + tablename; 85
conn.Open(); 86
SqlCommand cmd = new SqlCommand(sql, conn); 87
int count = int.Parse(cmd.ExecuteScalar().ToString()); 88
conn.Close(); 89
return count; 90
} 91
92
93
} 94
} 95





}