您目前尚未登陆,请选择【登陆】或【注册
首页->电子商务->我的小书坊源码(三层实现)>>BookAdd.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:我的小书坊源码(三层实现)
当前文件:文件类型 MyBookShop/BookAdd.aspx.cs打开代码结构图
普通视图
		            
1using System; 2using System.Collections; 3using System.ComponentModel; 4using System.Data; 5using System.Drawing; 6using System.Web; 7using System.Web.SessionState; 8using System.Web.UI; 9using System.Web.UI.WebControls; 10using System.Web.UI.HtmlControls; 11 12using MyBookShop.BusinessLogicLayer; 13using MyBookShop.BusinessLogicHelper; 14 15namespace MyBookShop.Web 16{ 17 /// <summary> 18 /// BookAdd 的摘要说明。 19 /// </summary> 20 public partial class BookAdd : System.Web.UI.Page 21 { 22 23 protected void Page_Load(object sender, System.EventArgs e) 24 { 25 if(!IsPostBack) 26 { 27 InitData(); 28 //InputPictureFile.Accept="image/*"; 29 } 30 } 31 32 private void InitData() 33 { 34 //初始化:类别下拉框中的数据,用Category表中的数据进行绑定 35 DataTable dt= Category.Query(new Hashtable()); 36 foreach(DataRow dr in dt.Rows) 37 { 38 DropDownListCategory.Items.Add(new ListItem(dr["CategoryName"].ToString(),dr["CategoryId"].ToString())); 39 } 40 } 41 42 /// <summary> 43 /// 提交按钮单击事件 44 /// </summary> 45 /// <param name="sender"></param> 46 /// <param name="e"></param> 47 protected void ButtonOK_Click(object sender, System.EventArgs e) 48 { 49 //构造book信息哈希表 50 Hashtable ht=new Hashtable(); 51 ht.Add("BookName",TextBoxBookName.Text.Trim()); 52 ht.Add("CategoryId",DropDownListCategory.SelectedValue); 53 ht.Add("Price",TextBoxPrice.Text.Trim()); 54 ht.Add("Publisher",TextBoxPublisher.Text.Trim()); 55 ht.Add("PublishDate",TextBoxPublishDate.Text.Trim()); 56 ht.Add("Author",TextBoxAuthor.Text.Trim()); 57 ht.Add("PageNum",TextBoxPageNum.Text.Trim()); 58 ht.Add("Description",TextBoxDescription.Text.Trim()); 59 60 //图片名,以当前时间为文件名,确保文件名没有重复 61 string uploadName=InputPictureFile.Value.Trim(); 62 string pictureName=""; 63 if(uploadName!="") 64 { 65 int idx=uploadName.LastIndexOf("."); 66 string suffix=uploadName.Substring(idx);//文件后缀 67 //Ticks属性的值为自 0001 年 1 月 1 日午夜 12:00 以来所经过时间以 100 毫微秒为间隔表示时的数字。 68 pictureName=System.DateTime.Now.Ticks.ToString()+suffix; 69 ht.Add("PictureUrl",pictureName); 70 } 71 72 ht.Add("SaleCount",1); 73 74 //添加图书,如果数据类型不正确,给出提示. 75 ArrayList WarningMessageList=new ArrayList(); 76 LabelWarningMessage.Text=""; 77 if(BookHelper.Add(ht,ref WarningMessageList)==false) 78 { 79 LabelWarningMessage.Text="<font color=red>"; 80 foreach(string item in WarningMessageList) 81 { 82 LabelWarningMessage.Text+=item+"<br>"; 83 } 84 LabelWarningMessage.Text+="</font>"; 85 } 86 87 //上传图片到目录"\BookPics\"中 88 else 89 { 90 if(uploadName!="") 91 { 92 string path=Server.MapPath(".\\BookPics\\"); 93 InputPictureFile.PostedFile.SaveAs(path+pictureName); 94 } 95 Response.Redirect("BookList.aspx"); 96 } 97 98 } 99 } 100} 101
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:我的小书坊源码(三层实现)
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号