📄 filepropety.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using Office.BLL;
using Office.Model;
public partial class File_FileManage_FilePropety : System.Web.UI.Page
{
private static Int32 FID; //文件ID
private static AccessoryFile accessory = null; //附件ID
private static String accessoryIds = ""; //附件Ids
private static List<string> OldFilePath = new List<string>(); //旧的文件路径
private static String filePathName = ""; //文件物理地址
private static Boolean isUpdate = false; //是否为更新状态
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//从请求获得到文件ID
String FileId = Request.QueryString["FID"];
string TT = Request.QueryString["TT"];
try
{
if (TT == "00")
{
isUpdate = false;
this.radNode.Checked = true;
this.lblCreateTime.Text = DateTime.Now.ToString();
this.labOwner.Text = ((UserInfo)Session["User"]).UserId;
if (Page.PreviousPage != null)
{
if (PreviousPage.IsCrossPagePostBack)
{
string path = ((TextBox)this.PreviousPage.FindControl("txtPath")).Text;
if (path == "")
path = "D:\\\\";
this.labFilePath.Text = path;
}
}
}
else
{
FID = Int32.Parse(FileId);
if (FileId != "")
{
isUpdate = true;
InitPage(FileId);
}
}
}
catch (Exception ex)
{
}
}
}
//初始化页面信息根据文件ID
private void InitPage(String FileId)
{
Office.Model.FileInfo file = FileInfoManager.GetFileInfoByFileId(FID);
this.txtFileName.Text = file.FileName;
filePathName = file.FileName;
this.labFilePath.Text = file.FilePath;
this.txtRemark.Text = file.Remark;
this.lblCreateTime.Text = file.CreateDate.ToString();
this.labOwner.Text = file.FileOwner.UserId;
switch (file.FileType.FileTypeId)
{
case 2:
setRad();radOther.Checked = true; break;
case 3:
setRad();radWord.Checked = true; break;
case 4:
setRad(); radExcel.Checked = true; break;
case 5:
setRad();radPPt.Checked = true; break;
case 6:
setRad(); radAccess.Checked = true; break;
case 7:
setRad();radHtm.Checked = true; break;
case 8:
setRad();radBmp.Checked = true; break;
case 9:
setRad();radZip.Checked = true; break;
case 10:
setRad(); radNode.Checked = true; break;
case 11:
setRad();radMedia.Checked = true; break;
case 12:
setRad(); radPdf.Checked = true; break;
case 13:
setRad();radExe.Checked = true; break;
}
Bind();
}
//获得文件类型
private Int32 GetFileType()
{
Int32 TypeId = 0;
if (radOther.Checked)
TypeId = 2;
if (radWord.Checked)
TypeId = 3;
if (radExcel.Checked)
TypeId = 4;
if (radPPt.Checked)
TypeId = 5;
if (radAccess.Checked)
TypeId = 6;
if (radHtm.Checked)
TypeId = 7;
if (radBmp.Checked)
TypeId = 8;
if (radZip.Checked)
TypeId = 9;
if (radNode.Checked)
TypeId = 10;
if (radMedia.Checked)
TypeId = 11;
if (radPdf.Checked)
TypeId = 12;
if (radExe.Checked)
TypeId = 13;
return TypeId;
}
//数据绑定(附件)
private void Bind()
{
IList<AccessoryFile> accessory = null;
if (isUpdate)
{
accessory = AccessoryFileManager.GetAllAccessoryFiles(FID);
}
else
{
accessory = AccessoryFileManager.GetAllAccessoryFiles(Int32.Parse(ViewState["FileId"].ToString()));
}
this.GridView1.DataSource = accessory;
this.GridView1.DataBind();
}
private void setRad()
{
radAccess.Checked = false;
radBmp.Checked = false;
radExcel.Checked = false;
radExe.Checked = false;
radHtm.Checked = false;
radMedia.Checked = false;
radNode.Checked = false;
radOther.Checked = false;
radPdf.Checked = false;
radPPt.Checked = false;
radWord.Checked = false;
radZip.Checked = false;
}
//上传
protected void btnUpLoad_Click(object sender, EventArgs e)
{
String UploadFileName = this.FileUpload1.PostedFile.FileName;
int typeID = 0;
if (UploadFileName == "")
{
Response.Write("<script>alert('不能上传空文件')</script>");
return;
}
else
{
String ExtName = Path.GetExtension(UploadFileName);
if (ExtName == ".doc")
typeID = 3;
else if (ExtName == ".xls")
typeID = 4;
else if (ExtName == ".ppt")
typeID = 5;
else if (ExtName == ".mdb")
typeID = 6;
else if (ExtName == ".htm" || ExtName == ".html")
typeID = 7;
else if (ExtName == ".gif")
typeID = 8;
else if (ExtName == ".rar")
typeID = 9;
else if (ExtName == ".txt")
typeID = 10;
else if (ExtName == ".avi")
typeID = 11;
else if (ExtName == ".pdf")
typeID = 12;
else if (ExtName == ".exe")
typeID = 13;
else
typeID = 2;
Int32 size = this.FileUpload1.PostedFile.ContentLength;
if (size <= 250 * 1024)
{
//String SavePath = this.labFilePath.Text;
String SavePath = Server.MapPath("~/FileUpload");
String SaveFileName = SavePath + "\\" + Path.GetFileName(UploadFileName);
this.FileUpload1.SaveAs(SaveFileName);
OldFilePath.Add(SavePath);
AccessoryFile file = new AccessoryFile();
file.AccessoryName = Path.GetFileName(UploadFileName);
file.AccessoryPath = SaveFileName;
file.AccessorySize = size;
file.AccessoryType = typeID;
file.CreateDate = DateTime.Now;
if (isUpdate)
{
Office.Model.FileInfo f = new Office.Model.FileInfo();
f.FileId = FID;
file.File = f;
}
else
{
file.File = this.AddFile();
ViewState["FileId"] = file.File.FileId;
}
accessory = AccessoryFileManager.AddAccessoryFile(file);
accessoryIds += accessory.AccessoryId + ",";
Bind();
OperateLog operateLog = new OperateLog();
operateLog.User = (UserInfo)Session["User"];
operateLog.OperateName = "增加";
operateLog.OperateTime = DateTime.Now;
operateLog.OperateDesc = "增加文件附件";
operateLog.ObjectId = file.File.FileId.ToString();
OperateLogManager.AddOperateLog(operateLog);
}
else
{
Response.Write("<JavaScript>alert('上传文件过大!')</JavaScript>");
}
}
}
//退出
//把上传的文件删除
protected void ibtnExit_Click(object sender, ImageClickEventArgs e)
{
try
{
if (OldFilePath != null)
{
foreach (string tmp in OldFilePath)
{
if (System.IO.File.Exists(tmp))
{
System.IO.File.Delete(tmp);
}
}
}
}
catch (IOException ex)
{
Response.Write("<Script>alert('删除文件出错!')</Script>");
}
finally
{
if (accessoryIds == "")
accessoryIds += "0,";
AccessoryFileManager.DeleteAccessoryFileByIds(accessoryIds.Substring(0, accessoryIds.Length - 1));
Bind();
accessoryIds = "";
OldFilePath.Clear();
Response.Redirect("~/File/FileManage/FileMain.aspx");
}
}
//保存退出
protected void ibtnSaveExit_Click(object sender, ImageClickEventArgs e)
{
if (isUpdate)
{
Office.Model.FileInfo file = new Office.Model.FileInfo();
file.FileId = FID;
file.FileName = txtFileName.Text;
FileTypeInfo filetype = FileTypeInfoManager.GetFileTypeInfoByFileTypeId(this.GetFileType());
file.FileType = filetype;
file.Remark = txtRemark.Text;
file.FileOwner = UserInfoManager.GetUserInfoByUserId(labOwner.Text);
file.CreateDate = DateTime.Now;
file.ParentId = (FileInfoManager.GetFileInfoByFileId(FID)).ParentId;
string temp = labFilePath.Text;
file.FilePath = temp.Substring(0, temp.Length - filePathName.Length) + "\\" + txtFileName.Text + "." + filetype.FileTypeSuffix;
FileInfoManager.ModifyFileInfo(file);
OperateLog operateLog = new OperateLog();
operateLog.User = (UserInfo)Session["User"];
operateLog.OperateName = "修改";
operateLog.OperateTime = DateTime.Now;
operateLog.OperateDesc = "修改文件";
operateLog.ObjectId = file.FileId.ToString();
OperateLogManager.AddOperateLog(operateLog);
}
Response.Redirect("~/File/FileManage/FileMain.aspx");
}
//添加文件
private Office.Model.FileInfo AddFile()
{
Office.Model.FileInfo file = new Office.Model.FileInfo();
file.FileName = txtFileName.Text;
FileTypeInfo filetype = FileTypeInfoManager.GetFileTypeInfoByFileTypeId(this.GetFileType());
file.FileType = filetype;
file.Remark = txtRemark.Text;
file.FileOwner = (UserInfo)Session["User"];
file.CreateDate = DateTime.Now;
IList<Office.Model.FileInfo> list = FileInfoManager.GetFileInfoByPath(labFilePath.Text);
if (list.Count > 0)
{
Office.Model.FileInfo tmp = list[0];
file.ParentId = tmp.FileId;
}
file.FilePath = labFilePath.Text + "\\" + txtFileName.Text + "." + filetype.FileTypeSuffix;
Office.Model.FileInfo fileinfo = FileInfoManager.AddFileInfo(file);
OperateLog operateLog = new OperateLog();
operateLog.User = (UserInfo)Session["User"];
operateLog.OperateName = "添加";
operateLog.OperateTime = DateTime.Now;
operateLog.OperateDesc = "添加文件";
operateLog.ObjectId = file.FileId.ToString();
OperateLogManager.AddOperateLog(operateLog);
return fileinfo;
}
//GridView命令行处理事件
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "del")
{
Int32 accessoryid = Int32.Parse(e.CommandArgument.ToString());
AccessoryFileManager.DeleteAccessoryFileById(accessoryid);
Bind();
}
}
//数据行绑定事件
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#FFFBD1'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor");
ImageButton img = e.Row.FindControl("ImageButton2") as ImageButton;
if (img != null)
{
img.Attributes.Add("onclick", "JavaScript:return confirm('你确定要删除吗?')");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -