예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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);
        }