📄 filemanage.aspx.cs
字号:
namespace PowerEasy.WebSite.Admin.Accessories
{
using PowerEasy.Common;
using PowerEasy.Components;
using PowerEasy.Controls;
using PowerEasy.Web.UI;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Security;
using System.Text;
using System.Web.UI.WebControls;
public class FileManage : AdminPage
{
protected Button BtnDelAll;
protected Button BtnDelCurrentFiles;
protected Button BtnDelSelected;
protected Button BtnSearch;
protected Button BtnThumb;
protected Button BtnWaterMark;
protected Label LblCurrentDir;
protected Literal LitMessage;
protected string m_ConfigUploadDir;
protected string m_CurrentDir;
protected DataTable m_CurrentDirectoryInfo;
private static Dictionary<string, string> m_ExtensionImgDictionary;
protected int m_ItemIndex;
protected string m_ParentDir;
protected string m_UrlReferrer;
protected AspNetPager Pager;
protected Panel PanContent;
protected Repeater RptFiles;
protected ExtendedSiteMapPath SmpNavigator;
protected TextBox TxtSearchKeyword;
protected void BindData()
{
DataView defaultView = this.m_CurrentDirectoryInfo.DefaultView;
if (!string.IsNullOrEmpty(BasePage.RequestString("SortField")) && !string.IsNullOrEmpty(BasePage.RequestString("Sort")))
{
defaultView.Sort = BasePage.RequestString("SortField") + " " + BasePage.RequestString("Sort");
}
this.Pager.RecordCount = defaultView.Count;
if (this.Pager.PageSize < defaultView.Count)
{
this.RptFiles.DataSource = defaultView;
this.RptFiles.DataBind();
}
else
{
int num = (this.Pager.CurrentPageIndex - 1) * this.Pager.PageSize;
int num2 = num + this.Pager.PageSize;
List<DataRowView> list = new List<DataRowView>();
for (int i = num; i < num2; i++)
{
if (i >= defaultView.Count)
{
break;
}
list.Add(defaultView[i]);
}
this.RptFiles.DataSource = list;
this.RptFiles.DataBind();
}
}
protected void BtnDelAll_Click(object sender, EventArgs e)
{
try
{
foreach (DataRow row in this.m_CurrentDirectoryInfo.Rows)
{
string file = this.m_ConfigUploadDir + this.m_CurrentDir + "/" + row["name"].ToString();
file = base.Request.PhysicalApplicationPath + file.Replace("/", @"\");
if (row["type"].ToString() == "2")
{
FileSystemObject.Delete(file, FsoMethod.File);
}
if (row["type"].ToString() == "1")
{
FileSystemObject.Delete(file, FsoMethod.Folder);
}
}
}
catch (SecurityException exception)
{
AdminPage.WriteErrMsg(exception.Message);
}
catch (UnauthorizedAccessException exception2)
{
AdminPage.WriteErrMsg(exception2.Message);
}
AdminPage.WriteSuccessMsg("<li>批量删除成功。</li>", this.m_UrlReferrer);
}
protected void BtnDelCurrentFiles_Click(object sender, EventArgs e)
{
try
{
foreach (DataRow row in this.m_CurrentDirectoryInfo.Rows)
{
string file = this.m_ConfigUploadDir + this.m_CurrentDir + "/" + row["name"].ToString();
file = base.Request.PhysicalApplicationPath + file.Replace("/", @"\");
if (row["type"].ToString() == "2")
{
FileSystemObject.Delete(file, FsoMethod.File);
}
}
}
catch (SecurityException exception)
{
AdminPage.WriteErrMsg(exception.Message);
}
catch (UnauthorizedAccessException exception2)
{
AdminPage.WriteErrMsg(exception2.Message);
}
AdminPage.WriteSuccessMsg("<li>批量删除成功。</li>", this.m_UrlReferrer);
}
protected void BtnDelSelected_Click(object sender, EventArgs e)
{
foreach (KeyValuePair<string, string> pair in this.GetRptFilesSelectRows())
{
string file = this.m_ConfigUploadDir + this.m_CurrentDir + "/" + pair.Key;
file = base.Request.PhysicalApplicationPath + file.Replace("/", @"\");
try
{
if (pair.Value == "DelFiles")
{
FileSystemObject.Delete(file, FsoMethod.File);
}
if (pair.Value == "DelDir")
{
FileSystemObject.Delete(file, FsoMethod.Folder);
}
continue;
}
catch (SecurityException exception)
{
AdminPage.WriteErrMsg(exception.Message);
continue;
}
catch (UnauthorizedAccessException exception2)
{
AdminPage.WriteErrMsg(exception2.Message);
continue;
}
}
base.Response.Write("<script type='text/javascript'>parent.frames[\"left\"].location.reload();</script>");
AdminPage.WriteSuccessMsg("<li>批量删除成功。</li>", this.m_UrlReferrer);
}
private void BtnSearch_Click(object sender, EventArgs e)
{
this.BindData();
}
protected void BtnThumb_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in this.RptFiles.Items)
{
CheckBox box;
HiddenField field = (HiddenField) item.FindControl("HdnName");
HiddenField field2 = (HiddenField) item.FindControl("HdnType");
HiddenField field3 = (HiddenField) item.FindControl("HdnExtension");
if (BasePage.RequestString("ShowType") != "0")
{
box = (CheckBox) item.FindControl("ChkListFiles");
}
else
{
box = (CheckBox) item.FindControl("ChkFiles");
}
if (box.Checked)
{
if (field2.Value == "1")
{
this.CreateThumbByFolder(field.Value);
}
if (field2.Value == "2")
{
this.CreateThumb("", field.Value, field3.Value);
}
}
}
AdminPage.WriteSuccessMsg("<li>批量生成缩略图成功。</li>", this.m_UrlReferrer);
}
protected void BtnWaterMark_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in this.RptFiles.Items)
{
CheckBox box;
HiddenField field = (HiddenField) item.FindControl("HdnName");
HiddenField field2 = (HiddenField) item.FindControl("HdnType");
HiddenField field3 = (HiddenField) item.FindControl("HdnExtension");
if (BasePage.RequestString("ShowType") != "0")
{
box = (CheckBox) item.FindControl("ChkListFiles");
}
else
{
box = (CheckBox) item.FindControl("ChkFiles");
}
if (box.Checked)
{
if (field2.Value == "1")
{
this.WaterMarkByFolder(field.Value);
}
if (field2.Value == "2")
{
this.WaterMarkByFile("", field.Value, field3.Value);
}
}
}
AdminPage.WriteSuccessMsg("<li>批量添加水印成功。</li>", this.m_UrlReferrer);
}
protected void CreateThumb(string filePath, string fileName, string extension)
{
string str = this.m_CurrentDir + "/" + filePath + "/";
if (this.IsPhoto(extension))
{
Thumbs.GetThumbsPath(str + fileName, str + Path.GetFileNameWithoutExtension(fileName) + "_S." + extension);
}
}
protected void CreateThumbByFolder(string folderPath)
{
string path = this.m_ConfigUploadDir + this.m_CurrentDir + "/" + folderPath;
path = (base.Request.PhysicalApplicationPath + path.Replace("/", @"\")).Replace(@"\\", @"\");
DirectoryInfo info = new DirectoryInfo(path);
if (info.Exists)
{
foreach (DataRow row in FileSystemObject.GetDirectoryInfos(path, FsoMethod.All).Rows)
{
if (row["type"].ToString() == "2")
{
this.CreateThumb(folderPath, row["name"].ToString(), row["content_type"].ToString());
}
if (row["type"].ToString() == "1")
{
this.CreateThumbByFolder(folderPath + "/" + row["name"].ToString());
}
}
}
}
protected bool GetDeleteEnabled(string forderName)
{
string str;
bool flag = true;
if (((str = forderName) != null) && (((str == "AuthorPic") || (str == "CopyFromPic")) || ((str == "TrademarkPic") || (str == "ProducerPic"))))
{
flag = false;
}
if (forderName == SiteConfig.SiteOption.AdvertisementDir)
{
flag = false;
}
return flag;
}
protected string GetFileContent(string fileName, string extension)
{
fileName = fileName.Replace(@"\", "/");
string str = base.BasePath + this.m_ConfigUploadDir + this.m_CurrentDir + "/" + fileName;
StringBuilder builder = new StringBuilder();
switch (extension)
{
case "jpeg":
case "jpe":
case "bmp":
case "png":
case "jpg":
case "gif":
builder.Append(@"<img src=\'" + str + @"\'");
builder.Append(@" width=\'200\'");
builder.Append(@" height=\'120\'");
builder.Append(@" border=\'0\' />");
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -