📄 addbook.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
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 Model;
using BLL;
using BLL.interfaces;
public partial class AddBook : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//if (Session["userId"] == null)
// Response.Redirect("login.aspx");
show();
}
}
private void show()
{
int j=1960;
while(j<=2010)
{
cboYear.Items.Add(j.ToString());
j++;
}
for (int i = 1; i <= 12; i++)
{
cboMother.Items.Add(i.ToString());
}
for (int i = 1; i <30; i++)
{
cboDay.Items.Add(i.ToString());
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string title = txtTitle.Text;
int pub = int.Parse(cboPub.SelectedValue);
string y = cboYear.SelectedValue.Trim();
string m = cboMother.SelectedValue.Trim();
string d = cboDay.SelectedValue.Trim();
string time = y + "-" + m + "-" + d;
int booktype = int.Parse(cboBookType.SelectedValue);
string price = txtprice.Text.Trim();
string author = txtAotherName.Text;
string emi = txtEmi.Text;
string authorComments = txtautherComment.Text;
string isbn = txtIsbn.Text.Trim();
string wordCount = txtwordCount.Text.Trim();
string imgUrl = Image1.ImageUrl.ToString();
string toc = txttoc.Text;
string comments = txtComments.Text;
int tuijian = rdblstTJ.SelectedIndex;
Book book = new Book();
book.Title = title;
book.PublisherId = pub;
book.PublishDate = DateTime.Parse(time);
book.TypeId = booktype;
book.UnitPrice = Double.Parse(price);
book.Author = author;
book.EditorComment = emi;
book.AuthorDescription = authorComments;
book.ISBN = isbn;
book.WordsCount =int.Parse(wordCount);
book.Img = imgUrl;
book.TOC = toc;
book.ContentDescription = comments;
book.SimplePY = "WOW";
book.Tuijian = tuijian;
IBook bookMessage = Factory.greatBook();
if (bookMessage.addBook(book))
{
ClientScript.RegisterStartupScript(typeof(string), "a", "alert('添加成功!')", true);
}
else
{
Response.Redirect("error.aspx");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
String path = Server.MapPath("~/image/");
string FileName = FileUpload1.FileName;
if (FileName.Trim().Length != 0)
{
//String fileExtension =
// System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
//// string kk = Server.MapPath("img/" + FileUpload1.PostedFile.FileName);
// String path = Server.MapPath("~/UploadedImages/");
// FileUpload1.PostedFile.SaveAs(kk);
Boolean fileOK = false;
if (FileUpload1.HasFile)
{
string str1 = "~/image/" + FileName;//上传到数据库路径
Image1.ImageUrl = str1;
String fileExtension = System.IO.Path.GetExtension(FileName).ToLower();
String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}
if (fileOK)
{
string fileUrl = path + FileUpload1.FileName;//上传到文件路径
FileUpload1.PostedFile.SaveAs(fileUrl);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -