/// <summary> /// 加载信息 /// </summary> protected void LoadInfo() { ddl_Class.DataSource = NewsAction.NewsClass.Where(p => p.IsLeafClass && p.ModelID == 2); ddl_Class.DataTextField = "ClassName"; ddl_Class.DataValueField = "ID"; ddl_Class.DataBind(); ddl_Class.SelectedValue = cls.ToS(); ddl_Author.DataSource = SysUserView.GetModelList(); ddl_Author.DataTextField = "UserName"; ddl_Author.DataValueField = "ID"; ddl_Author.DataBind(); ImageAlbum imga = ImageAlbumView.GetModelByID(id.ToS()); //txt_Title.Text = imga.Title; //ddl_Author.SelectedValue = imga.AuthorID.ToS(); //txt_Folder.Text = imga.Folder; //txt_Keyword.Text=imga. if (id > 0) { ddl_Class.SelectedValue = imga.ClassID.ToS(); txt_Title.Text = imga.Title; ddl_Author.Text = imga.AuthorID.ToS(); //txt_Folder.Text = imga.Folder; txt_Keyword.Text = imga.KeyWords; txt_ClickCount.Text = imga.ClickCount.ToS(); txt_ReplyCount.Text = imga.ClickCount.ToS(); txt_Intro.Text = imga.Intro; rp_list.DataSource = ImagesView.GetModelList(string.Format("AlbumID={0} order by id", imga.ID)); rp_list.DataBind(); } else { ImageAlbumView.Del("AuthorID=0 and CreateTime<'" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + "'"); imga = new ImageAlbum() { ClassID = cls, ClickCount = 0, ReplyCount = 0, ZtID = 0, CreateTime = DateTime.Now, AuthorID = 0, UpdateTime = DateTime.Now }; ImageAlbumView.Insert(imga); Response.Redirect(string.Format("ImageEdit.aspx?class={0}&id={1}", cls, imga.ID)); } }
/// <summary> /// 上传图片 /// </summary> /// <param name="file"></param> /// <param name="ClassID"></param> /// <returns></returns> public static Result UpLoadImage(HttpPostedFile file, int ImageAlbumID) { Result r = new Result(); SysSetting ss = BasePage.SystemSetting; string FileName = file.FileName.GetFileNameFromPath().ToLower(); //文件名 string ExtName = file.FileName.GetFileExtNameFromPath().ToLower(); //扩展名 string NewName = @string.GetGuid() + ExtName; //新文件名 if (!ExtName.Replace(".", "").IsInArray(ss.FileExtNameFilter.Split(','))) { r.Success = false; r.Text = "不允许上传此类文件"; return(r); } if (file.ContentLength > ss.MaxPostFileSize) { r.Success = false; r.Text = "文件太大"; return(r); } string Folder = ss.FileDir + "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/"; //文件目录 string FolderShotCut = Folder + "ShortCut/"; //缩略图目录 string FilePath = Folder + NewName; //文件路径 string FilePath_ShortCut = FolderShotCut + NewName; //缩略图路径 file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(FilePath), true); if (ExtName.ToLower().Replace(".", "").IsInArray("jpg,jpeg,png,gif,bmp".Split(','))) { ImageHelper.MakeThumbnail(System.Web.HttpContext.Current.Server.MapPath(FilePath), System.Web.HttpContext.Current.Server.MapPath(FilePath_ShortCut), 105, 118, "Cut"); } ImageAlbum album = ImageAlbumView.GetModelByID(ImageAlbumID.ToS()); Images img = new Images(); img.AlbumID = album.ID; img.ClickCount = 0; img.ExtName = ExtName; img.FilePath = FilePath; img.FileSize = file.ContentLength; img.Intro = ""; img.ReplyCount = 0; img.SmallPath = FilePath_ShortCut; img.Title = ""; img.UploadTime = DateTime.Now; ImagesView.Insert(img); ImageAlbum imga = ImageAlbumView.GetModelByID(ImageAlbumID.ToString()); imga.Size = ImagesView.Count(string.Format("AlbumID={0}", imga.ID)); ImageAlbumView.Update(imga); r.Success = true; r.Text = FilePath; return(r); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_Save_Click(object sender, EventArgs e) { Class cls = ClassView.GetModelByID(ddl_Class.SelectedValue); ImageAlbum imga = ImageAlbumView.GetModelByID(WS.RequestString("id")); imga.ClassID = ddl_Class.SelectedValue.ToInt32(); imga.Title = txt_Title.Text.TrimDbDangerousChar(); imga.AuthorID = ddl_Author.SelectedValue.ToInt32(); imga.Author = ddl_Author.SelectedItem.Text; imga.ClickCount = txt_ClickCount.Text.ToInt32(0); if (imga.ID <= 0) { imga.CreateTime = DateTime.Now; imga.Folder = DateTime.Now.ToString("yyyy-MM-dd"); } imga.Intro = txt_Intro.Text.TrimDbDangerousChar(); imga.KeyWords = txt_Keyword.Text.TrimDbDangerousChar(); imga.ReplyCount = txt_ReplyCount.Text.ToInt32(0); imga.SetTop = false; //imga.ShotCut = ""; //imga.Size = 0; imga.Title = txt_Title.Text; imga.UpdateTime = DateTime.Now; imga.ZtID = 0; if (imga.ID > 0) { ImageAlbumView.Update(imga); } else { ImageAlbumView.Insert(imga); } //保存单个图片设置 string[] t**s = WS.RequestString("tit[]").Split(','); string[] intrs = WS.RequestString("intro[]").Split(','); var imgs = ImagesView.GetModelList(string.Format("AlbumID={0} order by id", imga.ID)); for (int i = 0; i < imgs.Count; i++) { try { imgs[i].Title = t**s[i].ToS(); imgs[i].Intro = intrs[i].ToS(); ImagesView.Update(imgs[i]); } catch { } } //生成页面 CreatePage.CreateContentPage(imga, cls); ImageAlbum pre = GetPreImage(imga, cls); if (pre != null) { CreatePage.CreateContentPage(pre, cls); } CreatePage.CreateListPage(cls, 1); Js.AlertAndChangUrl("保存成功!", url); }