/// <summary> /// 绑定列表 /// </summary> private void BindDataList() { QueryParam qp = new QueryParam(); qp.OrderType = OrderType; if (!String.IsNullOrEmpty(Orderfld)) { qp.Orderfld = Orderfld; } else { qp.Orderfld = DNNGo_LayerGallery_Files._.ID; } #region "分页的一系列代码" int RecordCount = 0; int pagesize = qp.PageSize = 10; qp.PageIndex = PageIndex; #endregion //查询的方法 qp.Where = BindSearch(); List <DNNGo_LayerGallery_Files> Articles = DNNGo_LayerGallery_Files.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")); //ctlPagingControl.TotalRecords = RecordCount; //if (RecordCount <= pagesize) //{ // ctlPagingControl.Visible = false; //} gvArticleList.DataSource = Articles; gvArticleList.DataBind(); BindGridViewEmpty <DNNGo_LayerGallery_Files>(gvArticleList, new DNNGo_LayerGallery_Files()); }
/// <summary> /// 项的集合转字符串 /// </summary> /// <param name="ContentItem"></param> /// <returns></returns> public String ItemEntityToString(DNNGo_LayerGallery_Content ContentItem) { String ItemXml = String.Empty; if (ContentItem != null && ContentItem.ID > 0) { QueryParam qp = new QueryParam(); int RecordCount = 0; qp.Where.Add(new SearchParam(DNNGo_LayerGallery_Item._.ContentID, ContentItem.ID, SearchType.Equal)); List <DNNGo_LayerGallery_Item> list = DNNGo_LayerGallery_Item.FindAll(qp, out RecordCount); if (list != null && list.Count > 0) { List <GalleryItemEntity> ItemList = new List <GalleryItemEntity>(); foreach (DNNGo_LayerGallery_Item item in list) { ItemList.Add(EntityToXml(item)); } XmlFormat xf = new XmlFormat(MapPath(String.Format("{0}Resource/xml/ItemEntity.xml", ModulePath))); ItemXml = xf.ToXml <GalleryItemEntity>(ItemList); } } return(ItemXml); }
/// <summary> /// 导出数据到XML /// </summary> protected void cmdExportToXml_Click(object sender, EventArgs e) { try { //查询字段的数据,填充待导出的XML实体 QueryParam qp = new QueryParam(); qp.OrderType = 0; Int32 RecordCount = 0; qp.Where.Add(new SearchParam("ModuleId", ModuleId, SearchType.Equal)); List <DNNGo_LayerGallery_Content> ArticleList = DNNGo_LayerGallery_Content.FindAll(qp, out RecordCount); if (ArticleList != null && ArticleList.Count > 0) { List <GalleryContentEntity> xmlContentList = new List <GalleryContentEntity>(); List <GallerySettingsEntity> xmlSettingList = new List <GallerySettingsEntity>(); ImportExportHelper ieHelper = new ImportExportHelper(); ieHelper.ModuleID = ModuleId; ieHelper.UserId = UserId; //查询出所有的配置项 if (Settings != null && Settings.Count > 0) { List <KeyValueEntity> DefaultSettings = GetDefaultSettings(); foreach (KeyValueEntity kv in DefaultSettings) { String key = String.Format("Global_{0}", kv.Key); if (!xmlSettingList.Exists(r1 => r1.SettingName == key) && Settings[key] != null) { xmlSettingList.Add(new GallerySettingsEntity(key, Convert.ToString(Settings[key]))); } } } foreach (DNNGo_LayerGallery_Content ContentItem in ArticleList) { xmlContentList.Add(EntityToXml(ContentItem)); } XmlFormat xf = new XmlFormat(MapPath(String.Format("{0}Resource/xml/Entity.xml", ModulePath))); //将字段列表转换成XML的实体 String XmlContent = xf.ToXml <GalleryContentEntity>(xmlContentList, xmlSettingList); String XmlFilePath = FileSystemUtils.SaveXmlToFile(String.Format("ContentListEntity_{0}_{1}.xml", ModuleId, xUserTime.UtcTime().ToString("yyyyMMddHHmmssffff")), XmlContent, this); FileSystemUtils.DownloadFile(XmlFilePath, "ContentListEntity.xml"); } else { //没有可导出的文章条目 mTips.IsPostBack = true; mTips.LoadMessage("ExportContentError", EnumTips.Success, this, new String[] { "" }); } } catch (Exception ex) { DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex); } }
// 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) { DNNGo_LayerGallery_Files PhotoItem = new DNNGo_LayerGallery_Files(); 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(FileSystemUtils.HandleFileName(file.FileName)).Replace("." + PhotoItem.FileExtension, ""); //文件名称 String WebPath = String.Format("LayerGallery/uploads/{0}/{1}/{2}/", xUserTime.UtcTime().Year, xUserTime.UtcTime().Month, xUserTime.UtcTime().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}", FileSystemUtils.HandleFileName(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_LayerGallery_Files._.Sort; qp.OrderType = 1; qp.Where.Add(new SearchParam(DNNGo_LayerGallery_Files._.PortalId, PhotoItem.PortalId, SearchType.Equal)); PhotoItem.Sort = Convert.ToInt32(DNNGo_LayerGallery_Files.FindScalar(qp)) + 2; Int32 PhotoId = PhotoItem.Insert(); statuses.Add(new Resource_FilesStatus(PhotoItem, PortalSettings, ModulePath)); } } }
/// <summary> /// 绑定数据项到前台 /// </summary> public void BindDataItem(EffectDBEntity EffectDB) { List <DNNGo_LayerGallery_Content> DataList = new List <DNNGo_LayerGallery_Content>(); Hashtable Puts = new Hashtable(); TemplateFormat xf = new TemplateFormat(this); xf.PhContent = PhContent; //读取需要载入的参数 QueryParam qp = new QueryParam(); int RecordCount = 0; qp.Where.Add(new SearchParam(DNNGo_LayerGallery_Content._.ModuleId, Settings_ModuleID, SearchType.Equal)); qp.Where.Add(new SearchParam(DNNGo_LayerGallery_Content._.Status, (Int32)EnumStatus.Published, SearchType.Equal)); qp.Where.Add(new SearchParam(DNNGo_LayerGallery_Content._.StartTime, xUserTime.UtcTime(), SearchType.LtEqual)); qp.Where.Add(new SearchParam(DNNGo_LayerGallery_Content._.EndTime, xUserTime.UtcTime(), SearchType.GtEqual)); qp.OrderType = 0; if (EffectDB.Pager)//传入分页的数量 { qp.PageSize = (Int32)xf.ViewXmlSetting("PageSize", 9999); qp.PageSize = qp.PageSize <= 0 ? 9999 : qp.PageSize; qp.PageIndex = PageIndex; } if (Settings_Sortby == (Int32)EnumSortby.Name) { qp.Orderfld = DNNGo_LayerGallery_Content._.Title; DataList = DNNGo_LayerGallery_Content.FindAll(qp, out RecordCount); } else if (Settings_Sortby == (Int32)EnumSortby.Name_Desc) { qp.OrderType = 1; qp.Orderfld = DNNGo_LayerGallery_Content._.Title; DataList = DNNGo_LayerGallery_Content.FindAll(qp, out RecordCount); } else if (Settings_Sortby == (Int32)EnumSortby.Time) { qp.Orderfld = DNNGo_LayerGallery_Content._.StartTime; DataList = DNNGo_LayerGallery_Content.FindAll(qp, out RecordCount); } else if (Settings_Sortby == (Int32)EnumSortby.Time_Desc) { qp.OrderType = 1; qp.Orderfld = DNNGo_LayerGallery_Content._.StartTime; DataList = DNNGo_LayerGallery_Content.FindAll(qp, out RecordCount); } else if (Settings_Sortby == (Int32)EnumSortby.Random) { qp.Orderfld = " newid() "; DataList = DNNGo_LayerGallery_Content.FindRandomAll(qp, out RecordCount); } else { qp.Orderfld = DNNGo_LayerGallery_Content._.Sort; DataList = DNNGo_LayerGallery_Content.FindAll(qp, out RecordCount); } List <DNNGo_LayerGallery_Content> tList = new List <DNNGo_LayerGallery_Content>(); //查看需要过滤掉非激活的选项 foreach (var content in DataList) { String Activate = Convert.ToString(xf.GetValue(xf.ViewDicts(content), "activate", "on")); if (String.IsNullOrEmpty(Activate) || Activate.ToLower() == "on") { tList.Add(content); } } Puts.Add("DataList", tList); Puts.Add("EffectName", Settings_EffectName); Puts.Add("ThemeName", Settings_EffectThemeName); //加载LayerList Puts.Add("LayerList", GetLayerList()); if (EffectDB.Pager && RecordCount > qp.PageSize) { Puts.Add("Pager", new Pager(qp.PageIndex, qp.PageSize, ModuleId, RecordCount, EnumPageType.DnnURL).CreateHtml());//分页 } else { Puts.Add("Pager", ""); } String HtmlContent = ViewTemplate(EffectDB, "Effect.html", Puts, xf); //#if RELEASE //Release状态下需要格式化HTML代码 HtmlContent = CodeDeal.DealCode(HtmlContent); //格式化HTML //#endif liContent.Text = HtmlContent; }