using System; using System.Collections.Generic; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using MyShippingWeb.Classes; namespace web.Web.Mld { public partial class MainHome : System.Web.UI.Page { public List _PageData; protected void Page_Load(object sender, EventArgs e) { if (Session["islogin"]==null||Session["islogin"].ToString()=="0") { Response.Redirect("Login.aspx"); } if (Request["action"]=="save") { string msg = this.Save(); Response.Write(msg); Response.End(); } _PageData = GetDataList(); } private string Save() { string result = ""; string partname = Request["partname"]; string title = Request["title"]; string subtitle = Request["subtitle"]; string content = Request["content"]; int index = Convert.ToInt32(Request["index"]); string filename = ""; if (Request.Files.Count>0) { var file = Request.Files[0]; if (file != null)//验证是否包含文件 { //取得文件的扩展名,并转换成小写 if (true) { //对上传文件的大小进行检测,限定文件最大不超过8M if (file.ContentLength < 8192000) { string filepath = Server.MapPath("../Site/img/"); if (Directory.Exists(filepath) == false)//如果不存在就创建file文件夹 { Directory.CreateDirectory(filepath); } string savePath = filepath + "p"+index.ToString()+".jpg"; file.SaveAs(savePath); filename = file.FileName; } else { result = "文件大小超出8M!请重新选择!"; } } } } StringBuilder sb = new StringBuilder(); sb.Append("update HomePageSetting "); sb.Append("set parttitle = '"+title+"',"); sb.Append("partname = '"+partname+"',"); sb.Append("partsubtitle = '"+subtitle+"',"); sb.Append("partcontent = '"+content+"' "); if (filename!="") { sb.Append(",partimage = '"+filename+"'"); } sb.Append(" where orderindex = "+index); int rst = SQLHelper.ExcuteSQL(sb.ToString()); result = rst > 0 ? "更新成功" : "更新失败"; return result; } private List GetDataList() { string sql = "select * from HomePageSetting"; List list = new List(); using (SqlDataReader reader = SQLHelper.GetReader(sql)) { while (reader.Read()) { HomePagePartModel m = new HomePagePartModel(); m.id = Convert.ToInt32(reader["id"]); m.PageName = reader["PageName"].ToString(); m.PartName = reader["PartName"].ToString(); m.PartTitle = reader["PartTitle"].ToString(); m.PartSubTitle = reader["PartSubTitle"].ToString(); m.PartContent = reader["PartContent"].ToString(); m.PartImage = reader["PartImage"].ToString(); m.OrderIndex = Convert.ToInt32(reader["OrderIndex"]); m.UpdateTime = reader["UpdateTime"].ToString(); list.Add(m); } } return list; } } }