📄 fileinmanager.aspx.cs
字号:
List<AccessoryFileModel> liaccess = FileBLL.SelectFileidAcc(fileid);
gvAccessoryFileInfo.DataSource = liaccess;
gvAccessoryFileInfo.DataBind();
}
}
}
protected void gvAccessoryFileInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow) {
int AccessId = int.Parse(gvAccessoryFileInfo.DataKeys[e.Row.RowIndex].Value.ToString());
AccessoryFileModel accessFile = FileBLL.SeAccessoryId(AccessId);
string path = accessFile.AccessoryPath;
string[] http = path.Split(':');
int num = http[1].Length - 2;
string realpath = http[0] + ":\\" + http[1].Substring(2, num);
Label lblAccessoryName = (Label)e.Row.FindControl("lblLinkAccessoryName");
lblAccessoryName.ToolTip = "点击下载";
lblAccessoryName.Text = "<a href ='" + realpath + "'>" + accessFile .AccessoryName+ "</a>";
e.Row.Cells[2].Text =accessFile.Filetype.FileTypeName;//显示文件类型名字
ImageButton imgbtnDelete = (ImageButton)e.Row.FindControl("imgbtnDelete");//实例化image按钮控件
imgbtnDelete.CommandArgument = AccessId+"";//指定删除按钮的关联参数
e.Row.Attributes.Add("onmouseover","color=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=color");
}
}
protected void btnUpFile_Click(object sender, EventArgs e)
{
AccessoryFileModel accessoryFile = new AccessoryFileModel();//实例化附件实体
int fileSize = fileBrowser.PostedFile.ContentLength;//得到上传文件大小
byte[] arrFile = new byte[fileSize];//把文件大小转换成二进制数组
if (fileSize > 0)
{
string[] getFileType = fileBrowser.FileName.Split('.');
string accessoryName = getFileType[0].ToString();//得到文件名称部分
string suffix = getFileType[1].ToString();//得到文件后缀部分
FileTypeInfoModel fileType = FileBLL.SeHouZui(suffix);//根据文件后缀得到文件类型
if (fileType.FileTypeId.ToString() != RadioButtonList1.SelectedValue)
{
Response.Write("<script>alert('上传的文件类型和选择的文件类型不一致!');</script>");
}
else
{
accessoryFile.AccessoryName = accessoryName;
accessoryFile.AccessoryType = fileType.FileTypeId;
accessoryFile.AccessorySize = fileSize;
accessoryFile.CreateDate = DateTime.Now;
string accessoryPath = "";
int fileId = int.Parse(Request.QueryString["FileId"].ToString());
FileInfoModel fims = FileBLL.SeleFileId(fileId);
FileInfoModel fpaims = FileBLL.SeleFileId(fims.ParentId);
// FileInfoModel fif = FileBLL.SePathFileIn(lblFileLocation.Text);
//如果是修改文件操作
if (ViewState["Filesd"] != null)
{
accessoryPath = fpaims.FilePath + "\\" + fileBrowser.FileName;
//accessoryPath = lblFileLocation.Text + "\\" + fileBrowser.FileName;//得到文件附件路径
accessoryFile.FileId = int.Parse(ViewState["Filesd"].ToString());
accessoryFile.AccessoryPath = accessoryPath;
}
// 如果是添加文件操作,首先插入新文件
else
{
string filePath = lblFileLocation.Text + "\\" + txtFileName.Text.Trim();
accessoryPath = filePath + "\\" + fileBrowser.FileName;//得到文件附件路径
if (hidFileId.Value == ".doc")
{
//判断该文件是否已经存在
if (!File.Exists(filePath))
{
Directory.CreateDirectory(filePath);
UserInfoModel user = (UserInfoModel)Session["User"];//得到登录用户
//执行添加操作
FileInfoModel file = new FileInfoModel();//实例化一个新的文件
file.FileName = txtFileName.Text;
file.FileType = int.Parse(RadioButtonList1.SelectedValue);
file.Remark = txtRemark.Text;
file.CreateDate = DateTime.Now;
file.FileOwner = user.UserId;
file.FilePath = filePath;
FileInfoModel fin = (FileInfoModel)Session["FileMod"];
file.ParentId = fin.FileId;
//file.ParentId = int.Parse(ViewState["ParterfileId"].ToString());
file.IfDelete = 0;
int fileIds = FileBLL.InsertPage(file);
if (fileIds > 0)
{
hidFileId.Value = fileId.ToString();
accessoryFile.FileId = fileId;//指定附件对应的文件Id
accessoryFile.AccessoryPath = accessoryPath;//指定附件路径
}
else
{
Response.Write("<script>alert('添加附件过程中出现异常错误!');</script>");
}
}
else
{
Response.Write("<script>alert('添加附件过程中出现异常错误!');</script>");
}
}
else
{
accessoryFile.FileId = int.Parse(hidFileId.Value);//指定附件对应的文件Id
accessoryFile.AccessoryPath = accessoryPath;//指定附件路径
}
}
// 执行添加附件操作
//判断附件是否已经存在
if (File.Exists(accessoryPath))
{
Response.Write("<script>alert('该附件已经存在!');</script>");
}
else
{
Stream streamReader = fileBrowser.PostedFile.InputStream;
streamReader.Read(arrFile, 0, fileSize);
int accnumber=FileBLL.InsertAcc(accessoryFile);
if (accnumber!=0)
{
fileBrowser.PostedFile.SaveAs(accessoryPath);
if (ViewState["Filesd"] != null)
{
hidFileId.Value = ViewState["Filesd"].ToString();
}
Fujian(int.Parse(hidFileId.Value.Trim()));//显示附件信息
}
else
{
Response.Write("<script>alert('上传失败!');</script>");
}
}
}
}
else
{
Response.Write("<script>alert('上传过程中发生异常错误!');</script>");
}
}
protected void imgbtnExit_Click(object sender, ImageClickEventArgs e)
{
//退出时进行修改
if (ViewState["Filesd"] != null)
{
//判断是否已经添加了附件,如果已添加则删除之
if (hidFileId.Value != "")
{
int fileId = int.Parse(ViewState["Filesd"].ToString());
int num = int.Parse(hidAccessoryCount.Value);
//修改文件时,如果已经添加了附件,退出时从我的电脑中删除之
List<AccessoryFileModel> tempAccessoryFiles = FileBLL.GetTempAccessoryFiles(fileId, num);
foreach (AccessoryFileModel tempAccessoryFile in tempAccessoryFiles)
{
File.Delete(tempAccessoryFile.AccessoryPath);
}
bool result = FileBLL.DeleteTempAccessoryFiles(fileId, num);
if (result)
{
Response.Redirect("FileMain.aspx");
}
else
{
Response.Write("<script>您刚才添加的附件已经写进文件夹,要放弃修改,请删除刚才添加附件!</script>");
}
}
else
{
Response.Redirect("FileMain.aspx");
}
}
//退出时进行添加
else {
//判断是否已经添加了附件,如果已添加则删除添加的文件和对应的附件
if (hidFileId.Value != "")
{
int fileId = int.Parse(hidFileId.Value);
FileInfoModel file = FileBLL.SeleFileId(fileId);
Directory.Delete(file.FilePath, true);
int number = FileBLL.FangBack(fileId);
if (number!=0)
{
Response.Redirect("FileMain.aspx");
}
}
else
{
Response.Redirect("FileMain.aspx");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -