📄 filemanage.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
namespace ComputerWeb
{
/// <summary>
/// Summary description for ManageFile.
/// </summary>
public class ManageFile : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ChannelDropDown;
protected System.Web.UI.WebControls.DropDownList TopicDropDown;
protected System.Web.UI.WebControls.DropDownList SubTopicDropDown;
protected System.Web.UI.WebControls.Button AddButton;
protected System.Web.UI.WebControls.Button UpdateButton;
protected System.Web.UI.WebControls.Button DeleteButton;
protected System.Web.UI.WebControls.TextBox FileInfo;
protected System.Web.UI.WebControls.Button SubmitBtn;
protected System.Web.UI.WebControls.ListBox FileList;
protected System.Web.UI.WebControls.Panel Panel;
protected System.Web.UI.WebControls.Label HintFileInfo;
protected System.Web.UI.WebControls.TextBox LinkAddress;
protected System.Web.UI.WebControls.Label LinkInfo;
private static String commandName = "";
private void Page_Load(object sender, System.EventArgs e)
{
if(Session["UserID"] == null)
{
Response.Redirect("~/Admin/Default.aspx");
}
//判定是否有管理员权限
if(Session["UserID"] != null)
{
if((UserDB.IsValidChannel(Int32.Parse(Session["UserID"].ToString())) == false)
&&(UserDB.IsValidAdmin(Int32.Parse(Session["UserID"].ToString())) == false))
{
Response.Write("<script>parent.location='default.aspx';</script>");
}
}
else
{
Response.Write("<script>parent.location='default.aspx';</script>");
}
// if (!Page.IsPostBack)
// {
// //绑定所有数据
// BindChannelDropDown();
//
// BindTopicDropDown();
//
// BindSubTopicDropDown();
//
// BindFileList();
//
// DeleteButton.Attributes.Add("onclick","return confirm('你确定要删除所选择的文件吗?');");
// }
}
// private void BindChannelDropDown()
// {
// ChannelDropDown.Items.Clear();
//
// //根据UserID显示用户有权限管理的页表
// RelationDB relation = new RelationDB();
// SqlDataReader drRelation = relation.GetChannelByAuthor(Int32.Parse(Session["UserID"].ToString()));
//
// while (drRelation.Read())
// {
// ListItem listItem = new ListItem();
// listItem.Text = drRelation["Channel"].ToString();
// listItem.Value = drRelation["ID"].ToString();
// ChannelDropDown.Items.Add(listItem);
// }
// drRelation.Close();
// }
//
// /// <summary>
// /// 绑定标题列表
// /// </summary>
// private void BindTopicDropDown()
// {
// TopicDropDown.Items.Clear();
// if (ChannelDropDown.SelectedIndex > -1 )
// {
// TopicDB topic = new TopicDB();
// SqlDataReader dr = topic.GetTopics(Int32.Parse(ChannelDropDown.SelectedItem.Value));
// while (dr.Read())
// {
// ListItem listItem = new ListItem();
// listItem.Text = dr["Topic"].ToString();
// listItem.Value = dr["ID"].ToString();
// TopicDropDown.Items.Add(listItem);
// }
// dr.Close();
// }
// }
//
// /// <summary>
// /// 绑定栏目列表
// /// </summary>
// private void BindSubTopicDropDown()
// {
// SubTopicDropDown.Items.Clear();
// if (TopicDropDown.SelectedIndex > -1)
// {
// SubTopicDB topic = new SubTopicDB();
// SqlDataReader dr = topic.GetSubtopics(Int32.Parse(TopicDropDown.SelectedItem.Value));
// while (dr.Read())
// {
// ListItem listItem = new ListItem();
// listItem.Text = dr["SubTopic"].ToString();
// listItem.Value = dr["ID"].ToString();
// SubTopicDropDown.Items.Add(listItem);
// }
// dr.Close();
// }
// }
//
// private void BindFileList()
// {
// FileList.Items.Clear();
//
// //如果Subtopic中有选中的主题,则绑定下属的文件描述。
// if (SubTopicDropDown.SelectedIndex > -1)
// {
// UploadFileDB uploadFile = new UploadFileDB();
// SqlDataReader dr = uploadFile.GetFileBySubTopic(Int32.Parse(SubTopicDropDown.SelectedItem.Value));
//
// FileList.DataSource = dr;
// FileList.DataTextField = "FileInfo";
// FileList.DataValueField = "ID";
// FileList.DataBind();
//
// dr.Close();
// }
// else
// {
// //如果SubTopic中没有选中的主题,检查Topic中有没有选中的栏目
// if (TopicDropDown.SelectedIndex >-1)
// {
// UploadFileDB uploadFile = new UploadFileDB();
// SqlDataReader dr = uploadFile.GetFileByTopic(Int32.Parse(TopicDropDown.SelectedValue));
//
// FileList.DataSource = dr;
// FileList.DataTextField = "FileInfo";
// FileList.DataValueField = "ID";
// FileList.DataBind();
//
// dr.Close();
// }
// else
// {
// if (ChannelDropDown.SelectedIndex >-1)
// {
// UploadFileDB uploadFile = new UploadFileDB();
// SqlDataReader dr =uploadFile.GetFileByChannel(Int32.Parse(ChannelDropDown.SelectedValue));
//
// FileList.DataSource = dr;
// FileList.DataTextField = "FileInfo";
// FileList.DataValueField = "ID";
// FileList.DataBind();
//
// dr.Close();
// }
// }
// }
// }
//
// private void ChannelDropDown_SelectedIndexChanged(object sender, System.EventArgs e)
// {
// //绑定标题列表
// BindTopicDropDown();
//
// //绑定栏目列表
// BindSubTopicDropDown();
//
// //绑定内容列表
// BindFileList();
// }
//
// private void TopicDropDown_SelectedIndexChanged(object sender, System.EventArgs e)
// {
// //绑定栏目列表
// BindSubTopicDropDown();
//
// //绑定内容列表
// BindFileList();
// }
//
// private void SubTopicDropDown_SelectedIndexChanged(object sender, System.EventArgs e)
// {
// //绑定文件名列表
// BindFileList();
// }
//
// private void AddButton_Click(object sender, System.EventArgs e)
// {
// FileInfo.Text = "";
// LinkAddress.Text = "";
// Panel.Visible = true;
//
// //取得所用的命令
// commandName = ((Button)sender).CommandName;
// }
//
// /// <summary>
// /// 更新所选的内容
// /// </summary>
// private void UpdateButton_Click(object sender, System.EventArgs e)
// {
// if (FileList.SelectedIndex > -1)
// {
// Panel.Visible = true;
//
// UploadFileDB uploadFile = new UploadFileDB();
// SqlDataReader dr = uploadFile.GetUploadFile(Int32.Parse(FileList.SelectedItem.Value));
//
// //读出旧内容
// while(dr.Read())
// {
// FileInfo.Text = dr["FileInfo"].ToString();
// LinkAddress.Text = dr["FilePath"].ToString();
// }
// dr.Close();
//
// //取得所用的命令
// commandName = ((Button)sender).CommandName;
// }
// else
// {
// Response.Write("<script>alert(\"请选择要更改的地址!\")</script>");
// }
// }
//
// /// <summary>
// /// 删除所选的内容
// /// </summary>
// private void DeleteButton_Click(object sender, System.EventArgs e)
// {
// if (FileList.SelectedIndex > -1)
// {
// Panel.Visible = true;
//
// UploadFileDB uploadFile = new UploadFileDB();
// SqlDataReader dr = uploadFile.GetUploadFile(Int32.Parse(FileList.SelectedItem.Value));
//
// //读出旧内容
// while(dr.Read())
// {
// FileInfo.Text = dr["FileInfo"].ToString();
// LinkAddress.Text = dr["FilePath"].ToString();
// }
// dr.Close();
//
// //取得所用的命令
// commandName = ((Button)sender).CommandName;
// }
// else
// {
// Response.Write("<script>alert(\"请选择要更改的地址!\")</script>");
// }
// }
//
// private void SubmitBtn_Click(object sender, System.EventArgs e)
// {
// switch(commandName)
// {
// case "add":
// {
// AddLink();
// break;
// }
// case "update":
// {
// UpdateLink();
// break;
// }
// case "delete":
// {
// DeleteLink();
// break;
// }
// default:
// {
// break;
// }
// }
//
// //重新绑定内容列表和Panel的可见性
// BindFileList();
// Panel.Visible = false;
// }
// /// <summary>
// /// 删除所选的内容
// /// </summary>
// private void DeleteFile()
// {
// if(FileList.SelectedIndex > -1)
// {
// string sFilePath = "";
//
// UploadFileDB uploadFile = new UploadFileDB();
// SqlDataReader dr =uploadFile.GetUploadFile(Int32.Parse(FileList.SelectedItem.Value));
// if(dr.Read())
// {
// sFilePath = Server.MapPath(Request.ApplicationPath + dr["FilePath"].ToString());
// }
// dr.Close();
//
// if(File.Exists(sFilePath))
// {
// try
// {
// File.Delete(sFilePath);
// }
// catch(Exception ex)
// {
// string sRawURL = Request.RawUrl;
//
// if(sRawURL.IndexOf("?") > -1)
// {
// sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
// }
// Response.Redirect("~/Admin/AdminDenid.aspx?ErrorURL=" + sRawURL + "&ErrorInfo=" + ex.Message.Replace("\n","<br>"));
// }
// }
// else
// {
// Response.Write("<script>alert(\"你选择的文件已经被意外删除,程序会自动清除在数据库中的数据!\")</script>");
// }
//
// try
// {
// uploadFile.DeleteFile(Int32.Parse(FileList.SelectedValue));
// }
// catch(Exception ex)
// {
// string sRawURL = Request.RawUrl;
//
// if(sRawURL.IndexOf("?") > -1)
// {
// sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
// }
// Response.Redirect("~/Admin/AdminDenid.aspx?ErrorURL=" + sRawURL + "&ErrorInfo=" + ex.Message.Replace("\n","<br>"));
// }
// }
// else
// {
// Response.Write("<script>alert(\"请选择要删除的标题!\")</script>");
// }
// }
// private String JudgeBelong()
// {
// if(ChannelDropDown.Items.Count > 0)
// {
// if(TopicDropDown.Items.Count > 0)
// {
// if (SubTopicDropDown.Items.Count > 0)
// {
// return "SubTopic";
// }
// else
// {
// return "Topic";
// }
// }
// else
// {
// return "Channel";
// }
// }
// else
// {
// return "NoParent";
// }
// }
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
// this.ChannelDropDown.SelectedIndexChanged += new System.EventHandler(this.ChannelDropDown_SelectedIndexChanged);
// this.TopicDropDown.SelectedIndexChanged += new System.EventHandler(this.TopicDropDown_SelectedIndexChanged);
// this.SubTopicDropDown.SelectedIndexChanged += new System.EventHandler(this.SubTopicDropDown_SelectedIndexChanged);
// this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
// this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
// this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
// this.SubmitBtn.Click += new System.EventHandler(this.SubmitBtn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private int[] GetAllID(String sArea)
{
int[] allID = new int[3];
// switch(sArea)
// {
// case "Channel":
// {
// allID[0] = Int32.Parse(ChannelDropDown.SelectedValue);
// allID[1] = allID[2] = 0;
// break;
// }
// case "Topic":
// {
// allID[1] = Int32.Parse(TopicDropDown.SelectedValue);
// allID[0] = allID[2] = 0;
// break;
// }
// case "SubTopic":
// {
// allID[2] = Int32.Parse(SubTopicDropDown.SelectedValue);
// allID[0] = allID[1] = 0;
// break;
// }
// default:
// {
// allID[0] = allID[1] = allID[2] = 0;
// break;
// }
// }
return(allID);
}
/// <summary>
/// 添加新的链接
/// </summary>
private void AddLink()
{
// UploadFileDB file = new UploadFileDB();
// if((FileInfo.Text != "")&&(LinkAddress.Text != ""))
// {
// int[] allID = GetAllID(JudgeBelong());
// if((allID[0] > 0)||(allID[1] > 0)||(allID[2] > 0))
// {
// try
// {
// file.AddUploadFile(LinkAddress.Text,FileInfo.Text,Int32.Parse(Session["UserID"].ToString()),allID[0],allID[1],allID[2]);
// }
// catch(Exception ex)
// {
// string sRawURL = Request.RawUrl;
//
// if(sRawURL.IndexOf("?") > -1)
// {
// sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
// }
// Response.Redirect("~/Admin/AdminDenid.aspx?ErrorURL=" + sRawURL + "&ErrorInfo=" + ex.Message.Replace("\n","<br>"));
// }
// }
// }
// else
// {
// Response.Write("<script>alert(\"说明和地址不能为空!\")</script>");
// }
}
/// <summary>
/// 更新链接
/// </summary>
private void UpdateLink()
{
UploadFileDB file = new UploadFileDB();
if((FileInfo.Text != "")&&(LinkAddress.Text != ""))
{
try
{
file.UpdateFile(Int32.Parse(FileList.SelectedValue),FileInfo.Text,LinkAddress.Text);
}
catch(Exception ex)
{
string sRawURL = Request.RawUrl;
if(sRawURL.IndexOf("?") > -1)
{
sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
}
Response.Redirect("~/Admin/AdminDenid.aspx?ErrorURL=" + sRawURL + "&ErrorInfo=" + ex.Message.Replace("\n","<br>"));
}
}
else
{
Response.Write("<script>alert(\"请选择要更新的地址!\")</script>");
}
}
/// <summary>
/// 删除新的链接
/// </summary>
private void DeleteLink()
{
if(FileList.SelectedIndex > -1)
{
UploadFileDB file = new UploadFileDB();
try
{
file.DeleteFile(Int32.Parse(FileList.SelectedValue));
}
catch(Exception ex)
{
string sRawURL = Request.RawUrl;
if(sRawURL.IndexOf("?") > -1)
{
sRawURL = sRawURL.Substring(0,sRawURL.IndexOf("?"));
}
Response.Redirect("~/Admin/AdminDenid.aspx?ErrorURL=" + sRawURL + "&ErrorInfo=" + ex.Message.Replace("\n","<br>"));
}
}
else
{
Response.Write("<script>alert(\"请选择要删除的地址!\")</script>");
}
}
private String GetRandomint()
{
Random random = new Random();
return(random.Next(10000).ToString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -