protected int UploadFile(HttpPostedFile _file) { string fileName = _file.FileName; Model.t_picture picture = new Model.t_picture(); int id = new BLL.t_picture().GetMaxId(); string sqlwhere = " pic_name like '%" + fileName + "%'"; DataSet datas = new BLL.t_picture().GetList(sqlwhere); if (datas != null && datas.Tables[0].Rows.Count > 0) { string js = "alert('文件已存在');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "", js, true); return(-1); } string Img_Path = Page.MapPath("~/StaffSystem/UploadImage/") + fileName; try { //创建没有存在的目录 Directory.CreateDirectory(Page.MapPath("~/StaffSystem/UploadImage/")); _file.SaveAs(Img_Path); } catch { } if (File.Exists(Img_Path)) { DateTime img_Date = DateTime.Now; picture.pic_ID = id; picture.pic_date = img_Date; if (txtpic_name.Text.Trim() == "") { picture.pic_name = fileName; } else { picture.pic_name = txtpic_name.Text; } picture.pic_valid = "~/StaffSystem/UploadImage/" + picture.pic_name; picture.pic_cate_ID = int.Parse(ddl_add.SelectedValue); if (!new BLL.t_picture().Add(picture)) { return(-1); } return(id); } else { return(-1); } }
protected void Page_Load(object sender, EventArgs e) { BLL.t_picture add = new BLL.t_picture(); Model.t_picture picture; for (int i = 1; i <= 1587; i++) { picture = new Model.t_picture(); picture.pic_date = DateTime.Now; picture.pic_name = "废品图片" + i; picture.pic_valid = "../_wasteImage/" + i + ".jpg"; picture.pic_cate_ID = 4; add.Add(picture); } }