using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
public partial class SysAdmin_Update_Ful : System.Web.UI.Page
{
public static string imgs;
public static string ID;
public static DateTime dtime;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["id"] != null)
{
ID = Request.QueryString["id"].ToString();
Bind();
}
dtime = DateTime.Now;
}
}
///
/// 根据ID绑定要修改的信息
///
public void Bind()
{
string sql = "select a.cn_title,a.en_title,a.cn_content,a.en_content,a.cn_source,b.cn_tname from cultureinfotab as a,culturetypetab as b where a.tid=b.tid and a.id='"+ID+"'";
DataTable dts = DBH.DBHelper.GetDataSet(sql);
if (dts.Rows.Count > 0)
{
this.txtCname.Text=dts.Rows[0]["cn_title"].ToString();
this.txtEname.Text = dts.Rows[0]["en_title"].ToString();
this.txtSource.Text = dts.Rows[0]["cn_source"].ToString();
this.CN_content.Value = dts.Rows[0]["cn_content"].ToString();
this.EN_content.Value = dts.Rows[0]["en_content"].ToString();
this.Label1.Text = dts.Rows[0]["cn_tname"].ToString();
}
}
protected void ib1Save_Click(object sender, ImageClickEventArgs e)
{
string sql = "update cultureinfotab set cn_title='" + txtCname.Text.Trim() + "', imgs = '" + imgs + "',en_title='" + txtEname.Text.Trim() + "',cn_content='" + CN_content.Value.Replace("'", "‘") + "',en_content='" + EN_content.Value.Replace("'", "‘") +"',cn_source='" + txtSource.Text.Trim() + "',edate='" + dtime + "' where id='" + ID + "'";
int i = DBH.DBHelper.ExecuteNonQuery(sql);
if (i > 0)
{ Methods1.Methods1.MsgBox("信息修改成功", "culturelist.aspx"); }
else { Methods1.Methods1.Alert(this, "信息修改失败"); }
}
#region
///
/// 上传图片
///
///
///
protected void imgbtnUp_Click(object sender, ImageClickEventArgs e)
{
string imgUrl = "Upload/" + DateTime.Now.ToString("yyyyMMdd") + "/";//以当前日期为 今天上传图片目录
if (!System.IO.Directory.Exists(Server.MapPath("~/" + imgUrl)))
{
System.IO.Directory.CreateDirectory(Server.MapPath("~/" + imgUrl));//路径不存在 则创建该目录
}
if (Fupl.HasFile)
{
FileExtension[] fe = { FileExtension.GIF, FileExtension.JPG, FileExtension.PNG, FileExtension.BMP };
string doc = Server.MapPath("~/" + imgUrl);
if (IsAllowedExtension(Fupl, fe) && (Fup.PostedFile.ContentLength / 1024) < 10240) //头字节过滤非法图片 上传大小限制
{
string fileName = Path.GetFileName(Fupl.FileName);
fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + Path.GetExtension(Fupl.FileName); //以当前日期做为 上传图片名字, path.GetExtension获取文件扩展名
imgs = imgUrl + fileName;//获取图片相对路径
doc += fileName;
ImageUtility.MakeThumbImage(Fupl.PostedFile.InputStream, doc, 720, 450, "HW");
//Fup.PostedFile.SaveAs(doc);
Fupl.Dispose();
//Stream s= Fup.PostedFile.InputStream;
//// p1.Visible = true;
//生成缩略图
if (!System.IO.Directory.Exists(Server.MapPath("~/" + imgUrl + "/suo/")))
{
System.IO.Directory.CreateDirectory(Server.MapPath("~/" + imgUrl + "/suo/"));//路径不存在 则创建该目录
}
string simg = Server.MapPath("~/" + imgUrl + "suo/" + fileName);
string jieguo = ImageUtility.MakeThumbImage(doc, simg, 220, 168, "HW");
// this.RegisterStartupScript("", "");
// // img1.Src = "~/" + imgUrl + "suo/" + fileName;
//// txtImg.Value = imgUrl + fileName;
//// txtPic.Value = imgUrl + "suo/" + fileName;
this.RegisterStartupScript("", "");
}
else this.RegisterStartupScript("", "");
}
}
public bool IsAllowedExtension(FileUpload fu, FileExtension[] fileEx)
{
int contentLength = fu.PostedFile.ContentLength;
byte[] buffer = new byte[contentLength];
fu.PostedFile.InputStream.Read(buffer, 0, contentLength);
MemoryStream input = new MemoryStream(buffer);
BinaryReader reader = new BinaryReader(input);
string s = "";
try
{
s = reader.ReadByte().ToString();
s = s + reader.ReadByte().ToString();
}
catch
{
}
reader.Close();
input.Close();
foreach (FileExtension extension in fileEx)
{
if (int.Parse(s) == Convert.ToInt32(extension))
{
return true;
}
}
return false;
}
public enum FileExtension
{
GIF = 7173,
PNG = 13780,
JPG = 255216,
BMP = 6677,
}
#endregion
}