/// <summary>
        /// 绑定查询的方法
        /// </summary>
        private List <SearchParam> BindSearch()
        {
            List <SearchParam> Where = new List <SearchParam>();

            Where.Add(new SearchParam("PortalId", PortalId, SearchType.Equal));
            //Where.Add(new SearchParam("ModuleId", ModuleId, SearchType.Equal));

            //不是管理员,只能看到自己发布文章的评论
            if (!IsAdministrator)
            {
                Where.Add(new SearchParam(DNNGo_ThemePlugin_Multimedia._.LastUser, UserId, SearchType.Equal));
            }

            //筛选文章的状态
            if (FileType >= 0)
            {
                Where = DNNGo_ThemePlugin_Multimedia.ByType(Where, FileType);
            }


            if (!String.IsNullOrEmpty(Search_Title))
            {
                txtSearch.Text = HttpUtility.UrlDecode(Search_Title);
                Where.Add(new SearchParam(DNNGo_ThemePlugin_Multimedia._.Name, HttpUtility.UrlDecode(Search_Title), SearchType.Like));
            }



            return(Where);
        }
Beispiel #2
0
        // Delete file from the server
        private void DeleteFile(HttpContext context)
        {
            Int32 PhotoID = WebHelper.GetIntParam(context.Request, "ID", 0);
            DNNGo_ThemePlugin_Multimedia PhotoItem = DNNGo_ThemePlugin_Multimedia.FindByKeyForEdit(PhotoID);

            if (PhotoItem != null && PhotoItem.ID > 0)
            {
                //要删除实际的文件
                String DeletePath = HttpContext.Current.Server.MapPath(GetPhotoPath(PhotoItem.FilePath));

                //删除分类项
                //DNNGo_ThemePlugin_Articles_Files.DeleteByMultimedia(PhotoItem.ID);

                //删除文件
                if (File.Exists(DeletePath))
                {
                    try
                    {
                        File.Delete(DeletePath);
                    }
                    catch { }
                }
                //删除记录
                PhotoItem.Delete();
            }
        }
        /// <summary>
        /// 获取图片的路径
        /// </summary>
        /// <param name="media">媒体文件的实体</param>
        /// <returns></returns>
        public String GetPhotoPath(DNNGo_ThemePlugin_Multimedia media, PortalSettings ps)
        {
            String PhotoPath = String.Empty;

            if (media != null && media.ID > 0)
            {
                PhotoPath = GetPhotoPath(media.FilePath, ps);
            }
            return(PhotoPath);
        }
        public String ViewPicture(DNNGo_ThemePlugin_Multimedia DataItem, PortalSettings ps, String ModulePath)
        {
            String Picture = String.Format("{0}Resource/images/DefaultPhoto.png", ModulePath);

            if (DataItem != null && DataItem.ID > 0)
            {
                Picture = GetPhotoPath(DataItem, ps);
            }
            return(Picture);
        }
 private void SetValues(DNNGo_ThemePlugin_Multimedia PhotoItem, int fileLength, PortalSettings ps, String ModulePath)
 {
     name          = WebHelper.leftx(PhotoItem.Name, 35, "...");
     type          = "image/png";
     size          = PhotoItem.FileSize * 1024;
     progress      = "1.0";
     url           = ViewPicture(PhotoItem, ps, ModulePath);
     thumbnail_url = GetPhotoExtension(PhotoItem.FileExtension, PhotoItem.FilePath, ps, ModulePath);
     delete_url    = String.Format("{2}Resource_jQueryFileUpload.ashx?ID={0}&type=DELETE&{1}", PhotoItem.ID, WebHelper.GetScriptNameQueryString, ModulePath);
     delete_type   = "POST";
 }
        /// <summary>
        /// 绑定列表
        /// </summary>
        private void BindDataList()
        {
            QueryParam qp = new QueryParam();

            qp.OrderType = OrderType;
            if (!String.IsNullOrEmpty(Orderfld))
            {
                qp.Orderfld = Orderfld;
            }
            else
            {
                qp.Orderfld = DNNGo_ThemePlugin_Multimedia._.ID;
            }

            #region "分页的一系列代码"


            int RecordCount = 0;
            int pagesize    = qp.PageSize = 10;
            qp.PageIndex = PageIndex;


            #endregion

            //查询的方法
            qp.Where = BindSearch();

            List <DNNGo_ThemePlugin_Multimedia> Comments = DNNGo_ThemePlugin_Multimedia.FindAll(qp, out RecordCount);
            qp.RecordCount      = RecordCount;
            RecordPages         = qp.Pages;
            lblRecordCount.Text = String.Format("{0} {2} / {1} {3}", RecordCount, RecordPages, ViewResourceText("Title_Items", "Items"), ViewResourceText("Title_Pages", "Pages"));

            hlFileMateAll.Text   = String.Format("{1} ({0})", DNNGo_ThemePlugin_Multimedia.FindCountByType(0, -1), ViewResourceText("hlFileMateAll", "All"));
            hlFileMateImage.Text = String.Format("{1} ({0})", DNNGo_ThemePlugin_Multimedia.FindCountByType(0, (Int32)EnumFileMate.Image), ViewResourceText("hlFileMateImage", "Image"));
            hlFileMateZip.Text   = String.Format("{1} ({0})", DNNGo_ThemePlugin_Multimedia.FindCountByType(0, (Int32)EnumFileMate.Zip), ViewResourceText("hlFileMateZip", "Zip"));
            hlFileMateVideo.Text = String.Format("{1} ({0})", DNNGo_ThemePlugin_Multimedia.FindCountByType(0, (Int32)EnumFileMate.Video), ViewResourceText("hlFileMateVideo", "Video"));
            hlFileMateDoc.Text   = String.Format("{1} ({0})", DNNGo_ThemePlugin_Multimedia.FindCountByType(0, (Int32)EnumFileMate.Doc), ViewResourceText("hlFileMateDoc", "Doc"));


            //ctlPagingControl.TotalRecords = RecordCount;

            //if (RecordCount <= pagesize)
            //{
            //    ctlPagingControl.Visible = false;

            //}

            gvCommentList.DataSource = Comments;
            gvCommentList.DataBind();
            BindGridViewEmpty <DNNGo_ThemePlugin_Multimedia>(gvCommentList, new DNNGo_ThemePlugin_Multimedia());
        }
        /// <summary>
        /// 列表行绑定
        /// </summary>
        protected void gvArticleList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //还原出数据
                DNNGo_ThemePlugin_Multimedia Media = e.Row.DataItem as DNNGo_ThemePlugin_Multimedia;

                if (Media != null && Media.ID > 0)
                {
                    Label lblFileExtension = e.Row.FindControl("lblFileExtension") as Label;
                    lblFileExtension.Text = Media.FileExtension;

                    Image imgFileName = e.Row.FindControl("imgFileName") as Image;

                    HyperLink hlFileName = e.Row.FindControl("hlFileName") as HyperLink;
                    hlFileName.Text        = Media.FileName.Replace("." + Media.FileExtension, "");
                    imgFileName.ImageUrl   = GetPhotoExtension(Media.FileExtension, Media.FilePath);
                    hlFileName.NavigateUrl = GetPhotoPath(Media.FilePath);

                    HyperLink hlAdd = e.Row.FindControl("hlAdd") as HyperLink;

                    if (InsertType)
                    {
                        //插入到文章内容
                        hlAdd.Attributes.Add("onclick", String.Format("ReturnHtmlPicture('{0}',{1});", GetPhotoExtension(Media.FileExtension, Media.FilePath), Media.ID));
                    }
                    else
                    {
                        hlAdd.Attributes.Add("onclick", String.Format("ReturnPicture('{0}',{1});", GetPhotoExtension(Media.FileExtension, Media.FilePath), Media.ID));
                    }

                    //发布者信息
                    e.Row.Cells[1].Text = "--";
                    if (Media.LastUser > 0)
                    {
                        UserInfo uInfo = UserController.GetUserById(PortalId, Media.LastUser);
                        if (uInfo != null && uInfo.UserID > 0)
                        {
                            e.Row.Cells[1].Text = String.Format("{0}<br />{1}", uInfo.Username, uInfo.DisplayName);
                        }
                    }


                    //发布时间
                    e.Row.Cells[2].Text = Media.LastTime.ToShortDateString();

                    //状态
                    e.Row.Cells[3].Text = EnumHelper.GetEnumTextVal(Media.Status, typeof(EnumFileStatus));
                }
            }
        }
        /// <summary>
        /// 显示URL控件存放的值
        /// </summary>
        /// <param name="UrlValue"></param>
        /// <param name="IsPhotoExtension">是否显示扩展名图片</param>
        /// <returns></returns>
        public String ViewLinkUrl(String UrlValue, Boolean IsPhotoExtension)
        {
            String DefaultValue = String.Empty;

            if (!String.IsNullOrEmpty(UrlValue) && UrlValue != "0")
            {
                if (UrlValue.IndexOf("FileID=", StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    int FileID = 0;
                    if (int.TryParse(UrlValue.Replace("FileID=", ""), out FileID) && FileID > 0)
                    {
                        var fi = FileManager.Instance.GetFile(FileID);
                        if (fi != null && fi.FileId > 0)
                        {
                            DefaultValue = string.Format("{0}{1}{2}", PortalSettings.HomeDirectory, fi.Folder, Server.UrlPathEncode(fi.FileName));
                        }
                    }
                }
                else if (UrlValue.IndexOf("MediaID=", StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    DefaultValue = String.Format("{0}Resource/images/no_image.png", ModulePath);

                    int MediaID = 0;
                    if (int.TryParse(UrlValue.Replace("MediaID=", ""), out MediaID) && MediaID > 0)
                    {
                        DNNGo_ThemePlugin_Multimedia Multimedia = DNNGo_ThemePlugin_Multimedia.FindByID(MediaID);
                        if (Multimedia != null && Multimedia.ID > 0)
                        {
                            if (IsPhotoExtension)
                            {
                                DefaultValue = Server.UrlPathEncode(GetPhotoExtension(Multimedia.FileExtension, Multimedia.FilePath));// String.Format("{0}{1}", bpm.DNNGalleryPro_PortalSettings.HomeDirectory, Multimedia.FilePath);
                            }
                            else
                            {
                                DefaultValue = Server.UrlPathEncode(GetPhotoPath(Multimedia.FilePath));
                            }
                        }
                    }
                }
                else if (UrlValue.IndexOf("TabID=", StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    DefaultValue = Globals.NavigateURL(Convert.ToInt32(UrlValue.Replace("TabID=", "")), false, PortalSettings, Null.NullString, "", "");
                }
                else
                {
                    DefaultValue = UrlValue;
                }
            }
            return(DefaultValue);
        }
Beispiel #9
0
        /// <summary>
        /// 绑定列表
        /// </summary>
        private void BindDataList()
        {
            QueryParam qp = new QueryParam();

            qp.OrderType = OrderType;
            if (!String.IsNullOrEmpty(Orderfld))
            {
                qp.Orderfld = Orderfld;
            }
            else
            {
                qp.Orderfld = DNNGo_ThemePlugin_Multimedia._.ID;
            }

            #region "分页的一系列代码"


            int RecordCount = 0;
            int pagesize    = qp.PageSize = 10;
            qp.PageIndex = PageIndex;


            #endregion

            //查询的方法
            qp.Where = BindSearch();

            List <DNNGo_ThemePlugin_Multimedia> Articles = DNNGo_ThemePlugin_Multimedia.FindAll(qp, out RecordCount);
            qp.RecordCount      = RecordCount;
            RecordPages         = qp.Pages;
            lblRecordCount.Text = String.Format("{0} {2} / {1} {3}", RecordCount, RecordPages, ViewResourceText("Title_Items", "Items"), ViewResourceText("Title_Pages", "Pages"));


            //Boolean is_admin = !IsAdministrator && !IsAdmin;



            //ctlPagingControl.TotalRecords = RecordCount;

            //if (RecordCount <= pagesize)
            //{
            //    ctlPagingControl.Visible = false;

            //}

            gvArticleList.DataSource = Articles;
            gvArticleList.DataBind();
            BindGridViewEmpty <DNNGo_ThemePlugin_Multimedia>(gvArticleList, new DNNGo_ThemePlugin_Multimedia());
        }
        /// <summary>
        /// 显示URL控件存放的值
        /// </summary>
        /// <param name="UrlValue"></param>
        /// <returns></returns>
        public String ViewLinkUrl(String UrlValue, String DefaultValue, int PortalId)
        {
            if (!String.IsNullOrEmpty(UrlValue) && UrlValue != "0")
            {
                if (UrlValue.IndexOf("FileID=", StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    int FileID = 0;
                    if (int.TryParse(UrlValue.Replace("FileID=", ""), out FileID) && FileID > 0)
                    {
                        var fi = FileManager.Instance.GetFile(FileID);
                        if (fi != null && fi.FileId > 0)
                        {
                            DefaultValue = string.Format("{0}{1}{2}", bpm.PortalSettings.HomeDirectory, fi.Folder, bpm.Server.UrlPathEncode(fi.FileName));
                        }
                    }
                }
                else if (UrlValue.IndexOf("MediaID=", StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    int MediaID = 0;
                    if (int.TryParse(UrlValue.Replace("MediaID=", ""), out MediaID) && MediaID > 0)
                    {
                        DNNGo_ThemePlugin_Multimedia Multimedia = DNNGo_ThemePlugin_Multimedia.FindByID(MediaID);
                        if (Multimedia != null && Multimedia.ID > 0)
                        {
                            DefaultValue = bpm.Server.UrlPathEncode(bpm.GetPhotoPath(Multimedia.FilePath));// String.Format("{0}{1}", bpm.MemberGroup_PortalSettings.HomeDirectory, Multimedia.FilePath);
                        }

                        if (!String.IsNullOrEmpty(DefaultValue))
                        {
                            if (DefaultValue.ToLower().IndexOf("http://") < 0)
                            {
                                DefaultValue = string.Format("http://{0}{1}", WebHelper.GetHomeUrl(), DefaultValue);
                            }
                        }
                    }
                }
                else if (UrlValue.IndexOf("TabID=", StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    DefaultValue = Globals.NavigateURL(Convert.ToInt32(UrlValue.Replace("TabID=", "")), false, bpm.PortalSettings, Null.NullString, "", "");
                }
                else
                {
                    DefaultValue = UrlValue;
                }
            }
            return(DefaultValue);
        }
Beispiel #11
0
        /// <summary>
        /// 绑定相册集
        /// </summary>
        private void BindPictures(TabInfo Article)
        {
            List <String> SelectList = new List <String>();

            if (Article != null && Article.TabID > 0)
            {
                //填充相册集的关系
                List <DNNGo_ThemePlugin_Relationships> Relationships = DNNGo_ThemePlugin_Relationships.FindAllByID(EditTabID, PortalId, FileType);

                RepeaterFields.DataSource = Relationships;
                RepeaterFields.DataBind();

                foreach (DNNGo_ThemePlugin_Relationships Albums in Relationships)
                {
                    SelectList.Add(Albums.FileID.ToString());
                }
            }

            if (Article != null && Article.TabID > 0 && SelectList.Count > 0)
            {
                //绑定所有分类到页面
                QueryParam qp          = new QueryParam();
                int        RecordCount = 0;
                qp.Where.Add(new SearchParam(DNNGo_ThemePlugin_Multimedia._.PortalId, PortalId, SearchType.Equal));
                qp.Where.Add(new SearchParam(DNNGo_ThemePlugin_Multimedia._.ID, Common.GetStringByList(SelectList), SearchType.In));
                List <DNNGo_ThemePlugin_Multimedia> lst = DNNGo_ThemePlugin_Multimedia.FindAll(qp, out RecordCount);

                //拼接顶级分类的方法
                StringBuilder sb    = new StringBuilder();
                StringBuilder sbIDs = new StringBuilder();
                foreach (String FileID in SelectList)
                {
                    if (lst.Exists(r => r.ID.ToString() == FileID))
                    {
                        DNNGo_ThemePlugin_Multimedia PictureItem = lst.Find(r => r.ID.ToString() == FileID);
                        sb.AppendFormat("<tr data-value='{0}'>", PictureItem.ID).AppendLine();
                        sb.AppendFormat("<td>{0}<br/><img src=\"{1}\" style=\"max-width:120px; margin-right:15px;\"/></td>", PictureItem.FileName, GetPhotoExtension(PictureItem.FileExtension, PictureItem.FilePath)).AppendLine();
                        sb.AppendFormat("<td class=\"center\"><a  data-value='{0}' class=\"btn btn-xs btn-bricky tooltips\" href=\"javascript:;\" data-placement=\"top\" data-original-title=\"Delete\"><i class=\"fa fa-times fa fa-white\"></i></a></td>", PictureItem.ID).AppendLine();
                        sb.Append("</tr>").AppendLine();

                        sbIDs.AppendFormat("{0},", PictureItem.ID);
                    }
                }
                hfPictures.Value = sbIDs.ToString();
                liPictures.Text  = sb.ToString();
            }
        }
Beispiel #12
0
        /// <summary>
        /// 字段绑定事件
        /// </summary>
        protected void RepeaterFields_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DNNGo_ThemePlugin_Relationships FieldItem = e.Item.DataItem as DNNGo_ThemePlugin_Relationships;

                DNNGo_ThemePlugin_Multimedia PictureItem = DNNGo_ThemePlugin_Multimedia.FindByID(FieldItem.FileID);
                if (PictureItem != null && PictureItem.ID > 0)
                {
                    Literal liName = e.Item.FindControl("liName") as Literal;
                    liName.Text = PictureItem.FileName;

                    Image imgPicture = e.Item.FindControl("imgPicture") as Image;
                    imgPicture.ImageUrl = GetPhotoExtension(PictureItem.FileExtension, PictureItem.FilePath);
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// 页面加载需要绑定的方法
        /// </summary>
        public void BindPageLoad()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.AppendFormat("<ul id=\"{0}\" class=\"{1}\">", SkinClientID, CssClass).AppendLine();

            DNNGo_ThemePlugin_Menu Item = GetGlobalSettings();

            EnumRelationshipsFileType FileType = Token.IndexOf("Breadcrumb", StringComparison.CurrentCultureIgnoreCase) >= 0 ? EnumRelationshipsFileType.Breadcrumb : EnumRelationshipsFileType.Background;
            Boolean isGlobal = (Token.IndexOf("Breadcrumb", StringComparison.CurrentCultureIgnoreCase) >= 0 ? Item.Globals_Breadcrumb : Item.Globals_Background) == 1;

            List <String> FileIDs = new List <String>();
            List <DNNGo_ThemePlugin_Relationships> Relationships = DNNGo_ThemePlugin_Relationships.FindAllViewByID(PortalSettings.ActiveTab.TabID, PortalSettings.PortalId, (Int32)FileType, isGlobal);

            foreach (DNNGo_ThemePlugin_Relationships Relationship in Relationships)
            {
                FileIDs.Add(Relationship.FileID.ToString());
            }


            if (FileIDs != null && FileIDs.Count > 0)
            {
                //绑定所有分类到页面
                QueryParam qp          = new QueryParam();
                int        RecordCount = 0;
                qp.Where.Add(new SearchParam(DNNGo_ThemePlugin_Multimedia._.PortalId, PortalSettings.PortalId, SearchType.Equal));
                qp.Where.Add(new SearchParam(DNNGo_ThemePlugin_Multimedia._.ID, Common.GetStringByList(FileIDs), SearchType.In));
                List <DNNGo_ThemePlugin_Multimedia> lst = DNNGo_ThemePlugin_Multimedia.FindAll(qp, out RecordCount);

                foreach (String FileID in FileIDs)
                {
                    if (lst.Exists(r => r.ID.ToString() == FileID))
                    {
                        DNNGo_ThemePlugin_Multimedia PictureItem = lst.Find(r => r.ID.ToString() == FileID);
                        if (PictureItem != null && PictureItem.ID > 0)
                        {
                            sb.AppendFormat("<li style=\"background-image:url('{0}')\"></li>", GetPhotoPath(PictureItem.FilePath)).AppendLine();
                        }
                    }
                }
            }


            sb.Append("</ul>").AppendLine();
            liHTML.Text = sb.ToString();
        }
Beispiel #14
0
        private void DeliverFile(HttpContext context)
        {
            DNNGo_ThemePlugin_Multimedia DataItem = DNNGo_ThemePlugin_Multimedia.FindByKeyForEdit(WebHelper.GetStringParam(context.Request, "PhotoID", "0"));

            if (DataItem != null && DataItem.ID > 0)
            {
                String Picture = GetPhotoPath(DataItem);

                if (!String.IsNullOrEmpty(Picture) && File.Exists(context.Server.MapPath(Picture)))
                {
                    context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + DataItem.FileName + "\"");
                    context.Response.ContentType = "application/octet-stream";
                    context.Response.ClearContent();
                    context.Response.WriteFile(context.Server.MapPath(Picture));
                }
                else
                {
                    context.Response.StatusCode = 404;
                }
            }
            else
            {
                context.Response.StatusCode = 404;
            }



            //var filename = context.Request["PhotoID"];
            //var filePath = StorageRoot + filename;

            //if (File.Exists(filePath)) {
            //    context.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
            //    context.Response.ContentType = "application/octet-stream";
            //    context.Response.ClearContent();
            //    context.Response.WriteFile(filePath);
            //} else
            //    context.Response.StatusCode = 404;
        }
 public String ThumbnailUrl(DNNGo_ThemePlugin_Multimedia DataItem, PortalSettings ps, String ModulePath)
 {
     return(String.Format("{0}Resource_Service.aspx?Token=thumbnail&PortalId={1}&TabId={2}&ID={3}&width=40&height=40&mode=WH", ModulePath, ps.PortalId, ps.ActiveTab.TabID, DataItem.ID));
 }
        public Int32 SynchronizeAllFiles(FileInfo SynchronizeFile)
        {
            Int32 SynchronizeFileCount = 0;


            DNNGo_ThemePlugin_Multimedia PhotoItem = new DNNGo_ThemePlugin_Multimedia();

            PhotoItem.ModuleId = ModuleId;
            PhotoItem.PortalId = PortalId;


            PhotoItem.FileName = SynchronizeFile.Name;
            PhotoItem.FileSize = Convert.ToInt32(SynchronizeFile.Length / 1024);
            PhotoItem.FileMate = FileSystemUtils.GetContentType(Path.GetExtension(PhotoItem.FileName).Replace(".", ""));

            PhotoItem.FileExtension = System.IO.Path.GetExtension(PhotoItem.FileName).Replace(".", "");
            PhotoItem.Name          = System.IO.Path.GetFileName(PhotoItem.FileName).Replace(Path.GetExtension(PhotoItem.FileName), "");

            PhotoItem.Status = (Int32)EnumFileStatus.Approved;

            try
            {
                if (("png,gif,jpg,jpeg,bmp").IndexOf(PhotoItem.FileExtension) >= 0)
                {
                    //图片的流
                    System.Drawing.Image image = System.Drawing.Image.FromFile(SynchronizeFile.FullName);
                    PhotoItem.ImageWidth  = image.Width;
                    PhotoItem.ImageHeight = image.Height;

                    PhotoItem.Exif = Common.Serialize <EXIFMetaData.Metadata>(new EXIFMetaData().GetEXIFMetaData(image));
                }
            }
            catch
            {
            }

            PhotoItem.LastTime = xUserTime.UtcTime();
            PhotoItem.LastIP   = WebHelper.UserHost;
            PhotoItem.LastUser = UserInfo.UserID;

            //将文件存储的路径整理好
            String fileName = PhotoItem.Name; //文件名称
            String WebPath  = String.Format("ThemePlugin/uploads/{0}/{1}/{2}/", PhotoItem.LastTime.Year, PhotoItem.LastTime.Month, PhotoItem.LastTime.Day);
            //检测文件存储路径是否有相关的文件
            FileInfo fInfo = new FileInfo(HttpContext.Current.Server.MapPath(String.Format("{0}{1}{2}.{3}", PortalSettings.HomeDirectory, WebPath, fileName, PhotoItem.FileExtension)));

            //检测文件夹是否存在
            if (!System.IO.Directory.Exists(fInfo.Directory.FullName))
            {
                System.IO.Directory.CreateDirectory(fInfo.Directory.FullName);
            }
            else
            {
                Int32 j = 1;
                while (fInfo.Exists)
                {
                    //文件已经存在了
                    fileName = String.Format("{0}_{1}", PhotoItem.Name, j);
                    fInfo    = new FileInfo(HttpContext.Current.Server.MapPath(String.Format("{0}{1}{2}.{3}", PortalSettings.HomeDirectory, WebPath, fileName, PhotoItem.FileExtension)));
                    j++;
                }
            }

            PhotoItem.FilePath = String.Format("{0}{1}.{2}", WebPath, fileName, PhotoItem.FileExtension);
            PhotoItem.FileName = String.Format("{0}.{1}", fileName, PhotoItem.FileExtension);

            try
            {
                if (!fInfo.Directory.Exists)
                {
                    fInfo.Directory.Create();
                }
                //异步移动文件到文件夹中
                List <String> SynchronizeFileQueue = new List <string>();
                SynchronizeFileQueue.Add(SynchronizeFile.FullName);
                SynchronizeFileQueue.Add(fInfo.FullName);
                ManagedThreadPool.QueueUserWorkItem(new WaitCallback(ThreadMoveTo), SynchronizeFileQueue);
            }
            catch (Exception ex)
            {
            }

            //给上传的相片设置初始的顺序
            QueryParam qp = new QueryParam();

            qp.ReturnFields = qp.Orderfld = DNNGo_ThemePlugin_Multimedia._.Sort;
            qp.OrderType    = 1;
            qp.Where.Add(new SearchParam(DNNGo_ThemePlugin_Multimedia._.PortalId, PhotoItem.PortalId, SearchType.Equal));
            PhotoItem.Sort = Convert.ToInt32(DNNGo_ThemePlugin_Multimedia.FindScalar(qp)) + 2;
            Int32 PhotoId = PhotoItem.Insert();

            if (PhotoId > 0)
            {
                SynchronizeFileCount++;
            }


            return(SynchronizeFileCount);
        }
        public void Execute(BasePage Context)
        {
            QueryParam qp = new QueryParam();

            qp.Orderfld = DNNGo_ThemePlugin_Multimedia._.ID;

            qp.PageIndex = WebHelper.GetIntParam(Context.Request, "PageIndex", 1);
            qp.PageSize  = WebHelper.GetIntParam(Context.Request, "PageSize", Int32.MaxValue);
            qp.Where.Add(new SearchParam(DNNGo_ThemePlugin_Multimedia._.Status, (Int32)EnumFileStatus.Approved, SearchType.Equal));
            qp.Where.Add(new SearchParam(DNNGo_ThemePlugin_Multimedia._.PortalId, Context.PortalId, SearchType.Equal));

            int RecordCount = 0;
            List <DNNGo_ThemePlugin_Multimedia> fileList = DNNGo_ThemePlugin_Multimedia.FindAll(qp, out RecordCount);

            Dictionary <String, Object> jsonPictures = new Dictionary <string, Object>();

            TemplateFormat       xf           = new TemplateFormat();
            JavaScriptSerializer jsSerializer = new JavaScriptSerializer();


            foreach (var fileItem in fileList)
            {
                int index = fileList.IndexOf(fileItem); //index 为索引值

                Dictionary <String, Object> jsonPicture = new Dictionary <String, Object>();

                jsonPicture.Add("Pages", qp.Pages);


                jsonPicture.Add("ID", fileItem.ID);

                jsonPicture.Add("CreateTime", fileItem.LastTime);

                jsonPicture.Add("Name", WebHelper.leftx(fileItem.Name, 20, "..."));
                jsonPicture.Add("Extension", fileItem.FileExtension);


                String ThumbnailUrl = Context.ViewLinkUrl(String.Format("MediaID={0}", fileItem.ID));
                jsonPicture.Add("ThumbnailUrl", ThumbnailUrl);
                jsonPicture.Add("FileUrl", Context.GetPhotoPath(fileItem.FilePath));

                jsonPicture.Add("Thumbnail", String.Format("<img style=\"border-width:0px; max-height:60px;max-width:80px;\"  src=\"{0}\"  /> ", ThumbnailUrl));
                //判断当前文件是否为图片
                if (!String.IsNullOrEmpty(fileItem.FileExtension) && ("gif,jpg,jpeg,bmp,png").IndexOf(fileItem.FileExtension, StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    jsonPicture.Add("IsVideo", false);
                    jsonPicture.Add("IsPicture", true);
                }
                else if (!String.IsNullOrEmpty(fileItem.FileExtension) && ("mp4,mkv,avi,ogv,webm,m4v").IndexOf(fileItem.FileExtension, StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    jsonPicture.Add("IsVideo", true);
                    jsonPicture.Add("IsPicture", false);


                    switch (fileItem.FileExtension)
                    {
                    case "mp4": jsonPicture.Add("IsMp4", true); break;

                    case "m4v": jsonPicture.Add("IsM4v", true); break;

                    case "ogv": jsonPicture.Add("IsOgv", true); break;

                    case "webm": jsonPicture.Add("IsWebm", true); break;

                    default: break;
                    }
                }
                else if (!String.IsNullOrEmpty(fileItem.FileExtension) && ("flv,swf").IndexOf(fileItem.FileExtension, StringComparison.CurrentCultureIgnoreCase) >= 0)
                {
                    jsonPicture.Add("IsFlash", true);
                    jsonPicture.Add("IsPicture", false);
                    jsonPicture.Add("Guid", Guid.NewGuid().ToString());
                }
                else
                {
                    jsonPicture.Add("IsVideo", false);
                    jsonPicture.Add("IsPicture", false);
                }

                jsonPicture.Add("Json", jsSerializer.Serialize(jsonPicture));

                jsonPictures.Add(index.ToString(), jsonPicture);
            }

            //转换数据为json

            ResponseString = jsSerializer.Serialize(jsonPictures);
        }
        public void Execute(BasePage Context)
        {
            Dictionary <String, Object> jsonPicture = new Dictionary <String, Object>();

            Int32 MediaID = WebHelper.GetIntParam(Context.Request, "MediaID", 0);

            if (MediaID > 0)
            {
                DNNGo_ThemePlugin_Multimedia PictureItem = DNNGo_ThemePlugin_Multimedia.FindByKeyForEdit(MediaID);
                if (PictureItem != null && PictureItem.ID > 0)
                {
                    jsonPicture.Add("ID", PictureItem.ID);
                    jsonPicture.Add("CreateTime", PictureItem.LastTime);
                    jsonPicture.Add("Name", PictureItem.Name);
                    jsonPicture.Add("Extension", PictureItem.FileExtension);
                    String ThumbnailUrl = Context.ViewLinkUrl(String.Format("MediaID={0}", PictureItem.ID));
                    jsonPicture.Add("ThumbnailUrl", ThumbnailUrl);
                    jsonPicture.Add("FileUrl", Context.GetPhotoPath(PictureItem.FilePath));


                    jsonPicture.Add("Thumbnail", String.Format("<img style=\"border-width:0px; max-height:60px;max-width:80px;\"  src=\"{0}\"  /> ", ThumbnailUrl));

                    //判断当前文件是否为图片
                    if (!String.IsNullOrEmpty(PictureItem.FileExtension) && ("gif,jpg,jpeg,bmp,png").IndexOf(PictureItem.FileExtension, StringComparison.CurrentCultureIgnoreCase) >= 0)
                    {
                        jsonPicture.Add("IsVideo", false);
                        jsonPicture.Add("IsPicture", true);
                    }
                    else if (!String.IsNullOrEmpty(PictureItem.FileExtension) && ("mp4,mkv,avi,ogv,webm,m4v").IndexOf(PictureItem.FileExtension, StringComparison.CurrentCultureIgnoreCase) >= 0)
                    {
                        jsonPicture.Add("IsVideo", true);
                        jsonPicture.Add("IsPicture", false);


                        switch (PictureItem.FileExtension)
                        {
                        case "mp4": jsonPicture.Add("IsMp4", true); break;

                        case "m4v": jsonPicture.Add("IsM4v", true); break;

                        case "ogv": jsonPicture.Add("IsOgv", true); break;

                        case "webm": jsonPicture.Add("IsWebm", true); break;

                        default: break;
                        }
                    }
                    else if (!String.IsNullOrEmpty(PictureItem.FileExtension) && ("flv,swf").IndexOf(PictureItem.FileExtension, StringComparison.CurrentCultureIgnoreCase) >= 0)
                    {
                        jsonPicture.Add("IsFlash", true);
                        jsonPicture.Add("IsPicture", false);
                        jsonPicture.Add("Guid", Guid.NewGuid().ToString());
                    }
                    else
                    {
                        jsonPicture.Add("IsVideo", false);
                        jsonPicture.Add("IsPicture", false);
                    }
                }
            }

            //转换数据为json
            JavaScriptSerializer jsSerializer = new JavaScriptSerializer();

            ResponseString = jsSerializer.Serialize(jsonPicture);
        }
 public Resource_FilesStatus(DNNGo_ThemePlugin_Multimedia PhotoItem, int fileLength, PortalSettings ps, String ModulePath)
 {
     SetValues(PhotoItem, fileLength, ps, ModulePath);
 }
Beispiel #20
0
        // Upload entire file
        private void UploadWholeFile(HttpContext context, List <Resource_FilesStatus> statuses)
        {
            for (int i = 0; i < context.Request.Files.Count; i++)
            {
                var file = context.Request.Files[i];

                if (file != null && !String.IsNullOrEmpty(file.FileName) && file.ContentLength > 0)
                {
                    //To verify that if the suffix name of the uploaded files meets the DNN HOST requirements
                    bool Valid = FileSystemUtils.CheckValidFileName(file.FileName);
                    if (Valid)
                    {
                        DNNGo_ThemePlugin_Multimedia PhotoItem = new DNNGo_ThemePlugin_Multimedia();

                        PhotoItem.ModuleId = WebHelper.GetIntParam(context.Request, "ModuleId", 0);
                        PhotoItem.PortalId = WebHelper.GetIntParam(context.Request, "PortalId", 0);


                        PhotoItem.FileName = file.FileName;
                        PhotoItem.FileSize = file.ContentLength / 1024;
                        PhotoItem.FileMate = FileSystemUtils.GetContentType(Path.GetExtension(PhotoItem.FileName).Replace(".", ""));

                        PhotoItem.FileExtension = System.IO.Path.GetExtension(PhotoItem.FileName).Replace(".", "");
                        PhotoItem.Name          = System.IO.Path.GetFileName(file.FileName).Replace(Path.GetExtension(PhotoItem.FileName), "");
                        PhotoItem.Status        = (Int32)EnumFileStatus.Approved;

                        try
                        {
                            if (("png,gif,jpg,jpeg,bmp").IndexOf(PhotoItem.FileExtension) >= 0)
                            {
                                //图片的流
                                Image image = Image.FromStream(file.InputStream);
                                PhotoItem.ImageWidth  = image.Width;
                                PhotoItem.ImageHeight = image.Height;

                                PhotoItem.Exif = Common.Serialize <EXIFMetaData.Metadata>(new EXIFMetaData().GetEXIFMetaData(image));
                            }
                        }
                        catch
                        {
                        }

                        PhotoItem.LastTime = xUserTime.UtcTime();
                        PhotoItem.LastIP   = WebHelper.UserHost;
                        PhotoItem.LastUser = UserInfo.UserID;


                        //将文件存储的路径整理好
                        String fileName = System.IO.Path.GetFileName(file.FileName).Replace("." + PhotoItem.FileExtension, ""); //文件名称
                        String WebPath  = String.Format("ThemePlugin/uploads/{0}/{1}/{2}/", PhotoItem.LastTime.Year, PhotoItem.LastTime.Month, PhotoItem.LastTime.Day);
                        //检测文件存储路径是否有相关的文件
                        FileInfo fInfo = new FileInfo(HttpContext.Current.Server.MapPath(String.Format("{0}{1}{2}.{3}", PortalSettings.HomeDirectory, WebPath, fileName, PhotoItem.FileExtension)));

                        //检测文件夹是否存在
                        if (!System.IO.Directory.Exists(fInfo.Directory.FullName))
                        {
                            System.IO.Directory.CreateDirectory(fInfo.Directory.FullName);
                        }
                        else
                        {
                            Int32 j = 1;
                            while (fInfo.Exists)
                            {
                                //文件已经存在了
                                fileName = String.Format("{0}_{1}", PhotoItem.Name, j);
                                fInfo    = new FileInfo(HttpContext.Current.Server.MapPath(String.Format("{0}{1}{2}.{3}", PortalSettings.HomeDirectory, WebPath, fileName, PhotoItem.FileExtension)));
                                j++;
                            }
                        }

                        PhotoItem.FilePath = String.Format("{0}{1}.{2}", WebPath, fileName, PhotoItem.FileExtension);
                        PhotoItem.FileName = String.Format("{0}.{1}", fileName, PhotoItem.FileExtension);
                        try
                        {
                            if (!fInfo.Directory.Exists)
                            {
                                fInfo.Directory.Create();

                                // FileSystemUtils.AddFolder(PortalSettings, String.Format("{0}DNNGo_PhotoAlbums/{0}/{1}/"), String.Format("{0}DNNGo_PhotoAlbums/{0}/{1}/"), (int)DotNetNuke.Services.FileSystem.FolderController.StorageLocationTypes.InsecureFileSystem);
                            }

                            //构造指定存储路径
                            file.SaveAs(fInfo.FullName);
                            //FileSystemUtils.AddFile(PhotoItem.FileName, PhotoItem.PortalId, String.Format("DNNGo_PhotoAlbums\\{0}\\{1}\\", PhotoItem.ModuleId, PhotoItem.AlbumID), PortalSettings.HomeDirectoryMapPath, PhotoItem.FileMeta);
                        }
                        catch (Exception ex)
                        {
                        }

                        //给上传的相片设置初始的顺序
                        QueryParam qp = new QueryParam();
                        qp.ReturnFields = qp.Orderfld = DNNGo_ThemePlugin_Multimedia._.Sort;
                        qp.OrderType    = 1;
                        qp.Where.Add(new SearchParam(DNNGo_ThemePlugin_Multimedia._.PortalId, PhotoItem.PortalId, SearchType.Equal));
                        PhotoItem.Sort = Convert.ToInt32(DNNGo_ThemePlugin_Multimedia.FindScalar(qp)) + 2;
                        Int32 PhotoId = PhotoItem.Insert();



                        statuses.Add(new Resource_FilesStatus(PhotoItem, PortalSettings, ModulePath));
                    }
                }
            }
        }
        /// <summary>
        /// 状态应用按钮事件
        /// </summary>
        protected void btnApply_Click(object sender, EventArgs e)
        {
            try
            {
                Int32 Status = WebHelper.GetIntParam(Request, ddlStatus.UniqueID, -1);

                if (Status >= 0)
                {
                    string   Checkbox_Value       = WebHelper.GetStringParam(Request, "Checkbox", "");
                    string[] Checkbox_Value_Array = Checkbox_Value.Split(',');
                    Int32    IDX = 0;
                    mTips.IsPostBack = true;
                    for (int i = 0; i < Checkbox_Value_Array.Length; i++)
                    {
                        if (Int32.TryParse(Checkbox_Value_Array[i], out IDX))
                        {
                            DNNGo_ThemePlugin_Multimedia Multimedia = DNNGo_ThemePlugin_Multimedia.FindByKeyForEdit(IDX);
                            if (Multimedia != null && Multimedia.ID > 0)
                            {
                                //if (Multimedia.Status == (Int32)EnumFileStatus.Recycle && Status == (Int32)EnumFileStatus.Recycle)
                                //{
                                //要删除实际的文件
                                String DeletePath = Server.MapPath(GetPhotoPath(Multimedia.FilePath));
                                if (Multimedia.Delete() > 0)
                                {
                                    ////删除媒体与文章关系
                                    //DNNGo_ThemePlugin_Articles_Files.DeleteByMultimedia(Multimedia.ID);
                                    ////更新所属图片为空
                                    //DNNGo_ThemePlugin_Articles.DeleteByMultimedia(Multimedia.ID);

                                    //删除文件
                                    if (File.Exists(DeletePath))
                                    {
                                        File.Delete(DeletePath);
                                    }

                                    //操作成功
                                    mTips.LoadMessage("DeleteMediaLibrarySuccess", EnumTips.Success, this, new String[] { Multimedia.FileName });
                                }
                                else
                                {
                                    //操作失败
                                    mTips.LoadMessage("DeleteMediaLibraryError", EnumTips.Success, this, new String[] { Multimedia.FileName });
                                }

                                //}
                                //else
                                //{
                                //    Multimedia.Status = Status;
                                //    if (Multimedia.Update() > 0)
                                //    {
                                //    }
                                //}
                            }
                        }
                    }
                    BindDataList();
                }
            }
            catch (Exception ex)
            {
                ProcessModuleLoadException(ex);
            }
        }
        /// <summary>
        /// 列表上的项删除事件
        /// </summary>
        protected void btnRemove_Click(object sender, EventArgs e)
        {
            try
            {
                LinkButton btnRemove = (LinkButton)sender;

                if (btnRemove != null && !String.IsNullOrEmpty(btnRemove.CommandArgument))
                {
                    mTips.IsPostBack = true;

                    DNNGo_ThemePlugin_Multimedia Multimedia = DNNGo_ThemePlugin_Multimedia.FindByKeyForEdit(btnRemove.CommandArgument);

                    if (Multimedia != null && Multimedia.ID > 0)
                    {
                        //if (Multimedia.Status == (Int32)EnumFileStatus.Recycle)
                        //{
                        //要删除实际的文件
                        String DeletePath = Server.MapPath(GetPhotoPath(Multimedia.FilePath));
                        if (Multimedia.Delete() > 0)
                        {
                            //删除分类项
                            //DNNGo_ThemePlugin_Articles_Files.DeleteByMultimedia(Multimedia.ID);
                            //更新所属图片为空
                            //DNNGo_ThemePlugin_Articles.DeleteByMultimedia(Multimedia.ID);

                            //删除文件
                            if (File.Exists(DeletePath))
                            {
                                File.Delete(DeletePath);
                            }

                            //操作成功
                            mTips.LoadMessage("DeleteMediaLibrarySuccess", EnumTips.Success, this, new String[] { Multimedia.FileName });
                        }
                        else
                        {
                            //操作失败
                            mTips.LoadMessage("DeleteMediaLibraryError", EnumTips.Success, this, new String[] { Multimedia.FileName });
                        }
                        //}
                        //else
                        //{
                        //    Multimedia.Status = (Int32)EnumFileStatus.Recycle;
                        //    if (Multimedia.Update() > 0)
                        //    {
                        //        //移动到回收站操作成功
                        //        mTips.LoadMessage("DeleteCommentSuccess", EnumTips.Success, this, new String[] { Multimedia.FileName });
                        //    }
                        //    else
                        //    {
                        //        //移动到回收站操作失败
                        //        mTips.LoadMessage("DeleteCommentError", EnumTips.Success, this, new String[] { Multimedia.FileName });
                        //    }
                        //}
                        BindDataList();
                    }
                }
            }
            catch (Exception ex)
            {
                ProcessModuleLoadException(ex);
            }
        }
        /// <summary>
        /// 列表行绑定
        /// </summary>
        protected void gvCommentList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //还原出数据
                DNNGo_ThemePlugin_Multimedia Media = e.Row.DataItem as DNNGo_ThemePlugin_Multimedia;

                if (Media != null && Media.ID > 0)
                {
                    #region "编辑&删除按钮"
                    HyperLink  hlEdit          = e.Row.FindControl("hlEdit") as HyperLink;
                    HyperLink  hlMobileEdit    = e.Row.FindControl("hlMobileEdit") as HyperLink;
                    LinkButton btnRemove       = e.Row.FindControl("btnRemove") as LinkButton;
                    LinkButton btnMobileRemove = e.Row.FindControl("btnMobileRemove") as LinkButton;
                    //设置按钮的CommandArgument
                    btnRemove.CommandArgument = btnMobileRemove.CommandArgument = Media.ID.ToString();
                    //设置删除按钮的提示
                    //if (Media.Status == (Int32)EnumFileStatus.Recycle)
                    //{
                    btnRemove.Attributes.Add("onClick", "javascript:return confirm('" + Localization.GetString("DeleteItem") + "');");
                    btnMobileRemove.Attributes.Add("onClick", "javascript:return confirm('" + Localization.GetString("DeleteItem") + "');");
                    //}
                    //else
                    //{
                    //    btnRemove.Attributes.Add("onClick", "javascript:return confirm('" + ViewResourceText("DeleteRecycleItem", "Are you sure to move it to recycle bin?") + "');");
                    //    btnMobileRemove.Attributes.Add("onClick", "javascript:return confirm('" + ViewResourceText("DeleteRecycleItem", "Are you sure to move it to recycle bin?") + "');");
                    //}

                    hlEdit.NavigateUrl = hlMobileEdit.NavigateUrl = xUrl("ID", Media.ID.ToString(), "AddMedia");
                    #endregion

                    //发布者信息
                    e.Row.Cells[3].Text = "--";
                    if (Media.LastUser > 0)
                    {
                        UserInfo uInfo = UserController.GetUserById(PortalId, Media.LastUser);
                        if (uInfo != null && uInfo.UserID > 0)
                        {
                            e.Row.Cells[3].Text = String.Format("{0}<br />{1}", uInfo.Username, uInfo.DisplayName);
                        }
                    }


                    //发布时间
                    e.Row.Cells[4].Text = Media.LastTime.ToShortDateString();

                    //状态
                    e.Row.Cells[5].Text = EnumHelper.GetEnumTextVal(Media.Status, typeof(EnumFileStatus));

                    Label lblFileExtension = e.Row.FindControl("lblFileExtension") as Label;
                    lblFileExtension.Text = Media.FileExtension;

                    Image imgFileName = e.Row.FindControl("imgFileName") as Image;

                    HyperLink hlFileName = e.Row.FindControl("hlFileName") as HyperLink;
                    hlFileName.Text        = Media.FileName.Replace("." + Media.FileExtension, "");
                    imgFileName.ImageUrl   = GetPhotoExtension(Media.FileExtension.ToLower(), Media.FilePath);
                    hlFileName.NavigateUrl = GetPhotoPath(Media.FilePath);

                    Label lblSize = e.Row.FindControl("lblSize") as Label;
                    if (Media.FileSize > 1024)
                    {
                        lblSize.Text = String.Format("{0} MB", Media.FileSize / 1024);
                    }
                    else
                    {
                        lblSize.Text = String.Format("{0} KB", Media.FileSize);
                    }
                }
            }
        }