/// <summary> /// 添加广告图片 /// </summary> /// <param name="data"></param> /// <returns></returns> public static bool addwebimages(webimagesinfo data) { SqlParameter[] parms = new SqlParameter[5]; parms[0] = new SqlParameter("@imginfo", SqlDbType.VarChar, 500); parms[0].Value = data.imginfo; parms[1] = new SqlParameter("@imgurl", SqlDbType.VarChar, 50); parms[1].Value = data.imgurl; parms[2] = new SqlParameter("@imgname", SqlDbType.VarChar, 50); parms[2].Value = data.imgname; parms[3] = new SqlParameter("@itid",SqlDbType.Int); parms[3].Value = data.itid; parms[4] = new SqlParameter("@imgcor", SqlDbType.VarChar, 50); parms[4].Value = data.imgcor; string sql = "insert into webimages (imginfo,imgurl,imgname,itid,imgcor) values(@imginfo,@imgurl,@imgname,@itid,@imgcor)"; int result = 0; try { result = SqlHelper.ExecuteNonQuery(SqlHelper.connectionstring, CommandType.Text, sql, parms); } catch (Exception ex) { throw new Exception(ex.Message); } finally { } return result > 0; }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["wiid"] != null) { int wiid = TypeParse.DbObjToInt(Request.QueryString["wiid"].ToString(), 0); webimagesinfo data = webimages.getwebimagesinfo(wiid); webimagesinfoDATA = data; if (!Page.IsPostBack) { List<webimagesinfo> itlist = webimages.getimagestype(); itID.DataSource = itlist; itID.DataTextField = "imagestype"; itID.DataValueField = "itid"; itID.DataBind(); for (int i = 0; i < itID.Items.Count; i++) { if (itID.Items[i].Value == data.itid.ToString()) { itID.SelectedIndex = i; } } imgcor.Value = data.imgcor; imginfo.Value = data.imginfo; imgurl.Value = data.imgurl; swiid.Value = wiid.ToString(); oimgname.Value = data.imgname; } } }
protected void EditWebImages(object sender, EventArgs e) { string s_imginfo = imginfo.Value.Trim(); string s_imgcor = imgcor.Value.Trim(); string s_imgurl = imgurl.Value.Trim(); int s_itid = TypeParse.DbObjToInt(itID.SelectedValue, 0); string uploadName = imgname.Value;//获取待上传图片的完整路径,包括文件名 //string uploadName = InputFile.PostedFile.FileName; string pictureName = oimgname.Value.Trim();//上传后的图片名,以当前时间为文件名,确保文件名没有重复 if (imgname.Value != "") { int idx = uploadName.LastIndexOf("."); string suffix = uploadName.Substring(idx);//获得上传的图片的后缀名 if (suffix.ToLower() != ".bmp" && suffix.ToLower() != ".jpg" && suffix.ToLower() != ".jpeg" && suffix.ToLower() != ".png" && suffix.ToLower() != ".gif") { imgnote.InnerHtml = "<span style=\"color:red\">上传文件必须是图片格式!</span>"; return; } pictureName = DateTime.Now.Ticks.ToString() + suffix; } try { if (uploadName != "") { string path = Server.MapPath("/Files/WebImages/"); imgname.PostedFile.SaveAs(path + pictureName); } webimagesinfo item = new webimagesinfo(); item.imgcor = s_imgcor; item.imginfo = s_imginfo; item.imgname = pictureName; item.imgurl = s_imgurl; item.itid = s_itid; item.wiid = TypeParse.DbObjToInt(swiid.Value, 0); bool result = webimages.editwebimages(item); if (result) { Response.Write("<script>alert('编辑图片成功!');location.href='/Manager/WebImages.aspx';</script>"); return; } else { Response.Write("<script>alert('编辑图片失败!');location.href='/Manager/WebImages.aspx';</script>"); return; } } catch (Exception ex) { Response.Write(ex); } }
/// <summary> /// 添加图片类别 /// </summary> /// <param name="data"></param> /// <returns></returns> public static bool addimagestype(webimagesinfo data) { SqlParameter[] parms = new SqlParameter[1]; parms[0] = new SqlParameter("@imagestype", SqlDbType.VarChar, 20); parms[0].Value = data.imagestype; string sql = "insert into imagestype (imagestype) values(@imagestype)"; int result = 0; try { result = SqlHelper.ExecuteNonQuery(SqlHelper.connectionstring, CommandType.Text, sql, parms); } catch (Exception ex) { throw new Exception(ex.Message); } finally { } return result > 0; }
/// <summary> /// 绑定页面的广告图片 /// </summary> /// <param name="n"></param> /// <param name="imagestype"></param> /// <returns></returns> public static List<webimagesinfo> bindwebimages(int n, string imagestype) { SqlParameter[] parms = new SqlParameter[1]; parms[0] = new SqlParameter("@imagestype", SqlDbType.VarChar, 50); parms[0].Value = imagestype; List<webimagesinfo> webimageslist = new List<webimagesinfo>(); string sql = "SELECT top " + n + " webimages.wiid,webimages.imgurl,webimages.imginfo,webimages.itid,webimages.imgname,imagestype.imagestype FROM webimages,imagestype WHERE imagestype.imagestype=@imagestype AND webimages.itid=imagestype.itid order by webimages.wiid DESC"; try { DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.connectionstring, CommandType.Text, sql, parms).Tables[0]; if (dt != null) { foreach (DataRow dr in dt.Rows) { webimagesinfo item = new webimagesinfo(); item.wiid = TypeParse.DbObjToInt(dr["wiid"].ToString(), 0); item.imgurl = TypeParse.DbObjToString(dr["imgurl"].ToString(), ""); item.imginfo = TypeParse.DbObjToString(dr["imginfo"].ToString(), ""); item.imgname = TypeParse.DbObjToString(dr["imgname"].ToString(), "noimgs.jpg"); item.itid = TypeParse.DbObjToInt(dr["itid"].ToString(), 0); item.imagestype = TypeParse.DbObjToString(dr["imagestype"].ToString(), ""); webimageslist.Add(item); } } } catch (Exception ex) { throw new Exception(ex.Message); } finally { } return webimageslist; }
/// <summary> /// 根据图片类型名称得到单个广告图片信息 /// </summary> /// <param name="imagestype"></param> /// <returns></returns> public static webimagesinfo getwebimagesinfoOne(string imagestype) { SqlParameter[] parms = new SqlParameter[1]; parms[0] = new SqlParameter("@imagestype", SqlDbType.VarChar, 50); parms[0].Value = imagestype; webimagesinfo item = new webimagesinfo(); string sql = "SELECT top 1 webimages.wiid,webimages.imgurl,webimages.imginfo,webimages.itid,webimages.imgname,imagestype.imagestype FROM webimages,imagestype WHERE imagestype.imagestype=@imagestype AND webimages.itid=imagestype.itid order by webimages.wiid DESC"; try { SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.connectionstring, CommandType.Text, sql, parms); if (dr.Read()) { item.wiid = TypeParse.DbObjToInt(dr["wiid"].ToString(), 0); item.imgurl = TypeParse.DbObjToString(dr["imgurl"].ToString(), ""); item.imginfo = TypeParse.DbObjToString(dr["imginfo"].ToString(), ""); item.imgname = TypeParse.DbObjToString(dr["imgname"].ToString(), "noimgs.jpg"); item.itid = TypeParse.DbObjToInt(dr["itid"].ToString(), 0); item.imagestype = TypeParse.DbObjToString(dr["imagestype"].ToString(), ""); dr.Close(); dr.Dispose(); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { } return item; }
/// <summary> /// 得到单个广告图片信息 /// </summary> /// <param name="wiid"></param> /// <returns></returns> public static webimagesinfo getwebimagesinfo(int wiid) { SqlParameter[] parms = new SqlParameter[1]; parms[0] = new SqlParameter("@wiid", SqlDbType.Int); parms[0].Value = wiid; webimagesinfo item = new webimagesinfo(); string sql = "select webimages.wiid,webimages.imgurl,webimages.imginfo,webimages.itid,webimages.imgname,webimages.imgcor,imagestype.imagestype from webimages,imagestype where webimages.itid=imagestype.itid and webimages.wiid=@wiid"; try { SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.connectionstring, CommandType.Text, sql, parms); if (dr.Read()) { item.wiid = TypeParse.DbObjToInt(dr["wiid"].ToString(), 0); item.imgurl = TypeParse.DbObjToString(dr["imgurl"].ToString(), ""); item.imginfo = TypeParse.DbObjToString(dr["imginfo"].ToString(), ""); item.imgname = TypeParse.DbObjToString(dr["imgname"].ToString(), "noimgs.jpg"); item.itid = TypeParse.DbObjToInt(dr["itid"].ToString(), 0); item.imagestype = TypeParse.DbObjToString(dr["imagestype"].ToString(), ""); item.imgcor = TypeParse.DbObjToString(dr["imgcor"].ToString(), ""); dr.Close(); dr.Dispose(); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { } return item; }
/// <summary> /// 得到广告图片 /// </summary> /// <param name="pdata"></param> /// <returns></returns> public static List<webimagesinfo> getwebimages(pageinfo pdata) { List<webimagesinfo> webimageslist = new List<webimagesinfo>(); try { DataTable dt = pagehelper.getpagedt(pdata); if (dt != null) { foreach (DataRow dr in dt.Rows) { webimagesinfo item = new webimagesinfo(); item.wiid = TypeParse.DbObjToInt(dr["wiid"].ToString(), 0); item.imgurl = TypeParse.DbObjToString(dr["imgurl"].ToString(), ""); item.imginfo = TypeParse.DbObjToString(dr["imginfo"].ToString(), ""); item.imgname = TypeParse.DbObjToString(dr["imgname"].ToString(), "noimgs.jpg"); item.itid = TypeParse.DbObjToInt(dr["itid"].ToString(), 0); item.imagestype = TypeParse.DbObjToString(dr["imagestype"].ToString(), ""); item.imgcor = TypeParse.DbObjToString(dr["imgcor"].ToString(), ""); webimageslist.Add(item); } } } catch (Exception ex) { throw new Exception(ex.Message); } finally { } return webimageslist; }
/// <summary> /// 得到图片类别 /// </summary> /// <returns></returns> public static List<webimagesinfo> getimagestype() { string sql = "select itid,imagestype from imagestype"; List<webimagesinfo> itlist = new List<webimagesinfo>(); try { DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.connectionstring, CommandType.Text, sql); foreach (DataRow dr in ds.Tables[0].Rows) { webimagesinfo item = new webimagesinfo(); item.itid = TypeParse.DbObjToInt(dr["itid"].ToString(), 0); item.imagestype = TypeParse.DbObjToString(dr["imagestype"].ToString(), ""); itlist.Add(item); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { } return itlist; }
/// <summary> /// 编辑广告图片 /// </summary> /// <param name="data"></param> /// <returns></returns> public static bool editwebimages(webimagesinfo data) { SqlParameter[] parms = new SqlParameter[6]; parms[0] = new SqlParameter("@imgcor", SqlDbType.VarChar, 50); parms[0].Value = data.imgcor; parms[1] = new SqlParameter("@imgurl", SqlDbType.VarChar, 50); parms[1].Value = data.imgurl; parms[2] = new SqlParameter("@imginfo", SqlDbType.VarChar, 500); parms[2].Value = data.imginfo; parms[3] = new SqlParameter("@imgname", SqlDbType.VarChar, 50); parms[3].Value = data.imgname; parms[4] = new SqlParameter("@itid", SqlDbType.Int); parms[4].Value = data.itid; parms[5] = new SqlParameter("@wiid", SqlDbType.Int); parms[5].Value = data.wiid; string sql = "update webimages set imgcor=@imgcor, imgurl=@imgurl,imginfo=@imginfo,imgname=@imgname,itid=@itid where wiid=@wiid"; int result = 0; try { result = SqlHelper.ExecuteNonQuery(SqlHelper.connectionstring, CommandType.Text, sql, parms); } catch (Exception ex) { throw new Exception(ex.Message); } finally { } return result > 0; }
/// <summary> /// 编辑图片类别 /// </summary> /// <param name="data"></param> /// <returns></returns> public static bool editimagestype(webimagesinfo data) { SqlParameter[] parms = new SqlParameter[2]; parms[0] = new SqlParameter("@imagestype", SqlDbType.VarChar, 20); parms[0].Value = data.imagestype; parms[1] = new SqlParameter("@itid",SqlDbType.Int); parms[1].Value = data.itid; string sql = "update imagestype set imagestype=@imagestype where itid=@itid"; int result = 0; try { result = SqlHelper.ExecuteNonQuery(SqlHelper.connectionstring, CommandType.Text, sql, parms); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { } return result > 0; }