温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:淘淘网电子商务网站源码(毕业设计)
当前文件:
TaoTaoBiz/Admin/AddTopNews.aspx.cs,打开代码结构图
TaoTaoBiz/Admin/AddTopNews.aspx.cs,打开代码结构图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 web.Code; 12
//该源码下载自www.51aspx.com(51aspx.com) 13
14
namespace web.Admin 15
{ 16
/// <summary> 17
/// AddTopNews 的摘要说明。 18
/// </summary> 19
public partial class AddTopNews : System.Web.UI.Page 20
{ 21
protected System.Web.UI.HtmlControls.HtmlImage IMG1; 22
23
protected void Page_Load(object sender, System.EventArgs e) 24
{ 25
// 在此处放置用户代码以初始化页面 26
27
// updown updown1; 28
// updown1=(updown)Context.Handler; 29
// TextBox2.Text = TextBox2.Text + updown1.ImgUrl; 30
ImageButton1.Attributes.Add("onclick", "return btnOpen_Click();"); 31
btnAdd.Attributes.Add("onclick", "return checkEmpty(TextBox1)&&checkEmpty(TextBox2);"); 32
} 33
34
Web 窗体设计器生成的代码 53
54
private string getCategoryName() 55
{ 56
string categoryname = null; 57
switch( DropDownList1.SelectedValue.ToString() ) 58
{ 59
case "1": 60
categoryname = "电脑"; 61
break; 62
case "2": 63
categoryname = "手机"; 64
break; 65
case "3": 66
categoryname = "数码相机"; 67
break; 68
case "4": 69
categoryname = "MP3"; 70
break; 71
case "5": 72
categoryname = "办公外设"; 73
break; 74
} 75
return categoryname; 76
} 77
78
79
protected void btnAdd_Click(object sender, System.EventArgs e) 80
{ 81
TopNewsVO topNewsVO = new TopNewsVO(); 82
topNewsVO.Title = TextBox1.Text.Trim(); 83
topNewsVO.Content = TextBox2.Text.Replace("\n","<br>"); 84
topNewsVO.AddDate = DateTime.Now.ToString(); 85
if(CheckBox1.Checked) 86
{ 87
topNewsVO.IsAtIndex = 1; 88
topNewsVO.IsFirst = 1; 89
} 90
else if(CheckBox2.Checked) 91
{ 92
topNewsVO.IsAtIndex = 1; 93
topNewsVO.IsFirst = 0; 94
} 95
else 96
{ 97
topNewsVO.IsAtIndex = 0; 98
topNewsVO.IsFirst = 0; 99
} 100
topNewsVO.CategoryName = getCategoryName(); 101
TopNewsDAO topNewDAO = new TopNewsDAO(); 102
if( topNewDAO.AddTopNewsArticle( topNewsVO ) != 0 ) 103
{ 104
TextBox1.Text=null; 105
TextBox2.Text=null; 106
DropDownList1.SelectedIndex=0; 107
CheckBox2.Checked=false; 108
CheckBox1.Checked=false; 109
Response.Write("<script>alert('新闻已经添加!')</script>"); 110
} 111
} 112
113
protected void Button1_Click(object sender, System.EventArgs e) 114
{ 115
string fullFileName = up1.PostedFile.FileName; 116
string FileName = fullFileName.Substring( fullFileName.LastIndexOf("\\")+1 ); 117
string FileType = fullFileName.Substring( fullFileName.LastIndexOf(".")+1 ); 118
if( FileType == "bmp" || FileType == "jpg" || FileType == "gif" ) 119
{ 120
up1.PostedFile.SaveAs( Server.MapPath("../TopNews/UpDownImg/Home"+"\\"+FileName) ); 121
Response.Write("<script>alert('上传成功!')</script>"); 122
} 123
else 124
{ 125
Response.Write("<script>alert('你上传的文件格式不对!')</script>"); 126
} 127
} 128
129
protected void CheckBox2_CheckedChanged(object sender, System.EventArgs e) 130
{ 131
if(CheckBox2.Checked) 132
{ 133
Panel1.Visible=true; 134
} 135
else 136
{ 137
Panel1.Visible=false; 138
} 139
} 140
141
} 142
} 143





}