⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classadd.aspx.cs

📁 一个简单的新闻后台管理系统
💻 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.Data.SqlClient;

public partial class NewsClassManage_ClassAdd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //第一个文本框获得焦点
        this.TxtClassName.Focus();

    }
    protected void BtnSaveClass_Click(object sender, EventArgs e)
    {
        //记录所影响的行数

        int reader;
        //建立连接
        SqlConnection con = DataAccess.CreateConnection();
        //执行数据库insert语句
        SqlCommand com = new SqlCommand("insert into t_class(classname,itemid,classdesc,classorder) values(@classname,@itemid,@classdesc,@classorder)", con);
        //将文本框的值传入到数据库t_Class表中
        com.Parameters.Add("@classname", SqlDbType.VarChar).Value = this.TxtClassName.Text;
        com.Parameters.Add("@itemid",SqlDbType.VarChar).Value = this.DdlClassItemName.SelectedItem.Value;
        com.Parameters.Add("@classdesc", SqlDbType.VarChar).Value = this.TxtClassDesc.Text;
        com.Parameters.Add("@classorder", SqlDbType.VarChar).Value =this.TxtClassOrder.Text;
        try
        {
            //判断分类名称是否为空,为空给出提示,并把分类名称一栏设为焦点

            if (this.TxtClassName.Text == "")
            {
                //<script>window.alert</script>给出一个提示对话框
                Response.Write("<script>window.alert('分类名称不能为空!')</script>");
                this.TxtClassName.Focus();
            }
            else
            {
                //判断分类顺序一栏输入的是否是整数

                int a = int.Parse(this.TxtClassOrder.Text);
                //打开数据连接
                con.Open();
                //执行命令对象
                reader = com.ExecuteNonQuery();
                //查看所影响行数,如果为零

                if (reader == 0)
                {
                    Response.Write("<script>window.alert('操作失败!')</script>");
                }
                else
                {
                    Response.Write("<script>window.alert('操作成功!')</script>");
                    //把所有文本框置空
                    this.TxtClassName.Text = "";
                    this.TxtClassDesc.Text = "";
                    this.TxtClassOrder.Text = "";
                }
            }

        }
        catch (FormatException)
        {
            //给出提示,分类顺序一栏应输入整数
            Response.Write("<script>window.alert('分类顺序一栏必须输入整数,请重新输入!')</script>");
            //分类顺序一栏获得焦点,同时把文本框的值置为零
            this.TxtClassOrder.Focus();
            this.TxtClassOrder.Text = "";
        }
        finally
        {
            //关闭数据连接
           con.Close();
        }   
              
        
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -