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

📄 message.aspx.cs

📁 数据绑定采用GridView控件
💻 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;
using System.Net;
public partial class message : System.Web.UI.Page
{
    OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
    DataBase db = new DataBase();
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!this.Page.IsPostBack)
        {
            this.Radio1.Checked = true;
            this.Radio21.Checked = true;
            this.ShowSys();
        }
    }
    protected void submit_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(2000);
        string username = this.username.Text.Trim();
        string email = this.email.Text.Trim();
        string httpurl = this.httpurl.Text.Trim();
        string contact = this.contact.Text.Trim();
        if (this.content.Text.Length > Convert.ToInt32(Session["max"])) 
        {
            //this.Label1.Visible = true;
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language=javascript>alert('你的留言超过规定字数!');</script>");  
            //this.Label1.Text = "你的留言超过规定字数!";
            return;
        }
        if (!this.CheckZ(this.content.Text.Trim())) 
        {
            //this.Label1.Visible = true;
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language=javascript>alert(''你的留言中有非法字符!);</script>");  
            //this.Label1.Text= "你的留言中有非法字符!";
            return;
        }
        string content = this.content.Text.Trim();
        string faceurl = "";
        if (this.Radio1.Checked) { faceurl = @"image/face/face1.gif"; }
        if (this.Radio2.Checked) { faceurl = @"image/face/face2.gif"; }
        if (this.Radio3.Checked) { faceurl = @"image/face/face3.gif"; }
        if (this.Radio4.Checked) { faceurl = @"image/face/face4.gif"; }
        if (this.Radio5.Checked) { faceurl = @"image/face/face5.gif"; }
        if (this.Radio6.Checked) { faceurl = @"image/face/face6.gif"; }
        if (this.Radio7.Checked) { faceurl = @"image/face/face7.gif"; }
        if (this.Radio8.Checked) { faceurl = @"image/face/face8.gif"; }
        if (this.Radio9.Checked) { faceurl = @"image/face/face9.gif"; }
        if (this.Radio10.Checked) { faceurl = @"image/face/face10.gif"; }
        if (this.Radio11.Checked) { faceurl = @"image/face/face11.gif"; }
        if (this.Radio12.Checked) { faceurl = @"image/face/face12.gif"; }
        if (this.Radio13.Checked) { faceurl = @"image/face/face13.gif"; }
        if (this.Radio14.Checked) { faceurl = @"image/face/face14.gif"; }
        if (this.Radio15.Checked) { faceurl = @"image/face/face15.gif"; }
        if (this.Radio16.Checked) { faceurl = @"image/face/face16.gif"; }
        if (this.Radio17.Checked) { faceurl = @"image/face/face17.gif"; }
        if (this.Radio18.Checked) { faceurl = @"image/face/face18.gif"; }
        if (this.Radio19.Checked) { faceurl = @"image/face/face19.gif"; }
        if (this.Radio20.Checked) { faceurl = @"image/face/face20.gif"; }
        string picurl = "";
        if (this.Radio21.Checked) { picurl = @"image/face/pic1.gif"; }
        if (this.Radio22.Checked) { picurl = @"image/face/pic2.gif"; }
        if (this.Radio23.Checked) { picurl = @"image/face/pic3.gif"; }
        if (this.Radio24.Checked) { picurl = @"image/face/pic4.gif"; }
        if (this.Radio25.Checked) { picurl = @"image/face/pic5.gif"; }
        if (this.Radio26.Checked) { picurl = @"image/face/pic6.gif"; }
        if (this.Radio27.Checked) { picurl = @"image/face/pic7.gif"; }
        if (this.Radio28.Checked) { picurl = @"image/face/pic8.gif"; }
        if (this.Radio29.Checked) { picurl = @"image/face/pic9.gif"; }
        if (this.Radio30.Checked) { picurl = @"image/face/pic10.gif"; }
        string userip = HttpContext.Current.Request.UserHostAddress;
        //OleDbDataAdapter da = new OleDbDataAdapter("select * from message",conn);
        //OleDbCommandBuilder ou = new OleDbCommandBuilder(da);
        //DataSet ds = new DataSet();
        //da.Fill(ds,"a");
        //DataRow row = ds.Tables["a"].NewRow();
        //row["UserName"] = username;
        //row["UserEmail"] =email;
        //row["UserUrl"]= httpurl;
        //row["UserIP"] = userip;
        //row["faceurl"] = faceurl;
        //row["PicUrl"] = picurl;
        //row["UserContent"] = content;
        //row["Addtime"] = System.DateTime.Now.ToString();
        //row["orderid"] = 1;
        //row["hideid"] = 1;
        //row["replyid"] = 0;
        //ds.Tables["a"].Rows.Add(row);
        //da.Update(ds,"a");
        string sql = "insert into message (UserName,UserEmail,UserUrl,UserIP,faceurl,PicUrl,UserContent,Addtime,orderid,hideid,replyid) values ";
        sql += "('"+username+"','"+email+"','"+httpurl+"','"+userip+"','"+faceurl+"','"+picurl+"','"+content+"','"+System.DateTime.Now.ToString()+"',"+1+","+1+","+0+")";
        if(db.ExecSQl(sql))
        {
            
           Response.Redirect("index.aspx");   
        }
      
    }
    protected void cancel_Click(object sender, EventArgs e)
    {
        this.username.Text = String.Empty;
        this.httpurl.Text = String.Empty;
        this.email.Text = String.Empty;
        this.contact.Text = String.Empty;
        this.content.Text = String.Empty;
    }
    private void ShowSys() 
    {
        DataSet ds = db.GetDataSet("select * from sysconfig","sys");
        Session["max"] = ds.Tables["sys"].Rows[0]["maxletter"].ToString();
        Session["zanghua"]=ds.Tables["sys"].Rows[0]["zanghua"].ToString();
    }
    private bool CheckZ(string str) 
    {
        string temp = Session["zanghua"].ToString();
        string[] t = temp.Split(',');
        for (int i = 0; i < t.Length; i++)
        {
            if (str.Equals(t[i].ToString()))
            { return false; }
                
        }
        return true;
    }
}

⌨️ 快捷键说明

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