|
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>
/// Summary description of Tree.
/// </ summary>
public partial class Tree: System.Web.UI.Page
{
protected void Page_Load (object sender, System.EventArgs e)
{
// Place user code here to initialize the page
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 form designer generated code
override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is necessary for ASP.NET Web Form Designer.
//
InitializeComponent ();
base.OnInit (e);
}
The
/// <summary>
/// The designer supports the required method-do not use the code editor to modify
/// The content of this method.
/// </ summary>
private void InitializeComponent ()
{
}
#endregion
}
} |
|