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.Drawing;
using System.IO;
using System.Data.SqlClient;
public partial class SysAdmin_Other : System.Web.UI.Page
{
public static string imgs;//获取图片地址
public string editor;
public static DateTime dtime;
public static string suoImgs;//获取图片缩略图路径
public static string id;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["ID"] != null)
{
id = Request.QueryString["ID"].ToString();
bindDDL(id);
}
}
dtime = DateTime.Now;
if (Session["admin"] != null)
{
editor = Session["admin"].ToString();
}
else
editor = "匿名";
}
public void bindDDL(string id)
{
string str = "select id,contents,econtent,typename,etypename from othertab where typeid='" + id + "'";
DataTable dts = DBH.DBHelper.GetDataSet(str);
if (dts.Rows.Count > 0)
{
this.txtCname.Text = dts.Rows[0]["typename"].ToString();
this.txtEname.Text = dts.Rows[0]["etypename"].ToString();
this.CN_content.Value = dts.Rows[0]["contents"].ToString();
this.EN_content.Value = dts.Rows[0]["econtent"].ToString();
}
}
public void Update()
{
if (suoImgs == null)
{
string sql = "update Othertab set typename=@typename,etypename=@etypename,contents=@contents,econtent=@econtent,dates=@dates where typeid=@typeid";//修改语句
SqlParameter[] par ={
new SqlParameter("@typename",txtCname.Text),
new SqlParameter("@etypename",txtEname.Text),
new SqlParameter("@contents",CN_content.Value),
new SqlParameter("@econtent",EN_content.Value.Replace("'","‘")),
new SqlParameter("@dates",dtime),
new SqlParameter("@typeid",id),
};
int i = DBH.DBHelper.ExecuteNonQuery(sql, par);
if (i > 0)
{
//Methods1.Methods1.Alert(this, "信息添加成功");
Methods1.Methods1.MsgBox("信息修改成功", "Other.aspx");
}
else
{
Methods1.Methods1.Alert(this, "信息修改失败");
}
}
else
{
string sql = "update Othertab set typename=@typename,etypename=@etypename,contents=@contents,econtent=@econtent,dates=@dates,img=@img where typeid=@typeid";//修改语句
SqlParameter[] par ={
new SqlParameter("@typename",txtCname.Text),
new SqlParameter("@etypename",txtEname.Text),
new SqlParameter("@contents",CN_content.Value),
new SqlParameter("@econtent",EN_content.Value.Replace("'","‘")),
new SqlParameter("@dates",dtime),
new SqlParameter("@typeid",id),
new SqlParameter("@img",suoImgs)
};
int i = DBH.DBHelper.ExecuteNonQuery(sql, par);
if (i > 0)
{
//Methods1.Methods1.Alert(this, "信息添加成功");
Methods1.Methods1.MsgBox("信息修改成功", "Other.aspx");
}
else
{
Methods1.Methods1.Alert(this, "信息修改失败");
}
}
}
public void addmsg()
{
string tid = Methods1.Methods1.Numbers();
string sql;
if (suoImgs == null)
{
//EN_content.Value = EN_content.Value.Replace("'", "''");
//FCKEditor1.value.Replace("'", "''");
sql = "insert into Othertab(typeid,typename,Etypename,contents,econtent,dates)values(@typeid,@typename,@Etypename,@contents,@econtent,@dates)";
SqlParameter[] par ={
new SqlParameter("@typeid",tid),
new SqlParameter("@typename",txtCname.Text),
new SqlParameter("@Etypename",txtEname.Text),
new SqlParameter("@contents",CN_content.Value),
new SqlParameter("@econtent",EN_content.Value.Replace("'","‘")),
new SqlParameter("@dates",dtime),
};
int i = DBH.DBHelper.ExecuteNonQuery(sql, par);
if (i > 0)
{
//Methods1.Methods1.Alert(this, "信息添加成功");
Methods1.Methods1.MsgBox("信息添加成功", "Other.aspx");
}
else
{
Methods1.Methods1.Alert(this, "信息添加失败");
}
}
else
{
sql = @"insert into Othertab(typeid,typename,Etypename,contents,econtent,dates,img)values(@typeid,@typename,@Etypename,@contents,@econtent,@dates,@img)";
SqlParameter[] par ={
new SqlParameter("@typeid",tid),
new SqlParameter("@typename",txtCname.Text),
new SqlParameter("@Etypename",txtEname.Text),
new SqlParameter("@contents",CN_content.Value),
new SqlParameter("@econtent",EN_content.Value.Replace("'","‘")),
new SqlParameter("@dates",dtime),
new SqlParameter("@img",suoImgs)
};
int i = DBH.DBHelper.ExecuteNonQuery(sql, par);
if (i > 0)
{
//Methods1.Methods1.Alert(this, "信息添加成功");
Methods1.Methods1.MsgBox("信息添加成功", "Cultureinfo.aspx");
}
else
{
Methods1.Methods1.Alert(this, "信息添加失败");
}
}
////sql = sql.Replace("'", "/'");
//int i = DBH.DBHelper.ExecuteNonQuery(sql,par);
//if (i > 0)
//{
// Methods1.Methods1.Alert(this, "信息添加成功");
//}
//else
//{
// Methods1.Methods1.Alert(this, "信息添加失败");
//}
}
protected void ib1Save_Click(object sender, ImageClickEventArgs e)
{
if (id != null)//如果ID为空 则执行修改操作 否则执行添加
{ Update(); }
else {
addmsg();
}
}
#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 (Fup.HasFile)
{
FileExtension[] fe = { FileExtension.GIF, FileExtension.JPG, FileExtension.PNG, FileExtension.BMP };
string doc = Server.MapPath("~/" + imgUrl);
if (IsAllowedExtension(Fup, fe) && (Fup.PostedFile.ContentLength / 1024) < 10240) //头字节过滤非法图片 上传大小限制
{
string fileName = Path.GetFileName(Fup.FileName);
fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + Path.GetExtension(Fup.FileName); //以当前日期做为 上传图片名字, path.GetExtension获取文件扩展名
imgs = imgUrl + fileName;//获取图片相对路径
doc += fileName;
ImageUtility.MakeThumbImage(Fup.PostedFile.InputStream, doc, 720, 450, "HW");
//Fup.PostedFile.SaveAs(doc);
Fup.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");
suoImgs = simg;//获取上传图片缩略图的路径名称
// 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
}