/// <summary> /// 像图片表中插入数据 /// </summary> /// <param name="pho">实体对象 </param> /// <returns> int</returns> public int DAL_insert_phototable(phototable pho) { SqlParameter[] parm = new SqlParameter[] { new SqlParameter("@photoname", pho.photoname), new SqlParameter("@photodescribe", pho.photodescribe), new SqlParameter("@phoaddress ", pho.phoaddress), new SqlParameter("@photoalbumID ", pho.photoalbumID) }; int a = sqlHelper.ExecuteNonQuery("insert_phototable", parm); return(a); }
/// <summary> /// 根据相册ID查询该相册下的所有图片 /// </summary> /// <param name="phbumID"></param> /// <returns></returns> public List <string> DAL_select_phototable_where_photoalbumID(int phbumID) { List <string> list = new List <string>(); SqlParameter[] parm = new SqlParameter[] { new SqlParameter("@photoalbumID", phbumID) }; SqlDataReader dr = sqlHelper.ExecuteReader("select_phototable_where_photoalbumID", parm); while (dr.Read()) { phototable te = new phototable(); string stre = dr[0].ToString(); list.Add(stre); } return(list); }
//上传按钮 protected void btnupdown_Click(object sender, EventArgs e) { int a = 0;//更新失败的个数 foreach (GridViewRow dr in this.gvPic.Rows) { FileUpload fu = dr.FindControl("fuphotoAdress") as FileUpload; TextBox txtName = dr.FindControl("txtName") as TextBox; TextBox txtAbout = dr.FindControl("txtAbout") as TextBox; DropDownList ddl = dr.FindControl("ddlClass") as DropDownList; if (fu.HasFile)//是否存在文件 { //if (fu.PostedFile.ContentType.ToLower() == "image/gif" || fu.PostedFile.ContentType.ToLower() == "application/x-img" || fu.PostedFile.ContentType.ToLower() == "image/jpeg" || fu.PostedFile.ContentType.ToLower() == "image/png")//文件格式判断 //{ string guid = GetGuid();//产生唯一标识符 phototable pho = new phototable(); pho.photoname = txtName.Text; pho.phoaddress = @"~\Photo\" + guid + fu.FileName; pho.photodescribe = txtAbout.Text; pho.photoalbumID = Convert.ToInt32(ddl.SelectedValue); int dd = new BLL_photo().DAL_insert_phototable(pho); if (dd > 0) //插入数据库 { string fileadress = Server.MapPath(@"~\Photo\" + guid + fu.FileName); //上传到服务器 fu.PostedFile.SaveAs(fileadress); } else { a++; } //} //else //{ // a++; //} } else { a++; } } string msg = "<script>alert('更新失败" + a + "个')</script>"; Page.ClientScript.RegisterStartupScript(typeof(string), "s", msg); }
/// <summary> /// BLL像图片表中插入数据 /// </summary> /// <param name="pho">实体对象 </param> /// <returns> int</returns> public int DAL_insert_phototable(phototable pho) { return(new DAL_photo().DAL_insert_phototable(pho)); }