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

📄 bookedit.aspx.cs

📁 自己开发的一个wap手机网站源代码 公开代码供大家学习下载
💻 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.OleDb;

public partial class admins_BookEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.Session["name"] == null)
        {
            base.Response.Redirect("login.aspx");
        }
        else if (!base.IsPostBack && (base.Request.QueryString["id"] != null))
        {
            string id = base.Request.QueryString["id"].ToString();
            this.GetCount(id);
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (base.Request.QueryString["id"] != null)
        {
            string id = base.Request.QueryString["id"].ToString();
            this.upBook(id);
            base.Response.Redirect("book.aspx");
        }
        else
        {
            this.Insert();
            base.Response.Redirect("book.aspx");
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        base.Response.Redirect("book.aspx");
    }

    protected static string GetConnString()
    {
        string str2 = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        string path = ConfigurationManager.ConnectionStrings["DBPaths"].ConnectionString;
        string str4 = HttpContext.Current.Server.MapPath(path);
        return (str2 + str4 + ";");
    }
    private void GetCount(string id)
    {
        DataSet dataSet = new DataSet();
        string connString = GetConnString();
        new OleDbDataAdapter("select name as 名称, zhuozhe as 作者 , neirong as 内容, Type as 类型,Jibie as 级别 from books where id=" + id + " and DeleteFlag=False", connString).Fill(dataSet, "Tb1");
        if (dataSet.Tables[0].Rows.Count != 0)
        {
            this.TbxName.Text = dataSet.Tables[0].Rows[0]["名称"].ToString();
            this.TbxzZuozhe.Text = dataSet.Tables[0].Rows[0]["作者"].ToString();
            this.TbxNeirong.Text = dataSet.Tables[0].Rows[0]["内容"].ToString();
            this.TbxType.Text = dataSet.Tables[0].Rows[0]["类型"].ToString();
            this.TbxJi.Text = dataSet.Tables[0].Rows[0]["级别"].ToString();
        }
    }

    private void Insert()
    {
        OleDbConnection connection = new OleDbConnection(GetConnString());
        OleDbCommand command = new OleDbCommand("Insert Into books (name,zhuozhe,neirong,DeleteFlag,Type,Jibie) Values('" + this.TbxName.Text.Trim() + "','" + this.TbxzZuozhe.Text.Trim() + "' ,'" + this.TbxNeirong.Text.Trim() + "', 0 ,'" + this.TbxType.Text.Trim() + "'," + this.TbxJi.Text.Trim() + ")", connection);
        connection.Open();
        command.ExecuteNonQuery();
        connection.Close();
    }

    private void upBook(string id)
    {
        OleDbConnection connection = new OleDbConnection(GetConnString());
        OleDbCommand command = new OleDbCommand("update books set name='" + this.TbxName.Text.Trim() + "',zhuozhe='" + this.TbxzZuozhe.Text.Trim() + "' ,neirong ='" + this.TbxNeirong.Text.Trim() + "',Type='" + this.TbxType.Text.Trim() + "',Jibie ='" + this.TbxJi.Text.Trim() + "' where  id= " + id, connection);
        connection.Open();
        command.ExecuteNonQuery();
        connection.Close();
    }

}

⌨️ 快捷键说明

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