📄 ptype_alter.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
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 System.Data.SqlClient;
using System.Configuration;
namespace B2Bsite.admin
{
/// <summary>
/// 类型添加/删除/修改
/// </summary>
public class PType_alter : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox className;
protected System.Web.UI.WebControls.Button updata;
protected System.Web.UI.WebControls.Button delete;
protected System.Web.UI.WebControls.TextBox addTName;
protected System.Web.UI.WebControls.Button addT;
protected System.Web.UI.WebControls.TextBox addXName;
protected System.Web.UI.WebControls.Button addX;
protected SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
//protected static String strID="0";
protected System.Web.UI.WebControls.Label lblClassName;
//protected static String strPID="0";
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack && Request.QueryString["categoryid"]!=null)
{
Session["strID"]=Request.QueryString["categoryid"].ToString();
if(Session["strID"]==null)
{
Session["strID"]="0";
}
String sql="SELECT * FROM PType where category_ID=" + Session["strID"].ToString();
SqlCommand command=new SqlCommand(sql,conn);
conn.Open();
SqlDataReader dr=command.ExecuteReader();
if(dr.Read())
{
lblClassName.Text = dr["category_name"].ToString();
Session["strPID"] = dr["parentId"].ToString();
}
dr.Close();
conn.Close();
}
}
public static string InputText( string inputString )//过滤输入字符串
{
if ((inputString != null) && (inputString != String.Empty ))
{
inputString = inputString.Trim();
inputString = inputString.Replace("'",""");
inputString = inputString.Replace("<","<");
inputString = inputString.Replace(">",">");
inputString = inputString.Replace(" "," ");
return inputString.ToString();
}
return "";
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.delete.Click += new System.EventHandler(this.delete_Click);
this.updata.Click += new System.EventHandler(this.updata_Click);
this.addT.Click += new System.EventHandler(this.addT_Click);
this.addX.Click += new System.EventHandler(this.addX_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void updata_Click(object sender, System.EventArgs e)
{
string strName = InputText(className.Text.Trim());
if(strName == String.Empty)
{
Response.Write("<script>alert('不能为空!!!');</script>");
return;
}
if(Session["strID"]==null)
{
Session["strID"]="0";
}
String sql="UPDATE PType SET category_name='" + strName +"' where category_ID=" + Session["strID"].ToString();
SqlCommand command=new SqlCommand(sql,conn);
conn.Open();
command.ExecuteReader();
conn.Close();
}
private void addT_Click(object sender, System.EventArgs e)
{
string strName = InputText(addTName.Text.Trim());
if(strName == String.Empty)
{
Response.Write("<script>alert('不能为空!!!');</script>");
return;
}
if(Session["strPID"]==null)
{
Session["strPID"]="0";
}
String sql="INSERT INTO PType(parentId,category_name) VALUES(" + Session["strPID"].ToString() + ",'" + strName + "')";
SqlCommand command=new SqlCommand(sql,conn);
conn.Open();
command.ExecuteReader();
conn.Close();
addTName.Text="";
}
private void addX_Click(object sender, System.EventArgs e)
{
string strName = InputText(addXName.Text.Trim());
if(strName == String.Empty)
{
Response.Write("<script>alert('不能为空!!!');</script>");
return;
}
if(Session["strID"]==null)
{
Session["strID"]="0";
}
String sql="INSERT INTO PType(parentId,category_name) VALUES(" + Session["strID"].ToString() + ",'" + strName + "')";
SqlCommand command=new SqlCommand(sql,conn);
conn.Open();
command.ExecuteReader();
conn.Close();
addXName.Text="";
}
private void delete_Click(object sender, System.EventArgs e)
{
if(Session["strID"]==null)
{
Session["strID"]="0";
}
String sql="SELECT * FROM PType where parentId=" + Session["strID"].ToString();
SqlCommand command=new SqlCommand(sql,conn);
conn.Open();
SqlDataReader dr=command.ExecuteReader();
if(dr.Read())
{
Response.Write("<script>alert('该分类有子类!!不能删除!!!');</script>");
return;
}
dr.Close();
conn.Close();
String sql2="delete PType where category_ID=" + Session["strID"].ToString();
SqlCommand command2=new SqlCommand(sql2,conn);
conn.Open();
command2.ExecuteReader();
conn.Close();
className.Text="";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -