温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:ajax奥运留言本v2.0源码
当前文件:
OlympicBook20/message.aspx.cs,打开代码结构图
OlympicBook20/message.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.Data.OleDb; 12
using System.Net; 13
public partial class message : System.Web.UI.Page 14
{ 15
OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString); 16
DataBase db = new DataBase(); 17
protected void Page_Load(object sender, EventArgs e) 18
{ 19
if(!this.Page.IsPostBack) 20
{ 21
this.Radio1.Checked = true; 22
this.Radio21.Checked = true; 23
this.ShowSys(); 24
} 25
} 26
protected void submit_Click(object sender, EventArgs e) 27
{ 28
System.Threading.Thread.Sleep(2000); 29
string username = this.username.Text.Trim(); 30
string email = this.email.Text.Trim(); 31
string httpurl = this.httpurl.Text.Trim(); 32
string contact = this.contact.Text.Trim(); 33
if (this.content.Text.Length > Convert.ToInt32(Session["max"])) 34
{ 35
//this.Label1.Visible = true; 36
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language=javascript>alert('你的留言超过规定字数!');</script>"); 37
//this.Label1.Text = "你的留言超过规定字数!"; 38
return; 39
} 40
if (!this.CheckZ(this.content.Text.Trim())) 41
{ 42
//this.Label1.Visible = true; 43
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script language=javascript>alert(''你的留言中有非法字符!);</script>"); 44
//this.Label1.Text= "你的留言中有非法字符!"; 45
return; 46
} 47
string content =Server.HtmlEncode( this.content.Text.Trim()); 48
string faceurl = ""; 49
if (this.Radio1.Checked) { faceurl = @"image/face/face1.gif"; } 50
if (this.Radio2.Checked) { faceurl = @"image/face/face2.gif"; } 51
if (this.Radio3.Checked) { faceurl = @"image/face/face3.gif"; } 52
if (this.Radio4.Checked) { faceurl = @"image/face/face4.gif"; } 53
if (this.Radio5.Checked) { faceurl = @"image/face/face5.gif"; } 54
if (this.Radio6.Checked) { faceurl = @"image/face/face6.gif"; } 55
if (this.Radio7.Checked) { faceurl = @"image/face/face7.gif"; } 56
if (this.Radio8.Checked) { faceurl = @"image/face/face8.gif"; } 57
if (this.Radio9.Checked) { faceurl = @"image/face/face9.gif"; } 58
if (this.Radio10.Checked) { faceurl = @"image/face/face10.gif"; } 59
if (this.Radio11.Checked) { faceurl = @"image/face/face11.gif"; } 60
if (this.Radio12.Checked) { faceurl = @"image/face/face12.gif"; } 61
if (this.Radio13.Checked) { faceurl = @"image/face/face13.gif"; } 62
if (this.Radio14.Checked) { faceurl = @"image/face/face14.gif"; } 63
if (this.Radio15.Checked) { faceurl = @"image/face/face15.gif"; } 64
if (this.Radio16.Checked) { faceurl = @"image/face/face16.gif"; } 65
if (this.Radio17.Checked) { faceurl = @"image/face/face17.gif"; } 66
if (this.Radio18.Checked) { faceurl = @"image/face/face18.gif"; } 67
if (this.Radio19.Checked) { faceurl = @"image/face/face19.gif"; } 68
if (this.Radio20.Checked) { faceurl = @"image/face/face20.gif"; } 69
string picurl = ""; 70
if (this.Radio21.Checked) { picurl = @"image/face/pic1.gif"; } 71
if (this.Radio22.Checked) { picurl = @"image/face/pic2.gif"; } 72
if (this.Radio23.Checked) { picurl = @"image/face/pic3.gif"; } 73
if (this.Radio24.Checked) { picurl = @"image/face/pic4.gif"; } 74
if (this.Radio25.Checked) { picurl = @"image/face/pic5.gif"; } 75
if (this.Radio26.Checked) { picurl = @"image/face/pic6.gif"; } 76
if (this.Radio27.Checked) { picurl = @"image/face/pic7.gif"; } 77
if (this.Radio28.Checked) { picurl = @"image/face/pic8.gif"; } 78
if (this.Radio29.Checked) { picurl = @"image/face/pic9.gif"; } 79
if (this.Radio30.Checked) { picurl = @"image/face/pic10.gif"; } 80
string userip = HttpContext.Current.Request.UserHostAddress; 81
OleDbDataAdapter da = new OleDbDataAdapter("select * from message", conn); 82
OleDbCommandBuilder ou = new OleDbCommandBuilder(da); 83
DataSet ds = new DataSet(); 84
da.Fill(ds, "a"); 85
DataRow row = ds.Tables["a"].NewRow(); 86
row["UserName"] = username; 87
row["UserEmail"] = email; 88
row["UserUrl"] = httpurl; 89
row["UserIP"] = userip; 90
row["faceurl"] = faceurl; 91
row["PicUrl"] = picurl; 92
row["UserContent"] =content; 93
row["Addtime"] = DateTime.Now.ToLocalTime(); 94
row["orderid"] = 1; 95
row["hideid"] = 1; 96
row["replyid"] = 0; 97
ds.Tables["a"].Rows.Add(row); 98
da.Update(ds, "a"); 99
//string sql = "insert into message (UserName,UserEmail,UserUrl,UserIP,faceurl,PicUrl,UserContent,orderid,hideid,replyid) values "; 100
//sql += "('"+username+"','"+email+"','"+httpurl+"','"+userip+"','"+faceurl+"','"+picurl+"','"+content+"',"+1+","+1+","+0+")"; 101
//if(db.ExecSQl(sql)) 102
//{ 103
104
Response.Redirect("index.aspx"); 105
//} 106
107
} 108
protected void cancel_Click(object sender, EventArgs e) 109
{ 110
this.username.Text = String.Empty; 111
this.httpurl.Text = String.Empty; 112
this.email.Text = String.Empty; 113
this.contact.Text = String.Empty; 114
this.content.Text = String.Empty; 115
} 116
private void ShowSys() 117
{ 118
DataSet ds = db.GetDataSet("select * from sysconfig","sys"); 119
Session["max"] = ds.Tables["sys"].Rows[0]["maxletter"].ToString(); 120
Session["zanghua"]=ds.Tables["sys"].Rows[0]["zanghua"].ToString(); 121
} 122
private bool CheckZ(string str) 123
{ 124
string temp = Session["zanghua"].ToString(); 125
string[] t = temp.Split(','); 126
for (int i = 0; i < t.Length; i++) 127
{ 128
if (str.Equals(t[i].ToString())) 129
{ return false; } 130
131
} 132
return true; 133
} 134
} 135




OleDbConnection conn 
}
}