|
发表于 2020-5-19 11:45:01
|
显示全部楼层
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using AjaxPro;
namespace ch51
{
/// <summary>
/// Tree 的摘要说明。
/// </summary>
public partial class Tree : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Utility.RegisterTypeForAjax(typeof(Tree));
}
private Random rand = new Random();
[AjaxMethod()]
public DataSet GetSubCategory(int iCategoryID)
{
DataSet ds = new DataSet();
SqlConnection conn =
new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = string.Format("SELECT CategoryID, CategoryName, FatherID, dbo.IsLeaf(CategoryID) as IsChild FROM Category WHERE FatherID = {0}",
iCategoryID);
SqlDataAdapter da = new SqlDataAdapter(cmd);
try
{
da.Fill(ds);
}
catch (SqlException)
{
}
finally
{
conn.Close();
}
System.Threading.Thread.Sleep(500 + rand.Next(1000));
return ds;
}
[AjaxMethod()]
public DataSet GetDocInfo(int iCategoryID)
{
DataSet ds = new DataSet();
SqlConnection conn =
new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = string.Format(
"SELECT id, author, title, convert(varchar(20), writetime, 120) as writetime, url FROM DocInfo WHERE id = {0}", iCategoryID);
SqlDataAdapter da = new SqlDataAdapter(cmd);
try
{
da.Fill(ds);
}
catch (SqlException)
{
}
finally
{
conn.Close();
}
return ds;
}
[AjaxMethod()]
public DataSet GetDocInfoInCategory(int iCategoryID)
{
DataSet ds = new DataSet();
SqlConnection conn =
new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = string.Format(
"SELECT CategoryID, CategoryName, FatherID FROM Category WHERE FatherID = {0} AND dbo.IsLeaf(CategoryID) = 1", iCategoryID);
SqlDataAdapter da = new SqlDataAdapter(cmd);
try
{
da.Fill(ds);
}
catch (SqlException)
{
}
finally
{
conn.Close();
}
return ds;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
}
}
|
|