温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:校园新闻发布系统源码
当前文件:
SchoolNews/admin_articleadd.aspx.cs[5K,2009-6-12 11:53:16],打开代码结构图
SchoolNews/admin_articleadd.aspx.cs[5K,2009-6-12 11:53:16],打开代码结构图1using System; 2
using System.Collections; 3
using System.ComponentModel; 4
using System.Data; 5
using System.Drawing; 6
using System.Web; 7
using System.Web.SessionState; 8
using System.Web.UI; 9
using System.Web.UI.WebControls; 10
using System.Web.UI.HtmlControls; 11
using System.Data.OleDb; 12
//该源码下载自www.51aspx.com(51aspx.com) 13
14
namespace Lb_news 15
{ 16
/// <summary> 17
/// admin_articleadd 的摘要说明。 18
/// </summary> 19
public class admin_articleadd : System.Web.UI.Page 20
{ 21
protected System.Web.UI.HtmlControls.HtmlInputButton Submit1; 22
protected System.Web.UI.HtmlControls.HtmlInputHidden LbNewsContent; 23
protected System.Web.UI.HtmlControls.HtmlInputText Lb_Title; 24
protected System.Web.UI.WebControls.DropDownList ddl_class; 25
protected System.Web.UI.WebControls.CheckBox Is_Commend; 26
protected System.Web.UI.WebControls.CheckBox Is_Index; 27
protected System.Web.UI.HtmlControls.HtmlInputText Lb_Author; 28
protected int Lb_IsIndex=0; 29
protected int Lb_IsCommend=0; 30
protected int Lb_Classid; 31
protected int Lb_IsPic=0; 32
protected System.Web.UI.WebControls.CheckBox Is_Pic; 33
protected string Lb_Grade; 34
protected string Publisher; 35
protected System.Web.UI.HtmlControls.HtmlInputHidden LbNewsPublisher; 36
protected System.Web.UI.WebControls.TextBox LbNews_Intro; 37
38
protected Conn ds1=new Conn(); 39
40
protected OleDbDataReader rd; 41
protected System.Web.UI.HtmlControls.HtmlInputHidden Lb_TitlePic; 42
protected System.Web.UI.WebControls.Label News_Error; 43
protected DataSet ds; 44
45
private void Page_Load(object sender, System.EventArgs e) 46
{ 47
48
ds1.CheckCookies(1); 49
50
// 在此处放置用户代码以初始化页面postform 51
Submit1.Attributes.Add("OnClick", "document.postform.LbNewsContent.value = content1.document.body.innerHTML;return check_empty(this.form)"); 52
53
HttpCookie cookie=Request.Cookies["UserInfo"]; 54
55
56
Publisher=cookie.Values["username"].ToString(); 57
58
Lb_Grade=cookie.Values["grade"].ToString(); 59
60
61
62
if(!Page.IsPostBack) 63
{ 64
65
66
67
classDate(); 68
69
} 70
71
72
} 73
74
private void classDate() 75
{ 76
ds1.DBopen(); 77
78
ds=ds1.CreateDataSet("select * from Lb_Class","Lb_class"); 79
80
81
82
if (ds.Tables["Lb_class"].DefaultView.Count==0) 83
{ 84
85
News_Error.Text="目前没有类别,请先添加一级分类"; 86
} 87
else 88
{ 89
90
ddl_class.DataSource=ds; 91
ddl_class.DataTextField="C_Name"; 92
ddl_class.DataValueField="C_Id"; 93
ddl_class.DataBind(); 94
} 95
96
97
98
ListItem ClassDefault=new ListItem("请选择类别","def"); //增加一个空白项,并使之位于首位。 99
ddl_class.Items.Insert(0,ClassDefault); 100
ds1.DBclose(); 101
} 102
103
104
Web 窗体设计器生成的代码 129
130
private void Submit1_ServerClick(object sender, System.EventArgs e) 131
{ 132
ds1.DBopen(); 133
string title=Lb_Title.Value.ToString(); 134
string Content=LbNewsContent.Value.ToString().Replace("'"," "); 135
string Author=Lb_Author.Value.ToString(); 136
string TitlePic=Lb_TitlePic.Value.ToString(); 137
string Intro=LbNews_Intro.Text.ToString().Replace("\r\n","<br>").Replace("'"," "); 138
int lb_check; 139
140
Lb_Classid=ds1.ChangeToInt(ddl_class.SelectedItem.Value.ToString()); 141
try 142
{ 143
if (Lb_Grade=="1") 144
{ 145
lb_check=0; 146
} 147
else 148
{ 149
lb_check=1; 150
} 151
152
int result=ds1.ExecuteSql("insert into Lb_News([n_cid],[n_commend],[n_index],[n_ispic],[n_title],[n_spic],[n_author],[n_content],[n_publisher],[n_intro],[n_check])values("+Lb_Classid+","+Lb_IsCommend+","+Lb_IsIndex+","+Lb_IsPic+",'"+title+"','"+TitlePic+"','"+Author+"','"+Content+"','"+Publisher+"','"+Intro+"',"+lb_check+")"); 153
if (result>0) 154
{ 155
156
if (Lb_Grade=="1") 157
{ 158
ds1.alert("添加成功,需等待管理员审核","admin_articleadd.aspx"); 159
160
} 161
else 162
{ 163
ds1.alert("添加成功","admin_articleadd.aspx"); 164
} 165
166
} 167
else 168
{ 169
170
Response.Write ("增加失败"); 171
} 172
173
} 174
catch(System.Data.OleDb.OleDbException ex) 175
{ 176
Response.Write (ex.ToString()); 177
178
} 179
finally 180
{ 181
ds1.DBclose(); 182
} 183
184
185
186
187
} 188
189
private void Is_Commend_CheckedChanged(object sender, System.EventArgs e) 190
{ 191
if(Is_Commend.Checked) 192
{ 193
Lb_IsCommend=1; 194
} 195
} 196
197
private void Is_Index_CheckedChanged(object sender, System.EventArgs e) 198
{ 199
if(Is_Index.Checked) 200
{ 201
Lb_IsIndex=1; 202
} 203
} 204
205
private void ddl_class_SelectedIndexChanged(object sender, System.EventArgs e) 206
{ 207
Lb_Classid=ds1.ChangeToInt(ddl_class.SelectedItem.Value.ToString()); 208
209
} 210
211
private void Is_Pic_CheckedChanged(object sender, System.EventArgs e) 212
{ 213
if(Is_Pic.Checked) 214
{ 215
Lb_IsPic=1; 216
217
218
} 219
220
} 221
222
223
224
225
226
227
228
} 229
} 230






}