📄 cshanchu.aspx.cs
字号:
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;
using System.ComponentModel;
using System.Drawing;
using System.Web.SessionState;
using System.Diagnostics;
using System.Data.SqlClient;
public partial class Web_Cshanchu : System.Web.UI.Page
{
BaseClass bc = new BaseClass();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection conn = new SqlConnection
(System.Configuration.ConfigurationManager.ConnectionStrings["db_KnowledgeConnectionString"].ToString());
conn.Open();
//取得id
string strID = Request.QueryString["Category_id"];
//获取相关数据
string strsql = "SELECT Category_name FROM tb_Category WHERE Category_id='" + strID + "'";
SqlDataAdapter sda = new SqlDataAdapter(strsql, conn);
DataSet ds = new DataSet();
sda.Fill(ds, "tb_Category");
DataRowView rowview = ds.Tables["tb_Category"].DefaultView[0];
this.Label1.Text = rowview["Category_name"].ToString();
//取得id
//string strIDD = Request.QueryString["Category_id"];
////获取相关数据
//string strsqll = "SELECT Category_parent_id FROM tb_Category WHERE Category_id='" + strIDD + "'";
//SqlDataAdapter sdal = new SqlDataAdapter(strsqll, conn);
//DataSet dsl = new DataSet();
//sdal.Fill(dsl, "tb_Category");
//DataRowView row = dsl.Tables["tb_Category"].DefaultView[0];
//this.Label2.Text = row["Category_parent_id"].ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection sqlCon = new SqlConnection
(System.Configuration.ConfigurationManager.ConnectionStrings["db_KnowledgeConnectionString"].ToString());
string strParentID = Request.QueryString["Category_id"];
bc.ExecSQL("delete from tb_Category where Category_id ='" + strParentID + "'");
//string arr = "select Category_id form tb_Category where Category_parent_id = @Category_id";
deleteChildNodes(strParentID);
Response.Write(bc.MessageBox("删除成功!"));
Response.Write("<script>window.close()</script>");
Page.Response.Redirect("~/Web/ListCate.aspx");
}
private void deleteChildNodes(string parentID)
{
ArrayList chidlist = new ArrayList();
int a = 0;
chidlist.Add(GetchildID(parentID,ref a));
for(int i = 0; i < chidlist.Count; i++){
//int dildcomt;
//dildcomt = getchildcount(chidlist[i]);
if (a <= 0)
{
return;
}
else
{
deleteChildNodes(chidlist[i].ToString());
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Page.Response.Redirect("~/Web/ListCate.aspx");
}
private ArrayList GetchildID(string parentID,ref int a)
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["db_KnowledgeConnectionString"].ToString());
conn.Open();
string strsql = "select a.Category_id from tb_Category as a where a.Category_parent_id = "+ parentID +"";
//strsql.Parameters.Add("Category_id", SqlDbType.Int, 10);
//string strSql = "select * from tb_Category";
bc.ExecSQL(strsql);
DataSet dsl = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(strsql, conn);
sda.Fill(dsl);
ArrayList al = new ArrayList();
if (dsl.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < dsl.Tables[0].Rows.Count; i++)
{
al.Add(dsl.Tables[0].Rows[i][0].ToString());
}
}
a = dsl.Tables[0].Rows.Count;
return al;
}
//private int Getchildcount()
//{
//}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -