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

📄 bbs.aspx.cs

📁 小型物理试验管理系统Management system for small-scale physical experiments
💻 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 bbs : System.Web.UI.Page
{
    public static int currentpage, pagecount;
    PagedDataSource pagedDataSource1;
    static string sql = "SELECT [username], [email], [neirong], [shijian], [huifu] FROM [bbs] where style='一般留言' order by shijian desc";
    protected void Page_Load(object sender, EventArgs e)
    {
        
        Label8.Text = Session["uid"] +"欢迎您!";
        if (Session["power"] == "学生")
        {
            
        }
        if (!Page.IsPostBack)
        {
            LinkButton1.Enabled = false;
            LinkButton2.Enabled = false;
            data(sql);
        }
    }
    protected void data(string sql)
    {
        string myConnectionString = "server=localhost;uid=sa;pwd=;database = WXJ;";
        SqlConnection myConnection = new SqlConnection();
        myConnection.ConnectionString = myConnectionString;

        SqlCommand cmd = new SqlCommand(sql, myConnection);
        myConnection.Open();

        try
        {
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            DataSet ds = new DataSet();
            da.Fill(ds, "message");
            pagedDataSource1 = new PagedDataSource();
            pagedDataSource1.DataSource = ds.Tables["message"].DefaultView;
            pagedDataSource1.AllowPaging = true;
            pagedDataSource1.PageSize = 5;
            pagecount = pagedDataSource1.PageCount;
            currentpage = pagedDataSource1.CurrentPageIndex + 1;
            if (pagecount == 1)
            {
                LinkButton1.Enabled = false;
                LinkButton2.Enabled = false;
                LinkButton3.Enabled = false;
                LinkButton4.Enabled = false;
            }
            DataList1.DataSource = pagedDataSource1;
            DataList1.DataBind();

        }
        catch (Exception ex)
        {
            ex.ToString();
        }
        finally
        {
            myConnection.Close();
            cmd.Dispose();
            myConnection.Dispose();
        }
        Label6.Text = "当前第" + currentpage.ToString() + "页";
        Label7.Text = "共" + pagecount.ToString() + "页";
    }
   
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        pagedDataSource1.CurrentPageIndex = 0;

        LinkButton1.Enabled = false;
        LinkButton2.Enabled = false;
        LinkButton3.Enabled = true;
        LinkButton4.Enabled = true;
        sql = "SELECT [nicheng], [riqi], [neirong], [huifu] FROM [information] order by riqi desc";
        data(sql);

    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        pagedDataSource1.CurrentPageIndex -= 1;
        Response.Write(pagedDataSource1.CurrentPageIndex.ToString());
        if (pagedDataSource1.CurrentPageIndex == 0)
        {
            LinkButton1.Enabled = false;
            LinkButton2.Enabled = false;
            LinkButton3.Enabled = true;
            LinkButton4.Enabled = true;
        }
        sql = "SELECT [nicheng], [riqi], [neirong], [huifu] FROM [information] order by riqi desc";
        data(sql);
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        pagedDataSource1.CurrentPageIndex += 1;
        if (pagedDataSource1.CurrentPageIndex == 1)
        {
            LinkButton2.Enabled = true;
            LinkButton1.Enabled = true;
        }
        if (pagedDataSource1.CurrentPageIndex == pagedDataSource1.PageCount - 1)
        {
            LinkButton3.Enabled = false;
            LinkButton4.Enabled = false;
        }
        sql = "SELECT [nicheng], [riqi], [neirong], [huifu] FROM [information] order by riqi desc";
        data(sql);
    }
    protected void LinkButton4_Click(object sender, EventArgs e)
    {
        pagedDataSource1.CurrentPageIndex = pagedDataSource1.PageCount - 1;
        LinkButton3.Enabled = false;
        LinkButton4.Enabled = false;
        LinkButton2.Enabled = true;
        LinkButton1.Enabled = true;
        sql = "SELECT [nicheng], [riqi], [neirong], [huifu] FROM [information] order by riqi desc";
        data(sql);
    }

    protected void liuyan_Click(object sender, ImageClickEventArgs e)
    {
        if (TextBox1.Text == "")
        {
            Label9.Text = "请输入您的留言!";
        }
        else
        {
            string date = System.DateTime.Now.ToString();
            string datetime = date.Substring(0, 18);

            string neirong = TextBox1.Text.Trim();
            string leixing;
            string huifu = null;
            if (CheckBox1.Checked)
            {
                leixing = CheckBox1.Text;
            }
            else
                leixing = "一般留言";

            string sqlstr = "insert into bbs values('" + Session["username"] + "','" + Session["email"] + "','" + datetime + "','" + neirong + "','" + huifu + "','" + leixing + "')";

            string myConnectionString = "server=localhost;uid=sa;pwd=;database = WXJ;";
            SqlConnection myConnection = new SqlConnection();
            myConnection.ConnectionString = myConnectionString;
            SqlCommand cmd = new SqlCommand(sqlstr, myConnection);
            myConnection.Open();
            try
            {
                cmd.ExecuteNonQuery();
                Response.Write("<script language=javascript>alert(\"留言成功!\")</script>");
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
            finally
            {
                myConnection.Close();
                cmd.Dispose();
                myConnection.Dispose();
            }
            TextBox1.Text = "";

            data(sql);
        }

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        
    }
}

⌨️ 快捷键说明

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