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); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Model.t_staff staff = (Model.t_staff)Session["UserInfo"]; HttpCookie staffc = new HttpCookie("staff"); if (staff != null) { Session["UserInfo"] = null; staffc.Value = "用户信息"; // 设定cookie的生命周期,在这里定义为一个小时 DateTime dtNow = DateTime.Now; TimeSpan tsMinute = new TimeSpan(0, 5, 3, 0); staffc.Expires = dtNow + tsMinute; staffc["staffImg"] = new BLL.t_picture().GetModel(Convert.ToInt32(staff.sta__pic_id)).pic_valid; staffc["staffName"] = staff.sta_userName; staffc["staffUserName"] = staff.sta_id.ToString(); staffc["staffpw"] = staff.sta_passWord; staffc["staffID"] = staff.sta_id.ToString(); Response.Cookies.Add(staffc); imgPhoto.Src = staffc.Values["staffImg"]; StaffName.Text = staffc.Values["staffName"]; } else { if (staffc.Values["staffName"] == "" || staffc == null) { Response.Redirect("../Admin/Login.aspx"); } else { imgPhoto.Src = staffc.Values["staffImg"]; StaffName.Text = staffc.Values["staffName"]; } } } }